Skip to content
Tutorials Center
My learning

Topics

Lesson 20 of 38 ยท Filters: IIR

Designing IIR Filters with the Bilinear Transform

Turn an analog prototype into a digital IIR filter with the bilinear transform, understand frequency warping and pre-warping, and design Butterworth filters with SciPy.

Analog filter theory is mature: decades of work produced prototypes with known, well-behaved responses. The classic way to design a digital IIR filter is to start from one of those analog prototypes and map it into the digital domain. The most widely used mapping is the bilinear transform. This lesson explains how it works, what its one big side effect is (frequency warping), and how to use it through SciPy.

The substitution

The analog transfer function H(s) lives in the s-plane; the digital one H(z) lives in the z-plane. The bilinear transform replaces

s = 2 fs (z - 1) / (z + 1)

where fs is the sampling rate. This maps the entire left half of the s-plane (stable analog systems) into the inside of the unit circle (stable digital systems), so stability is always preserved. It also maps the entire analog frequency axis, from 0 to infinity, onto the digital range 0 to fs/2. No aliasing can occur, which is the main advantage over the older impulse-invariance method.

Frequency warping

Squeezing an infinite axis into a finite one cannot be linear. The relation between the analog frequency ฮฉ and the digital frequency ฯ‰ (radians per sample) is

ฮฉ = 2 fs tan(ฯ‰ / 2)

Near zero the mapping is almost linear; close to fs/2 it is strongly compressed. A cutoff you asked for in the analog prototype therefore lands at the wrong digital frequency unless you correct for it.

Pre-warping fixes the cutoff. Before designing the analog prototype, convert the wanted digital cutoff fc to the analog frequency ฮฉ_c = 2 fs tan(ฯ€ fc / fs) and design the analog filter at that frequency. After the bilinear transform the digital cutoff lands exactly where you wanted.

Python Warping and pre-warping

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Without pre-warping a 3000 Hz request ends up near 2.2 kHz, far from the target. With pre-warping the match is exact. SciPy does the pre-warping for you.

Butterworth filters

A Butterworth filter has a maximally flat passband: the magnitude response is 1 / sqrt(1 + (ฮฉ/ฮฉ_c)^(2N)). At the cutoff the gain is always 1/sqrt(2) (about -3 dB), and the roll-off steepens with order N at 20N dB per decade. There is no ripple anywhere, which makes it the default choice when you want a smooth response.

In SciPy, signal.butter(N, Wn, btype, fs=fs) designs the digital filter, using the bilinear transform with pre-warping internally.

Python Designing a Butterworth low-pass

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The listing shows a flat passband near 0 dB, exactly -3 dB at 1000 Hz and rapid attenuation beyond it. You can also design high-pass ("high"), band-pass ("band" with two edge frequencies) and band-stop ("bandstop") filters with the same call.

Choosing the order

How many poles do you need? Specify the passband edge wp, the stopband edge ws, the maximum passband loss gpass and the minimum stopband attenuation gstop in dB, then ask SciPy for the smallest order that meets the specification with signal.buttord.

Python Finding the minimum order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A narrow transition band or deep stopband drives the order up quickly. If the order is higher than you can afford, the next lesson shows Chebyshev and elliptic filters, which trade ripple for a sharper cutoff.

A design recipe

  1. Write down the specification: type, passband and stopband edges, allowed ripple, required attenuation, sampling rate.
  2. Use buttord (or its Chebyshev and elliptic siblings) to find the order.
  3. Design with butter(..., output="sos") so the filter is stored as stable second-order sections.
  4. Check the response with sosfreqz and test on a real signal.
  5. Decide whether phase matters; if you are filtering offline, consider zero-phase filtering with sosfiltfilt.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the bilinear transform guarantee about stability?

    The left half of the s-plane maps inside the unit circle, so a stable analog prototype yields a stable digital filter.
  2. 2. Why is pre-warping used?

    The tan relation compresses high frequencies; designing the analog filter at the pre-warped frequency cancels the compression at the key frequency.
  3. 3. What is the gain of any Butterworth low-pass at its cutoff frequency?

    The Butterworth magnitude at the cutoff is 1/sqrt(2) for every order, which is about -3.01 dB.
  4. 4. What does buttord return?

    buttord computes the minimum order N and the natural frequency Wn from the passband and stopband requirements.

Summary

  • The bilinear transform substitutes s = 2 fs (z-1)/(z+1), preserving stability and avoiding aliasing.
  • It warps frequency by ฮฉ = 2 fs tan(ฯ‰/2); pre-warp the critical frequencies to compensate.
  • Butterworth filters have a maximally flat passband and -3 dB at the cutoff.
  • butter designs the filter; buttord finds the minimum order for a specification.
  • Follow a recipe: specify, choose order, design as second-order sections, verify, then decide on phase handling.

Next: Chebyshev and Elliptic Filters