One spec can be met by an FIR filter or by an IIR filter. Below, both are drawn against the same spec, and then their delays. Watch the delay panel: one line stays flat, and the other climbs at the band edge.
One spec, two filters
The running spec: 19.3's 26-tap equiripple FIR and an elliptic IIR of order 5.
The running spec as zones: two filters will meet it.
Describe this picture
Two stacked panels for the running spec, 19.3’s 26-tap equiripple FIR and an elliptic IIR of order 5. The first is drawn like the spec drawings of 18.1: the gain from −80 to 5 dB against frequency from 0 to 4000 Hz, with the running spec’s zones. The second shows the group delay of 12.4 across the pass band, from 0 to 25 samples against frequency from 0 to 1000 Hz. In both panels the FIR filter is the dashed curve and the IIR filter the solid curve. The readouts are the multiplies per sample and the delay at 250 Hz and at 1000 Hz, each in samples to one decimal, in the form “FIR 12.5, IIR 3.6”. Before a filter is drawn, a readout shows “not yet”.
The clip lasts 14 s. At the start only the zones are drawn. Then the FIR’s curves draw and hold: 26 taps, it passes, and it delays every frequency by the same 12.5 samples, 1.6 ms. Then the IIR draws. It also passes, with 11 multiplies a sample; its delay is 3.6 samples at 250 Hz but 23.1 at the band edge. After the clip a dotted cursor named “Frequency” appears on the delay panel and moves from 0 to 1000 Hz in steps of 10 Hz. The arrow keys move it by 10 Hz, Page Up and Page Down by 100 Hz, and Home and End jump to the two ends. While it moves, the two delay readouts become one, the delay at the cursor, and the caption reads like “750 Hz: FIR 12.5 samples, IIR 6.7.”; at 1000 Hz it is the end caption again. The cursor’s place is kept in the link, as two.f.
One spec, two filters
You now know two ways to build a low-pass filter. Chapter 19 built FIR filters, with a finite list of taps. Chapter 20 built IIR filters, which feed their own outputs back. Both can meet the same spec, so which one should you use? This page puts the two side by side, on the spec you know best.
That is the running spec of Filter specifications (18.1). The sample rate is 8 kHz. From 0 to 1 kHz the gain must stay within , and from 1.5 kHz to 4 kHz it must stay at or below 0.01, which is 40 dB down.
The FIR candidate is the shortest design of Optimal FIR design (19.3): the equiripple filter with 26 taps and stop-band weight 5. Its pass band strays from 0.9565 to 1.0436, and its stop band reaches −41.08 dB.
The IIR candidate is the elliptic filter of Analog prototype filters (20.1), turned digital by IIR design by the bilinear transform (20.2). Analog frequency is ω (rad/s), digital frequency is Ω (rad/sample); Oppenheim and Schafer use the opposite letters. An IIR filter’s gain peaks at 1, so its pass band is written as a loss: at most dB. SciPy’s ellipord asks for order 5, and ellip(5, 0.4455, 40, 1000, fs=8000) designs it.
How do we compare their cost? Each output sample takes a fixed number of multiplications, so I count multiplies per sample. The FIR filter computes , so it needs 26.
Its taps are symmetric, (17.3). So you can add each pair of inputs first and multiply once:
That is 13 multiplies.
The IIR filter is a difference equation, as in Difference equations (6.1). With the numbers that multiply inputs and the numbers that multiply past outputs,
There are six and five ( needs no multiply), so 11 multiplies. Computed this way, straight from the difference equation, the filter is in what Filter structures (21.1) calls direct form.
So the IIR filter costs 11 multiplies, against 26 for the FIR, or 13 if you use the symmetry. That is less than half. What does it cost in other ways? The picture at the top of the page draws both filters against the running spec, and then their delays.
After the clip, a dotted cursor on the delay panel reads both delays; drag it, or use the arrow keys. Move it from 0 Hz to the band edge. The dashed FIR line never moves from 12.5. The solid IIR curve starts at 3.7 samples, dips a little, passes 4.2 at 500 Hz and 9.4 at 900 Hz, then climbs fast: 14.0 at 950 Hz and 23.1 at 1000 Hz.
Notice the band edge. There the IIR filter is the slower of the two, by more than 10 samples. Below about 940 Hz the solid curve is the lower one, and above it the dashed line is.
Think of two ways to drive across a city. The short cut through town is faster on average, but its time depends on the traffic. The motorway always takes the same time. The FIR filter is the motorway: every frequency arrives 12.5 samples late. The IIR filter is the short cut.
Why does the delay climb at the edge? In 20.1 you saw that a steep edge bends the delay near the cutoff. The elliptic filter has the steepest edge for its order, and it buys it with a pole pair at radius 0.9527, close to the unit circle. Their angle, ±45.64°, is the frequency 1014 Hz, just past the pass-band edge.
What does a changing delay do to a signal? Linear-phase systems (17.3) showed it: a bent phase delays the slow parts of a pulse by one amount and the fast parts by another, so the pulse comes apart. A straight phase only moves it.
So the IIR filter is cheaper and, at low frequencies, quicker, but it changes the shape of a waveform. The FIR filter keeps the shape and is late by the same amount everywhere.
Run it forwards, then backwards
Is there a way to have the IIR filter’s low cost and still keep the shape? If the whole signal is already stored, yes. Run the filter over the signal, then run it again over the result, from the last sample back to the first.
The backwards run is the reversal of Shifting, reversing and scaling time (2.1). I reverse the signal, filter it as usual, and reverse the output.
Call the first output , so . Reversing gives , as in Properties of the DTFT (12.3). Filtering multiplies by , and the last reversal replaces by again:
The impulse response is real, so by 12.3, . A number times its conjugate is its size squared:
The gain is real and never negative, so it adds no phase at all. I call this forward–backward filtering, or zero-phase filtering. Every frequency is delayed by zero samples, and nothing changes shape through the phase. The price is that the gain is squared: the pass band now lies between and 1, and the stop band at , 80 dB down.
In SciPy this is scipy.signal.filtfilt(b, a, x). The instrument below does it by hand on a pulse, with the elliptic filter of the first instrument. It marks each output’s centre with a dot; by centre I mean 17.3’s balance point, . Watch where the dot sits after each pass.
Run it forwards, then backwards
A 24-sample pulse through the elliptic filter of clip 1: forwards, then the result backwards.
A 24-sample pulse, centred at n = 199.5.
Describe this picture
Two stacked panels for a 24-sample pulse through the elliptic filter of the first instrument: forwards, then the result backwards. They share the sample axis, from 170 to 240, and a vertical axis from −0.2 to 1.25. The first, “forwards”, shows the input as a thin dashed outline and the forward output as a solid curve. The second, “forwards, then backwards”, shows the same input outline and the final output as a solid curve. Each output has a dot at its centre. The readouts are how far the centre moved, in samples to two decimals, and the stop band, in dB to one decimal. There is no control.
The clip lasts 13 s. At the start only the input is drawn, a 24-sample pulse centred at . Then the forward output builds from the first sample to the last. When it holds, the pulse arrives 3.72 samples late, overshoots to 1.154 and rings only after its edges, and the stop band reads −40.0 dB. Next the forward output is filtered again from the end backwards, and the second output builds from the last sample to the first. At the end it is centred on the input (moved 0.00), symmetric, ringing equally before and after, and the stop band is now −80.0 dB; the caption adds that this is only possible when the whole signal is stored.
Look at the first panel first. The forward output is the pulse with its corners rounded and a ripple after each edge. Before it is exactly zero: a filter that runs in real time cannot react to an edge before the edge arrives.
The centre moved by 3.72 samples, and that is no accident. The centre of a filter’s output moves by the centre of its impulse response, , and for a real that equals the group delay at 0 Hz, 3.717 samples.
Now the second panel. The output is symmetric about , the centre of the input. Its ripples dip to −0.047 before the pulse and again after it, and its peak, 1.065, is lower than the forward peak.
That ripple before the pulse is the thing to notice. No real-time filter can produce it, because it is a reaction to an edge that has not arrived yet. The backward pass saw the future, because the whole signal was stored.
Think of combing tangled hair. Comb only from the left, and the hair ends up pushed to the right. Comb from the left and then from the right, and no side is favoured.
So forward–backward filtering suits recordings: a stored ECG, offline audio, a column of data in a data-science notebook. It never suits a live stream, because the backward pass needs samples that have not arrived yet.
FIR or IIR: a checklist
Here is how I decide. Each row names a need, the filter it points to, and the reason.
| Your task needs | Choose | Why |
|---|---|---|
| linear phase, or a waveform’s exact shape | FIR, or IIR forwards and backwards if the data are stored | a constant delay keeps the shape (17.3) |
| a tight delay budget at low frequencies, a steep edge, little computation | IIR | fewer multiplies and a short delay where most of the signal lies |
| a filter that adapts or is redesigned often | FIR | always stable and simple to update (Adaptive filters: LMS, 26.3) |
| fixed point with few bits | FIR, or IIR as second-order sections, with care | rounded IIR coefficients can move poles (Second-order sections, 21.2; Finite word-length effects, 21.3) |
| a very long or very narrow FIR filter | FFT convolution or multirate | Fast convolution (14.3); Downsampling and decimation (22.1) |
For the running spec, in one line each: the FIR filter costs 26 multiplies and delays every frequency by 12.5 samples. The IIR filter, order 5, costs 11 multiplies and delays from 3.5 to 23.1 samples across the pass band.
A word on stability. An FIR filter has no feedback, so it cannot become unstable. The IIR filter is stable because all its poles are inside the unit circle, as Stability and causality (16.4) showed. The largest radius is 0.9527. Rounding the coefficients in fixed point moves the poles, and a pole that close to the circle has little room. 21.2 and 21.3 show how to keep it inside.
One more choice sits between the two columns. A minimum-phase FIR filter, as in Minimum phase (17.2), has a shorter delay than a linear-phase one, but it gives up the constant delay.
Worked example
Let’s write out both designs for the running spec and check the numbers of this page.
1. The elliptic design. ellip(5, 0.4455, 40, 1000, fs=8000) gives these coefficients, to six decimals:
- : 0.022446, −0.012274, 0.021538, 0.021538, −0.012274, 0.022446
- : 1, −3.317488, 5.080257, −4.269604, 1.962663, −0.392408
Its five poles are 0.6659, and . All five lie inside the unit circle, so the filter is stable. Its five zeros lie on the circle, at , and at . As frequencies, those zeros are 1276 Hz, 1698 Hz and 4000 Hz, where the gain is exactly zero.
2. Other IIR families on the running spec. SciPy’s order functions give Butterworth 12, Chebyshev I 7 and Chebyshev II 7. Their delays in the pass band differ a lot:
| Family and order | Delay at 0 Hz | Largest delay in the pass band |
|---|---|---|
| Butterworth, 12 | 8.4 samples | 17.7 samples |
| Chebyshev I, 7 | 7.5 samples | 28.7 samples |
| Chebyshev II, 7 | 3.1 samples | 10.3 samples |
| elliptic, 5 | 3.7 samples | 23.1 samples |
The Chebyshev II filter is interesting: its delay never reaches 12.5 samples in the pass band, so it is quicker than the FIR filter at every frequency there. It costs 15 multiplies in direct form, against the elliptic filter’s 11.
3. Cost at 8 kHz. The FIR filter needs multiplies a second, or 104 000 with the symmetry. The IIR filter needs .
4. Delay in time. At 8 kHz one sample is 0.125 ms. The FIR filter’s 12.5 samples are 1.5625 ms. The IIR filter’s 3.717 samples at 0 Hz are 0.46 ms, and its 23.14 samples at 1000 Hz are 2.89 ms.
5. Forwards and backwards. The gain is squared. The pass band then lies between 0.9025 and 1, which is −0.89 dB at worst, and the stop band is at −80.00 dB. The worst pass-band loss doubles, from 0.4455 dB to 0.8911 dB, because squaring a gain doubles its dB value.
Where you’ll meet this
Audio plug-ins often offer both kinds. An equaliser may have a “linear phase” mode, which keeps the shape of drum hits at the cost of delay, and a “minimum phase” mode with almost no delay, for live use.
Biomedical toolkits filter stored recordings forwards and backwards. An ECG’s waves keep their timing and shape, so a doctor can still measure them. Real-time control loops, such as a motor controller, use IIR filters for their short delay, because every sample of delay in a feedback loop makes it harder to keep stable.
How do you actually run an IIR filter, and how do you keep it stable with rounded numbers? That is chapter 21: Filter structures (21.1), Second-order sections (21.2) and Finite word-length effects (21.3).
The maths behind it · symmetric matrices
Write filtering a stored signal as a matrix: , with lower triangular. Reversing is the exchange matrix of 17.3’s bridge, so forwards then backwards is . Flipping a Toeplitz matrix end to end transposes it, so this equals the symmetric matrix . A symmetric operator cannot shift anything one way.
The maths behind it · centred moving averages
A centred moving average smooths a time series without lag, and a trailing one lags (17.3’s bridge). Forward–backward filtering is how time-series software, for example scipy.signal.filtfilt, gets the centred version of any filter.
Reference card
| Property | FIR (equiripple, 26 taps) | IIR (elliptic, order 5) |
|---|---|---|
| Multiplies per sample | 26 (13 with symmetry) | 11 |
| Delay | 12.5 samples, every frequency | 3.7 at 0 Hz, 23.1 at 1 kHz |
| Phase | linear: shapes kept | bent: shapes change |
| Stability | always | poles must stay inside (21.2–21.3) |
| Offline zero phase | not needed: the delay is already constant | forwards then backwards: |
| Quantity | Formula | Notes |
|---|---|---|
| Multiplies per sample, FIR | , or with symmetric taps | 26 or 13 here |
| Multiplies per sample, IIR | number of plus number of after | here |
| Forwards then backwards | zero phase, gain squared, offline only | |
| Centre of an output | moves by | 3.72 samples forwards, 0.00 forwards and backwards |