I was studying this code:
fm = 8000;
dt = 1/fm; % dt=0.000125
t = [1:dt:5];
y = sin(2*pi*200*t);
tw = 0.05;
ws = 2 .^ round( log2( tw*fm ) ); % ws=512
o = ws/2; % o=128
w = hanning(ws);
[ X, f, tj ] = specgram( y, ws, fm, w, o );
What X represents is an array of Spectrums, one per "tw" windows on the signal. When I call:
plot(f,abs(X));
Matlab gives me the plot of one spectrum. Is that spectrum the summation of the all the spectrums of the signal?
Thanks in advance!
All of your spectrums are there. They're just overlapped. Try zooming in. Or type
whosand look at the size ofX. If you want a spectral image plot, you need to call the function with no outputs:which generates a figure like this:
Alternatively, you can manually plot the spectrum image using
surf:Also, FYI, the help for
specgramin Matlab R2012b states:You'll need to change the order of your inputs to use
spectrogram, I think, assuming you have it in your version. Try: