TExcelTAD
Home › Fourier Analysis & Signals › The Sampling Theorem

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 fs/2f_s/2, the samples determine it completely. This is the theorem behind every digital audio, video and measurement system.

The statement

Let x(t)x(t) be band-limited: x^(s)=0\hat{x}(s) = 0 for ∣s∣≥B\lvert s \rvert \ge B. If it is sampled at rate fs>2Bf_s > 2B (period Ts=1/fsT_s = 1/f_s), then

x(t)=∑n=−∞∞x(nTs) sinc⁡ ⁣(t−nTsTs)x(t) = \sum_{n=-\infty}^{\infty} x(nT_s)\, \operatorname{sinc}\!\left(\frac{t - nT_s}{T_s}\right)

The rate 2B2B is the Nyquist rate; fs/2f_s/2 is the Nyquist frequency. CDs sample at 44.1 kHz because human hearing ends near 20 kHz.

Why it works

Sampling multiplies xx by a train of deltas spaced TsT_s apart. The Fourier transform of a delta train is another delta train, spaced fsf_s apart (Osgood's "Shah" function). By the convolution theorem, sampling copies the spectrum to every multiple of fsf_s:

xsampled^(s)=fs∑kx^(s−kfs)\widehat{x_\text{sampled}}(s) = f_s \sum_k \hat{x}(s - k f_s)

If fs>2Bf_s > 2B, the copies do not overlap, and a low-pass filter (multiplying by Π(s/fs)\Pi(s/f_s), which is convolution with a sinc in time) cuts out the original copy exactly. That filter is the sinc formula above.

python · try it yourself
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 MM samples (rate fs/Mf_s/M) creates copies spaced at the new rate:

python · try it yourself
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 50−40=1050 - 40 = 10 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 2B=302B = 30 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 sin⁡(2πBt)\sin(2\pi B t) at exactly fs=2Bf_s = 2B not enough?

Answer

All samples can be zero.

Solution

At t=n/(2B)t = n/(2B), sin⁡(2πBt)=sin⁡(πn)=0\sin(2\pi B t) = \sin(\pi n) = 0 for every nn. The samples cannot distinguish this sine from silence; the theorem needs strict inequality fs>2Bf_s > 2B.

Exercise 3: Reconstruct a single value (code)

Using the sinc formula with fs=30f_s = 30, reconstruct x(0.517)x(0.517) for the signal above.

Answer

True value −0.7966-0.7966, reconstruction −0.7971-0.7971: close, with the small error coming from truncating the sum to 1201 samples.

Solution
python · try it yourself
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 BB Hz can be recovered from samples taken at…

  1. any rate
  2. a rate above 2B2B
  3. exactly BB
  4. a rate above BB

In the frequency domain, sampling…

  1. removes high frequencies
  2. creates copies of the spectrum at multiples of fsf_s
  3. multiplies the spectrum by fsf_s only
  4. shifts the spectrum by fs/2f_s/2

The ideal reconstruction filter corresponds to interpolating with…

  1. straight lines
  2. sinc functions
  3. Gaussians
  4. step functions