sflee
sflee

Reputation: 1719

Matlab spectrogram Hann window

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

  1. What is the relationship between the window size and its FFT size? I through they are independent in the past but I am not sure. Anyone can provide a simple answer or some reference reading?
  2. I have a command specgram(x, 512, 8000, hamming(80)); --- I guess the original purpose is that:
    signal sampling frequency : 8000
    window nfft : 1024
    window period : 10ms
    Actually, I am not sure the original purpose of this code, anyone can read it?

Upvotes: 0

Views: 2967

Answers (1)

MZimmerman6
MZimmerman6

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

Related Questions