ADCx[0]–x[1]–x[2]–x[3]–x[4]–DAC1import numpy as np2f, fs = 1000, 20003n = np.arange(5)4x = np.sin(2*np.pi*f*n/fs)x = 0.00 Vfs = 8000 /sx
01234-1-0.500.51t (ms)volts (V)x(t) AND SAMPLESfs 8000 · 8/cyclefs 2500 · 2.5/cyclefs 2000 · 2/cyclefs 1500 · 1.5/cycle024681000.51frequency (kHz)size (V)SPECTRUMfs/2fs/2fs/2fs/2fs 8000 · keeps 0–4 kHzfs 2500 · keeps 0–1.25 kHzfs 2000 · all samples 0fs 1500 · keeps 0–0.75 kHz
Coloured parts: what the current step is about; everything else rests in whiteBlocks: tone generator, sample clock, converter (ADC), memory, rebuilder (DAC) and a Python code cardPlots: the tone, its samples and the rebuilt wave (dashed); the spectrum of the samples with the kept band 0 .. fs/2The clock lamp flashes at every sample and the sample token flies in slow motionA 1000 Hz tone sampled at 8000, 2500, 2000 and 1500 samples a second. At exactly fs = 2f the result depends on where the samples fall: a sine sampled at its zero crossings gives all zeros, a cosine gives +1, −1, +1 ... That ambiguity is why the theorem needs fs strictly greater than 2f. Telephone (ITU-T G.711) samples 8000 times a second for a voice band of about 300 to 3400 Hz; CD audio samples 44,100 times a second for hearing up to about 20 kHz, leaving a 2.05 kHz band for the anti-alias filter.

A tone and a clock

  1. A tone generator makes a 1000 Hz tone: x(t) = sin(2π·1000·t) volts. It repeats 1000 times a second, so one cycle lasts 1 ms. The question: how often must we measure it to keep it?

How slow can we go?

The rule

In code

The working

# step 1/10 · tone

x(t) = sin(2π·f·t) V
  f = 1000 Hz (cycles per second)
  T = 1/f = 1 ms per cycle
  peak = 1 V

plot: 4 ms = 4 cycles

sampling = measuring x(t) at evenly spaced
instants (lesson "Sampling: taking snapshots")
motion in the figure: slowed down a lot

The 1000 Hz, 1 V tone and the four clock rates are chosen examples. Every value, dot and curve in the figure is computed from the model: the rebuilt wave by Whittaker–Shannon (sinc) interpolation of 8001 samples, the spectrum as the DTFT of 40 ms of Hann-windowed samples. The motion is slowed down a great deal: the real clock ticks thousands of times a second.