The Discrete Fourier Transform (DFT) decomposes a finite sequence of N samples into N complex frequency components: Xₖ = Σₙ xₙ · e^(−2πiknN) for k = 0 … N−1. It reveals which frequencies contribute to a signal but assumes the entire signal is stationary — it cannot tell you when a frequency occurs. The Short-Time Fourier Transform (STFT) addresses this by computing the DFT on successive overlapping windowed frames, producing a 2D time-frequency spectrogram. The trade-off is fundamental: a narrow window gives good time resolution but poor frequency resolution (uncertainty principle: Δt · Δf ≥ 1/4π), while a wide window reverses the balance — the same Heisenberg-like constraint that governs quantum mechanics.
The simulator lets you draw a waveform or load an audio clip, then watch the DFT spectrum and the STFT spectrogram update live. You can adjust the window function (Hann, Hamming, rectangular) and the overlap percentage to observe how they trade time against frequency resolution.
What is the difference between DFT and FFT?
The DFT is the mathematical transform itself; the FFT (Fast Fourier Transform) is an efficient algorithm for computing it. A naive DFT computation requires O(N²) multiplications; the Cooley-Tukey FFT algorithm, published in 1965, reduces this to O(N log N) by exploiting the symmetry of the complex exponentials. For N = 1,048,576 (2²⁰) samples this is about 200,000 times faster. The FFT is considered one of the most important algorithms of the 20th century.
What is a spectrogram and how is it read?
A spectrogram is a 2D plot of an STFT: time runs along the horizontal axis, frequency along the vertical axis, and colour or brightness represents the magnitude (or log magnitude in dB) at each time-frequency bin. Horizontal streaks indicate sustained tones; vertical streaks indicate transient clicks; diagonal streaks indicate frequency sweeps (chirps). Speech spectrograms show formants — the dark horizontal bands that encode vowel identity and enable automatic speech recognition.
Why can't we have perfect time and frequency resolution simultaneously?
This is the time-frequency uncertainty principle: Δt · Δf ≥ 1/(4π), where Δt is the RMS duration of the window and Δf is the RMS bandwidth of the resulting frequency response. Using a narrow window localises events in time (small Δt) but smears the spectrum (large Δf), and vice versa. The Gaussian window achieves the minimum uncertainty product (the equality case), which is why it is used in wavelet analysis and Gabor transforms.
When you take the DFT of a finite block of samples, you implicitly multiply the signal by a rectangular window — abruptly cutting it off at the edges. This creates spectral leakage: the sharp edges introduce spurious frequency components that spread energy from strong tones into neighbouring bins. Window functions like Hann, Hamming, Blackman, or Kaiser taper the signal smoothly to zero at the edges, reducing leakage at the cost of slightly wider main lobes (reduced frequency resolution). The choice of window depends on whether you need low leakage (Blackman) or narrow main lobe (rectangular).
The Nyquist-Shannon sampling theorem states that a signal containing no frequencies above fₘₐₓ can be perfectly reconstructed from samples taken at a rate of at least 2fₘₐₓ (the Nyquist rate). Sampling below this rate causes aliasing: high-frequency components fold back and appear as phantom low-frequency signals. Audio CDs use a 44,100 Hz sample rate to capture frequencies up to 22,050 Hz — slightly above the human hearing limit of ~20,000 Hz.
Each DFT coefficient Xₖ is a complex number with magnitude |Xₖ| (how strongly frequency k is present) and phase arg(Xₖ) (the timing offset of that frequency component relative to the start of the window). Spectrograms typically display only |Xₖ|² (the power spectrum) because phase is hard to interpret visually and less perceptually relevant for audio. However, phase is critical for signal reconstruction: inverse DFT requires both magnitude and phase to recover the original signal.
MP3 and AAC audio codecs use a modified version of the STFT — the Modified Discrete Cosine Transform (MDCT) — to convert audio to the frequency domain. They then apply psychoacoustic masking: loud tones mask nearby quieter ones, so bits can be re-allocated from masked frequencies to audible ones. The MDCT frame size is adapted dynamically (longer for stationary signals, shorter for transients) — exactly the time-frequency trade-off the STFT window size controls.
Both the STFT and the wavelet transform analyse a signal at multiple time locations, but they differ in how they tile the time-frequency plane. The STFT uses a fixed window size, giving uniform resolution in both time and frequency at all scales. The wavelet transform uses a window that scales with frequency: wider windows for low frequencies (good frequency resolution) and narrower windows for high frequencies (good time resolution). This gives wavelets a constant relative bandwidth (Q-factor), better matched to how the human auditory system processes sound.
Zero-padding means appending zeros to a signal before computing its DFT, increasing N without adding new information. It interpolates the frequency spectrum — the output bins become more densely spaced in frequency — making the spectral peaks easier to see. However, it does not improve the actual frequency resolution (which is determined by the true signal length, not the padded length). Zero-padding is commonly used for display purposes and for efficient convolution via the overlap-add or overlap-save methods.