Matlab's spectrogram() function calculates the STFT of a signal. It describes its NFFT argument as follows:

S = SPECTROGRAM(X,WINDOW,NOVERLAP,NFFT) specifies the number of frequency points used to calculate the discrete Fourier transforms. If NFFT is not specified, the default NFFT is used.

Am I correct in that NFFT is a trade-off only between frequency resolution and number of computations? For my offline work, there's no need to save cycles. Is there any maximum limit for NFFT, imposed e.g. by spectral leakage, or any other problem that I should know about, or can I set that argument to as high as possible?


1 Answer 1


The length of the FFT is a tradeoff between frequency and time resolution. Spectrograms are often generated by calculating overlapping FFTs on the signal of interest. If you make the FFT longer, then the effective bandwidth of each output bin becomes smaller, so the resolution along the frequency axis improves. The only limiting factor to the frequency resolution that you can obtain is the total observation time that you have from the signal.

At the same time, however, your ability to resolve a feature that is localized in time diminishes. An intuitive way to think about this is to view the FFT as a complex downconversion followed by an integrate-and-dump operation:

$$ X[k] = \sum_{n=0}^{N-1} (x[n] e^{\frac{-j2 \pi n k}{N}}) $$

Viewing it in this way makes the loss of time resolution more apparent. The product in parentheses shifts $x[n]$ down in frequency by $\frac{2 \pi n k}{N}$, and the resulting signal is integrated over a window of $N$ samples. If there is a feature in $x[n]$ that is only located in a limited time span, then as $N$ becomes larger, more of the overlapped FFTs will contain that time period inside their integration time windows. Therefore, the feature will appear in more rows of the spectrogram image (assuming time is along the Y axis). If you then make a cut down the columns (i.e. the frequency bins) of the spectrogram that the feature is located in, you would notice a broader, smeared out peak. You therefore have a lesser ability to resolve the actual time location of the feature's onset.

You are also right that increasing the FFT length does require more computations, which might be relevant for real-time applications.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.