The following code generates a spectrogram as shown in the image. The matrix
s which is the spectrogram is of size
129x40 for a signal of length
N=80. Based on my understanding, this means that the number of frames,
frames = 40 which forms the
X axis of the spectrogram image. Using the following values
w=2 (window), into the formula of
nfft (the number of frequency datapoints in each frame), I obtain :
nfft = 2 * ((step_size) - 1) = 78(
frames = floor((N - w) / step_size) + 1 = 40. (
frames form the
X axis of the spectrogram and labelled as
Time in the graph/image plot.
Q1: Can somebody please explain how the matrix
s is formed and the meaning of the dimensions? The following code segments the time series into chunks of data by sliding a window of size
w=2 that creates
40 frames each containing
nfft = 78 frequency datapoints. I thought there should be
nfft = 78 data points in each frame of size
w=2. I recall that we take half of the frequency points since the other half is repeated due to the complex conjugate. I don't quite understand what the
129 points denote and how they come.
Q2: In the Matlab documentation, it is mentioned that
nfft has to greater than 256. But I am getting 78. So is my spectrogram construction incorrect?
Please correct me where wrong.
t = 0:0.001:2; N=80; %signal length (shortening it) signal = chirp(t,100,1,200,'quadratic'); signal = signal(1:N); noverlap = 0; w = 2; noverlap = 0; s=spectrogram(signal,w,noverlap); specto= (20*log10(abs(s))); imagesc(specto) colormap Jet; h = colorbar; set(get(h,'label'),'string','power (dB)/freq (Hz)'); axis image; xlabel('Time','FontSize',14,'FontWeight','bold'); ylabel('Frequency','FontSize',14,'FontWeight','bold');