TactivergeLite

Lite / Textbooks / Signals and Systems / Chapter 7

7. The DFT: measuring a spectrum

Version 1 · Technically checked (automated checks only) · 2 source lessons · Full interactive version

Introduction

Given a list of samples, the discrete Fourier transform asks one question per frequency bin: how much of this wave is in the signal? It answers by correlating the samples with a test sinusoid. The bins are spaced by the sample rate divided by the number of samples, so a longer recording resolves finer detail. Transforms like this let engineers change the question, from "what happens next?" to "which frequencies are there?"

Figure 7.1. Bin spacing = fs / N (described in words)

DFT bins 0 to 10 drawn as bars, with bin 5 highlighted. With N = 100 samples at 1000 Hz the bins are 10 Hz apart, so bin 5 is 50 Hz and the last useful bin, 50, is 500 Hz.

Explanation

Built from 2 School lessons. Each part is the lesson's own explanation.

7.1 The DFT: asking 'how much of this wave?'

A computer only has eight numbers from a sensor. How can it say there is a strong 250 Hz component in them?

Correlation with probes

X[k] = Σ x[n]·cos(2πkn/N) − j·Σ x[n]·sin(2πkn/N). Each bin multiplies the signal by a probe wave with k cycles in the window and adds up. If the signal contains that wave, products are mostly positive and the sum is big; otherwise positives and negatives cancel. The cosine and sine sums together catch the component whatever its phase.

Bins and frequencies

With N samples at rate fs, bin k corresponds to f = k·fs/N. Resolution is fs/N: to tell close frequencies apart, record for longer. For a real signal, bins above N/2 mirror those below (they are the negative frequencies). A pure cosine of amplitude A exactly on bin k gives |X[k]| = A·N/2.

Small enough to do by hand

For N = 4 the probes take only the values 1, 0 and −1, so X[0] = x0 + x1 + x2 + x3, X[2] = x0 − x1 + x2 − x3, and X[1] = (x0 − x2) − j(x1 − x3). For x = [1, 0, −1, 0], X[1] = 2: one cycle of a cosine, amplitude 1, times N/2 = 2.

Common mix-ups

Open the Lite lesson: The DFT: asking 'how much of this wave?'

7.2 Transforms: why engineers change the question

Filtering is a messy running sum in time but a simple multiplication in frequency. What other hard problems become easy when you transform them?

Filtering = multiplying spectra

In time, a filter output is a weighted running sum of the input (a convolution). In frequency, the same operation is just Y(f) = H(f)·X(f): each component is scaled by the gain at its frequency and shifted by the phase. That is why a frequency response is the most useful single description of a filter.

Low-pass, high-pass, and the rest

Low-pass keeps slow changes (smoothing, anti-aliasing). High-pass keeps fast changes and removes offsets and drift (AC coupling, removing gyro bias). A band-pass keeps a range (radio tuning), and a notch removes one frequency (mains hum). High-pass can be built as 1 − low-pass.

The Laplace transform, conceptually

The Fourier transform describes a signal with steady sinusoids. The Laplace transform uses e^{st} with complex s = σ + jω: sinusoids that can also grow or decay. Differentiation becomes multiplication by s, so a circuit's differential equation becomes algebra, e.g. an RC low-pass has H(s) = 1/(1 + sRC). Where H(s) blows up (its poles) tells you whether a system is stable.

Common mix-ups

Open the Lite lesson: Transforms: why engineers change the question

Worked examples

The DFT: asking 'how much of this wave?': example 1

Compute all four DFT bins of x = [2, 1, 0, 1].

Solution

X[0] = 4. X[2] = 2 − 1 + 0 − 1 = 0. X[1] = (2 − 0) − j(1 − 1) = 2. X[3] = 2. So DC of 1 (4/N) plus one cosine cycle of amplitude 1 (2·2/N).

Transforms: why engineers change the question: example 1

A sensor reading is 2.5 V of steady offset plus a 5 Hz vibration plus 200 Hz noise, sampled at 1 kHz. Which filter keeps just the vibration?

Solution

A band-pass around 5 Hz: a high-pass to remove the 2.5 V DC, followed by a low-pass that cuts 200 Hz. In frequency: H is about 0 at 0 Hz, about 1 at 5 Hz and about 0 at 200 Hz.

Interactive figures, in words

Figure 7.2 from The DFT: asking 'how much of this wave?'

Pick 'cos 2 + ½·sin 3'. Step the probe k from 0 to 7, watching the products column. Which k give big sums, and why do the cosine part and the sine part show up in different columns?

For the signal cos(2·2πn/8) + ½·sin(3·2πn/8), the probe shows |X[k]| = 4 at k = 2 and 6 (cosine part, through the Σx·cos column) and 2 at k = 3 and 5 (sine part, through the Σx·sin column); every other bin is zero.

Figure 7.3 from Transforms: why engineers change the question

Compare four filters: moving average and IIR, each as low-pass and high-pass. For each, read the gain at f/fs = 0, 0.05 and 0.45. Write a one-line description of what each would do to a slowly drifting, noisy sensor.

Reading the explorer: both low-pass filters have gain 1 at 0 and small gain near 0.45; both high-pass filters have gain 0 at 0 and close to 1 at high frequencies. On a drifting, noisy sensor the low-pass keeps the drift and removes the noise; the high-pass removes the drift and keeps the noise.

The interactive versions are in the full chapter.

Laboratory

These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.

Practice

Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.

  1. In an N-point DFT, what does bin k measure?
    Answer it in “The DFT: asking 'how much of this wave?'”
  2. x = [1, 0, −1, 0]. What is |X[1]| of its 4-point DFT?
    Answer it in “The DFT: asking 'how much of this wave?'”
  3. A 1024-point DFT is taken of a signal sampled at 8 kHz. What frequency, in Hz, does bin k = 64 represent?
    Answer it in “The DFT: asking 'how much of this wave?'”
  4. You need to tell 100 Hz and 102 Hz apart. What helps most?
    Answer it in “The DFT: asking 'how much of this wave?'”
  5. Filtering in time corresponds to what in frequency?
    Answer it in “Transforms: why engineers change the question”
  6. Which job needs a high-pass filter?
    Answer it in “Transforms: why engineers change the question”
  7. What does the Laplace transform mainly do for an engineer?
    Answer it in “Transforms: why engineers change the question”

Engineering applications

Tuners and analysers

A guitar tuner records a fraction of a second of sound, takes its spectrum and finds the strongest peak. The recording length sets how finely it can tell two nearby notes apart.

Fast algorithms

Computing a DFT directly takes about N² operations; the fast Fourier transform needs about N log N. That difference is why spectra can be computed in real time on small processors.

Watch (optional)

Streaming video uses a lot of data. Everything you need is in the text.

Summary

Glossary

Sampling and aliasing
Sampling measures a signal at regular intervals. Any frequency above half the sample rate, the Nyquist frequency, is indistinguishable from a lower 'alias' frequency. Field Guide
Frequency and period
Frequency is how many cycles happen per second; the period is the time for one cycle. Each is the reciprocal of the other. Field Guide
Low-pass filter (moving average and EMA)
A low-pass filter lets slow changes through and attenuates fast ones. In firmware the simplest are the moving average and the exponential moving average. Field Guide

Project: Find the hidden tones

Generate a signal from two sinusoids 3 Hz apart plus noise, sampled at 200 Hz. Compute its spectrum with recordings of 1 s, 2 s and 4 s, and find the shortest recording that separates the two peaks. Explain the result with the bin spacing.

Deliverables

Write it up on paper or in your own notes. Lite never stores what you write.

References

← 6. Sinusoids and Fourier series8. Filters seen in frequency →