The Convolution Theorem
The most useful fact in this course: convolution in time is multiplication in frequency. A filter that would take a long sum per output sample becomes a pointwise product of spectra. This turns filtering into "turn some frequency knobs down", explains why blurs remove detail, and makes the FFT the fastest way to convolve long signals.
The theorem
Proof sketch: write out , substitute , and the double integral splits into . The exponential's property does all the work.
import numpy as np
dt = 0.002
t = np.arange(-10, 10, dt)
box = (np.abs(t) < 0.5).astype(float)
tri = np.convolve(box, box, mode="same") * dt # Pi * Pi = Lambda
ft = lambda f, s: np.sum(f * np.exp(-2j * np.pi * s * t)) * dt
for s in (0.0, 0.3, 0.7, 1.5):
lhs = ft(tri, s)
rhs = ft(box, s) ** 2
print(f"s={s}: F(box*box) = {lhs.real:+.5f} F(box)^2 = {rhs.real:+.5f} sinc^2 = {np.sinc(s) ** 2:+.5f}")s=0.0: F(box*box) = +1.00000 F(box)^2 = +1.00000 sinc^2 = +1.00000
s=0.3: F(box*box) = +0.73684 F(box)^2 = +0.73684 sinc^2 = +0.73684
s=0.7: F(box*box) = +0.13534 F(box)^2 = +0.13533 sinc^2 = +0.13534
s=1.5: F(box*box) = +0.04503 F(box)^2 = +0.04502 sinc^2 = +0.04503
So , the pair from The Fourier Transform, without computing any integral.
Filtering seen in frequency
A blur with a Gaussian kernel multiplies the spectrum by a Gaussian: high frequencies (fine detail, noise) are scaled down, low frequencies kept. Convolving two Gaussians gives a wider Gaussian, because the product of their spectra is a narrower Gaussian: variances add.
import numpy as np
N = 512
n = np.arange(N)
rng = np.random.default_rng(4)
x = np.sin(2 * np.pi * 5 * n / N) + 0.5 * rng.normal(size=N)
k = np.arange(-20, 21)
kernel = np.exp(-0.5 * (k / 4.0) ** 2); kernel /= kernel.sum()
padded = np.zeros(N); padded[k % N] = kernel # kernel centered at index 0, circularly
y_time = np.real(np.fft.ifft(np.fft.fft(x) * np.fft.fft(padded))) # multiply spectra
y_conv = np.array([np.sum(x[(i - k) % N] * kernel) for i in range(N)]) # circular convolution sum
print("frequency-domain result equals direct convolution:", np.allclose(y_time, y_conv))
H = np.abs(np.fft.fft(padded))
print("filter gain at bins 0, 5, 20, 60, 128:", np.round(H[[0, 5, 20, 60, 128]], 4).tolist())
print("noise power before / after:", round(np.var(x - np.sin(2 * np.pi * 5 * n / N)), 3),
round(np.var(y_time - np.sin(2 * np.pi * 5 * n / N)), 3))frequency-domain result equals direct convolution: True
filter gain at bins 0, 5, 20, 60, 128: [1.0, 0.9703, 0.6176, 0.0131, 0.0]
noise power before / after: 0.251 0.022
The gain is nearly 1 at the signal's frequency (bin 5) and tiny at high frequencies, so most of the white noise is removed while the sine survives.
The other direction: windowing
Multiplying in time convolves in frequency. Cutting a signal to a finite window (multiplying by ) convolves its spectrum with a sinc, smearing every sharp spectral line into a sinc shape. That is spectral leakage, the subject of Spectral Leakage.
In software
scipy.signal.fftconvolveandoaconvolveimplement convolution via the theorem; cuDNN picks FFT-based convolution for large kernels.- Deconvolution (deblurring, removing a known echo) divides spectra, which is unstable where is near 0; Wiener filtering regularizes that division.
Exercises
Exercise 1: Convolution of Gaussians
What is ?
Answer
.
Solution
The transform is . By the scaling rule this is the transform of .
Exercise 2: Which frequencies survive?
A signal contains 10 Hz and 50 Hz components. It is convolved with a kernel whose spectrum is 1 below 30 Hz and 0 above. What comes out?
Answer
Only the 10 Hz component.
Solution
The output spectrum is the product: the 10 Hz line is multiplied by 1 and the 50 Hz line by 0. This is an ideal low-pass filter.
Exercise 3: Check with sequences (code)
Verify the discrete theorem: for and , compare the inverse DFT of with np.convolve(x, h).
Answer
Both give when the arrays are padded long enough.
Solution
import numpy as np
x = np.array([1, 2, 3, 0, 0], dtype=float)
h = np.array([1, -1, 0, 0, 0], dtype=float)
via_fft = np.real(np.fft.ifft(np.fft.fft(x) * np.fft.fft(h)))
print((np.round(via_fft, 10) + 0.0).tolist(), np.convolve(x[:3], h[:2]).tolist())[1.0, 1.0, 1.0, -3.0, 0.0] [1.0, 1.0, 1.0, -3.0]
The zeros at the end make room for the full linear convolution; without them the DFT computes a circular convolution that wraps around.
Test yourself
The Fourier transform of is…
Multiplying a signal by a window in time…
- multiplies the spectrum by the window
- convolves the spectrum with the window's transform
- has no effect on the spectrum
- shifts the spectrum
Why is deconvolution numerically hard?
- it needs complex numbers
- it divides by the kernel's spectrum, which may be near zero
- convolution is not linear
- the FFT cannot be inverted