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

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.

Windows Gibbs phenomenon Parks-McClellan Bilinear transform Prewarping

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:

\[ h[n] = 2 f_c\, \frac{\sin(2\pi f_c\, (n - M))}{2\pi f_c\, (n - M)}\, w[n] \] With \( M = (N-1)/2 \) and \( n = 0, \ldots, N - 1 \). Truncating without a window (rectangular window) produces the Gibbs phenomenon: a ripple that does not go away as \( N \) increases and leaves the stopband at only 21 dB.
WindowMinimum stopband attenuationApproximate transition width
Rectangular21 dB\( 0.9/N \)
Hann44 dB\( 3.1/N \)
Hamming53 dB\( 3.3/N \)
Blackman74 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.

Lab · designing an FIR with windows

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:

\[ s = \frac{2}{T}\,\frac{z - 1}{z + 1} \] \[ \omega_a = \frac{2}{T}\,\tan\frac{\omega_d T}{2} \] In exchange, it warps the frequency axis: the digital frequency \( \omega_d \) corresponds to the analog one \( \omega_a \). That is why the critical frequencies are prewarped before designing the analog filter. For a 1 kHz cutoff with 8 kHz sampling, the analog filter is designed for 1.055 kHz.

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

Activity 1 · Windows in Python

Design the same lowpass with firwin using the four windows and compare their responses with those of the lab.

Activity 2 · FIR on a microcontroller

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.

Activity 3 · Bilinear

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.
Development of the topic “Filter design” 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