Use Fast Fourier Transform
FFT computes the discrete Fourier transform in O(n log n) instead of O(n^2). Used in signal processing, polynomial multiplication, and audio analysis.
- 1
The FFT converts a signal from time domain to frequency domain. It decomposes a signal into its frequency components. The DFT is O(n^2); the FFT (Cooley-Tukey) is O(n log n) by recursively splitting even and odd indices. Requirements: input length should be a power of 2 (zero-pad if not). Applications: audio processing, image compression (JPEG), polynomial multiplication, convolution.
- 2 Complex Multiply →
FFT uses complex arithmetic. The twiddle factors are complex roots of unity: e^(-2πi k/n). This tool performs complex multiplication, which is the core operation in the FFT butterfly. Each butterfly combines two complex values with a twiddle factor.
- 3 Polynomial Evaluate →
FFT can multiply polynomials in O(n log n) instead of O(n^2): evaluate both polynomials at the n-th roots of unity (FFT), multiply pointwise, then interpolate (inverse FFT). This is faster than direct coefficient multiplication for large polynomials.
Frequently asked questions
- What is the difference between DFT and FFT?
- The DFT (Discrete Fourier Transform) is the mathematical definition — O(n^2). The FFT (Fast Fourier Transform) is an algorithm that computes the DFT in O(n log n) by exploiting symmetry and recursion. The result is identical; the FFT is just much faster. For n=1024, FFT is ~100x faster than DFT.
- Why must the input length be a power of 2?
- The Cooley-Tukey FFT algorithm recursively splits the input into even and odd halves. This requires the length to be a power of 2. For other lengths, zero-pad to the next power of 2, or use mixed-radix FFT (supports lengths that are products of small primes). Most FFT libraries handle non-power-of-2 lengths automatically.
Learn more
Want to understand why?