D55 of 13
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

D5 · Lesson 5 · IIR filters

Filters that feed their own output back, the one-pole smoother with its exponential memory, time constant and corner frequency, why a few feedback coefficients do the work of hundreds of FIR taps, the biquad section, designing from analog prototypes with the bilinear transform, and the stability and phase costs

An FIR filter remembers only its last N inputs. Let a filter also remember its own past outputs and it can remember forever: an impulse sets off a response that decays but never quite ends, so it's called infinite impulse response. The simplest one, "new output = 0.9 × old output + 0.1 × new input", is a digital RC low-pass in one line of code, and it's in every sensor-smoothing routine ever written. Feedback makes IIR filters extraordinarily efficient, but it also brings the analog world's problems back: phase distortion and the possibility of instability.

  • The frequency response of the one-pole smoother yn=ayn−1+(1−a)xn at a sampling rate of 1 kHz: H(f)=1−a1−ae−j2πf/fs.
  • As a approaches 1 the filter remembers longer and its corner moves down. Its DC gain is always 1.
  • It behaves like an RC low-pass with a time constant of −1/ln⁡a samples, until the response flattens near the Nyquist frequency.

Predict

A sensor reading is smoothed by yn=0.9yn−1+0.1xn at 1000 samples per second. After a sudden step in the reading, about how long does the output take to cover 63% of the step?

Name it

The IIR filter

yn=∑k=0Mbkxn−k−∑k=1Nakyn−k,H(z)=∑bkz−k1+∑akz−k

The feedback terms give the transfer function poles (lesson 6). A filter is stable only if every pole lies inside the unit circle; quantizing the coefficients can push a pole outside.

The one-pole smoother

yn=ayn−1+(1−a)xn has DC gain 1, a time constant of −1/ln⁡a samples, and a −3 dB frequency where

cos⁡2πffs=1−(1−a)22a

To get a time constant of τ samples, use a=e−1/τ.

Efficiency

A fourth-order IIR elliptic filter can match the sharpness of a 100-tap FIR filter with about 10 multiplications per sample. In practice, high-order IIR filters are built as cascades of second-order biquad sections, each b0+b1z−1+b2z−2 over 1+a1z−1+a2z−2, because one big high-order polynomial is too sensitive to coefficient rounding.

Designing from analog prototypes

Butterworth, Chebyshev and elliptic designs (C4) carry over through the bilinear transform s=2T1−z−11+z−1, which maps the whole analog frequency axis onto the digital one up to the Nyquist frequency. That squeezes frequencies, so the analog prototype is designed at the prewarped frequency

fa=fsπtan⁡πfdfs

for each critical digital frequency fd.

The cost

IIR filters can't have exactly linear phase, so they distort waveform shapes, and their feedback makes them sensitive to rounding (lesson 12).

Worked example

For a = 0.9 at 1 kHz, where's the −3 dB point? What a gives a 100-sample time constant?

Show the solution
  1. Cosine of the corner. Put a=0.9 in cos⁡ω=1−(1−a)2/(2a): cos⁡ω=1−0.011.8=0.99444
  2. Corner angle. ω=0.1055rad/sample
  3. Corner in hertz. f=0.1055×10002πHz=16.8Hz
  4. Pole for τ = 100 samples. a=e−1/τ=e−0.01=0.99005

Answer the −3 dB point is at 16.8 Hz, and a = 0.99005 gives a 100-sample time constant.

Worked example

A digital low-pass at 8 kHz needs its corner at 1 kHz. At what frequency should the analog prototype be designed?

Show the solution
  1. Prewarp the corner. fa=8000πtan⁡π8=2546.5×0.4142=1054.8Hz
  2. Check. The bilinear transform's squeeze then lands the corner exactly at 1 kHz.

Answer design the analog prototype with its corner at 1054.8 Hz.

Worked example

A one-pole smoother at 1 kHz should have a 10 ms time constant. What pole a does it need?

Show the solution
  1. Pole. Each sample should keep this fraction of the previous output: a=e−T/τ=e−1/10=0.905
  2. Difference equation. The input gets the rest, 0.095: yn=0.905yn−1+0.095xn
  3. Analog equivalent. It's the digital equivalent of an RC filter with RC = 10 ms.

Answer a = 0.905, so yn=0.905yn−1+0.095xn.

Check

A one-pole smoother with a = 0.9 runs at 1 kHz. What's its time constant?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

Check

What coefficient a gives a one-pole smoother a time constant of 5 samples?

Check

Where is the −3 dB point of a one-pole smoother with a = 0.9 at 1 kHz?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

A digital filter at 32 kHz needs a critical frequency of 6 kHz. At what frequency should its analog prototype be designed for the bilinear transform?

Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.

Check

A one-pole smoother at 1 kHz should have a 10 ms time constant.

(a)

What pole a?

(b)

What input weight 1−a?

Check

A bilinear-transform low-pass at 8 kHz needs a digital corner at 1 kHz.

(a)

Where should the analog prototype's corner be (prewarped)?

Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.

(b)

How far above the target is that, in percent?

Explain why

How can a few feedback coefficients replace hundreds of FIR taps?

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.