ENع
←Bilinear transform
Lesson 44 · Digital filter design

IIR design with the bilinear transform

18 min11 steps5 questionsAdvanced
About this lesson

Turn a proven analog filter into a digital one. Replacing each integrator by the trapezoid rule gives the bilinear map s = (2/T)(z − 1)/(z + 1). It sends the jΩ axis once around the unit circle and keeps stable filters stable, but it squeezes frequency: ω = 2·atan(ΩT/2). Follow one design end to end: a 2nd-order Butterworth lowpass, cutoff 1000 Hz at fs = 8000 Hz. Prewarp the cutoff to 6627.4 rad/s, substitute, and get b = [0.0976, 0.1953, 0.0976], a = [1, −0.9428, 0.3333], exactly what scipy.signal.butter returns.

You'll learn to

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

Fig 44 · Interactive
01 / 11

The order: a digital lowpass

We want a digital lowpass filter: keep tones below 1000 Hz, cut those above, for audio sampled at 8000 Hz. Plan: borrow a proven analog design, a 2nd-order Butterworth, and translate it from s into z.

wanted   lowpass, cutoff fc = 1000 Hz (−3 dB)
sampled  fs = 8000 Hz, T = 1/fs = 125 µs

analog designs are solved and tabled:
  Butterworth order 2 (previous lesson)
  Ha(s) = Ωc² / (s² + √2·Ωc·s + Ωc²)

IIR = infinite impulse response:
  the output feeds back, like the analog
  filter's capacitors remember
Loading figure…
or ← →
Read the lesson step by step
  1. The order: a digital lowpass

    We want a digital lowpass filter: keep tones below 1000 Hz, cut those above, for audio sampled at 8000 Hz. Plan: borrow a proven analog design, a 2nd-order Butterworth, and translate it from s into z.

    wanted   lowpass, cutoff fc = 1000 Hz (−3 dB)
    sampled  fs = 8000 Hz, T = 1/fs = 125 µs
    
    analog designs are solved and tabled:
      Butterworth order 2 (previous lesson)
      Ha(s) = Ωc² / (s² + √2·Ωc·s + Ωc²)
    
    IIR = infinite impulse response:
      the output feeds back, like the analog
      filter's capacitors remember
  2. Integrate with trapezoids

    An analog filter is built from integrators, 1/s. With only samples, a computer integrates by adding trapezoids: each step adds T/2 × (x[n] + x[n−1]). Eight trapezoids give 0.628; the true area is 0.637.

    integrator:  y(t) = ∫ x dt     (transfer 1/s)
    
    trapezoid rule, one step of width T:
      y[n] = y[n−1] + (T/2)·(x[n] + x[n−1])
    
    example  x(t) = sin(π·t / 1 ms) volts
             T = 0.125 ms, 8 steps to 1 ms
      sum   = 0.628 V·ms
      exact = 2/π = 0.637 V·ms
  3. Trapezoids give the bilinear map

    Take the z-transform of the trapezoid rule: 1/s becomes (T/2)(1 + z⁻¹)/(1 − z⁻¹). Flip it: s = (2/T)(z − 1)/(z + 1). Put this in for every s in H(s) and the filter order stays 2.

    y[n] − y[n−1] = (T/2)(x[n] + x[n−1])
    Y(z)(1 − z⁻¹) = (T/2) X(z)(1 + z⁻¹)
    
    Y/X = (T/2)·(1 + z⁻¹)/(1 − z⁻¹)   ≈ 1/s
    
    so   s = (2/T)·(z − 1)/(z + 1)
           2/T = 2·fs = 16000 per second
    
    ratio of two first-order terms in z:
    "bilinear". A 2nd-order H(s) stays
    a 2nd-order H(z).
  4. The jΩ axis lands on the unit circle

    Solve for z: z = (1 + sT/2)/(1 − sT/2). For s = jΩ, top and bottom have the same size, so |z| = 1. The left half-plane lands inside the circle: a stable analog filter stays stable.

    z = (1 + sT/2) / (1 − sT/2)
    
    s = jΩ:  |1 + jΩT/2| = |1 − jΩT/2|
             so |z| = 1  (on the unit circle)
    
    s = σ + jΩ with σ < 0 (left half):
      |1 + sT/2| < |1 − sT/2|
      so |z| < 1  (inside)
    
    stable in s  ->  stable in z
    the dot climbs jΩ; its image goes round
  5. Frequency warping

    The whole infinite jΩ axis must fit once around the circle, so frequencies get squeezed: ω = 2·atan(ΩT/2). Low ones barely move; 10 kHz analog lands at 3365 Hz. Infinity lands at 4000 Hz, z = −1.

    on the circle z = e^(jω), and
      ω = 2·atan(ΩT/2)      (rad per sample)
      Ω = (2/T)·tan(ω/2)
    
    analog      digital
       100 Hz  ->   99.9 Hz
      1000 Hz  ->   952.9 Hz
      10000 Hz  ->  3365 Hz
         ∞     ->  4000 Hz  (z = −1)
    
    no aliasing: each Ω lands once
  6. Prewarp the cutoff

    Warping would pull a 1000 Hz analog cutoff down to 952.9 Hz. So aim high on purpose: Ωc = (2/T)·tan(ωc/2) = 16000·tan(π/8) = 6627.4 rad/s, that is 1054.8 Hz. The map warps it to exactly 1000 Hz.

    ωc = 2π·fc/fs = 2π·1000/8000 = π/4
    
    Ωc = (2/T)·tan(ωc/2)
       = 16000 × tan(π/8)
       = 16000 × 0.41421
       = 6627.4 rad/s   (1054.8 Hz)
    
    not prewarped: Ωc = 2π·1000 = 6283.2
      -> digital cutoff 952.9 Hz (too low)
  7. The analog prototype

    Butterworth order 2 with Ωc = 6627.4 rad/s: Ha(s) = Ωc²/(s² + √2·Ωc·s + Ωc²). Its poles sit on a circle of radius Ωc at ±135°: s = −4686 ± j4686 per second, both in the left half.

    Ha(s) = Ωc² / (s² + √2·Ωc·s + Ωc²)
    Ωc = 6627.4 rad/s
    
    poles: s = Ωc·e^(±j135°)
           = −4686 ± j4686  (1/s)
    
    |Ha| at Ωc = 1/√2  (−3 dB)
    flat pass band, no ripple
    (Butterworth: previous lesson)
  8. Substitute and collect

    Put s = (2/T)(z − 1)/(z + 1) into Ha(s) and tidy into powers of z⁻¹. With K = tan(π/8) = 0.41421, five numbers come out: b = 0.0976, 0.1953, 0.0976 and a1 = −0.9428, a2 = 0.3333.

    K = Ωc·T/2 = tan(π/8) = 0.41421
    D = 1 + √2·K + K² = 1.7574
    
    b0 = b2 = K²/D       = 0.0976
    b1      = 2K²/D      = 0.1953
    a1      = 2(K² − 1)/D = −0.9428
    a2      = (1 − √2K + K²)/D = 0.3333
    
    y[n] = 0.0976x[n] + 0.1953x[n−1] + 0.0976x[n−2]
           + 0.9428y[n−1] − 0.3333y[n−2]
  9. Poles and zeros move over

    Each analog pole maps by z = (1 + sT/2)/(1 − sT/2) to 0.4714 ± j0.3333, radius 0.5774: inside the circle, stable. The two zeros at s = ∞ land on z = −1, so the gain is exactly 0 at 4000 Hz.

    s = −4686 + j4686
    sT/2 = −0.2929 + j0.2929
    z = (0.7071 + j0.2929)/(1.2929 − j0.2929)
      = 0.4714 + j0.3333
    |z| = 0.5774 < 1   stable
    
    zeros: Ha(s) -> 0 as s -> ∞ (twice)
           ∞ maps to z = −1 (double zero)
    
    numerator (1 + z⁻¹)² = 1 + 2z⁻¹ + z⁻²
      -> b is K²/D × [1, 2, 1]
  10. Check the response

    Sweep the digital filter from 0 to 4000 Hz. At 1000 Hz the gain is 0.7071 (−3.01 dB), just as ordered. Near 4000 Hz it falls faster than the analog prototype, because warping squeezes its tail onto z = −1.

    |H(e^jω)| at 1000 Hz = 0.7071  (−3.01 dB)
    |H(e^jω)| at 4000 Hz = 0       (z = −1)
    
    analog |Ha| at 4000 Hz = 0.0694
    digital: 0, the tail is folded onto
             the zero at z = −1
    
    pass band: the same Butterworth shape
    with the cutoff exactly at 1000 Hz
  11. The same in Python

    SciPy does the substitution: signal.bilinear uses s = 2·fs·(z − 1)/(z + 1) but does no prewarping, so we prewarp W first. The result matches signal.butter(2, 1000, fs=8000) to every digit.

    import numpy as np
    from scipy.signal import bilinear
    fs, fc = 8000, 1000
    W = 2*fs*np.tan(np.pi*fc/fs)
    den = [1, np.sqrt(2)*W, W**2]
    b, a = bilinear([W**2], den, fs)
    
    >>> b.round(4), a.round(4)
    ([0.0976, 0.1953, 0.0976],
     [1., −0.9428, 0.3333])
    >>> signal.butter(2, 1000, fs=8000)
    (the same b and a)
    
    (Python 3, numpy, scipy; checked
     with SciPy 1.18.1)

Quiz Unlocks after the last step.