The Sampling Theorem
How can a list of numbers capture a continuous signal, which has infinitely many values between any two samples? The sampling theorem (Whittaker, Kotelnikov, Nyquist, Shannon) answers: if the signal contains no frequencies at or above , the samples determine it completely. This is the theorem behind every digital audio, video and measurement system.
The statement
Let be band-limited: for . If it is sampled at rate (period ), then
The rate is the Nyquist rate; is the Nyquist frequency. CDs sample at 44.1 kHz because human hearing ends near 20 kHz.
Why it works
Sampling multiplies by a train of deltas spaced apart. The Fourier transform of a delta train is another delta train, spaced apart (Osgood's "Shah" function). By the convolution theorem, sampling copies the spectrum to every multiple of :
If , the copies do not overlap, and a low-pass filter (multiplying by , which is convolution with a sinc in time) cuts out the original copy exactly. That filter is the sinc formula above.
import numpy as np
# a band-limited signal: components at 3, 7 and 11 Hz (B = 11 Hz)
x = lambda t: np.sin(2 * np.pi * 3 * t) + 0.5 * np.cos(2 * np.pi * 7 * t + 0.4) + 0.3 * np.sin(2 * np.pi * 11 * t)
fs = 30.0 # above the Nyquist rate 22 Hz
n = np.arange(-600, 601) # many samples, centered on the interval of interest
samples = x(n / fs)
t = np.linspace(0, 1, 7)
recon = np.array([np.sum(samples * np.sinc(fs * ti - n)) for ti in t])
print("t: ", np.round(t, 3).tolist())
print("true x(t):", np.round(x(t), 4).tolist())
print("from samples via sinc:", np.round(recon, 4).tolist())t: [0.0, 0.167, 0.333, 0.5, 0.667, 0.833, 1.0]
true x(t): [0.4605, -0.1982, -0.6587, -0.4605, 0.1982, 0.6587, 0.4605]
from samples via sinc: [0.4605, -0.1982, -0.6587, -0.4605, 0.1982, 0.6587, 0.4605]
The sinc sum, using only the samples, reproduces the signal between the sample points to about four decimals (the remaining error comes from truncating the infinite sum).
Seeing the spectral copies
A DFT of a finely sampled signal shows the spectrum; sampling it every samples (rate ) creates copies spaced at the new rate:
import numpy as np
fs_fine = 1000
t = np.arange(0, 1, 1 / fs_fine)
x = np.cos(2 * np.pi * 40 * t) # a single 40 Hz tone
for M in (5, 10, 20): # new rates 200, 100, 50 Hz
fs = fs_fine / M
xs = x[::M]
f = np.fft.fftfreq(xs.size, 1 / fs)
peaks = np.sort(np.abs(f[np.abs(np.fft.fft(xs)) > 0.25 * xs.size]))
print(f"fs = {fs:5.0f} Hz: the tone appears at {np.unique(peaks).tolist()} Hz")fs = 200 Hz: the tone appears at [40.0] Hz
fs = 100 Hz: the tone appears at [40.0] Hz
fs = 50 Hz: the tone appears at [10.0] Hz
At 200 Hz and 100 Hz the tone is correctly seen at 40 Hz. At 50 Hz (Nyquist frequency 25 Hz) the copy centered at Hz lands in the visible band: the tone masquerades as 10 Hz. That is aliasing.
In software
- Audio: 44.1 or 48 kHz; telephony: 8 kHz (speech band limited to about 3.4 kHz); medical ECG: 250-1000 Hz.
- Every analog-to-digital converter has an anti-aliasing filter in front of it to enforce the band limit before sampling.
Exercises
Exercise 1: Minimum rate
A signal contains frequencies up to 15 kHz. What is the minimum sampling rate?
Answer
Anything above 30 kHz.
Solution
The Nyquist rate is kHz; in practice one samples somewhat higher (for example 44.1 kHz) so that a realistic anti-aliasing filter has room to roll off.
Exercise 2: Exactly at the Nyquist rate
Why is sampling at exactly not enough?
Answer
All samples can be zero.
Solution
At , for every . The samples cannot distinguish this sine from silence; the theorem needs strict inequality .
Exercise 3: Reconstruct a single value (code)
Using the sinc formula with , reconstruct for the signal above.
Answer
True value , reconstruction : close, with the small error coming from truncating the sum to 1201 samples.
Solution
import numpy as np
x = lambda t: np.sin(2 * np.pi * 3 * t) + 0.5 * np.cos(2 * np.pi * 7 * t + 0.4) + 0.3 * np.sin(2 * np.pi * 11 * t)
fs = 30.0
n = np.arange(-600, 601)
t0 = 0.517
print(round(float(x(t0)), 4), round(float(np.sum(x(n / fs) * np.sinc(fs * t0 - n))), 4))-0.7971 -0.7966
Test yourself
A signal band-limited to Hz can be recovered from samples taken at…
- any rate
- a rate above
- exactly
- a rate above
In the frequency domain, sampling…
- removes high frequencies
- creates copies of the spectrum at multiples of
- multiplies the spectrum by only
- shifts the spectrum by
The ideal reconstruction filter corresponds to interpolating with…
- straight lines
- sinc functions
- Gaussians
- step functions