Skip to content

Anti-aliasing and practical converters

See why a filter corner at the Nyquist frequency fails, count the filter order a 60 dB spec needs, and estimate the jitter limit on SNR.

Before this7.4 · 10.2 · 3 more
Chapter 10 · Lesson 4 of 5

First, the picture

Here is a plan I might make. I will sample at 8 kHz, so the Nyquist frequency is 4 kHz, and I put a filter in front of the sampler with its corner at 4 kHz. Is a 7 kHz tone safe? Make your guess, then watch the tone’s bar pass the filter and land after sampling.

A corner is not a wall

One RC stage with its corner at 4 kHz, then sampling at 8 kHz.

One RC stage with its corner at f_N = 4 kHz, and a 7 kHz tone of size 1 arriving.

tone in
7 kHz
after the filter
1.000
lands at
not sampled yet
0.00 / 9.00 s
Describe this picture

Size against frequency from 0 to 8 kHz, for one RC stage with its corner at 4 kHz, then sampling at 8 kHz. The picture plays by itself and has no control. A vertical line labelled “corner = f_N” marks 4 kHz, and a bar labelled “tone” arrives at 7 kHz with size 1. The bar shrinks to meet the curve labelled “one RC stage”, at a gain of 0.496 (−6.1 dB), then moves along the mirror about 4 kHz and lands at 1 kHz. The readouts are “tone in”, 7 kHz, “after the filter”, which goes from 1.000 to 0.496, and “lands at”, which goes from “not sampled yet” to “1 kHz”. The captions follow the three steps and end: “After sampling at 8 kHz it lands on 1 kHz at half its size, inside the band you meant to keep.”

A corner is not a wall

Sampling and aliasing (10.1) showed that a tone at frequency ff above the Nyquist frequency fN=fs/2f_N=f_s/2 lands at fs−ff_s-f, and that nothing afterwards can separate it from a real tone there. The sampling theorem (10.2) gave the rule: keep everything above fNf_N out. This lesson is about the part that does the keeping out. It is a low-pass filter placed in front of the sampler, called an anti-aliasing filter.

The filter in the picture at the top is one RC stage, the circuit from Frequency response and Bode plots (8.4), whose gain at frequency ff is

∣H∣=11+(f/fc)2,\lvert H\rvert=\frac{1}{\sqrt{1+(f/f_c)^2}},

with corner frequency fc=4f_c=4 kHz. At the corner this gives 1/21/\sqrt2, which is −3.01-3.01 dB, the figure from 8.4.

The filter did take 3 dB off at its corner, but the tone is 3 kHz past the corner and the gain there is still 0.4960.496. One RC stage falls slowly. A corner marks where the filter has started to act, and it has not stopped anything yet. A cheap sound card built this way records a 7 kHz whistle as a 1 kHz tone.

Where the filter must be strong

The mistake above was looking at fNf_N. The right question is which frequencies fold into the part of the spectrum I want to keep. Suppose I want to keep everything up to fpassf_\text{pass}, the top of the passband. A tone at ff lands at fs−ff_s-f, so it lands inside the passband when fs−f≤fpassf_s-f\le f_\text{pass}, which is when f≥fs−fpassf\ge f_s-f_\text{pass}.

So the filter must be small everywhere from

fstop=fs−fpassf_\text{stop}=f_s-f_\text{pass}

upward. I call fstopf_\text{stop} the stop edge. It is not fNf_N. Between fpassf_\text{pass} and fstopf_\text{stop} the filter is allowed to fall, and that range of frequencies is the transition band. Everything about practical anti-aliasing is a trade for the width of that band.

How steep must the fall be? One RC stage falls 20 dB for every factor of 10 in frequency above its corner (8.4, section 3). Put NN such stages in a row and their slopes add, so the fall is 20N20N dB per decade. The number NN is the order of the filter. Starting from a corner at fpassf_\text{pass}, the straight-line fall to fstopf_\text{stop} is 20Nlog⁡10(fstop/fpass)20N\log_{10}(f_\text{stop}/f_\text{pass}) dB. To be AA dB down there,

N≥A20log⁡10(fstop/fpass).N\ge\frac{A}{20\log_{10}(f_\text{stop}/f_\text{pass})}.

I round NN up to a whole number, because stages come whole. Designs in Chapter 20 keep the passband flat, for example the Butterworth filter in Analog prototype filters (20.1), and they need the same order for this spec.

Now keep 0 to 20 kHz, with a 60 dB fall. At the CD rate of 44.1 kHz, the stop edge is 44.1−20=24.144.1-20=24.1 kHz. The ratio 24.1/2024.1/20 spans only log⁡10(1.205)=0.0810\log_{10}(1.205)=0.0810 of a decade, so

N≥6020×0.0810=37.04,N\ge\frac{60}{20\times0.0810}=37.04,

and the order is 38.

Before you play the next instrument, guess: how much does the order fall if I double the sample rate? Watch the stop edge move away from 20 kHz, and the order needed fall with it.

Sample faster, filter less

Keep 0 to 20 kHz; be 60 dB down wherever content would fold into it.

At 44.1 kHz the filter has from 20 to 24.1 kHz, a twelfth of a decade, to fall 60 dB. That takes order 38.

sample rate f_s
44.1 kHz
stop edge
24.1 kHz
order needed
38
0.00 / 12.00 s
Describe this picture

Gain in dB, from 0 to −80, against frequency in Hz on a logarithmic scale with decades marked 10 k, 100 k and 1 M; the brief is to keep 0 to 20 kHz and be 60 dB down wherever content would fold into it. A strip labelled “passband” runs up to 20 kHz, and a tick labelled “f_s” marks the sample rate. A marker at −60 dB, labelled “stop edge f_s − 20 kHz”, sits where the filter must have finished falling, and a straight line labelled “N × 20 dB per decade” joins the passband edge to it. The tick slides from 44.1 kHz to 88.2 kHz and then 176.4 kHz, and the stop edge moves with it, from 24.1 kHz to 68.2 kHz and 156.4 kHz. The readouts are “sample rate f_s”, “stop edge” and “order needed”, and the order goes 38, 6, 4. At the end a diamond marks the stop edge, with a dashed line dropping from it to the axis. Once the clip has finished, dragging along the frequency axis, or the arrow keys once the frame has focus, set the sample rate from 44.1 to 400 kHz, one hundredth of a decade per press; Home goes to 44.1 kHz and End to 400 kHz, and the caption names your rate.

The caption at the end says: “At four times, 176.4 kHz: order 4. Sample faster and a cheap analog filter will do; the digital side finishes the job.” When the clip has finished, drag along the frequency axis to try your own rate. At 400 kHz the stop edge is 380.0 kHz and the order is 3.

Here is why. On a log axis, a stop edge at 24.1 kHz is a sliver away from 20 kHz. At 88.2 kHz it is at 68.2 kHz, over half a decade away, and the same 60 dB can be spread over a much longer slope. The orders for the three rates are 38, 6 and 4. Order 38 is a very large analog circuit to build and keep stable. Order 4 is a small one.

The caption said “the digital side finishes the job”. After sampling fast, a digital low-pass filter removes what lies between 20 kHz and the new fNf_N, and then the sample rate is lowered. That is the subject of Downsampling and decimation (22.1). Oversampling and noise shaping (11.3) shows a second gain from sampling fast. This is why audio converters sample at many times 48 kHz inside the chip and only hand you 48 kHz at the end.

The maths behind it · linear equations in logarithms

The straight-line rule is a linear equation in the logarithms. Plot gain in dB against log⁡10f\log_{10}f and the fall is a line whose slope is −20N-20N. Asking for AA dB at fstopf_\text{stop} is solving a one-unknown linear equation for NN.

A late sample on a steep slope

The filter is half of the story. The other half is the measurement itself. A converter cannot read a voltage that is moving, so a sample-and-hold circuit freezes the input at each tick, and the converter measures the frozen value. The tick has to arrive at the right instant, and a real clock is slightly wrong each time. That timing error is clock jitter, and I write its size as tjt_j.

A sample taken tjt_j late is wrong by about the slope times tjt_j. A sine xc(t)=Asin⁡(2πft)x_c(t)=A\sin(2\pi ft) has slope 2πfAcos⁡(2πft)2\pi fA\cos(2\pi ft), which is the derivative rule from Fourier series and LTI systems (7.4), ddtejωt=jωejωt\tfrac{d}{dt}e^{j\omega t}=j\omega e^{j\omega t}. The steepest slope is 2πfA2\pi fA. A fast signal is steep, so it suffers most.

Before you play the clip: a 20 kHz sine of size 1 is sampled 1 ns late, at its steepest point. Guess how big the height error is. As the view zooms in, watch the sine turn into a straight line through the sample instant.

A late sample on a steep slope

A 20 kHz sine, size 1, sampled 1 ns late.

A 20 kHz sine, and one sample instant on its steepest part.

timing slip t_j
1 ns
height error
not visible yet
SNR limit at 20 kHz
78.0 dB
0.00 / 10.00 s
Describe this picture

A 20 kHz sine of size 1, sampled 1 ns late; the picture has no control. At first the axes are time from 0 to 100 µs and xc(t)x_c(t) from −1.2 to 1.2, and a ring labelled “intended sample” sits on the sine’s rising zero crossing at 50 µs. The view zooms in on the ring: the time axis becomes µs from the sample instant, then ns from the sample instant. At that scale the curve is a straight line, and a dot labelled “actual sample” sits 1 ns after the ring. When the zoom ends, a bar labelled “height error” joins the ring’s height to the dot’s. The readouts are “timing slip tjt_j” 1 ns, “height error” 0.000126 and “SNR limit at 20 kHz” 78.0 dB, and the last caption says the 78.0 dB cap holds whatever the number of bits.

The bar is 0.000126 tall, and here is why. The slope is 2π×20 000=1.2566×1052\pi\times20\,000=1.2566\times10^{5} per second, and a slip of 10−910^{-9} s gives

2πftj=1.257×10−4.2\pi ft_j=1.257\times10^{-4}.

The SNR limit needs the RMS values from How big is a signal (1.3). A sine of size AA has RMS A/2A/\sqrt2. Its slope is a cosine of size 2πfA2\pi fA, so the slope’s RMS is 2πf2\pi f times the signal’s. A timing error with RMS tjt_j then gives a height error with RMS 2πf tj2\pi f\,t_j times the signal’s RMS. The signal-to-noise ratio is the signal’s RMS over the error’s:

SNR=12πftj,SNRdB=−20log⁡10(2πftj).\mathrm{SNR}=\frac{1}{2\pi ft_j},\qquad \mathrm{SNR}_\text{dB}=-20\log_{10}(2\pi ft_j).

For 20 kHz and 1 ns this is −20log⁡10(1.257×10−4)=78.0-20\log_{10}(1.257\times10^{-4})=78.0 dB. Adding bits does not move it, because the error comes from the clock and not from the rounding.

The maths behind it · propagation of error

Clock jitter is a small random timing error. Through the slope it becomes a random height error, whose RMS is the slope’s RMS times the timing RMS. Statistics calls this propagation of error.

Radio receivers sample hundreds of MHz, so they need clocks good to picoseconds. At 100 MHz with tj=1t_j=1 ps, the limit is only 64.0 dB.

Three ways to convert

An anti-aliasing filter and a good clock serve a converter. The converter itself comes in a few designs, and each one trades something. Here are three.

TypeHow it worksTradesWhere you meet it
SAR (successive approximation)finds one bit at a time by halving the rangemedium speedsensors, microcontrollers
Pipelinedstages in a row, each resolving a few bitsvery fastradio, video
Sigma-deltaone or a few bits at a very high rate, then digital filteringspeed for precisionaudio, precision measurement

The sigma-delta row is the oversampling idea of this lesson taken as far as it will go. Oversampling and noise shaping (11.3) explains it.

Worked example

The trap, in numbers. One RC stage with corner 4 kHz has gain 1/1+(f/4)21/\sqrt{1+(f/4)^2}, with ff in kHz. At 5, 6 and 7 kHz it is 0.6250.625, 0.5550.555 and 0.4960.496, which is −4.09-4.09, −5.12-5.12 and −6.09-6.09 dB. At the corner it is −3.01-3.01 dB.

Orders for 60 dB, fpass=20f_\text{pass}=20 kHz.

Sample rate fsf_sStop edge fstopf_\text{stop}Decades log⁡10(fstop/fpass)\log_{10}(f_\text{stop}/f_\text{pass})NN before roundingOrder
44.1 kHz24.1 kHz0.081037.0438
88.2 kHz68.2 kHz0.53285.636
176.4 kHz156.4 kHz0.89323.364

The same rule at 48, 96 and 192 kHz gives 21, 6 and 4. The question from Sampling and aliasing (10.1), protecting the band against a tone at 25 kHz, has ratio 25/2025/20 and gives 60/(20×0.0969)=30.9660/(20\times0.0969)=30.96, so 31.

A telephone line. Sample at fs=8f_s=8 kHz and keep up to 3.4 kHz, so the stop edge is 8−3.4=4.68-3.4=4.6 kHz. For 40 dB, N≥40/(20log⁡10(4.6/3.4))=15.23N\ge40/(20\log_{10}(4.6/3.4))=15.23, so 16.

Jitter.

Frequency ffTiming slip tjt_jProduct 2πftj2\pi ft_jSNR limit
20 kHz1 ns1.257×10−41.257\times10^{-4}78.0 dB
20 kHz100 ps1.257×10−51.257\times10^{-5}98.0 dB
1 MHz1 ps6.28×10−66.28\times10^{-6}104.0 dB
100 MHz1 ps6.28×10−46.28\times10^{-4}64.0 dB

Where you’ll meet this

Every audio interface has an anti-aliasing filter before its converter, and most of them sample far above 48 kHz inside. Phone lines sample at 8 kHz, so they need the steep filter in the worked example. Software-defined radios and oscilloscopes spend much of their cost on a low-jitter clock. Chapter 22 returns to the digital filter that follows a fast sampler.

Reference card

QuantityFormulaNotes
Stop edgefstop=fs−fpassf_\text{stop}=f_s-f_\text{pass}where content would fold into the passband
Order for AA dBN≥A20log⁡10(fstop/fpass)N\ge\dfrac{A}{20\log_{10}(f_\text{stop}/f_\text{pass})}straight-line rule, 20 dB per decade per order
One RC stage∣H∣=1/1+(f/fc)2\lvert H\rvert=1/\sqrt{1+(f/f_c)^2}−3.01-3.01 dB at fcf_c: a corner is not a wall
Jitter errorabout 2πfA tj2\pi fA\,t_j on the steepest slopeslope times the slip
Jitter SNR limit−20log⁡10(2πftj)-20\log_{10}(2\pi ft_j)independent of the bits

End of lesson 10.4

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look