Before any filter is designed, someone writes down where its gain may not go. Below, those places are hatched, and two filters are tried against them. Watch where each curve runs into a hatched zone.
A spec is a set of zones to keep out of
f_s = 8 kHz. Pass band 0 to 1 kHz: gain between 0.95 and 1.05. Stop band 1.5 to 4 kHz: gain at most 0.01.
Describe this picture
One panel for kHz: the gain from 0 to 1.2 against frequency from 0 to 4000 Hz. The forbidden zones are hatched: outside 0.95 to 1.05 in the pass band, 0 to 1 kHz, and above 0.01 in the stop band, 1.5 to 4 kHz. Along the top the bands are named “pass band”, “transition” and “stop band”. Two curves are drawn, the 4-point average as a dashed line and a 41-tap FIR as a solid line; each name in the key gains “fails” or “passes” once its curve is complete. Where a curve fails a band, a cross marks its worst point there. The readouts are the worst value in the pass band and in the stop band, for the curve drawn last; they read “not yet” before the first curve.
The clip lasts 15 s. First the zones fade in, with the transition band, 1 to 1.5 kHz, left free. Then the dashed curve draws. It fails both bands: 0.653 at 1 kHz, far below 0.95, and 0.3182 at 1.5 kHz. Last the solid curve draws. It stays out of every zone, between 0.997 and 1.012 in the pass band and at most 0.0095 in the stop band, so it meets the spec; the readouts end on 1.012 and 0.0095, both passing.
A spec is a set of zones to keep out of
On the page Frequency response of discrete-time systems (12.4) you saw that the ideal low-pass cannot be built. Its impulse response never ends, and half of it comes before the input. So every real filter is only close to ideal. The engineer’s question is how close is close enough.
The answer is written down before any design starts, and it is called a specification. Here is the one I will use for this chapter and the next, so I call it the running spec.
The sample rate is kHz. Keep everything from 0 to 1 kHz with the gain between 0.95 and 1.05. Remove everything from 1.5 to 4 kHz, with the gain at most 0.01. Between 1 and 1.5 kHz the gain may do anything.
The three ranges have names. The range we keep is the pass band, and its top is Hz, as in Anti-aliasing and practical converters (10.4). The range we remove is the stop band, from Hz up.
The free range between them is the transition band. I write the allowed error in the pass band as , so the gain stays within , and the stop-band limit as .
Now draw it. Shade every place on the gain plot where the curve may not go: above 1.05 or below 0.95 in the pass band, and above 0.01 in the stop band. Each shaded area is a forbidden zone, and the drawing is the spec’s tolerance scheme. Think of a bowling lane with bumpers: any path to the pins is fine, as long as it never touches a bumper.
The picture at the top of the page draws this scheme for the running spec and tries two filters against it. The dashed curve is 12.4’s 4-point moving average, run at 8 kHz. You met its gain of 0.653 at in 12.4, and at 8 kHz that frequency is 1000 Hz, far below 0.95.
The solid curve is a 41-tap FIR low-pass. Its method is the subject of Window-method FIR design (19.1). This filter uses a Kaiser window from Window functions compared (15.2), with and a cutoff of 1250 Hz. For now, only its gain curve matters.
Look at the stop band at the end. The solid curve is so close to 0 that you cannot see it pass, even though the readout says it does. A gain of 0.01 is a hair above the axis.
Ripple and attenuation in decibels
The cure is the decibel scale of How big is a signal (1.3). A gain is an amplitude ratio, so its level is of it. For the stop band I define the stop-band attenuation
The minus sign makes it a positive number, because is less than 1. So is 20 dB, 0.01 is 40 dB and 0.001 is 60 dB. Each extra 20 dB is ten times less leakage. This is the “A dB down” of 10.4.
The pass band works the same way. The top of the corridor is dB, and the bottom is dB. They are not mirror images, because the logarithm stretches values below 1 more than values above it. From top to bottom the pass-band ripple is
On a dB axis, 0.01 sits at −40 dB, far from 0, so a spec is usually drawn in dB. Datasheets and design tools quote it that way too: MATLAB’s designfilt asks for a “PassbandRipple” and a “StopbandAttenuation” in dB.
A filter design also needs the spec in rad/sample. With from Frequency in discrete time (12.1), the band edges are
The transition width is the distance between them, rad/sample. In hertz it is Hz.
Four shapes of one scheme
A low-pass keeps the low band. Flip the zones and you get a high-pass, which keeps the high band. A band-pass keeps one band in the middle and removes both sides, and a band-stop removes one band in the middle and keeps both sides. Each is the same kind of drawing, with pass bands, stop bands and free transitions between them.
The notch of Resonators, notches and combs (17.4) fits here. It removes a narrow band around the hum and keeps the rest, so it is a band-stop whose stop band is very narrow.
Halve the transition, double the taps
What does a spec cost? Take three FIR low-passes made by the same method as before, with 41, 81 and 161 taps. Each has its transition centred on 1250 Hz.
Now keep that centre and squeeze the transition band from both sides. It is like braking: to stop in half the distance, you need a much harder brake. Below, the zones close in while the three curves stay put.
Halve the transition, double the taps
The running spec in dB, its transition band centred on 1250 Hz. Three FIR low-passes made by the method of 19.1: 41, 81 and 161 taps.
Transition 1000 to 1500 Hz, 500 Hz wide: all three pass. The shortest, 41 taps, delays the signal by 20 samples, 2.5 ms.
Describe this picture
One panel of the running spec in dB, its transition band centred on 1250 Hz, with three FIR low-passes made by the method of 19.1. It plots the gain from −80 to 5 dB against frequency from 0 to 4000 Hz. The forbidden zones are hatched: above +0.42 dB and below −0.45 dB in the pass band, and above −40 dB in the stop band, whose edge is labelled “−40 dB”. The two inner zone edges carry their frequencies under the axis, 1000 Hz and 1500 Hz at the start. The 41-tap filter is a solid line, the 81-tap one dashed and the 161-tap one dotted. A curve that fails is drawn faint, with a cross at its worst point, and the key row adds “passes” or “fails” to each name. The readouts are the transition width and the shortest filter that passes, with its delay.
The clip lasts 14 s. It starts at the running spec, 1000 to 1500 Hz: all three pass, and the shortest, 41 taps, delays the signal by 20 samples, 2.5 ms. Then the zones close in around 1250 Hz. At 250 Hz wide, 1125 to 1375 Hz, 41 taps fail both bands, and 81 taps pass, with a delay of 5.0 ms. At the end, 125 Hz wide, only 161 taps pass, at −40.1 dB, with a delay of 10.0 ms: each halving of the transition doubled the length and the delay. After the clip either inner edge of the transition band is a handle named “Transition width”, from 100 to 1000 Hz, with a value like “125 Hz: 161 taps pass”; both edges move together about 1250 Hz. The arrow keys change the width by 25 Hz, Page Up and Page Down by 100 Hz, and Home and End jump to 100 and 1000 Hz. At other widths the caption reads like “Transition 400 Hz: the shortest that passes is 81 taps, 5.0 ms.” The width is kept in the link, as drawer.width.
Watch the curves as the zones move. The curves stay where they are; only the zones, the words and the crosses change. A curve fails when the narrower transition asks it to fall faster than its length allows.
After the clip, drag either inner edge of the transition band, or use the arrow keys, to set the width yourself. At 100 Hz none of the three passes. On the 25 Hz steps, 41 taps pass from 450 Hz, 81 taps from 225 Hz and 161 taps from 125 Hz.
Between the 25 Hz steps the limits are a little lower. With exact band edges, the narrowest transition each filter passes is 445.0 Hz for 41 taps, 223.6 Hz for 81 and 111.9 Hz for 161. Each time the length roughly doubles, the width it can meet halves.
Phase and the delay budget
Magnitude is not the whole story. In Linear-phase systems (17.3) you saw that symmetric taps delay every frequency by the same
so a waveform keeps its shape and only arrives late. Divide by to get seconds. The 41-tap filter delays by 20 samples, which is 2.5 ms at 8 kHz. Halving the transition doubled the length, and so it doubled that delay too.
A real-time system can only wait so long. The most delay it can afford is its delay budget. A hearing aid aims to keep all its processing under about 10 ms, because the wearer also hears the direct sound, and a longer gap can sound like an echo. Musicians who listen to themselves live want only a few ms.
At 16 kHz, a budget of 10 ms allows samples, so the filter can have at most 321 taps. Offline work, such as cleaning a recording or analysing a stored ECG, has no budget at all.
Phase also decides which filter you may use. Some jobs need the shape: an ECG’s waves must keep their form for a doctor to read them, and a linear-phase FIR keeps it. Other jobs care only about the gain, like removing hiss from speech. There a filter whose phase bends, the IIR filters of chapter 20, can meet the same gain spec with far fewer coefficients.
The maths behind it · convex polytopes
For a linear-phase FIR the gain at each frequency is a linear function of the taps, . Each zone edge is then a linear inequality on , and the taps that meet the spec form a convex polytope, the intersection of half-spaces. Designing a filter is finding a point inside it. 19.2 and 19.3 do this with linear programming and the Remez exchange.
Worked example
Put the running spec and the filters of this page into numbers.
- The spec. gives +0.42 dB and −0.45 dB, so 0.87 dB from top to bottom. gives dB. The band edges are and , so rad/sample.
- The 4-point average against it. Its gain is 0.653 at 1 kHz, which is −3.70 dB, and 0.318 at 1.5 kHz, which is −9.95 dB. Its side lobe peaks at 0.272, near 2929 Hz. It misses the pass band by 0.297 and the stop band by 30 dB.
- The 41-tap FIR. Its pass band runs from 0.997 to 1.012, and its stop band stays at most 0.0095, which is −40.45 dB. At the 1250 Hz cutoff the gain is 0.502, which is −5.98 dB, about half way down.
- Three lengths. Centred on 1250 Hz, the narrowest transition each filter passes is 445.0 Hz for 41 taps, 223.6 Hz for 81 and 111.9 Hz for 161. Their delays are 20, 40 and 80 samples, which are 2.5, 5.0 and 10.0 ms at 8 kHz.
- Two budgets. A budget of 2.5 ms at 48 kHz is 120 samples, so and the filter has at most 241 taps. A budget of 10 ms at 16 kHz allows , so 321 taps.
Where you’ll meet this
Datasheets of converters and codecs state a filter in these same terms. A typical audio converter quotes a pass-band ripple of ±0.005 dB, a stop-band attenuation of 100 dB, and its group delay in samples. Reading such a line, you can now draw its tolerance scheme.
The running spec of this page comes back in the next chapter. Window-method FIR design (19.1), Frequency-sampling design (19.2) and Optimal FIR design (19.3) each meet it, and 19.3 compares their shortest lengths. Specs for analog and IIR filters are in Analog prototype filters (20.1). Choosing between FIR and IIR for one spec is Choosing FIR or IIR (20.6), and delay in real-time systems is Real-time processing (21.4).
The maths behind it · specification limits
A tolerance scheme is a set of specification limits, as in quality control: a part passes only if every measurement lies inside its limits. Like a spec, it judges the worst value, not the average. 19.3 turns that difference into two kinds of optimal filter.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Pass band | for | ripple dB |
| Stop band | for | dB |
| Transition | free; | |
| Band edges | running spec: , | |
| dB of a ripple | 0.1, 0.01, 0.001 → 20, 40, 60 dB | amplitude ratio (1.3) |
| Linear-phase delay | samples, seconds | the same at every frequency |
| Cost | halve → about twice the taps and the delay | 41 → 81 → 161 taps here |
| Four shapes | low-pass, high-pass, band-pass, band-stop | a notch is a narrow band-stop |