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

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: |H(f)|=|sin⁡(πfM/fs)Msin⁡(πf/fs)|.
  • It's a crude low-pass: the main lobe ends in a null at fs/M, with more nulls at every multiple of it.
  • Choose M so that a null lands on a disturbance: M = 20 at fs = 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?

Name it

The FIR filter

yn=∑k=0N−1hkxn−k

The taps hk 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, H(f)=∑hke−j2πfk/fs.

Linear phase

If the taps are symmetric, hk=hN−1−k, every frequency is delayed by the same

N−12 samples

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

N≈A−82.285×2πΔf/fs

Each output costs N multiply-accumulates, so the work is Nfs 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
  1. Kaiser's estimate. With A−8=52 and the 1 kHz transition in radians per sample: N≈522.285×2π×100048000=174taps
  2. Round to an odd length. Choose 175, an odd number for a symmetric filter with a whole-sample delay.
  3. Delay. D=175−12=87samples=1.81ms
  4. Work. Every output takes 175 multiply-accumulates: 175×48000=8.4×106per second

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
  1. Gain at 60 Hz. 60 Hz at 1 kHz is 0.06 cycles per sample, and 8×0.06=0.48: |H|=|sin⁡(π×0.48)8sin⁡(π×0.06)|=0.666 or −3.5 dB.
  2. Removing 60 Hz entirely. Choose the average so that 60 Hz completes whole cycles in it: M = 20 at 1.2 kHz, since 1200Hz20=60Hz

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
  1. Delay in samples. 101−12=50samples
  2. Delay in time. 5048000Hz=1.04ms the same for all frequencies, so a pulse keeps its shape.
  3. 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 N≈(A−8)/(2.285Δω).

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

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.