D5 · Lesson 4 · FIR filters
Filters that compute each output as a weighted sum of recent inputs, the moving average and its comb of nulls, the impulse response equal to the taps, linear phase and its constant delay, designing a low-pass by windowing a sinc, and how many taps a sharp filter needs
The simplest digital filter is an average: replace each sample with the mean of the last few. It smooths noise, and it has a remarkable property: frequencies whose period fits a whole number of times into the averaging window vanish completely. Generalize the average to a weighted sum and you have the finite impulse response filter, the workhorse of digital signal processing. FIR filters are always stable, can have perfectly linear phase so that every frequency is delayed equally, and can be designed to any shape, at the cost of many multiplications per sample.
- The frequency response, in decibels, of an M-point moving average at a sampling rate of 1 kHz: .
- It's a crude low-pass: the main lobe ends in a null at , with more nulls at every multiple of it.
- Choose M so that a null lands on a disturbance: M = 20 at = 1.2 kHz would remove 60 Hz hum and all its harmonics.
Predict
An 8-point moving average runs at 1 kHz. At what frequency does its response first fall to zero?
A tone at 1000/8 = 125 Hz completes exactly one cycle in the 8 samples being averaged, so the average of its samples is zero whatever its phase. The same holds at 250 and 375 Hz. The −3 dB point is lower, at 55.7 Hz: a moving average is a poor low-pass but an excellent notch for anything periodic in M samples.
Name it
The FIR filter
The taps are the filter's impulse response: an impulse in gives the taps out, and after N samples the response is over, hence "finite". There's no feedback, so an FIR filter is always stable. Its frequency response is the DTFT of the taps, .
Linear phase
If the taps are symmetric, , every frequency is delayed by the same
so the waveform's shape is preserved, which matters for audio, data pulses and ECGs. Analog filters can't do this exactly.
Designing a low-pass
An ideal low-pass has a sinc impulse response, infinitely long. Truncating it to N taps and multiplying by a window (lesson 3) gives a practical filter; the window sets the stopband attenuation, and the length sets the transition width. Kaiser's estimate for the taps needed for attenuation A dB over a transition Δf is
Each output costs N multiply-accumulates, so the work is per second.
Worked example
An audio low-pass at 48 kHz needs 60 dB of stopband attenuation and a 1 kHz transition. How many taps, how much delay and how much work?
Show the solution
- Kaiser's estimate. With and the 1 kHz transition in radians per sample:
- Round to an odd length. Choose 175, an odd number for a symmetric filter with a whole-sample delay.
- Delay.
- Work. Every output takes 175 multiply-accumulates:
Answer 175 taps, a delay of 87 samples (1.81 ms), and 8.4 million multiply-accumulates per second.
Worked example
How much does the 8-point, 1 kHz moving average attenuate a 60 Hz tone?
Show the solution
- Gain at 60 Hz. 60 Hz at 1 kHz is 0.06 cycles per sample, and : or −3.5 dB.
- Removing 60 Hz entirely. Choose the average so that 60 Hz completes whole cycles in it: M = 20 at 1.2 kHz, since
Answer the average passes 0.666 of the 60 Hz tone, an attenuation of 3.5 dB; a 20-point average at 1.2 kHz would remove it.
Worked example
A linear-phase FIR filter has 101 taps at 48 kHz. What delay does every frequency see?
Show the solution
- Delay in samples.
- Delay in time. the same for all frequencies, so a pulse keeps its shape.
- Effect on music. Musicians notice delays of about 10 ms, so this one is harmless; a 1001-tap filter's 10 ms would not be.
Answer every frequency is delayed 50 samples, 1.04 ms.
Check
A 4-point moving average runs at 8 kHz. Where is its first null?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
Check
A symmetric 65-tap FIR filter runs at 8 kHz. How long does it delay the signal?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
About how many taps does a windowed FIR filter at 48 kHz need for 60 dB of attenuation with a 0.5 kHz transition band?
Check
How many million multiply-accumulates per second does a 101-tap FIR filter at 8 kHz need?
Check
A Kaiser-window FIR at 8 kHz needs 60 dB of attenuation and a 2 kHz transition; Kaiser's estimate is .
(a)
About how many taps?
(b)
What delay does it add?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
An 8-point moving average runs at 2 kHz.
(a)
What is its gain at 50 Hz?
(b)
Where is its first null?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
Explain why
Why does an FIR filter with symmetric taps delay every frequency by the same amount?
With symmetric taps, the filter's response can be written as a pair of terms for each tap equally far from the center, and each pair combines into a cosine centered on the middle tap. So the whole response is a real-valued function of frequency multiplied by a single phase factor that corresponds to a delay of half the filter's length. A pure delay shifts every frequency by the same time, so all the frequency components of a waveform come out aligned as they went in, and its shape is preserved apart from the filtering of its spectrum. Filters with feedback, or asymmetric taps, delay different frequencies by different amounts and distort the waveform's shape.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.