4.10.26Advanced Topics (Elite Level)

Fourier analysis — DFT, FFT algorithm (Cooley-Tukey)

1,920 words9 min readdifficulty · medium3 backlinks

1. The Discrete Fourier Transform (DFT)

WHY this formula? (Derivation from first principles)

WHAT we want: write xnx_n as a combination of the simplest periodic functions on NN points — the complex exponentials e2πikn/Ne^{2\pi i k n /N}, one per integer frequency kk.

Step 1 — Propose the basis. Define vectors e(k)\mathbf{e}^{(k)} with components en(k)=e2πikn/Ne^{(k)}_n = e^{2\pi i kn/N}.

Why this step? On a discrete grid of NN points, only NN distinct frequencies exist (frequency kk and k+Nk+N give the same samples since e2πi(k+N)n/N=e2πikn/Ne^{2\pi i (k+N)n/N}=e^{2\pi i kn/N}). So we need exactly NN basis vectors.

Step 2 — Show they are orthogonal. Compute the inner product (with conjugate): e(k),e(j)=n=0N1e2πikn/Ne2πijn/N=n=0N1(e2πi(kj)/N)n.\langle \mathbf{e}^{(k)},\mathbf{e}^{(j)}\rangle = \sum_{n=0}^{N-1} e^{2\pi i kn/N}\,e^{-2\pi i jn/N}=\sum_{n=0}^{N-1} \big(e^{2\pi i(k-j)/N}\big)^n. This is a geometric series with ratio r=e2πi(kj)/Nr=e^{2\pi i(k-j)/N}.

Why this step? Orthogonality means we can extract each coefficient independently — no solving a linear system.

  • If k=jk=j: every term is 11, sum =N=N.
  • If kjk\ne j: r1r\ne 1 but rN=e2πi(kj)=1r^N = e^{2\pi i(k-j)}=1, so nrn=rN1r1=0\sum_{n} r^n = \dfrac{r^N-1}{r-1}=0.

Thus e(k),e(j)=Nδkj\langle \mathbf{e}^{(k)},\mathbf{e}^{(j)}\rangle = N\,\delta_{kj}.

Step 3 — Project. Write xn=1NkXke2πikn/Nx_n=\frac1N\sum_k X_k\, e^{2\pi i kn/N} (inverse). Taking the inner product with e(k)\mathbf e^{(k)} and using orthogonality kills all but one term, giving Xk=n=0N1xne2πikn/N=nxnωNnk.X_k=\sum_{n=0}^{N-1} x_n\, e^{-2\pi i kn/N}=\sum_n x_n\,\omega_N^{nk}. That is the DFT. The minus sign appears because we conjugate when projecting.


2. Cost of the naïve DFT

Each XkX_k is a sum of NN products; there are NN outputs \Rightarrow N2N^2 complex multiplications. For N=106N=10^6 that's 101210^{12} ops — too slow. The FFT fixes this.


3. The FFT — Cooley–Tukey (radix-2)

Assume NN is even (radix-2 needs N=2mN=2^m). Split: Xk=n evenxnωNnk+n oddxnωNnk.X_k=\sum_{n\text{ even}} x_n\omega_N^{nk}+\sum_{n\text{ odd}} x_n\omega_N^{nk}. Let n=2mn=2m (even) and n=2m+1n=2m+1 (odd), m=0,,N/21m=0,\dots,N/2-1: Xk=mx2mωN2mk+ωNkmx2m+1ωN2mk.X_k=\sum_{m} x_{2m}\,\omega_N^{2mk}+\omega_N^{k}\sum_m x_{2m+1}\,\omega_N^{2mk}.

Key identity: ωN2=e4πi/N=e2πi/(N/2)=ωN/2\omega_N^{2}=e^{-4\pi i/N}=e^{-2\pi i/(N/2)}=\omega_{N/2}.

Why this matters: ωN2mk=ωN/2mk\omega_N^{2mk}=\omega_{N/2}^{mk}, so each inner sum is exactly a DFT of length N/2N/2:   Xk=Ek+ωNkOk  \boxed{\;X_k = E_k + \omega_N^{k}\,O_k\;} where Ek=DFTN/2(even part)E_k=\text{DFT}_{N/2}(\text{even part}), Ok=DFTN/2(odd part)O_k=\text{DFT}_{N/2}(\text{odd part}).

The free second half (the symmetry that gives the speedup): EkE_k and OkO_k are periodic with period N/2N/2, and ωNk+N/2=ωNN/2ωNk=ωNk\omega_N^{k+N/2}=\omega_N^{N/2}\omega_N^k=-\omega_N^k. Therefore: Xk=Ek+ωNkOk,Xk+N/2=EkωNkOk,k=0,,N21.X_{k} = E_k + \omega_N^k O_k,\qquad X_{k+N/2}=E_k - \omega_N^k O_k,\quad k=0,\dots,\tfrac N2-1.

Figure — Fourier analysis — DFT, FFT algorithm (Cooley-Tukey)

Complexity (derive it)

Let T(N)T(N) = work to do an NN-point FFT. We do two half-size FFTs plus N/2N/2 butterflies (O(N)O(N) combine): T(N)=2T(N/2)+cN.T(N)=2\,T(N/2)+cN. By the Master Theorem (or unrolling log2N\log_2 N levels, each costing cNcN): T(N)=O(Nlog2N).T(N)=O(N\log_2 N). Why logN\log N levels? Halving NN repeatedly until size 1 takes log2N\log_2 N steps; each full level touches all NN values once.


4. Worked examples


5. Common mistakes (Steel-manned)


6. Active recall

Recall Flashcards

#flashcards/maths DFT formula for XkX_k? ::: Xk=n=0N1xnωNnkX_k=\sum_{n=0}^{N-1}x_n\,\omega_N^{nk} with ωN=e2πi/N\omega_N=e^{-2\pi i/N}. Why are the DFT basis vectors usable independently? ::: They are orthogonal: e(k),e(j)=Nδkj\langle e^{(k)},e^{(j)}\rangle=N\delta_{kj} (geometric-series argument). Why does the kjk\ne j inner product vanish? ::: Geometric series with ratio r1r\ne1 but rN=1r^N=1, so (rN1)/(r1)=0(r^N-1)/(r-1)=0. Cooley–Tukey split — what two sub-DFTs appear? ::: Length-N/2N/2 DFTs of the even-indexed and odd-indexed samples, EkE_k and OkO_k. Key identity that makes sub-sums into half-size DFTs? ::: ωN2=ωN/2\omega_N^2=\omega_{N/2}. The butterfly equations? ::: Xk=Ek+ωNkOkX_k=E_k+\omega_N^kO_k and Xk+N/2=EkωNkOkX_{k+N/2}=E_k-\omega_N^kO_k. Why does Xk+N/2X_{k+N/2} come almost free? ::: ωNk+N/2=ωNk\omega_N^{k+N/2}=-\omega_N^k, so only a sign flips. FFT recurrence and its solution? ::: T(N)=2T(N/2)+cNO(Nlog2N)T(N)=2T(N/2)+cN\Rightarrow O(N\log_2 N). Speedup factor over naïve DFT? ::: N/log2NN/\log_2 N. For real input, relation between XkX_k and XNkX_{N-k}? ::: XNk=XkX_{N-k}=\overline{X_k} (conjugate symmetry). Why the 1/N1/N in the IDFT? ::: Basis vectors have squared norm NN; normalization undoes it.

Recall Feynman: explain to a 12-year-old

Imagine you record a chord on a piano as a wiggly line. The DFT is a machine that listens and tells you "this much C, this much E, this much G." Doing it the slow way is like checking every note against every moment of the recording — tons of checking. The FFT is a smart shortcut: it splits the recording into "even moments" and "odd moments," figures out each smaller piece, then glues them back with one quick twist each. Splitting again and again means way less work — and that's how your phone shows music bars dancing in real time.


7. Connections

  • Roots of UnityωN\omega_N and the cyclic structure powering the DFT.
  • Geometric Series — proves basis orthogonality.
  • Linear Algebra — Orthogonal Bases — DFT is a change of basis by a unitary (Fourier) matrix.
  • Divide and Conquer Algorithms — same recurrence as merge sort.
  • Master Theorem — solves T(N)=2T(N/2)+cNT(N)=2T(N/2)+cN.
  • Convolution Theorem — FFT makes polynomial/integer multiplication O(NlogN)O(N\log N).
  • Continuous Fourier Transform — the integral limit of the DFT.
  • Sampling & Aliasing (Nyquist) — why kk wraps to negative frequencies.

Concept Map

expanded in

are orthogonal

geometric series

defines

projection gives

inverted by

needs

naive cost

too slow

same result as

split even and odd

recombine via symmetry

enables

Sampled signal

Complex exponential basis

Orthogonality N delta

Nth root of unity omega N

DFT coefficients X k

Inverse DFT with 1 over N

Normalization from norm N

O of N squared ops

FFT Cooley-Tukey

Two half-size DFTs

O of N log N

Audio JPEG MP3 MRI

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, DFT ka matlab simple hai: tumhare paas NN samples hain (jaise sound ya signal), aur tum jaanna chahte ho ki usme kaun kaun si frequencies kitni hain. Iske liye hum signal ko pure rotating waves (e2πikn/Ne^{-2\pi i kn/N}) ke combination me todte hain. Har wave alag frequency kk ki hoti hai, aur formula Xk=nxnωNnkX_k=\sum_n x_n\,\omega_N^{nk} bas yeh "kitna" measure karta hai. Yeh waves orthogonal hoti hain (geometric series se prove hota hai), isiliye har coefficient alag se nikal aata hai — koi bada equation solve nahi karna padta.

Ab problem yeh hai ki naive tareeke se yeh N2N^2 operations leta hai, jo bade NN ke liye bahut slow hai. Yahin pe FFT (Cooley–Tukey) ka jaadu aata hai. Idea: samples ko even index aur odd index me baant do. Dono halves khud apne aap me chhoti DFT (N/2N/2 size) ban jaate hain — kyunki ek mast identity hai, ωN2=ωN/2\omega_N^2=\omega_{N/2}. Phir dono ko jodne ke liye butterfly use karte hain: Xk=Ek+ωNkOkX_k=E_k+\omega_N^k O_k aur Xk+N/2=EkωNkOkX_{k+N/2}=E_k-\omega_N^k O_k. Dhyaan do — neeche wala output bas sign flip se mil gaya, free me! Ek multiply me do output.

Yeh splitting baar baar karte raho, toh log2N\log_2 N levels banti hain, har level NN work, total O(NlogN)O(N\log N). N=220N=2^{20} pe yeh lagbhag 50,000 guna fast hai naive se. Isiliye MP3, JPEG, MRI, mobile audio bars — sab FFT pe chalte hain.

Ek common galti: log sochte hain FFT aur DFT alag-alag answer dete hain. Nahi! FFT bas DFT ka fast algorithm hai, answer bilkul same. Aur radix-2 FFT ke liye NN ka power-of-2 hona zaroori hai, warna mixed-radix ya Bluestein lagta hai. Inverse karte waqt 1/N1/N lagana mat bhoolna, warna scale bigad jaata hai.

Go deeper — visual, from zero

Test yourself — Advanced Topics (Elite Level)

Connections