Spectrogram frequency resolution for a given window value?

29 views (last 30 days)
I understand that the window value is what determines the time and frequency resolution of a spectrogram. A larger window should give me a smaller resolution in the frequency domain but a larger resolution in the time domain, and likewise a smaller window should give me a larger resolution in frequency, but a smaller resolution in time.
I have been using some code with a spectrogram for for a while, with a fixed window value, no overlap, and leaving the frequency input empty, so the spectrogram function can calculate an appropiate frequency resolution based on the window value.
[STFT,F,T] = spectrogram(C,window,0,[],fs);
I have now realised that I need the resulting stft output array to be a different size, so I initially thought of changing my window value until I create the number of frequency steps that I want. But upon looking at the spectrogram documentation, I have realised that I can just input a new variable F, to specify the frequency steps I want and it seems to calculate the STFT with the steps I want.
[STFT,F,T] = spectrogram(C,window,0,F,fs);
I have tried changing F to give me very large and very small frequency steps, and the spectrogram function seems to run just fine in both cases. But, this then implies that I can get any frequency resolution I like without changing the windowing value, I just need to input the resolution I like into F. Is this correct? And if so could you please explain to me how the spectrogram function works, so it can produce an STFT array at the frequency resolution I choose for a given window value.
  2 Comments
Michael Whitmore
Michael Whitmore on 24 Sep 2022
The spectrogram function relies on the fft function. In the case that the requested frequency resolution is finer than the length of the windowed data permits (i.e. the requested number of points Nfft is larger than the number of points in the window M), then the fft function resorts to zero-padding. While the zero-padding allows you to computationally get a higher frequency resolution, the resulting data will show "binning" at a frequency resolution imposed by the physical timescale of the window. In the opposite case, you can request a frequency resolution that is coarser than the window length permits. In this case the windowed data will be wrapped at the requested number of Nfft points. The function will change the number of points in the fft accordingly to get the frequencies you requested in F.

Sign in to comment.

Answers (0)

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!