SimuVeda/ Engineering

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.

CollegeCollege signals and systems

Experiments 0 of 0 Challenge not tried

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.

Related simulators

Worked example

A 7 Hz tone sampled at 10 Hz. The Nyquist frequency is 10 / 2 = 5 Hz, and 7 Hz is above it, so it aliases.

Alias: falias = |7 − 1 × 10| = 3 Hz. The samples are exactly those of a 3 Hz wave, and the reconstruction shows 3 Hz.

Another case: 23 Hz sampled at 20 Hz gives |23 − 20| = 3 Hz as well. Very different signals can produce identical samples.

Fix: sample at more than 2 × 7 = 14 Hz, or filter out everything above 5 Hz before sampling. CD audio uses 44.1 kHz so that everything up to 22.05 kHz, above human hearing, is kept.

Bit depth: each extra bit halves the rounding step. 8 bits give 256 levels (about 50 dB signal-to-noise), 16 bits give 65 536 levels (about 98 dB).

Common questions

What is the Nyquist sampling theorem?

A signal can be rebuilt exactly from its samples if it contains no frequency at or above half the sampling rate. That half is the Nyquist frequency.

What is aliasing?

When a frequency above the Nyquist limit is sampled, its samples match a lower frequency, so it appears as the wrong, lower tone. It is the same effect as wheels that seem to spin backwards in films.

How do you calculate the alias frequency?

Subtract the nearest whole multiple of the sampling rate: falias = |f − k fs|, choosing k so the result lies between 0 and fs/2.

Keyboard shortcuts

Space
Play or pause
S
Step
R
Reset
F
Full screen
?
Show this list