The DFT: one spectrum for the whole signal
The Discrete Fourier Transform takes N samples of a signal and rewrites them as a sum of N sinusoids at evenly spaced frequencies, each with its own amplitude and phase. It answers which frequencies are present, on average, across the whole recording:
X[k] = Σ_{n=0}^{N-1} x[n] · e^(−2πi·kn/N), k = 0 … N−1
magnitude spectrum: |X[k]| → "how much energy at frequency k·(fs/N)"
computed via the FFT in O(N log N) instead of O(N²)
What a single spectrum hides
A DFT magnitude spectrum has no time axis at all — it is a snapshot of the entire signal collapsed into frequency. Feed it a chirp that sweeps from 200 Hz to 2000 Hz over five seconds and the spectrum shows energy smeared across that whole range, indistinguishable from a signal that contained all of those frequencies simultaneously the entire time. Any signal whose frequency content changes over time — speech, music, a chirp, an AM-modulated carrier — loses exactly the information you usually care about: when each frequency happened.
STFT: chop the signal into overlapping windows
The Short-Time Fourier Transform fixes this with a simple idea: slide a short window (a few hundred samples, tapered at the edges with a Hann or Hamming function to avoid sharp cutoffs) along the signal, take a DFT of each windowed chunk separately, and stack the resulting spectra side by side. The result is a spectrogram — a 2D image with time on one axis, frequency on the other, and colour or brightness showing magnitude — which is exactly how you read a chirp's frequency rising over time, or see the vertical bands of energy that mark consonants in speech.
for each window position t:
segment = x[t : t+W] * hann(W) # taper to reduce spectral leakage
spectrogram[:, t] = |FFT(segment)|
window length W trades time resolution for frequency resolution
The uncertainty trade-off you cannot avoid
A short window pins down when something happened precisely but smears out which frequency it was (few samples means coarse frequency bins); a long window does the opposite. This is not an implementation flaw — it is a direct consequence of the time-frequency uncertainty principle, the same mathematics behind the Heisenberg uncertainty relation in quantum mechanics, applied to signals instead of particles. There is no single window length that is simultaneously optimal for both a sharp instant (like a drum hit) and a pure tone (like a sustained note); every spectrogram is a compromise chosen for the signal at hand.
Understanding the modes in this simulator
A pure sine wave displays one horizontal band; a chord produces several stacked horizontal bands, each corresponding to a note; a chirp shows a rising or falling diagonal streak, representing the DFT's smeared blur resolved into a trajectory; AM modulation exhibits a strong carrier line with two symmetric sidebands spaced at the modulation frequency, consistent with amplitude-modulation theory predictions; and broadband noise occupies the entire frequency axis without any discernible structure due to its lack of dominant frequency.
Frequently asked questions
Чому простий DFT не показує підйом висоти звуку трелей?
DFT стискає весь час сигналу в один спектр без осі часу, тому частота, яка змінюється вгору з часом, виглядає однаково з багатьма частотами, присутніми одночасно протягом усього запису. Лише нарізка сигналу по часу, як це робить STFT, дозволяє відновити, коли кожна частота відбувалася.
Чому STFT не може мати ідеальної часової та частотної роздільної здатності?
Бо роздільність у кожній області залежить від довжини вікна протилежними способами: коротке вікно локалізує час точно, але вимірює лише кілька циклів, розмиваючи частоту; довге вікно детально розв’язує частоту, але усереднює тривалий часовий проміжок. Цей компроміс між часом та частотою є математичним обмеженням, а не помилкою, яку можна виправити за допомогою кращого алгоритму.
Що представляють собою бічні смуги поруч з носієм у режимі AM?
Амплітудно-модулювання носія на частоті fc з тоном на частоті fm математично виробляє три компоненти: сам носій fc, а також дві бічну смугу на частотах fc − fm та fc + fm. Дисплей STFT показує всі три як окремі горизонтальні лінії, оскільки це справді тричастотний сигнал, а не артефакт ілюстрації.
Спробуйте наживо
Усе, що вище, працює прямо у вашому браузері — відкрийте DFT & STFT Visualiser і змінюйте параметри під час роботи. Нічого не встановлюється, нічого не завантажується на сервер, уся модель живе в одній вкладці.
▶ Відкрити симуляцію DFT & STFT Visualiser