TExcelTAD
Home › Signals, Systems & Digital Filters for Engineers › Biquads, Second-Order Sections and Coefficient Quantisation

Biquads, Second-Order Sections and Coefficient Quantisation

An 8th-order elliptic low-pass with a 1 kHz1\ \text{kHz} passband at 48 kSa/s48\ \text{kSa/s} is a routine audio or sensor filter. Write it as one transfer function B(z)/A(z)B(z)/A(z), round the nine denominator coefficients to 24 fractional bits (finer than a 32-bit float), and the filter is unstable: its output grows without bound. Write the same filter as four second-order sections and it survives rounding to 16 bits. This lesson shows why, defines the biquad and its stability triangle, and gives the rules for ordering and scaling sections. Every IIR filter in practice, in SciPy, in an audio plug-in or on a microcontroller, is run this way. Background: IIR Filters and Poles and Zeros in z.

The biquad

A biquad is a second-order IIR filter:

Hk(z)=b0k+b1kz−1+b2kz−21+a1kz−1+a2kz−2,H(z)=∏k=1LHk(z)H_k(z) = \frac{b_{0k} + b_{1k} z^{-1} + b_{2k} z^{-2}}{1 + a_{1k} z^{-1} + a_{2k} z^{-2}}, \qquad H(z) = \prod_{k=1}^{L} H_k(z)

One complex-conjugate pole pair re±jθr e^{\pm j\theta} gives a1=−2rcos⁡θa_1 = -2r\cos\theta and a2=r2a_2 = r^2; a zero pair works the same way in the numerator. An order-NN filter becomes ⌈N/2⌉\lceil N/2 \rceil biquads in cascade. SciPy stores them as an array sos of shape (L,6)(L, 6) with rows [b0,b1,b2,1,a1,a2][b_0, b_1, b_2, 1, a_1, a_2], and sosfilt, sosfreqz, sosfilt_zi work on it directly. Every design function returns it with output='sos'.

Why one polynomial fails

The poles of a sharp low-pass at a low frequency crowd together near z=1z = 1. The roots of a polynomial are extremely sensitive to its coefficients when roots are clustered: a change Δak\Delta a_k moves a pole pip_i by roughly

Δpi≈−piN−k∏j≠i(pi−pj) Δak\Delta p_i \approx -\frac{p_i^{N-k}}{\prod_{j \ne i}(p_i - p_j)}\,\Delta a_k

and the product of small distances in the denominator makes the factor huge. In a biquad each pole has only its own conjugate as a neighbour, so the sensitivity stays small. The direct-form coefficients also span a wide range (here up to 64), costing integer bits in fixed point.

Worked example: quantising an 8th-order elliptic low-pass

Given: an elliptic low-pass, order 8, 0.5 dB0.5\ \text{dB} ripple, 70 dB70\ \text{dB} attenuation, passband edge 1 kHz1\ \text{kHz}, fs=48 kHzf_s = 48\ \text{kHz}.

Find: the largest pole radius after rounding the coefficients to 24, 20 and 16 fractional bits, for one 8th-order polynomial and for four biquads, and the gain error at 500 Hz500\ \text{Hz}.

Solve: round xx to round⁡(x⋅2B)/2B\operatorname{round}(x \cdot 2^B)/2^B and recompute the roots:

python · try it yourself
import numpy as np
from scipy import signal

# A narrow 8th-order elliptic low-pass: fs = 48 kHz, passband to 1 kHz
fs = 48000
sos = signal.ellip(8, 0.5, 70, 1000, output="sos", fs=fs)
b, a = signal.sos2tf(sos)
print("direct form: a =", np.array2string(a, precision=4, max_line_width=100))
_, H0 = signal.sosfreqz(sos, worN=[500], fs=fs)
print(f"largest pole radius, exact: {np.abs(np.roots(a)).max():.6f}; gain at 500 Hz, exact: {20 * np.log10(abs(H0[0])):.3f} dB")

def quantise(x, frac_bits):                     # round to a fixed-point grid with frac_bits fractional bits
    return np.round(x * 2**frac_bits) / 2**frac_bits

for bits in (24, 20, 16):
    aq = quantise(a, bits)
    r_tf = np.abs(np.roots(aq)).max()
    sq = quantise(sos, bits)
    r_sos = max(np.abs(np.roots(s[3:])).max() for s in sq)
    _, H = signal.sosfreqz(sq, worN=[0, 500], fs=fs)
    print(f"{bits} fractional bits: one polynomial -> max |pole| {r_tf:.4f} ({'UNSTABLE' if r_tf >= 1 else 'stable'}); "
          f"4 biquads -> max |pole| {r_sos:.6f}, gain at 500 Hz {20 * np.log10(abs(H[1])):.3f} dB")
direct form: a = [  1.      -7.8123  26.7413 -52.3829  64.226  -50.4709  24.8242  -6.987    0.8616]
largest pole radius, exact: 0.996989; gain at 500 Hz, exact: -0.489 dB
24 fractional bits: one polynomial -> max |pole| 1.0358 (UNSTABLE); 4 biquads -> max |pole| 0.996989, gain at 500 Hz -0.490 dB
20 fractional bits: one polynomial -> max |pole| 1.1353 (UNSTABLE); 4 biquads -> max |pole| 0.996989, gain at 500 Hz -0.517 dB
16 fractional bits: one polynomial -> max |pole| 1.2370 (UNSTABLE); 4 biquads -> max |pole| 0.996989, gain at 500 Hz 0.923 dB

Check: the exact filter's largest pole radius is 0.996990.99699, only 0.0030.003 inside the unit circle. Rounding the polynomial's coefficients by at most 2−25=3×10−82^{-25} = 3 \times 10^{-8} pushes a pole out to 1.0361.036: unstable. The four biquads keep their poles to six decimals even at 16 bits. At 16 bits the gain moves instead (+0.92 dB+0.92\ \text{dB} at 500 Hz500\ \text{Hz} against −0.49 dB-0.49\ \text{dB} exact): the first section's numerator coefficients are about 3×10−43 \times 10^{-4}, so 16-bit rounding changes them by a few percent. That is a gain-distribution problem, solved by scaling (below), not a stability problem.

Reading the sections

python · try it yourself
import numpy as np
from scipy import signal

fs = 48000
sos = signal.ellip(8, 0.5, 70, 1000, output="sos", fs=fs)
print(" section   b0          b1          b2          a1         a2       pole r   f0 (Hz)   Q    in triangle")
for i, (b0, b1, b2, _, a1, a2) in enumerate(sos):
    p = np.roots([1, a1, a2])[0]
    r, w = abs(p), abs(np.angle(p))
    # analog-equivalent f0 and Q from the z-plane pole (s = fs ln z)
    s = fs * np.log(p)
    f0, Q = abs(s) / (2 * np.pi), abs(s) / (-2 * s.real)
    ok = abs(a2) < 1 and abs(a1) < 1 + a2
    print(f"   {i}   {b0:10.3e} {b1:10.3e} {b2:10.3e}  {a1:9.5f} {a2:9.6f}  {r:.5f}  {f0:7.1f}  {Q:5.2f}   {ok}")

# Run a unit step through the exact sections and through the 24-bit direct-form polynomial
b, a = signal.sos2tf(sos)
aq = np.round(a * 2**24) / 2**24
x = np.ones(3000)
y_sos = signal.sosfilt(sos, x)
y_tf = signal.lfilter(b, aq, x)
print(f"step response after 3000 samples: SOS {y_sos[-1]:.4f}, quantised polynomial {y_tf[-1]:.3e}")
 section   b0          b1          b2          a1         a2       pole r   f0 (Hz)   Q    in triangle
   0    3.281e-04 -5.396e-04  3.281e-04   -1.92655  0.929064  0.96388    390.5   0.69   True
   1    1.000e+00 -1.944e+00  1.000e+00   -1.94510  0.953737  0.97659    718.5   1.99   True
   2    1.000e+00 -1.969e+00  1.000e+00   -1.96385  0.978253  0.98907    922.3   5.49   True
   3    1.000e+00 -1.975e+00  1.000e+00   -1.97680  0.993986  0.99699   1003.8  21.78   True
step response after 3000 samples: SOS 0.9441, quantised polynomial -2.517e+43

Each section is one pole pair and one zero pair. Numerators 1−1.94z−1+z−21 - 1.94z^{-1} + z^{-2} have zeros exactly on the unit circle (the stopband nulls of the elliptic filter); the overall gain sits in the first row. The poles get closer to the unit circle and their Q rises toward the band edge: the last section has Q=21.8Q = 21.8 and a pole radius of 0.996990.99699. Every section is inside the stability triangle ∣a2∣<1\lvert a_2 \rvert < 1, ∣a1∣<1+a2\lvert a_1 \rvert < 1 + a_2. The 24-bit polynomial, run on a step for 3000 samples, reaches −2.5×1043-2.5 \times 10^{43}.

-2 -1 1 2 1 -1 a1 a2 stable complex poles above the dashed parabola zoom: the 4 sections -2.0 -1.95 -1.9 0.93 1.00 Q = 0.7 Q = 2.0 Q = 5.5 Q = 21.8 a2 = 1: poles on the unit circle

The figure shows why biquads near DC are hard even on their own: the sections sit in the corner a1→−2a_1 \to -2, a2→1a_2 \to 1, where a small coefficient step is a large change of pole radius or angle. Low-frequency, high-Q sections at high sample rates need more coefficient bits (or a different structure, see Filter Structures). One remedy is to run such a filter at a lower rate after decimation.

Pairing, ordering and scaling

SciPy's zpk2sos (used by every output='sos' design) follows the classic rules:

  • Pairing: each pole pair is matched with the zero pair closest to it, so each section's numerator partly cancels its own resonance and no section has a huge gain peak.
  • Ordering: sections are ordered by pole radius; SciPy's output puts the poles closest to the unit circle last (its documentation describes the pairing, not the order, but the table above shows it), so the high-Q, high-gain section is fed by a signal that the earlier sections have already filtered.
  • Scaling: in fixed point, each section's internal peak must not overflow. The overall gain is distributed so that the gain from the input to each section's output stays below 1 (an L∞L_\infty, or worst-case sine, norm) or the sum of the absolute values of its impulse response stays below 1 (L1L_1, never overflows). Scaling moves gain between sections; it does not change the overall response.

Guided lab: float32 against fixed point

Hand calculation. The exact filter has −0.49 dB-0.49\ \text{dB} at 500 Hz500\ \text{Hz} and a DC gain of −0.5 dB-0.5\ \text{dB} (an even-order elliptic starts at the bottom of its ripple), so a 1 V1\ \text{V} step settles to 0.944 V0.944\ \text{V}.

Simulation. In the first program, round the coefficients to np.float32 (sos.astype(np.float32)) and check the pole radii; then try 12 fractional bits: every section's poles stay inside the circle, but the first section's numerator (about 3×10−43 \times 10^{-4}, close to one step of 2−122^{-12}) rounds to 2−12(1−2z−1+z−2)2^{-12}(1 - 2z^{-1} + z^{-2}), a double zero at z=1z = 1, and the DC gain vanishes. The poles only reach the unit circle below about 8 fractional bits, so with this filter the gain distribution fails long before stability does.

What you would measure. Implement the four sections on a USB-powered microcontroller board with float32 and with 16-bit fixed-point coefficients, feed a 500 Hz500\ \text{Hz} sine of 0.5 V0.5\ \text{V} amplitude and compare the output amplitudes on a scope. Expect float32 within ±0.1 dB\pm 0.1\ \text{dB} of −0.49 dB-0.49\ \text{dB} and the unscaled 16-bit version about 1.4 dB1.4\ \text{dB} higher, as the simulation predicts. The direct-form 8th-order version, if you try it, oscillates or saturates: switch it off at once.

Hazards and safe setup. Signals below the converter's input range from a function generator; USB-powered board; an unstable filter saturates the DAC output at a rail but cannot damage anything at these levels. Keep headphones off while testing unstable code.

Pitfalls

  • Converting a stable sos to (b, a) with sos2tf "for convenience" and running high orders that way.
  • Quantising coefficients without re-checking the pole radii and the frequency response.
  • Assuming float32 is always enough: high-Q sections near DC at high sample rates can lose many bits.
  • Ignoring the gain distribution: a section with a tiny numerator loses relative accuracy.
  • Changing the section order without re-scaling.

Practice

  1. A biquad has poles at 0.9e±jπ/40.9e^{\pm j\pi/4}. Find a1a_1 and a2a_2.
  2. Is a1=−1.9a_1 = -1.9, a2=0.89a_2 = 0.89 stable? And a1=−1.9a_1 = -1.9, a2=0.9a_2 = 0.9?
  3. How many biquads does a 7th-order Butterworth need, and what is the odd one?
Answer
  1. a1=−2×0.9cos⁡(π/4)=−1.2728a_1 = -2 \times 0.9 \cos(\pi/4) = -1.2728, a2=0.81a_2 = 0.81.
  2. ∣a1∣<1+a2\lvert a_1 \rvert < 1 + a_2: 1.9<1.891.9 < 1.89 is false, so the first is unstable (a real pole just outside z=1z = 1). 1.9<1.91.9 < 1.9 is also false: a pole exactly at z=1z = 1, marginally stable at best; in practice unstable.
  3. Four: three biquads plus one first-order section (stored as a biquad with b2=a2=0b_2 = a_2 = 0).

Test yourself

Why are high-order IIR filters implemented as cascades of biquads?

  1. biquads are faster
  2. pole positions are far less sensitive to coefficient rounding
  3. biquads have linear phase
  4. SciPy cannot handle polynomials

A biquad's denominator is stable if

  1. a1<2a_1 < 2
  2. ∣a2∣<1\lvert a_2 \rvert < 1 and ∣a1∣<1+a2\lvert a_1 \rvert < 1 + a_2
  3. a1+a2<0a_1 + a_2 < 0
  4. b0=1b_0 = 1

A pole pair re±jθr e^{\pm j\theta} gives a2=a_2 =

  1. rr
  2. r2r^2
  3. −2rcos⁡θ-2r\cos\theta
  4. cos⁡θ\cos\theta

In the example, rounding the 8th-order denominator to 24 fractional bits

  1. changed nothing
  2. moved a pole outside the unit circle
  3. only changed the gain
  4. removed the ripple