|
| 1 | +\documentclass{beamer} |
| 2 | +\usepackage{amsmath} |
| 3 | +\usepackage{amssymb} |
| 4 | +\usepackage{graphicx} |
| 5 | +\usepackage{algorithm,algorithmic} |
| 6 | +\usepackage{listings} |
| 7 | +\usepackage{color} |
| 8 | + |
| 9 | +\definecolor{codegreen}{rgb}{0,0.6,0} |
| 10 | +\definecolor{codegray}{rgb}{0.5,0.5,0.5} |
| 11 | +\definecolor{codepurple}{rgb}{0.58,0,0.82} |
| 12 | +\definecolor{backcolour}{rgb}{0.95,0.95,0.92} |
| 13 | + |
| 14 | +\lstset{ |
| 15 | + backgroundcolor=\color{backcolour}, |
| 16 | + commentstyle=\color{codegreen}, |
| 17 | + keywordstyle=\color{magenta}, |
| 18 | + numberstyle=\tiny\color{codegray}, |
| 19 | + stringstyle=\color{codepurple}, |
| 20 | + basicstyle=\footnotesize\ttfamily, |
| 21 | + breakatwhitespace=false, |
| 22 | + breaklines=true, |
| 23 | + captionpos=b, |
| 24 | + keepspaces=true, |
| 25 | + numbers=left, |
| 26 | + numbersep=5pt, |
| 27 | + showspaces=false, |
| 28 | + showstringspaces=false, |
| 29 | + showtabs=false, |
| 30 | + tabsize=2, |
| 31 | + language=Python |
| 32 | +} |
| 33 | + |
| 34 | +\title{Fast Fourier Transform (FFT) Algorithm} |
| 35 | +\author{Morten HJ} |
| 36 | +\date{Old notes from Comp Phys on FFT} |
| 37 | + |
| 38 | +\usetheme{Madrid} |
| 39 | + |
| 40 | +\begin{document} |
| 41 | + |
| 42 | +\frame{\titlepage} |
| 43 | + |
| 44 | +\section{Introduction} |
| 45 | + |
| 46 | +\begin{frame}{Motivation} |
| 47 | + \begin{itemize} |
| 48 | + \item The Fourier Transform is a fundamental tool in signal processing, physics, engineering, and applied mathematics |
| 49 | + \item Direct computation of the Discrete Fourier Transform (DFT) is computationally expensive: $O(N^2)$ |
| 50 | + \item The Fast Fourier Transform (FFT) reduces this to $O(N \log N)$ |
| 51 | + \item Applications include: |
| 52 | + \begin{itemize} |
| 53 | + \item Signal processing (audio, image, video) |
| 54 | + \item Solving partial differential equations |
| 55 | + \item Polynomial multiplication |
| 56 | + \item Data compression |
| 57 | + \item Spectral analysis |
| 58 | + \end{itemize} |
| 59 | + \end{itemize} |
| 60 | +\end{frame} |
| 61 | + |
| 62 | +\begin{frame}{Historical Context} |
| 63 | + \begin{itemize} |
| 64 | + \item First discovered by Gauss in 1805 (unpublished) for calculating asteroid orbits |
| 65 | + \item Rediscovered by Cooley and Tukey in 1965 |
| 66 | + \item Popularized with the advent of digital computers |
| 67 | + \item One of the most important numerical algorithms of the 20th century |
| 68 | + \end{itemize} |
| 69 | +\end{frame} |
| 70 | + |
| 71 | +\section{Mathematical Foundations} |
| 72 | + |
| 73 | +\begin{frame}{Discrete Fourier Transform (DFT)} |
| 74 | + The DFT of a sequence $x[n]$ of length $N$ is defined as: |
| 75 | + \[ X[k] = \sum_{n=0}^{N-1} x[n] e^{-j 2\pi k n / N}, \quad k = 0,1,\ldots,N-1 \] |
| 76 | + where: |
| 77 | + \begin{itemize} |
| 78 | + \item $x[n]$ is the input sequence (time domain) |
| 79 | + \item $X[k]$ is the output sequence (frequency domain) |
| 80 | + \item $N$ is the number of samples |
| 81 | + \item $j = \sqrt{-1}$ is the imaginary unit |
| 82 | + \end{itemize} |
| 83 | +\end{frame} |
| 84 | + |
| 85 | +\begin{frame}{Inverse DFT} |
| 86 | + The inverse transform is given by: |
| 87 | + \[ x[n] = \frac{1}{N} \sum_{k=0}^{N-1} X[k] e^{j 2\pi k n / N}, \quad n = 0,1,\ldots,N-1 \] |
| 88 | + \begin{block}{Key Properties} |
| 89 | + \begin{itemize} |
| 90 | + \item Linearity: $a x_1[n] + b x_2[n] \leftrightarrow a X_1[k] + b X_2[k]$ |
| 91 | + \item Periodicity: $X[k+N] = X[k]$ |
| 92 | + \item Symmetry: For real $x[n]$, $X[N-k] = X^*[k]$ |
| 93 | + \item Convolution: Multiplication in one domain equals convolution in the other |
| 94 | + \end{itemize} |
| 95 | + \end{block} |
| 96 | +\end{frame} |
| 97 | + |
| 98 | +\section{FFT Algorithm} |
| 99 | + |
| 100 | +\begin{frame}{FFT Basic Idea} |
| 101 | + \begin{itemize} |
| 102 | + \item Exploits symmetry and periodicity of the complex exponential |
| 103 | + \item Decimates the DFT computation into smaller DFTs |
| 104 | + \item Most common approach: Cooley-Tukey algorithm (radix-2) |
| 105 | + \item Requires $N$ to be a power of 2 (can be generalized) |
| 106 | + \end{itemize} |
| 107 | + \begin{center} |
| 108 | +% \includegraphics[width=0.5\textwidth]{butterfly.png} |
| 109 | + \end{center} |
| 110 | +\end{frame} |
| 111 | + |
| 112 | +\begin{frame}{Divide and Conquer Approach} |
| 113 | + Split the DFT sum into even and odd terms: |
| 114 | + \begin{align*} |
| 115 | + X[k] &= \sum_{n=0}^{N-1} x[n] W_N^{kn} \\ |
| 116 | + &= \sum_{m=0}^{N/2-1} x[2m] W_N^{k(2m)} + \sum_{m=0}^{N/2-1} x[2m+1] W_N^{k(2m+1)} \\ |
| 117 | + &= \sum_{m=0}^{N/2-1} x_{\text{even}}[m] W_{N/2}^{km} + W_N^k \sum_{m=0}^{N/2-1} x_{\text{odd}}[m] W_{N/2}^{km} \\ |
| 118 | + &= E[k] + W_N^k O[k] |
| 119 | + \end{align*} |
| 120 | + where $W_N = e^{-j 2\pi/N}$ is the twiddle factor. |
| 121 | +\end{frame} |
| 122 | + |
| 123 | +\begin{frame}{Recursive Structure} |
| 124 | + \begin{itemize} |
| 125 | + \item The DFT of size $N$ is decomposed into: |
| 126 | + \begin{itemize} |
| 127 | + \item Two DFTs of size $N/2$ (even and odd terms) |
| 128 | + \item $O(N)$ complex multiplications and additions |
| 129 | + \end{itemize} |
| 130 | + \item Applying this recursively gives $O(N \log N)$ complexity |
| 131 | + \end{itemize} |
| 132 | + \begin{center} |
| 133 | +% \includegraphics[width=0.7\textwidth]{fft_recursion.png} |
| 134 | + \end{center} |
| 135 | +\end{frame} |
| 136 | + |
| 137 | +\begin{frame}{Butterfly Operation} |
| 138 | + The basic computational unit of the FFT: |
| 139 | + \begin{center} |
| 140 | +% \includegraphics[width=0.5\textwidth]{butterfly_diagram.png} |
| 141 | + \end{center} |
| 142 | + Mathematically: |
| 143 | + \begin{align*} |
| 144 | + X[m] &= E[m] + W_N^m O[m] \\ |
| 145 | + X[m+N/2] &= E[m] - W_N^m O[m] |
| 146 | + \end{align*} |
| 147 | +\end{frame} |
| 148 | + |
| 149 | +\section{Implementation} |
| 150 | + |
| 151 | +\begin{frame}{Pseudocode for Radix-2 FFT} |
| 152 | + \begin{algorithm}[H] |
| 153 | + \begin{algorithmic}[1] |
| 154 | + \REQUIRE $N$ is a power of 2, $x$ is input array of size $N$ |
| 155 | + \IF{$N == 1$} |
| 156 | + \RETURN $x$ |
| 157 | + \ENDIF |
| 158 | + \STATE $x_{\text{even}} \gets [x[0], x[2], \ldots, x[N-2]]$ |
| 159 | + \STATE $x_{\text{odd}} \gets [x[1], x[3], \ldots, x[N-1]]$ |
| 160 | + \STATE $E \gets \text{FFT}(x_{\text{even}})$ |
| 161 | + \STATE $O \gets \text{FFT}(x_{\text{odd}})$ |
| 162 | + \STATE $W_N \gets e^{-2\pi j / N}$ |
| 163 | + \STATE $W \gets 1$ |
| 164 | + \FOR{$k = 0$ to $N/2 - 1$} |
| 165 | + \STATE $X[k] \gets E[k] + W \cdot O[k]$ |
| 166 | + \STATE $X[k + N/2] \gets E[k] - W \cdot O[k]$ |
| 167 | + \STATE $W \gets W \cdot W_N$ |
| 168 | + \ENDFOR |
| 169 | + \RETURN $X$ |
| 170 | + \end{algorithmic} |
| 171 | + \caption{Recursive Radix-2 FFT} |
| 172 | + \end{algorithm} |
| 173 | +\end{frame} |
| 174 | + |
| 175 | +\begin{frame}[fragile]{Python Implementation} |
| 176 | + \begin{lstlisting} |
| 177 | + import numpy as np |
| 178 | + |
| 179 | + def fft(x): |
| 180 | + N = len(x) |
| 181 | + if N == 1: |
| 182 | + return x |
| 183 | + even = fft(x[::2]) |
| 184 | + odd = fft(x[1::2]) |
| 185 | + T = [np.exp(-2j * np.pi * k / N) * odd[k] |
| 186 | + for k in range(N // 2)] |
| 187 | + return [even[k] + T[k] for k in range(N // 2)] + \ |
| 188 | + [even[k] - T[k] for k in range(N // 2)] |
| 189 | + \end{lstlisting} |
| 190 | +\end{frame} |
| 191 | + |
| 192 | +\begin{frame}{Iterative Implementation} |
| 193 | + \begin{itemize} |
| 194 | + \item Recursive implementation has overhead |
| 195 | + \item More efficient: iterative version with bit-reversal permutation |
| 196 | + \item Three main steps: |
| 197 | + \begin{enumerate} |
| 198 | + \item Bit-reverse the input array |
| 199 | + \item Perform butterfly operations at each level |
| 200 | + \item Combine results |
| 201 | + \end{enumerate} |
| 202 | + \end{itemize} |
| 203 | +\end{frame} |
| 204 | + |
| 205 | +\section{Complexity Analysis} |
| 206 | + |
| 207 | +\begin{frame}{Computational Complexity} |
| 208 | + \begin{itemize} |
| 209 | + \item Let $N = 2^m$ |
| 210 | + \item At each level $k$ ($k = 1$ to $m$): |
| 211 | + \begin{itemize} |
| 212 | + \item $2^{k-1}$ butterfly operations |
| 213 | + \item Each butterfly has 1 complex multiplication and 2 additions |
| 214 | + \item Total operations per level: $N/2$ butterflies $\times$ 3 operations |
| 215 | + \end{itemize} |
| 216 | + \item Total levels: $\log_2 N$ |
| 217 | + \item Total operations: $\frac{3}{2} N \log_2 N$ |
| 218 | + \item Thus, complexity is $O(N \log N)$ vs. $O(N^2)$ for DFT |
| 219 | + \end{itemize} |
| 220 | +\end{frame} |
| 221 | + |
| 222 | +\begin{frame}{Comparison with Direct Computation} |
| 223 | + For $N = 1024$: |
| 224 | + \begin{itemize} |
| 225 | + \item Direct DFT: $N^2 = 1,048,576$ complex multiplications |
| 226 | + \item FFT: $\frac{N}{2} \log_2 N = 5120$ complex multiplications |
| 227 | + \item Speedup factor: ~205 times |
| 228 | + \end{itemize} |
| 229 | + \begin{center} |
| 230 | + \begin{tabular}{|c|c|c|} |
| 231 | + \hline |
| 232 | + $N$ & DFT Operations & FFT Operations \\ |
| 233 | + \hline |
| 234 | + 32 & 1,024 & 80 \\ |
| 235 | + 64 & 4,096 & 192 \\ |
| 236 | + 128 & 16,384 & 448 \\ |
| 237 | + 256 & 65,536 & 1,024 \\ |
| 238 | + 512 & 262,144 & 2,304 \\ |
| 239 | + 1024 & 1,048,576 & 5,120 \\ |
| 240 | + \hline |
| 241 | + \end{tabular} |
| 242 | + \end{center} |
| 243 | +\end{frame} |
| 244 | + |
| 245 | +\section{Variations and Extensions} |
| 246 | + |
| 247 | +\begin{frame}{Different FFT Algorithms} |
| 248 | + \begin{itemize} |
| 249 | + \item \textbf{Radix-2}: Most common, requires $N$ power of 2 |
| 250 | + \item \textbf{Radix-4}: More efficient for certain architectures |
| 251 | + \item \textbf{Mixed-radix}: For arbitrary $N$ (prime factor algorithm) |
| 252 | + \item \textbf{Bluestein's algorithm}: For arbitrary $N$ (Chirp-Z transform) |
| 253 | + \item \textbf{Winograd FFT}: Minimizes multiplications |
| 254 | + \end{itemize} |
| 255 | +\end{frame} |
| 256 | + |
| 257 | +\begin{frame}{Multidimensional FFT} |
| 258 | + \begin{itemize} |
| 259 | + \item Separable transform: Apply 1D FFT along each dimension |
| 260 | + \item For 2D image of size $M \times N$: |
| 261 | + \[ X[k,l] = \sum_{m=0}^{M-1} \sum_{n=0}^{N-1} x[m,n] e^{-j2\pi (km/M + ln/N)} \] |
| 262 | + \item Computed as: |
| 263 | + \begin{enumerate} |
| 264 | + \item Apply 1D FFT to each row ($M \times O(N \log N)$) |
| 265 | + \item Apply 1D FFT to each column ($N \times O(M \log M)$) |
| 266 | + \end{enumerate} |
| 267 | + \item Total complexity: $O(MN \log MN)$ |
| 268 | + \end{itemize} |
| 269 | +\end{frame} |
| 270 | + |
| 271 | +\section{Applications} |
| 272 | + |
| 273 | +\begin{frame}{Practical Applications} |
| 274 | + \begin{itemize} |
| 275 | + \item \textbf{Signal Processing}: |
| 276 | + \begin{itemize} |
| 277 | + \item Filtering (convolution via multiplication in frequency domain) |
| 278 | + \item Spectral analysis |
| 279 | + \item Audio compression (MP3, AAC) |
| 280 | + \end{itemize} |
| 281 | + \item \textbf{Image Processing}: |
| 282 | + \begin{itemize} |
| 283 | + \item JPEG compression (2D FFT on 8x8 blocks) |
| 284 | + \item Filtering and enhancement |
| 285 | + \item Feature extraction |
| 286 | + \end{itemize} |
| 287 | + \item \textbf{Numerical Analysis}: |
| 288 | + \begin{itemize} |
| 289 | + \item Solving PDEs (spectral methods) |
| 290 | + \item Fast polynomial multiplication |
| 291 | + \end{itemize} |
| 292 | + \item \textbf{Other Fields}: |
| 293 | + \begin{itemize} |
| 294 | + \item Quantum computing (QFT) |
| 295 | +% \option{Medical imaging (MRI reconstruction) |
| 296 | + \item Astronomy (interferometry) |
| 297 | + \end{itemize} |
| 298 | + \end{itemize} |
| 299 | +\end{frame} |
| 300 | + |
| 301 | +\begin{frame}{Example: Polynomial Multiplication} |
| 302 | + \begin{itemize} |
| 303 | + \item Multiply two polynomials $A(x)$ and $B(x)$ of degree $n-1$ |
| 304 | + \item Naive approach: $O(n^2)$ operations |
| 305 | + \item Using FFT: |
| 306 | + \begin{enumerate} |
| 307 | + \item Evaluate $A$ and $B$ at $2n$ points using FFT ($O(n \log n)$) |
| 308 | + \item Pointwise multiply the results ($O(n)$) |
| 309 | + \item Interpolate to get coefficients using inverse FFT ($O(n \log n)$) |
| 310 | + \end{enumerate} |
| 311 | + \item Total complexity: $O(n \log n)$ |
| 312 | + \end{itemize} |
| 313 | +\end{frame} |
| 314 | + |
| 315 | +\section{Conclusion} |
| 316 | + |
| 317 | +\begin{frame}{Summary} |
| 318 | + \begin{itemize} |
| 319 | + \item FFT is an efficient algorithm to compute the DFT |
| 320 | + \item Reduces complexity from $O(N^2)$ to $O(N \log N)$ |
| 321 | + \item Based on divide-and-conquer strategy |
| 322 | + \item Numerous applications across science and engineering |
| 323 | + \item Modern implementations (FFTW) are highly optimized |
| 324 | + \end{itemize} |
| 325 | +\end{frame} |
| 326 | + |
| 327 | +\begin{frame}{Further Reading} |
| 328 | + \begin{itemize} |
| 329 | + \item Cooley, J. W.; Tukey, J. W. (1965). ``An algorithm for the machine calculation of complex Fourier series''. Math. Comput. 19: 297-301. |
| 330 | + \item Brigham, E. O. (1988). \textit{The Fast Fourier Transform and Its Applications}. Prentice-Hall. |
| 331 | + \item Van Loan, C. (1992). \textit{Computational Frameworks for the Fast Fourier Transform}. SIAM. |
| 332 | + \item FFTW: http://www.fftw.org/ |
| 333 | + \item Numerical Recipes in C: The Art of Scientific Computing |
| 334 | + \end{itemize} |
| 335 | +\end{frame} |
| 336 | + |
| 337 | +\end{document} |
0 commit comments