---
title: FIR design by windowing
heading: Truncating the ideal impulse response, how the window's spectrum sets ripple and transition width, the classic windows, and Kaiser's design formulas
eyebrow: S7 · Lesson 22 · FIR design by windowing
xp: 50
---

::: hook
The ideal lowpass filter's impulse response is known exactly, a sinc, but it's infinitely long. Cutting it off gives a realizable FIR filter, and the way it's cut off decides how good that filter is. Chopping abruptly leaves the Gibbs ripple of lesson 1: 9% overshoot, about 21 dB of stopband rejection, however many taps are used. Tapering the cut with a smooth window trades a wider transition band for much smaller ripple. Kaiser's window turns that trade into two formulas that give the length and shape needed to meet a specification directly.
:::

::: play
- The spectra of three windows of length M + 1 in dB: rectangular, Hamming and Blackman, each computed exactly as a sum of shifted Dirichlet kernels.
- The rectangular window has the narrowest main lobe but sidelobes only 13 dB down; Hamming's are 42 dB down and Blackman's 58 dB, with main lobes two and three times as wide.
- Increasing M narrows every main lobe without lowering any sidelobe: length buys sharpness, while the window's shape buys rejection.
:::
:::

```sim plot
view: graph
x: w = 0..3.1416
y: W = -120..0 dB
slider: M = 10..100 = 40 step 2
plot: 20*log(abs(sin((M + 1)*(w + 1e-9)/2)/sin((w + 1e-9)/2))/(M + 1)) | samples: 1500 | label: rectangular
plot: 20*log(abs(0.54*sin((M + 1)*(w + 1e-9)/2)/sin((w + 1e-9)/2) + 0.23*(sin((M + 1)*(w - 2*pi/M + 1e-9)/2)/sin((w - 2*pi/M + 1e-9)/2) + sin((M + 1)*(w + 2*pi/M + 1e-9)/2)/sin((w + 2*pi/M + 1e-9)/2)))/(0.54*(M + 1) - 0.46)) | samples: 1500 | color: ch2 | label: Hamming
plot: 20*log(abs(0.42*sin((M + 1)*(w + 1e-9)/2)/sin((w + 1e-9)/2) + 0.25*(sin((M + 1)*(w - 2*pi/M + 1e-9)/2)/sin((w - 2*pi/M + 1e-9)/2) + sin((M + 1)*(w + 2*pi/M + 1e-9)/2)/sin((w + 2*pi/M + 1e-9)/2)) + 0.04*(sin((M + 1)*(w - 4*pi/M + 1e-9)/2)/sin((w - 4*pi/M + 1e-9)/2) + sin((M + 1)*(w + 4*pi/M + 1e-9)/2)/sin((w + 4*pi/M + 1e-9)/2)))/(0.42*M)) | samples: 1500 | color: ch3 | label: Blackman
```

::: predict
## A rectangular-window lowpass design gives only 21 dB of stopband attenuation. Will doubling the number of taps improve it?

- [ ] Yes, to about 42 dB
- [ ] Yes, by about 6 dB
- [x] No: the transition narrows, but the ripple stays about the same
- [ ] It gets worse

::: reveal
No. The filter's response is the ideal response smoothed by the window's spectrum, and the ripple comes from the window's sidelobes, whose level relative to the main lobe is fixed by the window's shape, about −13 dB for the rectangle, giving roughly −21 dB of stopband error after integration. More taps only make the main lobe, and so the transition band, narrower. Better rejection needs a different window.
:::
:::

::: nameit
## Windowing the ideal response

For a lowpass with cutoff $\omega_c$ and delay α = M/2:

$$h_d[n] = \frac{\sin\omega_c(n - \alpha)}{\pi(n - \alpha)}, \qquad h[n] = h_d[n]w[n], \quad 0 \le n \le M$$

The designed response is the ideal one convolved (periodically) with $W(e^{j\omega})/2\pi$: the window's **main-lobe width** sets the transition width, and its **sidelobes** set the ripple, which is about the same in passband and stopband ($\delta_1 \approx \delta_2$).

| Window | Peak sidelobe | Main-lobe width | Peak error, 20 log δ |
|---|---|---|---|
| Rectangular | −13 dB | 4π/(M + 1) | −21 dB |
| Hann | −31 dB | 8π/M | −44 dB |
| Hamming | −41 dB | 8π/M | −53 dB |
| Blackman | −57 dB | 12π/M | −74 dB |

(Oppenheim and Schafer's Table 7.2.) The transition width of the designed filter is roughly the main-lobe width, a little less.

## The Kaiser window

$w[n] = I_0\left(\beta\sqrt{1 - ((n - \alpha)/\alpha)^2}\right)/I_0(\beta)$ has a shape parameter β. For a stopband attenuation $A = -20\log\delta$ and transition width $\Delta\omega = \omega_s - \omega_p$:

$$\beta = \begin{cases}0.1102(A - 8.7), & A > 50\\ 0.5842(A - 21)^{0.4} + 0.07886(A - 21), & 21 \le A \le 50\\ 0, & A < 21\end{cases} \qquad M = \frac{A - 8}{2.285\,\Delta\omega}$$

with $\omega_c$ midway between $\omega_p$ and $\omega_s$.
:::

::: example
## Design a Kaiser lowpass with $\omega_p$ = 0.4π, $\omega_s$ = 0.6π and $\delta_1 = \delta_2$ = 0.001.

::: solution
1. **Attenuation and transition.** A = 60 dB and Δω = 0.2π.
2. **Shape parameter.**
   $$\begin{aligned} \beta &= 0.1102(60 - 8.7) \\ &= 5.653 \end{aligned}$$
3. **Order.**
   $$\begin{aligned} M &= \frac{52}{2.285 \times 0.628} \\ &= 36.2 \end{aligned}$$
   so M = 37 (38 taps).
4. **Cutoff.** Put $\omega_c$ midway, at 0.5π.
5. **Check.** This is Oppenheim and Schafer's Example 7.8; the finished filter meets the specification with a little to spare.

**Answer:** β = 5.653, M = 37 (38 taps) and $\omega_c$ = 0.5π.
:::
:::

::: example
## Designing for the same 0.2π transition with a Hamming window: how long is it, and how much rejection does it give?

::: solution
1. **Length.** Hamming's main lobe is 8π/M wide, so a transition of about 0.2π needs
   $$\begin{aligned} M &\approx \frac{8\pi}{0.2\pi} \\ &= 40 \end{aligned}$$
   a little more than Kaiser's 37.
2. **Rejection.** Hamming gives a fixed −53 dB, short of the 60 dB required.
3. **Why Kaiser wins.** Kaiser's adjustable β is what lets it hit exactly the rejection needed with the shortest length.

**Answer:** M ≈ 40, with a fixed 53 dB of rejection, short of the 60 dB required.
:::
:::

::: example
## A lowpass needs about 44 dB of rejection and a 0.1π transition. Compare a Hann design with a Kaiser design.

::: solution
1. **Hann.** Hann's main lobe is 8π/M wide, so
   $$\begin{aligned} M &= \frac{8\pi}{0.1\pi} \\ &= 80 \end{aligned}$$
   for its fixed −44 dB peak error.
2. **Kaiser's β for A = 44.**
   $$\begin{aligned} \beta &= 0.5842(23)^{0.4} \\ &\quad + 0.07886 \times 23 \\ &= 3.86 \end{aligned}$$
3. **Kaiser's order.**
   $$\begin{aligned} M &= \frac{44 - 8}{2.285 \times 0.1\pi} \\ &= 50.1 \end{aligned}$$
   so M = 51.
4. **Compare.** The Kaiser window reaches the same rejection with about 40% fewer taps, because its β can be set for exactly the attenuation needed instead of a fixed window's.

**Answer:** Hann needs M = 80; Kaiser needs M = 51 (β = 3.86), about 40% fewer taps.
:::
:::

::: check
given: A = 55 | 60 | 80 | 100
answer: 0.1102*(A - 8.7)
tolerance: 0.5%

## A Kaiser design needs {A} dB of stopband attenuation. What β?

::: right
Right. $0.1102(A - 8.7)$ = {answer}.
:::

::: misses
- [0.5842*(A - 21)^0.4 + 0.07886*(A - 21)] That formula is for 21 to 50 dB.
- [any] Not yet. For A > 50: β = 0.1102(A − 8.7).
:::
:::

::: check
given: A = 30 | 40 | 45
answer: 0.5842*(A - 21)^0.4 + 0.07886*(A - 21)
tolerance: 0.5%

## A Kaiser design needs only {A} dB. What β?

::: right
Right. $0.5842(A - 21)^{0.4} + 0.07886(A - 21)$ = {answer}.
:::

::: misses
- [0.1102*(A - 8.7)] That formula is for A above 50 dB.
- [any] Not yet. Use the middle range of Kaiser's formula.
:::
:::

::: check
given: A = 40 | 60 | 80; d = 0.05 | 0.1 | 0.2
answer: (A - 8)/(2.285*d*pi)
tolerance: 0.5%

## A Kaiser design needs {A} dB with a transition width of {d}π. What does the formula give for M (before rounding up)?

::: right
Right. $(A - 8)/(2.285\Delta\omega)$ = {answer}.
:::

::: misses
- [(A - 8)/(2.285*d)] Δω is in radians: multiply by π.
- [any] Not yet. $M = (A - 8)/(2.285\,\Delta\omega)$.
:::
:::

::: check
given: M = 20 | 36 | 50; c = 0.35 | 0.45 | 0.62; n = 3 | 8 | 13
answer: sin(c*pi*(n - M/2))/(pi*(n - M/2))
tolerance: 0.5%

## A length-(M + 1) lowpass with M = {M} and cutoff {c}π: what's the ideal coefficient $h_d[\given{n}]$?

::: right
Right. $\frac{\sin\omega_c(n - M/2)}{\pi(n - M/2)}$ = {answer}.
:::

::: misses
- [sin(c*pi*n)/(pi*n)] Center the sinc at n = M/2 for a causal, linear-phase filter.
- [any] Not yet. Delay the ideal response by α = M/2.
:::
:::

::: check
given: M = 30 | 50 | 64; n = 5 | 12 | 20
answer: 0.54 - 0.46*cos(2*pi*n/M)
tolerance: 0.5%

## What's the Hamming window's value at n = {n} for M = {M}?

::: right
Right. $0.54 - 0.46\cos(2\pi n/M)$ = {answer}.
:::

::: misses
- [0.5 - 0.5*cos(2*pi*n/M)] That's the Hann window.
- [any] Not yet. $w[n] = 0.54 - 0.46\cos(2\pi n/M)$.
:::
:::

::: check
given: d = 0.05 | 0.1 | 0.25
answer: 12/d
tolerance: 0.5%

## A Blackman-window design must have a transition width of about {d}π. Roughly what M does that take, using the main-lobe width?

::: right
Right. 12π/M = Δω gives M ≈ {answer}.
:::

::: misses
- [8/d] That's a Hann or Hamming window's main lobe.
- [any] Not yet. The Blackman main lobe is 12π/M wide.
:::
:::

::: check
kind: parts
given: d = 0.05 | 0.1 | 0.2

## A lowpass needs about 44 dB of rejection with a {d}π transition.

::: part
answer: 8/d
tolerance: 0.5%

### What order does a Hann window need (main lobe 8π/M)?

::: misses
- [4/d] That's the rectangular window's main lobe.
- [any] $M = 8\pi/\Delta\omega$.
:::
:::

::: part
answer: 36/(2.285*d*pi)
tolerance: 0.5%

### What order does Kaiser's formula give for 44 dB?

::: misses
- [any] $(A - 8)/(2.285\Delta\omega)$.
:::
:::
:::

::: check
kind: derivation
vars: M = 10..100, c = 0.1..0.9, n = 0..100

## A length-(M + 1) Hamming-window lowpass with cutoff cπ is evaluated at tap n (n ≠ M/2).

::: step
answer: sin(c*pi*(n - M/2))/(pi*(n - M/2))

### What is the ideal coefficient $h_d[n]$?
:::

::: step
answer: 0.54 - 0.46*cos(2*pi*n/M)

### What is the Hamming window there?
:::

::: step
answer: sin(c*pi*(n - M/2))/(pi*(n - M/2))*(0.54 - 0.46*cos(2*pi*n/M))

### What is the designed coefficient?
:::

::: right
Right. The window tapers the ideal sinc's slow decay, trading a wider transition for lower sidelobes.
:::
:::

::: explain
## Why does tapering the window lower the ripple but widen the transition band?

::: model
Multiplying the ideal impulse response by a window means the designed frequency response is the ideal brick-wall response convolved with the window's spectrum. Every bump of that spectrum, as it slides across the brick wall's edge, adds a little wiggle to the result, so the sidelobes of the window become the ripple of the filter, and the main lobe's width sets how gradually the response falls from passband to stopband. A rectangular window has the narrowest possible main lobe for its length, but its abrupt ends give it high sidelobes. Tapering the ends smooths the window, which spreads its spectrum's energy into a wider main lobe and drains the sidelobes. The filter gets less ripple and a slower transition, and only more taps can narrow it again.
:::
:::

::: practice

::: check
given: A = 55 | 60 | 65 | 70 | 80 | 90 | 100
answer: 0.1102*(A - 8.7)
tolerance: 0.5%

## Kaiser β for {A} dB?

::: misses
- [any] $0.1102(A - 8.7)$.
:::
:::

::: check
given: A = 50 | 70; d = 0.08 | 0.15
answer: (A - 8)/(2.285*d*pi)
tolerance: 0.5%

## Kaiser M for {A} dB, transition {d}π?

::: misses
- [any] $(A - 8)/(2.285\Delta\omega)$.
:::
:::

::: check
given: M = 24 | 40; c = 0.3 | 0.6; n = 4 | 9
answer: sin(c*pi*(n - M/2))/(pi*(n - M/2))
tolerance: 0.5%

## $h_d[\given{n}]$: M {M}, cutoff {c}π?

::: misses
- [any] Centered sinc.
:::
:::
:::
