此为PSD函数所得功率谱密度
clear all;
% Generate the signal with noise and display
N=1024;
n=[0:N-1];
Fs=500;
t=n/Fs;
Mlag=100;
% Generate noise
wn=randn(1,length(t));
xn=sin(2*pi*10*n)+0.7*wn;
figure(1);
plot(t,xn); xlabel('n');
grid;
title(' 原函数');
% Estimate the PSD
window=boxcar(N/8);
[Pxx,Pxxc,f]=psd(xn,1024,1000,window,0,0.9);
f=(0:length(Pxx)-1)/length(Pxx);
plot_Pxx=10*log10(abs(Pxx));
figure(2);
plot(f,plot_Pxx);
xlabel('Frequency'),
ylabel('Power Spectrum (dB)');
title('功率谱');
grid ;
%Estimate the PSD with 90% confidence interval
figure(3);
plot(f,10*log10(Pxx-Pxxc(:,1)), f,10*log10(Pxx+Pxxc(:,1)));
xlabel('Frequency(Hz)');
ylabel('Power Spectrum(dB)');
title('PSD with 90% confidence interval');
grid;
|