Filter design
In an FIR designed with windows, adding coefficients does not improve rejection: with the Hamming window it stays at 53 dB with 21 coefficients or with 101. What changes is the width of the transition.
01From specification to coefficients
Designing a digital filter means following a fixed path: start from the template (bands, attenuations, sampling frequency), choose between FIR or IIR, compute the coefficients with an approximation method, choose the structure, quantize the coefficients to the processor’s format and verify that the quantized filter still meets the specification. Almost all the steps are done today by a program, but choosing the method and judging the result requires understanding what each one does.
02FIR by the window method
The ideal lowpass with cutoff frequency \( f_c \) (as a fraction of \( f_s \)) has an infinite impulse response, shaped like a sinc function. The window method truncates it to \( N \) samples, centered, and multiplies it by a window that smooths the ends:
| Window | Minimum stopband attenuation | Approximate transition width |
|---|---|---|
| Rectangular | 21 dB | \( 0.9/N \) |
| Hann | 44 dB | \( 3.1/N \) |
| Hamming | 53 dB | \( 3.3/N \) |
| Blackman | 74 dB | \( 5.5/N \) |
The window sets the attenuation; the length \( N \), the width of the transition. The Kaiser window has a parameter that allows the attenuation to be chosen continuously, with empirical formulas for the required length.
A linear-phase FIR lowpass. You choose the cutoff frequency, the number of coefficients and the window. At the top, the coefficients; below, the magnitude of the response in dB from 0 to \( f_s/2 \), with the minimum attenuation measured in the stopband.
03Other methods for FIR
Frequency sampling sets the desired response at equally spaced points and obtains the coefficients with an inverse DFT. The Parks-McClellan algorithm looks for the shortest FIR that meets the template, with the error spread as equal ripples in both bands: it is the optimal design, and the one that programs use by default. For the same specification, it usually needs considerably fewer coefficients than the window method.
04IIR from analog filters
IIR filters are almost always designed starting from an analog filter —Butterworth, Chebyshev, elliptic— and transforming it to the z-plane. The most widely used transformation is the bilinear one, which maps the whole \( j\omega \) axis onto the unit circle exactly once, without aliasing:
Impulse invariance, the alternative, samples the impulse response of the analog filter: it preserves the shape in time but suffers from aliasing, and is only suitable for lowpass and bandpass filters that are well band-limited.
05Tools and verification
In Python, the scipy.signal module has firwin (windows), remez
(Parks-McClellan) and butter, cheby1 and ellip with bilinear transformation, and
returns IIR filters directly as second-order sections. Octave and MATLAB have equivalent functions. The
final verification is always done with the coefficients already quantized to the processor’s format: an IIR that
meets the specification with 64-bit coefficients may fail to, or become unstable, with 16.
06In the lab
Design the same lowpass with firwin using the four windows and compare their responses with those of the
lab.
Load the coefficients of a 31-coefficient FIR in 16-bit fixed point onto a microcontroller, filter an ADC signal and measure the response with a generator and an oscilloscope.
Design a fourth-order Butterworth for 1 kHz with 8 kHz sampling, with and without prewarping, and measure where the cutoff ends up in each case.
07Common mistakes
- Increasing N expecting more attenuation. The attenuation is set by the window; N only narrows the transition.
- Forgetting prewarping in the bilinear transform. The cutoff ends up lower than designed.
- Verifying with double-precision coefficients. The real filter uses the quantized ones.
- Specifying the cutoff frequency in hertz in a function that expects it normalized. Each tool uses its own convention: a fraction of \( f_s \), of \( f_s/2 \), or radians per sample.
08Self-assessment
Which window is suitable for 50 dB of stopband rejection?
Hamming, which gives about 53 dB; Hann falls short.
How many coefficients does an FIR with a Hamming window and a 0.05 fs transition need?
\( N \approx 3.3/0.05 = 66 \): 67, to make it odd.
For what analog frequency is a digital cutoff of 2 kHz with 10 kHz sampling designed?
\( f_a = (f_s/\pi)\tan(\pi f_d/f_s) = (10\,000/\pi)\tan(0.2\pi) \approx 2.31 \) kHz.
What advantage does Parks-McClellan have over windows?
It meets the same template with fewer coefficients, because it distributes the error optimally.
09Further reading
- Alan V. Oppenheim and Ronald W. Schafer. Discrete-Time Signal Processing. 3rd ed., Pearson, 2010. FIR and IIR design methods with their theoretical justification, including the Kaiser window and the bilinear transform.
- Richard G. Lyons. Understanding Digital Signal Processing. 3rd ed., Prentice Hall, 2010. Filter design explained with examples and with the mistakes made in practice.
- John G. Proakis and Dimitris G. Manolakis. Digital Signal Processing. 4th ed., Pearson, 2007 (Spanish edition, “Tratamiento digital de señales”). The design methods with many solved exercises.