|
我估计楼主用函数:
[pxx,f]=psd(y,NFFT,Fs,window,overlaps)
后将用线性坐标去作图,而
psd(y,NFFT,Fs,window,overlaps)
指令是直接画出对数坐标的谱图。我给出以下程序,其中用到[pxx,f]=psd(y,NFFT,Fs,window,overlaps),又用pxx对数值作图,和直接用psd(y,NFFT,Fs,window,overlaps) 进行比较,可看出两者完全一致:
clear;
Fs=1000;
n=0:1/Fs:1;
xn=cos(2*pi*40*n)+3*cos(2*pi*100*n)+randn(size(n));
nfft=1024;
window=boxcar(length(n)); %矩形窗
noverlap=0; %数据无重叠
[Pxx,f]=psd(xn,nfft,Fs,window,noverlap);
index=0:nfft/2;
k=index*Fs/nfft;
plot_Pxx=10*log10(Pxx(index+1));
figure(1)
plot(f,Pxx); grid;
figure(2)
plot(f,plot_Pxx); grid;
axis([0 500 -30 40]);
figure(3)
psd(xn,nfft,Fs,window,noverlap);
axis([0 500 -30 40]); |
|