C941 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C9 · Lesson 41 · Designing FIR filters

From an ideal response to taps you can run

The ideal low-pass filter's impulse response is a sinc that runs forever in both directions. A real FIR filter keeps only a few dozen of its samples, delays them so the filter is causal, and tapers the ends with a window. That recipe gives a filter with exactly linear phase, guaranteed stability and a response you can predict before computing a single tap. What it costs is length, and the formulas say how much.

  • The curve is the response, in dB, of a 21-tap low-pass built by the window method: the ideal sinc for cutoff ωc, cut to 21 samples.
  • With the rectangular window (h = 0) the stopband ripples sit only about 21 dB down, and the passband ripples near the edge (the Gibbs effect).
  • Switch to the Hamming window (h = 1): the stopband drops to around −53 dB, and the transition from pass to stop gets wider. Move the cutoff: the shape slides along without changing.

Predict

A Hamming-window design meets its stopband with 53 dB to spare in a 31-tap filter. The transition band must be made half as wide. What happens to the stopband attenuation if the filter is lengthened to 61 taps?

Name it

The window method

  1. Pick the cutoff ωc in the middle of the transition band.
  2. Take the ideal low-pass response, delayed by M samples so it's centered: hd[n]=sin⁡(ωc(n−M))π(n−M) (and ωc/π at n = M).
  3. Keep N = 2M + 1 samples, n = 0 to N − 1, and multiply by a window w[n].

The filter's response is the ideal one convolved with the window's spectrum. The window's main lobe sets the transition width, and its side lobes set the stopband attenuation.

WindowStopband attenuationTransition width Δf, cycles per sample
rectangular21 dB0.9/N
Hann44 dB3.1/N
Hamming53 dB3.3/N
Blackman74 dB5.5/N

So N≈C/Δf, where Δf is the transition width divided by the sample rate.

The Kaiser window

The Kaiser window has a parameter β that trades attenuation against width continuously. For a stopband attenuation of A dB and a transition of Δω radians per sample:

N≈A−82.285Δω+1,β={0.1102(A−8.7)A>500.5842(A−21)0.4+0.07886(A−21)21≤A≤50

Linear phase and cost

Symmetric taps give exactly linear phase: every frequency is delayed by M = (N − 1)/2 samples, so the waveform's shape is kept. An N-tap filter costs N multiply-adds per output sample, or about N/2 multiplies if the symmetric pairs are added first. High-pass, band-pass and band-stop filters come from the same recipe, using differences of ideal low-passes.

Worked example

Design a low-pass for an 8 kHz system: pass up to 1 kHz, stop from 1.5 kHz down by at least 50 dB.

Show the solution
  1. Transition width. The transition is 500 Hz: Δf=500/8000=0.0625
  2. Length. Hamming gives 53 dB, so N≈3.3/0.0625=52.8 which makes 53 taps.
  3. Cutoff. The cutoff goes in the middle, 1.25 kHz: ωc=2π×1250/8000=0.982rad
  4. Kaiser alternative. A Kaiser design for exactly 50 dB needs N=422.285×0.393+1=47.8 so 48 taps, with β = 4.53: a few taps saved by not overshooting the attenuation.

Answer a 53-tap Hamming design with ωc = 0.982 rad (1.25 kHz), or a 48-tap Kaiser design with β = 4.53.

Worked example

How long does that 53-tap filter delay a signal, and what does it cost to run?

Show the solution
  1. Delay. (53−1)/2=26samples which is 3.25 ms at 8 kHz, the same at every frequency.
  2. Cost. It needs 53 multiply-adds per sample, 424,000 a second, or 27 multiplies per sample if the symmetric pairs are summed first.
  3. In context. Easy for any processor at 8 kHz, but at 100 MHz sample rates it's why FIR filters are built in hardware.

Answer a delay of 26 samples (3.25 ms), and 53 multiply-adds per sample, 424,000 a second.

Worked example

Find the center tap and the taps 1 and 4 samples from it for an ideal low-pass with ωc=π/4, before windowing.

Show the solution
  1. Center. ωc/π=0.25
  2. One away. sin⁡(π/4)/π=0.225
  3. Four away. sin⁡(π)/(4π)=0
  4. The pattern. The taps are symmetric about the center, and every fourth one is zero. With the Hamming window, the taps 4 away are still 0 and the others are scaled toward the ends.

Answer the center tap is 0.25, the taps 1 away are 0.225, and the taps 4 away are 0.

Check

A low-pass at 8000 Hz passes up to 1000 Hz and stops from 1000 + 1000 Hz, using a Hamming window.

(a)

About how many taps does it need?

(b)

Where should the cutoff go?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

A Kaiser-window design needs 60 dB of attenuation over a transition of Δf = 0.02 cycles per sample.

(a)

About how many taps does it need?

(b)

What β does it use?

Check

A linear-phase FIR filter has 53 taps at 8 kHz.

(a)

How long does it delay every frequency?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

(b)

How many multiply-adds a second does it need, without using the symmetry?

Check

An ideal low-pass has ωc = 0.25π.

(a)

What is its center tap?

(b)

What is the tap 1 samples from the center?

Check

A specification needs 65 dB of stopband attenuation. Which window can the window method use?

Check

A window whose transition width is C/N cycles per sample is used at sample rate f for a transition of t hertz.

Step 1

What is the transition in cycles per sample?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why does a longer FIR filter give a sharper transition but not a deeper stopband?

Practice

Keep practicing

7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.