Continuous-Time Convolution and Step Responses
An RC filter in front of an ADC receives a pulse from a sensor. How high does the filtered pulse get, and how long until it is gone? In Circuit Theory you would solve the differential equation twice, once for the rising edge and once for the falling edge. The systems view is shorter: find the circuit's impulse response once, and the output for any input is the convolution integral. This lesson works with continuous-time convolution the way an engineer uses it: the impulse response of real circuits, the step response you can measure, and numerical convolution and scipy.signal.lsim to check hand results. The mathematics is in The Dirac Delta and Convolution.
The convolution integral
The same argument as in discrete convolution, with the sifting property in place of the sum of impulses, gives
For a causal system and an input that starts at the limits shrink to . The impulse response has units of "output per input per second": for an RC low-pass, in , so that , the DC gain.
Impulse and step responses of everyday systems.
| System | step response | |
|---|---|---|
| RC low-pass, | ||
| RC high-pass | ||
| ideal delay | ||
| ideal integrator | (unbounded) | |
| second-order low-pass, , | rings at |
Measuring . You cannot apply a true Dirac impulse, but you can apply a step (switch a supply, a square wave with a long period) and differentiate: . A short pulse of width much shorter than the system's time constants also works: its response is , the pulse's area times . Both are standard ways of identifying a sensor or an amplifier on the bench.
Worked example: a pulse through an RC filter
Given: , (); input a rectangular pulse of from to .
Find: , its peak, and its value at .
Solve: write the pulse as . By linearity and time invariance the output is the step response minus a delayed step response:
Check: the peak is below because the pulse lasts only ; it reaches only for pulses longer than about . Evaluating the convolution integral directly gives the same result, as the code below shows.
import numpy as np
from scipy import signal
R, C = 1e3, 1e-6
tau = R * C
dt = 1e-6 # 1 us integration step
t = np.arange(0, 8e-3, dt)
x = np.where(t < 2e-3, 5.0, 0.0) # 5 V, 2 ms pulse
h = np.exp(-t / tau) / tau # impulse response in 1/s
y_conv = np.convolve(x, h)[:len(t)] * dt # the integral as a Riemann sum
sys = signal.lti([1.0], [tau, 1.0]) # H(s) = 1/(s tau + 1)
_, y_lsim, _ = signal.lsim(sys, x, t)
def exact(tt):
return 5 * (1 - np.exp(-tt / tau)) - np.where(tt >= 2e-3, 5 * (1 - np.exp(-(tt - 2e-3) / tau)), 0.0)
for tm in (1e-3, 2e-3, 3e-3, 6e-3):
i = int(round(tm / dt))
print(f"t = {1e3 * tm:.0f} ms: exact {exact(tm):.4f} V, convolution {y_conv[i]:.4f} V, lsim {y_lsim[i]:.4f} V")
print(f"area of h: {np.sum(h) * dt:.4f} (DC gain)")t = 1 ms: exact 3.1606 V, convolution 3.1640 V, lsim 3.1606 V
t = 2 ms: exact 4.3233 V, convolution 4.3212 V, lsim 4.3208 V
t = 3 ms: exact 1.5905 V, convolution 1.5897 V, lsim 1.5895 V
t = 6 ms: exact 0.0792 V, convolution 0.0791 V, lsim 0.0791 V
area of h: 1.0002 (DC gain)
Both numerical answers agree with the formula to a few millivolts. The Riemann sum carries the left-sum bias of Signal Classes (of order near the edges); lsim solves the state equation exactly but assumes the input is linear between samples, so it sees the falling edge as a ramp and ends low after it. Halve dt and both errors halve.
Simulation. The same circuit in the netlist lab, with the pulse source and the cursor at : about at the end of the pulse and at (the source's edges and the solver's time step shift the third digit). Drag to see the peak fall as grows beyond the pulse width.
Step response to impulse response, and second-order ringing
A MEMS accelerometer behaves like a second-order low-pass with and . Its step response overshoots by and rings at . Below, the impulse response is recovered from a "measured" step response by differentiation:
import numpy as np
from scipy import signal
fn, zeta = 100.0, 0.2
wn = 2 * np.pi * fn
sys = signal.lti([wn**2], [1, 2 * zeta * wn, wn**2])
t = np.linspace(0, 0.05, 5001) # 10 us steps
_, s = sys.step(T=t)
_, h = sys.impulse(T=t)
h_from_s = np.gradient(s, t) # differentiate the step response
print(f"overshoot {100 * (s.max() - 1):.1f} % at t = {1e3 * t[np.argmax(s)]:.2f} ms (theory {100 * np.exp(-np.pi * zeta / np.sqrt(1 - zeta**2)):.1f} % at {1e3 / (2 * fn * np.sqrt(1 - zeta**2)):.2f} ms)")
print(f"max |h - ds/dt| = {np.max(np.abs(h - h_from_s)):.2f} 1/s out of peak h = {h.max():.1f} 1/s")
print(f"area of h = {np.trapezoid(h, t):.4f} (DC gain 1)")overshoot 52.7 % at t = 5.10 ms (theory 52.7 % at 5.10 ms)
max |h - ds/dt| = 1.97 1/s out of peak h = 475.1 1/s
area of h = 0.9987 (DC gain 1)
The difference between the true and is about of its peak with a clean step (the central difference is second-order accurate; it is largest where curves most). The area falls short of 1 because the record stops at , while the ringing envelope still has left. On real data the derivative amplifies noise, so smooth the step response or average many steps before differentiating.
Guided lab: identify an RC filter from its step response
Hand calculation. , : ; a step reaches () at ; a pulse peaks at .
Simulation. The netlist lab above; and the lsim program with the pulse width changed to (peak , nearly times : the short-pulse approximation).
What you would measure. Drive the RC from a function generator (square wave, to , so each half period is ), scope on the capacitor. Read the time to : expect within the tolerances of the parts (typically to for the capacitor, so to ). Then switch to a pulse of and compare the peak with . A generator output adds to , i.e. to ; a probe adds about to , negligible here.
Hazards and safe setup. Generator and battery or USB-powered equipment only, signals; use a non-polarised (film or ceramic) capacitor, since the square wave may swing negative if the offset is wrong.
Pitfalls
- Forgetting the factor when approximating the convolution integral with
np.convolve: the result is off by the sampling rate. - Treating the peak of a filtered pulse as the pulse amplitude: a pulse shorter than about never reaches it.
- Differentiating a noisy measured step response without smoothing.
- Mixing up the impulse response's units ( for a voltage-to-voltage system) with the step response's (dimensionless).
Practice
- What is the response of an RC low-pass () to a step, at ?
- A system's step response is . What is ?
- A pulse of drives a system with . Estimate the peak output.
Answer
- .
- with , for .
- The pulse is short compared with , so ; the peak is (exactly ).
Test yourself
The impulse response of an RC low-pass with time constant is
How can you obtain from a bench measurement?
- integrate the step response
- differentiate the step response
- square the step response
- it cannot be measured
A 5 V pulse lasting drives an RC low-pass. The output peaks at
- 5 V
- 4.32 V
- 3.16 V
- 2.5 V
Approximating with np.convolve(x, h) needs
- nothing else
- a factor
- a factor
- flipping first