Impulse Response
The impulse response is the fingerprint of an LTI system. Its length says how long the system remembers, its sign pattern whether it smooths or sharpens, and two simple tests on it decide causality and stability. This lesson reads those properties off and measures an impulse response from input-output data.
Causality and stability
- Causal: the output never depends on future inputs. For an LTI system this means for . Real-time systems must be causal; offline processing (editing a recording) need not be.
- BIBO stable: every bounded input gives a bounded output. For an LTI system this holds exactly when .
import numpy as np
n = np.arange(0, 2000)
candidates = {
"h = 0.9^n u[n]": 0.9 ** n,
"h = 1.01^n u[n]": 1.01 ** n,
"h = u[n] (summer)": np.ones_like(n, dtype=float),
"h = 1/(n+1) u[n]": 1 / (n + 1.0),
"h = 1/(n+1)^2 u[n]": 1 / (n + 1.0) ** 2,
}
for name, h in candidates.items():
partial = [np.sum(np.abs(h[:m])) for m in (100, 1000, 2000)]
print(f"{name:20s} sum|h| over 100, 1000, 2000 terms: {[f'{p:.4g}' for p in partial]}")h = 0.9^n u[n] sum|h| over 100, 1000, 2000 terms: ['10', '10', '10']
h = 1.01^n u[n] sum|h| over 100, 1000, 2000 terms: ['170.5', '2.096e+06', '4.393e+10']
h = u[n] (summer) sum|h| over 100, 1000, 2000 terms: ['100', '1000', '2000']
h = 1/(n+1) u[n] sum|h| over 100, 1000, 2000 terms: ['5.187', '7.485', '8.178']
h = 1/(n+1)^2 u[n] sum|h| over 100, 1000, 2000 terms: ['1.635', '1.644', '1.644']
Only and have converging sums: those systems are stable. The accumulator is unstable (a constant input makes its output grow forever), and so is , whose sum grows like .
FIR and IIR
- FIR (finite impulse response): has finitely many nonzero values. Always stable. Moving averages and most audio equalizer designs in software.
- IIR (infinite impulse response): goes on forever, typically from feedback, as in , whose . Stable when (IIR Filters and Feedback).
Step response
The response to a unit step is the running sum of , . It shows how quickly a system settles after "switching on", which is how control engineers specify systems (rise time, overshoot, settling time).
import numpy as np
a = 0.8
n = np.arange(15)
h = (1 - a) * a ** n # a normalized one-pole smoother, sum of h = 1
step = np.cumsum(h)
print("h: ", np.round(h, 3).tolist())
print("step:", np.round(step, 3).tolist())
print("samples to reach 90 %:", int(np.argmax(step >= 0.9)) + 1)h: [0.2, 0.16, 0.128, 0.102, 0.082, 0.066, 0.052, 0.042, 0.034, 0.027, 0.021, 0.017, 0.014, 0.011, 0.009]
step: [0.2, 0.36, 0.488, 0.59, 0.672, 0.738, 0.79, 0.832, 0.866, 0.893, 0.914, 0.931, 0.945, 0.956, 0.965]
samples to reach 90 %: 11
Measuring an impulse response
You cannot always apply a perfect impulse, but with a known noise-like input and the recorded output you can solve for : cross-correlating the output with white noise input returns scaled by the input power. This is how room and loudspeaker responses are measured.
import numpy as np
rng = np.random.default_rng(7)
h_true = np.array([0.0, 1.0, 0.6, 0.0, -0.3, 0.1])
x = rng.normal(size=20000) # white noise test signal
y = np.convolve(x, h_true)[:x.size] + 0.05 * rng.normal(size=x.size) # measured with noise
h_est = np.array([np.dot(y[k:], x[:x.size - k]) for k in range(8)]) / np.dot(x, x)
print("true h: ", h_true.tolist() + [0.0, 0.0])
print("estimated h:", (np.round(h_est, 2) + 0.0).tolist())true h: [0.0, 1.0, 0.6, 0.0, -0.3, 0.1, 0.0, 0.0]
estimated h: [0.0, 1.0, 0.59, 0.01, -0.29, 0.12, 0.0, -0.01]
In software
- Convolution reverbs in audio software store measured impulse responses of concert halls and apply them by (fast) convolution.
scipy.signal.impulseanddimpulsecompute impulse responses of continuous and discrete models.
Exercises
Exercise 1: Causal or not?
Is causal?
Answer
No.
Solution
: the output needs the next input sample.
Exercise 2: Stability
For which is stable?
Answer
.
Solution
is a geometric series, finite exactly when , with sum .
Exercise 3: Settling time (code)
For the smoother with , how many samples does the step response need to reach 90 %?
Answer
45 samples.
Solution
The step response is , which reaches 0.9 when , that is .
import numpy as np
a = 0.95
step = np.cumsum((1 - a) * a ** np.arange(200))
print(int(np.argmax(step >= 0.9)) + 1)45
Test yourself
An LTI system is causal when…
- for
- is finite
An LTI system is BIBO stable when…
- is causal
- is periodic
Which filter type is always stable?
- IIR
- FIR
- any filter with feedback
- the accumulator