Skip to content

FIR vs IIR Filters

Copy this iframe to your website:

1
<iframe src="https://dmccreary.github.io/signal-processing/sims/fir-vs-iir/main.html" width="100%" height="702px" scrolling="no"></iframe>

Run MicroSim in Fullscreen

Description

This MicroSim designs two low-pass filters for the same cutoff \(f_c\) and draws them on shared axes. The FIR filter (blue) is a windowed sinc with \(N\) taps, \(h[n] = 2f_c\,\mathrm{sinc}\big(2f_c(n-M)\big)\,w[n]\) with \(M = (N-1)/2\) and a Hamming window, scaled so that its DC gain is exactly 1. Its taps are symmetric, so its phase is exactly linear. The IIR filter (green) is a Butterworth filter: analog poles spaced evenly on a circle of radius \(\Omega_c = 2\tan(\pi f_c)\) (pre-warped), mapped to the \(z\)-plane by the bilinear transform, with every zero at \(z = -1\).

The sliders set the cutoff (0.02 to 0.45 of \(f_s\)), the FIR length \(N\) (5 to 101, odd) and the IIR order (1 to 8). The panels show the magnitude in dB, the unwrapped phase, the group delay, the first 64 samples of each impulse response, and the IIR pole-zero plot. The table gives the multiplies per output sample (FIR: \(N\); IIR: \(2N+1\) in direct form, 5 per biquad plus 3 for a first-order section in cascade form), the group delay at DC, \(|H|\) at \(f_c\) and \(2f_c\), and the largest pole radius. Note that the two filters define "cutoff" differently: the windowed sinc is about 6 dB down at \(f_c\), the Butterworth exactly 3 dB. Hover over any plot to read values at one frequency or sample.

Quantize IIR to B bits rounds the IIR coefficients to \(B\)-bit fixed point (4 to 16 bits), either as one direct-form polynomial or as cascaded biquads. Each coefficient list shares one binary point, placed so its largest value fits, and \(a_0 = 1\) stays exact. Red marks show the new poles and zeros; direct-form roots are found with the Durand-Kerner iteration. If any pole reaches the unit circle, the filter is unstable and no frequency response is drawn.

This simulation is used in Chapter 9: Filter Design Fundamentals.

Lesson Plan

Learning Objectives

After using this MicroSim, students will be able to:

  1. Compare the magnitude, phase and group delay of an FIR and an IIR low-pass filter with the same cutoff, and explain why a symmetric FIR has a constant group delay of \((N-1)/2\) samples
  2. Distinguish a finite impulse response from an infinite one, and relate the decay of \(h[n]\) to the largest pole radius
  3. Calculate the multiplies per output sample of an FIR filter, a direct-form IIR filter and a cascade of biquads
  4. Evaluate which filter type is cheaper for a given attenuation, and explain why the FIR's cost grows as the cutoff narrows
  5. Analyze how rounding IIR coefficients to \(B\) bits moves the poles, and explain why cascaded biquads stay stable where a high-order direct form fails

Target Audience

Undergraduates in a first digital signal processing course (junior or senior electrical engineering, computer engineering or computer science). Plan 25 to 30 minutes for the activities below.

Prerequisites

  • The \(z\)-transform, poles and zeros, and the unit-circle stability test (Chapter 8)
  • Difference equations and convolution with an impulse response
  • Frequency response in decibels and normalized frequency \(f/f_s\)

Activities

Activity 1: Same cutoff, different trade-offs (7 min). Start from the defaults (\(f_c = 0.100\,f_s\), \(N = 31\), IIR order 4, direct form). The table shows \(|H(f_c)|\) = −6.1 dB for the FIR and −3.0 dB for the IIR, and \(|H(2f_c)|\) = −70.6 dB and −28.0 dB. The FIR costs 31 multiplies per sample, the IIR 9 (10 as biquads). In the group-delay panel the FIR is a flat line at 15 samples, while the IIR starts at 4.02 samples at DC, peaks at about 6.5 samples near \(0.09\,f_s\) and falls below 1 sample at high frequencies. Hover the phase panel at \(f = 0.100\,f_s\): the FIR phase is \(-3.00\pi\) rad (\(= -2\pi \cdot 0.1 \cdot 15\)) and the IIR phase is \(-1.00\pi\). Set \(N = 101\): the FIR delay becomes 50.0 samples. Set the order to 8: the IIR delay at DC rises to 7.89 samples and its peak to about 15.7 samples.

Activity 2: Finite versus infinite (5 min). With the defaults, the dashed blue line marks where the FIR ends (\(n = 30\)); the IIR \(h[n]\) keeps going and is still nonzero at \(n = 63\) (hover: about \(-2 \times 10^{-7}\)). Now set \(f_c = 0.020\,f_s\), \(N = 101\) and order 8. The largest pole radius is 0.9758, close to the unit circle, so the IIR response is still ringing at \(n = 63\) (\(h \approx 0.0120\)), and its group delay peaks near 74 samples at \(0.019\,f_s\).

Activity 3: Which filter is cheaper? (8 min). At \(f_c = 0.100\,f_s\) with order 4, the IIR gives −28.0 dB at \(2f_c\) for 9 multiplies. Lower \(N\) until the FIR just beats it: \(N = 15\) gives −34.2 dB, while \(N = 13\) gives only −27.4 dB. Repeat at \(f_c = 0.020\,f_s\): the order-4 IIR gives −24.2 dB, and the FIR needs \(N = 57\) (−24.5 dB; \(N = 55\) gives −23.1 dB), so 57 multiplies and 28 samples of delay against 9 multiplies.

Activity 4: Rounding the coefficients (10 min). Return to the defaults and tick Quantize IIR to B bits (8 bits, direct form). The filter is stable (largest pole radius 0.7630 instead of 0.7954) but its DC gain is about +1.9 dB. At \(B = 6\) the radius is 0.9809, the response has a +13.8 dB peak near \(0.106\,f_s\) and \(h[n]\) rings. At \(B = 5\) the radius is 1.0268: UNSTABLE. Switch to Cascaded biquads at \(B = 5\): radius 0.7906, stable. Set the order to 8: the direct form needs 13 bits (12 bits gives 1.0074, unstable; 13 bits gives 0.9099), while biquads are stable even at 4 bits (0.8660). Finally set \(f_c = 0.020\,f_s\): the order-8 direct form is unstable even at 16 bits (1.2987); biquads are stable at 8 bits (0.9763), and at 7 bits one pole lands exactly on \(z = 1\).

Assessment

  1. A symmetric FIR filter has 41 taps. What is its group delay, and does it depend on frequency? Answer: \((41 - 1)/2 = 20\) samples at every frequency, because symmetric taps give exactly linear phase.
  2. How many multiplies per output sample does an order-6 Butterworth filter need in direct form, and as cascaded biquads? Answer: \(2 \cdot 6 + 1 = 13\) in direct form and \(3 \times 5 = 15\) as three biquads.
  3. At \(f_c = 0.020\,f_s\) and order 8 the IIR impulse response is still ringing at \(n = 63\), but at \(f_c = 0.100\,f_s\) and order 4 it has died out. Why? Answer: \(h[n]\) decays roughly like \(r^n\) for the largest pole radius \(r\). \(0.9758^{63} \approx 0.21\), but \(0.7954^{63} \approx 5 \times 10^{-7}\).
  4. A design needs cutoff \(0.02\,f_s\) and at least 24 dB attenuation at \(0.04\,f_s\). Compare the two filter types. Answer: an order-4 Butterworth reaches −24.2 dB with 9 multiplies (10 as biquads); the Hamming FIR needs 57 taps, 57 multiplies and 28 samples of delay. Choose the IIR unless linear phase is required.
  5. With \(f_c = 0.100\,f_s\) and order 8, the direct form needs 13 bits to stay stable while biquads are stable at 4 bits. Explain the difference. Answer: the roots of a high-order polynomial with clustered poles are extremely sensitive to small changes in its coefficients. Each biquad holds only two poles, set by its own \(a_1\) and \(a_2\), so a rounding error moves those two poles only a little.

Common Misconceptions

"A zero outside the unit circle makes the filter unstable." Tick Quantize IIR to B bits at the defaults: rounding the direct-form numerator splits the four zeros at \(z = -1\) into reciprocal pairs, two of them at radius 1.375, outside the circle. The table still reports a stable filter (largest pole radius 0.7630). Stability depends only on the poles.

"Cutoff means the same thing for every filter." At the same \(f_c\) the FIR is 6.1 dB down and the Butterworth 3.0 dB down. When you compare designs, compare the attenuation at the frequencies that matter, as in Activity 3, not the labels.

References

  1. Finite impulse response - Wikipedia - FIR structure, linear phase from symmetric taps, and the window design method
  2. Infinite impulse response - Wikipedia - recursive filters, transfer functions and pole-based stability
  3. Butterworth filter - Wikipedia - maximally flat response and poles evenly spaced on a circle
  4. Bilinear transform - Wikipedia - mapping an analog prototype to the z-plane with frequency pre-warping
  5. Digital biquad filter - Wikipedia - second-order sections and why cascades are less sensitive to coefficient quantization
  6. Group delay and phase delay - Wikipedia - definition of the group delay plotted in the sim
  7. Durand–Kerner method - Wikipedia - the root-finding iteration used for the quantized direct-form poles
  8. The Scientist and Engineer's Guide to Digital Signal Processing - Steven W. Smith - free textbook with chapters on windowed-sinc and recursive filters