Skip to content

Filter specifications

Draw the zones a filter's gain must avoid, quote them in dB, and see what a narrow transition costs in taps and delay.

Before this17.3 · 17.4 · 4 more
Chapter 18 · Lesson 1 of 2

First, the picture

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.

pass band, worst
not yet
stop band, worst
not yet
0.00 / 15.00 s
Describe this picture

One panel for fs=8f_s=8 kHz: the gain ∣H∣\lvert H\rvert 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 fs=8f_s=8 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 fpass=1000f_\text{pass}=1000 Hz, as in Anti-aliasing and practical converters (10.4). The range we remove is the stop band, from fstop=1500f_\text{stop}=1500 Hz up.

The free range between them is the transition band. I write the allowed error in the pass band as δpass=0.05\delta_\text{pass}=0.05, so the gain stays within 1±δpass1\pm\delta_\text{pass}, and the stop-band limit as δstop=0.01\delta_\text{stop}=0.01.

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 Ω=0.25π\Omega=0.25\pi 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 β=3.40\beta=3.40 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 20log⁡1020\log_{10} of it. For the stop band I define the stop-band attenuation

Astop=−20log⁡10δstop dB.A_\text{stop}=-20\log_{10}\delta_\text{stop}\ \text{dB}.

The minus sign makes it a positive number, because δstop\delta_\text{stop} is less than 1. So δstop=0.1\delta_\text{stop}=0.1 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 20log⁡101.05=+0.4220\log_{10}1.05=+0.42 dB, and the bottom is 20log⁡100.95=−0.4520\log_{10}0.95=-0.45 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

20log⁡101+δpass1−δpass=20log⁡101.050.95=0.87 dB.20\log_{10}\frac{1+\delta_\text{pass}}{1-\delta_\text{pass}}=20\log_{10}\frac{1.05}{0.95}=0.87\ \text{dB}.

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 Ω=2πf/fs\Omega=2\pi f/f_s from Frequency in discrete time (12.1), the band edges are

Ωpass=2π⋅10008000=0.25π,Ωstop=2π⋅15008000=0.375π.\begin{aligned} \Omega_\text{pass}&=2\pi\cdot\frac{1000}{8000}=0.25\pi,\\ \Omega_\text{stop}&=2\pi\cdot\frac{1500}{8000}=0.375\pi. \end{aligned}

The transition width is the distance between them, ΔΩ=Ωstop−Ωpass=0.125π=0.393\Delta\Omega=\Omega_\text{stop}-\Omega_\text{pass}=0.125\pi=0.393 rad/sample. In hertz it is Δf=fstop−fpass=500\Delta f=f_\text{stop}-f_\text{pass}=500 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.

low-pass0100020003000400000.51frequency (Hz)gainhigh-pass0100020003000400000.51frequency (Hz)gainband-pass0100020003000400000.51frequency (Hz)gainband-stop0100020003000400000.51frequency (Hz)gain
Fig. Four tolerance schemes at f_s = 8 kHz. A low-pass keeps the low band and a high-pass the high one; a band-pass keeps a band in the middle and a band-stop removes one. 17.4’s notch is a very narrow band-stop.

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.

transition width
500 Hz
shortest that passes
41 taps, 2.5 ms
0.00 / 14.00 s
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

α=Nh−12 samples,\alpha=\frac{N_h-1}{2}\ \text{samples},

so a waveform keeps its shape and only arrives late. Divide by fsf_s 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 α≤160\alpha\le160 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, Hzp(Ω)=c(Ω)⊤hH_\text{zp}(\Omega)=\mathbf{c}(\Omega)^\top\mathbf{h}. Each zone edge is then a linear inequality on h\mathbf{h}, 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.

  1. The spec. δpass=0.05\delta_\text{pass}=0.05 gives +0.42 dB and −0.45 dB, so 0.87 dB from top to bottom. δstop=0.01\delta_\text{stop}=0.01 gives Astop=40A_\text{stop}=40 dB. The band edges are Ωpass=0.25π\Omega_\text{pass}=0.25\pi and Ωstop=0.375π\Omega_\text{stop}=0.375\pi, so ΔΩ=0.125π=0.3927\Delta\Omega=0.125\pi=0.3927 rad/sample.
  2. 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.
  3. 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.
  4. 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.
  5. Two budgets. A budget of 2.5 ms at 48 kHz is 120 samples, so α≤120\alpha\le120 and the filter has at most 241 taps. A budget of 10 ms at 16 kHz allows α=160\alpha=160, 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

QuantityFormulaNotes
Pass band1−δpass≤∣H∣≤1+δpass1-\delta_\text{pass}\le\lvert H\rvert\le1+\delta_\text{pass} for Ω≤Ωpass\Omega\le\Omega_\text{pass}ripple 20log⁡101+δpass1−δpass20\log_{10}\frac{1+\delta_\text{pass}}{1-\delta_\text{pass}} dB
Stop band∣H∣≤δstop\lvert H\rvert\le\delta_\text{stop} for Ω≥Ωstop\Omega\ge\Omega_\text{stop}Astop=−20log⁡10δstopA_\text{stop}=-20\log_{10}\delta_\text{stop} dB
TransitionΔΩ=Ωstop−Ωpass\Delta\Omega=\Omega_\text{stop}-\Omega_\text{pass}free; Δf=ΔΩfs/2π\Delta f=\Delta\Omega f_s/2\pi
Band edgesΩ=2πf/fs\Omega=2\pi f/f_srunning spec: 0.25π0.25\pi, 0.375π0.375\pi
dB of a ripple0.1, 0.01, 0.001 → 20, 40, 60 dBamplitude ratio (1.3)
Linear-phase delayα=(Nh−1)/2\alpha=(N_h-1)/2 samples, α/fs\alpha/f_s secondsthe same at every frequency
Costhalve ΔΩ\Delta\Omega → about twice the taps and the delay41 → 81 → 161 taps here
Four shapeslow-pass, high-pass, band-pass, band-stopa notch is a narrow band-stop

End of lesson 18.1

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look