Blog · updated 18 Nov 2026 · 129 min read

The discrete Fourier world: sampling, aliasing, the FFT and the uncertainty principle

What changes when signals are sampled and finite. The four Fourier transforms and the rule that links them, Poisson summation and the sampling theorem, aliasing in images and inside neural networks, the DFT and FFT computed by hand in 1-D and 2-D, leakage and windows, the DCT behind JPEG, and a proof that no signal is sharp in both time and frequency. Part 2 of Seeing in frequencies.

Contents
  1. Notation and conventions
  2. 1. Four Fourier transforms, one rule
  3. 2. Sampling
  4. Poisson summation: sampling one side samples the other
  5. Sampling makes the spectrum periodic
  6. The sampling theorem
  7. What aliasing looks like
  8. 3. Aliasing inside neural networks
  9. 4. The DFT, by hand
  10. Circular convolution
  11. 5. The 2-D DFT, by hand
  12. 6. Reading an FFT output
  13. 7. Leakage and windows
  14. The bright cross in image spectra
  15. 8. The FFT
  16. 9. The DCT, and why JPEG uses it
  17. 10. The uncertainty principle
  18. 11. The short-time Fourier transform
  19. 12. Implementation and caveats
  20. 13. Where it is used, and what is open
  21. Self-check
  22. References

Seeing in frequencies, part 2 of 4. Fourier analysis → the discrete Fourier world → wavelets → wavelets for images.

Keep every fourth pixel of the image on the left, and rings appear that were never there.

The rings in the middle panel are aliases: fine detail that could not survive the subsampling and came back as coarse detail instead. The right panel, blurred before subsampling, has none. This post explains exactly why, and then everything else that changes when the clean integrals of Part 1 meet a computer: signals are sampled, and they are finite.

Almost every bug in spectral code is one of these two facts forgotten. Sampling makes spectra periodic (Section 2), which is aliasing; finiteness makes them leak (Section 7), which is why a pure tone shows up in every bin. Between those two sections the post builds the discrete Fourier transform by hand in one and two dimensions, and then the FFT, the fast algorithm that computes it. It ends with the theorem that limits all of this, the uncertainty principle, and the tool built on it, the spectrogram, which is where wavelets begin.

Notation and conventions

SymbolMeaning
TT, fs=1/Tf_s = 1/Tsampling interval and rate
x[n]=f(nT)x[n] = f(nT)samples
X(ν)X(\nu)discrete-time Fourier transform (DTFT)
NNnumber of samples
ωN=e−2πi/N\omega_N = e^{-2\pi i/N}the DFT’s root of unity
X[k]=∑nx[n] ωNknX[k] = \sum_n x[n]\,\omega_N^{kn}discrete Fourier transform (DFT)
F\mathbf{F}the N×NN \times N DFT matrix, Fkn=ωNkn\mathbf{F}_{kn} = \omega_N^{kn}
x⊛yx \circledast ycircular convolution

Frequencies are in cycles per unit (Hz for time, cycles per pixel for images), as in Part 1. The DFT follows NumPy: no factor on the forward transform, 1/N1/N on the inverse.

1. Four Fourier transforms, one rule

Part 1 met two transforms: the Fourier series (periodic signals) and the Fourier transform (signals on the whole line). Sampling adds two more, and the four sit on a two-by-two grid.

four Fourier transforms, one ruletime: not periodictime: periodictime:continuoustime:discreteFourier transformtimespectrum: continuousFourier seriestimespectrum: discrete linesDTFTtimespectrum: continuous, periodicDFT (what the FFT computes)timespectrum: discrete, periodicdiscrete in one domain ⟺ periodic in the otheramber marks: one period
Signal in timeSpectrumName
continuous, not periodiccontinuous, not periodicFourier transform
continuous, periodicdiscreteFourier series
discrete, not periodiccontinuous, periodicDTFT
discrete, periodicdiscrete, periodicDFT

One rule organises the table: discrete in one domain if and only if periodic in the other. Part 1 proved half of it already: a periodic signal has a discrete spectrum, the Fourier series. Section 2 proves the other half: a sampled signal has a periodic spectrum. A computer can only hold finitely many numbers in each domain, so it must be discrete in both, hence periodic in both: that is the DFT.

Question 1

“The FFT computes the Fourier transform.” What does it actually compute?

Answer

The DFT of NN numbers. Read as a statement about a continuous signal, that is the Fourier transform of the signal after three changes: it was sampled (so its spectrum is replaced by the sum of shifted copies, Section 2), cut to NN samples (so the spectrum is smeared by a sinc, Section 7), and treated as periodic (so the spectrum is read at only NN frequencies, Section 4). Each change has a visible consequence, and each has a fix.

2. Sampling

Poisson summation: sampling one side samples the other

One identity does most of the work in this post. It relates samples of a function to samples of its transform.

Theorem 1 (Poisson summation)

For a smooth, rapidly decaying ff,

∑n=−∞∞f(n)=∑k=−∞∞f^(k),and more generally∑nf(nT)=1T∑kf^ ⁣(kT).\sum_{n=-\infty}^{\infty} f(n) = \sum_{k=-\infty}^{\infty}\hat f(k), \qquad \text{and more generally} \qquad \sum_{n} f(nT) = \frac{1}{T}\sum_{k}\hat f\!\left(\frac{k}{T}\right).
Proof

Step 1. Make a periodic function. Let F(x)=∑nf(x+n)F(x) = \sum_n f(x + n). Because ff decays fast the sum converges and is smooth, and F(x+1)=F(x)F(x + 1) = F(x).

Step 2. Its Fourier coefficients are samples of f^\hat f. ck(F)=∫01∑nf(x+n) e−2πikxdx=∑n∫nn+1f(u) e−2πik(u−n)duc_k(F) = \int_0^1\sum_n f(x + n)\,e^{-2\pi ikx}dx = \sum_n\int_n^{n+1}f(u)\,e^{-2\pi ik(u - n)}du (substitute u=x+nu = x + n). Since e2πikn=1e^{2\pi ikn} = 1, this is ∑n∫nn+1f(u)e−2πikudu=∫−∞∞f(u)e−2πikudu=f^(k)\sum_n\int_n^{n+1}f(u)e^{-2\pi iku}du = \int_{-\infty}^{\infty}f(u)e^{-2\pi iku}du = \hat f(k): the integrals over the unit intervals tile the line.

Step 3. Evaluate the series at 00. FF is smooth, so its coefficients decay fast (Part 1, Section 4) and its Fourier series converges to it at every point. At x=0x = 0: F(0)=∑kck(F)F(0) = \sum_k c_k(F), that is, ∑nf(n)=∑kf^(k)\sum_n f(n) = \sum_k\hat f(k).

Step 4. Other spacings. Apply this to g(x)=f(Tx)g(x) = f(Tx), whose transform is g^(ξ)=1Tf^(ξ/T)\hat g(\xi) = \frac1T\hat f(\xi/T) by the scaling rule: ∑nf(nT)=1T∑kf^(k/T)\sum_n f(nT) = \frac1T\sum_k\hat f(k/T).

Sampling makes the spectrum periodic

Sample ff every TT: x[n]=f(nT)x[n] = f(nT). The natural transform of a sequence is the discrete-time Fourier transform, X(ν)=∑nx[n] e−2πiνnTX(\nu) = \sum_n x[n]\,e^{-2\pi i\nu nT}, a function of frequency ν\nu in Hz. It is periodic with period fsf_s, since adding fsf_s to ν\nu multiplies each term by e−2πin=1e^{-2\pi i n} = 1. What is it, in terms of f^\hat f?

Proposition 1 (The sampled spectrum is a sum of shifted copies)

X(ν)=fs∑k=−∞∞f^(ν−kfs).X(\nu) = f_s\sum_{k=-\infty}^{\infty}\hat f(\nu - k f_s).
Proof

Step 1. Fold the exponential into the function. Let g(x)=f(x)e−2πiνxg(x) = f(x)e^{-2\pi i\nu x}. Then X(ν)=∑ng(nT)X(\nu) = \sum_n g(nT).

Step 2. Its transform is a shift. By the modulation rule, g^(ξ)=f^(ξ+ν)\hat g(\xi) = \hat f(\xi + \nu).

Step 3. Poisson summation with spacing TT: ∑ng(nT)=1T∑kg^(k/T)=fs∑kf^(ν+kfs)\sum_n g(nT) = \frac1T\sum_k\hat g(k/T) = f_s\sum_k\hat f(\nu + kf_s). Relabel k→−kk \to -k.

Sampling every TT seconds places a copy of the spectrum at every multiple of fsf_s. If ff contains no frequencies at or above fs/2f_s/2, the copies sit side by side and the original can be read off the central one. If it does, they overlap, and in the overlap the frequencies of different copies add up and can no longer be separated. That overlap is aliasing.

The spectrum of a band-limited signal (teal) and the copies that sampling creates. Above twice the bandwidth they stay apart; below it they overlap (amber), and the overlap is aliasing.

The sampling theorem

Theorem 2 (Nyquist–Shannon sampling theorem)

If f^(ξ)=0\hat f(\xi) = 0 for all ∣ξ∣≥fs/2\lvert\xi\rvert \ge f_s/2, then ff is determined by its samples, and

f(x)=∑n=−∞∞f(nT) sinc⁡ ⁣(fsx−n).f(x) = \sum_{n=-\infty}^{\infty} f(nT)\,\operatorname{sinc}\!\big(f_s x - n\big).

The frequency fs/2f_s/2 is the Nyquist frequency.

Proof

Step 1. Only one copy is non-zero in the band. For ∣ν∣<fs/2\lvert\nu\rvert < f_s/2, every copy f^(ν−kfs)\hat f(\nu - kf_s) with k≠0k \ne 0 is evaluated at a frequency of size at least fs/2f_s/2, where f^\hat f vanishes. So X(ν)=fsf^(ν)X(\nu) = f_s\hat f(\nu) there.

Step 2. Invert f^\hat f over the band. f(x)=∫−fs/2fs/2f^(ν)e2πiνxdν=1fs∫−fs/2fs/2X(ν)e2πiνxdνf(x) = \int_{-f_s/2}^{f_s/2}\hat f(\nu)e^{2\pi i\nu x}d\nu = \frac{1}{f_s}\int_{-f_s/2}^{f_s/2}X(\nu)e^{2\pi i\nu x}d\nu.

Step 3. Insert the samples. Substitute X(ν)=∑nf(nT)e−2πiνnTX(\nu) = \sum_n f(nT)e^{-2\pi i\nu nT} and exchange sum and integral (valid for the nice ff we assume): f(x)=∑nf(nT)⋅1fs∫−fs/2fs/2e2πiν(x−nT)dνf(x) = \sum_n f(nT)\cdot\frac1{f_s}\int_{-f_s/2}^{f_s/2}e^{2\pi i\nu(x - nT)}d\nu.

Step 4. The integral is a sinc. ∫−fs/2fs/2e2πiνudν=sin⁡(πfsu)πu=fssinc⁡(fsu)\int_{-f_s/2}^{f_s/2}e^{2\pi i\nu u}d\nu = \frac{\sin(\pi f_s u)}{\pi u} = f_s\operatorname{sinc}(f_s u) (the box pair of Part 1 with duality). With u=x−nTu = x - nT, fsu=fsx−nf_s u = f_sx - n.

Checked numerically: sinc⁡2(6x)\operatorname{sinc}^2(6x), whose spectrum fills [−6,6][-6, 6] Hz, sampled at 14 Hz and rebuilt from 801 samples, matches itself to 2×10−102\times10^{-10}.

What aliasing looks like

A single cosine makes aliasing concrete. Sampled at rate fsf_s, the waves e2πifte^{2\pi i f t} and e2πi(f+mfs)te^{2\pi i(f + mf_s)t} agree at every sample, because e2πimfs⋅nT=e2πimn=1e^{2\pi imf_s\cdot nT} = e^{2\pi imn} = 1. So a frequency ff is indistinguishable from f−mfsf - mf_s for every whole mm, and reconstruction picks the one inside [−fs/2,fs/2][-f_s/2, f_s/2]. A 7 Hz wave sampled at 10 Hz produces exactly the samples of a 3 Hz wave (checked to machine precision).

Three things people get wrong about the theorem:

  1. “Sample at twice the frequency.” At exactly fs=2ff_s = 2f the samples of cos⁡(2πft+φ)\cos(2\pi ft + \varphi) are (−1)ncos⁡φ(-1)^n\cos\varphi, which vanish for a sine. The theorem needs the signal strictly below fs/2f_s/2. Set the figure to f=5f = 5, fs=10f_s = 10 and move the phase.
  2. “The rate depends on the highest frequency.” It depends on the width of the band. A signal confined to [fL,fH][f_L, f_H] can be sampled at as little as 2(fH−fL)2(f_H - f_L) under conditions on where the band sits (bandpass sampling), because the copies can interleave without overlapping. Radio receivers rely on this.
  3. “Subsampling an image is free.” Keeping every dd-th pixel is sampling at 1/d1/d of the rate, so everything above 1/(2d)1/(2d) cycles per pixel aliases. That is the opening figure: the zone plate’s rings have frequency r/256r/256 cycles per pixel at radius rr, so with d=4d = 4 everything beyond radius 3232 folds back. Image libraries blur before shrinking for this reason (antialias=True in PyTorch’s interpolate; PIL’s default resampling filters).

3. Aliasing inside neural networks

A strided convolution or a pooling layer keeps every other sample. Section 2 says what that does to anything above a quarter of the sampling rate: it folds. A consequence that surprised the deep-learning community is that convolutional networks are not shift-invariant: move the input by one pixel and the output of a strided layer changes, often a lot (Azulay and Weiss, 2019). Zhang (2019) applied the textbook fix, blur before subsampling (“BlurPool”), and recovered much of the lost invariance; Karras et al. (2021) built StyleGAN3 around alias-free signal processing to stop textures from sticking to pixel coordinates.

The input is a slow wave plus a texture at 0.470.47 cycles per sample. Plain stride-2 subsampling folds the texture into a slow false wave whose size depends on where the samples land: over eight one-sample shifts the output energy varies by 19% (standard deviation over mean). Blurring with [1,2,1]/4[1, 2, 1]/4 first, whose frequency response is cos⁡2(πξ)\cos^2(\pi\xi), passes the slow wave (0.980.98) and almost erases the texture (0.0090.009): variation 0%. The price is lost detail; the network must decide what it was going to throw away anyway.

4. The DFT, by hand

Now finiteness. Take NN samples x[0],…,x[N−1]x[0], \ldots, x[N-1]. Their DTFT, in cycles per sample, is X(ν)=∑n=0N−1x[n]e−2πiνnX(\nu) = \sum_{n=0}^{N-1}x[n]e^{-2\pi i\nu n}, a continuous, 1-periodic function. A computer stores finitely many of its values, and the natural choice is NN equally spaced ones.

Definition 1 (Discrete Fourier transform)

X[k]=X ⁣(kN)=∑n=0N−1x[n] e−2πikn/N=∑n=0N−1x[n] ωNkn,k=0,…,N−1.X[k] = X\!\left(\frac kN\right) = \sum_{n=0}^{N-1}x[n]\,e^{-2\pi ikn/N} = \sum_{n=0}^{N-1}x[n]\,\omega_N^{kn}, \qquad k = 0, \ldots, N - 1 .

In matrix form X=Fx\boldsymbol{X} = \mathbf{F}\boldsymbol{x} with Fkn=ωNkn\mathbf{F}_{kn} = \omega_N^{kn}, ωN=e−2πi/N\omega_N = e^{-2\pi i/N}.

Proposition 2 (The DFT is invertible, and unitary up to scale)

FHF=NI\mathbf{F}^{\mathsf H}\mathbf{F} = N\mathbf{I}. Hence x[n]=1N∑k=0N−1X[k] e2πikn/Nx[n] = \frac1N\sum_{k=0}^{N-1}X[k]\,e^{2\pi ikn/N}, and ∑k∣X[k]∣2=N∑n∣x[n]∣2\sum_k\lvert X[k]\rvert^2 = N\sum_n\lvert x[n]\rvert^2 (Parseval).

Proof

Step 1. An entry of FHF\mathbf{F}^{\mathsf H}\mathbf{F}. (FHF)nm=∑kωNkn‾ ωNkm=∑k=0N−1e2πik(n−m)/N(\mathbf{F}^{\mathsf H}\mathbf{F})_{nm} = \sum_k\overline{\omega_N^{kn}}\,\omega_N^{km} = \sum_{k=0}^{N-1}e^{2\pi ik(n - m)/N}.

Step 2. A geometric sum. With r=e2πi(n−m)/Nr = e^{2\pi i(n - m)/N}: if n=mn = m every term is 11 and the sum is NN. If n≠mn \ne m (both in 0..N−10..N-1), then r≠1r \ne 1 and the sum is 1−rN1−r=0\frac{1 - r^N}{1 - r} = 0, because rN=e2πi(n−m)=1r^N = e^{2\pi i(n - m)} = 1.

Step 3. Consequences. F−1=1NFH\mathbf{F}^{-1} = \frac1N\mathbf{F}^{\mathsf H} gives the inverse formula, and ∥X∥2=xHFHFx=N∥x∥2\lVert\boldsymbol{X}\rVert^2 = \boldsymbol{x}^{\mathsf H}\mathbf{F}^{\mathsf H}\mathbf{F}\boldsymbol{x} = N\lVert\boldsymbol{x}\rVert^2. (Some libraries divide both directions by N\sqrt N to make F\mathbf{F} exactly unitary; NumPy’s norm="ortho".)

The inverse formula defines x[n]x[n] for every integer nn, and the values repeat with period NN. So the DFT silently treats your NN samples as one period of a periodic signal: the bottom-right corner of the map in Section 1.

Example 1 (A 4-point DFT by hand)

With N=4N = 4, ω4=e−iπ/2=−i\omega_4 = e^{-i\pi/2} = -i, so every entry of F\mathbf{F} is one of 1,−i,−1,i1, -i, -1, i:

F=[11111−i−1i1−11−11i−1−i].\mathbf{F} = \begin{bmatrix}1 & 1 & 1 & 1\\ 1 & -i & -1 & i\\ 1 & -1 & 1 & -1\\ 1 & i & -1 & -i\end{bmatrix}.

For x=(1,2,0,−1)\boldsymbol{x} = (1, 2, 0, -1):

  • X[0]=1+2+0−1=2X[0] = 1 + 2 + 0 - 1 = 2 (the sum: the DC term);
  • X[1]=1+2(−i)+0(−1)+(−1)(i)=1−3iX[1] = 1 + 2(-i) + 0(-1) + (-1)(i) = 1 - 3i;
  • X[2]=1−2+0+1=0X[2] = 1 - 2 + 0 + 1 = 0;
  • X[3]=1+2i+0+(−1)(−i)=1+3iX[3] = 1 + 2i + 0 + (-1)(-i) = 1 + 3i.

X[3]=X[1]‾X[3] = \overline{X[1]}, as it must for real input (Part 1, Section 3): index 33 is frequency −1-1. NumPy agrees: np.fft.fft([1, 2, 0, -1]) gives [2, 1-3j, 0, 1+3j].

Example 2 (An 8-point box)

x=(1,1,1,1,0,0,0,0)\boldsymbol{x} = (1, 1, 1, 1, 0, 0, 0, 0). Then X[k]=∑n=03ω8kn=1−ω84k1−ω8kX[k] = \sum_{n=0}^{3}\omega_8^{kn} = \frac{1 - \omega_8^{4k}}{1 - \omega_8^k} for k≠0k \ne 0, and ω84k=(−1)k\omega_8^{4k} = (-1)^k. So X[0]=4X[0] = 4, X[k]=0X[k] = 0 for even k≠0k \ne 0, and X[k]=21−ω8kX[k] = \frac{2}{1 - \omega_8^k} for odd kk: numerically X[1]=1−2.414iX[1] = 1 - 2.414i, X[3]=1−0.414iX[3] = 1 - 0.414i, and their conjugates at k=7,5k = 7, 5. This is a sampled sinc, the discrete cousin of Part 1’s box pair. Section 8 computes it again, fast.

Circular convolution

Proposition 3 (The DFT turns circular convolution into multiplication)

With (x⊛y)[n]=∑m=0N−1x[m] y[(n−m) mod N](x\circledast y)[n] = \sum_{m=0}^{N-1}x[m]\,y[(n - m)\bmod N], the DFT of x⊛yx\circledast y is X[k] Y[k]X[k]\,Y[k].

Proof

Step 1. Write it out. ∑n∑mx[m] y[(n−m) mod N] ωNkn\sum_n\sum_m x[m]\,y[(n - m)\bmod N]\,\omega_N^{kn}.

Step 2. Split the exponent as ωNkn=ωNkmωNk(n−m)\omega_N^{kn} = \omega_N^{km}\omega_N^{k(n - m)} and swap the sums: ∑mx[m]ωNkm∑ny[(n−m) mod N] ωNk(n−m)\sum_m x[m]\omega_N^{km}\sum_n y[(n - m)\bmod N]\,\omega_N^{k(n-m)}.

Step 3. The inner sum is Y[k]Y[k]. As nn runs over 0..N−10..N-1, j=(n−m) mod Nj = (n - m)\bmod N also runs over 0..N−10..N-1, and ωNk(n−m)=ωNkj\omega_N^{k(n - m)} = \omega_N^{kj} because ωNN=1\omega_N^N = 1. What remains is X[k]Y[k]X[k]Y[k].

The “mod NN” is the catch. Multiplying two DFTs computes a convolution that wraps around. Convolve (1,2,3)(1, 2, 3) with (1,1)(1, 1): the true result is (1,3,5,3)(1, 3, 5, 3), but with N=3N = 3 the last value wraps onto the first and you get (4,3,5)(4, 3, 5). The fix is to zero-pad both signals to length at least L+M−1L + M - 1 for lengths LL and MM: with N=4N = 4 the product of DFTs returns (1,3,5,3)(1, 3, 5, 3) exactly.

5. The 2-D DFT, by hand

Images are where the 2-D DFT lives, and courses usually skip from the formula to the picture. Small cases can be done by hand.

Definition 2 (2-D DFT)

For an M×NM \times N image x[m,n]x[m, n] (row mm, column nn),

X[k,l]=∑m=0M−1∑n=0N−1x[m,n] ωMkm ωNln.X[k, l] = \sum_{m=0}^{M-1}\sum_{n=0}^{N-1}x[m, n]\,\omega_M^{km}\,\omega_N^{ln}.

Proposition 4 (Rows, then columns)

The 2-D DFT is a 1-D DFT of every row followed by a 1-D DFT of every column (or the other way round).

Proof

Group the sum: X[k,l]=∑mωMkm(∑nx[m,n] ωNln)X[k, l] = \sum_m\omega_M^{km}\Big(\sum_n x[m, n]\,\omega_N^{ln}\Big). The bracket, for each row mm, is the 1-D DFT of that row at frequency ll; the outer sum is a 1-D DFT down each column of the result. Because the sums are finite, they can be taken in either order.

Example 3 (Two images by hand)

A 2×22 \times 2 image [abcd]\begin{bmatrix}a & b\\ c & d\end{bmatrix}. With N=2N = 2, ω2=−1\omega_2 = -1, so every factor is ±1\pm1:

X=[a+b+c+da−b+c−da+b−c−da−b−c+d].X = \begin{bmatrix}a + b + c + d & a - b + c - d\\ a + b - c - d & a - b - c + d\end{bmatrix}.

Sum, left minus right, top minus bottom, checker. Remember these four; Part 4 shows that, divided by 4, they are exactly one level of the 2-D Haar wavelet transform.

A 4×44 \times 4 image of vertical stripes, x[m,n]=1x[m, n] = 1 when nn is even. The image does not depend on mm, so the column sum is ∑m(−i)km=4\sum_m(-i)^{km} = 4 if k=0k = 0 and 00 otherwise. Along a row, ∑n∈{0,2}(−i)ln=1+(−1)l\sum_{n\in\{0,2\}}(-i)^{ln} = 1 + (-1)^l, which is 22 for even ll and 00 for odd ll. So exactly two coefficients survive: X[0,0]=8X[0, 0] = 8 (the mean, times 16) and X[0,2]=8X[0, 2] = 8 (the stripes: two cycles across each row).

Check these, and any other 4×44 \times 4 pattern, below. Click pixels to change the image, click a coefficient to see the factor 11, −i-i, −1-1 or ii that each pixel is multiplied by.

Question 2

Which index is the “horizontal frequency”?

Answer

In NumPy’s fft2(x), axis 0 is rows, so the first index kk counts cycles going down the image (vertical frequency) and ll counts cycles going across (horizontal frequency). Vertical stripes therefore live at (0,l)(0, l). Because image rows run downward, a spectrum displayed as an image is upside down relative to a mathematics textbook’s (ξ,η)(\xi, \eta) plane, where η\eta points up. Neither is wrong; say which you use.

6. Reading an FFT output

The DFT returns NN numbers in an order that confuses everyone once.

reading an FFT output: N = 8 samples at fs = 8 Hzk = 00 Hzk = 11 Hzk = 22 Hzk = 33 Hzk = 4±4 Hzk = 5−3 Hzk = 6−2 Hzk = 7−1 HzX[k]DCpositiveNyquistnegativefftshift±4−3−2−10123bin spacing fs / N = 1 Hz; real input: X[N − k] = conj X[k], so the right half repeats the leftrfft keeps k = 0 … N/2: N/2 + 1 numbers
  • Bin kk is frequency kfs/Nk f_s/N for k<N/2k < N/2, and (k−N)fs/N(k - N)f_s/N for k>N/2k > N/2: the upper half holds the negative frequencies, because the DFT is periodic in kk with period NN.
  • Bin N/2N/2 (for even NN) is the Nyquist frequency, shared by +fs/2+f_s/2 and −fs/2-f_s/2; for real input it is real.
  • fftfreq(N, d=T) returns these frequencies; fftshift reorders the output so zero is in the middle (in 2-D, both axes).
  • Real input gives X[N−k]=X[k]‾X[N - k] = \overline{X[k]}, so half the output is redundant. rfft returns only k=0,…,N/2k = 0, \ldots, N/2, which is N/2+1N/2 + 1 numbers; rfft2 on an M×NM \times N image returns M×(N/2+1)M \times (N/2 + 1).
  • Resolution is fs/Nf_s/N: one over the duration of the record. More samples per second raise the Nyquist frequency; a longer record sharpens the frequency spacing.

7. Leakage and windows

Ask an FFT for the spectrum of a pure tone and it usually answers with every bin.

Proposition 5 (A tone between bins leaks into all of them)

For x[n]=e2πif0n/Nx[n] = e^{2\pi if_0n/N}, n=0,…,N−1n = 0, \ldots, N-1, with f0f_0 in cycles per record,

∣X[k]∣=∣sin⁡(π(f0−k))sin⁡(π(f0−k)/N)∣.\lvert X[k]\rvert = \left\lvert\frac{\sin\big(\pi(f_0 - k)\big)}{\sin\big(\pi(f_0 - k)/N\big)}\right\rvert .

If f0f_0 is a whole number this is NN at k=f0k = f_0 and 00 elsewhere. Otherwise it is non-zero at every kk, and falls off only like 1/∣f0−k∣1/\lvert f_0 - k\rvert.

Proof

Step 1. A geometric sum. X[k]=∑n=0N−1e2πi(f0−k)n/N=1−e2πi(f0−k)1−e2πi(f0−k)/NX[k] = \sum_{n=0}^{N-1}e^{2\pi i(f_0 - k)n/N} = \frac{1 - e^{2\pi i(f_0 - k)}}{1 - e^{2\pi i(f_0 - k)/N}} when the ratio is not 11.

Step 2. Factor half-angles. 1−e2iθ=−2i eiθsin⁡θ1 - e^{2i\theta} = -2i\,e^{i\theta}\sin\theta. Applied to the numerator (θ=π(f0−k)\theta = \pi(f_0 - k)) and the denominator (θ=π(f0−k)/N\theta = \pi(f_0 - k)/N), the magnitudes of the phase factors are 11, leaving the ratio of sines.

Step 3. Whole f0f_0. The numerator sin⁡(π(f0−k))\sin(\pi(f_0 - k)) vanishes for every integer kk; at k=f0k = f_0 the sum is simply NN terms equal to 11.

Step 4. Decay. For ∣f0−k∣≪N\lvert f_0 - k\rvert \ll N, sin⁡(π(f0−k)/N)≈π(f0−k)/N\sin(\pi(f_0 - k)/N) \approx \pi(f_0 - k)/N, so ∣X[k]∣≈N∣sin⁡π(f0−k)∣/(π∣f0−k∣)\lvert X[k]\rvert \approx N\lvert\sin\pi(f_0 - k)\rvert/(\pi\lvert f_0 - k\rvert).

Why? The DFT pretends the record repeats. A tone that does not fit a whole number of cycles into the record has a jump where the end meets the start, and Part 1 showed what a jump costs: slowly decaying coefficients. Two numbers measured on N=64N = 64: a cosine exactly on bin 10 lights 2 bins (bins 10 and 54, the negative frequency); a cosine at bin 10.5 lights all 64, and its peak drops to 0.650.65 of its true height (−3.8-3.8 dB, the “scalloping loss”).

Windows taper the record to zero at both ends, removing the jump. The Hann window, w[n]=12−12cos⁡(2πn/N)w[n] = \tfrac12 - \tfrac12\cos(2\pi n/N), is the clearest case: since cos⁡(2πn/N)=12(e2πin/N+e−2πin/N)\cos(2\pi n/N) = \tfrac12(e^{2\pi in/N} + e^{-2\pi in/N}) and multiplying by e±2πin/Ne^{\pm2\pi in/N} shifts a DFT by one bin, a windowed spectrum is 12X[k]−14X[k−1]−14X[k+1]\tfrac12X[k] - \tfrac14X[k - 1] - \tfrac14X[k + 1]. The leakage of neighbouring bins has alternating signs, and this combination cancels most of it. The cost is a wider main lobe. Measured on 64 samples with heavy zero-padding:

WindowMain lobe half-widthHighest side lobe
none (rectangular)1 bin−13.3 dB
Hann2 bins−31.5 dB
Blackman3 bins−58.1 dB

Question 3

Zero-padding a signal before the FFT gives more frequency bins. Does it give more resolution?

Answer

No. Padding NN samples with zeros to length PNPN returns the same DTFT X(ν)X(\nu) sampled PP times more densely: a smoother drawing of the same curve. What decides whether two tones can be told apart is the curve itself, whose main lobes are about 1/N1/N wide. Measured: two tones 0.70.7 bins apart in 64 samples (Hann window) show one peak with padding ×1\times1, ×4\times4 and ×16\times16, and two peaks when the record is four times longer. Padding is useful for locating a single peak precisely and for avoiding wrap-around in convolution, not for resolution.

The bright cross in image spectra

The same mechanism explains the bright ”+” through the centre of many image spectra. The 2-D DFT treats the image as a tile of a periodic wallpaper, so wherever the left edge differs from the right (or the top from the bottom) there is a jump along a whole border, and its slowly decaying energy lands on the axes. The standard remedy is to remove the jump without touching the image’s content: Moisan’s periodic plus smooth decomposition writes u=p+su = p + s, where ss is the smooth function (solving a discrete Laplace equation) that carries the border mismatch, and pp is periodic. In the DFT, s^[q,r]=v^[q,r]/(2cos⁡2πqM+2cos⁡2πrN−4)\hat s[q, r] = \hat v[q, r]/\big(2\cos\frac{2\pi q}{M} + 2\cos\frac{2\pi r}{N} - 4\big), where vv is zero except along the four borders, where it holds the difference between opposite edges.

The Eye sketch, its log spectrum with a bright cross along the axes, and the log spectrum of its periodic component, where the cross is much weaker.

But the cross is not always an artefact. Measuring the average power on the axes against the average power off them, at the same radii (16 to 120 cycles per image): for the Eye, whose borders differ, removing the border jump lowers the excess from 6.2× to 3.6×. For the Portrait it stays at 3.1×, because there the cross comes from genuine horizontal and vertical structure. Do not assume; decompose and compare.

8. The FFT

Computed directly, the DFT costs N2N^2 multiplications. The fast Fourier transform computes exactly the same numbers with about N2log⁡2N\frac N2\log_2N, by noticing that a DFT of even length is two DFTs of half the length.

Proposition 6 (Radix-2 decimation in time)

Let NN be even, and let E[k]E[k] and O[k]O[k] be the N/2N/2-point DFTs of the even-indexed and odd-indexed samples. Then for k=0,…,N/2−1k = 0, \ldots, N/2 - 1,

X[k]=E[k]+ωNk O[k],X[k+N/2]=E[k]−ωNk O[k].X[k] = E[k] + \omega_N^k\,O[k], \qquad X[k + N/2] = E[k] - \omega_N^k\,O[k].
Proof

Step 1. Split the sum by parity of nn: X[k]=∑m=0N/2−1x[2m] ωN2mk+∑m=0N/2−1x[2m+1] ωN(2m+1)kX[k] = \sum_{m=0}^{N/2-1}x[2m]\,\omega_N^{2mk} + \sum_{m=0}^{N/2-1}x[2m+1]\,\omega_N^{(2m+1)k}.

Step 2. Halve the root of unity. ωN2=e−4πi/N=ωN/2\omega_N^2 = e^{-4\pi i/N} = \omega_{N/2}. So the first sum is ∑mx[2m] ωN/2mk=E[k]\sum_m x[2m]\,\omega_{N/2}^{mk} = E[k] and the second is ωNk∑mx[2m+1] ωN/2mk=ωNkO[k]\omega_N^k\sum_m x[2m+1]\,\omega_{N/2}^{mk} = \omega_N^kO[k].

Step 3. The other half. EE and OO are periodic with period N/2N/2, and ωNk+N/2=ωNke−iπ=−ωNk\omega_N^{k + N/2} = \omega_N^ke^{-i\pi} = -\omega_N^k. Substituting k+N/2k + N/2 gives E[k]−ωNkO[k]E[k] - \omega_N^kO[k].

Proposition 7 (Cost)

If NN is a power of two, applying the split recursively uses C(N)=N2log⁡2NC(N) = \frac N2\log_2 N complex multiplications.

Proof

Step 1. Recurrence. One level does two half-size transforms and N/2N/2 multiplications by ωNk\omega_N^k (each product ωNkO[k]\omega_N^kO[k] is used twice): C(N)=2C(N/2)+N/2C(N) = 2C(N/2) + N/2, with C(1)=0C(1) = 0.

Step 2. Induction. If C(N/2)=N4log⁡2N2C(N/2) = \frac N4\log_2\frac N2, then C(N)=N2(log⁡2N−1)+N2=N2log⁡2NC(N) = \frac N2(\log_2N - 1) + \frac N2 = \frac N2\log_2N.

For N=220N = 2^{20}, about a million samples, that is about ten million multiplications instead of a trillion.

the FFT: three stages of butterflies (N = 8)x0X0x4X1x2X2x6X3x1X4x5X5x3X6x7X7w⁰w⁰w⁰w⁰w⁰w²w⁰w²w⁰w¹w²w³pairs 1 apartpairs 2 apartpairs 4 aparteach butterfly: (a, b) ↦ (a + wᵏ b, a − wᵏ b), with w = e^(−2πi/8); 3 stages × 4 butterflies = 12 multiplications, not 64
Example 4 (The 8-point box, through the butterflies)

Even samples (1,1,0,0)(1, 1, 0, 0), odd samples (1,1,0,0)(1, 1, 0, 0): the same, so E=O=(2, 1−i, 0, 1+i)E = O = (2,\ 1 - i,\ 0,\ 1 + i) (a 4-point DFT, by the rule of Section 4). Then X[1]=E[1]+ω8 O[1]=(1−i)(1+ω8)X[1] = E[1] + \omega_8\,O[1] = (1 - i)(1 + \omega_8) with ω8=1−i2\omega_8 = \frac{1 - i}{\sqrt2}: (1−i)+(1−i)22=1−i−2 i=1−2.414i(1 - i) + \frac{(1 - i)^2}{\sqrt2} = 1 - i - \sqrt2\,i = 1 - 2.414i, matching Section 4. And X[5]=E[1]−ω8O[1]=1−i+2 i=1+0.414iX[5] = E[1] - \omega_8O[1] = 1 - i + \sqrt2\,i = 1 + 0.414i.

Question 4

Is the FFT a different transform from the DFT?

Answer

No. It is an algorithm that computes the DFT exactly (up to round-off, which grows only like log⁡N\log N). Any difference between fft(x) and a direct N2N^2 sum is floating-point error.

How real libraries do it. Production FFTs (FFTW, pocketfft inside NumPy and SciPy, cuFFT on GPUs) are not limited to powers of two. Mixed-radix algorithms split NN into any factors, and Bluestein’s algorithm turns a prime length into a convolution of power-of-two length, so every NN costs O(Nlog⁡N)O(N\log N); but the constant depends on NN‘s factors. Measured with SciPy on my laptop: length 65,536=21665{,}536 = 2^{16} took 0.55 ms, the prime 65,53765{,}537 took 2.11 ms, and 65,610=2⋅38⋅565{,}610 = 2\cdot3^8\cdot5 (what scipy.fft.next_fast_len(65537) suggests) took 0.40 ms. Pad to a fast length when you can. FFT convolution beats direct convolution once the kernel is long enough: convolving 16,384 samples, the crossover on the same laptop fell between kernel lengths 64 and 128 (direct 0.15 ms vs FFT 0.18 ms at 64; 0.24 vs 0.17 ms at 128). CNN kernels are tiny, which is why deep-learning libraries mostly convolve directly.

9. The DCT, and why JPEG uses it

Section 7 showed that the DFT’s hidden periodic extension creates jumps at the borders. There is a cleaner way to make a finite signal periodic: reflect it. The mirrored sequence x[0],…,x[N−1],x[N−1],…,x[0]x[0], \ldots, x[N-1], x[N-1], \ldots, x[0] has no jump anywhere, only kinks, and by Part 1 its coefficients decay like 1/k21/k^2 instead of 1/k1/k.

Proposition 8 (The DCT is the DFT of the mirrored signal)

Let yy be the length-2N2N mirror extension of xx. Then its DFT is Y[k]=2eiπk/(2N) C[k]Y[k] = 2e^{i\pi k/(2N)}\,C[k] with the DCT-II

C[k]=∑n=0N−1x[n]cos⁡ ⁣(πk(n+12)N).C[k] = \sum_{n=0}^{N-1}x[n]\cos\!\Big(\frac{\pi k(n + \tfrac12)}{N}\Big).
Proof

Step 1. Pair each sample with its mirror image. y[n]=y[2N−1−n]=x[n]y[n] = y[2N - 1 - n] = x[n] for n<Nn < N, so Y[k]=∑n=0N−1x[n](e−2πikn/(2N)+e−2πik(2N−1−n)/(2N))Y[k] = \sum_{n=0}^{N-1}x[n]\big(e^{-2\pi ikn/(2N)} + e^{-2\pi ik(2N - 1 - n)/(2N)}\big).

Step 2. Simplify the second exponential. e−2πik(2N−1−n)/(2N)=e−2πik eiπk(n+1)/N=eiπk(n+1)/Ne^{-2\pi ik(2N - 1 - n)/(2N)} = e^{-2\pi ik}\,e^{i\pi k(n + 1)/N} = e^{i\pi k(n+1)/N}.

Step 3. Factor out half a step. e−iπkn/N+eiπk(n+1)/N=eiπk/(2N)(e−iπk(n+1/2)/N+eiπk(n+1/2)/N)=2eiπk/(2N)cos⁡(πk(n+12)/N)e^{-i\pi kn/N} + e^{i\pi k(n+1)/N} = e^{i\pi k/(2N)}\big(e^{-i\pi k(n + 1/2)/N} + e^{i\pi k(n + 1/2)/N}\big) = 2e^{i\pi k/(2N)}\cos\big(\pi k(n + \tfrac12)/N\big).

Measured on a ramp of 64 samples (the worst case for the DFT, since its two ends differ by the full range): coefficient size falls by a factor of about 2.3 to 2.9 each time kk triples for the DFT, roughly 1/k1/k, and by about 9 for the DCT, roughly 1/k21/k^2. The first four DCT coefficients hold 99.8% of the (mean-removed) energy; the first four DFT frequencies hold 86.8%. Energy compaction is the whole point of a compression transform: few large coefficients, many negligible ones.

JPEG, in five steps8 × 8 blockof pixelsDCT64 coefficientsquantisedivide, roundzig-zaglow to high freq.entropy codeto bitsthe only lossy stepthe DCT itself loses nothing; rounding the high frequencies hardest is where the saving,and at low quality the 8 × 8 blocks, come from

JPEG applies the 2-D DCT to each 8×88\times8 block, divides each coefficient by an entry of a quantisation table (large for high frequencies) and rounds. At low quality most high-frequency coefficients round to zero, and since each block is coded alone, the blocks stop agreeing at their borders.

A 64 by 64 crop of the Eye sketch: the original, and the same crop after JPEG compression at quality 8, where 8 by 8 blocks are clearly visible.

At quality 8 the whole 256×256256\times256 sketch compresses from 65,536 bytes to 1,939, with a peak signal-to-noise ratio of 28.1 dB, and the blocks are plain to see. JPEG 2000 replaced the blocks with a wavelet transform, which is one of the stories of Part 4.

10. The uncertainty principle

Part 1 showed that squeezing a function widens its transform. How far can both be narrow at once? Measure the spread of ∣f∣2\lvert f\rvert^2 and of ∣f^∣2\lvert\hat f\rvert^2 by their standard deviations.

Theorem 3 (Heisenberg–Gabor uncertainty principle)

Let ff be smooth and decaying with ∫∣f∣2=1\int\lvert f\rvert^2 = 1, and let σx2=∫(x−xˉ)2∣f(x)∣2dx\sigma_x^2 = \int(x - \bar x)^2\lvert f(x)\rvert^2dx, σξ2=∫(ξ−ξˉ)2∣f^(ξ)∣2dξ\sigma_\xi^2 = \int(\xi - \bar\xi)^2\lvert\hat f(\xi)\rvert^2d\xi, where xˉ\bar x, ξˉ\bar\xi are the means. Then

σx σξ  ≥  14π,\sigma_x\,\sigma_\xi \;\ge\; \frac{1}{4\pi},

with equality exactly for Gaussians f(x)=Ae−a(x−xˉ)2+2πiξˉxf(x) = Ae^{-a(x - \bar x)^2 + 2\pi i\bar\xi x}, a>0a > 0.

Proof

Step 1. Centre both. Replacing f(x)f(x) by e−2πiξˉxf(x+xˉ)e^{-2\pi i\bar\xi x}f(x + \bar x) changes neither spread (shift and modulation only move ∣f∣2\lvert f\rvert^2 and ∣f^∣2\lvert\hat f\rvert^2), so assume xˉ=ξˉ=0\bar x = \bar\xi = 0.

Step 2. Integrate 11 by parts. 1=∫∣f∣2dx=[x∣f∣2]−∞∞−∫x (∣f∣2)′dx=−∫x (∣f∣2)′dx1 = \int\lvert f\rvert^2dx = \big[x\lvert f\rvert^2\big]_{-\infty}^{\infty} - \int x\,(\lvert f\rvert^2)'dx = -\int x\,(\lvert f\rvert^2)'dx; the boundary term vanishes because ff decays.

Step 3. Differentiate ∣f∣2=ff‾\lvert f\rvert^2 = f\overline f. (ff‾)′=f′f‾+ff′‾=2Re⁡(f‾f′)(f\overline f)' = f'\overline f + f\overline{f'} = 2\operatorname{Re}(\overline f f'). So 1=−2Re⁡∫xf‾f′dx≤2∫∣xf∣ ∣f′∣ dx1 = -2\operatorname{Re}\int x\overline f f'dx \le 2\int\lvert xf\rvert\,\lvert f'\rvert\,dx.

Step 4. Cauchy–Schwarz. ∫∣xf∣∣f′∣≤(∫x2∣f∣2)1/2(∫∣f′∣2)1/2=σx∥f′∥\int\lvert xf\rvert\lvert f'\rvert \le \big(\int x^2\lvert f\rvert^2\big)^{1/2}\big(\int\lvert f'\rvert^2\big)^{1/2} = \sigma_x\lVert f'\rVert.

Step 5. Plancherel and the derivative rule. ∥f′∥2=∫∣2πiξf^(ξ)∣2dξ=4π2σξ2\lVert f'\rVert^2 = \int\lvert2\pi i\xi\hat f(\xi)\rvert^2d\xi = 4\pi^2\sigma_\xi^2, so ∥f′∥=2πσξ\lVert f'\rVert = 2\pi\sigma_\xi.

Step 6. Combine. 1≤2σx⋅2πσξ1 \le 2\sigma_x\cdot2\pi\sigma_\xi.

Step 7. Equality. Cauchy–Schwarz is tight only when f′=c xff' = c\,xf for a constant cc, and Step 3 is tight only when cc is real and negative. Solving f′=cxff' = cxf gives f=Aecx2/2f = Ae^{cx^2/2}, a Gaussian.

Measured: a Gaussian gives σxσξ=0.07958=1/(4π)\sigma_x\sigma_\xi = 0.07958 = 1/(4\pi) to five digits; e−∣x∣e^{-\lvert x\rvert} gives 0.11250.1125 and sech⁡x\operatorname{sech}x gives 0.08330.0833, both above the bound.

Question 5

Is this about measurement, as in quantum mechanics?

Answer

No. It is a theorem about a function and its Fourier transform, true before anyone measures anything. Quantum mechanics inherits it because a particle’s position and momentum wavefunctions are a Fourier pair. In signal processing it says something equally concrete: a pulse lasting 11 ms (as a standard deviation) cannot have a frequency spread below 1/(4π⋅0.001)≈801/(4\pi\cdot0.001) \approx 80 Hz, whatever the hardware.

The discrete world has its own version, with an elementary proof.

Theorem 4 (Discrete uncertainty principle (Donoho and Stark, 1989))

If x∈CN\boldsymbol{x} \in \mathbb{C}^N is non-zero with NtN_t non-zero entries and its DFT has NνN_\nu non-zero entries, then NtNν≥NN_tN_\nu \ge N.

Proof

Step 1. Bound one sample. By the inverse DFT and the triangle inequality, ∣x[n]∣≤1N∑k∣X[k]∣\lvert x[n]\rvert \le \frac1N\sum_k\lvert X[k]\rvert, a sum over the NνN_\nu non-zero X[k]X[k].

Step 2. Cauchy–Schwarz on that sum. ∑k∣X[k]∣≤Nν∥X∥=NνN∥x∥\sum_k\lvert X[k]\rvert \le \sqrt{N_\nu}\lVert\boldsymbol{X}\rVert = \sqrt{N_\nu}\sqrt N\lVert\boldsymbol{x}\rVert, using Parseval from Section 4.

Step 3. So every sample is small: ∣x[n]∣2≤NνN∥x∥2\lvert x[n]\rvert^2 \le \frac{N_\nu}{N}\lVert\boldsymbol{x}\rVert^2.

Step 4. Sum over the NtN_t non-zero samples. ∥x∥2≤NtNνN∥x∥2\lVert\boldsymbol{x}\rVert^2 \le N_t\frac{N_\nu}{N}\lVert\boldsymbol{x}\rVert^2; divide by ∥x∥2>0\lVert\boldsymbol{x}\rVert^2 > 0.

Equality holds for a comb: in N=16N = 16, a spike every 4 samples has 4 non-zero entries, and its DFT is again a comb with 4 (checked).

11. The short-time Fourier transform

Part 1 ended with a spectrum that knows what but not when. The obvious fix is to look through a window: multiply by a window ww centred at time τ\tau, take the Fourier transform, and slide.

Definition 3 (Short-time Fourier transform and spectrogram)

S(τ,ξ)=∫f(t) w(t−τ) e−2πiξt dt.S(\tau, \xi) = \int f(t)\,w(t - \tau)\,e^{-2\pi i\xi t}\,dt .

The spectrogram is ∣S(τ,ξ)∣2\lvert S(\tau, \xi)\rvert^2.

Proposition 9 (Inversion)

If ww is real with ∫w2=1\int w^2 = 1, then f(t)=∬S(τ,ξ) w(t−τ) e2πiξt dξ dτf(t) = \iint S(\tau, \xi)\,w(t - \tau)\,e^{2\pi i\xi t}\,d\xi\,d\tau.

Proof

Step 1. For fixed τ\tau, S(τ,⋅)S(\tau, \cdot) is the Fourier transform of gτ(t)=f(t)w(t−τ)g_\tau(t) = f(t)w(t - \tau), so by inversion ∫S(τ,ξ)e2πiξtdξ=f(t)w(t−τ)\int S(\tau, \xi)e^{2\pi i\xi t}d\xi = f(t)w(t - \tau).

Step 2. Multiply by w(t−τ)w(t - \tau) and integrate over τ\tau: f(t)∫w(t−τ)2dτ=f(t)f(t)\int w(t - \tau)^2d\tau = f(t).

(The discrete version is “overlap-add”: windows that sum to a constant when shifted by the hop, such as Hann at half-overlap, rebuild the signal exactly.)

window (samples, at 2048 per second)

This is the song of Part 1: a chord of two tones 16 Hz apart, a rising chirp, and a click. A window of LL samples sees about L/fsL/f_s seconds and separates frequencies about fs/Lf_s/L apart, and the product of the two is fixed. Measured with a peak count on the chord’s spectrum: windows of 32, 64 and 128 samples merge the two tones, 256 and 512 resolve them, and the longer the window, the more the click smears. This is the uncertainty principle at work, and no window escapes it. The tiles below show how three transforms divide the time–frequency plane.

Fourier analysis knows frequency exactly and time not at all. The short-time Fourier transform uses one tile shape for every frequency. Wavelets change the shape with frequency: short in time where frequencies are high, long where they are low.

A chord wants a long window; a click wants a short one; a chirp wants something in between that changes as it rises. One window for all frequencies is the STFT’s limit. Gabor (1946) chose the Gaussian window, which meets the uncertainty bound with equality, but even the best single window is a compromise. The obvious next step, letting the window shrink as the frequency grows, is the wavelet transform of Part 3.

12. Implementation and caveats

Each trap as symptom, cause and fix:

  • False patterns after resizing. Aliasing. Low-pass before subsampling (antialias=True; a Gaussian with σ ≈ d/2 for a factor d).
  • A pure tone appears in every bin. Leakage: the record is not a whole number of cycles. Use a window (Hann, Blackman) and accept the wider main lobe.
  • A weak tone is invisible next to a strong one. The rectangular window’s side lobes (−13 dB). Use a low-side-lobe window (Blackman, −58 dB; Blackman–Harris, about −92 dB).
  • Two close tones merge. The record is too short. Record longer; zero-padding does not help.
  • The start of a convolution is wrong. Circular wrap-around. Pad to L+M−1L + M - 1.
  • A bright cross in an image spectrum. Border jumps, or real structure. Use the periodic + smooth decomposition, then compare.
  • An FFT that is oddly slow. An awkward length (a prime, say). Pad to scipy.fft.next_fast_len(n).
  • Twice the time and memory on real data. A complex FFT of real input. Use rfft, rfft2.
  • Features that change when the input moves by a pixel. Strided layers alias. Blur before the stride (BlurPool), or design alias-free.
import numpy as np
from scipy import fft, signal

fs, N = 1000.0, 1000
t = np.arange(N) / fs
x = np.cos(2 * np.pi * 50.5 * t) + 1e-3 * np.cos(2 * np.pi * 80 * t)   # a weak tone 60 dB down
X_rect = np.abs(fft.rfft(x))                                        # no window: leakage buries the weak tone
X_bh = np.abs(fft.rfft(x * signal.windows.blackmanharris(N)))      # side lobes near -92 dB: it shows
f = fft.rfftfreq(N, d=1 / fs)                                       # bin frequencies, 1 Hz apart
# measured at 80 Hz: no window, 1.3 dB *below* the neighbouring leakage; Blackman-Harris, 14 dB above it

13. Where it is used, and what is open

Use the discrete Fourier toolkit whenBe careful when
filtering or convolving long signals, images or volumesthe signal is not periodic and you have not windowed or mirrored
measuring periodicities, vibrations, spectrathe record is short relative to the frequencies you need to separate
resampling, after a proper low-passyou subsample without one
compressing smooth data (DCT)the data has many edges (blocks; Part 4 does better)

In current work. Anti-aliased and alias-free networks (BlurPool, StyleGAN3, alias-free U-Nets and neural operators); FFT-based global filtering and long convolutions in vision and sequence models; spectrograms and learned filterbanks as inputs to audio models; compressed sensing and accelerated MRI, which sample below the Nyquist rate and recover the rest from a prior; non-uniform FFTs for radio astronomy, MRI with spiral trajectories, and point-cloud learning.

Open questions.

  1. Alias-free at low cost. Exact shift-equivariance needs ideal low-pass filters, and every nonlinearity creates new high frequencies that must be filtered again (Karras et al., 2021). What is the cheapest architecture with a provable bound on aliasing?
  2. Sampling below Nyquist with learned priors. Compressed sensing has sharp guarantees for sparse signals (Candès, Romberg and Tao, 2006); with generative priors (Bora et al., 2017) the guarantees are partial. When do they hold, and how should failure be detected?
  3. Irregular samples. Point clouds, sensor networks and unstructured meshes are not on grids. Fast, accurate and differentiable transforms exist (the non-uniform FFT), but how best to build learning layers on them is unsettled.
  4. Learned versus fixed front ends. Learnable filterbanks sometimes beat fixed spectrograms and sometimes do not. Which properties of a fixed transform (stability, invertibility, the uncertainty trade-off) should a learned one be forced to keep?
Note (Shoulders to stand on)

Self-check

Question 6

A 60 Hz mains hum is recorded at 100 samples per second. At what frequency does it appear?

Answer

60−100=−4060 - 100 = -40: it appears at 40 Hz (Section 2), a frequency nobody played.

Question 7

You convolve a signal of length 1000 with a filter of length 100 using FFTs. What is the smallest transform length that gives the linear convolution, and what would you actually use?

Answer

At least 1000+100−1=10991000 + 100 - 1 = 1099, or the result wraps around (Section 4). In practice a fast length at or above it: scipy.fft.next_fast_len(1099) returns 1100.

Question 8

You zero-pad 64 samples to 1024 before the FFT. What improves, and what does not?

Answer

The spectrum is drawn on a 16 times finer grid, so a single peak can be located more precisely and the plot looks smooth. The ability to separate two close frequencies does not change; it is set by the 64-sample record (Section 7).

Question 9

Prove that the DFT of a real signal satisfies X[N−k]=X[k]‾X[N - k] = \overline{X[k]}.

Answer

X[N−k]=∑nx[n] ωN(N−k)n=∑nx[n] ωN−knX[N - k] = \sum_nx[n]\,\omega_N^{(N - k)n} = \sum_nx[n]\,\omega_N^{-kn} because ωNNn=1\omega_N^{Nn} = 1. Since x[n]x[n] is real and ωN−kn=ωNkn‾\omega_N^{-kn} = \overline{\omega_N^{kn}}, this is ∑nx[n]ωNkn‾=X[k]‾\overline{\sum_nx[n]\omega_N^{kn}} = \overline{X[k]}.

Question 10

A Gaussian pulse has a time spread σt=1\sigma_t = 1 ms. What is the smallest possible frequency spread, and which pulses reach it?

Answer

σξ≥1/(4πσt)≈80\sigma_\xi \ge 1/(4\pi\sigma_t) \approx 80 Hz; only Gaussians (possibly shifted and modulated) reach it (Section 10).

Question 11

Why does a JPEG at low quality show blocks, and why can the DCT not be blamed?

Answer

The DCT is invertible: on its own it loses nothing. The loss is in rounding the coefficients, which JPEG does independently in every 8×88\times8 block, so neighbouring blocks no longer agree along their shared edges (Section 9).

References

  • C. E. Shannon. Communication in the presence of noise. Proceedings of the IRE 37(1), 1949.
  • J. W. Cooley, J. W. Tukey. An algorithm for the machine calculation of complex Fourier series. Mathematics of Computation 19, 1965.
  • F. J. Harris. On the use of windows for harmonic analysis with the discrete Fourier transform. Proceedings of the IEEE 66(1), 1978.
  • L. Moisan. Periodic plus smooth image decomposition. Journal of Mathematical Imaging and Vision 39(2), 2011.
  • G. K. Wallace. The JPEG still picture compression standard. Communications of the ACM 34(4), 1991.
  • D. Gabor. Theory of communication. Journal of the IEE 93, 1946.
  • D. L. Donoho, P. B. Stark. Uncertainty principles and signal recovery. SIAM Journal on Applied Mathematics 49(3), 1989.
  • A. Azulay, Y. Weiss. Why do deep convolutional networks generalize so poorly to small image transformations? JMLR 20, 2019.
  • R. Zhang. Making convolutional networks shift-invariant again. ICML, 2019.
  • T. Karras et al. Alias-free generative adversarial networks. NeurIPS, 2021.
  • E. J. Candès, J. Romberg, T. Tao. Robust uncertainty principles: exact signal reconstruction from highly incomplete frequency information. IEEE Transactions on Information Theory 52(2), 2006.
  • A. Bora, A. Jalal, E. Price, A. G. Dimakis. Compressed sensing using generative models. ICML, 2017.
  • M. Frigo, S. G. Johnson. The design and implementation of FFTW3. Proceedings of the IEEE 93(2), 2005.
  • A. Torralba, P. Isola, W. T. Freeman. Foundations of Computer Vision. MIT Press, 2024.