A1015 of 28
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A10 · Lesson 15 · Sampling and the DFT, previewed

From a continuous signal to a list of numbers, and back to a spectrum

A computer can't store a continuous signal. It stores samples: the voltage measured thousands or millions of times a second. Between samples it knows nothing. Surprisingly, that's enough to rebuild the signal exactly, if you sample fast enough. Sample too slowly and a high frequency puts on a disguise: it shows up as a lower frequency that was never there. Once the signal is a list of numbers, the discrete Fourier transform finds its spectrum, and that's what runs inside every digital scope and spectrum analyzer.

Play

  • A sine at frequency f is sampled at 1 kHz. The staircase holds each sample until the next one, the way a simple converter does. The dashed curve is the lowest-frequency sine that passes through the same samples.
  • Start well below 500 Hz and raise f. What happens once f passes 500 Hz? At 1 kHz?
  • Find two different values of f that give exactly the same samples.

Predict

A 900 Hz tone is sampled at 1 kHz, with no filter first. What frequency does the sampled data seem to contain?

Name it

Sampling

Samples. Measuring x(t) every Ts seconds gives the list x[n]=x(nTs), at a sample rate fs=1/Ts.

The sampling theorem. A signal whose frequencies all lie below fs/2 can be rebuilt exactly from its samples. That limit, fs/2, is the Nyquist frequency; equivalently, you must sample at more than twice the highest frequency present. CD audio samples at 44.1 kHz to cover hearing up to 20 kHz.

Aliasing. A frequency above fs/2 isn't lost, it's disguised. Its samples match those of a lower frequency, the alias:

falias=|f−kfs|

for the whole number k that brings it into the range 0 to fs/2. Every frequency band folds back into that range. So every analog-to-digital converter is preceded by an anti-aliasing filter, a low-pass that removes what's above fs/2 before it can masquerade as something else.

The discrete Fourier transform

With N samples, the DFT correlates the data with N complex sinusoids, exactly like the Fourier series coefficients of lesson 2:

X[k]=∑n=0N−1x[n]e−j2πkn/N
  • Bin k corresponds to the frequency kfs/N, so the bins are fs/N apart: one over the record's length (lesson 13's resolution limit).
  • A tone that fits a whole number of cycles in the record lands in a single bin. One that doesn't spreads into its neighbors: leakage, which window functions reduce.
  • Computed directly, the DFT takes about N2 operations. The fast Fourier transform (FFT) gets the same answer in about Nlog2⁡N: for a million samples, 20 million instead of a trillion. It's one of the most important algorithms in engineering.

Course C9 (signals and systems) and the DSP survey build on all of this.

Worked example

Tones at 7, 13 and 23 kHz are sampled at 10 kHz. Where does each appear?

Show the solution
  1. The rule. Bring each tone into 0 to 5 kHz with |f−kfs|.
  2. Fold each tone. In kHz: |7−10|=3|13−10|=3|23−20|=3
  3. Compare. All three land at 3 kHz and can't be told apart in the data.

Answer all three appear at 3 kHz.

Worked example

You take a DFT of 1000 samples at 10 kHz. How far apart are the bins, where does a 1.25 kHz tone land, and how much work does the FFT save?

Show the solution
  1. The bin spacing. 10kHz1000=10Hz
  2. The tone's bin. 1250Hz10Hz=125
  3. A direct DFT. It takes about 10002=106 operations.
  4. The FFT. It takes about 1000log2⁡1000≈10,000 a hundred times fewer.

Answer the bins are 10 Hz apart, the tone lands in bin 125, and the FFT does about a hundred times less work.

Worked example

Telephone speech is limited to 3.4 kHz and sampled at 8 kHz. What is the minimum sampling rate, and why use more?

Show the solution
  1. Nyquist's minimum. It's twice the highest frequency: 2×3.4kHz=6.8kHz
  2. The guard band. Sampling at 8 kHz puts the first alias of a 3.4 kHz tone at 8−3.4=4.6kHz 1.2 kHz above the band.
  3. What the filter has to do. The anti-aliasing filter only has to roll off between 3.4 and 4.6 kHz, which a practical filter can do, rather than from 3.4 kHz to 3.4 kHz, which no filter can.

Answer the minimum is 6.8 kHz; sampling at 8 kHz leaves a 1.2 kHz guard band that a practical anti-aliasing filter can work in.

Check

A signal has frequencies up to 4 kHz. What is the lowest sample rate that can capture it without aliasing?

Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.

Check

A 6 kHz tone is sampled at 10 kHz with no anti-aliasing filter. At what frequency does it appear in the data?

Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.

Check

A DFT of 1024 samples taken at 8000 Hz has bins how far apart?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

A sine wave at an unknown frequency has been sampled for you: x holds 1000 samples taken at 1000 Hz. Use np.fft.rfft to find its frequency, and set f_peak to it in hertz.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Where does an anti-aliasing filter go, and why?

Check

A signal is limited to 15 kHz and must leave a guard band of 1.2 kHz below the first alias.

(a)

What sampling rate does that take?

Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.

Check

A DFT of N samples taken at fs (kHz).

Step 1

What is the bin spacing, in Hz?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why does a tone above half the sample rate show up at a lower frequency in sampled data?

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.