Skip to content

Designing IIR filters

An FIR filter computes each output from recent inputs only. An infinite impulse response (IIR) filter also feeds its own recent outputs back in. That feedback is what makes IIR filters so efficient, since a handful of coefficients can do the work of hundreds of FIR taps. It’s also the source of their complications: they can be unstable, and they can’t have linear phase.

This page builds up slowly. It starts with the simplest feedback loop, derives its frequency response with nothing more than the algebra from the FIR page, and only then introduces the notation (z, poles, zeros) that the classic designs are described in.

Frequencies are normalised as on the FIR page: cycles per sample, 0 to 0.5 (Nyquist).

The moving average smooths a signal by averaging the last MM inputs, which costs MM multiplies per sample. Here’s a cheaper way to smooth: keep a running estimate, and nudge it a little towards each new input.

y[n]=(1−a) x[n]+a y[n−1]y[n] = (1-a)\,x[n] + a\,y[n-1]

Each output is a blend of the new input and the previous output, with aa (between 0 and 1) setting the mix. With a=0a = 0 the output is just the input. With a=0.8a = 0.8 each output is 80 % “what I said last time” and 20 % “what just came in”. This is the exponentially weighted moving average.

The two weights (1−a)(1-a) and aa add up to 1. That’s why the input is scaled by (1−a)(1-a): feed in a steady value cc and the output settles at exactly cc, since c=(1−a)c+acc = (1-a)c + ac. You’ll also often see the unscaled version, y[n]=x[n]+a y[n−1]y[n] = x[n] + a\,y[n-1]. It has exactly the same shape of response, just 1/(1−a)1/(1-a) times louder (10× for a=0.9a = 0.9). It’s slightly tidier for algebra. Both are common, and the figure below lets you switch between them.

Feed it an impulse (a single 1, then zeros). The first output is (1−a)(1-a). After that the input is zero, so each output is just aa times the previous one: (1−a)(1-a), (1−a)a(1-a)a, (1−a)a2(1-a)a^2, (1−a)a3(1-a)a^3, … Each output is fed back in, so the response never quite ends. That’s where the name infinite impulse response comes from. However long that tail, it costs two multiplies per sample.

Top: the impulse response: each sample is the previous one times aa. Middle: the response to a step (a switch from 0 to 1), which creeps up to 1, more slowly the larger aa is. Bottom: the frequency response, a low-pass. Untick the scaling to see the same shapes 1/(1−a)1/(1-a) times bigger. Then push ∣a∣|a| to 1 or beyond: the response no longer decays, it runs away. Feedback can make a filter unstable, which an FIR filter can never be. (Negative aa makes the impulse response alternate in sign, which emphasises high frequencies instead.)

As with FIR filters, a sinusoid going in comes out as a sinusoid of the same frequency, only scaled and shifted in time. Here’s the one-pole filter with a test sinusoid:

Top: a sinusoid in (grey) and out (blue). Bottom: the gain at every frequency, with the measured gain as a dot. Two things to notice. Higher frequencies come out smaller: it’s a low-pass. And the output lags the input, but by an amount that depends on the frequency: about a/(1−a)a/(1-a) samples (4 for a=0.8a = 0.8) at low frequencies, and less as the frequency rises. A symmetric FIR filter delays every frequency by the same amount. This frequency-dependent delay is the “price in phase” that section 8 comes back to.

2 · The frequency response, without any new maths

Section titled “2 · The frequency response, without any new maths”

Where does that gain curve come from? On the FIR page we used one fact about sinusoids: delaying a sinusoid by one sample multiplies it by e−jωe^{-j\omega}. Here ω=2πf\omega = 2\pi f is the angle the sinusoid turns through per sample, and multiplying by e−jωe^{-j\omega} turns it back by one sample’s worth.

So feed the filter a sinusoid xx. The output yy is a sinusoid too, and its previous sample y[n−1]y[n-1] is just e−jω ye^{-j\omega}\,y. The filter’s equation becomes plain algebra:

y=(1−a) x+a e−jω y⟹y (1−a e−jω)=(1−a) x⟹H(ω)=yx=1−a1−a e−jωy = (1-a)\,x + a\,e^{-j\omega}\,y \quad\Longrightarrow\quad y\,\big(1 - a\,e^{-j\omega}\big) = (1-a)\,x \quad\Longrightarrow\quad H(\omega) = \frac{y}{x} = \frac{1-a}{1 - a\,e^{-j\omega}}

H(ω)H(\omega) is a complex number: its size is the gain and its angle is the phase shift. To get the gain we need the size of the bottom line, ∣1−a e−jω∣|1 - a\,e^{-j\omega}|. Multiply the inside by ejωe^{j\omega}, whose size is 1, so the size doesn’t change. That gives ∣ejω−a∣|e^{j\omega} - a|. Now:

  • ejωe^{j\omega} is the point on the unit circle (the circle of radius 1 around 0 in the complex plane) at angle ω\omega. As the frequency goes from 0 to Nyquist, the angle goes from 0° to 180°: the point walks round the top half of the circle.
  • aa is just a point on the horizontal (real) axis.
  • The size of the difference between two points is the distance between them.

So the gain is

∣H(ω)∣=1−adistance from the point at angle ω to the point a|H(\omega)| = \frac{1-a}{\text{distance from the point at angle } \omega \text{ to the point } a}

Left: the unit circle, the point aa (×) and the point at the current frequency (green), joined by the dashed line whose length we need. Right: the gain, traced out as you go. Press Walk round the circle. At 0° (DC) the point is as close to aa as it gets: the distance is 1−a1-a, so the gain is 1. At 180° (Nyquist) it’s furthest away: the distance is 1+a1+a. Move aa towards the circle and the gain near DC gets sharper. Move it to the left of centre and the filter favours high frequencies instead. Notice that the gain then rises above 1, to (1−a)/(1+a)(1-a)/(1+a) at Nyquist (4 for a=−0.6a = -0.6), even though the pole is safely inside the circle. Being inside the circle guarantees stability (the impulse response dies away), not a gain of at most 1. The (1−a)(1-a) scaling only pins the gain at DC to 1. A high-pass would normally be scaled by (1+a)(1+a) instead, which pins the gain at Nyquist to 1.

The point aa is the filter’s pole. If the walking point ever landed exactly on it, the distance would be zero and the gain infinite. Notice the stability rule from section 1: the impulse response (1−a) an(1-a)\,a^n dies away only if ∣a∣<1|a| < 1. In other words, the filter is stable only if its pole is inside the unit circle.

3 · The general recipe: b’s, a’s, poles and zeros

Section titled “3 · The general recipe: b’s, a’s, poles and zeros”

A general IIR filter makes each output from a weighted sum of recent inputs and recent outputs:

y[n]=b0 x[n]+b1 x[n−1]+⋯+bM x[n−M]  −  a1 y[n−1]−a2 y[n−2]−⋯−aN y[n−N]y[n] = b_0\,x[n] + b_1\,x[n-1] + \dots + b_M\,x[n-M] \;-\; a_1\,y[n-1] - a_2\,y[n-2] - \dots - a_N\,y[n-N]
  • The b’s are the feed-forward coefficients. They’re exactly FIR taps. If every aa were zero, this would be an FIR filter.
  • The a’s are the feedback coefficients.

The minus signs in front of the feedback terms are a convention. Move the feedback terms to the left-hand side and the equation tidies into “outputs on the left, inputs on the right”: y[n]+a1y[n−1]+⋯=b0x[n]+b1x[n−1]+…y[n] + a_1 y[n-1] + \dots = b_0 x[n] + b_1 x[n-1] + \dots. The catch is that the convention flips the sign of a feedback coefficient. The one-pole filter y[n]=(1−a) x[n]+a y[n−1]y[n] = (1-a)\,x[n] + a\,y[n-1] in this notation is:

coefficientvalue for the one-pole filter
b0b_01−a1 - a
b1,b2,…b_1, b_2, \dots0
a1a_1−a-a (note the sign)
a2,a3,…a_2, a_3, \dots0

The transfer function, and where z comes from

Section titled “The transfer function, and where z comes from”

Use the same trick as section 2: a sinusoid delayed by kk samples is multiplied by e−jkωe^{-jk\omega}. Every term becomes a multiple of xx or yy, and solving for y/xy/x gives

H(ω)=b0+b1e−jω+⋯+bMe−jMω1+a1e−jω+⋯+aNe−jNωH(\omega) = \frac{b_0 + b_1 e^{-j\omega} + \dots + b_M e^{-jM\omega}}{1 + a_1 e^{-j\omega} + \dots + a_N e^{-jN\omega}}

The top line is the FIR page’s frequency-response formula with the b’s as taps. The bottom line is what the feedback adds.

Writing ejωe^{j\omega} everywhere gets clumsy, and soon we’ll want to ask where the top and bottom lines equal zero. Those places usually aren’t on the unit circle. So we give the point a name, zz, and let it be any complex number, anywhere in the plane:

H(z)=b0+b1z−1+⋯+bMz−M1+a1z−1+⋯+aNz−NH(z) = \frac{b_0 + b_1 z^{-1} + \dots + b_M z^{-M}}{1 + a_1 z^{-1} + \dots + a_N z^{-N}}

This is the filter’s transfer function, and the plane that zz lives in is the z-plane. That’s all zz is. Put zz back on the unit circle (z=ejωz = e^{j\omega}) and you have the frequency response again. For the one-pole filter, H(z)=(1−a) / (1−az−1)H(z) = (1-a)\,/\,(1 - a z^{-1}).

First, one piece of notation. You know Σ\Sigma (capital sigma) means “add these up”. ∏\prod (capital pi, for “product”) means “multiply these together”:

∑i=13ci=c1+c2+c3∏i=13ci=c1×c2×c3\sum_{i=1}^{3} c_i = c_1 + c_2 + c_3 \qquad\qquad \prod_{i=1}^{3} c_i = c_1 \times c_2 \times c_3

Like any polynomial, the top and bottom of H(z)H(z) can be factored. For example, 1−0.9z−1+0.2z−2=(1−0.4z−1)(1−0.5z−1)1 - 0.9z^{-1} + 0.2z^{-2} = (1 - 0.4z^{-1})(1 - 0.5z^{-1}): multiply it out and check. A factor (1−rz−1)(1 - r z^{-1}) is zero exactly when z=rz = r, so factoring finds the places where the polynomial is zero. Factor both lines:

H(z)=k (1−q1z−1)(1−q2z−1)⋯(1−p1z−1)(1−p2z−1)⋯=k ∏i(1−qiz−1)∏i(1−piz−1)H(z) = k\,\frac{(1 - q_1 z^{-1})(1 - q_2 z^{-1})\cdots}{(1 - p_1 z^{-1})(1 - p_2 z^{-1})\cdots} = k\,\frac{\prod_i (1 - q_i z^{-1})}{\prod_i (1 - p_i z^{-1})}
  • The qiq_i, where the top is zero, are the filter’s zeros: there, H=0H = 0.
  • The pip_i, where the bottom is zero, are its poles: there, HH would be infinite.
  • kk is an overall gain (k=b0k = b_0).

(Books usually write the zeros as ziz_i, which is easy to confuse with the variable zz. They’re specific points, so this page uses qiq_i.)

Each factor works exactly like the one-pole filter’s bottom line: on the unit circle, its size is the distance from the point at angle ω\omega to that root. So

∣H(ω)∣=∣k∣×∏i(distance to zero qi)∏i(distance to pole pi)|H(\omega)| = |k| \times \frac{\prod_i \big(\text{distance to zero } q_i\big)}{\prod_i \big(\text{distance to pole } p_i\big)}

As the point walks round the circle, passing near a zero pulls the gain down (a small number on top) and passing near a pole pushes it up (a small number underneath). And the stability rule generalises: each pole adds a pnp^n term to the impulse response, so the filter is stable exactly when every pole is inside the unit circle. Zeros can go anywhere.

Poles don’t have to sit on the horizontal axis. They can be anywhere in the plane: complex numbers. But a filter whose coefficients are ordinary real numbers can only have complex poles in mirror-image pairs, reflected in the horizontal axis. Here’s why. Describe the upper pole by its distance rr from the centre and its angle θ\theta, and multiply out its factor together with its mirror image’s. The imaginary parts cancel, leaving real coefficients:

(1−p z−1)(1−p∗z−1)=1−2rcos⁡θ  z−1+r2 z−2⟹a1=−2rcos⁡θ,a2=r2\big(1 - p\,z^{-1}\big)\big(1 - p^*z^{-1}\big) = 1 - 2r\cos\theta\;z^{-1} + r^2\,z^{-2} \qquad\Longrightarrow\qquad a_1 = -2r\cos\theta,\quad a_2 = r^2

(p∗p^*, the complex conjugate, is pp reflected in the horizontal axis.) So the filter is

y[n]=b0 x[n]+2rcos⁡θ  y[n−1]−r2 y[n−2]y[n] = b_0\,x[n] + 2r\cos\theta\;y[n-1] - r^2\,y[n-2]

Left: a pair of poles at radius rr and angle ±θ\pm\theta, with the walking point and its distances to both. Right: the gain, and the impulse response. As the point passes angle θ\theta it comes close to the upper pole, so the product of the distances gets small and the gain peaks at frequency θ/2π\theta / 2\pi. The lower pole stays far away and just tilts the curve a little. Push rr towards 1: the peak gets taller and narrower, and the impulse response rings for longer. It’s a sinusoid at the peak frequency, decaying like rnr^n, like a struck bell. That’s a resonance, and it’s what IIR filters are made of. (With rr exactly 1 the ringing never decays: you’ve built an oscillator.)

Now put it all together. Add zeros (which pull the gain down) to poles (which push it up), and almost any response shape is possible.

Listen:

Left: the z-plane. Poles are ×, zeros are ○; drag either half of a mirror-image pair. The green dot is the probe frequency, with dashed lines to every root, and the line under the plot multiplies those distances out to give ∣H∣|H| there. Right: the magnitude, the group delay (how long each frequency is held up, in samples), and the impulse response. Things to try:

  • Notch: a zero exactly on the circle kills one frequency completely. The pole just inside it, at the same angle, keeps the notch narrow, because away from the notch the zero’s and the pole’s distances nearly cancel.
  • All-pass: each pole has a zero at the mirror-image position outside the circle (at radius 1/r1/r). Their distances stay in a fixed ratio all the way round, so the gain is flat: only the delay changes. All-pass filters adjust phase, and they’re the building blocks of reverbs and phasers.
  • 2nd-order low-pass: two zeros at Nyquist (180°) pin the top of the band to zero, while a pole pair near DC lifts the bottom.
  • Unstable: a pole outside the circle. Its pnp^n grows, and so does the output.
  • Add your own poles and zeros, and watch the response follow the distances.

Two poles and two zeros, the biquad, is enough for any single resonance, notch, shelf or second-order roll-off. Larger IIR filters are almost always built as a cascade of biquads, not as one big high-order polynomial. Rounding errors in the coefficients of a high-order polynomial move its roots a long way, and poles near the unit circle (exactly where sharp filters put them) can be nudged right outside it. Second-order sections keep each pair of poles under separate, well-conditioned control.

For audio, the standard recipes are Robert Bristow-Johnson’s Audio EQ Cookbook: closed-form biquad coefficients for each type of EQ, from a centre frequency, a Q (sharpness) and a gain.

Listen:

Left: the biquad’s poles and zeros. Right: its magnitude on a log-frequency axis, as an audio EQ shows it. Raising Q pulls the poles towards the unit circle: a sharper peak or notch. A peaking boost puts the poles slightly closer to the circle than the zeros; a cut swaps them round. These five numbers are the whole filter, and running it costs 5 multiplies per sample.

7 · Borrowing from analogue: how the classic recipes are made

Section titled “7 · Borrowing from analogue: how the classic recipes are made”

Placing poles by hand works for one biquad, but how do you design, say, a 60 dB low-pass with a sharp transition? Analogue electronics solved this decades before digital filters existed, with closed-form optimal designs. The usual digital approach is to design an analogue filter, then convert it.

You can use the results without following this section’s analogue theory. The designer further down does all of it for you, and the families are described by what they do. But if you’re curious how the recipes are made:

Analogue filters have a transfer function too, written H(s)H(s). ss plays the role of zz, and the picture is the same with one change: in the ss-plane the frequency axis is the vertical axis (the imaginary axis), not the unit circle. So the walking point goes straight up the vertical axis as the frequency rises, all the way to infinity, and the gain is still distances to zeros over distances to poles. Stable analogue poles sit in the left half of the plane, instead of inside the circle.

To turn an analogue design into a digital one, you need a way to bend that infinite vertical line into the unit circle. The standard one is the bilinear transform, a substitution of one variable for the other:

s=2 z−1z+1⟹Ωanalogue=2tan⁡(πf)s = 2\,\frac{z - 1}{z + 1} \qquad\Longrightarrow\qquad \Omega_\text{analogue} = 2 \tan(\pi f)

It maps the analogue frequency axis onto the unit circle exactly once. Stable analogue filters (poles in the left half-plane) become stable digital ones (poles inside the circle), and there’s no aliasing. But the mapping isn’t linear. The infinite analogue frequency axis gets squeezed into 0 to fs/2f_s/2, increasingly hard towards the top. So you pre-warp: ask the analogue design for the cutoff 2tan⁡(πfc)2\tan(\pi f_c), which lands exactly on fcf_c after the squeeze.

Top: the warping curve. Analogue frequencies (horizontal) map to digital ones (vertical). Low frequencies map almost one-to-one; everything else is crammed in below Nyquist. Bottom: a Butterworth low-pass designed for the cutoff you set. Without pre-warping, the cutoff lands too low. That’s barely noticeable at 0.05, but at 0.3 it’s well off. Tick pre-warp and it lands exactly on target. Either way, the squeeze sharpens the roll-off near Nyquist compared with the analogue original.

There are four classic analogue families. All are low-pass prototypes; high-pass, band-pass and band-stop versions come from frequency transformations of them.

  • Butterworth: maximally flat, with no ripple anywhere and a smooth but slow roll-off. Its analogue poles sit evenly spaced on a semicircle.
  • Chebyshev type I: allows ripple in the passband in exchange for a much steeper roll-off. The poles move onto an ellipse.
  • Chebyshev type II: flat passband, ripple in the stopband instead. It adds zeros, which land on the unit circle and give nulls in the stopband.
  • Elliptic (Cauer): ripple in both bands. It’s the sharpest possible transition for a given order, which makes it the IIR counterpart of FIR equiripple design.
Listen:

Set a spec and pick a family. By default the order is the minimum that meets the spec, computed from each family’s closed-form order formula. Left: poles and zeros (Butterworth’s poles form a curved column; Chebyshev II and elliptic add zeros on the unit circle). Right: magnitude with the spec mask, a close-up of the passband, and the group delay. The table is the punchline. For the default spec, Butterworth needs order 23, Chebyshev order 9, and elliptic just order 6: three biquads, 15 multiplies per sample. An equiripple FIR filter meeting the same spec needs 63 taps, plus a 31-sample delay. Untick minimum order and lower the order to see the spec fail.

That efficiency isn’t free. A symmetric FIR filter delays every frequency by exactly the same amount (linear phase). An IIR filter can’t. Its group delay varies with frequency, and it peaks near the band edge, where the poles crowd up against the unit circle. Different frequencies come out at different times, so the waveform’s shape changes even inside the passband.

An elliptic IIR filter and an equiripple FIR filter built to the same spec. Top: their group delay. The FIR filter’s is a flat line; the IIR filter’s is small at low frequencies but rises steeply near the band edge. Bottom: the two filters’ outputs for the same input, each shifted back by its own low-frequency delay so they line up with the input (dashed). The FIR filter rings symmetrically, before each edge as well as after (pre-ringing). The IIR filter rings only afterwards, but with a lopsided shape, because the high frequencies near the cutoff arrive late. (Its output also sits a little low: an even-order elliptic filter’s gain at DC is at the bottom of its passband ripple.) Neither is wrong; they’re different trade-offs. The FIR filter is also much more expensive and has a much longer delay.

When the whole signal is available in advance (offline processing, not real time), there’s a trick: filter forwards, then filter the result backwards. The phase shifts cancel exactly, giving zero phase, and the magnitude response is applied twice. This is MATLAB’s and scipy’s filtfilt.

FIRIIR
Cost for a sharp filterHigh: tens to hundreds of multiplies per sampleLow: a few biquads
PhaseLinear phase possible: no waveform distortionNon-linear; group delay peaks near the band edge
DelayLong: (N−1)/2(N-1)/2 samples, the same for every frequencyShort at low frequencies, larger near the edge
StabilityAlways stableStable only if every pole is inside the unit circle
Numerical behaviourForgivingSensitive near the unit circle, so use cascaded biquads
Arbitrary response shapesEasy (any magnitude, via design methods like Parks–McClellan)Natural for classic shapes (low-pass, EQ); harder otherwise

And among the IIR families:

FamilyPassbandStopbandOrder needed
ButterworthMaximally flatMonotonicHighest
Chebyshev IEquirippleMonotonicMedium
Chebyshev IIFlatEquiripple (with nulls)Medium
EllipticEquirippleEquirippleLowest

In audio, IIR biquads dominate EQ, tone controls and crossovers, because they’re cheap, have short delay, and suit analogue-style responses. FIR filters win where phase matters (measurement, linear-phase mastering EQ, some crossovers) or where the response shape is arbitrary.

  • Robert Bristow-Johnson, Audio EQ Cookbook: the biquad formulas used above.
  • Julius O. Smith III, Introduction to Digital Filters: a free online book, excellent on poles, zeros and biquads.
  • S. J. Orfanidis, “Lecture notes on elliptic filter design” (2006): the elliptic-function method this page implements.
  • A. V. Oppenheim and R. W. Schafer, Discrete-Time Signal Processing, chapter 7: the bilinear transform and the classic families.