---
title: Designing IIR filters
heading: Borrowing analog designs through the bilinear transform
eyebrow: C9 · Lesson 42 · Designing IIR filters
xp: 40
---

::: hook
Decades of analog filter design, Butterworth, Chebyshev and elliptic tables, describe filters by poles and zeros in the s-plane. A digital filter needs them in the z-plane. The bilinear transform carries a whole analog design across in one substitution, keeps it stable, and keeps the shape of its response; its one quirk is that it squeezes the analog frequency axis to fit inside half the sample rate. A sixth-order IIR filter built this way can do the job of an FIR filter several times longer.
:::

::: play
- The dashed curve is an analog first-order low-pass with corner $f_c$; the solid one is its bilinear-transform copy at sample rate $f_s$, designed with prewarping so the corners match.
- Both are 0.707 (−3 dB) at $f_c$. Toward $f_s/2$ the digital one falls to zero, where the analog one is still well above it: the whole analog axis, up to infinity, has been squeezed into 0 to $f_s/2$.
- Raise $f_c$ toward $f_s/2$: the difference grows. For corners well below $f_s/2$ the two are nearly the same.
:::

```sim plot
view: graph
x: f = 0..24 kHz
y: G = 0..1.05
slider: fc = 0.5..10 step 0.5 = 4 kHz
slider: fs = 16..48 step 4 = 48 kHz
plot: 1/sqrt(1 + (f/fc)^2) | dashed | label: analog
plot: step(fs/2 - f)/sqrt(1 + (tan(pi*f/fs)/tan(pi*fc/fs))^2) | label: bilinear, prewarped
readout: prewarped analog corner, kHz = fs/pi*tan(pi*fc/fs) | digits: 4
```

::: predict
## An analog low-pass with its corner at 3 kHz is carried to an 8 kHz digital filter by the bilinear transform with no prewarping. Where does the digital corner end up?

- [ ] At 3 kHz
- [x] Lower, near 2.2 kHz
- [ ] Higher, near 3.8 kHz
- [ ] At 4 kHz

::: reveal
Near 2.2 kHz. The transform maps analog frequency Ω to digital frequency $\omega = 2\arctan(\Omega T/2)$, which bends high frequencies down toward the Nyquist frequency. $2\arctan(\pi \times 3000/8000) = 1.734$ rad, which is 2.21 kHz. Prewarping fixes it: design the analog filter for $\frac{f_s}{\pi}\tan(\pi f_c/f_s)$ instead of $f_c$.
:::
:::

::: nameit
## The bilinear transform

Replace every s in an analog H(s) with

$$s = \frac{2}{T}\cdot\frac{z - 1}{z + 1} = \frac{2}{T}\cdot\frac{1 - z^{-1}}{1 + z^{-1}}$$

It maps the left half of the s-plane inside the unit circle, so a stable analog filter gives a stable digital one, and it maps the whole jΩ axis onto the unit circle once. A filter of order N stays order N.

## Frequency warping

On the unit circle, analog and digital frequencies are related by

$$\Omega = \frac{2}{T}\tan\frac{\omega}{2}$$

Low frequencies map almost linearly; near the Nyquist frequency the axis is crushed. So design the analog prototype at **prewarped** edges, $\Omega = \frac{2}{T}\tan(\pi f/f_s)$, and those edges land exactly where they should.

## A first-order low-pass

With $\Omega_c = \tan(\pi f_c/f_s)$ (taking T = 2, which cancels out):

$$H(z) = \frac{b(1 + z^{-1})}{1 + az^{-1}}, \qquad b = \frac{\Omega_c}{1 + \Omega_c}, \quad a = \frac{\Omega_c - 1}{1 + \Omega_c}$$

The zero at z = −1 puts a perfect null at $f_s/2$.

## Butterworth order

To pass to $\omega_p$ within $A_p$ dB and stop beyond $\omega_s$ by at least $A_s$ dB, prewarp both edges and use

$$N \ge \frac{\log_{10}\!\left[(10^{A_s/10} - 1)/(10^{A_p/10} - 1)\right]}{2\log_{10}(\Omega_s/\Omega_p)}$$

## IIR or FIR

IIR filters reach a given sharpness with far fewer coefficients, but their phase isn't linear, they need care with coefficient precision, and feedback can make them unstable if poles drift outside the unit circle. FIR filters cost more but have exact linear phase and are always stable. **Impulse invariance**, sampling the analog impulse response, is the other classic method; it keeps the time response but aliases the frequency response, so it suits only low-pass designs well below Nyquist.
:::

::: example
## Design a first-order low-pass with its −3 dB point at 1 kHz for an 8 kHz system.

::: solution
1. **Prewarp the corner.**
   $$\begin{aligned} \Omega_c &= \tan(\pi/8) \\ &= 0.4142 \end{aligned}$$
2. **Coefficients.**
   $$\begin{aligned} b &= 0.4142/1.4142 \\ &= 0.2929 \\ a &= -0.5858/1.4142 \\ &= -0.4142 \end{aligned}$$
3. **The filter.**
   $$\begin{aligned} y[n] &= 0.4142\,y[n-1] \\ &\quad + 0.2929(x[n] + x[n-1]) \end{aligned}$$
4. **Check.** Its DC gain is 2(0.2929)/(1 − 0.4142) = 1, its gain at 1 kHz is exactly $1/\sqrt2$, and at 4 kHz it's 0.

**Answer:** $y[n] = 0.4142\,y[n-1] + 0.2929(x[n] + x[n-1])$.
:::
:::

::: example
## What Butterworth order meets: within 1 dB to 1 kHz, at least 40 dB down from 2 kHz, at 8 kHz?

::: solution
1. **Prewarp both edges.**
   $$\begin{aligned} \Omega_p &= \tan(\pi/8) \\ &= 0.4142 \\ \Omega_s &= \tan(\pi/4) \\ &= 1 \end{aligned}$$
   a ratio of 2.414.
2. **Order.**
   $$\begin{aligned} N &\ge \frac{\log_{10}(9999/0.2589)}{2\log_{10}2.414} \\ &= 4.587/0.766 \\ &= 5.99 \end{aligned}$$
3. **Round up.** Order 6: three second-order sections, about 15 coefficients.
4. **Compare an FIR.** A Kaiser FIR filter for the same edges and 40 dB needs about 19 taps, and it gets linear phase for the extra cost.

**Answer:** order 6, built as three second-order sections.
:::
:::

::: example
## Without prewarping, where does an analog corner at 3 kHz land in an 8 kHz design?

::: solution
1. **Map the corner.**
   $$\begin{aligned} \omega &= 2\arctan(\Omega T/2) \\ &= 2\arctan(\pi \times 3000/8000) \\ &= 2\arctan(1.178) \\ &= 1.734\ \text{rad} \end{aligned}$$
2. **In hertz.**
   $$1.734 \times 8000/2\pi = 2208\ \text{Hz}$$
   The filter would cut off 26% lower than designed.
3. **Prewarp.** Prewarping the analog corner to
   $$(8000/\pi)\tan(3\pi/8) = 6148\ \text{Hz}$$
   puts the digital corner back at exactly 3 kHz.

**Answer:** at 2208 Hz, 26% lower than designed.
:::
:::

::: check
kind: parts
given: fc = 1 | 2 | 3.5; fs = 8 | 12 | 16

## A digital filter at {fs} kHz should have its corner at {fc} kHz.

::: part
answer: fs/pi*tan(pi*fc/fs)
unit: kHz
tolerance: 0.5%

### At what corner should the analog prototype be designed?

::: misses
- [fc] Prewarp: the bilinear transform bends the axis.
- [any] $\frac{f_s}{\pi}\tan(\pi f_c/f_s)$.
:::
:::

::: part
answer: fs/pi*tan(pi*fc/fs)/fc
tolerance: 0.5%

### How many times higher is that than {fc} kHz?

::: misses
- [any] The ratio of the two.
:::
:::
:::

::: check
kind: parts
given: fc = 0.5 | 1 | 2; fs = 8 | 10

## A first-order bilinear low-pass has its corner at {fc} kHz, at {fs} kHz.

::: part
answer: tan(pi*fc/fs)/(1 + tan(pi*fc/fs))
tolerance: 0.5%

### What is b, the numerator coefficient?

::: misses
- [any] $\Omega_c/(1 + \Omega_c)$ with $\Omega_c = \tan(\pi f_c/f_s)$.
:::
:::

::: part
answer: (tan(pi*fc/fs) - 1)/(1 + tan(pi*fc/fs))
tolerance: 0.5%

### What is a, the denominator coefficient?

::: misses
- [any] $(\Omega_c - 1)/(1 + \Omega_c)$.
:::
:::
:::

::: check
kind: parts
given: fa = 1 | 3 | 6; fs = 8 | 16

## An analog corner of {fa} kHz is carried to a {fs} kHz design without prewarping.

::: part
answer: fs/pi*asin((pi*fa/fs)/sqrt(1 + (pi*fa/fs)^2))
unit: kHz
tolerance: 0.5%

### Where does the digital corner land?

::: misses
- [any] $\frac{f_s}{\pi}\arctan(\pi f_a/f_s)$.
:::
:::

::: part
answer: (fs/pi*asin((pi*fa/fs)/sqrt(1 + (pi*fa/fs)^2)) - fa)/fa*100
unit: %
tolerance: 0.5%

### By what percentage is it off?

::: misses
- [any] (landed − intended) ÷ intended.
:::
:::
:::

::: check
kind: parts
given: As = 40 | 60; Ap = 0.5 | 1 | 3; r = 1.5 | 2 | 3

## A Butterworth design needs {As} dB of stopband loss, at most {Ap} dB of passband loss, and the prewarped stopband edge is {r} times the passband edge.

::: part
answer: log((10^(As/10) - 1)/(10^(Ap/10) - 1))/(2*log(r))
tolerance: 0.5%

### What does the order formula give, before rounding?

::: misses
- [any] $\log_{10}[(10^{A_s/10} - 1)/(10^{A_p/10} - 1)]/(2\log_{10} r)$.
:::
:::

::: part
answer: ceil(log((10^(As/10) - 1)/(10^(Ap/10) - 1))/(2*log(r)))
tolerance: 0

### What order is needed?

::: misses
- [any] Round up.
:::
:::
:::

::: check
kind: derivation
vars: w = 0..3.1, T = 0.00001..0.01

## Put $z = e^{j\omega}$ into $s = \frac{2}{T}\cdot\frac{1 - z^{-1}}{1 + z^{-1}}$.

::: step
answer: 2/T*tan(w/2)

### What analog frequency Ω does s = jΩ give? (Its imaginary part.)
:::

::: step
answer: 2/T*tan(w/2)*T/2

### What is ΩT/2?
:::

::: right
Right. $\Omega = \frac{2}{T}\tan(\omega/2)$: the unit circle covers the whole jΩ axis once.
:::
:::

::: check
kind: choice

## A filter for audio must not change the shape of transients, so every frequency must be delayed equally. Which design fits?

- [ ] A Butterworth IIR filter by the bilinear transform
- [x] A symmetric FIR filter
- [ ] An elliptic IIR filter, since it's the sharpest
- [ ] Any filter with a flat passband

::: misses
- [1] Its phase isn't linear, so different frequencies are delayed differently.
- [3] Sharpest, but with the least linear phase near the edge.
- [4] Flat magnitude doesn't mean equal delay.
:::
:::

::: explain
## Why does the bilinear transform never alias, while impulse invariance does?

::: model
Impulse invariance samples the analog impulse response, and sampling makes the frequency response periodic: the analog response repeats around multiples of the sample rate and the copies overlap wherever it isn't already near zero at half the sample rate. The bilinear transform doesn't sample anything. It's an algebraic substitution that maps the entire analog frequency axis, from zero to infinity, onto the unit circle exactly once, so no two analog frequencies land on the same digital one and nothing can overlap. The price is the nonlinear squeeze of the frequency axis, which prewarping compensates at the frequencies that matter.
:::
:::

::: practice
::: check
given: fc = 1 | 5; fs = 20 | 48
answer: fs/pi*tan(pi*fc/fs)
unit: kHz
tolerance: 0.5%

## Prewarped analog corner for {fc} kHz at {fs} kHz?

::: misses
- [any] $\frac{f_s}{\pi}\tan(\pi f_c/f_s)$.
:::
:::

::: check
given: fc = 1 | 3; fs = 8 | 12
answer: (tan(pi*fc/fs) - 1)/(1 + tan(pi*fc/fs))
tolerance: 0.5%

## Denominator coefficient of a first-order bilinear low-pass at {fc} kHz, {fs} kHz?

::: misses
- [any] $(\Omega_c - 1)/(1 + \Omega_c)$.
:::
:::

::: check
given: As = 30 | 50; r = 2 | 4
answer: ceil(log((10^(As/10) - 1)/(10^(0.1) - 1))/(2*log(r)))
tolerance: 0

## Butterworth order for {As} dB at {r} times the passband edge, 1 dB ripple?

::: misses
- [any] The order formula, rounded up.
:::
:::
:::
