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 hum harmonic has folded to in an 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 . With and the corner is at , and the readout "Filter gain at " shows : the alias at is still there at about a tenth of its amplitude. Move to : it still aliases to , but now at . Set (the corner): , so the filter already eats into the top of the useful band. That is the whole design problem: steep enough above , flat enough below .
The specification
Four numbers describe the filter:
- Passband edge : the highest frequency you need, with at most dB of droop or ripple (for example or ).
- Stopband edge : the lowest input frequency whose alias lands inside . Components between and alias too, but onto , a band you can still remove digitally.
- Stopband attenuation : enough to push a worst-case interferer below the noise you can tolerate, often the converter's quantisation floor, for 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 sets the order. For a Butterworth filter the minimum order is
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 to with at most droop; a 10-bit converter, so aliases must be down; two options, or .
Find: the minimum analog filter order for Butterworth, Chebyshev type I and elliptic responses at each rate.
Solve: at , and . The Butterworth formula gives , so 4. At , , the ratio is 31 and , so 3. SciPy's order functions agree and add the other families:
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 to across the band, while the Bessel's stays at , 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 , filtered by a 4th-order Butterworth low-pass with its corner at , then sampled at by keeping every 64th point. The input is a , signal plus a interferer at , which folds to .
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 signal untouched to four decimals and cuts the alias by a factor of about 180, from to , as its at predicts. For a 10-bit converter with a range () that is roughly one LSB: good enough, but only because the corner was put at , 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 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 has : at , at .
Simulation. Replace the butter(4, 2e3, ...) line by butter(2, 1e3, ...) and move the interferer to (7000, alias at ; change the alias bin accordingly). Expect the alias near .
What you would measure. Drive the filter (an op-amp on a supply, input biased at mid-supply) with from a generator; measure output amplitude at , and with a scope. With capacitors and resistors expect the corner within about and the attenuation within of ; at the output is only about , 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 ), generator output within the op-amp's input range; no mains-powered circuit under test.
Pitfalls
- Setting instead of (over-specifying the filter), or forgetting interference far above 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 and , for example in several current TI audio ADCs, not at ).
- Component tolerances: a 6th-order filter built with capacitors does not have the response you designed.
Practice
- A 16-bit channel needs of alias rejection, , . What Butterworth order is needed ()?
- Why does the stopband start at rather than at ?
- Name two reasons to prefer a Bessel anti-alias filter.
Answer
- ; with the bracket is about , so : order 4.
- Inputs between and alias onto , outside the wanted band, where a digital filter can still remove them.
- 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 kSa/s and a 1 kHz passband, the anti-alias stopband must start by
- 1 kHz
- 4 kHz
- 7 kHz
- 8 kHz
Raising 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
- 2
- 3
- 4
Which family gives the steepest transition for a given order?
- Bessel
- Butterworth
- Chebyshev I
- elliptic
Oversampling helps anti-aliasing because
- it removes aliases after sampling
- it widens the gap between and , so a simple analog filter suffices
- it increases the number of bits
- it removes the need for any filter