FFT vs. STFT

FFT vs. STFT: When to Use Each for Signal Analysis

Overview

The fast Fourier transform (FFT) and short-time Fourier transform (STFT) are foundational tools for analyzing signals in the frequency domain. The FFT is an efficient algorithm for computing the discrete Fourier transform (DFT), converting amplitude versus time data to amplitude versus frequency data. The FFT shows which frequency components are present in the signal and their relative magnitudes.

The STFT extends this idea by applying the FFT to short segments of a signal, making it possible to see how frequency content changes over time. This produces a time-frequency representation often visualized as a spectrogram.

Use the FFT when frequency content remains relatively constant over the analysis interval. Use the STFT when frequency content changes over time and you need to know when specific frequencies occur.

Comparing FFT and STFT

Type FFT (Fast Fourier Transform) STFT (Short-Time Fourier Transform)
Best For Stationary signals where frequency content remains constant Nonstationary signals where frequencies change over time
Output Data 1-D array of frequency magnitudes 2-D array of frequency magnitudes versus time (often visualized as a spectrogram)
Resolution Maximum frequency resolution based on the total signal length; no resolution in time $$ \Delta f = \frac{f_s}{N} $$ Trade-off between time and frequency resolution dictated by window size \(N\) (Heisenberg uncertainty principle) $$\Delta f = \frac{f_s}{N} \qquad \Delta t = \frac{N}{f_s} $$
Computation Efficient computation with time complexity \(O(n \log n)\) Multiple FFT computations; total FFTs required dependent on window length and overlap

Time-Frequency Resolution

The FFT describes the frequency content over the entire analysis window. It will show which frequency components exist and at what magnitudes, but not when. The FFT will provide the highest frequency resolution of the two techniques but does not provide any time information.

The STFT introduces time information at the cost of frequency resolution. It describes when the frequency exists but blurs the information about those frequencies. This fundamental nature, that time and frequency cannot be simultaneously localized, is described by the Heisenberg uncertainty principle.

Computational Complexity and When to Use Each Method

The FFT improves the DFT time complexity for large \(N\), from \(O(n^2)\) to \(O(n \log n)\), where \(n\) is the number of DFT points. The STFT requires multiple FFT computations. The number of FFT calculations depends on the frame rate and window overlap chosen for the STFT calculation. So, computing the STFT of a signal will require more computations than computing the FFT for a given signal. The FFT is best used for stationary signals; for example, vibration analysis with steady frequencies or communications signals that occupy a specific frequency band. STFT is best used for nonstationary signals; for example, audio and biomedical signals.

FFT and STFT in MATLAB

\( Y = \operatorname{fft}(X) \) is the most common syntax for computing the FFT in MATLAB. If \(X\) is a time-domain signal, \(Y\) is returned as the frequency-domain representation. The magnitude of each element of \(Y\) can be plotted versus the frequency to visualize the amplitude of each frequency component.

A common visualization method for spectral analysis is the periodogram. A periodogram visualizes the power spectral density (PSD) of the signal, showing the amount of power per frequency unit.

Periodogram power spectrum plot displaying frequency peaks and an inset data table

The periodogram of a sinusoid that has gone through a power amplifier. The periodogram shows that the nonlinearity in the amplifier has produced harmonic distortion. Harmonics are multiples of the fundamental frequency.

\( S = \operatorname{stft}(X) \) is the basic syntax for computing the STFT in MATLAB. If \(X\) is the time-domain signal, \(S\) is returned as a matrix where time increases across the columns of \(S\) and frequency increases down the rows. The default parameters for the STFT include a Hann window of length 128, an FFT length of 128, and a 75% window overlap length. The STFT is visualized as a spectrogram to show the time-frequency information.

Blue spectrogram showing four acoustic calls: one vertical pulsing pattern followed by three stacked horizontal harmonic bands.

The spectrogram shows the audio of a whale moan. The audio changes over time, showing how the whale alters the tones it is singing.

Choosing Between FFT and STFT

The FFT and STFT are complementary signal analysis techniques. Use the FFT when you need the highest frequency resolution and the signal’s spectral content remains relatively constant. Use the STFT when frequency content changes over time and understanding when events occur is as important as identifying their frequencies.



FFT vs. STFT FAQs

The FFT converts a signal from the time domain to the frequency domain, showing which frequency components are present across the entire signal. The STFT applies the FFT to short segments of a signal, revealing how frequency content changes over time.

Use the FFT when the signal's frequency content remains relatively constant over the analysis interval and you need the highest possible frequency resolution. Common examples include vibration analysis with steady frequencies and communications signals that occupy a specific frequency band.

Use the STFT when frequency content changes over time and knowing when specific frequencies occur is important. It is best suited for nonstationary signals such as audio and biomedical signals.

A spectrogram is a visualization of the STFT output, displaying a grid of amplitudes with time on one axis and frequency on the other to show how a signal's frequency content changes. For example, MATLAB's spectrogram function can display the time-frequency content of audio signals.

Window length creates a trade-off between time and frequency resolution governed by the Heisenberg uncertainty principle. A longer window provides better frequency resolution, while a shorter window better captures rapid changes in frequency content over time.

The basic syntax is S = stft(X), where X is the time-domain signal and S is returned as a matrix with time increasing across columns and frequency increasing down rows. The default parameters include a Hann window of length 128, an FFT length of 128, and 75% window overlap.

The most common syntax is Y = fft(X), where X is a time-domain signal and Y is returned as its frequency-domain representation. The magnitude of each element of Y can be plotted versus frequency to visualize the amplitude of each frequency component.

Yes, because the STFT requires multiple FFT computations across overlapping signal segments, while the FFT requires only a single computation. The total number of FFT calculations depends on the frame rate and window overlap chosen for the STFT.

The FFT produces a one-dimensional array of frequency magnitudes with no time information. The STFT produces a two-dimensional array of frequency magnitudes versus time, which is often visualized as a spectrogram.