The Fourier Transform
The Fourier transform turns a signal into its spectrum , a complex function of frequency. This lesson computes the standard transform pairs, the rectangle, the triangle, the Gaussian and the one-sided exponential, and builds the intuition that will carry the rest of the course: narrow in time means wide in frequency, and smooth in time means fast decay in frequency.
Definition
is the magnitude spectrum (how much of frequency ) and the phase spectrum (where in time those oscillations line up). The transform exists, for example, whenever .
Four essential pairs
| Notes | ||
|---|---|---|
| : 1 for , else 0 | jumps: decay like | |
| corners: decay like | ||
| smooth: decays faster than any power | ||
| for , 0 before | complex: has a phase |
import numpy as np
dt = 0.0005
t = np.arange(-30, 30, dt)
pairs = {
"rect": ((np.abs(t) < 0.5).astype(float), lambda s: np.sinc(s)),
"triangle": (np.clip(1 - np.abs(t), 0, None), lambda s: np.sinc(s) ** 2),
"gaussian": (np.exp(-np.pi * t ** 2), lambda s: np.exp(-np.pi * s ** 2)),
"one-sided exp (a=1)": (np.where(t >= 0, np.exp(-np.clip(t, 0, None)), 0.0), lambda s: 1 / (1 + 2j * np.pi * s)),
}
S = np.array([0.0, 0.3, 1.2, 2.5])
for name, (f, exact) in pairs.items():
num = np.array([np.sum(f * np.exp(-2j * np.pi * s * t)) * dt for s in S])
print(f"{name:20s} max error vs formula: {np.max(np.abs(num - exact(S))):.1e}")rect max error vs formula: 5.0e-04
triangle max error vs formula: 8.3e-08
gaussian max error vs formula: 2.3e-12
one-sided exp (a=1) max error vs formula: 2.5e-04
The errors are tiny (Riemann-sum and truncation errors), confirming all four formulas.
Reading a spectrum
The one-sided exponential, a capacitor discharging or a struck bell's envelope, has a complex transform: its magnitude is largest at low frequencies, and its phase runs from 0 to , reflecting that the signal is not symmetric in time.
import numpy as np
a = 2.0
for s in (0, 0.1, 0.3, 1, 3):
F = 1 / (a + 2j * np.pi * s)
print(f"s={s:4}: |F| = {abs(F):.4f} phase = {np.degrees(np.angle(F)) + 0.0:7.2f} deg")
half_power = a / (2 * np.pi)
print(f"half-power frequency a/(2 pi) = {half_power:.4f}: |F|^2 there = {abs(1 / (a + 2j * np.pi * half_power)) ** 2:.4f} = (1/a^2)/2 = {1 / a ** 2 / 2:.4f}")s= 0: |F| = 0.5000 phase = 0.00 deg
s= 0.1: |F| = 0.4770 phase = -17.44 deg
s= 0.3: |F| = 0.3639 phase = -43.30 deg
s= 1: |F| = 0.1517 phase = -72.34 deg
s= 3: |F| = 0.0528 phase = -83.94 deg
half-power frequency a/(2 pi) = 0.3183: |F|^2 there = 0.1250 = (1/a^2)/2 = 0.1250
The half-power point is the "cutoff frequency" of the RC low-pass filter whose impulse response this is.
In software
- Spectra of continuous signals are almost always estimated from samples with the FFT; analytic pairs like these are the test cases for such code.
np.sincis the normalized sinc , matching this course; some books define .
Exercises
Exercise 1: Value at zero
Why is ? Use it to find .
Answer
At the exponential is 1; .
Solution
, so is the area under . The triangle of base 2 and height 1 has area 1, matching .
Exercise 2: Zeros of the sinc
At which frequencies is the spectrum of zero, and why?
Answer
At .
Solution
at integers . At those frequencies a whole number of periods fits in the pulse's width 1, so the oscillation integrates to zero against the pulse.
Exercise 3: A wider pulse (code)
Numerically compute the transform of a rectangle of width 2 (1 for ) at and guess the formula.
Answer
Values 2, about 1.2732 and 0; formula .
Solution
import numpy as np
dt = 0.0005
t = np.arange(-5, 5, dt)
f = (np.abs(t) < 1).astype(float)
for s in (0, 0.25, 0.5):
val = np.sum(f * np.exp(-2j * np.pi * s * t)) * dt
print(s, round(val.real, 4) + 0.0, round(2 * np.sinc(2 * s), 4) + 0.0)0 2.0 2.0
0.25 1.2732 1.2732
0.5 0.0 0.0
Twice as wide in time gives a spectrum twice as tall and half as wide, the scaling theorem.
Test yourself
The Gaussian has Fourier transform…
- a delta
equals…
- the area under
- the maximum of
- 0
A signal with jumps has a spectrum that decays like…
- it does not decay