Spectrogram (STFT)
Time-frequency representation. Shows how frequency content changes over time. Short-Time Fourier Transform.
Visualization
Interactive visualization for Spectrogram (STFT)
Spectrogram:
- • Visual frequency representation
- • Time-frequency analysis
Interactive visualization with step-by-step execution
Implementation
1function spectrogram(signal: number[], windowSize: number, hopSize: number): number[][] {
2 const frames = Math.floor((signal.length - windowSize) / hopSize) + 1;
3 const spec: number[][] = [];
4 const window = hammingWindow(windowSize);
5
6 for (let i = 0; i < frames; i++) {
7 const start = i * hopSize;
8 const frame = signal.slice(start, start + windowSize);
9 const windowed = frame.map((s, j) => s * window[j]);
10 const fft = computeFFT(windowed);
11 const magnitudes = fft.slice(0, windowSize / 2).map(c => Math.sqrt(c.re**2 + c.im**2));
12 spec.push(magnitudes);
13 }
14
15 return spec;
16}Deep Dive
Theoretical Foundation
STFT: apply FFT to overlapping windows. X[m,k] = Σ x[n]×w[n-m×hop]×e^(-j2πkn/N). m=frame, k=frequency bin. Window (Hamming, Hann) reduces artifacts. Hop size controls overlap.
Complexity
Time
O(frames × n log n)
O(frames × n log n)
O(frames × n log n)
Space
O(frames × n)
Applications
Industry Use
Speech and music analysis and synthesis
Audio fingerprinting and recognition
Biomedical signal analysis (EEG, EMG)
Radar and sonar signal processing
Vibration monitoring and fault detection
Wildlife sound analysis and classification
Seismic data interpretation
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.