Reputation: 1719
My task
I have a signal in .wav format with sampling frequency as 44100Hz. I want to get its power spectrum. I would like to do the STFT with a Hann window with size as 200ms and the window period as 50Hz. The frequency range that I am forcing is from 0 ~ 22000Hz.
My question
Can I get what I want with the following code?
[y, Fs, nbits, opts] = wavread('a.wav');
[S,F,T,P]=spectrogram(y,hanning(8820),7938,[0:100:22000],Fs);
The matrix P returned from the above code is what I want, am I right?
Further question
Upvotes: 0
Views: 2967
Reputation: 8623
I do not think you are formatting you spectrogram code properly.
the commands are as follows
[S,F,T,P] = spectrogram(X,WINDOW,NOVERLAP,NFFT,Fs)
Where X
is your data, WINDOW
is your hanning window, NOVERLAP
would be your window jump, NFFT
is your FFT size and Fs
is the data's sampling rate. With this you would want
NFFT = 2^nextpow2(Fs*200/1000);
spectrogram(y,hanning(NFFT),Fs/50,NFFT,Fs);
so your Hanning window is however many samples is in 200ms, which is dependent on your sampling rate.
This should window things how you want, and give you the desired spectrogram, which you can then use however you want.
As for the question if P
is what you want. Yes this will return the power spectrum. If that's what you want, sure.
Upvotes: 2