Catto / Topic Map · Circuit Theory II Level 4
Circuit Theory II · 120 h · Topic 7 of 8

IIR and FIR digital filters

An eight-sample average and an exponential with α = 0.22 reduce noise equally. The first needs eight samples in memory; the second, a single variable.

FIR IIR Linear phase Moving average Fixed point

01Two families of digital filters

A digital filter is a difference equation that a processor computes at every sample. If it uses only inputs, its impulse response is finite (FIR); if it feeds back previous outputs, it is infinite (IIR). The choice between the two is the first design decision:

FIRIIR
StabilityAlways stable: it has no poles away from the originIt has to be ensured: the poles inside the unit circle
PhaseCan have exactly linear phaseNonlinear phase, like analog filters
Order for a steep transitionHigh: tens or hundreds of coefficientsLow: a few poles are enough
Cost per sampleOne multiplication per coefficientFew multiplications
Sensitivity to quantizationLowHigh: rounding a coefficient moves the poles

02Linear phase and group delay

The group delay \( \tau(\Omega) = -d\varphi/d\Omega \) says how many samples each frequency takes to pass through. If it is the same for all of them, the waveform comes out intact, just delayed. An FIR with symmetric coefficients has exactly linear phase:

\[ h[n] = h[M - 1 - n] \ \Rightarrow\ \tau = \frac{M - 1}{2} \] A symmetric FIR of \( M \) coefficients delays all frequencies by the same amount: \( (M-1)/2 \) samples. An IIR delays each frequency differently, and distorts pulses even if its magnitude is flat.

That is why FIR filters dominate in digital communications, professional audio and instrumentation, where the shape of the pulses matters, and IIR filters where cost or latency matters: control, tone detection, low-power equalizers.

03The two simplest filters

\[ y[n] = \frac{1}{M}\sum_{k=0}^{M-1} x[n-k] \] \[ y[n] = \alpha\, x[n] + (1 - \alpha)\, y[n-1] \] The moving average is an FIR of \( M \) equal coefficients; exponential smoothing, a one-pole IIR at \( 1 - \alpha \). Both are lowpass and both reduce white noise: the variance drops to \( 1/M \) in the first and to \( \alpha/(2 - \alpha) \) in the second.

The moving average needs to store \( M \) samples and, computed recursively, two additions per sample; the exponential needs a single variable and one multiplication. They are the filters in almost all measurement firmware.

Lab · moving average versus exponential smoothing

At the top, the magnitude of the frequency response of the two filters from 0 to π. Below, their response to a step with white noise (the same noise sequence for both). You adjust the length of the average and the coefficient of the exponential.

04Structures and implementation

The same transfer function can be computed with different structures: direct form, transposed direct form, cascade of second-order sections (biquads) or lattice. Mathematically they are equivalent; numerically they are not. A high-order IIR in direct form is very sensitive to the rounding of its coefficients, and in practice it is always implemented as a cascade of biquads, just as active filters are built with second-order sections.

On a microcontroller without floating point, work is done in fixed point, with scaled integers. You have to watch out for overflow in the sums, for rounding, which adds noise, and for limit cycles: small oscillations that an IIR sustains through rounding even when the input is zero. Signal processors multiply and accumulate in one cycle, with wide accumulators to avoid overflow, as seen in processor architecture.

05In the lab

Activity 1 · Filtering a measurement

Read a noisy sensor with a microcontroller, apply a moving average and an exponential with the same noise reduction, and compare their response to an abrupt change.

Activity 2 · Linear phase

Filter a square wave with a symmetric FIR and with an IIR of the same cutoff frequency, and compare the shape of the edges on the oscilloscope.

Activity 3 · Fixed point

Implement the exponential in 16-bit fixed point and find the smallest α that still converges to the final value.

06Common mistakes

  • Forgetting the filter delay. A 32-sample average delays by 15.5 samples: in a control loop it can destabilize it.
  • Implementing a high-order IIR in direct form. The rounding of the coefficients makes it unstable.
  • Using a very small α in fixed point. The product is rounded to zero and the output stalls short of the final value.
  • Believing that the moving average is a good lowpass filter. Its sidelobes let quite a lot through; it is good against noise, not for separating frequencies.

07Self-assessment

How much does a symmetric 31-coefficient FIR delay at 48 kHz?

15 samples: 0.31 ms.

What α gives the same noise reduction as an 8-sample average?

\( \alpha/(2-\alpha) = 1/8 \Rightarrow \alpha = 2/9 \approx 0.22 \).

Where is the pole of the exponential with α = 0.1?

At \( z = 0.9 \): inside the circle, stable.

Why is an FIR always stable?

Because all its poles are at the origin: the output is a finite sum of bounded inputs.

08Further reading

  • Richard G. Lyons. Understanding Digital Signal Processing. 3rd ed., Prentice Hall, 2010. FIR and IIR filters explained intuitively, including structures and fixed point.
  • Alan V. Oppenheim and Ronald W. Schafer. Discrete-Time Signal Processing. 3rd ed., Pearson, 2010. The complete theory of structures and of the effects of quantization.
  • Steven W. Smith. The Scientist and Engineer's Guide to Digital Signal Processing. California Technical Publishing, 1997. The moving-average chapter is the best analysis of why it is so useful against noise.
Development of the topic “IIR and FIR digital filters” of Circuit Theory II (Level 4), based on the curriculum of the UTN Electronic Engineering program, 2023 curriculum — Ordinance No. 1849 of the UTN Higher Council. Back to the Topic Map · catto.ar