Filters
A filter keeps some frequencies and removes others, and it does it with nothing but arithmetic: no sieve, no resonant circuit, just a weighted sum of recent samples, repeated for every sample that flows through. This chapter opens that arithmetic up, defines the three numbers every filter is specified by, and prices steepness with the lab's real counts. Chapter 6's filter gets its explanation here at last.
The weighted sum, worked small
Imagine a filter whose whole recipe is
three weights: ¼, ½, ¼. Each output is
¼ × the previous sample + ½ × this one
+ ¼ × the next. Feed it a steady
signal — 8, 8, 8, 8 — and it answers
8 (the weights sum to 1). Feed it a
signal that alternates every sample —
0, 16, 0, 16 — and at a 16 it answers
¼×0 + ½×16 + ¼×0 = 8; at a 0 it answers
¼×16 + 0 + ¼×16 = 8. The wild
alternation has been smoothed flat,
while the steady signal passed
untouched. That toy is a low-pass
filter: slow changes survive, fast
changes are averaged away. The weights
are called taps, and real filters
are this same sum with more of them,
chosen by mathematics (the firdes
designer functions) rather than by
hand-waving — chapter 6's filter had
231 taps, and every output sample
cost 231 multiplications to produce.
Remember that price when chapter 15
totals the computer bill.
Why a sum of neighbours prefers slow signals: a slow wave's neighbours are nearly equal to it, so the weighted average is the wave itself. A fast wave's neighbours disagree — what one adds, the next subtracts — and the average collapses. Filtering is disagreement, averaged.
The three numbers
- Cutoff frequency: where the keeping stops and the removing begins. A low-pass with a 1,500 Hz cutoff keeps the band below and removes the band above.
- Transition band: the filter cannot
turn on a knife edge. Between "kept"
and "removed" lies a slope whose width
you choose — 500 Hz in chapter 6. On
the slope, signals are partly kept.
Narrower is tidier and costs more:
the lab asked the designer for the
same filter with a 200 Hz transition
and the tap count rose from 231 to
579 (
t07-filter-taps.txt) — two and a half times the arithmetic for every sample, forever, to buy a steeper hillside. - Gain: how much the kept band is scaled — 1.0, unchanged, throughout this guide.
The same shape turned inside out is a high-pass (keeps the fast, removes the slow); a band-pass is a kept slice with a slope on each side. One idea, three postures.
What filtering cannot do
Chapter 3's warning belongs here too, because filters are where readers try to break it: a filter cannot un-alias. Once a too-fast signal has folded into your band, it is — as far as any arithmetic downstream can know — a genuine signal at its false address. Filtering works on signals that have been sampled honestly. The order of operations in the next chapter (filter while still fast, then slow down) is not a style preference; it is the only order in which the information still exists to be kept.
And a filter is not free in time either: 231 taps means the output at any moment is a judgement about the last 231 inputs — the startup transient chapter 6 measured (mean 0.9965, peak 1.0310, energy in the neighbouring bins) is the visible edge of that fact, the filter thinking with a partly empty notebook for its first instants.
Check: a 1,000 Hz tone and a
5,000 Hz tone enter chapter 6's filter
together. The 1,000 Hz tone is in the
kept band (cutoff 1,500): it passes.
The 5,000 Hz tone is far up the slope
and beyond: it is removed — not turned
down a little, removed, by tens of
decibels. Predict that, run it through
the lab script with a second source
added, and let measure.py grade you:
chapter 9 is waiting with a sterner
exam, where the same filter is the
difference between a clean signal and
a forged one.