TactivergeLite

Lite / Textbooks / Applied Engineering Mathematics / Chapter 5

5. Fourier and transform thinking

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

Introduction

Sometimes the best way to answer a question about a signal is to ask a different question: not 'what is its value now?' but 'how much of each frequency does it contain?'. This chapter builds signals from sinusoids, rebuilds a square wave from its odd harmonics, measures frequency content with the discrete Fourier transform, and sees filtering in time as multiplication in frequency.

Figure 5.1. A square wave from three sinusoids (described in words)

A square wave of height ±1 over one period, with the sum of its first three odd harmonics drawn over it. A bar chart shows the harmonic amplitudes 4/(nπ): 1.273 for n = 1, 0.424 for n = 3 and 0.255 for n = 5. Even harmonics are zero.

Explanation

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

5.1 Seeing a signal's ingredients

A chord played on a piano is one wobbly line on an oscilloscope. How can a tuner app name every note in it?

Two views of one signal

The time domain shows value against time. The frequency domain shows how much of each frequency is present. A magnitude spectrum draws a bar of height Aᵢ at each fᵢ. The same information, arranged differently, like a recipe versus the cake.

Phase hides in the time view

Shifting a component's phase reshapes the waveform (peaks can line up or cancel) but leaves its bar the same. That is why two signals that look different can sound identical: your ear cares mostly about magnitudes. A full description keeps the phase too, so the time signal can be rebuilt.

Power adds across frequencies

Sinusoids of different frequencies average to zero when multiplied together, so the cross terms vanish and P = Σ Aᵢ²/2. That is Parseval's theorem in miniature: power computed in time equals power computed from the spectrum. Components at the same frequency are different: they combine as phasors first.

Common mix-ups

Open the Lite lesson: Seeing a signal's ingredients

5.2 A square wave made of curves

A square wave has perfectly sharp corners. Sine waves have none. Yet enough sine waves add up to a square. How many, and what's left over?

The series

A square wave swinging between +A and −A is x(t) = (4A/π)·[sin ωt + sin 3ωt/3 + sin 5ωt/5 + …]. Harmonic n has amplitude bₙ = 4A/(nπ) for odd n and 0 for even n. The fundamental is 4/π ≈ 1.27 times taller than the square itself.

Power is concentrated low

The square has power A². The fundamental alone carries (4A/π)²/2 = 8A²/π² ≈ 81 % of it; adding the 3rd and 5th reaches about 93 %. So a square wave through a low-pass filter quickly looks like a sine: that is how some cheap sine-wave inverters work.

Gibbs: the overshoot that won't go away

Near each jump the partial sum overshoots by about 9 % of the jump, however many terms you add. More terms make the overshoot narrower, not lower. In practice, ringing near edges in a band-limited system is the same effect: a sharp edge truly needs infinitely high frequencies.

Common mix-ups

Open the Lite lesson: A square wave made of curves

5.3 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?'

5.4 The moving average, seen in frequency

Averaging the last four readings smooths a sensor beautifully. So why does it completely erase one particular frequency?

One line of code

y[n] = (x[n] + x[n−1] + … + x[n−M+1])/M. It is a finite impulse response (FIR) filter: an impulse affects exactly M outputs, then is forgotten. Random noise of standard deviation σ comes out with σ/√M, because independent errors partly cancel.

Nulls and side lobes

Its gain is 1 at DC and falls to exactly zero at fs/M, 2fs/M, …, with bumps (side lobes) in between: the first is about 0.22 for large M. Great for removing a known interference, like 50 Hz mains when fs/M = 50 Hz, but a mediocre general low-pass because the side lobes leak.

The price: lag

The output is centred (M − 1)/2 samples in the past. With M = 9 at 100 Hz that is 40 ms: fine for a thermometer, dangerous inside a fast control loop where delay erodes stability. Doubling M halves the noise power again but doubles the lag.

Derivation: The moving-average frequency response
  1. Input x[n] = e^{jωn} with ω = 2πf/fs. Output y[n] = (1/M)·Σ_{k=0}^{M−1} e^{jω(n−k)} = e^{jωn}·H, with H = (1/M)·Σ e^{−jωk}.

  2. That is a geometric series: H = (1/M)·(1 − e^{−jωM})/(1 − e^{−jω}).

  3. Factor out half-angles: (1 − e^{−jθ}) = e^{−jθ/2}·2j·sin(θ/2).

  4. So |H| = |sin(ωM/2) / (M·sin(ω/2))| = |sin(πMf/fs)/(M·sin(πf/fs))|, with a pure delay of (M − 1)/2 samples.

  5. It is 1 at f = 0 and 0 whenever Mf/fs is a whole number (other than multiples of M): nulls at f = fs/M, 2fs/M, …

Common mix-ups

Open the Lite lesson: The moving average, seen in frequency

5.5 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

Seeing a signal's ingredients: example 1

Sketch the spectrum of 3 + 2·cos(2π·10t) + sin(2π·30t).

Solution

A bar of height 3 at 0 Hz (DC), height 2 at 10 Hz and height 1 at 30 Hz. Power = 3² + 2²/2 + 1²/2 = 9 + 2 + 0.5 = 11.5.

A square wave made of curves: example 1

A ±5 V, 1 kHz square wave drives a speaker. What is the amplitude of the 3 kHz component?

Solution

n = 3: b₃ = 4 × 5/(3π) ≈ 2.12 V.

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).

The moving average, seen in frequency: example 1

A 5-point moving average filters x = [2, 4, 6, 8, 10, 12]. Find y[4] and y[5].

Solution

y[4] = (2 + 4 + 6 + 8 + 10)/5 = 6. y[5] = (4 + 6 + 8 + 10 + 12)/5 = 8. A ramp comes out as the same ramp delayed by (5 − 1)/2 = 2 samples.

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 5.2 from Seeing a signal's ingredients

Load 'Three tones'. Read the spectrum bars, then change each phase and watch the time plot. Next put two components at the same frequency and vary one phase: what happens to that bar now?

With three tones at 2, 5 and 8 Hz the spectrum shows three bars of heights 1, 0.6 and 0.3. Changing phases changes the waveform's shape but not the bars. Putting two components at the same frequency makes one bar whose height depends on their phase difference (from the sum to the difference of the amplitudes).

Figure 5.3 from A square wave made of curves

Start with 1 harmonic, then add them one by one up to 25. Watch the power captured and the peak of the sum. Does the overshoot near the jump get smaller, or only narrower?

With 1 harmonic the builder draws a sine of peak 1.27 over the square. Adding odd harmonics (3, 5, 7…) fills in the corners; captured power rises from 81 % to about 98 % with 13 terms; the peak near each jump stays about 1.18, a 9 % overshoot of the jump of 2.

Figure 5.4 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 5.5 from The moving average, seen in frequency

Choose 'Moving average', low-pass. Set M = 4 and slide the test frequency to find the null. Change M to 8 and 2: where do the nulls go? Watch the step response: how many samples does it take to reach the top?

In the explorer, the 4-point moving average has gain 1 at 0, falls to about 0.77 at f/fs = 0.1, and reaches 0 at f/fs = 0.25 (a null), with a small bump after it. With M = 8 the first null moves to 0.125. The step response climbs in M equal steps to 1.

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. x(t) = 2·sin(2π·50t) + 1·sin(2π·150t). What is its average power?
    Answer it in “Seeing a signal's ingredients”
  2. Where does a constant offset appear in a spectrum?
    Answer it in “Seeing a signal's ingredients”
  3. What is the amplitude of the fundamental of a ±1 square wave (3 decimal places)?
    Answer it in “A square wave made of curves”
  4. You add more and more harmonics. What happens to the overshoot near each jump?
    Answer it in “A square wave made of curves”
  5. 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?'”
  6. You need to tell 100 Hz and 102 Hz apart. What helps most?
    Answer it in “The DFT: asking 'how much of this wave?'”
  7. A moving average with M = 10 runs at fs = 500 Hz. What is the lowest frequency it removes completely, in Hz?
    Answer it in “The moving average, seen in frequency”
  8. Filtering in time corresponds to what in frequency?
    Answer it in “Transforms: why engineers change the question”

Engineering applications

Machine condition monitoring

A failing bearing adds energy at frequencies set by its geometry and shaft speed. A spectrum of a vibration sensor shows the fault long before it can be heard.

Choosing a filter

Knowing that a motor's switching noise sits at 20 kHz while the signal stays below 100 Hz tells you what filter to design. In frequency, the job becomes obvious.

Watch (optional)

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

Summary

Glossary

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
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
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
Logarithms and decibels
A logarithm answers 'what power gives this number?'. Decibels use logarithms to express ratios: 10 log10 for power ratios and 20 log10 for amplitude ratios. Field Guide

Project: What is in that hum?

Generate or record a signal that mixes a 50 Hz hum, its third harmonic and noise. Compute its DFT, identify each component and its amplitude, then design a moving-average or first-order filter and show its effect on the spectrum.

Deliverables

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

References

← 4. Differential equations and stability6. Numerical methods and their errors →