Fast Fourier Transform (FFT)
Efficiently computes Discrete Fourier Transform. Converts time-domain signal to frequency domain. O(n log n) vs O(n²) DFT. Cooley-Tukey algorithm.
Visualization
Interactive visualization for Fast Fourier Transform (FFT)
FFT:
- • Fast Fourier Transform
- • Time: O(n log n)
Interactive visualization with step-by-step execution
Implementation
1class FFT {
2 compute(signal: number[]): Complex[] {
3 const n = signal.length;
4
5 // Base case
6 if (n === 1) return [{ re: signal[0], im: 0 }];
7
8 // Divide
9 const even = signal.filter((_, i) => i % 2 === 0);
10 const odd = signal.filter((_, i) => i % 2 === 1);
11
12 // Conquer
13 const evenFFT = this.compute(even);
14 const oddFFT = this.compute(odd);
15
16 // Combine
17 const result: Complex[] = new Array(n);
18 for (let k = 0; k < n / 2; k++) {
19 const angle = -2 * Math.PI * k / n;
20 const twiddle = { re: Math.cos(angle), im: Math.sin(angle) };
21 const t = this.multiply(twiddle, oddFFT[k]);
22
23 result[k] = this.add(evenFFT[k], t);
24 result[k + n / 2] = this.subtract(evenFFT[k], t);
25 }
26
27 return result;
28 }
29
30 private multiply(a: Complex, b: Complex): Complex {
31 return {
32 re: a.re * b.re - a.im * b.im,
33 im: a.re * b.im + a.im * b.re
34 };
35 }
36
37 private add(a: Complex, b: Complex): Complex {
38 return { re: a.re + b.re, im: a.im + b.im };
39 }
40
41 private subtract(a: Complex, b: Complex): Complex {
42 return { re: a.re - b.re, im: a.im - b.im };
43 }
44}
45
46interface Complex { re: number; im: number; }Deep Dive
Theoretical Foundation
Divide-and-conquer: splits DFT into even/odd indexed samples. Recursively computes smaller DFTs, combines using twiddle factors W = e^(-2πi/N). Requires n = power of 2. Applications: spectral analysis, filtering, compression.
Complexity
Time
O(n log n)
O(n log n)
O(n log n)
Space
O(n log n) recursive, O(n) iterative
Applications
Industry Use
MP3 and audio compression algorithms
Digital audio workstations (DAWs)
Radar and sonar signal processing
Medical imaging (MRI, CT scans)
Telecommunications and modulation
Image processing and computer vision
Vibration analysis in engineering
Astronomical data processing
Use Cases
Related Algorithms
A* Search Algorithm
Informed search algorithm combining best-first search with Dijkstra's algorithm using heuristics. Widely used in pathfinding and graph traversal, A* is optimal and complete when using admissible heuristic. Used in games, GPS navigation, and robotics. Invented by Peter Hart, Nils Nilsson, and Bertram Raphael in 1968.
Convex Hull (Graham Scan)
Find smallest convex polygon containing all points. Graham Scan invented by Ronald Graham in 1972, runs in O(n log n). Essential in computational geometry, computer graphics, and pattern recognition.
Line Segment Intersection
Determine if two line segments intersect. Fundamental geometric primitive used in graphics, CAD, GIS. Uses orientation and collinearity tests.
Caesar Cipher
The Caesar Cipher is one of the oldest and simplest encryption techniques, named after Julius Caesar who used it to protect military messages around 100 BC. It works by shifting each letter in the plaintext by a fixed number of positions down the alphabet. For example, with a shift of 3, A becomes D, B becomes E, and so on. Despite being used for over 2000 years, it's extremely weak by modern standards with only 25 possible keys, making it trivially breakable by brute force or frequency analysis.