AI Glossary / Time series and signal processing / Advanced
Short-Time Fourier Transform
Definition
The Short-Time Fourier Transform, or STFT, represents how a signal's frequency content changes over time. It applies a window to successive short segments and computes a Fourier transform for each segment. The result contains complex coefficients indexed by both time position and frequency.
What it means
A Fourier transform of an entire recording describes its overall frequency content. An STFT adds information about where that content occurs in time. This is useful when the signal changes rather than maintaining the same character throughout.
The representation depends on analysis choices. Window shape, window length, overlap, sampling rate and scaling affect the result. A visual pattern in an STFT is evidence about the sampled signal under those choices, not an automatic diagnosis of its physical cause.
How it works
Choose a window and move it along the samples in fixed increments called hops. Multiply each segment by the window, then compute its discrete Fourier transform, often using an FFT algorithm. Stack the transforms to form a time-frequency array.
The hop controls spacing between successive analysis times. The sampling rate divided by the FFT length gives frequency-bin spacing. Window duration influences how localized the analysis is in time and how well nearby frequencies can be distinguished. Zero-padding creates a denser frequency grid without adding new observed information.
The STFT retains phase as well as magnitude. A spectrogram often displays squared magnitudes, with a stated scaling. Reconstruction requires compatible windows, hop settings and boundary handling; it is not guaranteed by every arbitrary configuration.
Three practical examples
1. Audio analysis: examine how frequency content changes across syllables, notes or other short sound events.
2. Equipment monitoring: follow changing vibration components while retaining their approximate timing.
3. AI feature preparation: create time-frequency inputs for a classifier, keeping preprocessing settings consistent between training and operational use.
Think of it this way
Think of reading a musical passage through a moving viewing slot. A wide slot gives more context about the notes but makes their precise timing less localized. A narrow slot isolates a smaller moment while showing less context. The slot's position and width both affect what can be inferred.
Worked example
Take this invented eight-sample real signal, sampled at eight samples per second:
x = [1,0,-1,0,1,-1,1,-1].
Use a four-sample rectangular window, meaning all four window weights equal one. Set the hop to two samples and keep only windows fully inside the supplied signal. No boundary padding, detrending or amplitude normalization is applied.
The three frames start at sample positions 0, 2 and 4, corresponding to start times 0, 0.25 and 0.5 seconds. They are [1,0,-1,0], [-1,0,1,-1] and [1,-1,1,-1]. Neighboring frames overlap by two samples, or 50% of the window length.
A four-sample window at this sampling rate has nominal duration 4/8 = 0.5 seconds. Its first and last sample timestamps are 3/8 = 0.375 seconds apart. These two descriptions use different conventions and should not be confused. Here we label frames by start time, rather than claiming to reproduce a library's default centered timestamps.
For each frame z, use the unnormalized four-point transform X[k] = sum over n = 0,1,2,3 of z[n] exp(-i × 2pi × k × n/4). The imaginary unit i satisfies i^2 = -1. This formula uses local indices within each frame.
For the first frame, the transform is [0,2,0,2]. For example, the zero-frequency coefficient is the sample sum, 1 + 0 - 1 + 0 = 0. At k = 1, the nonzero contributions are 1 and (-1)exp(-i × pi) = 1, giving two.
The second frame's transform is [-1,-2-i,1,-2+i]. Its zero-frequency coefficient is -1 + 0 + 1 - 1 = -1. The pair -2-i and -2+i are complex conjugates, as expected for the corresponding positive and negative frequency bins of real-valued data.
The third frame's transform is [0,0,4,0]. Its alternating samples align with the Nyquist-frequency component at half the sampling rate, four hertz.
The frequency-bin spacing is 8/4 = 2 hertz. In this four-point ordering, the bins correspond to zero, positive two, the Nyquist frequency and negative two hertz. The first frame has energy in the positive and negative two-hertz bins; the last frame concentrates at Nyquist. The middle frame crosses the transition and contains a mixture, rather than establishing several persistent physical oscillations.
Squaring coefficient magnitudes gives [0,4,0,4], [1,5,1,5] and [0,0,16,0] for the three frames. For example, |-2-i|^2 = (-2)^2 + (-1)^2 = 5. These arrays provide an unscaled spectrogram representation, not a calibrated power spectral density.
An energy check verifies the arithmetic. With this DFT convention, the sum of squared transform magnitudes divided by four equals the sum of squared samples in that frame. The results are 8/4 = 2, 12/4 = 3 and 16/4 = 4, matching the three frame energies. Summing overlapping frame energies would count shared samples more than once.
If each four-sample frame were padded to an eight-point FFT, the bin spacing would become one hertz. The original nonzero observation span would remain four samples. The finer grid alone would not provide the frequency discrimination of a genuinely longer observation window.
Illustrative case study
Fictional Cedar Monitoring compares two vibration displays and assumes that the one with more frequency bins contains more measured information. Its analyst checks the window and FFT lengths and discovers that the second display only uses additional zero-padding.
The team records those settings alongside the plots and validates any fault classification separately. This invented case illustrates interpretation of an analysis configuration, not a demonstrated equipment diagnosis.
Common misconceptions and mistakes
"An STFT is only a colored image." Its underlying coefficients are complex numbers.
"More overlap creates independent observations." Overlapping frames share samples.
"Zero-padding adds signal measurements." It adds zeros for the calculation.
"Squared magnitudes automatically have calibrated physical units." Scaling must be specified.
Business use
Record sample rate, window, hop, FFT length, scaling and boundary treatment. Ensure that comparisons use compatible settings. For AI workflows, validate predictions on appropriately separated recordings so that nearly identical overlapping frames do not create misleading evaluation results.
People also ask
Is an FFT the same as an STFT?
No; an FFT can compute each frame's Fourier transform.
Does an STFT retain phase?
Yes.
Must a spectrogram display phase?
No; magnitude-based displays omit it.
Check your understanding
What is the hop duration?
Answer: 0.25 seconds.
What is the four-point frequency-bin spacing?
Answer: Two hertz.
Why is the middle frame different?
Answer: It includes samples from both sides of the transition.
Related terms
- Fourier transform
- Spectrogram
- Nyquist frequency
- FFT
- window function
- hop size
- spectral leakage
- time-frequency analysis
Learn next
Set the hop to four samples while retaining the original window and signal. Identify the remaining frames and their start times. Explain what transition information is lost when the middle overlapping frame is omitted.
More in Time series and signal processing
- Seasonal exponential smoothing - Seasonal exponential smoothing is a family of forecasting methods that updates a series' level and seasonal pattern as observations arrive.
- Seasonal index - A seasonal index summarizes the estimated contribution of a particular position in a recurring seasonal cycle.
- Seasonal variation - Seasonal variation is recurring movement in a time series associated with a known seasonal or calendar period.
- Signal detection theory - Signal detection theory is a framework for separating the ability to distinguish a meaningful signal from background noise from the decision rule used to...
- Smoothing - Smoothing refers to methods that moderate unstable estimates or use surrounding information to estimate an underlying quantity.
- Source-filter model - The source-filter model explains speech as an excitation signal shaped by the acoustic response of the vocal tract.
Sources
SciPy developers, Signal Processing user guide, Short-Time Fourier Transform: https://docs.scipy.org/doc/scipy/tutorial/signal.html#short-time-fourier-transform
SciPy developers, ShortTimeFFT reference, timing, scaling and spectrogram conventions: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.ShortTimeFFT.html
Previous: Shingling Next: Shortest Augmenting Path