Skip to content
AI.info

Speech and audio

Time–Frequency Analysis: Fourier Transform, STFT, and Windowing

Develop practical intuition for Fourier analysis, the short-time Fourier transform, windows, hop size, leakage, and invertibility.

By the end you can

Example

The bearing dataset the whole field tested on, before anyone audited it

Machinery diagnosis has a public reference recording, and its settings are published rather than described. The Case Western Reserve University Bearing Data Center seeded its faults by electro-discharge machining, from 0.007 to 0.040 inches in diameter. It ran the motor at loads of 0 to 3 hp, at speeds from 1797 down to 1720 rpm. And it fixed the sampling rate before anything else: “Data was collected at 12,000 samples/second and at 48,000 samples/second for drive end bearing experiments.”

Those numbers are the whole analysis contract. A fault seven thousandths of an inch across announces itself as something brief happening against something steady. Twelve thousand samples a second decides how brief a thing can still be represented at all. The length of the stretch you transform decides whether it survives being averaged with everything around it. Average a long record into a single spectrum and a short repeating impact is spread thin across the whole of it. Put the same record into a time–frequency view and it is obvious. Nothing in the analysis breaks when the impact vanishes. That is the uncomfortable part. The resolution figures come out perfectly respectable and give no sign that anything was lost.

The dataset also shows what it costs to find out. The field had been testing algorithms on it without a benchmark. Smith and Randall built one in 2015: three established diagnostic techniques, applied to the entire data set, every record categorised. The study has been cited 2,643 times. A dataset everyone had already published on still had to be re-examined record by record before its numbers meant anything.

  • This lesson is about making that choice deliberately instead of inheriting it: Fourier analysis, the short-time Fourier transform, window length, hop size, leakage and invertibility.
  • One failure produces the whole result: a window chosen by convention rather than by the duration of the event. The sampling rate, fault sizes and shaft speeds were all fixed and published in advance.
  • The evidence anyone would ask for is time and frequency resolution under the chosen window. That is precisely the number that looks fine either way.
  • The practical response is Smith and Randall's, scaled down. Run signals with known answers through the same settings first — a steady tone, a short impulse, a frequency sweep — instead of trusting a record because others have published on it.

Comparison

Sharper in frequency, blurrier in time — or two windows at once, by regulation

A long window does one thing well. Length buys frequency discrimination: the longer the stretch of signal you transform, the finer the distinctions you can draw between neighbouring tones. It pays for that in time. The longer the window, the more thoroughly a rapid change is spread across it and averaged with everything else inside. A short window makes the opposite bargain. Transients land where they happened, spectral peaks widen, fine frequency detail goes.

Multi-resolution analysis declines to make a single bargain. In broadcast loudness metering, declining is not a design preference. It is a written requirement. EBU Tech 3341, in its 2023 edition, meters the same signal at two window lengths at once: “The Momentary Loudness uses a sliding rectangular time window of length 0.4 s.” Short-term loudness runs alongside it on a sliding rectangular window of 3 s. Both are explicitly ungated. A second body defines the same two scales independently. ITU-R BS.1771-1 uses a first-order low-pass filter with a 400 ms time-constant for Momentary, and an ungated interval of 3 seconds for Short-term.

The ratio matters more than either number. One signal, two events being watched: a sudden jump and a sustained level. No single window answers both, so two run side by side and neither is called the default. None of the three arrangements is safe by inheritance. Each has to be defended on its own numbers, against the event someone is actually trying to see.

FigureComparison · 3 columns

Long window

Sharper frequency discrimination but poorer localization of rapid change.

  • Decision focus: Choose the event duration
  • Useful evidence: Time and frequency resolution under the chosen window
  • Watch for: Choosing a window from convention rather than event duration
  • Best used when its assumptions are documented for time–frequency analysis

Short window

Better transient localization but wider spectral peaks and less frequency detail.

  • Decision focus: Select window and hop
  • Useful evidence: Spectral leakage on controlled tones
  • Watch for: Treating zero padding as newly observed frequency detail
  • Best used when its assumptions are documented for time–frequency analysis

Multi-resolution analysis

Combines several scales at additional compute and design complexity.

  • Decision focus: Choose scaling and representation
  • Useful evidence: Reconstruction error when invertibility matters
  • Watch for: Discarding phase before a task that needs reconstruction or localization
  • Best used when its assumptions are documented for time–frequency analysis

Twenty-five milliseconds, ten milliseconds, and why

Behind that trade sits a mechanism worth stating plainly. The Fourier transform represents a signal using sinusoidal components. The short-time Fourier transform applies that same analysis to overlapping windows, one after another, so the picture is allowed to change as the signal does. Three settings govern the result: the length of the window, its shape, and the hop between consecutive windows. Between them they decide which distinctions in time and in frequency remain visible at all, and how faithfully the representation can be inverted back into a signal.

In practice those settings are not free parameters. For speech, two independent teams wrote down the same ones. Conformer, in 2020: “We extracted 80-channel filterbanks features computed from a 25ms window with a stride of 10ms.” Whisper, three years later: “All audio is re-sampled to 16,000 Hz, and an 80-channel log-magnitude Mel spectrogram representation is computed on 25-millisecond windows with a stride of 10 milliseconds.” Same window, same stride, same 80 channels, different organisations.

Neither figure is a convention. Ten milliseconds gives a hundred frames a second, close to the rate at which phones change. Twenty-five milliseconds is long enough to resolve a pitch period and short enough to treat as stationary. At Whisper's stated 16,000 Hz those durations are concrete: a 400-sample window advanced 160 samples at a time. And the setting delivers. The 118.8M-parameter Conformer (L) reaches 2.1%/4.3% WER on LibriSpeech test-clean/test-other without a language model, and 1.9%/3.9% with one. That is what a window matched to an event looks like when somebody has done the work.

What comes out the other end is still not a photograph of independent physical frequencies. The bins of a spectrogram reflect the analysis basis you chose: a finite window, a sampling rate, a scale, a display transform. Lines and blobs can be artifacts of leakage or of plotting. So two questions decide whether an analysis can be trusted, and neither is about the model. Was the window matched to the event you are trying to see? Were controlled test signals run through the same settings? Without both answers, the resolution numbers cannot support the decision they are quoted for.

Figure

The window and stride both Conformer and Whisper use, drawn as they actually overlap, and the per-second budget they imply.

Pick the window before the model, because a distinction erased at analysis time cannot be recovered by anything downstream.

Visual

Test the analysis on a tone first

The tone, the impulse and the sweep come before the real data. Each has an answer you already know: the frequency of the tone, the moment of the impulse, where the sweep has reached at any instant. So whatever the analysis blurs, shifts or adds shows up as a discrepancy rather than as a discovery.

Step two is where the argument has to be made, and somebody has made it in public. Broadcast loudness measurement does not leave the window and the hop to the implementer. ITU-R BS.1770-5, from November 2023, writes them down: “A gating block is a set of contiguous audio samples of duration Tg = 400 ms, to the nearest sample. The overlap of each gating block shall be 75% of the gating block duration.” Seventy-five per cent overlap of a 400 ms block is a 100 ms hop. The same Recommendation fixes an absolute gate at −70 LKFS, and a relative gate 10 dB below the level measured after the absolute gate. EBU Tech 3341 independently restates the same 400 ms blocks at 75% overlap and the −70 LUFS gate. A window and a hop can be a written obligation, not whatever the library defaulted to.

That discipline only holds if the four moves are kept apart: what was measured, what was modelled, what was decided, and what was verified. Windowing decisions hide easily inside a single score. A resolution figure that was a measurement of the analysis gets read as a verification of the result.

FigureProcess · 4 steps
  1. 1. Choose the event duration

    Estimate whether the phenomenon lasts milliseconds, syllables, seconds, or longer.

  2. 2. Select window and hop

    Balance temporal localization, frequency resolution, compute, and overlap.

  3. 3. Choose scaling and representation

    Decide magnitude, power, phase, log scale, or complex input according to the task.

  4. 4. Validate with controlled signals

    Use tones, chirps, impulses, mixtures, and reconstruction tests to expose artifacts.

Event duration chosen once is the window the controlled-signal test itself runs in, so a bad choice gets confirmed rather than exposed.

Example

One window will not serve four domains

Twenty-five milliseconds at a ten-millisecond stride is an answer. Be exact about the question it answers. Speech, re-sampled to 16,000 Hz, by teams who reasoned from pitch periods and phone rates and then reported the word error rates the setting bought them. Carry it elsewhere and the reasoning does not travel with it. Broadcast loudness runs 400 ms and 3 s at once, because two bodies wrote both down. Machinery is the Case Western Reserve recording from the opening of this lesson, sampled at 12,000 or 48,000 samples per second, where something brief has to be seen against something steady. Spatial audio asks for a quantity the other three can afford to throw away. Each domain sets its own units. None of them is answered by what answered another.

  • Speech asks one window to serve two clocks at once. Conformer and Whisper both settle on 80 channels from a 25 ms window at a 10 ms stride, because phonetic transitions and pitch cues do not operate at the same time scale. 25 ms is the compromise between them.
  • Broadcast needs more than one resolution simultaneously, and says so in writing. EBU Tech 3341 puts Momentary loudness on a sliding rectangular window of 0.4 s alongside Short-term loudness on a sliding rectangular window of 3 s, both ungated. ITU-R BS.1771-1 defines the same pair.
  • Machinery is the bearing again. On the Case Western Reserve data, faults seeded by electro-discharge machining from 0.007 to 0.040 inches in diameter produce brief impacts. They sit in the same recording as stable rotational harmonics at 1797–1720 rpm. Each wants the opposite window.
  • Spatial audio makes a demand the others do not: complex phase can be essential to estimating delay and direction. Phase discarded at analysis time is exactly what Griffin and Lim's iterative algorithm exists to try to recover afterwards.

Steps

Build a window-selection experiment

The habit under test is the one that opened the lesson: a window picked by convention instead of by the length of the event. An experiment is worth building only if another team can run it without you and bring that charge for themselves. Smith and Randall did exactly that to a whole community's favourite dataset in 2015 — three established diagnostic techniques, the entire set, every record categorised, rather than an argument.

Three things go on the page. Write down what matching the window to the event duration assumes. Add one counterexample, a case where that matching would mislead you. The broadcast meters are ready-made, since no single window satisfies both the 0.4 s and the 3 s obligation. Then say what a run on controlled test signals tells you afterwards, and what it cannot tell you, because the test runs inside the window you already chose. Send a steady tone, a short impulse and a frequency sweep through several window lengths, overlaps and window functions. Record the smearing, the leakage, the missed transients and the compute. Then choose from how the task behaves, not from how the plot looks.

FigureProcess · 4 steps
  1. 1. Create three probe signals

    Use a steady tone, a short impulse, and a frequency sweep.

  2. 2. Render multiple STFT settings

    Vary window length, overlap, and window function.

  3. 3. Record visible artifacts

    Note smearing, leakage, missed transients, and computational cost.

  4. 4. Choose with evidence

    Select settings from task behavior rather than visual appeal alone.

Settings chosen because a plot looks clean are chosen by the wrong judge; let task behavior on controlled test signals decide instead.

Example

Leakage looks exactly like a signal, and it has a published number

Go back to the figures that looked fine. Time and frequency resolution under the chosen window is a property of the analysis that was run. It states what that window could in principle have separated. It says nothing at all about whether the window fitted the event. That is why a window picked out of habit still produces respectable numbers.

Leakage, at least, is not a matter of impression. It has a published number, and has had one since 1978. Harris catalogued, window by window, the 3.0-dB main-lobe bandwidth and the highest sidelobe level. The rectangle window's first sidelobe sits roughly 13 dB below the main-lobe peak. The Hamming window with coefficient 0.53856 attains a −43 dB sidelobe level. Thirty decibels of difference, printed in a table, in a paper OpenAlex records at 7,277 citations. So the core figure needs provenance, and it needs company. Name the unit, say which recordings it came from, how uncertain it is, and what was running while it was measured. Then put three more kinds of number beside it.

  • Report time and frequency resolution under the chosen window as the core task figure — but never on its own.
  • Beside it, spectral leakage measured on controlled tones against Harris's 1978 table. A shoulder 13 dB down under a rectangle is what that window does to any tone. The same tone through a Hamming window with coefficient 0.53856 should leave its highest sidelobe near −43 dB. That is how you tell a line produced by the sound from a line produced by the analysis.
  • Where invertibility matters, reconstruction error as Griffin and Lim defined it in 1984 — and keep their two algorithms apart. The first estimates a signal from a modified STFT by minimising the mean squared error between the STFT of the estimated signal and the modified STFT. The second is built on it and is iterative: it estimates a signal from a modified STFT magnitude, and is shown to decrease at each iteration the mean squared error between the STFT magnitude of the estimated signal and the modified STFT magnitude.
  • Across the life of the system, downstream performance broken out over transient and stationary slices. That is the split Conformer reports as 2.1% against 4.3% WER on test-clean against test-other, and it is where a front end tuned for one kind of material and not the other finally becomes visible.

Report time and frequency resolution under the chosen window together with downstream performance across transient and stationary slices.

Key idea

Zero padding invents nothing

Four habits do most of the damage in time–frequency analysis, and each began as a defensible shortcut. The first has been the subject of this lesson: choosing a window from convention rather than from event duration. ITU-R BS.1770-5 shows what the alternative looks like — 400 ms blocks at 75% overlap, written down, with the body that issued them attached. The second is treating zero padding as newly observed frequency detail, when nothing new was observed. More bins interpolate one window; they do not lengthen it. The main-lobe bandwidth Harris tabulated in 1978 does not shrink because you appended zeros. The third is discarding phase before a task that needs reconstruction or localization. That is the spatial-audio demand, thrown away, and the reason Griffin and Lim's 1984 iterative algorithm has been cited 2,123 times. The fourth is reading display colour as though it were a calibrated physical quantity.

All four make the same move. They treat the picture as the thing measured, rather than as one rendering of it. The working test is cheap: change the window, change the scale, change the colour map, and see what stays. A shoulder 13 dB below a peak under a rectangle window that collapses toward −43 dB under a Hamming window was the window talking, not the sound. No amount of zero padding will promote it to an observation.

A window picked by convention and a spectrogram read as a photograph fail the same way: features of the analysis basis get reported as sound.

Key takeaways