The issue with the x axis is because you are not specifying the sample frequency when calling spectrogram
. Try
[S,F,T] = spectrogram(y,window,[],[],Fs);
Also, I think you are misinterpreting the window
argument. It refers to window shape (by the way you define it, maybe you are thinking it defines the window positions?). So I would use something like
window = ones(1,10);
(or try window shapes other than rectangular).
As for the y axis, in 313 the y axis is (instantaneous) frequency, whereas in 312 it is spectral amplitude. So they are not comparable. In principle, you could compare the color (z axis) of 313 with the y axis of 312, as both are spectral amplitude; however, their normalization is probably different.