Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 38 ยท Filters: IIR

Second-Order Sections and Filter Stability

Learn why high-order IIR filters must be built as cascaded biquads, how to check stability from pole locations, and how to use SOS output and sosfilt in SciPy.

You can write any IIR filter as a single transfer function b, a. For a low order that is fine. For an order of 8, 10 or more, it fails in practice: tiny rounding errors in the coefficients move the poles, and the filter can become unstable or badly wrong. The cure is to factor the filter into second-order sections (SOS, also called biquads) and run them in a cascade. This lesson shows the problem, the cure and how to test stability.

Stability and poles

A causal LTI filter is bounded-input bounded-output stable if and only if all its poles lie strictly inside the unit circle of the z-plane. A pole on the circle gives an oscillator that never decays; a pole outside gives an output that grows without limit.

You can find the poles as the roots of the denominator polynomial.

Python Checking poles

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 stable system decays toward zero; the unstable one blows up even from a single impulse.

The problem with high orders

Polynomial roots are extremely sensitive to coefficient errors, and the sensitivity grows fast with order. When you design a narrow-band filter of high order and then store b, a as 64-bit floats (or worse, as 32-bit or fixed point), the poles you actually get can differ from the ones you designed. A narrow low-pass at a low cutoff is a classic example: all poles bunch close to z = 1.

Python When transfer function form fails

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.

Compare the two results. The SOS version behaves like a proper 40 Hz low-pass impulse response and decays. The transfer function form has a computed pole radius above 1, so its output explodes (the exact huge numbers depend on floating-point details, which is itself the lesson).

Second-order sections

Any real polynomial factors into real first- and second-order pieces, so a filter of order N becomes a cascade

H(z) = g * H1(z) * H2(z) * ... * HK(z) with K = ceil(N/2)

Each section is a biquad (b0 + b1 z^-1 + b2 z^-2) / (1 + a1 z^-1 + a2 z^-2). Each biquad has only two poles, so its coefficients are insensitive to rounding. SciPy stores an SOS filter as a K by 6 array with rows [b0, b1, b2, a0, a1, a2] (and a0 = 1).

Python Inspecting an SOS array

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.

Pairing and ordering

Which pole pairs go in which section, and in what order, affects dynamic range and noise in fixed-point hardware. Good practice is to pair each pole with its nearest zero and sort sections by increasing pole radius (so the sharpest section comes last). SciPy's tf2sos and the design functions do this for you with sensible defaults.

Using SOS filters in practice

Python
from scipy import signal

sos = signal.butter(8, [300, 3400], btype="band", fs=16000, output="sos")
y = signal.sosfilt(sos, x)           # causal, one pass
y0 = signal.sosfiltfilt(sos, x)      # zero phase: forward and backward
w, h = signal.sosfreqz(sos, fs=16000)
  • sosfilt keeps the state between calls if you pass zi (use sosfilt_zi for a steady-state start), which you need for streaming audio.
  • sosfiltfilt squares the magnitude response and cancels the phase; use it offline only.
  • Always design with output="sos" for any order above about 4.

Never design a high-order filter, convert it to b, a and then run it in 32-bit floating point or fixed point. The poles will move. Keep SOS form, and consider a higher internal precision for the state variables.

Direct forms

How you wire a biquad also matters. Direct form I stores two past inputs and two past outputs. Direct form II transposed stores only two state values and has better numeric properties; it is what lfilter uses. Fixed-point designs often choose structures such as lattice or coupled-form sections to keep quantization noise low.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. When is a causal IIR filter stable?

    BIBO stability of a causal LTI system requires all poles inside the unit circle. Zeros do not affect stability.
  2. 2. Why are high-order filters implemented as cascaded biquads?

    Each second-order section has only two poles, whose positions are far less sensitive to rounding errors than the roots of a long polynomial.
  3. 3. What does one row of an SOS array contain?

    SciPy stores each section as three numerator and three denominator coefficients, with a0 equal to 1.
  4. 4. What is sosfiltfilt used for?

    It filters forward and backward so the phase delay cancels; this needs the whole signal, so it cannot run in real time.

Summary

  • Stability means every pole of a causal filter has magnitude below one; check with np.roots(a).
  • High-order transfer functions in b, a form are numerically fragile.
  • Factor the filter into second-order sections and run them in a cascade (output="sos", sosfilt).
  • SOS arrays have rows [b0, b1, b2, a0, a1, a2]; pairing and ordering affect noise.
  • sosfiltfilt gives zero phase offline; streaming uses sosfilt with saved state.

Next: Windowing and Spectral Leakage