IIR filters and feedback
About this lesson
An IIR filter feeds its own past outputs back in. That feedback lets a few multiplies do the work of a long FIR filter. Follow one impulse round the loop of y[n] = x[n] + 0.9·y[n−1] − 0.81·y[n−2]: the output rings 1, 0.9, 0, −0.729, −0.6561, 0 … every 6 samples. You will see how the feedback weights set the poles, why the gain peaks at 6.08 near a sixth of the sample rate, how too much feedback makes the filter unstable, and what the filter costs in phase. It builds on the lessons "Difference equations", "Poles, zeros and the shape of the response", "Stability and the unit circle" and "Linear phase and group delay", and on the Circuits lessons on filters and Bode plots.
A filter that feeds itself
An IIR filter feeds its own past outputs back in. Ours: y[n] = x[n] + 0.9·y[n−1] − 0.81·y[n−2]. Two delay boxes remember the last two outputs; two multipliers weight them; the adder sums everything.
y[n] = x[n] + 0.9·y[n−1] − 0.81·y[n−2]
x[n] the input, sample n
y[n−1] the output one sample ago (delay 1)
y[n−2] the output two samples ago (delay 2)
per sample: 2 multiplies, 2 adds,
2 stored numbers
IIR = infinite impulse response:
the feedback keeps old outputs aliveRead the lesson step by step
A filter that feeds itself
An IIR filter feeds its own past outputs back in. Ours: y[n] = x[n] + 0.9·y[n−1] − 0.81·y[n−2]. Two delay boxes remember the last two outputs; two multipliers weight them; the adder sums everything.
y[n] = x[n] + 0.9·y[n−1] − 0.81·y[n−2] x[n] the input, sample n y[n−1] the output one sample ago (delay 1) y[n−2] the output two samples ago (delay 2) per sample: 2 multiplies, 2 adds, 2 stored numbers IIR = infinite impulse response: the feedback keeps old outputs aliven = 0: one kick
Feed in an impulse: a single 1, then zeros. Both delays start at 0 (initial rest), so the feedback adds nothing yet. y[0] = 1 + 0 − 0 = 1. Then the delays shift: delay 1 now holds 1.
n = 0 x[0] = 1 0.9·y[−1] = 0.9 × 0 = 0 −0.81·y[−2] = −0.81 × 0 = 0 y[0] = 1 after the tick the delays shift: delay 2 <- delay 1 (0) delay 1 <- y[0] (1)n = 1: the input is gone
Now x[1] = 0, but delay 1 returns y[0] = 1, and 0.9 × 1 = 0.9. Delay 2 still holds 0. So y[1] = 0 + 0.9 − 0 = 0.9. No input, yet output: the feedback carries it.
n = 1 x[1] = 0 0.9·y[0] = 0.9 × 1 = 0.9 −0.81·y[−1] = −0.81 × 0 = 0 y[1] = 0.9 delays now: delay 1 = 0.9, delay 2 = 1n = 2: two paths cancel
Delay 1 gives 0.9 and delay 2 gives the old 1. y[2] = 0.9 × 0.9 − 0.81 × 1 = 0.81 − 0.81 = 0. The push from one path and the pull from the other cancel exactly.
n = 2 0.9·y[1] = 0.9 × 0.9 = 0.81 −0.81·y[0] = −0.81 × 1 = −0.81 y[2] = 0.81 − 0.81 = 0 the −0.81 path pulls the output back down: that is what makes it swingIt rings
Keep ticking: −0.729, −0.6561, 0, then 0.5314, 0.4783, 0. The output swings down and up again every 6 samples, and the swing shrinks by a factor of 0.9 every sample. It never quite stops.
n y[n] 0 1 1 0.9 2 0 3 −0.729 4 −0.6561 5 0 6 0.5314 7 0.4783 8 0 closed form: h[n] = 0.9ⁿ · sin((n+1)·60°) / sin 60° (period 6, shrinking ×0.9 per sample)Poles: where the ring comes from
The feedback weights fix the poles. H(z) = 1 / (1 − 0.9z⁻¹ + 0.81z⁻²), and the bottom is zero at z = 0.9·e^(±jπ/3). Radius 0.9 is the shrink per sample; angle π/3 (60°) gives one swing every 6 samples.
H(z) = 1 / (1 − 0.9·z⁻¹ + 0.81·z⁻²) poles p = R·e^(±jθ), R = 0.9, θ = π/3 0.9 = 2·R·cos θ = 2 × 0.9 × 0.5 0.81 = R² R -> h[n] shrinks ×0.9 per sample θ -> 2π/θ = 6 samples per swing zeros: two at z = 0 numpy: np.roots([1, -0.9, 0.81]) -> 0.45 ± 0.7794j (|p| = 0.9)A peak from two multiplies
A filter that rings at a frequency passes that frequency best. The gain peaks at 6.08 near ω = π/3, a sixth of the sample rate. It is only 1.1 at ω = 0 and 0.37 at ω = π.
|H(e^jω)| = 1 / |1 − 0.9e^(−jω) + 0.81e^(−2jω)| ω = 0 1.1 ω ≈ 0.332π 6.08 (peak, 15.7 dB) ω = π 0.37 half-power width ≈ −2·ln R = 0.211 rad per sample poles nearer the circle: taller, narrower peakToo much feedback: unstable
Push the poles out to radius 1.05: weights 1.05 and −1.1025. Now the response grows 1.05 times every sample: 1, 1.05, 0, −1.158, −1.216 … and it grows forever. Poles outside the unit circle make a feedback filter unstable.
y[n] = x[n] + 1.05·y[n−1] − 1.1025·y[n−2] poles 1.05·e^(±jπ/3) h[n]: 1, 1.05, 0, −1.158, −1.216 … grows ×1.05 per sample stable <=> every pole has |p| < 1 R = 1 exactly: rings forever an FIR filter has no feedback, so it is always stableWhat an FIR would cost
An FIR copy of this response needs 44 taps before every dropped sample is under 1% of the first. The IIR does it with 2 multiplies and 2 stored numbers. The price: its delay depends on frequency, so its phase is not linear.
FIR copy of h[n], cut where |h| < 0.01: 44 taps -> 44 multiplies per sample IIR: 2 multiplies, 2 stored outputs group delay (samples): ω = 0 −0.79 ω ≈ 0.332π 8.5 not constant -> phase not linear risks: poles near |z| = 1 are touchy, and rounding errors go round the loopIn Python: lfilter
In Python 3 with scipy, lfilter(b, a, x) runs this loop. a = [1, −0.9, 0.81] holds the feedback weights with their signs flipped, because scipy writes every y term on the left. It prints 1, 0.9, 0, −0.729, −0.6561, 0.
from scipy import signal b, a = [1], [1, -0.9, 0.81] x = [1, 0, 0, 0, 0, 0] y = signal.lfilter(b, a, x) print(y.round(4)) prints (scipy 1.13, numpy 2.0): [ 1. 0.9 -0. -0.729 -0.6561 -0. ] lfilter runs a[0]·y[n] = b[0]·x[n] − a[1]·y[n−1] − a[2]·y[n−2] y[n] = x[n] + 0.9·y[n−1] − 0.81·y[n−2] "-0." is a rounding remnant (about 1e-17) w, H = signal.freqz(b, a) -> the gain curve
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01A filter runs y[n] = x[n] + 0.5·y[n−1] − 0.25·y[n−2] from rest. The input is an impulse (1, then zeros). What is y[2]?
y[0] = 1 and y[1] = 0.5 × 1 = 0.5. Then y[2] = 0.5 × 0.5 − 0.25 × 1 = 0.25 − 0.25 = 0. These weights put the poles at radius 0.5 and angle 60°, the same angle as the lesson's filter.
02A two-pole filter has its poles at radius R and angle ±θ. Which choice makes it unstable?
The impulse response grows like Rⁿ. Every R below 1 shrinks it, even 0.99, which only rings for a long time. R = 1.05 makes the response 5% bigger every sample (each 6-sample swing is about 1.34 times the last), so the output grows without limit.
03The poles sit at angle θ = π/4. About how many samples does one swing of the ringing take?
One full swing takes 2π/θ samples. With θ = π/4 that is 8 samples. The lesson's filter has θ = π/3, so its ring repeats every 6 samples.
04Why might you choose an IIR filter over an FIR filter?
The lesson's IIR filter needs 2 multiplies per sample; an FIR copy of its response needs 44 taps. The price is phase that is not linear and feedback that can go unstable. FIR filters are always stable and can have exactly linear phase.
05You want y[n] = x[n] + 1.2·y[n−1] − 0.5·y[n−2] with scipy.signal.lfilter(b, a, x). What is a?
lfilter runs a[0]·y[n] = b[0]·x[n] − a[1]·y[n−1] − a[2]·y[n−2]. Moving the y terms to the left flips their signs: y[n] − 1.2·y[n−1] + 0.5·y[n−2] = x[n], so a = [1, −1.2, 0.5].
Glossary
- FIR filter
- Finite impulse response filter: no feedback, just a weighted sum of recent inputs. Each weight is called a tap, so N taps cost N multiplies per sample.
- IIR filter
- Infinite impulse response filter: a filter with feedback, so one input sample keeps the output going forever (in exact maths).
- Feedback
- Sending past outputs back into the adder through delays, so each new output depends on earlier outputs.
- Delay (z⁻¹)
- A box that holds one sample for one tick. Two in a row give y[n−2].
- Pole
- A value of z where the bottom of H(z) is zero. For a feedback filter, the poles come from the feedback weights and set how the output rings and decays.
- Resonator
- A filter whose poles sit near the unit circle, so it rings and has a tall gain peak at one frequency.
- Unit circle
- The circle |z| = 1 in the z-plane. A causal filter is stable when every pole is inside it.
- Group delay
- How many samples a narrow band of frequencies is delayed by the filter: minus the slope of the phase. Constant group delay means linear phase.
Notes and sources
- The pole radius 0.9 and angle 60° are chosen so the feedback weights are short exact numbers (0.9 and 0.81) and the ring repeats every 6 samples. Every value in the figure is computed from this model and was checked against scipy 1.13.
- scipy.signal.lfilter and most books put every output term on the left: y[n] − 0.9·y[n−1] + 0.81·y[n−2] = x[n]. That is why a = [1, −0.9, 0.81] holds −0.9 for a feedback weight of +0.9.
- numpy prints "-0." for y[2] and y[5] because 0.9 × 0.9 is not exactly 0.81 in binary floating point; the leftover is about 1e-17. In fixed-point hardware such leftovers can circulate in the loop, a topic for the fixed-point lesson.
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing, 2nd ed., Prentice Hall 1999 (§5.3 frequency response of rational system functions, §6.3 basic structures for IIR systems, ch. 7 filter design; the text of MIT OCW 6.341)
- A. V. Oppenheim, A. S. Willsky, S. H. Nawab, Signals and Systems, 2nd ed., Pearson 1997 (ch. 10: the z-transform, poles and stability)
- MIT OpenCourseWare 6.341 Discrete-Time Signal Processing (A. V. Oppenheim, Fall 2005)
- MIT OpenCourseWare 6.003 Signals and Systems, Fall 2011, lecture notes (3: feedback, poles and fundamental modes; 9: frequency response)
- J. O. Smith III, Introduction to Digital Filters, CCRMA Stanford: the two-pole filter (a1 = −2R cos θ, a2 = R²)
- J. O. Smith III, Introduction to Digital Filters: resonator bandwidth in terms of pole radius
- SciPy documentation: scipy.signal.lfilter (the difference equation it runs and its sign convention)
- SciPy documentation: scipy.signal.freqz
- SciPy documentation: scipy.signal.group_delay
- Infinite impulse response (Wikipedia): lower order than FIR for the same specification, stability and phase
Quiz Unlocks after the last step.