Chapter 13 designed IIR filters by transforming analog prototypes. This chapter designs FIR filters(有限脈衝響應濾波器) directly in discrete time. The simplest idea: start from a desired (usually ideal) frequency response $H_d(e^{j\omega})$ and find the best finite-length impulse response $h_t[n]$ that approximates it.
“Best” needs a criterion. The natural first choice is to minimize the Integral Squared Error(積分平方誤差,ISE) between the desired and the actual frequency responses:
The ideal impulse response is $h_d[n] = \mathrm{IDTFT}\{H_d(e^{j\omega})\}$, which is usually infinite-extent. By Parseval’s theorem(帕塞瓦爾定理), the frequency-domain error equals a time-domain error:
Now constrain $h_t[n]$ to exist only for $n = -M,\dots,M$ (length $2M+1$). Split the sum:
The second term is fixed; the first is zeroed by simply copying $h_d[n]$ inside the support. So the minimum mean-squared-error FIR approximation of length $2M+1$ is the truncated IDTFT(截斷的反離散時間傅立葉變換):
The truncated $h_t[n]$ is symmetric around $n=0$, hence noncausal. Make it causal(因果) by delaying $M$ samples:
Recall (from the Fourier-domain chapter) the ideal lowpass filter(理想低通濾波器) with cutoff $\omega_c$:
The sinc-shaped $h_{LP}[n]$ extends from $-\infty$ to $\infty$ and decays only like $1/n$ — it can never be realized exactly. Applying the recipe of §14.1:
(at $n = M$ the value is $\omega_c/\pi$ by the limit). The shift $n \to n-M$ is the causal delay.
Fig. 14-1 shows the whole pipeline for $\omega_c = 0.3\pi$, $M = 12$: take the ideal sinc, keep $2M+1 = 25$ central samples, shift right by $M$, then look at the magnitude response.
Plotting $|H_t(e^{j\omega})|$ for two lengths (25 and 129 points) reveals the Gibbs phenomenon(吉布斯現象): oscillatory ripples that pile up near the band edge, with a peak overshoot of about 9% of the discontinuity size.
Truncation of $h_d[n]$ to $2M+1$ points is multiplication by a rectangular window(矩形窗):
Multiplication in the time domain is (periodic) convolution in the frequency domain(頻域摺積) — the modulation/windowing theorem:
So the frequency response of the truncated filter is the ideal brick wall smeared by the DTFT of the rectangular window, which is the periodic sinc(週期 sinc / Dirichlet 核):
As the mainlobe slides across the ideal discontinuity at $\omega_c$, the running integral of the sidelobes produces the ripples: in the passband the result oscillates around 1, in the transition it rolls off across the mainlobe width, and in the stopband it oscillates around 0. This is exactly the “type of approximation obtained at a discontinuity of an ideal frequency response” pictured on the slides.
Since the rectangular window’s $-13$ dB sidelobes give only ~$-21$ dB stopband ripple, we trade mainlobe width for lower sidelobes by using tapered windows(漸變窗). With the symmetric convention $-M \le n \le M$ (length $2M+1$), the slides list:
Qualitatively (matching the slide annotations): rectangular has big sidelobes; Hann has a double-width mainlobe but much lower sidelobes; Hamming has a reduced first sidelobe (the 0.54/0.46 split is tuned to partially cancel it); Blackman has a triple-width mainlobe with the lowest sidelobes of the four. The Bartlett(三角窗)window $w[n] = 1 - |n|/M$ also appears in the comparison table.
The standard table (Oppenheim & Schafer Table 7.2, reproduced on slide 18) — here $M$ is the filter order (window length $M+1$):
| Type of window | Peak sidelobe amplitude (relative, dB) | Approx. mainlobe width | Peak approximation error $20\log_{10}\delta$ (dB) | Equivalent Kaiser $\beta$ | Transition width of equiv. Kaiser |
|---|---|---|---|---|---|
| Rectangular | −13 | $4\pi/(M+1)$ | −21 | 0 | $1.81\pi/M$ |
| Bartlett | −25 | $8\pi/M$ | −25 | 1.33 | $2.37\pi/M$ |
| Hann | −31 | $8\pi/M$ | −44 | 3.86 | $5.01\pi/M$ |
| Hamming | −41 | $8\pi/M$ | −53 | 4.86 | $6.27\pi/M$ |
| Blackman | −57 | $12\pi/M$ | −74 | 7.04 | $9.19\pi/M$ |
The fixed windows offer only discrete main-sidelobe trade-offs. The Kaiser window(凱瑟窗) is parametric: a continuous knob $\beta$ sweeps the trade-off.
where $I_0(\cdot)$ is the modified zero-order Bessel function(零階修正貝索函數). $\beta = 0$ gives the rectangular window; larger $\beta$ tapers harder ⇒ lower sidelobes, wider mainlobe.
Kaiser also gave empirical design formulas. Given the required minimum stopband attenuation $\alpha$ in dB (with $\alpha = -20\log_{10}\delta$) and the transition width $\Delta\omega = \omega_s - \omega_p$:
(The slides round the coefficients to $0.11$, $0.58$, $0.08$ and use $2.3$; Oppenheim & Schafer’s constant is $2.285$ — same formula to slide precision.) Note that for $\alpha < 21$ dB the Kaiser window degenerates to rectangular: you cannot ask for less ripple than Gibbs gives for free.
kaiser(N,beta) generates the window; kaiserord turns a spec $\{\omega_p,\omega_s,\delta_p,\delta_s\}$ directly into [n, Wn, beta, ftype] for fir1. The generic windowed design is one line: h = fir1(n, Wn, kaiser(n+1, beta)). For other windows use hann, hamming, blackman with fir1(n, Wn, window).
No specific transition/ripple requirements are given, so we compromise with a Hamming window.
The ideal LPF has a pure-real frequency response: $\theta(\omega) = 0$, $H(e^{j\omega}) = |H(e^{j\omega})|$. Pure-real responses can be added and subtracted like numbers, so piecewise-constant ideal responses are built from ideal lowpass blocks. Example — an ideal highpass(高通):
since $\delta[n] \leftrightarrow H(e^{j\omega}) = 1$ (allpass). The same arithmetic gives bandpass and bandstop responses (Exercise 5).
Window methods give you no independent control of passband vs. stopband ripple:
Since the worst-case error of a windowed design is concentrated at the band edges, a better criterion is minimax(極大極小): minimize the maximum weighted error over passband and stopband. The optimal solution is equiripple(等漣波) — the error oscillates with equal peaks (alternation theorem), and the Parks–McClellan algorithm finds it by iterative Chebyshev approximation (Remez exchange). Every ripple is pushed down to exactly the spec, no accuracy is wasted, so for the same spec the equiripple filter needs fewer taps than any windowed design.
[n,fo,ao,w] = firpmord([fp fs], [1 0], [dp ds]) estimates the order, then h = firpm(n, fo, ao, w) runs Parks–McClellan (formerly remez). In Python: scipy.signal.remez.
The slides close with a benchmark spec — passband edge $0.22\pi$, stopband edge $0.29\pi$, passband gain $0$ to $-1$ dB, stopband $\le -40$ dB — designed with every method (O&S Table 7.3):
| Filter design | Order | Type | Multiplications (symmetric structure) |
|---|---|---|---|
| Butterworth | 18 | IIR | — |
| Chebyshev I | 8 | IIR | — |
| Chebyshev II | 8 | IIR | — |
| Elliptic | 5 | IIR | 8 |
| Kaiser (window) | 63 | FIR | 32 (linear phase) |
| Parks–McClellan | 44 | FIR | 23 (linear phase) |
1) $\omega_c = 2\pi f_c/f_s$. 2) $h_d[n] = \mathrm{IDTFT}\{H_d\}$ (sinc for LPF). 3) Pick window shape from ripple spec, length from transition spec. 4) $h[n] = h_d[n]w[n]$. 5) Delay by $M$ for causality (linear phase).
By Parseval, ISE-optimal length-$(2M+1)$ FIR = plain truncation of $h_d[n]$ to $|n| \le M$. Optimal in energy, terrible in worst case.
Truncation = × rectangular window = frequency-domain convolution with a periodic sinc. ~9% ears at discontinuities; longer filters narrow the ears but never shorten them. Not minimax-optimal.
Mainlobe width ($\propto 1/L$) → transition band. Sidelobe height (shape-determined, length-invariant) → ripple. Rect −21 dB, Hann −44, Hamming −53, Blackman −74 dB peak error.
$w[n] = I_0\bigl(\beta\sqrt{1-(n/M)^2}\bigr)/I_0(\beta)$; $\beta$ from $\alpha$ (piecewise empirical fit), order $N \approx (\alpha-8)/(2.3\,\Delta\omega)$. One continuous knob replaces the window zoo.
Parks–McClellan minimizes the max error ⇒ equiripple, fewest taps (44 vs Kaiser 63 on the benchmark). IIR (elliptic order 5) is still far cheaper, but FIR gives exact linear phase and unconditional stability.
Problem: A desired frequency response $H_d(e^{j\omega})$ has ideal impulse response $h_d[n]$ (infinite extent). We seek the FIR filter $h_t[n]$, nonzero only for $-M \le n \le M$, that minimizes $\phi = \frac{1}{2\pi}\int_{-\pi}^{\pi} |H_d(e^{j\omega}) - H_t(e^{j\omega})|^2 d\omega$. (a) Show that the minimizer is $h_t[n] = h_d[n]$ for $|n| \le M$. (b) Give the residual (minimum) error. (c) Explain why this “best” filter can still have a large error at a single frequency.
(a) By Parseval’s theorem the cost equals the time-domain energy of the error:
$$\phi = \sum_{n=-\infty}^{\infty}\bigl|h_d[n]-h_t[n]\bigr|^2 = \sum_{n=-M}^{M}\bigl|h_d[n]-h_t[n]\bigr|^2 + \sum_{|n|>M}\bigl|h_d[n]\bigr|^2 .$$Each term is nonnegative. The second sum does not depend on $h_t[n]$ at all (there $h_t[n]=0$ by constraint). The first sum is minimized — made exactly zero — by choosing $h_t[n] = h_d[n]$ on $-M \le n \le M$. Hence truncation is optimal.
(b) The residual error is the energy of the discarded tail:
$$\phi_{\min} = \sum_{n < -M,\; n > M}\bigl|h_d[n]\bigr|^2 .$$For the ideal LPF, $h_d[n] \sim 1/n$, so $\phi_{\min} \sim 1/M$: it decays, but slowly.
(c) The ISE is an integral criterion: it penalizes total error energy, not peak error. The error can concentrate into ever-narrower spikes near a discontinuity (Gibbs ears) whose energy → small while their height stays ≈ 9% of the jump. Minimizing ISE therefore says nothing about the worst-case (minimax) error.
Problem: A student designs a lowpass FIR by truncating the ideal sinc to 25 points and observes ~9% overshoot near the cutoff. To fix it, the student increases the length to 129 points. (a) What happens to the overshoot and why? (b) Express the truncated response $H_t(e^{j\omega})$ in terms of $H_d$ and the window spectrum. (c) Which property of $W_R(e^{j\omega})$ controls the transition width, and how does it scale with length? (d) What should the student change to reduce the overshoot?
(a) The overshoot height stays ≈ 9% — the ears only get narrower. The relative sidelobe level of the rectangular window (−13 dB) is essentially independent of its length, and the overshoot is set by the integrated sidelobes, not by $N$.
(b) Truncation is multiplication by $w_R[n]$, so by the modulation theorem
$$H_t(e^{j\omega}) = \frac{1}{2\pi}\int_{-\pi}^{\pi} H_d(e^{j\theta})\, W_R\!\left(e^{j(\omega-\theta)}\right) d\theta , \qquad W_R(e^{j\omega}) = \frac{\sin\bigl((2M+1)\omega/2\bigr)}{\sin(\omega/2)} .$$(c) The mainlobe width, $4\pi/(2M+1)$ between zero crossings: it shrinks as $1/$length, so the transition band sharpens as the filter lengthens.
(d) Change the window shape, not (only) the length: use a tapered window (Hann/Hamming/Blackman) or a Kaiser window with $\beta$ chosen from the required attenuation. Lower sidelobes ⇒ smaller ripples/overshoot, at the price of a wider mainlobe (longer filter for the same transition width).
Problem: Design a 33-point linear-phase FIR low-pass filter with cutoff 1 kHz for a system sampled at 8 kHz, using a Hann window. (a) Find $\omega_c$. (b) Write the closed-form $h[n]$ (noncausal form) and state the causal shift. (c) Using the comparison table, estimate the stopband attenuation and the transition width. (d) What is the group delay in samples and in milliseconds?
(a) $\displaystyle \omega_c = \frac{1000}{8000}\times 2\pi = 0.25\pi$ rad/sample.
(b) $N = 33 = 2M+1 \Rightarrow M = 16$. With the slide convention:
$$h[n] = \frac{\sin 0.25\pi n}{\pi n}\left(0.5 + 0.5\cos\frac{2\pi n}{33}\right), \qquad -16 \le n \le 16,$$with $h[0] = \omega_c/\pi = 0.25$. Delay by $M = 16$ samples: $\hat h[n] = h[n-16]$, $0 \le n \le 32$.
(c) Hann window: peak approximation error $\approx -44$ dB ⇒ stopband attenuation ≈ 44 dB (and passband ripple $\delta_p = \delta_s \approx 10^{-44/20} \approx 0.0063$). Transition width (table, order $M_{\text{ord}} = 32$): $\Delta\omega \approx 8\pi/32 = 0.25\pi$ rad/sample, i.e. about $0.25\pi/(2\pi)\times 8000 = 1$ kHz.
(d) Linear phase with symmetric $h[n]$: group delay $= M = 16$ samples $= 16/8000 = 2$ ms.
Problem: A lowpass filter must satisfy: passband edge $\omega_p = 0.22\pi$, stopband edge $\omega_s = 0.29\pi$, minimum stopband attenuation $\alpha = 40$ dB. Using Kaiser’s empirical formulas, find (a) the ripple $\delta$, (b) the shape parameter $\beta$, (c) the required order $N$, and (d) the cutoff $\omega_c$ you would hand to the ideal-sinc prototype.
(a) $\delta = 10^{-\alpha/20} = 10^{-2} = 0.01$ (window methods force $\delta_p = \delta_s = \delta$).
(b) $21 \le \alpha \le 50$, so
$$\beta = 0.5842\,(40-21)^{0.4} + 0.07886\,(40-21) = 0.5842(19)^{0.4} + 0.07886 \times 19 \approx 1.897 + 1.498 \approx 3.40 .$$(c) $\Delta\omega = \omega_s - \omega_p = 0.07\pi \approx 0.2199$ rad. Then
$$N \approx \frac{\alpha - 8}{2.3\,\Delta\omega} = \frac{32}{2.3 \times 0.2199} \approx 63.3 \;\Rightarrow\; N = 63 \text{ (order)},$$i.e. 64 taps — matching the “Kaiser: 63” row of Table 7.3 (the slides’ benchmark). (With O&S’s constant 2.285 the estimate is 63.7; tools like kaiserord round up and may return 64–65 taps.)
(d) Center the transition band: $\omega_c = (\omega_p + \omega_s)/2 = 0.255\pi$.
Problem: Using only ideal-lowpass building blocks $h_{LP}[n;\omega_c] = \sin(\omega_c n)/(\pi n)$ and the allpass $\delta[n]$, find the ideal impulse responses of (a) a highpass filter with cutoff $\omega_c$, (b) a bandpass filter with band $\omega_1 < |\omega| < \omega_2$, and (c) a bandstop filter that rejects $\omega_1 < |\omega| < \omega_2$. (d) State the property of the ideal responses that makes this arithmetic legal, and what you must not do before combining them.
All ideal responses here are pure real (zero phase), so magnitudes add/subtract directly.
(a) $H_{HP} = 1 - H_{LP}(\omega_c)$:
$$h_{HP}[n] = \delta[n] - \frac{\sin \omega_c n}{\pi n}$$(b) $H_{BP} = H_{LP}(\omega_2) - H_{LP}(\omega_1)$:
$$h_{BP}[n] = \frac{\sin \omega_2 n}{\pi n} - \frac{\sin \omega_1 n}{\pi n}$$(c) $H_{BS} = 1 - H_{BP}$:
$$h_{BS}[n] = \delta[n] - \frac{\sin \omega_2 n}{\pi n} + \frac{\sin \omega_1 n}{\pi n}$$(d) Legality rests on $\theta(\omega) = 0$ for every block, so that $H_1 \pm H_2$ manipulates the magnitudes themselves; with nonzero (e.g. different linear) phases, $|H_1 \pm H_2| \neq |H_1| \pm |H_2|$ and the brick walls would be destroyed. Therefore: do not apply the causal delay to the individual blocks first — combine the zero-phase responses, window the result, and delay once at the very end. (Windowing the combination with $w[n]$ then delaying by $M$ keeps everything consistent because all blocks share the same window and the same delay.)
kaiserord / fir1Problem: Implement the benchmark spec of §14.6.2 in MATLAB: $\omega_p = 0.22\pi$, $\omega_s = 0.29\pi$, passband ripple $\le 1$ dB, stopband attenuation $\ge 40$ dB. Use kaiserord + fir1 to design the filter, plot the magnitude response in dB against the spec mask, and compare the resulting number of taps with a Parks–McClellan design from firpmord/firpm.
Convert the dB spec into linear ripples first ($1$ dB passband ⇒ $\delta_p = (10^{1/20}-1)/(10^{1/20}+1) \approx 0.0575$; $-40$ dB ⇒ $\delta_s = 0.01$). Frequencies for fir1/kaiserord are normalized to the Nyquist frequency (1 corresponds to $\pi$):
% spec: wp = 0.22*pi, ws = 0.29*pi, Rp = 1 dB, As = 40 dB
dp = (10^(1/20)-1)/(10^(1/20)+1); % 1 dB passband -> delta_p = 0.0575
ds = 10^(-40/20); % 40 dB stopband -> delta_s = 0.01
% --- Kaiser window design ---
[n, Wn, beta, ftype] = kaiserord([0.22 0.29], [1 0], [dp ds]);
hK = fir1(n, Wn, ftype, kaiser(n+1, beta), 'noscale');
fprintf('Kaiser: %d taps, beta = %.3f\n', n+1, beta);
% --- Parks-McClellan for comparison ---
[n2, fo, ao, w] = firpmord([0.22 0.29], [1 0], [dp ds]);
hPM = firpm(n2, fo, ao, w);
fprintf('Parks-McClellan: %d taps\n', n2+1);
% --- plot against the spec mask ---
[H, wfr] = freqz(hK, 1, 4096);
plot(wfr/pi, 20*log10(abs(H))); hold on; grid on;
plot([0.29 1], [-40 -40], 'k--', [0 0.22], [-1 -1], 'k--');
xlabel('\omega/\pi'); ylabel('|H| (dB)');
title('Kaiser windowed FIR vs. spec');
Result: kaiserord returns $\beta \approx 3.40$ (matching Exercise 4) and ≈ 64–65 taps; firpmord/firpm meets the same spec with ≈ 45 taps (order 44, Table 7.3) — the equiripple design saves roughly 20 taps. The regenerated result (Python/scipy, signal.kaiserord(40, 0.07) ⇒ 65 taps, $\beta = 3.395$, signal.firwin cutoff $0.255\pi$):