FIR Filters
In 2012, a firmware bug in a cochlear implant processor caused high-frequency whine for patients. The root cause: an IIR filter designed for floating-point was deployed on fixed-point hardware. The filter was stable in simulation but oscillated on the device due to coefficient quantization moving a pole outside the unit circle. FIR filters cannot have this failure mode - they are unconditionally stable regardless of coefficient precision. Understanding FIR design is understanding why safety-critical signal processing chooses structure over efficiency.
- **Apple AirPods Pro** use a 48-tap FIR filter in the active noise cancellation (ANC) system to ensure linear phase in the anti-noise path. Non-linear phase would cause the anti-noise to arrive out-of-sync with the environmental noise at different frequencies, degrading cancellation by 10-20 dB.
- **NASA Deep Space Network** uses Parks-McClellan equiripple FIR filters for the baseband processing of spacecraft signals at 8 GHz. The optimal minimax design extracts the maximum SNR from signals arriving 20+ minutes after transmission, where every 0.1 dB matters.
- **Spotify's audio loudness normalization** (ReplayGain implementation) uses a 512-tap Kaiser-windowed FIR filter with 80 dB stopband rejection to measure true-peak levels. IIR would be faster, but the linear phase ensures that pre-ringing and post-ringing artifacts from the filter itself do not affect the peak measurement.
FIR Filter Fundamentals
A Finite Impulse Response (FIR) filter of order N computes each output sample as a weighted sum of the current and N past input samples: y[n] = sum_{k=0}^{N} h[k] * x[n-k]. The coefficients h[k] are the filter's impulse response - they completely characterize the filter. Because FIR filters have no feedback (no poles), they are always stable. The frequency response H(e^{jw}) is the DTFT of h[k]: H(e^{jw}) = sum_{k=0}^{N} h[k] * e^{-jwk}. Filter design means choosing h[k] to approximate a desired frequency response.
**FIR vs IIR trade-off**: FIR filters require more coefficients (higher order) than IIR to achieve the same transition band sharpness - a Butterworth IIR might need 4th order where a FIR needs 64 taps. But FIR is always stable, can have exact linear phase (zero group delay distortion), and supports efficient polyphase decomposition for sample-rate conversion. For audio processing, biomedical signals, and communications, FIR's linear phase is often non-negotiable.
Why is a FIR filter always stable regardless of coefficient values?
Window Design Method
The window method designs FIR filters in three steps: (1) specify the ideal (infinite-duration) impulse response h_d[n] corresponding to the desired frequency response; (2) truncate h_d[n] to N+1 samples by multiplying by a window function w[n]; (3) the resulting h[n] = h_d[n]*w[n] is the FIR filter. For a low-pass filter with cutoff wc, the ideal impulse response is h_d[n] = wc/pi * sinc(wc*n/pi) (infinite, non-causal). The window determines the transition width and stopband attenuation trade-off.
| Window | Peak Sidelobe (dB) | Stopband Atten. (dB) | Transition Width | Use Case |
|---|---|---|---|---|
| Rectangular | -13 | 21 | ~0.9/N | Gibbs artifact - rarely used |
| Hanning | -31 | 44 | ~3.1/N | General purpose |
| Hamming | -41 | 53 | ~3.3/N | Audio processing |
| Blackman | -57 | 74 | ~5.5/N | High attenuation needed |
| Kaiser (beta=8) | -57 | 80 | ~5.3/N | Flexible via beta parameter |
Increasing the Kaiser window beta parameter from 4 to 8 for a fixed filter order N will:
Parks-McClellan Equiripple Design
The Parks-McClellan algorithm (1972) finds the optimal FIR filter - optimal in the minimax sense: it minimizes the maximum error between the desired and actual frequency response across all specified bands. This produces an equiripple filter where the approximation error oscillates uniformly in each band. For a given order N and transition band, Parks-McClellan achieves the minimum possible peak error. The algorithm uses the Remez exchange algorithm (a Chebyshev approximation technique) iterating over extremal frequency points until convergence.
**When to use Parks-McClellan vs window method**: use Parks-McClellan when filter order is constrained and you need the best possible performance for that order (e.g., real-time DSP with fixed compute budget). The window method is simpler, but for the same order N, Parks-McClellan achieves roughly 10-15 dB more stopband attenuation or a proportionally narrower transition band. Texas Instruments' TMS320 DSP library ships Parks-McClellan coefficients for all standard audio filter configurations.
What makes the Parks-McClellan filter 'optimal' compared to window-method filters of the same order?
Linear Phase and Symmetry
A filter has linear phase if its phase response is H(w) = A(w) * e^{-j*alpha*w}, where A(w) is real and alpha is the group delay (constant). This means all frequency components are delayed by exactly the same amount (alpha samples), preserving the waveform shape. FIR filters achieve linear phase by having symmetric coefficients: h[k] = h[N-k] (Type I and II, even/odd symmetry) or anti-symmetric h[k] = -h[N-k] (Type III and IV, for differentiators and Hilbert transformers). Signal processing functions like firwin() and remez() produce linear-phase FIR by default.
**Non-causal delay compensation**: a linear-phase FIR filter of order N introduces a group delay of N/2 samples. For real-time systems, this means an N/2 sample latency. For audio at 48 kHz with a 1024-tap filter, that is 10.7 ms - perceptible latency for live monitoring. Options: (1) use zero-phase offline filtering (scipy filtfilt, doubles the order effect but zero latency for offline); (2) use a lower-order IIR with minimum phase for low-latency applications; (3) accept the delay if the application allows (EQ for recorded material).
FIR filters are always better than IIR filters because they are stable and have linear phase.
FIR and IIR filters each excel in different scenarios. FIR is mandatory when linear phase is required (biomedical ECG, data communications) or when stability must be guaranteed under coefficient quantization. IIR is preferred when low order (and thus low latency and low compute) is more important than perfect phase linearity - audio EQ, radio receivers, real-time control systems.
Achieving the same stopband attenuation and transition width requires 5-10x more FIR taps than IIR poles. A 4th-order Butterworth IIR can match a 50-tap FIR low-pass in magnitude response. The 50-tap FIR requires 50 multiplications per sample vs 8 for the 4th-order IIR. For embedded DSP running at 10 kHz control loops with a Cortex-M4 at 168 MHz, this arithmetic translates directly to available CPU budget.
A linear-phase FIR filter of order 100 introduces a group delay of 50 samples at all frequencies. What does this mean for the output signal?
Key Ideas
- **FIR filters** are always stable and can achieve exact linear phase via coefficient symmetry. The cost is higher filter order compared to IIR for the same frequency selectivity.
- **Window method** is simple and fast: multiply the ideal sinc response by a window function. Kaiser window provides flexible stopband control via the beta parameter. Parks-McClellan achieves optimal (minimax) performance for the same order at the cost of more complex design.
- **Linear phase** (constant group delay = N/2 samples) means all frequencies are delayed by the same amount, preserving waveform shape. Type I (odd length, symmetric) FIR is the most versatile; Type II cannot implement highpass filters due to a zero at Nyquist.
Related Topics
FIR filters are the foundation for understanding the trade-offs in filter design:
- IIR Filters — IIR filters (Butterworth, Chebyshev, elliptic) achieve the same magnitude response with far fewer coefficients by using feedback (poles). Understanding FIR linear phase and stability makes the IIR trade-offs concrete.
- Discrete Fourier Transform — FIR filtering in the frequency domain uses the DFT/FFT: overlap-add and overlap-save algorithms multiply the DFT of h by the DFT of signal blocks, then inverse-DFT. This FFT-based convolution runs in O(N log N) vs O(N^2) for direct convolution.
Вопросы для размышления
- A real-time audio application requires a 60 dB stopband FIR filter with a 200 Hz transition band at 44.1 kHz sample rate. Using Kaiser's formula, estimate the required filter order. At 44.1 kHz, what is the resulting latency in milliseconds? Is this acceptable for live monitoring?
- Parks-McClellan allows specifying different weights for passband and stopband error. If the stopband weight is 100x the passband weight, what happens to the distribution of ripple between bands, and in what application would this be desirable?
- A symmetric FIR filter (Type I, 65 taps) is applied to a signal twice in sequence. What is the net group delay? Is the result still linear phase? How does this compare to using scipy's filtfilt() for zero-phase offline filtering?