SimuVeda

Engineering · Simulator 097

Digital Sampling

Digital systems store a signal as a list of numbers taken at regular moments. Change how fast the signal oscillates and how often it is sampled. See when the samples capture it faithfully, when a fast wave masquerades as a slow one, and how the number of bits per sample limits precision.

How the model works

Sampling at rate f_s keeps only the values at times n/f_s. The Nyquist–Shannon sampling theorem says a signal containing only frequencies below f_s / 2 (the Nyquist frequency) can be rebuilt exactly from its samples by sinc interpolation:

x(t) = Σₙ x[n] · sinc(f_s t − n), sinc(u) = sin(πu) / (πu)

A frequency above f_s/2 is not lost but disguised: its samples are identical to those of a lower alias,

f_alias = | f − k f_s | for the whole number k that brings it into 0 … f_s/2

The spectrum chart shows why: sampling copies the signal's spectrum around every multiple of f_s, and only the copy inside the shaded band 0 … f_s/2 is reconstructed. Real converters therefore put an anti-aliasing filter before the sampler.

A zero-order hold (a staircase that holds each value until the next sample) is how simple converters output samples; it is not an exact reconstruction. Quantization rounds each sample to one of 2ⁿ levels; for a full-scale sine wave the signal-to-quantization-noise ratio is about 6.02 n + 1.76 dB.

Frequencies here are in hertz on a slow time scale so the waves are visible; the same rules apply to audio at kilohertz. Sinc reconstruction uses a finite stretch of samples, so it is very slightly imperfect near the edges.

Guided experiments

  1. Plenty of samples. A 3 Hz wave sampled at 20 Hz. Prediction: 3 Hz is well below the Nyquist frequency of 10 Hz, so the sinc reconstruction lies on top of the original.
  2. Aliasing. A 9 Hz wave sampled at 10 Hz. Prediction: the samples trace a slow 1 Hz wave (|9 − 10| = 1); the reconstruction is a convincing but wrong 1 Hz signal, like a wagon wheel turning backwards in a film.
  3. Exactly at Nyquist. 5 Hz sampled at 10 Hz, phase 0°, then 90°. Prediction: with phase 0° every sample falls on a zero crossing and the signal disappears; with phase 90° every sample hits a peak. At exactly f_s/2 the samples cannot tell amplitude from phase.
  4. Few bits. 3-bit quantization. Prediction: the samples snap to 8 levels and the reconstruction is visibly distorted; the theory gives about 19.8 dB SQNR, against about 98 dB for 16 bits (CD audio).

Challenge

CD audio samples at 44.1 kHz. What is the highest frequency it can represent? If a 30 kHz ultrasonic tone reached the converter without filtering, at what frequency would it be heard?

Reveal the explanation

The Nyquist frequency is 22.05 kHz. A 30 kHz tone aliases to |30 − 44.1| = 14.1 kHz, well inside the audible range, which is why an anti-aliasing filter must remove everything above about 20 kHz before sampling. Scaled down: try 30 Hz sampled at 44.1 Hz.

References

  • Shannon, C. E. (1949), "Communication in the presence of noise", Proceedings of the IRE 37(1): 10–21.
  • Oppenheim, A. V. and Schafer, R. W., Discrete-Time Signal Processing, 3rd ed. (2010), ch. 4.
  • Smith, S. W., The Scientist and Engineer's Guide to Digital Signal Processing (1997), ch. 3.