一、直接法
clear;clc;close all;
Fs=1000;
t=0:1/Fs:1;
nfft=2048;
x1=cos(2*pi*40*t)+3*cos(2*pi*45*t);
x2=randn(size(t));
x3=x1+x2;
[Pxx,f]=periodogram(x3,window,nfft,Fs);
plot(f,10*log10(Pxx));title('直接法 nfft=2048');;
set(gca,'xlim',[1 120]); ;ylabel('Am/dB');
xlabel('Frequency/Hz');
二、间接法
Fs=1000;
n=0:1/Fs:1;
x1=cos(2*pi*40*n)+3*cos(2*pi*45*n);
x2=randn(size(n));
x3=x1+x2;
nfft=1024;
cxn=xcorr(x3);
CXk=fft(cxn);
Pxx=abs(CXk);
index=0:round(nfft/2-1);
f=index*Fs/nfft;
plot_Pxx=10*log10(Pxx(index+1));
figure (1)
plot(f,plot_Pxx);
title('间接法 nfft=1024');ylabel('Am/dB');
set(gca,'xlim',[1 120]);
xlabel('Frequency/Hz');
三、Bartlett法
clear;clc;close all;
Fs=1000;
t=0:1/Fs:1;
nfft=1024;
x1=cos(2*pi*40*t)+3*cos(2*pi*45*t);
x2=randn(size(t));
x3=x1+x2;
window=hamming(512);
noverlap=0;
p=0.9;
[Pxx,Pxxc]=psd(x3,nfft,Fs,window,noverlap,p);
index=0:round(nfft/2-1);
k=index*Fs/nfft;
plot_Pxx=10*log10(Pxx(index+1));
plot_Pxxc=10*log10(Pxxc(index+1));
figure(1)
plot(k,plot_Pxx);title('Bartlett法海明窗');;
set(gca,'xlim',[1 120]); ;ylabel('Am/dB');
xlabel('Frequency/Hz');
四、Welch法
clear;clc;close all;
Fs=1000;
t=0:1/Fs:1;
nfft=1024;
x1=cos(2*pi*40*t)+3*cos(2*pi*45*t);
x2=randn(size(t));
x3=x1+x2;
window=hamming(512);
noverlap=128;
range='onesided';
[Pxx1,f]=pwelch(x3,window,noverlap,nfft,Fs,range);
plot_Pxx1=10*log10(Pxx1);
figure(1);
plot(f,plot_Pxx1);title('Welch法海明窗');ylabel('Am/dB');
set(gca,'xlim',[1 120]); xlabel('Frequency/Hz');
对所给的实测信号进行谱估计,本文采用了周期图法和Welch法。其程序如下所示:
一、周期图法
clear;clc;close all;
Fs=2000;
load Chanel8Xia2Data.mat;
x1=Chanel8Xia2Gray;
x2=Chanel8Xia2Sti;
Mlag=length(x1);
[Pxx1,f]=periodogram(x1,window,length(x1),Fs);
[Pxx2,f]=periodogram(x2,window,length(x1),Fs);
plot_Pxx1=10*log10(Pxx1);
plot_Pxx2=10*log10(Pxx2);
figure(1);
plot(f,plot_Pxx1,'b');
axis([0,100,-50,40]);grid on;
title('直接法 ');;
set(gca,'xlim',[1 100]);
ylabel('Am/dB');
hold on;
plot(f,plot_Pxx2,'r');
axis([0,100,-50,40]);grid on;
title('直接法 ');
xlabel('Frequency/Hz');ylabel('Am/dB');
二、Welch法
clear;clc;close all;
Fs=2000;
load Chanel8Xia2Data.mat;
x1=Chanel8Xia2Gray;
x2=Chanel8Xia2Sti;
window1=hamming(1024);
noverlap=256;
range='onesided';
[Pxx1,f]=pwelch(x1,window1,noverlap,length(x1),Fs,range);
[Pxx2,f]=pwelch(x2,window1,noverlap,length(x1),Fs,range);
plot_Pxx1=10*log10(Pxx1);
plot_Pxx2=10*log10(Pxx2);
figure(1);
plot(f,plot_Pxx1,'b');
axis([0,100,-30,30]);grid on;
title('Welch法海明窗');ylabel('Am/dB');
set(gca,'xlim',[1 100]);
hold on;
plot(f,plot_Pxx2,'r');
title('Welch法海明窗');ylabel('Am/dB');
xlabel('Frequency/Hz');