ENع
←IIR filters
Lesson 42 · Digital filter design

IIR filters and feedback

16 min10 steps5 questionsAdvanced
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.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 42 · Interactive
01 / 10

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 alive
Loading figure…
or ← →
Read the lesson step by step
  1. 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 alive
  2. n = 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)
  3. 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 = 1
  4. n = 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 swing
  5. It 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)
  6. 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)
  7. 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 peak
  8. Too 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 stable
  9. What 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 loop
  10. In 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

Quiz Unlocks after the last step.