TExcelTAD
Home › Signals, Systems & Digital Filters for Engineers › Filter Specifications and the Design Workflow

Filter Specifications and the Design Workflow

"Put a low-pass filter on it" is not a specification. A vibration channel sampled at 8 kSa/s8\ \text{kSa/s} needs everything below 1 kHz1\ \text{kHz} kept within 1 dB1\ \text{dB} and a motor whine above 1.5 kHz1.5\ \text{kHz} pushed down by 60 dB60\ \text{dB}. Those four numbers decide whether the filter costs 15 multiplications per sample or 60, whether it delays the signal by about 0.5 ms0.5\ \text{ms} or nearly 4 ms4\ \text{ms}, and whether it distorts the shape of a pulse. This lesson turns a requirement into a tolerance mask, estimates the order each filter family needs, and lays out the workflow the next six lessons follow. What a filter is (FIR, IIR, moving average) is covered in Filters: Introduction; the analog versions are in First-Order Filters and Second-Order Filters.

The tolerance mask

0 1 kHz 1.5 2 3 4 kHz = fs/2 0 -20 -40 -60 -80 gain (dB) passband ripple Ap = 1 dB transition stopband attenuation As = 60 dB frequency (Hz), fs = 8 kHz; red = forbidden, green = transition band

A frequency-selective filter is specified by bands and tolerances, not by a single cutoff:

Quantity Symbol Example Meaning
sampling rate fsf_s 8 kHz8\ \text{kHz} all digital frequencies live in 0…fs/20 \ldots f_s/2
passband edge fpf_p 1 kHz1\ \text{kHz} highest frequency that must be kept
stopband edge fstf_{st} 1.5 kHz1.5\ \text{kHz} lowest frequency that must be removed
passband ripple ApA_p 1 dB1\ \text{dB} allowed peak-to-peak gain variation in the passband
stopband attenuation AsA_s 60 dB60\ \text{dB} minimum attenuation everywhere in the stopband

The band between fpf_p and fstf_{st} is the transition band: the filter may do anything there. Design methods often state the tolerances as linear deviations: the passband gain stays in 1±δp1 \pm \delta_p and the stopband gain below δs\delta_s, with

Ap=20log⁡101+δp1−δp,As=−20log⁡10δsA_p = 20\log_{10}\frac{1 + \delta_p}{1 - \delta_p}, \qquad A_s = -20\log_{10}\delta_s

so Ap=1 dBA_p = 1\ \text{dB} is δp=0.0575\delta_p = 0.0575 and As=60 dBA_s = 60\ \text{dB} is δs=0.001\delta_s = 0.001. Some tools define the ripple from 11 down to 1−δp1 - \delta_p only (gain 00 to −Ap-A_p dB); say which convention you use in the specification.

Other requirements come with the mask: phase (must the waveform shape survive? then linear phase, so FIR or a delay-equalised IIR), delay (a control loop or a hearing aid tolerates only a few milliseconds), cost (multiplications per sample, memory, word length) and step response (overshoot matters for sensor data, not for audio).

How hard is a mask? Order estimates

The difficulty grows with the attenuation and shrinks with the normalised transition width Δf/fs\Delta f/f_s. For a linear-phase FIR filter Kaiser's estimate of the length is

N≈As−7.9514.36 Δf/fs+1N \approx \frac{A_s - 7.95}{14.36\,\Delta f/f_s} + 1

so halving the transition band doubles the length, while each extra 20 dB20\ \text{dB} costs only about 40 % more taps (from 6060 to 80 dB80\ \text{dB}). For IIR filters the analog prototype orders (next section, Analog Prototypes) grow with the logarithm of the attenuation divided by the logarithm of the steepness fst/fpf_{st}/f_p (after pre-warping). SciPy has an estimator for each family:

python · try it yourself
import numpy as np
from scipy import signal

# Specification: fs = 8 kHz, passband 0-1 kHz with 1 dB ripple, stopband from 1.5 kHz with 60 dB attenuation
fs, fp, fst, Ap, As = 8000, 1000, 1500, 1.0, 60.0
dp = (10**(Ap / 20) - 1) / (10**(Ap / 20) + 1)      # passband deviation from Ap = 20 log10((1+dp)/(1-dp))
ds = 10**(-As / 20)                                 # stopband deviation
print(f"delta_p = {dp:.4f}, delta_s = {ds:.6f}, transition = {fst - fp} Hz = {(fst - fp) / fs:.4f} fs")

numtaps, beta = signal.kaiserord(As, (fst - fp) / (fs / 2))
print(f"FIR, Kaiser window : {numtaps} taps (beta = {beta:.3f})")
for name, fn in (("Butterworth", signal.buttord), ("Chebyshev I", signal.cheb1ord),
                 ("Chebyshev II", signal.cheb2ord), ("elliptic", signal.ellipord)):
    n, wn = fn(fp, fst, Ap, As, fs=fs)
    print(f"IIR, {name:12s}: order {n:2d} -> {int(np.ceil(n / 2))} biquads, about {5 * int(np.ceil(n / 2))} multiplies/sample")
delta_p = 0.0575, delta_s = 0.001000, transition = 500 Hz = 0.0625 fs
FIR, Kaiser window : 60 taps (beta = 5.653)
IIR, Butterworth : order 16 -> 8 biquads, about 40 multiplies/sample
IIR, Chebyshev I : order  8 -> 4 biquads, about 20 multiplies/sample
IIR, Chebyshev II: order  8 -> 4 biquads, about 20 multiplies/sample
IIR, elliptic    : order  6 -> 3 biquads, about 15 multiplies/sample

FIR or IIR?

FIR IIR
phase exactly linear if the taps are symmetric: delay (N−1)/2(N-1)/2 samples non-linear, worst near the band edge
stability always stable poles must stay inside the unit circle, also after rounding the coefficients
cost for a sharp mask high (tens to hundreds of taps) low (a few biquads)
fixed point robust, no feedback, no limit cycles needs care: scaling, limit cycles
design window, equiripple, frequency sampling analog prototype + bilinear transform
typical use audio crossovers with phase constraints, communications pulse shaping, decimation sensor smoothing, audio equalisers, anything replacing an analog filter cheaply

Worked example: choosing a filter for the vibration channel

Given: the mask above: fs=8 kHzf_s = 8\ \text{kHz}, fp=1 kHzf_p = 1\ \text{kHz}, Ap=1 dBA_p = 1\ \text{dB}, fst=1.5 kHzf_{st} = 1.5\ \text{kHz}, As=60 dBA_s = 60\ \text{dB}; no phase requirement, but the delay should stay below 5 ms5\ \text{ms}.

Find: the cost and delay of a Kaiser-window FIR and of the cheapest IIR.

Solve: Kaiser's formula with Δf/fs=500/8000=0.0625\Delta f/f_s = 500/8000 = 0.0625: N≈(60−7.95)/(14.36×0.0625)+1=59.0N \approx (60 - 7.95)/(14.36 \times 0.0625) + 1 = 59.0, and kaiserord returns 60 taps. A symmetric FIR needs about 30 multiplications per sample (pairs of equal taps share one multiplier) and delays every frequency by (60−1)/2=29.5(60 - 1)/2 = 29.5 samples =3.69 ms= 3.69\ \text{ms}. The elliptic filter needs order 6: three biquads, about 15 multiplications per sample, and a group delay that is small at low frequencies (0.53 ms0.53\ \text{ms} at DC) but peaks near the band edge (4.9 ms4.9\ \text{ms} just below 1 kHz1\ \text{kHz}; the Frequency Response lesson shows how to compute it). A Butterworth would need order 16: the maximally flat family pays for its smoothness with order.

Check: design both and test them against the mask on a dense frequency grid. Never trust an order estimate without this check.

python · try it yourself
import numpy as np
from scipy import signal

fs, fp, fst, Ap, As = 8000, 1000, 1500, 1.0, 60.0

def check(name, sos=None, b=None):
    f = np.linspace(0, fs / 2, 4001)
    if sos is not None:
        _, H = signal.sosfreqz(sos, worN=f, fs=fs)
    else:
        _, H = signal.freqz(b, worN=f, fs=fs)
    g = 20 * np.log10(np.maximum(np.abs(H), 1e-12))
    pb, sb = g[f <= fp], g[f >= fst]
    ripple = pb.max() - pb.min()
    atten = -sb.max()
    ok = ripple <= Ap + 1e-3 and atten >= As - 1e-3
    print(f"{name:22s} passband ripple {ripple:5.3f} dB, stopband attenuation {atten:5.1f} dB -> {'meets' if ok else 'FAILS'} the mask")

n, wn = signal.ellipord(fp, fst, Ap, As, fs=fs)
check(f"elliptic, order {n}", sos=signal.ellip(n, Ap, As, wn, output='sos', fs=fs))
check(f"elliptic, order {n - 1}", sos=signal.ellip(n - 1, Ap, As, wn, output='sos', fs=fs))
numtaps, beta = signal.kaiserord(As, (fst - fp) / (fs / 2))
check(f"FIR Kaiser, {numtaps} taps", b=signal.firwin(numtaps, (fp + fst) / 2, window=('kaiser', beta), fs=fs))
elliptic, order 6      passband ripple 1.000 dB, stopband attenuation  60.0 dB -> meets the mask
elliptic, order 5      passband ripple 1.000 dB, stopband attenuation  52.5 dB -> FAILS the mask
FIR Kaiser, 60 taps    passband ripple 0.016 dB, stopband attenuation  60.4 dB -> meets the mask

The order-5 elliptic filter misses the stopband by more than 7 dB7\ \text{dB}, so order 6 is the minimum. The FIR meets the mask with a passband ripple far smaller than allowed: the window method gives (nearly) the same deviation δ\delta in both bands, so the 60 dB60\ \text{dB} stopband forces δp≈0.001\delta_p \approx 0.001, i.e. about 0.02 dB0.02\ \text{dB}. An equiripple design can trade that wasted passband accuracy for fewer taps.

The design workflow

  1. Write the mask from the application: band edges in hertz, ripple and attenuation in dB, phase, delay and cost limits. Check fst<fs/2f_{st} < f_s/2.
  2. Choose the family with the table above and estimate the order.
  3. Design (window, equiripple, or prototype + bilinear transform), as second-order sections for IIR.
  4. Verify the frequency response against the mask on a dense grid, plus the group delay and the step or impulse response.
  5. Quantise the coefficients to the target word length and verify again (Biquads and SOS).
  6. Simulate the implementation with real signals, then measure the built system.

Guided lab: measuring a filter against its mask

Hand calculation. For the elliptic filter of the example, the gain should lie between 00 and −1 dB-1\ \text{dB} up to 1 kHz1\ \text{kHz} and below −60 dB-60\ \text{dB} from 1.5 kHz1.5\ \text{kHz} on; at 1.25 kHz1.25\ \text{kHz} (inside the transition band) anything goes.

Simulation. Run the check program; then tighten the stopband edge to 1.3 kHz1.3\ \text{kHz} and see which orders change.

What you would measure. Run the filter on a microcontroller or audio interface sampling at 8 kSa/s8\ \text{kSa/s}, feed sines from a function generator (0.5 V0.5\ \text{V} amplitude, inside the converter's input range) and read input and output amplitudes on a scope or with the FFT. Expect the passband readings within about ±0.1 dB\pm 0.1\ \text{dB} of the design (generator flatness, ADC and DAC gain). Stopband readings near −60 dB-60\ \text{dB} are only 0.5 mV0.5\ \text{mV} for a 0.5 V0.5\ \text{V} input, close to the noise floor of a 12-bit converter; measure them with an FFT and averaging, and expect them to be limited by noise, not by the filter.

Hazards and safe setup. Low-voltage signals only: generator and USB-powered board. Set the generator offset and amplitude with its output off and check them on a scope so the ADC pin never sees less than 0 V0\ \text{V} or more than its supply.

Pitfalls

  • Specifying only "cutoff 1 kHz1\ \text{kHz}": a cutoff is a −3 dB-3\ \text{dB} point, not a mask, and says nothing about attenuation.
  • Mixing up the band edges in hertz with normalised frequency (SciPy's fs= argument avoids this; without it, 1.01.0 means Nyquist, not fsf_s).
  • Trusting an order estimate without checking the designed response.
  • Forgetting the delay: 60 taps at 8 kHz8\ \text{kHz} is 3.7 ms3.7\ \text{ms}, too much inside a fast control loop.
  • Placing the stopband edge above fs/2f_s/2: the digital filter cannot see it.

Practice

  1. Convert Ap=0.5 dBA_p = 0.5\ \text{dB} and As=80 dBA_s = 80\ \text{dB} to δp\delta_p and δs\delta_s.
  2. Estimate the Kaiser FIR length for As=80 dBA_s = 80\ \text{dB} and a transition of 200 Hz200\ \text{Hz} at fs=48 kHzf_s = 48\ \text{kHz}.
  3. A linear-phase FIR has 101 taps at fs=10 kHzf_s = 10\ \text{kHz}. What is its delay?
Answer
  1. δp=(100.025−1)/(100.025+1)=0.0288\delta_p = (10^{0.025} - 1)/(10^{0.025} + 1) = 0.0288; δs=10−4\delta_s = 10^{-4}.
  2. Δf/fs=200/48 000=0.004167\Delta f/f_s = 200/48\,000 = 0.004167; N≈72.05/(14.36×0.004167)+1≈1205N \approx 72.05/(14.36 \times 0.004167) + 1 \approx 1205 taps: sharp transitions at high sampling rates are expensive, which is one reason for multirate designs.
  3. (101−1)/2=50(101 - 1)/2 = 50 samples =5 ms= 5\ \text{ms}.

Test yourself

As=60A_s = 60 dB corresponds to a stopband gain of at most

  1. 0.06
  2. 0.01
  3. 0.001
  4. 10−610^{-6}

Halving the transition width of a Kaiser-window FIR roughly

  1. leaves the length unchanged
  2. doubles the length
  3. halves the length
  4. adds 6 dB of attenuation

For the same mask, which IIR family needs the lowest order?

  1. Butterworth
  2. Chebyshev I
  3. Chebyshev II
  4. elliptic

Why does the window-method FIR in the example have only 0.02 dB passband ripple?

  1. the window is too long
  2. the window method gives about the same deviation in both bands, set by the stopband
  3. the elliptic filter helps it
  4. rounding of the coefficients