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.
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 above the Nyquist frequency lands at , and that nothing afterwards can separate it from a real tone there. The sampling theorem (10.2) gave the rule: keep everything above 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 is
with corner frequency kHz. At the corner this gives , which is 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 . 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 . 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 , the top of the passband. A tone at lands at , so it lands inside the passband when , which is when .
So the filter must be small everywhere from
upward. I call the stop edge. It is not . Between and 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 such stages in a row and their slopes add, so the fall is dB per decade. The number is the order of the filter. Starting from a corner at , the straight-line fall to is dB. To be dB down there,
I round 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 kHz. The ratio spans only of a decade, so
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.
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 , 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 and the fall is a line whose slope is . Asking for dB at is solving a one-unknown linear equation for .
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 .
A sample taken late is wrong by about the slope times . A sine has slope , which is the derivative rule from Fourier series and LTI systems (7.4), . The steepest slope is . 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.
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 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 ” 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 per second, and a slip of s gives
The SNR limit needs the RMS values from How big is a signal (1.3). A sine of size has RMS . Its slope is a cosine of size , so the slope’s RMS is times the signal’s. A timing error with RMS then gives a height error with RMS times the signal’s RMS. The signal-to-noise ratio is the signal’s RMS over the error’s:
For 20 kHz and 1 ns this is 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 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.
| Type | How it works | Trades | Where you meet it |
|---|---|---|---|
| SAR (successive approximation) | finds one bit at a time by halving the range | medium speed | sensors, microcontrollers |
| Pipelined | stages in a row, each resolving a few bits | very fast | radio, video |
| Sigma-delta | one or a few bits at a very high rate, then digital filtering | speed for precision | audio, 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 , with in kHz. At 5, 6 and 7 kHz it is , and , which is , and dB. At the corner it is dB.
Orders for 60 dB, kHz.
| Sample rate | Stop edge | Decades | before rounding | Order |
|---|---|---|---|---|
| 44.1 kHz | 24.1 kHz | 0.0810 | 37.04 | 38 |
| 88.2 kHz | 68.2 kHz | 0.5328 | 5.63 | 6 |
| 176.4 kHz | 156.4 kHz | 0.8932 | 3.36 | 4 |
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 and gives , so 31.
A telephone line. Sample at kHz and keep up to 3.4 kHz, so the stop edge is kHz. For 40 dB, , so 16.
Jitter.
| Frequency | Timing slip | Product | SNR limit |
|---|---|---|---|
| 20 kHz | 1 ns | 78.0 dB | |
| 20 kHz | 100 ps | 98.0 dB | |
| 1 MHz | 1 ps | 104.0 dB | |
| 100 MHz | 1 ps | 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
| Quantity | Formula | Notes |
|---|---|---|
| Stop edge | where content would fold into the passband | |
| Order for dB | straight-line rule, 20 dB per decade per order | |
| One RC stage | dB at : a corner is not a wall | |
| Jitter error | about on the steepest slope | slope times the slip |
| Jitter SNR limit | independent of the bits |