I want to make a plot of the power spectrum for a .wav sound file, over the frequency range from -2000 to 2000 Hz.
Attempt:
I used the following code, but the resulting plot is one sided. It doesn't plot the negative frequencies. But the graph I need to produce has to contain negative frequencies. What do I need to do?
Any help would be appreciated.
Here is my code:
[s, Fs] = wavread('chord.wav');
nfft = 2^nextpow2(length(s));
Pxx = abs(fft(s,nfft)).^2/length(s)/Fs;
Hpsd = dspdata.psd(Pxx(1:length(Pxx)/2),'Fs',Fs);
plot(Hpsd)
axis([-2 2 -150 -35]) %change axis range
Produces:
dspdata.psd
. $\endgroup$ – Gilles Apr 26 '16 at 9:03Hpsd=dspdata.psd(Pxx(1:length(Pxx)/2),'Fs',Fs,'SpectrumType','twosided');
. What is wrong here? $\endgroup$ – Merin Apr 26 '16 at 9:24Pxx
from1
tolength(Pxx)/2
. You should plot the full of it. i.e. from1
tolength(Pxx)
or simplyPxx
with no indexes and use thetwosided
argument. $\endgroup$ – Gilles Apr 26 '16 at 9:28dspdata.psd(Pxx,'Fs',Fs,'SpectrumType','twosided');
. But it still returns the same one sided graph. Why is that? So, if we can't do this usingpsd
, can we get the power spectrum by directly plotting $Pxx^2$ versus frequency? $\endgroup$ – Merin Apr 26 '16 at 10:19axis([-2 2 -150 -35])
. $\endgroup$ – Gilles Apr 26 '16 at 10:23