Skip to content

Sampling the spectrum

Keep N equally spaced values of a spectrum and see that they describe the signal repeated every N samples. Find the shortest N that loses nothing.

Before this12.2 · 6 more
Chapter 13 · Lesson 1 of 6

First, the picture

Keep only NN equally spaced values of the spectrum of x=4,3,2,1x=4,3,2,1, and they describe copies of xx, one every NN samples. Watch the copies close in as NN falls, until at N=3N=3 they overlap and one period no longer reads 4, 3, 2, 1.

Fewer spectrum samples, closer copies

x = 4, 3, 2, 1 for n = 0 to 3. N samples of its spectrum describe x repeated every N samples.

N = 8: the eight spectrum samples describe x repeated every 8 samples, with 4 zeros between copies.

spectrum samples N
8
gap between copies
4 samples
0.00 / 14.00 s
Describe this picture

Two stacked panels for x=4,3,2,1x=4,3,2,1 at n=0n=0 to 3. The upper strip is the spectrum: the size ∣X∣\lvert X\rvert, from 0 to 11, against Ω\Omega from 0 to 2π2\pi, with the curve and NN filled dots on it. The lower panel is time, sample nn from −8-8 to 15, with x~[n]\tilde x[n] up the side. Each copy of xx is drawn as open-circle stems, and the copies r=−1r=-1, 0 and 1 are labelled. Their sum x~[n]\tilde x[n] is drawn as filled-square stems. A hatched band labelled “overlap” marks every sample where two copies add, and a bracket labelled “one period” covers n=0n=0 to N−1N-1. A key names the copies, their sum and the overlap, so nothing relies on colour.

The readouts are the number of spectrum samples NN and the gap between copies. The gap reads a number of samples while there are zeros between copies, “touching” when there are none, and “overlap of 1 sample” or more when copies share samples. The clip runs for 14 s. While the copies slide, the dots move to their new Ωk\Omega_k and the caption is blank; with reduced motion the clip steps instead.

At the start N=8N=8 and the gap is 4 samples: copies every 8 samples, with 4 zeros between. At 4 s, N=6N=6 and the gap is 2 samples. At 6.75 s, N=4N=4, the length of xx, and the copies touch; each period is still exactly 4, 3, 2, 1. At 14 s, N=3N=3 and the copies overlap by 1 sample: the last sample, 1, lands on the first, 4, and one period reads 5, 3, 2, so xx cannot be read back. The caption calls this time-domain aliasing.

After the clip ends, a slider named “Spectrum samples N” on the time panel sets NN from 1 to 12: drag the end of the period, or use the arrow keys. Page Up and Page Down change NN by 4, and Home and End jump to 1 and 12. At other values of NN the caption reads, for example, “N = 2: copies every 2 samples, overlap of 2 samples.”

N numbers of a curve

The DTFT of The DTFT (12.2) is a curve: a value X(ejΩ)X(e^{j\Omega}) for every Ω\Omega. A computer cannot hold a whole curve. It can hold NN numbers, so I keep NN equally spaced values of the curve and throw the rest away. The question for this page is what signal those NN numbers still describe.

The spacing between the values is 2π/N2\pi/N. By Frequency in discrete time (12.1), frequencies 2π2\pi apart are the same frequency, so one period of 2π2\pi holds everything. I write the kept frequencies as

Ωk=2πkN,k=0,1,…,N−1,\Omega_k=\frac{2\pi k}{N},\qquad k=0,1,\dots,N-1,

and the kept values as X(ejΩk)X(e^{j\Omega_k}). The figure shows them for x=4,3,2,1x=4,3,2,1 at n=0,1,2,3n=0,1,2,3, with N=8N=8.

105size |X|k = 0k = 1k = 2k = 3k = 4k = 5k = 6k = 70π2πΩ (rad/sample)
Fig. x = 4, 3, 2, 1 has the size curve |X(e^{jΩ})|, from 10 at Ω = 0 down to 2 at π. Keep only N = 8 values, one every 2π/8 = 0.25π: these eight numbers are all a computer stores.

The curve starts at 10, which is the sum 4+3+2+14+3+2+1, and falls to 2 at Ω=π\Omega=\pi. The eight dots read 10, 7.25, 2.83, 2.72, 2, 2.72, 2.83 and 7.25. The dots at kk and 8−k8-k match, because the size curve of a real signal is mirrored about Ω=π\Omega=\pi.

What signal do N values describe?

I can rebuild a signal from the NN values. The DTFT (12.2) gets x[n]x[n] back with an integral of X(ejΩ)ejΩnX(e^{j\Omega})e^{j\Omega n} over one period. I replace that integral by an average over the NN kept points, and call the result x~[n]\tilde x[n]:

x~[n]=1N∑k=0N−1X(ej2πk/N) ej2πkn/N.\tilde x[n]=\frac1N\sum_{k=0}^{N-1}X(e^{j2\pi k/N})\,e^{j2\pi kn/N}.

Now put in the definition X(ejΩ)=∑mx[m]e−jΩmX(e^{j\Omega})=\sum_m x[m]e^{-j\Omega m} at Ω=2πk/N\Omega=2\pi k/N and swap the order of the sums:

x~[n]=∑mx[m][1N∑k=0N−1ej2πk(n−m)/N].\tilde x[n]=\sum_m x[m]\left[\frac1N\sum_{k=0}^{N-1}e^{j2\pi k(n-m)/N}\right].

The bracket holds the whole answer. If n−mn-m is a multiple of NN, every term is ej2πk⋅integer=1e^{j2\pi k\cdot\text{integer}}=1, so the average is 1. If it is not, the NN terms are equally spaced points on the unit circle, some of them visited more than once. Equally spaced points on a circle add to 0, as in Complex numbers for signals (3.3), so the average is 0.

For N=8N=8 and n−m=3n-m=3 the eight points add to 0. For n−m=8n-m=8 each term is 1 and the sum is 8, so the average is 1. Only the terms with m=n−rNm=n-rN, for whole numbers rr, survive:

x~[n]=∑r=−∞∞x[n−rN].\tilde x[n]=\sum_{r=-\infty}^{\infty}x[n-rN].

So NN values of the spectrum describe xx repeated every NN samples, with the copies added where they overlap. Each term x[n−rN]x[n-rN] is xx delayed by rNrN, as in Shifting, reversing and scaling time (2.1). This is The sampling theorem (10.2) with time and frequency swapped. Sampling a signal in time put copies of its spectrum every 2π2\pi in frequency. Sampling the spectrum puts copies of the signal every NN in time.

Fewer spectrum samples, closer copies

The picture at the top shows these copies for x=4,3,2,1x=4,3,2,1, at N=8N=8, 6, 4 and 3. Between copies it reads a gap of 4 samples, then 2, then none, then an overlap of 1 sample.

The gap follows from counting. The signal xx occupies 4 samples, n=0n=0 to 3, and the next copy starts at n=Nn=N. So between them there are N−4N-4 samples of zero when NN is greater than 4. At N=4N=4 the copies touch, and below 4 they share 4−N4-N samples. At N=3N=3 the sample x[3]=1x[3]=1 lands on x[0]=4x[0]=4, and 4+1=54+1=5. This overlap is time-domain aliasing: samples of different copies add and cannot be separated again. A word written on a ring of paper too short for it does the same, because the end writes over the start.

After the clip ends, drag the end of the period, or use the arrow keys, to set any NN from 1 to 12.

The periods the instrument shows, one period of x~\tilde x starting at n=0n=0, are:

N=8: 4,3,2,1,0,0,0,0,N=6: 4,3,2,1,0,0,N=5: 4,3,2,1,0,N=4: 4,3,2,1,N=3: 5,3,2,N=2: 6,4,N=1: 10.\begin{aligned} N=8&:\ 4,3,2,1,0,0,0,0, & N=6&:\ 4,3,2,1,0,0,\\ N=5&:\ 4,3,2,1,0, & N=4&:\ 4,3,2,1,\\ N=3&:\ 5,3,2, & N=2&:\ 6,4,\qquad N=1:\ 10. \end{aligned}

Each one adds to 10, which is X(ej0)X(e^{j0}), the first of the kept values. Folding the samples of xx onto NN slots, as when N=2N=2 puts 4+24+2 and 3+13+1 together, never changes their total.

The maths behind it · seasonal profiles

Folding a long record onto one period and adding, as x~\tilde x does, is how a seasonal profile is built: years of monthly data are stacked onto 12 months. If the season is not really 12 months long, the folded profile smears, which is the same overlap you see here.

Keeping x intact

The rule is a count. The copies have room while NN is at least the length of xx, here 4. Then one period of x~\tilde x is xx followed by zeros, and nothing is lost. For N=8N=8 and N=6N=6 the period is xx and zeros, and at N=4N=4 it is xx alone. Below the length, the period no longer shows xx.

A signal of length LL therefore needs N≥LN\ge L spectrum samples. A 1 s recording at 8 kHz has L=8000L=8000 samples, so at least 8000 spectrum samples keep it intact.

N arrows: the discrete Fourier series

Now suppose NN is at least the length of xx, so one period of x~\tilde x is xx itself. The signal x~\tilde x repeats every NN samples, so it is a sum of arrows, as in Fourier series coefficients (7.2). The arrows are ej2πkn/Ne^{j2\pi kn/N}. Only NN of them are different: the arrow for k+Nk+N turns 2πn2\pi n more than the arrow for kk at sample nn, which is a whole number of turns, so it gives the same samples (Frequency in discrete time, 12.1). Taking k=0,…,N−1k=0,\dots,N-1 is enough:

x~[n]=1N∑k=0N−1X~[k] ej2πkn/N,X~[k]=∑n=0N−1x~[n] e−j2πkn/N.\tilde x[n]=\frac1N\sum_{k=0}^{N-1}\tilde X[k]\,e^{j2\pi kn/N},\qquad \tilde X[k]=\sum_{n=0}^{N-1}\tilde x[n]\,e^{-j2\pi kn/N}.

This is the discrete Fourier series of the period-NN signal x~\tilde x, and the numbers X~[k]\tilde X[k] are its coefficients. It is the series of 7.2 with the integral over a period replaced by a sum over NN samples. When NN is at least the length of xx, the coefficients X~[k]\tilde X[k] are exactly the NN spectrum samples X(ejΩk)X(e^{j\Omega_k}), because the only nonzero terms of the sum are n=0n=0 to the end of xx. The DFT (13.2) gives these NN numbers their usual name.

The maths behind it · a basis of arrows

The NN arrow sequences ej2πkn/Ne^{j2\pi kn/N} are NN vectors of length NN, and every length-NN vector is a weighted sum of them. A set of vectors with that property is a basis. The DFT as a matrix (13.5) writes the weights as a matrix product.

Worked example

  1. The curve. For x=4,3,2,1x=4,3,2,1, ∣X∣\lvert X\rvert is 10 at Ω=0\Omega=0, 2.828 at 0.5π0.5\pi and 2 at π\pi. The eight samples are 10, 7.2545, 2.8284, 2.7153, 2, 2.7153, 2.8284 and 7.2545, the same as np.fft.fft(x, 8).
  2. The periods. The one period of x~\tilde x for N=8N=8 is 4, 3, 2, 1, 0, 0, 0, 0. For N=3N=3 it is 5, 3, 2, and for N=2N=2 it is 6, 4. Each period adds to 10.
  3. Points on the circle. For N=8N=8 and n−m=3n-m=3, ∑k=07ej2πk⋅3/8=0\sum_{k=0}^{7}e^{j2\pi k\cdot3/8}=0. For n−m=8n-m=8 it is 8.
  4. Practice. A 1 s recording at 8 kHz has 8000 samples, so at least 8000 spectrum samples keep it intact.

Where you’ll meet this

A computer that transforms a recording keeps NN spectrum values, and this page says what that choice means: the signal is treated as one period of a repeating signal. The DFT (13.2) names the NN values and puts them on a frequency axis in hertz. Circular vs linear convolution (13.4) uses the repeating picture to explain why the ends of a filtered block wrap around. Zero-padding and resolution (15.3) uses the rule N≥LN\ge L the other way: it adds zeros to get more spectrum samples.

Reference card

QuantityFormulaNotes
Spectrum samplesX(ejΩk)X(e^{j\Omega_k}), Ωk=2πk/N\Omega_k=2\pi k/N, k=0,…,N−1k=0,\dots,N-1spacing 2π/N2\pi/N
What they describex~[n]=∑rx[n−rN]\tilde x[n]=\sum_r x[n-rN]xx repeated every NN, copies added
No time aliasingN≥N\ge length of xxthen one period is xx
Points on the circle1N∑k=0N−1ej2πkm/N=1\frac1N\sum_{k=0}^{N-1}e^{j2\pi km/N}=1 if NN divides mm, else 03.3
Discrete Fourier seriesx~[n]=1N∑k=0N−1X~[k]ej2πkn/N\tilde x[n]=\frac1N\sum_{k=0}^{N-1}\tilde X[k]e^{j2\pi kn/N}NN arrows suffice
DFS coefficientsX~[k]=∑n=0N−1x~[n]e−j2πkn/N\tilde X[k]=\sum_{n=0}^{N-1}\tilde x[n]e^{-j2\pi kn/N}equal to the spectrum samples when there is no aliasing
The swapsample in time: copies every 2π2\pi; sample in frequency: copies every NN10.2 and 13.1

End of lesson 13.1

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look