DSP·GUIDEOUT LOUD
Book episodes

Episode 03 · Foundations · Book chapter 3 · 46m55s

Sampling and Quantization

The one mistake you can never undo. Aliasing, the sampling theorem, dither, antialias filter choice, and bandpass sampling.

The original recording, including numerical examples and figure cues. Switching versions starts at the beginning.

0:0046:55

Choose a playback speed that feels comfortable. Open in Google Drive to download or play on a phone.

Save for offline listening:Detailed MP3Driving MP3
Figures

Two independent operations

Converting a continuous signal to a digital one involves two entirely separate operations, and they are almost always confused with one another. Sampling discretizes time — you keep values only at particular instants. Quantization discretizes amplitude — each value must be one of a finite set of levels.

They have separate theory, separate failure modes, and separate remedies. When someone says “the resolution isn’t good enough”, the first question is always which of the two they mean.

Quantization, and the case for adding noise

An ADC picks the nearest available level, so the error is bounded at half an LSB. Modelled as additive noise it is uniformly distributed across one step, which — from the variance of a uniform distribution being one twelfth — gives a standard deviation of 0.29 LSB. That single number is worth memorising.

The counterintuitive part is that deliberately adding noise before the converter can recover detail far below one quantization step. Drag the amplitude below half an LSB with dither off, and watch the output die completely.

Dither: recovering detail below one quantization step

Interactive
-3-2-10+1+2+3
0.30 LSB
0.41 LSB
Quantization noise 0.29 LSBAveraged over 96 samplesReconstruction error 0.052 LSB RMSWell chosen — the shape is recovered almost exactly
Cyan is the true signal, amber the plain quantizer, violet the dithered output averaged over 96 samples. Drop the amplitude below about 0.2 LSB and the amber staircase flatlines — every value rounds to the same code and the signal is destroyed.

Now sweep the dither strength on the stuck-code signal and watch the error figure rather than the picture. At zero it is 0.32 LSB — nothing unsticks the code. It falls steadily to a minimum near 0.3 LSB of dither, where the error is about 0.05 LSB: roughly six times better. Past that it climbs again — 0.10 at 0.9 LSB, 0.21 by 2.0 — as the added noise costs more than it buys.

That U-shape is the whole story: dither is not “on or off” but an amount you tune. Note the classic TPDF preset sits at 0.41 LSB, slightly above the minimum here — it is chosen to fully decorrelate the quantization error, not to minimise RMS against one particular test signal. And the payment is always made in bandwidth: you only get any of this if you average, which is the square-root-of-N trade from episode two.

The sampling theorem, and the one unrecoverable mistake

A continuous signal can be properly sampled only if it contains no frequencies above half the sampling rate. Properly sampled means exactly reconstructable — not approximately.

Above that limit, a signal does not degrade gracefully. It disguises itself as a different frequency, and the samples it produces are numerically identical to those a lower-frequency signal would have produced. Aliasing is not difficult to reverse; it is logically impossible to reverse, because the data does not contain the information that would distinguish the two.

Aliasing: what the samples can and cannot tell you

Interactive
0 s1 s
3.0 Hz
Sample rate 20 HzNyquist 10 HzSamples / cycle 6.67Apparent frequency 3.0 HzProperly sampled — exactly reconstructable
Drag the frequency past 10 Hz and the samples stop describing the signal you sent. The grey curve is what was actually transmitted; the amber curve is the only thing the samples can testify to. At 19 Hz the samples are numerically identical to a 1 Hz signal — no algorithm can tell them apart, because the distinguishing information is not present. This is the one mistake no later processing can undo.

This is why the antialias filter has to be analog and has to come before the converter. A digital filter operates on the samples, and by then the alias is sitting on top of your real signal at a legitimate low frequency, indistinguishable from it.

Choosing the antialias filter

Butterworth optimises passband flatness, Chebyshev optimises roll-off sharpness, and Bessel optimises step response. You cannot have all three, so you choose by asking where the information in your signal lives.

Audio carries its meaning in the frequency domain, so aliasing is catastrophic and waveform distortion is not — use the sharp filter. An electrocardiogram carries its meaning in the shape, so a sharp filter’s ringing would add features that were never in the patient. Use a Bessel at about a quarter of the sampling frequency and accept some aliasing.

Why the antialias filter choice depends on your signal

Figure
1.00violet = sharpest
Illustrative second-order step responses. The Bessel-like curve (cyan) reaches its final value without overshoot but takes its time. The Butterworth-like curve (amber) is faster and overshoots slightly. The Chebyshev-like curve (violet) is fastest to the target and overshoots by roughly a quarter, then rings. On an electrocardiogram that overshoot is a peak the patient never had — which is why a sharp filter is the wrong answer when the waveform shape carries the meaning.

What perfect reconstruction actually looks like

Not straight lines between the samples, and not an arbitrary smooth curve. The exact answer is to replace every sample with a sinc function centred on it, scaled by that sample’s value, and sum them all.

Exact reconstruction is sinc interpolation

Figure
Each sample (amber) is replaced by a sinc function scaled to that sample’s value (faint), and all of them are summed (cyan). The sinc’s zeros land exactly on every other sample position, so each sample contributes its full value at its own instant and precisely nothing at the others — which is why the sum passes exactly through every sample. It is also unbuildable: the sinc extends infinitely in both directions, so perfect reconstruction would need infinite delay.

The sinc will keep reappearing for the rest of the series — as the ideal low-pass filter in episode 12, as the droop from a zero-order hold, and as the shape of a rectangular window’s spectrum. It is always the same fact: a rectangle in one domain is a sinc in the other.

Key points

  1. Digitizing involves two independent operations. Sampling discretizes time; quantization discretizes amplitude. They have separate theory and separate failure modes.
  2. Quantization error is bounded at plus or minus half an LSB and is modeled as uniformly distributed additive noise with a standard deviation of one over the square root of twelve, which is about zero point two nine LSB.
  3. That noise is roughly one part in nine hundred of full scale for eight bits, one in fourteen thousand for twelve bits, and one in two hundred and twenty seven thousand for sixteen bits. Each additional bit halves the noise, worth about six decibels.
  4. Independent noise sources combine in quadrature — square the standard deviations, add, take the root. An eight bit converter on a one volt range digitizing a signal with one millivolt of noise raises the total noise by about fifty percent, which means the converter is poorly matched to the signal.
  5. Resolution far below the existing analog noise floor buys nothing. Match the converter to the noise already present.
  6. Dither means deliberately adding noise before the converter, typically about two thirds of an LSB. It unsticks slowly varying signals so their value is encoded in the proportion of ones to twos, letting averaging recover precision far finer than one LSB. Randomness can preserve information that rounding would destroy.
  7. The sampling theorem: a continuous signal can be properly sampled only if it contains no frequencies above half the sampling rate. Properly sampled means exactly reconstructable, not approximately.
  8. The Nyquist frequency is half your sampling rate — a property of the system. The Nyquist rate is twice the highest signal frequency — a property of the signal. Do not confuse them.
  9. At zero point zero nine of the sampling rate you get eleven samples per cycle and it looks fine. At zero point three one you get three point two samples per cycle and it looks far too sparse — but it is properly sampled, and the reconstruction is exact. Sampled data routinely looks worse than it is.
  10. At zero point nine five of the sampling rate, the samples are numerically identical to those from a signal at zero point zero five. Aliasing is not merely difficult to reverse; it is logically impossible, because the data does not contain the information that would distinguish the two. Aliasing can also invert phase by one hundred and eighty degrees.
  11. Aliasing must be prevented with an analog filter before the converter. A digital filter cannot help, because by then the alias is indistinguishable from real signal.
  12. Butterworth optimizes passband flatness, Chebyshev optimizes roll-off sharpness, Bessel optimizes step response. You cannot have all three.
  13. Choose by asking where the information lives. Frequency domain information, such as audio, wants a sharp filter — Chebyshev or Butterworth. Time domain information, such as an electrocardiogram, wants a Bessel filter at about one quarter of the sampling frequency, because a sharp filter's ringing would add features that were never in the signal.
  14. The sampling theorem is really about bandwidth, not about the highest frequency present. A narrow band sitting at a high frequency can be sampled far below twice its highest frequency, using aliasing deliberately as a free frequency translation. That is bandpass sampling, and it underpins software defined radio.
  15. Bandpass sampling requires a bandpass antialias filter, a sampling rate chosen to avoid forbidden values where folded copies collide, and a converter whose analog input bandwidth — a different specification from its sample rate — actually reaches the input frequency.
  16. Aperture jitter turns timing uncertainty into amplitude error, and the error is proportional to signal slope, hence to input frequency. The same converter and clock can give sixteen effective bits at one kilohertz and eleven at a hundred megahertz. Suspect the clock first when high frequency performance disappoints.
  17. Exact reconstruction means replacing each sample with a sinc function centered on it and summing. The sinc's zeros land on every other sample position, so the sum passes exactly through every sample. It is exact and also unbuildable, since the sinc extends infinitely and would require infinite delay.
  18. A DAC holds each value constant, producing a staircase. That hold is itself a filter with a sinc shaped response, costing about four decibels at the Nyquist frequency, and the droop is corrected either in the analog reconstruction filter or digitally beforehand.
  19. Oversampling samples far faster than needed so that a cheap gentle analog filter suffices, then does the sharp filtering digitally and decimates. It also improves resolution, gaining roughly one bit per factor of four in oversampling.
  20. Delta sigma conversion uses a single bit at very high speed with noise shaping, pushing quantization noise into high frequencies that are then filtered away. A one bit converter is perfectly linear by construction, since two points define a straight line. The whole trend is to trade expensive analog precision for cheap digital computation.