TExcelTAD
Home › Signals, Systems & Digital Filters for Engineers › Aliasing and Anti-Alias Filter Design

Aliasing and Anti-Alias Filter Design

The previous lesson showed where every frequency lands after sampling. This one decides what to do about the frequencies you do not want. The sampler cannot help: once a 7.3 kHz7.3\ \text{kHz} hum harmonic has folded to 0.7 kHz0.7\ \text{kHz} in an 8 kSa/s8\ \text{kSa/s} record it is part of the data. The only place to stop it is the analog path before the converter, so the anti-alias filter is an analog filter with a digital specification: its corners come from the sample rate, its attenuation from the converter's resolution. We write that specification, compare the filter families that meet it, and see why oversampling makes the analog filter almost trivial. Background: Aliasing and the DAQ view in Data Acquisition.

Intuition: how much does a filter buy?

The lab has a built-in anti-alias filter: a 4th-order Butterworth low-pass with its corner at 0.4fs0.4 f_s. With f=7 Hzf = 7\ \text{Hz} and fs=10 Hzf_s = 10\ \text{Hz} the corner is at 4 Hz4\ \text{Hz}, and the readout "Filter gain at ff" shows −19.49 dB-19.49\ \text{dB}: the alias at 3 Hz3\ \text{Hz} is still there at about a tenth of its amplitude. Move ff to 13 Hz13\ \text{Hz}: it still aliases to 3 Hz3\ \text{Hz}, but now at −40.95 dB-40.95\ \text{dB}. Set f=4 Hzf = 4\ \text{Hz} (the corner): −3.01 dB-3.01\ \text{dB}, so the filter already eats into the top of the useful band. That is the whole design problem: steep enough above fs−fpf_s - f_p, flat enough below fpf_p.

-A0+A0.0 s0.2 s0.4 s0.6 s0.8 s1.0 sx (V)input 7.0 Hzafter the filterreconstructed 3.00 Hzsamples, fs = 10.0 Hz0A0102030405060708090100f (Hz)fs/2faliasaliased: f > fs/2 = 5.00 Hz

The specification

fp fs/2 fs - fp fs 0 -As f |H| (dB) passband stopband transition anything above fs - fp that survives folds onto 0..fp

Four numbers describe the filter:

  • Passband edge fpf_p: the highest frequency you need, with at most ApA_p dB of droop or ripple (for example 0.10.1 or 1 dB1\ \text{dB}).
  • Stopband edge fst=fs−fpf_\text{st} = f_s - f_p: the lowest input frequency whose alias lands inside 0…fp0 \ldots f_p. Components between fs/2f_s/2 and fs−fpf_s - f_p alias too, but onto fp…fs/2f_p \ldots f_s/2, a band you can still remove digitally.
  • Stopband attenuation AsA_s: enough to push a worst-case interferer below the noise you can tolerate, often the converter's quantisation floor, 6.02N+1.76 dB6.02N + 1.76\ \text{dB} for NN bits, reduced by how far below full scale the interference really is.
  • Phase or group delay requirements: in control loops and in multi-channel measurements, delay and its flatness matter as much as attenuation.

The ratio fst/fpf_\text{st}/f_p sets the order. For a Butterworth filter the minimum order is

n≥log⁡10 ⁣[(10As/10−1)/(10Ap/10−1)]2log⁡10(fst/fp)n \ge \frac{\log_{10}\!\left[\left(10^{A_s/10} - 1\right)/\left(10^{A_p/10} - 1\right)\right]}{2\log_{10}(f_\text{st}/f_p)}

Chebyshev and elliptic filters trade ripple for steepness (Analog Prototypes); a Bessel filter has the flattest group delay but the gentlest roll-off. Circuit realisations (Sallen–Key, multiple feedback) are in Active Filters and Filter Approximations.

Worked example: a 1 kHz sensor channel

Given: wanted band 00 to 1 kHz1\ \text{kHz} with at most 1 dB1\ \text{dB} droop; a 10-bit converter, so aliases must be 60 dB60\ \text{dB} down; two options, fs=8 kSa/sf_s = 8\ \text{kSa/s} or 32 kSa/s32\ \text{kSa/s}.

Find: the minimum analog filter order for Butterworth, Chebyshev type I and elliptic responses at each rate.

Solve: at 8 kSa/s8\ \text{kSa/s}, fst=7 kHzf_\text{st} = 7\ \text{kHz} and fst/fp=7f_\text{st}/f_p = 7. The Butterworth formula gives n≥log⁡10(106/0.2589)/(2log⁡107)=6.587/1.690=3.9n \ge \log_{10}(10^6/0.2589)/(2\log_{10}7) = 6.587/1.690 = 3.9, so 4. At 32 kSa/s32\ \text{kSa/s}, fst=31 kHzf_\text{st} = 31\ \text{kHz}, the ratio is 31 and n≥6.587/2.983=2.2n \ge 6.587/2.983 = 2.2, so 3. SciPy's order functions agree and add the other families:

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

w = 2 * np.pi                                     # work in rad/s for analog designs
fp, Ap, As = 1e3, 1.0, 60.0
for fs in (8e3, 32e3):
    fst = fs - fp
    nb, _ = signal.buttord(w * fp, w * fst, Ap, As, analog=True)
    nc, _ = signal.cheb1ord(w * fp, w * fst, Ap, As, analog=True)
    ne, _ = signal.ellipord(w * fp, w * fst, Ap, As, analog=True)
    print(f"fs = {fs / 1e3:4.0f} kSa/s, stopband from {fst / 1e3:4.1f} kHz: Butterworth {nb}, Chebyshev I {nc}, elliptic {ne}")

# Group delay of the three 4th-order designs at low frequency and at the band edge (analog, from the phase slope)
f = np.array([10.0, 1000.0])
for name, (b, a) in {
    "Butterworth": signal.butter(4, w * fp * 1.4, analog=True),
    "Chebyshev I": signal.cheby1(4, Ap, w * fp, analog=True),
    "Bessel     ": signal.bessel(4, w * fp * 1.4, analog=True, norm="mag"),
}.items():
    ww = np.concatenate([w * f, w * f * 1.001])
    _, h = signal.freqs(b, a, ww)
    ph = np.unwrap(np.angle(h))
    gd = -(ph[2:] - ph[:2]) / (ww[2:] - ww[:2])
    mag = 20 * np.log10(abs(h[1]))
    print(f"{name}: gain at 1 kHz {mag:6.2f} dB, group delay {1e6 * gd[0]:6.1f} us at 10 Hz, {1e6 * gd[1]:6.1f} us at 1 kHz")
fs =    8 kSa/s, stopband from  7.0 kHz: Butterworth 4, Chebyshev I 4, elliptic 3
fs =   32 kSa/s, stopband from 31.0 kHz: Butterworth 3, Chebyshev I 3, elliptic 2
Butterworth: gain at 1 kHz  -0.28 dB, group delay  297.1 us at 10 Hz,  404.1 us at 1 kHz
Chebyshev I: gain at 1 kHz  -1.00 dB, group delay  429.0 us at 10 Hz, 1270.1 us at 1 kHz
Bessel     : gain at 1 kHz  -1.47 dB, group delay  240.3 us at 10 Hz,  239.9 us at 1 kHz

Check: the Butterworth orders match the hand formula (4 and 3). The delay lines show the price of steepness: the Chebyshev filter's group delay grows from 429429 to 1270 μs1270\ \mu\text{s} across the band, while the Bessel's stays at 240 μs240\ \mu\text{s}, which distorts pulse shapes even though all three pass the band.

Simulating aliasing with and without the filter

Here an "analog" signal is modelled at 512 kSa/s512\ \text{kSa/s}, filtered by a 4th-order Butterworth low-pass with its corner at 2 kHz2\ \text{kHz}, then sampled at 8 kSa/s8\ \text{kSa/s} by keeping every 64th point. The input is a 300 Hz300\ \text{Hz}, 1 V1\ \text{V} signal plus a 0.5 V0.5\ \text{V} interferer at 7.3 kHz7.3\ \text{kHz}, which folds to 0.7 kHz0.7\ \text{kHz}.

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

fa, fs, M = 512e3, 8e3, 64                       # "analog" rate, ADC rate, ratio
t = np.arange(int(1.0 * fa)) / fa                # 1 s
x = 1.0 * np.sin(2 * np.pi * 300 * t) + 0.5 * np.sin(2 * np.pi * 7300 * t)
sos = signal.butter(4, 2e3, fs=fa, output="sos")  # close to the analog filter at this high rate
xf = signal.sosfilt(sos, x)

def tone_amp(y, f):
    """Amplitude of a tone at an integer frequency f in a 1 s record (bin spacing 1 Hz)."""
    Y = np.fft.rfft(y) / len(y) * 2
    return abs(Y[int(f)])

for label, sig in (("no filter  ", x), ("4th-order LP", xf)):
    y = sig[::M][800:]                            # sample at 8 kSa/s, drop the first 0.1 s (filter start-up)
    y = y[:7200]                                  # 0.9 s = whole number of periods of 300 Hz and 700 Hz
    Y = np.fft.rfft(y) / len(y) * 2
    k300, k700 = int(300 * 0.9), int(700 * 0.9)
    print(f"{label}: 300 Hz {abs(Y[k300]):.4f} V, alias at 700 Hz {1e3 * abs(Y[k700]):.2f} mV")
print(f"predicted alias with the filter: {0.5e3 * 10 ** (-44.98 / 20):.2f} mV (filter at 7.3 kHz: -44.98 dB)")
no filter  : 300 Hz 1.0000 V, alias at 700 Hz 500.00 mV
4th-order LP: 300 Hz 1.0000 V, alias at 700 Hz 2.81 mV
predicted alias with the filter: 2.82 mV (filter at 7.3 kHz: -44.98 dB)

The filter leaves the 300 Hz300\ \text{Hz} signal untouched to four decimals and cuts the alias by a factor of about 180, from 500 mV500\ \text{mV} to 2.81 mV2.81\ \text{mV}, as its −44.98 dB-44.98\ \text{dB} at 7.3 kHz7.3\ \text{kHz} predicts. For a 10-bit converter with a ±1 V\pm 1\ \text{V} range (q≈2 mVq \approx 2\ \text{mV}) that is roughly one LSB: good enough, but only because the corner was put at 2 kHz2\ \text{kHz}, double the band edge.

Oversampling: move the problem into the digital domain

The modern answer is to sample much faster than needed with a simple analog filter (often 1st to 3rd order), then remove everything above fpf_p with a sharp digital filter and reduce the rate (decimation, Multirate). Digital filters are exact, have no component tolerance and can have linear phase. Sigma-delta converters push this to the extreme: they sample at 64 to 256 times the output rate, so a single RC in front is often enough, and the decimation filter inside the chip sets the real anti-alias response; read its stopband specification in the datasheet.

Guided lab: measuring an anti-alias filter

Hand calculation. A 2nd-order Sallen–Key Butterworth low-pass with fc=1 kHzf_c = 1\ \text{kHz} has ∣H∣=1/1+(f/fc)4\lvert H \rvert = 1/\sqrt{1 + (f/f_c)^4}: −3.0 dB-3.0\ \text{dB} at 1 kHz1\ \text{kHz}, −33.8 dB-33.8\ \text{dB} at 7 kHz7\ \text{kHz}.

Simulation. Replace the butter(4, 2e3, ...) line by butter(2, 1e3, ...) and move the interferer to 7 kHz7\ \text{kHz} (7000, alias at 1 kHz1\ \text{kHz}; change the alias bin accordingly). Expect the alias near 0.5 V×10−33.8/20≈10 mV0.5\ \text{V} \times 10^{-33.8/20} \approx 10\ \text{mV}.

What you would measure. Drive the filter (an op-amp on a 5 V5\ \text{V} supply, input biased at mid-supply) with 1 Vpp1\ \text{V}_\text{pp} from a generator; measure output amplitude at 100 Hz100\ \text{Hz}, 1 kHz1\ \text{kHz} and 7 kHz7\ \text{kHz} with a scope. With 5 %5\,\% capacitors and 1 %1\,\% resistors expect the corner within about ±5 %\pm 5\,\% and the 7 kHz7\ \text{kHz} attenuation within ±1 dB\pm 1\ \text{dB} of 33.8 dB33.8\ \text{dB}; at 7 kHz7\ \text{kHz} the output is only about 20 mVpp20\ \text{mV}_\text{pp}, so use the scope's averaging or a narrow FFT to read it above the noise.

Hazards and safe setup. Low-voltage bench supply with its current limit set (for example 50 mA50\ \text{mA}), generator output within the op-amp's input range; no mains-powered circuit under test.

Pitfalls

  • Setting fst=fs/2f_\text{st} = f_s/2 instead of fs−fpf_s - f_p (over-specifying the filter), or forgetting interference far above fsf_s that also folds.
  • Ignoring the filter's own passband droop and group delay, which become part of the measurement.
  • Trusting a sigma-delta ADC's anti-alias claim without checking where its digital filter's stopband starts (often between about 0.55fs0.55 f_s and 0.6fs0.6 f_s, for example 0.58fs0.58 f_s in several current TI audio ADCs, not at 0.5fs0.5 f_s).
  • Component tolerances: a 6th-order filter built with 10 %10\,\% capacitors does not have the response you designed.

Practice

  1. A 16-bit channel needs 98 dB98\ \text{dB} of alias rejection, fp=2 kHzf_p = 2\ \text{kHz}, fs=48 kSa/sf_s = 48\ \text{kSa/s}. What Butterworth order is needed (Ap=3 dBA_p = 3\ \text{dB})?
  2. Why does the stopband start at fs−fpf_s - f_p rather than at fs/2f_s/2?
  3. Name two reasons to prefer a Bessel anti-alias filter.
Answer
  1. fst/fp=46/2=23f_\text{st}/f_p = 46/2 = 23; with Ap=3 dBA_p = 3\ \text{dB} the bracket is about 109.810^{9.8}, so n≥9.8/(2×1.362)=3.6n \ge 9.8/(2 \times 1.362) = 3.6: order 4.
  2. Inputs between fs/2f_s/2 and fs−fpf_s - f_p alias onto fp…fs/2f_p \ldots f_s/2, outside the wanted band, where a digital filter can still remove them.
  3. Nearly constant group delay (pulses and steps keep their shape, little overshoot) and matched delay between channels; useful in control and transient measurement.

Test yourself

With fs=8f_s = 8 kSa/s and a 1 kHz passband, the anti-alias stopband must start by

  1. 1 kHz
  2. 4 kHz
  3. 7 kHz
  4. 8 kHz

Raising fsf_s from 8 to 32 kSa/s for the same 1 kHz band and 60 dB requirement lowers the minimum Butterworth order from 4 to

  1. 1
  2. 2
  3. 3
  4. 4

Which family gives the steepest transition for a given order?

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

Oversampling helps anti-aliasing because

  1. it removes aliases after sampling
  2. it widens the gap between fpf_p and fs−fpf_s - f_p, so a simple analog filter suffices
  3. it increases the number of bits
  4. it removes the need for any filter