Skip to content

Filter structures

Wire one biquad five ways, from direct form I to a lattice, and find the same output with different delays and different stored values.

Before this20.5 · 20.6 · 6 more
Chapter 21 · Lesson 1 of 4

First, the picture

One filter can be wired up in several ways. Below, a biquad’s block diagram rearranges itself: its two halves swap places, and then their delays merge. Watch the delay count fall while the multipliers stay at five.

Swap the halves, share the delays

A biquad, H(z) = (b₀ + b₁z⁻¹ + b₂z⁻²)/(1 + a₁z⁻¹ + a₂z⁻²), as a block diagram.

Direct form I: the zeros' half on the inputs, then the poles' half on the outputs. Four delays, five multipliers.

delays
4
multipliers
5
0.00 / 13.00 s
Describe this picture

One panel, a block diagram with no axes, of a biquad, H(z)=(b0+b1z−1+b2z−2)/(1+a1z−1+a2z−2)H(z)=(b_0+b_1z^{-1}+b_2z^{-2})/(1+a_1z^{-1}+a_2z^{-2}). The input x[n]x[n] goes in and the output y[n]y[n] comes out. The delay boxes read z−1z^{-1}. The gain triangles read b0b_0, b1b_1 and b2b_2 on the zeros’ half, and −a1-a_1 and −a2-a_2 on the poles’ half; the adders are circles marked ⊕. Under the two halves sit their labels, “zeros (b’s)” and “poles (a’s)”. The signal on each delay column is labelled with what it holds: x[n−1]x[n-1] and y[n−1]y[n-1] at first, and later w[n−1]w[n-1]. The readouts, in one row, are the delays and the multipliers. There is no control.

The clip lasts 13 s. It starts with direct form I: the zeros’ half on the inputs, then the poles’ half on the outputs, four delays and five multipliers. From 2 s to 5 s the two halves slide past each other and trade places, because two LTI systems in a row can go in either order. At 6.25 s, poles first and zeros second, the same H(z)H(z): both delay columns now hold the same signal, w[n]w[n], the input through the poles alone. From 7.5 s to 9.5 s the two delay columns slide together and become one. At the end, direct form II: one column of two delays serves both halves, with the same H(z)H(z), five multipliers, and the fewest delays a biquad can have.

Swap the halves, share the delays

A filter’s equation says what to compute. It does not say how to wire it up, and there are several ways. They all give the same output, but they keep different numbers inside. In this lesson I build one filter five ways and look inside each.

The filter is the biquad of Audio equalisers and biquads (20.5):

H(z)=b0+b1z−1+b2z−21+a1z−1+a2z−2.H(z)=\frac{b_0+b_1z^{-1}+b_2z^{-2}}{1+a_1z^{-1}+a_2z^{-2}}.

I write B(z)B(z) for its top and A(z)A(z) for its bottom, so H(z)=B(z)/A(z)H(z)=B(z)/A(z). By Transfer functions, poles & zeros (16.3), the roots of BB are the zeros and the roots of AA are the poles. Read backwards, the same page turns H(z)H(z) into its difference equation:

y[n]=b0x[n]+b1x[n−1]+b2x[n−2]−a1y[n−1]−a2y[n−2].\begin{aligned} y[n]&=b_0x[n]+b_1x[n-1]\\ &\quad+b_2x[n-2]-a_1y[n-1]\\ &\quad-a_2y[n-2]. \end{aligned}

In Difference equations (6.1), every term became a wire into an adder, with a delay box for each step back and a gain triangle for its number. Do that here. The three xx terms hang off a column of two delay boxes on the input, and the two yy terms off a second column on the output.

That wiring is called direct form I. Its first half computes B(z)B(z) on the input and its past: I call it the zeros’ half. Its second half divides by A(z)A(z), using past outputs: the poles’ half. It needs four delays and five multipliers.

Now the trick. The two halves are two LTI systems in a row, and by Properties of LTI systems (5.4) their order does not matter. So swap them: poles first, zeros second. In the z-domain it is one line:

H(z)=B(z)⋅1A(z)=1A(z)⋅B(z).H(z)=B(z)\cdot\frac{1}{A(z)}=\frac{1}{A(z)}\cdot B(z).

After the swap, both delay columns are fed by the same signal, so they hold the same numbers. Think of two people each keeping a copy of the same notebook: one copy, shared, is enough.

The picture at the top of the page makes the swap, and then shares the delays. Notice what changed and what did not. The multipliers stay five; only the delays halve. The output depends on two steps of the past, so two delays is the fewest possible. A structure with as many delays as the filter’s order is called canonical, and this one is direct form II.

What direct form II stores

Name the signal on the shared column w[n]w[n]. It is the input passed through the poles alone, so W(z)=X(z)/A(z)W(z)=X(z)/A(z). Then the zeros’ half builds the output from it:

w[n]=x[n]−a1w[n−1]−a2w[n−2],y[n]=b0w[n]+b1w[n−1]+b2w[n−2].\begin{aligned} w[n]&=x[n]-a_1w[n-1]\\ &\quad-a_2w[n-2],\\ y[n]&=b_0w[n]+b_1w[n-1]\\ &\quad+b_2w[n-2]. \end{aligned}

This w[n]w[n] is not a window, even though windows also use the letter; here it is a signal inside a filter. The two delays hold w[n−1]{w[n-1]} and w[n−2]{w[n-2]}, and nothing else.

There is a third way to wire a biquad with two delays, the transposed form. I will show where it comes from after the next instrument. Its delays hold two running sums, s1[n]s_1[n] and s2[n]s_2[n]:

y[n]=b0x[n]+s1[n−1],s1[n]=b1x[n]−a1y[n]+s2[n−1],s2[n]=b2x[n]−a2y[n].\begin{aligned} y[n]&=b_0x[n]+s_1[n-1],\\ s_1[n]&=b_1x[n]-a_1y[n]+s_2[n-1],\\ s_2[n]&=b_2x[n]-a_2y[n]. \end{aligned}

Each output is b0x[n]b_0x[n] plus the sum saved one step ago. Then both sums are brought up to date for the next step. SciPy’s lfilter works this way.

Same output, different insides

Do the three structures really agree, and what do they store? Let’s feed one sine to each.

The filter is a piece of the elliptic filter of Choosing FIR or IIR (20.6). Its order is 5, so it has five poles: one on the real axis and two mirror pairs. The pair nearest the unit circle, at radius 0.9527 and angles ±45.64°, makes the sharpest peak. With its two zeros, it is one biquad:

H(z)=1−1.0764z−1+z−21−1.3322z−1+0.9076z−2.H(z)=\frac{1-1.0764z^{-1}+z^{-2}}{1-1.3322z^{-1}+0.9076z^{-2}}.

Its zeros sit on the unit circle at ±57.44°, which is 1276 Hz at fs=8f_s=8 kHz. The input is a 1 kHz sine of amplitude 1, x[n]=sin⁡(2π⋅1000n/8000)=sin⁡(πn/4)x[n]=\sin(2\pi\cdot1000n/8000)=\sin(\pi n/4): eight samples a cycle. It starts from rest, so every stored value starts at 0.

Three kitchens can make the same soup, one of them in a pot that nearly overflows. Watch for the pot. Many chips store numbers in fixed point: a fixed number of bits and a fixed range, as in Quantization & noise (11.1). A stored value that outgrows the range overflows.

Same output, different insides

The sharpest biquad of 20.6's elliptic filter (poles 0.953∠±45.6°), fed a 1 kHz sine of amplitude 1 from rest, built three ways.

Direct form I stores the last two inputs and outputs.

structure
direct form I
output peak
not yet
largest stored value
not yet
Structure
0.00 / 15.50 s
Describe this picture

Two stacked panels for the sharpest biquad of 20.6’s elliptic filter (poles 0.953∠±45.6°), fed a 1 kHz sine of amplitude 1 from rest and built three ways. They share the sample axis, nn from 0 to 199. The first plots the output y[n]y[n], from −16 to 16, as a solid line. The second, on the same range, draws the structure’s stored signals as thin dashed and dotted lines, each labelled: x[n]x[n] and y[n]y[n] for direct form I, s1[n]s_1[n] and s2[n]s_2[n] for the transposed form, and w[n]w[n] for direct form II. A dotted level marks the largest stored value and is labelled with it. The readouts are the structure, on its own row, then the output peak and the largest stored value, with three decimals.

The clip lasts 15.5 s. It starts with empty panels; the output draws first, then the stored signals. At 4 s, direct form I, which stores the last two inputs and outputs: the output peaks at 4.856, and nothing it stores is bigger. Then the stored panel cross-fades to the next structure, with a blank caption, while the output panel stays as it is. At 7.5 s, transposed direct form II: the same output, and its two stored sums stay within 4.856 too. After a second cross-fade, direct form II: the same output, but its stored w[n]w[n] reaches 14.376, about three times the output; the caption adds that in fixed point it would overflow first (21.3). After the clip three buttons in a group named “Structure” choose a structure, each with its caption from the clip. The choice is kept in the link, as inside.s, and starts at direct form II.

After the clip, choose a structure with its button to compare their insides.

The output panel never changes. In floating point the three outputs differ by less than 10−1410^{-14}, rounding noise in the last digits. What differs is the inside: direct form I and the transposed form keep numbers no bigger than the output, while direct form II’s w[n]w[n] is about three times bigger.

Why? By Properties of LTI systems (5.4), once the start-up has died away, a sine that goes in comes out as a sine at the same frequency, scaled by the gain there. At 1 kHz the biquad’s gain is ∣H∣=5.010\lvert H\rvert=5.010, but the poles alone give ∣1/A∣=14.83\lvert 1/A\rvert=14.83. And w[n]w[n] is the input through the poles alone.

The zeros pull the output back down. They sit on the circle at 1276 Hz, not far from 1 kHz, so ∣B∣\lvert B\rvert is only 0.3378 there. So ww is bigger than yy by 1/∣B∣=2.9601/\lvert B\rvert=2.960, and the peaks on screen have the same ratio. They are a little lower than 5.010 and 14.83 because here the eight samples of a cycle never land exactly on a crest.

Three more ways to build it

The same biquad can be built in three more ways, and the figure draws each with its numbers. The transposed form is the one from the equations above. The parallel form splits H(z)H(z) into a sum of simpler filters that all see the same input.

The lattice builds the poles’ half, 1/A(z)1/A(z), from two stages. One wire runs forwards from x[n]x[n] to y[n]y[n], and one runs back through the delays. Each stage has one number, its reflection coefficient: k2k_2 for the stage the input enters, k1k_1 for the next. In stage 1 two gains, k1k_1 and −k1-k_1, cross between the wires; stage 2 needs only −k2-k_2.

This biquad has b0=b2=1b_0=b_2=1. As in 6.1, a gain of 1 is not drawn, so two wires of (a) have no triangle.

(a) transposedx[n]−1.0764+++z⁻¹s₁[n]z⁻¹s₂[n]y[n]1.3322−0.9076(b) parallelx[n]1.1018−0.1018 + 0.3915z⁻¹1 − 1.3322z⁻¹ + 0.9076z⁻²+y[n](c) lattice, 1/A(z)x[n]++y[n]z⁻¹+z⁻¹−k₂−k₁k₁k₂ = 0.9076k₁ = −0.6984
Fig. One biquad, three more structures. The lattice’s reflection coefficients are both between −1 and 1, which is exactly 16.4’s stability triangle: k₂ = a₂ and k₁ = a₁/(1 + a₂).

Transposing. A branch point is a dot where one wire splits into several. To transpose a block diagram, reverse every arrow, turn every adder into a branch point and every branch point into an adder, and swap input and output. The result has the same H(z)H(z).

Transposing direct form II gives (a). In direct form II each tap of the delay column is a branch point, feeding a bb gain and an aa gain. In (a) those taps have become adders, which is why its delays hold sums. The Linear Algebra note below gives a one-line reason the rule works.

Parallel. In Properties and the inverse z-transform (16.2), residuez split a ratio of polynomials into a direct term plus one fraction per pole. Do that here, then add the two fractions of the mirror pair back together, so that the coefficients are real:

H(z)=1.1018+−0.1018+0.3915z−11−1.3322z−1+0.9076z−2.\begin{aligned} H(z)&=1.1018\\ &+\frac{-0.1018+0.3915z^{-1}}{1-1.3322z^{-1}+0.9076z^{-2}}. \end{aligned}

That is (b): a constant beside a second-order branch, both fed x[n]x[n], their outputs added. A longer filter gets one real branch per pair of poles, two delays each.

Cascade. Or keep the biquads one after another, the output of one feeding the next. SciPy’s sosfilt runs 20.6’s whole filter this way, and it is the subject of Second-order sections (21.2).

Lattice. Follow the wires of (c) back from y[n]y[n], stage by stage, and the input comes out as

x[n]=y[n]+k1(1+k2) y[n−1]+k2 y[n−2].\begin{aligned} x[n]&=y[n]+k_1(1+k_2)\,y[n-1]\\ &\quad+k_2\,y[n-2]. \end{aligned}

That is the equation of 1/A(z)1/A(z) when a1=k1(1+k2)a_1=k_1(1+k_2) and a2=k2a_2=k_2. Turned round, k2=a2k_2=a_2 and k1=a1/(1+a2)k_1=a_1/(1+a_2).

Now the reason to use it. Stability and causality (16.4) said both poles are inside the circle when ∣a2∣<1\lvert a_2\rvert < 1, 1+a1+a2>01+a_1+a_2 > 0 and 1−a1+a2>01-a_1+a_2 > 0. In terms of the kk‘s, the first is ∣k2∣<1\lvert k_2\rvert < 1, which makes 1+k21+k_2 positive. The last two are (1+k2)(1+k1)>0(1+k_2)(1+k_1) > 0 and (1+k2)(1−k1)>0(1+k_2)(1-k_1) > 0.

So the stability triangle is just ∣k1∣<1\lvert k_1\rvert < 1 and ∣k2∣<1\lvert k_2\rvert < 1. You can read stability straight off the lattice’s gains. Here k2=0.9076k_2=0.9076 and k1=−0.6984k_1=-0.6984, so the biquad is stable.

The maths behind it · state-space realisations

Every structure is a state-space realisation, s[n+1]=As[n]+bx[n]\mathbf{s}[n+1]=\mathbf{A}\mathbf{s}[n]+\mathbf{b}x[n] and y[n]=c⊤s[n]+dx[n]y[n]=\mathbf{c}^\top\mathbf{s}[n]+dx[n], where s\mathbf{s} holds the stored values. A change of coordinates s=Ts′\mathbf{s}=\mathbf{T}\mathbf{s}' gives another structure with the same H(z)H(z) and differently sized stored values. Transposition is A→A⊤\mathbf{A}\to\mathbf{A}^\top with b\mathbf{b} and c\mathbf{c} swapped: the transfer function is a single number, and a number equals its own transpose.

Worked example

1. Counting. For a biquad, direct form I has 4 delays, direct form II has 2 and the transposed form has 2. All three have 5 multipliers, or 4 when b0=1b_0=1. This lesson’s biquad also has b2=1b_2=1, so it needs only 3.

2. Three samples by hand. The input starts x[0]=0x[0]=0, x[1]=0.7071x[1]=0.7071, x[2]=1x[2]=1. Direct form II gives w[0]=0w[0]=0 and w[1]=0.7071w[1]=0.7071, then w[2]=1+1.3322⋅0.7071=1.9420w[2]=1+1.3322\cdot0.7071=1.9420. The output is y[1]=w[1]=0.7071y[1]=w[1]=0.7071 and y[2]=1.9420−1.0764⋅0.7071=1.1809y[2]=1.9420-1.0764\cdot0.7071=1.1809. Already ww is bigger than yy.

3. The parallel form. residuez(b, a) gives the residues −0.05091∓0.23762j-0.05091\mp0.23762j at the poles 0.66612±0.68108j0.66612\pm0.68108j, and the direct term 1.10182. Combined, the branch numerator is −0.10182+0.39150z−1-0.10182+0.39150z^{-1}. Check at z=1z=1. There the branch’s top is −0.10182+0.39150=0.28968-0.10182+0.39150=0.28968 and its bottom is A(1)=0.57535A(1)=0.57535, so H(1)=1.10182+0.28968/0.57535=1.6053H(1)=1.10182+0.28968/0.57535=1.6053, the gain at DC.

4. The lattice. k2=a2=0.90759k_2=a_2=0.90759 and k1=a1/(1+a2)=−1.33224/1.90759=−0.69839k_1=a_1/(1+a_2)=-1.33224/1.90759=-0.69839. Both are between −1 and 1, so the biquad is stable.

Where you’ll meet this

Audio code often runs the transposed form in floating point: it has the fewest stored values and good numerics. Fixed-point DSP chips often use direct form I. Its five products add up in one wide running total, the accumulator, and it stores only inputs and outputs, so nothing it stores outgrows them.

Speech coders use lattices, because their reflection coefficients show stability at a glance (Parametric models and linear prediction, 25.3). Next come cascades of biquads in Second-order sections (21.2), and overflow and word length in Finite word-length effects (21.3). Polyphase structures for changing the sample rate are in Polyphase structures (22.4).

The maths behind it · partial autocorrelations

The lattice’s reflection coefficients are, up to sign, the partial autocorrelations of time-series analysis. The Levinson recursion (25.3) produces them, and an AR model is stationary exactly when they all lie between −1 and 1.

Reference card

StructureDelays (biquad)What it stores
Direct form I4past inputs and outputs
Direct form II2w[n]w[n]: input through the poles; can be large
Transposed II2running sums; SciPy lfilter
Cascade2 per biquad21.2
Parallel2 per branchfrom residuez
Lattice2reflection coefficients; stable ⇔ all ∣ki∣<1\lvert k_i\rvert < 1
Transpositionreverse every arrow, swap in and outsame H(z)H(z)

End of lesson 21.1

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look