# What is the maximal frequency resolution for Matlab's STFT implementation spectrogram()?

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?

$$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.