Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Digital IIR design by the bilinear transform

ProblemTurn an analogue prototype into a digital recursive (IIR) filter with prescribed cutoffs, and choose the smallest order that meets a passband and stopband specification
Devised byArnold Tustin (1947), the bilinear substitution; James Kaiser (1963) and Charles Rader and Bernard Gold (1967), its use for digital filter design with frequency prewarping
AccuracyDesigns, order selections and responses agree with SciPy to or better (reference table)
Cost for a design of order
Read firstAnalogue prototypes: Butterworth, Chebyshev, elliptic and Bessel
APIbutter, cheby1, cheby2, ellip, bessel (ButterOutputType::{Ba, Zpk}), buttord, cheb1ord, cheb2ord, ellipord, bilinear, bilinear_zpk, freqz

Overview

A digital infinite impulse response (IIR) filter computes each output from past outputs as well as inputs. Its transfer function is a ratio of polynomials in , and a few coefficients give a sharp frequency response. The usual way to design one is not to start from scratch, but to take a well-understood analogue prototype and map the -plane to the -plane. The bilinear transform does this so that stable analogue filters become stable digital ones and the analogue frequency axis maps onto the unit circle exactly once, so ripples and attenuations carry over unchanged. The price is a nonlinear warping of the frequency axis, which is undone by prewarping the critical frequencies before the analogue design. SciPy’s butter, cheby1, cheby2, ellip and bessel, and their order-selection companions, follow this recipe, and the library reproduces them.

Where it is used

IIR filters reach a sharp cutoff with far fewer coefficients than FIR filters, which matters when computing power or power consumption is limited.

  • Embedded systems. Sensor conditioning in a microcontroller (accelerometer smoothing, motor-current filtering, ECG baseline removal) uses low-order IIR filters.
  • Audio. Equalisers, tone controls and crossovers are built from IIR sections.
  • Control. Digital controllers use discretised versions of analogue compensators, designed with the bilinear transform.

History

Arnold Tustin (1947) introduced the substitution to simulate continuous control systems on sampled data. When digital filtering began at Bell Labs and MIT Lincoln Laboratory in the 1960s, James Kaiser (1963) and Charles Rader and Bernard Gold (1967) used it to turn the classical analogue designs into recursive digital filters, with prewarping to place the cutoffs exactly. Other mappings, impulse invariance and the matched z-transform, were tried and remain in use for special purposes, but the bilinear transform became the standard for frequency-selective filters.

The idea

The bilinear transform

An analogue filter is described by a transfer function and a digital one by (see the chapter’s background section). To convert one into the other we need a rule that replaces by an expression in .

Where the rule comes from. In an analogue circuit, is the transfer function of an integrator. A digital filter cannot integrate, but it can approximate an integral numerically. The trapezoid rule with sample interval updates a running integral of the input by

Writing for a delay of one sample, this says , so the digital integrator has the transfer function . Using it in place of every amounts to the substitution

the bilinear transform. Applied to a rational of order it gives a rational of the same order.

Its key properties.

  • Frequencies map to frequencies. Put , a point on the unit circle. Then , so with

The unit circle corresponds to the imaginary axis: the digital filter’s response at equals the analogue filter’s response at . As runs from 0 to (Nyquist), runs from 0 to . The whole infinite analogue frequency axis is compressed onto , each frequency appearing exactly once, so there is no aliasing.

  • Stability is preserved. The left half of the -plane maps to the inside of the unit circle, so the poles of a stable analogue filter become the poles of a stable digital one.
  • Poles and zeros map individually. A zero or pole at moves to . An analogue low-pass filter has more poles than zeros; its response falls to zero as . Infinite analogue frequency corresponds to , so each excess pole of the prototype contributes a zero at , the Nyquist frequency.

Frequency warping and prewarping

Figure 14.6. Frequency warping.

The tangent is nearly linear at low frequencies but stretches without bound towards Nyquist. A prototype designed for cutoff would therefore land at the wrong digital frequency. Prewarping inverts the tangent: to put a digital cutoff at , design the analogue prototype for . Only the critical frequencies land exactly where requested, but because the map is monotonic, equiripple bands stay equiripple and the ripple levels are preserved.

The design recipe

butter, cheby1, cheby2, ellip and bessel all:

  1. prewarp the requested edges (in units of fs, Nyquist being fs/2; by default fs = 2, so edges are fractions of Nyquist);
  2. build the normalised prototype in zero-pole-gain form;
  3. transform it to the requested low-pass, high-pass, band-pass or band-stop shape;
  4. apply the bilinear transform to the zeros, poles and gain;
  5. return either the zeros, poles and gain, or the expanded polynomials b and a with .

Figure 14.7. Minimum-order designs.

The four families at the smallest orders that meet the same specification, shown dashed. The elliptic filter’s zeros lie on the unit circle, producing the notches in its stopband, and its poles crowd towards the circle near the passband edge.

Choosing the order

Each family has a closed form for the smallest order that meets a specification of passband edge with ripple dB and stopband edge with attenuation dB. After prewarping, the specification reduces to the prototype’s selectivity (for band filters, the worst of the two sides, through the band transformation). Then, for Butterworth,

with in place of for the Chebyshev types, and a ratio of complete elliptic integrals for the elliptic family. The functions also return the critical frequency to pass to the design function: for Butterworth, the 3 dB frequency that meets the passband edge exactly; for Chebyshev II, the stopband edge that meets it. For band-stop filters, SciPy also moves each passband edge, within its allowed range, to the place that minimises the order.

One golden-section search for the optimal edges serves buttord, cheb1ord, cheb2ord and ellipord; without it, band-stop specifications come out one order higher than SciPy’s.

Phase

Figure 14.8. Group delay of the designs.

IIR filters have nonlinear phase. Their group delay peaks at the passband edge, highest for the sharpest filters. A Bessel design keeps it nearly flat, but the bilinear warping spoils the analogue Bessel filter’s flatness away from DC. When linear phase matters, FIR filters, or IIR filtering applied forwards and then backwards, are the answer.

Evaluating the response

freqz evaluates at chosen frequencies or on a uniform grid, in radians per sample by default or in the units of fs. Unlike SciPy, its uniform grid includes the Nyquist frequency unless include_nyquist is Some(false), and whole = true returns the axis on rather than .

Algorithm

butter, cheby1, cheby2, ellip and bessel share one procedure. Input: the order, the ripple parameters of the family, the band edges and the band type.

  1. Validate and prewarp. Check that the edges lie between zero and the Nyquist frequency and are in increasing order. Replace each edge by the analogue frequency .
  2. Prototype. Build the family’s analogue prototype of the requested order, as zeros, poles and gain.
  3. Frequency transformation. Transform the prototype to the requested band type at the prewarped edges. For a band-pass or band-stop filter with edges , the centre is and the width .
  4. Bilinear transform. Map each zero and pole to . Add a zero at for each pole in excess of the zeros. Multiply the gain by , taken over the analogue zeros and poles, which keeps the response’s level the same.
  5. Output. Return the zeros, poles and gain; or, if coefficients are requested, multiply out the factors into the polynomials and , with .

Order selection (buttord and its companions): prewarp the passband and stopband edges; reduce the specification to the selectivity of the equivalent low-pass prototype; evaluate the family’s closed-form expression for the order and round it up; and compute the critical frequency to pass to the design function.

Implementation

    let warped = wn.iter().map(|&w| prewarp_frequency(w, fs)).collect::<Vec<_>>();
    let analog = butter_analog_zpk(order, &warped, filter_type)?;
    let digital_zpk = bilinear_zpk(
        analog.z.as_slice().unwrap_or(&[]),
        analog.p.as_slice().unwrap_or(&[]),
        analog.k,
        fs,
    )?;
    let fs2 = 2.0 * fs;
    let fs2c = Complex::new(fs2, 0.0);

    let z_d = z
        .iter()
        .map(|zi| {
            let zi = zi.to_complex();
            (fs2c + zi) / (fs2c - zi)
        })
        .collect::<Vec<_>>();

    let p_d = p
        .iter()
        .map(|pi| {
            let pi = pi.to_complex();
            (fs2c + pi) / (fs2c - pi)
        })
        .collect::<Vec<_>>();

    let degree = p.len() - z.len();
    let mut z_out = z_d;
    z_out.extend((0..degree).map(|_| Complex::new(-1.0, 0.0)));

    let num = z
        .iter()
        .fold(Complex::new(1.0, 0.0), |acc, zi| acc * (fs2c - zi.to_complex()));
    let den = p
        .iter()
        .fold(Complex::new(1.0, 0.0), |acc, pi| acc * (fs2c - pi.to_complex()));
    if den.norm_sqr() <= 1e-24 {
        return Err(ErrorsJSL::RuntimeError(
            "bilinear_zpk gain normalization encountered zero denominator",
        ));
    }
    let k_d = k.to_complex() * num / den;
  • Designs are carried out on zeros, poles and gain; only the final step multiplies out polynomials, whose coefficients are ill-conditioned for high orders (see IIR structures).
  • ButterOutput holds either form; the Ba coefficients are complex numbers with negligible imaginary parts for real designs.

In practice

//! Digital IIR design: choose the order, design, check the response and filter a signal.

use lib_jsl_dsp::continuous::filter::design::IirFilterBandType;
use lib_jsl_dsp::discrete::filters::butterworth::ButterOutput;
use lib_jsl_dsp::discrete::filters::discrete_linear_filter::DiscreteLinearFilter;
use lib_jsl_dsp::discrete::filters::elliptic::{ellip, ellipord};
use lib_jsl_dsp::discrete::spectral::freqz::{FreqzWorN, freqz};

fn main() {
    // Sampling at 8 kHz: pass up to 1 kHz with 0.5 dB ripple, reject above 1.3 kHz by 60 dB.
    let fs = 8000.0;
    let spec = ellipord(&[1000.0], &[1300.0], 0.5, 60.0, IirFilterBandType::Lowpass, Some(fs)).unwrap();
    println!("elliptic order {} (critical frequency {:.1} Hz)", spec.order, spec.wn[0]);
    let ButterOutput::Ba(ba) = ellip(spec.order, 0.5, 60.0, &spec.wn, IirFilterBandType::Lowpass, None, Some(fs)).unwrap() else { unreachable!() };
    let (b, a): (Vec<f64>, Vec<f64>) = (ba.beta.iter().map(|c| c.re).collect(), ba.alpha.iter().map(|c| c.re).collect());
    let r = freqz(&b, Some(&a), Some(FreqzWorN::Frequencies(vec![500.0, 1000.0, 1300.0, 2000.0])), None, Some(fs), None).unwrap();
    for (f, h) in r.w.iter().zip(&r.h) {
        println!("{f:6.0} Hz: {:7.2} dB", 20.0 * h.norm().log10());
    }
    // Filter 400 Hz + 2 kHz: the 2 kHz tone should disappear.
    let x: Vec<f64> = (0..800).map(|n| (2.0 * std::f64::consts::PI * 400.0 * n as f64 / fs).sin() + (2.0 * std::f64::consts::PI * 2000.0 * n as f64 / fs).sin()).collect();
    let mut filter = DiscreteLinearFilter::new(&b, &a);
    let y: Vec<f64> = x.iter().map(|v| filter.step(v)).collect();
    let rms = |v: &[f64]| (v.iter().map(|s| s * s).sum::<f64>() / v.len() as f64).sqrt();
    println!("RMS in {:.3} (two unit tones), out {:.3} (one tone: 0.707)", rms(&x[400..]), rms(&y[400..]));
}
elliptic order 7 (critical frequency 1000.0 Hz)
   500 Hz:   -0.06 dB
  1000 Hz:   -0.50 dB
  1300 Hz:  -63.39 dB
  2000 Hz:  -74.54 dB
RMS in 1.000 (two unit tones), out 0.679 (one tone: 0.707)

The design meets the specification with margin to spare at the stopband edge, because the order is rounded up. The 400 Hz tone passes with a gain inside the 0.5 dB ripple band (0.679 of 0.707), and the 2 kHz tone is gone.

Strengths

  • Sharp responses at low order and low cost per sample; exact placement of the critical frequencies.
  • Systematic order selection; stability is inherited from the prototype.

Weaknesses

  • Nonlinear phase, with delay peaks at the band edges.
  • Only the shapes of the classical families; arbitrary magnitude responses need FIR methods.
  • High-order designs in polynomial form are numerically fragile.

Exercises

  1. Show that the bilinear transform maps the left half -plane onto the interior of the unit disc.
  2. Derive from the substitution with .
  3. Design a first-order low-pass filter by hand from with , and compare with the reference row “bilinear 1/(s+1) fs 2”.
  4. Explain why impulse invariance aliases a high-pass prototype but the bilinear transform does not.
  5. Derive the Butterworth order formula from .
Hints and answers
  1. gives . Then iff .
  2. With and : , so .
  3. with : ; check the first coefficients against the reference.
  4. Impulse invariance samples the analogue response, whose spectrum periodically repeats at ; a high-pass response does not vanish at , so the copies overlap (alias). The bilinear transform maps the whole axis onto one turn of the unit circle, so there is nothing to alias.
  5. Require at the stopband edge: , so , rounded up.

Further reading

  • A. V. Oppenheim and R. W. Schafer, Discrete-Time Signal Processing, 3rd ed., Pearson, 2010, section 7.2.
  • C. M. Rader and B. Gold, “Digital filter design techniques in the frequency domain”, Proceedings of the IEEE 55 (1967) 149–171.
  • T. W. Parks and C. S. Burrus, Digital Filter Design, Wiley, 1987, chapter 7.
  • A. Tustin, “A method of analysing the behaviour of linear systems in terms of time series”, Journal of the IEE, Part IIA 94 (1947) 130–142.