Outline
14.1 Least Integral-Squared Error
14.2 Approximating Ideal Filters
14.3 Gibbs Phenomenon
14.4 Window Shapes
14.5 Windowed Design in Practice
14.6 Iterative Optimization; FIR vs IIR
14.7 Summary
Exercises
DSP Study Guide · Chapter 14

FIR Filter Design

Designing finite impulse response filters by windowing the ideal impulse response — least-squares truncation, the Gibbs phenomenon, window trade-offs, the Kaiser window, and a look at equiripple optimization.

14.1 Least Integral-Squared Error Design

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.

14.1.1 “Best” in what sense?

“Best” needs a criterion. The natural first choice is to minimize the Integral Squared Error(積分平方誤差,ISE) between the desired and the actual frequency responses:

Integral squared error $$\phi \;=\; \frac{1}{2\pi}\int_{-\pi}^{\pi}\bigl|H_d(e^{j\omega}) - H_t(e^{j\omega})\bigr|^{2}\,d\omega , \qquad H_t(e^{j\omega}) = \mathrm{DTFT}\{h_t[n]\}$$

14.1.2 Parseval and the optimal truncation

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:

ISE in the time domain (Parseval) $$\phi \;=\; \sum_{n=-\infty}^{\infty}\bigl|h_d[n]-h_t[n]\bigr|^{2}$$

Now constrain $h_t[n]$ to exist only for $n = -M,\dots,M$ (length $2M+1$). Split the sum:

Split the error $$\phi \;=\; \underbrace{\sum_{n=-M}^{M}\bigl|h_d[n]-h_t[n]\bigr|^{2}}_{\text{minimized by } h_t[n]\,=\,h_d[n]} \;+\; \underbrace{\sum_{n<-M,\;n>M}\bigl|h_d[n]\bigr|^{2}}_{\text{not altered by } h_t[n]}$$

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(截斷的反離散時間傅立葉變換):

Optimal (least-ISE) truncation $$h_t[n] \;=\; \begin{cases} \dfrac{1}{2\pi}\displaystyle\int_{-\pi}^{\pi} H_d(e^{j\omega})\,e^{j\omega n}\,d\omega , & -M \le n \le M \\[4pt] 0, & \text{otherwise} \end{cases}$$
Key result
In the least-squares sense, the best length-$(2M+1)$ FIR approximation of any desired response is obtained by keeping the middle $2M+1$ samples of the ideal impulse response and discarding the rest. No fancy optimization needed — truncation is the ISE-optimal answer.
直觀解釋(點擊展開)
Parseval 定理說「頻域的總誤差能量 = 時域的總誤差能量」。既然 $h_t[n]$ 只能在 $-M\le n\le M$ 內非零,視窗外的誤差 $\sum_{|n|>M}|h_d[n]|^2$ 是注定逃不掉的;我們唯一能做的就是把視窗內的誤差降到 0 —— 也就是直接複製 $h_d[n]$。所以「截斷」不是偷懶,它正是最小平方誤差的最佳解。但注意:最佳是以「平方誤差總量」衡量,不代表每個頻率點的誤差都小(見 Gibbs 現象)。

14.1.3 Making it causal

The truncated $h_t[n]$ is symmetric around $n=0$, hence noncausal. Make it causal(因果) by delaying $M$ samples:

Causal shift $$h_t'[n] \;=\; h_t[n-M] \qquad\Rightarrow\qquad h_t'[n] = 0 \;\text{ for } n < 0,\quad \text{support } 0 \le n \le 2M$$
Why the delay is harmless
A pure delay multiplies the frequency response by $e^{-j\omega M}$: the magnitude $|H_t'(e^{j\omega})| = |H_t(e^{j\omega})|$ is untouched, and the phase becomes exactly linear phase(線性相位) $-\omega M$, because the delayed impulse response is symmetric about its midpoint $n = M$. Linear phase = constant group delay of $M$ samples = no phase distortion, just latency.

14.2 Approximating Ideal Filters

14.2.1 Ideal lowpass pair

Recall (from the Fourier-domain chapter) the ideal lowpass filter(理想低通濾波器) with cutoff $\omega_c$:

Ideal LPF: frequency response and impulse response $$H_{LP}(e^{j\omega}) = \begin{cases} 1, & |\omega| < \omega_c \\ 0, & \omega_c < |\omega| \le \pi \end{cases} \qquad\Longleftrightarrow\qquad h_{LP}[n] = \frac{\sin \omega_c n}{\pi n}\quad(\text{doubly infinite})$$

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:

Minimum-ISE causal FIR lowpass (length 2M+1) $$\hat h_{LP}[n] \;=\; \begin{cases} \dfrac{\sin \omega_c (n-M)}{\pi\,(n-M)} , & 0 \le n \le 2M \\[4pt] 0 , & \text{otherwise} \end{cases}$$

(at $n = M$ the value is $\omega_c/\pi$ by the limit). The shift $n \to n-M$ is the causal delay.

14.2.2 Windowed-sinc design steps

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.

2026-06-12T22:40:38.411971 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −20 −10 0 10 20 n 0.0 0.1 0.2 0.3 h_d[n] (a) Ideal IR h_d[n] = sin(0.3pin)/(pin) (doubly infinite; keep |n| <= M) 0 5 10 15 20 25 n 0.0 0.1 0.2 0.3 h_LP[n] (b) Truncate to 2M+1 = 25 points and delay by M = 12 -> causal h_LP[n] 0.0 0.2 0.4 0.6 0.8 1.0 omega/pi 0.0 0.2 0.4 0.6 0.8 1.0 magnitude (c) Magnitude of the truncated design vs. ideal brick wall |H_t|, N = 25 (rect.) ideal H_d
Fig. 14-1 — Windowed-sinc lowpass design steps: (a) ideal $h_d[n]$ with the kept region shaded, (b) truncated and delayed causal impulse response, (c) resulting magnitude vs. the ideal brick wall. Note the ripples near the cutoff.(理想 sinc 截斷 → 右移成因果 → 頻率響應出現過渡帶與漣波)
Common exam trap
The truncated design is optimal in integrated squared error, not in worst-case (minimax) error. Panel (c) of Fig. 14-1 already shows the price: an overshoot of about 9% right next to the discontinuity that no amount of filter length will remove — the Gibbs phenomenon of §14.3.

14.3 Gibbs Phenomenon

14.3.1 Truncated ideal filters have Gibbs “ears”

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.

2026-06-12T22:40:38.675583 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0.0 0.2 0.4 0.6 0.8 1.0 omega/pi 0.0 0.2 0.4 0.6 0.8 1.0 1.2 |H_t| Gibbs ears: ~9% overshoot, height does NOT shrink with N Rectangular truncation of ideal LPF (omega_c = 0.3pi): ears narrow but never flatten 25-point (M=12) 129-point (M=64)
Fig. 14-2 — Gibbs “ears” for rectangular truncation at $N=25$ and $N=129$. Increasing the length makes the ears narrower (so the ISE does decrease) but their height stays the same (~9% overshoot).(加長濾波器只會讓「耳朵」變窄、不會變矮)
Must remember
Increasing filter length $\Rightarrow$ narrower ears (reduces ISE) but the ear height stays $\approx 9\%$. Therefore the truncated design is not optimal by the minimax criterion(極大極小準則) — its worst-case error never improves.

14.3.2 Where Gibbs comes from

Truncation of $h_d[n]$ to $2M+1$ points is multiplication by a rectangular window(矩形窗):

Truncation = windowing $$h_t[n] \;=\; h_d[n]\cdot w_R[n], \qquad w_R[n] = \begin{cases} 1, & -M \le n \le M \\ 0, & \text{otherwise} \end{cases}$$

Multiplication in the time domain is (periodic) convolution in the frequency domain(頻域摺積) — the modulation/windowing theorem:

Modulation (windowing) theorem $$g[n]\cdot h[n] \;\;\longleftrightarrow\;\; \frac{1}{2\pi}\int_{-\pi}^{\pi} G(e^{j\theta})\,H\!\left(e^{j(\omega-\theta)}\right) d\theta$$

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 核):

Rectangular window spectrum $$W_R(e^{j\omega}) \;=\; \sum_{n=-M}^{M} e^{-j\omega n} \;=\; \frac{\sin\!\left((2M+1)\,\omega/2\right)}{\sin\left(\omega/2\right)}$$
2026-06-12T22:40:38.919836 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −1.00 −0.75 −0.50 −0.25 0.00 0.25 0.50 0.75 1.00 omega/pi −2.5 0.0 2.5 5.0 7.5 10.0 12.5 15.0 W_R mainlobe, width 4pi/(2M+1) sidelobes -> ripples (~invariant with length) DTFT of rectangular window (M = 7): periodic sinc sin((2M+1)w/2)/sin(w/2)
Fig. 14-3 — The periodic sinc $W_R(e^{j\omega})$ for $M=7$. Mainlobe (shaded) has width $4\pi/(2M+1)$; the first zero crossings sit at $\pm 2\pi/(2M+1)$. Sidelobes oscillate with nearly length-invariant relative height.(矩形窗的頻譜:主瓣決定過渡帶,旁瓣決定漣波)

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.

14.3.3 Mainlobe vs. sidelobes — who controls what

The two knobs of windowed design
  • Mainlobe width(主瓣寬度) $\propto 1/L$ (inverse of window length) ⟶ determines the transition band(過渡帶) width. Longer filter ⇒ sharper transition.
  • Sidelobe height(旁瓣高度) ⟶ determines the ripples(漣波) in passband and stopband. It is set by the window shape and is ≈ invariant with length — you cannot ripple your way out by adding taps.
直觀解釋(點擊展開)
把理想磚牆響應想成一張清晰的圖,窗函數的頻譜 $W(e^{j\omega})$ 是一支「模糊刷」。刷子的主瓣寬度決定邊緣被塗開多寬(過渡帶);刷毛旁邊的旁瓣則在平坦區留下波紋(漣波)。把濾波器加長,刷子整體變細(過渡帶縮小),但旁瓣相對於主瓣的高度比例不變,所以波紋高度不變 —— 這就是 Gibbs 耳朵不會變矮的原因。想要更低的漣波,必須換一支「旁瓣更低」的刷子(換窗形),代價是主瓣更寬。

14.4 Window Shapes for FIR Filters

14.4.1 Commonly used windows

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:

Window definitions (−M ≤ n ≤ M) $$\begin{aligned} \text{Rectangular:}\quad & w[n] = 1 \\[2pt] \text{Hann:}\quad & w[n] = 0.5 + 0.5\cos\!\Bigl(2\pi\tfrac{n}{2M+1}\Bigr) \\[2pt] \text{Hamming:}\quad & w[n] = 0.54 + 0.46\cos\!\Bigl(2\pi\tfrac{n}{2M+1}\Bigr) \\[2pt] \text{Blackman:}\quad & w[n] = 0.42 + 0.5\cos\!\Bigl(2\pi\tfrac{n}{2M+1}\Bigr) + 0.08\cos\!\Bigl(2\pi\tfrac{2n}{2M+1}\Bigr) \end{aligned}$$

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.

2026-06-12T22:40:39.509757 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −10 0 10 0.0 0.2 0.4 0.6 0.8 1.0 Rectangular −10 0 10 0.0 0.2 0.4 0.6 0.8 1.0 Hann −10 0 10 0.0 0.2 0.4 0.6 0.8 1.0 Hamming −10 0 10 0.0 0.2 0.4 0.6 0.8 1.0 Blackman 0.0 0.2 0.4 0.6 0.8 1.0 omega/pi −100 −80 −60 −40 −20 0 |W| (dB) Window spectra on dB scale (N = 25): mainlobe width vs. sidelobe level trade-off Rectangular Hann Hamming Blackman
Fig. 14-4 — Top: the four windows in the time domain ($N = 25$). Bottom: their spectra in dB. Rectangular: narrowest mainlobe, $-13$ dB sidelobes. Blackman: widest mainlobe (3×), sidelobes below $-57$ dB.(窗形比較:主瓣寬度與旁瓣高度互相犧牲)

14.4.2 Comparison of commonly used windows

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)$−210$1.81\pi/M$
Bartlett−25$8\pi/M$−251.33$2.37\pi/M$
Hann−31$8\pi/M$−443.86$5.01\pi/M$
Hamming−41$8\pi/M$−534.86$6.27\pi/M$
Blackman−57$12\pi/M$−747.04$9.19\pi/M$
Two different M conventions — don’t mix them
The window formulas of §14.4.1 use $-M\le n\le M$, i.e. length $L = 2M+1$ and order $2M$. The table above (from O&S) uses $M$ = filter order, i.e. length $M+1$. When you plug numbers into “$8\pi/M$”, make sure $M$ is the order, not the half-width. On exams, state your convention explicitly.
How to read the table on an exam
  • Peak approximation error = the stopband ripple you actually get in the filter (e.g. Hamming ⇒ about $-53$ dB stopband), which is better than the raw sidelobe level because the convolution integrates the sidelobes.
  • The window shape fixes the ripple $\delta$; the window length then fixes the transition width. Two specs ⇒ two knobs.
  • Windowed designs always give $\delta_p = \delta_s$ — equal passband and stopband ripple (see §14.5.3).

14.4.3 Adjustable windows: the Kaiser window

The fixed windows offer only discrete main-sidelobe trade-offs. The Kaiser window(凱瑟窗) is parametric: a continuous knob $\beta$ sweeps the trade-off.

Kaiser window $$w[n] \;=\; \frac{I_0\!\left(\beta\sqrt{1-\left(\frac{n}{M}\right)^{2}}\,\right)}{I_0(\beta)}, \qquad -M \le n \le M$$

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.

2026-06-12T22:40:39.958636 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −10 −5 0 5 10 n 0.0 0.2 0.4 0.6 0.8 1.0 w[n] envelope Kaiser window shape (M = 12) beta = 0 beta = 3 beta = 6 beta = 9 0.0 0.2 0.4 0.6 0.8 1.0 omega/pi −100 −80 −60 −40 −20 0 dB Spectra: beta trades mainlobe vs sidelobes beta = 0 beta = 3 beta = 6 beta = 9
Fig. 14-5 — Kaiser window family for $\beta = 0, 3, 6, 9$ ($M=12$): shapes (left) and spectra (right). One parameter continuously trades mainlobe width against sidelobe level.($\beta$ 連續調整主瓣/旁瓣的取捨)

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$:

Kaiser β from stopband attenuation α (dB) $$\beta \;=\; \begin{cases} 0.1102\,(\alpha - 8.7), & \alpha > 50 \\[2pt] 0.5842\,(\alpha - 21)^{0.4} + 0.07886\,(\alpha - 21), & 21 \le \alpha \le 50 \\[2pt] 0, & \alpha < 21 \end{cases}$$
Required order from transition width $$N \;\approx\; \frac{\alpha - 8}{2.3\,\Delta\omega}$$

(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.

MATLAB
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).

14.5 Windowed Design in Practice

14.5.1 Worked example: 25-point Hamming lowpass

Example 14-1 — Design a 25-point FIR low-pass filter with cutoff 600 Hz (sampling rate 8 kHz)

No specific transition/ripple requirements are given, so we compromise with a Hamming window.

Step 0 — convert to radians/sample: $$\omega_c \;=\; \frac{600}{8000}\times 2\pi \;=\; 0.15\pi \ \text{rad/sample}$$ (600 cycles/sec ÷ 8000 samples/sec × 2π rad/cycle.)
Step 1 — ideal impulse response: $$h_d[n] = \frac{\sin 0.15\pi n}{\pi n}$$
Step 2 — get the window: Hamming at $N = 25 \Rightarrow M = 12$ (since $N = 2M+1$): $$w[n] = 0.54 + 0.46\cos\!\Bigl(2\pi\frac{n}{25}\Bigr), \qquad -12 \le n \le 12$$
Step 3 — apply the window: $$h[n] = h_d[n]\cdot w[n] = \frac{\sin 0.15\pi n}{\pi n}\Bigl(0.54 + 0.46\cos\frac{2\pi n}{25}\Bigr), \quad -12 \le n \le 12$$ then delay by 12 samples for causality.
2026-06-12T22:40:40.455643 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 5 10 15 20 25 n 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 h[n] h[n] = h_d[n-12] w[n-12], N = 25 0.0 0.2 0.4 0.6 0.8 1.0 omega/pi −100 −80 −60 −40 −20 0 |H| (dB) omega_c = 0.15pi (600 Hz @ 8 kHz) Magnitude: ~ -53 dB stopband (Hamming)
Fig. 14-6 — Example 14-1 result: causal impulse response (left) and magnitude in dB (right). The Hamming window delivers its promised ≈ −53 dB stopband; the transition is centered on $\omega_c = 0.15\pi$ (600 Hz at $f_s$ = 8 kHz).(25 點 Hamming 視窗低通:阻帶約 −53 dB)

14.5.2 Frequency-response (FR) arithmetic

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(高通):

Highpass from allpass minus lowpass $$H_{HP}(e^{j\omega}) = 1 - H_{LP}(e^{j\omega}) \qquad\Longleftrightarrow\qquad h_{HP}[n] \;=\; \delta[n] - \frac{\sin \omega_c n}{\pi n}$$

since $\delta[n] \leftrightarrow H(e^{j\omega}) = 1$ (allpass). The same arithmetic gives bandpass and bandstop responses (Exercise 5).

This wouldn’t work if phases were nonzero!
$|H_1 + H_2| \ne |H_1| + |H_2|$ in general. FR arithmetic relies on the ideal responses being zero-phase (pure real). After designing, you may delay the final $h[n]$ for causality — a common error is to subtract responses that carry different delays, which scrambles the magnitudes.

14.5.3 Window technique: “overdesign”

Window methods give you no independent control of passband vs. stopband ripple:

14.6 Design by Iterative Optimization; FIR vs. IIR

14.6.1 Equiripple design (Parks–McClellan)

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.

2026-06-12T22:40:40.729991 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0.0 0.2 0.4 0.6 0.8 1.0 omega/pi −80 −70 −60 −50 −40 −30 −20 −10 0 |H| (dB) stopband spec -40 dB passband spec -1 dB Same spec (wp=0.22pi, ws=0.29pi, A=40 dB): equiripple needs fewer taps Kaiser window, 65 taps (beta = 3.40) Parks-McClellan (equiripple), 45 taps
Fig. 14-7 — Same spec ($\omega_p = 0.22\pi$, $\omega_s = 0.29\pi$, $-1$ dB passband, $-40$ dB stopband): Kaiser window needs ~64 taps; the Parks–McClellan equiripple design meets it with 45 taps. Notice the equal-height stopband ripples of the equiripple design vs. the decaying ripples of the Kaiser design.(等漣波設計把每個漣波都「貼著規格」,因此階數更省)
MATLAB
[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.

14.6.2 Note on IIR and FIR design

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 designOrderTypeMultiplications (symmetric structure)
Butterworth18IIR
Chebyshev I8IIR
Chebyshev II8IIR
Elliptic5IIR8
Kaiser (window)63FIR32 (linear phase)
Parks–McClellan44FIR23 (linear phase)
The FIR-vs-IIR verdict
  • IIR requires far fewer multiplications (less complexity): elliptic order 5 ⇒ 8 multiplies vs. 23–32 for FIR.
  • FIR can achieve exactly linear phase (symmetric $h[n]$ — which also halves the multiplications) and has no stability concern (no poles outside $z=0$, no limit cycles).
  • Choose IIR when complexity dominates and phase doesn’t matter; choose FIR when linear phase / robustness matter.

14.7 Summary

Windowed design recipe

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).

Least integral-squared error

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.

Gibbs phenomenon

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.

Window trade-off

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.

Kaiser formulas

$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.

Equiripple & FIR vs IIR

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.

Exercises

Exercise 1 — Optimal truncation in the ISE sense

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.

Click to reveal solution

(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.

Exercise 2 — Gibbs phenomenon (concept)

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?

Click to reveal solution

(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).

Exercise 3 — Windowed-sinc lowpass design

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?

Click to reveal solution

(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.

Exercise 4 — Kaiser window sizing from a spec

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.

Click to reveal solution

(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$.

Exercise 5 — Frequency-response arithmetic

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.

Click to reveal solution

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.)

Exercise 6 — MATLAB: Kaiser design with kaiserord / fir1

Problem: 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.

Click to reveal solution

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$):

2026-06-12T22:40:41.016901 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0.0 0.2 0.4 0.6 0.8 1.0 omega/pi −80 −60 −40 −20 0 dB Kaiser design, 65 taps: full band 0.00 0.05 0.10 0.15 0.20 0.25 0.30 omega/pi −2.0 −1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 2.0 Passband zoom: ripple << 1 dB
Exercise 6 figure — Kaiser design (65 taps): the full-band response just touches the −40 dB stopband line; the passband zoom shows ripple far below the 1 dB allowance — the “overdesign” of window methods ($\delta_p = \delta_s$) in action.(窗法強制 $\delta_p=\delta_s$,通帶因此被「過度設計」)