Skip to content

The sampling theorem

Sampling copies a signal's spectrum to every multiple of the sample rate. See why the copies stay apart exactly when the rate exceeds twice the highest frequency.

Before this8.3 · 8.4 · 10.1 · 4 more
Chapter 10 · Lesson 2 of 5

First, the picture

Sampling multiplies a signal by a comb of spikes, and the comb is a sum of cosines. Here the comb is built one cosine at a time, at a sample rate of 10 kHz. Watch each new cosine bring a new pair of copies of the signal’s spectrum.

Copies from the comb's cosines

f_s = 10 kHz. Copy heights are drawn relative to X; each carries a factor 1/T_s.

The comb's first term is a constant, 1. Multiplying by it leaves x alone: one spectrum, centred at 0.

cosines of the comb added
0
sample rate f_s
10 kHz
0.00 / 12.00 s
Describe this picture

Two panels; the sample rate fsf_s is 10 kHz. The comb panel shows “comb so far, in units of 1/T_s” against time in ms: a solid curve, “comb so far”, and, while a cosine is being added, a dashed curve “cosine k = ±1” (or ±2, ±3), drawn in the colour of its copies. The spectrum panel shows size, relative to X’s peak, against frequency in kHz, with triangles centred at kfskf_s, each labelled “k = 0”, “k = ±1” and so on, in the colour of its kk. Copy heights are drawn relative to XX, leaving out the factor 1/Ts1/T_s each carries. The clip runs for 12 s: the cosine for k=1k=1 fades in between 2 and 3 s, k=2k=2 between 5 and 6 s and k=3k=3 between 8 and 9 s. The readout “cosines of the comb added” goes from 0 to 3, while the comb’s peaks go 1, 3, 5, 7 and the copies reach ±30\pm30 kHz. A caption appears once its picture is complete, so the caption area is empty while a cosine fades in and while the readout is 1.

A sampled signal is a signal times a comb

The page Sampling & aliasing (10.1) found where one tone lands after sampling. This page looks at a whole spectrum at once. The answer is short: sampling puts a copy of the spectrum at every multiple of the sample rate fsf_s. The sampling theorem is the condition under which those copies do not overlap.

First I need a way to write sampling as an operation on a signal. Take a continuous-time signal xc(t)x_c(t) and multiply it by the impulse train δTs(t)=∑nδ(t−nTs)\delta_{T_s}(t)=\sum_n\delta(t-nT_s) from Transforms of common signals (8.3), a spike every sample period Ts=1/fsT_s=1/f_s. A spike times a signal is the spike scaled by the signal’s value there, as in Impulse, step and ramp (3.1). So

xs(t)=xc(t) δTs(t)=∑nx[n] δ(t−nTs),x[n]=xc(nTs).x_s(t)=x_c(t)\,\delta_{T_s}(t)=\sum_n x[n]\,\delta(t-nT_s),\qquad x[n]=x_c(nT_s).

The signal xs(t)x_s(t) is the samples written as spikes. It is a model: the spikes exist on paper, not on a wire. The model is useful because xs(t)x_s(t) is a continuous-time signal, so the transforms of Chapter 8 apply to it.

The comb has a series, found in Transforms of common signals (8.3): equal arrows of size 1/Ts1/T_s at every multiple of fsf_s, for positive and negative multiples alike. Pair the arrow at +kfs+kf_s with the arrow at −kfs-kf_s. Each pair is a cosine, because ejθ+e−jθ=2cos⁡θe^{j\theta}+e^{-j\theta}=2\cos\theta, as in Complex exponentials & phasors (3.4). So

δTs(t)=1Ts[1+2cos⁡(2πfst)+2cos⁡(2π 2fst)+2cos⁡(2π 3fst)+⋯].\delta_{T_s}(t)=\frac1{T_s}\Big[1+2\cos(2\pi f_st)+2\cos(2\pi\,2f_st)+2\cos(2\pi\,3f_st)+\cdots\Big].

The signal I use throughout is called xcx_c. Its spectrum X(f)X(f) is a triangle from −4-4 kHz to 44 kHz, with height 1 at f=0f=0. Nothing in xcx_c is above 4 kHz. I call a signal with that property band-limited, and I call the highest frequency it contains fmaxf_\text{max}, here fmax=4f_\text{max}=4 kHz. I wrote XX in hertz, X(f)X(f), the form given beside X(jω)X(j\omega) in From series to transform (8.1). A real signal’s spectrum is mirrored at negative frequency, so a real xcx_c has both edges, ±4\pm4 kHz.

Each cosine of the comb makes a pair of copies

Multiply xcx_c by the comb one term at a time. The constant 1 leaves xcx_c alone, so its spectrum stays where it is. Each cosine term is a modulation, from Properties of the Fourier transform (8.2): in hertz, multiplying by cos⁡(2πf1t)\cos(2\pi f_1t) gives half a copy of XX at +f1+f_1 and half a copy at −f1-f_1,

x(t)cos⁡(2πf1t) ↔ 12[X(f−f1)+X(f+f1)].x(t)\cos(2\pi f_1t)\ \leftrightarrow\ \tfrac12\left[X(f-f_1)+X(f+f_1)\right].

The comb’s cosines carry a factor 2, which turns each half copy into a whole one. So 2cos⁡(2πkfst)2\cos(2\pi kf_st) makes full copies of XX at +kfs+kf_s and −kfs-kf_s.

That is what the picture at the top of the page showed, with fs=10f_s=10 kHz. Each new cosine in the comb panel brings one new pair of copies in the spectrum panel, in the same colour and label:

  • The comb’s first term is a constant, 1. Multiplying by it leaves xx alone: one spectrum, centred at 0, and a comb flat at 1.
  • Two cosines in, the comb’s peaks reach 5 at 0 and at ±0.1\pm0.1 ms, and the copies stand at 00, ±10\pm10 and ±20\pm20 kHz. Each cosine of the comb at kfskf_s makes a pair of copies at ±kfs\pm kf_s.
  • With three cosines the comb’s peaks are 7 and the copies reach ±30\pm30 kHz. Every cosine added sharpens the spikes and adds a pair of copies: sampling copies the spectrum to every multiple of fsf_s.

The comb with KK cosines peaks at 1+2K1+2K, in units of 1/Ts1/T_s, so the peaks are 1, 3, 5 and 7 for K=0,1,2,3K=0,1,2,3. The spikes sharpen because more cosines agree at the peaks and disagree everywhere else. With every cosine added, which is what the comb really has, the copies reach every multiple of fsf_s.

Adding all the terms, the spectrum of the samples is

Xs(f)=1Ts∑k=−∞∞X(f−kfs).X_s(f)=\frac1{T_s}\sum_{k=-\infty}^{\infty}X(f-kf_s).

Each copy carries the factor 1/Ts1/T_s. The instruments draw every copy relative to the peak of XX and leave the factor out. A wallpaper repeats one pattern at every step along the wall: sampling does the same to the spectrum, with fsf_s as the step.

The maths behind it · systematic sampling

Picking every tenth name from a list, called systematic sampling, has the same trap. If the list repeats a pattern every ten names, every pick lands on the same point of the pattern, and you see only that one point of it. A sampled signal can fail the same way, and the copies are how that failure shows up in the spectrum.

Copies approach, touch, overlap

The copies sit fsf_s apart. The copy of XX at 0 reaches up to fmaxf_\text{max}, and the copy at fsf_s reaches down to fs−fmaxf_s-f_\text{max}. So between them there is a gap of

space between copies=(fs−fmax)−fmax=fs−2fmax.\text{space between copies}=(f_s-f_\text{max})-f_\text{max}=f_s-2f_\text{max}.

A negative value means the copies overlap. For fmax=4f_\text{max}=4 kHz and fs=12f_s=12 kHz the space is 12−8=412-8=4 kHz, and at 9 kHz it is 1 kHz.

The next instrument lowers fsf_s from 12 kHz to 6 kHz. The dashed box marks what an ideal low-pass from Frequency response and Bode plots (8.4) would keep. Watch the space between the copies close.

Copies approach, touch, overlap

x has nothing above 4 kHz. Copy heights relative to X.

Sample rate 12 kHz: the copies sit with 4 kHz of clear space between them, and the dashed low-pass could lift the middle one out whole.

sample rate f_s
12.0 kHz
space between copies
4.0 kHz
0.00 / 12.00 s
Describe this picture

One panel, size relative to X’s peak against frequency in kHz, for an xx with nothing above 4 kHz. The copies for k=−3k=-3 to 33 are drawn faint, labelled “k = 0”, “k = ±1” and so on. A key above the plot names the other marks: the solid curve “spectrum of the samples”, the sum of the copies; the hatched region “overlap”, where copies overlap; and the dashed box from −fs/2-f_s/2 to fs/2f_s/2, “ideal low-pass (8.4)”. The readouts are “sample rate f_s”, in kHz with one decimal, and “space between copies”, which reads “4.0 kHz” at 12 kHz, “touching” at 8 kHz and “overlap of 2.0 kHz” at 6 kHz. The clip runs for 12 s: fsf_s falls from 12 to 8 kHz in the first six seconds, holds until 7.5 s, then falls to 6 kHz by 10.5 s and holds. Each caption shows only at the rate it describes, 12, 8 or 6 kHz. When the clip ends, the control “Sample rate f_s” turns on: drag across the spectrum, or use the arrow keys (0.1 kHz) and Page Up and Page Down (1 kHz), from 4 to 14 kHz. Below 6 kHz, copies beyond k=±3k=\pm3 also reach the view, drawn faint and added into the sum but not labelled.

At 12 kHz the copies sit with 4 kHz of clear space between them, and the dashed low-pass could lift the middle one out whole. At 8 kHz, twice the highest frequency, the copies just touch. At 6 kHz they overlap from 2 to 4 kHz. There the heights add to a flat 0.5, and no filter can pull the original back out.

When the clip ends, drag across the spectrum to set the sample rate yourself. The space reaches 0 at 8 kHz, and below that the summed curve loses the triangle’s shape.

Why does the sum read a flat 0.5? At fs=6f_s=6 kHz, between 2 and 4 kHz, the triangle is 1−f/41-f/4 and the copy centred at 6 kHz is 1−(6−f)/4=(f−2)/41-(6-f)/4=(f-2)/4. Their sum is 1−f4+f4−12=121-\tfrac f4+\tfrac f4-\tfrac12=\tfrac12. The two slopes cancel, and the original triangle is not recoverable there, because every height in the overlap is the sum of two unknowns.

The fold is an overlap

Page 10.1 said that a tone above half the sample rate folds back. The copies explain why. Take the part of xcx_c at 3.5 kHz and sample at fs=6f_s=6 kHz.

-3.502.56Xcopy at 6frequency (kHz)
Fig. The part of x at 3.5 kHz has a mirror at −3.5 kHz. Its copy, moved up by f_s = 6 kHz, sits at 2.5 kHz: 10.1’s fold, 6 − 3.5 = 2.5.

The triangle at −3.5-3.5 kHz has height 1−3.5/4=0.1251-3.5/4=0.125. The copy centred at 6 kHz carries that point to −3.5+6=2.5-3.5+6=2.5 kHz, and keeps its height 0.1250.125. At 2.5 kHz the original triangle has height 1−2.5/4=0.3751-2.5/4=0.375, so the two add to 0.375+0.125=0.50.375+0.125=0.5, the flat value of the overlap. This is 10.1’s fold, fs−f=6−3.5=2.5f_s-f=6-3.5=2.5 kHz, seen as two copies that overlap.

The theorem

If the copies do not overlap, the middle one is a clean copy of XX and nothing else. An ideal low-pass filter that keeps ∣f∣<fs/2\lvert f\rvert < f_s/2 and has gain TsT_s lifts it out and cancels the factor 1/Ts1/T_s. What is left is X(f)X(f), and so xc(t)x_c(t). That is the whole argument, and it needs the gap fs−2fmaxf_s-2f_\text{max} to be positive.

Theorem. If X(f)=0X(f)=0 for ∣f∣>fmax\lvert f\rvert>f_\text{max} and fs>2fmaxf_s>2f_\text{max}, the copies do not overlap, and the samples determine xcx_c: keep the middle copy. Reconstruction (10.3) shows how in time.

This is the Nyquist–Shannon sampling theorem.

Two names go with it, and they are easy to mix up. The number 2fmax2f_\text{max} is the Nyquist rate: it belongs to the signal. The number fN=fs/2f_N=f_s/2 is the Nyquist frequency: it belongs to the sampler. The theorem says the sample rate must exceed the signal’s Nyquist rate. That is the same as saying fmax<fNf_\text{max}<f_N.

For the example signal, the Nyquist rate is 2⋅4=82\cdot4=8 kHz. At 10 kHz the Nyquist frequency is 5 kHz, which is above 4 kHz, so there is room: the space is 10−8=210-8=2 kHz.

Exactly twice

The theorem says “greater than”, and the instrument showed the copies just touching at 8 kHz. Why not “at least”? Sample a 2 kHz wave at exactly twice its frequency, fs=4f_s=4 kHz, so that the samples fall every half period.

012time (ms)sinedots: 0cosinedots: ±145° late±0.707
Fig. Sampled at exactly twice its frequency, the same 2 kHz wave gives dots at 0, at ±1 or at ±0.707, depending on where it starts. The samples cannot tell its size, so the rule is strictly greater than 2f_max.

The first strip is a sine of size 1 and all its samples are 0, the same as the samples of a signal that is silent. The other two strips are waves of the same frequency and the same size, and they give different dots. No rule can recover the size from the dots, so the theorem asks for strictly more than twice. In the spectrum this is the same event as the copies touching: the spike of the wave at +fmax+f_\text{max} lands on the copy of its mirror spike at −fmax-f_\text{max}.

Real signals need margin

A band-limited signal lasts forever. The reason is the trade of Properties of the Fourier transform (8.2): a signal that is exactly zero above fmaxf_\text{max} cannot be zero in time outside a finite stretch. The ideal low-pass of Frequency response and Bode plots (8.4) shows the same thing, because its response never stops. A recording lasts a finite time, so it always has a little energy above any fmaxf_\text{max} you pick.

So practice leaves space and filters first. CD audio keeps content up to 20 kHz, so its Nyquist rate is 40 kHz. It samples at 44.1 kHz, which gives a Nyquist frequency of 22.05 kHz and a space of 44.1−40=4.144.1-40=4.1 kHz for a real filter to fall in. Anti-aliasing and practical converters (10.4) picks this up.

The maths behind it · a basis and coordinates

Every signal with nothing above fmaxf_\text{max} can be written as a weighted sum of the same building blocks, one per sample, with the samples themselves as the weights. Reconstruction (10.3) draws them. A set of building blocks like that is a basis, and the weights are coordinates: when the theorem holds, sampling loses nothing.

Worked example

  1. Copies. With fs=10f_s=10 kHz and fmax=4f_\text{max}=4 kHz, the copies are centred at 0,±10,±20,…0,\pm10,\pm20,\dots kHz. The space between them is 10−2⋅4=210-2\cdot4=2 kHz.
  2. Slide. The space fs−2fmaxf_s-2f_\text{max} is 4 kHz at 12 kHz, 1 kHz at 9 kHz and 0 at 8 kHz (touching). At 7 kHz the copies overlap by 1 kHz, and at 6 kHz by 2 kHz. At 6 kHz the triangle 1−f/41-f/4 and the copy (f−2)/4(f-2)/4 sum to 0.50.5 on 2≤f≤42\le f\le4.
  3. CD. For fmax=20f_\text{max}=20 kHz the Nyquist rate is 40 kHz. At fs=44.1f_s=44.1 kHz the Nyquist frequency is fN=22.05f_N=22.05 kHz and the space is 4.1 kHz.
  4. Telephone. Speech up to 3.4 kHz has a Nyquist rate of 6.8 kHz. At fs=8f_s=8 kHz the space is 8−6.8=1.28-6.8=1.2 kHz.
  5. Comb. The partial sum with KK cosines peaks at 2K+12K+1, in units of 1/Ts1/T_s: 1, 3, 5, 7 for K=0,1,2,3K=0,1,2,3.
  6. Exactly twice. A 2 kHz sine sampled at 4 kHz gives samples all 0. The cosine gives 1,−1,1,…1,-1,1,\dots. The cosine started 45° late gives ±0.7071\pm0.7071.

Where you’ll meet this

Every audio interface, phone and sensor board has a sample rate chosen with this rule. The rate has to be more than twice the highest frequency worth keeping, and a filter before the sampler enforces that limit. Page 10.4 is about those filters.

Two ideas continue from here. Reconstruction (10.3) shows what cutting out the middle copy does in time. Bandpass sampling (10.5) asks what happens to a signal whose frequencies sit in a high band, so that its copies can fit in the gaps. Later, The DTFT (12.2) writes the spectrum of the samples as a function of a digital frequency, and the copies reappear as its period.

Reference card

QuantityFormulaNotes
CombδTs(t)=∑nδ(t−nTs)=1Ts[1+2∑k≥1cos⁡(2πkfst)]\delta_{T_s}(t)=\sum_n\delta(t-nT_s)=\tfrac1{T_s}\left[1+2\sum_{k\ge1}\cos(2\pi kf_st)\right]8.3’s impulse train
Sampled signal (model)xs(t)=xc(t) δTs(t)=∑nx[n] δ(t−nTs)x_s(t)=x_c(t)\,\delta_{T_s}(t)=\sum_n x[n]\,\delta(t-nT_s)spikes exist only in the model
Its spectrumXs(f)=1Ts∑kX(f−kfs)X_s(f)=\tfrac1{T_s}\sum_k X(f-kf_s)copies every fsf_s (ωs=2πfs\omega_s=2\pi f_s)
TheoremX(f)=0X(f)=0 for ∣f∣>fmax\lvert f\rvert>f_\text{max} and fs>2fmaxf_s>2f_\text{max}strictly greater
Nyquist rate2fmax2f_\text{max}of the signal
Nyquist frequencyfN=fs/2f_N=f_s/2of the sampler
Space between copiesfs−2fmaxf_s-2f_\text{max}negative means overlap

End of lesson 10.2

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look