I am trying to use Matlab
to compute the spectrogram of a signal but I can't seem to figure out how Matlab computes the spectrogram.Consider the case where I have a signal x(t) with M samples and I want to compute it's spectrogram using hann windows of length N and using an overlap of K samples.
Because there are M samples and the advance time is (N - K) samples, I would expect the resultant spectrogram to have dimensions of either $N$ by $\frac{W}{(N - K)}$ OR if matlab only provides frequencies up to $\frac{f_s}{2}$ then dimensions to be $\frac{N}{2}$ by $\frac{W}{(N-K)}$ but I am getting weird dimensions.
The code below shows the case where I have computed the spectrogram when M = 32 * 700 = 24400, N = 256 and K = 256 - 32 = 224.
%specgram(data, ChunkSize, SampleRate, Size Of Hanning Window, Overlap (in Samples)
D = specgram( 1:1:(32*700),256, 8000 ,256 , 224);
produces a 129 * 693 matrix instead of the (256 * 700) or (128 * 700) spectrogram I was expecting.
Result should be an ($M$ by $\text{Number Of STFT Chuncks}$) matrix and $$ \text{Number Of Chunks} = \frac{\text{Number Of Samples in Signal}}{\text{Advance Time (in Samples)}} $$
$$ \text{Number Of Chunks} = \frac{32 * 700}{32} = 700 $$
Have I missed out on something? Any help will be appreciated.
specgram
is being deprecated, and replaced byspectrogram
. $\endgroup$