|
没有这么专业的相关程序,不知道下面的频谱分析程序对你有什么帮助没有?
%SpectrumCorrect_Test.m
close all;
clear all;
clc;
fs=1024;
N=1024;
t=(0:N-1)/fs;
x=4*cos(2*pi*80*t+30*pi/180)+3*cos(2*pi*150.232*t+80*pi/180)+1*cos(2*pi*253.5453*t+240*pi/180);
xf=fft(x);
xf=xf(1:N/2)/N*2;
XfCorrect=SpectrumCorrect(xf,3,1);
XfCorrect(:,1)=XfCorrect(:,1)*fs/N;
XfCorrect
w=hann(N,'periodic');
xfw=fft(x.*w');
xfw=xfw(1:N/2)/N*4;
XfCorrectW=SpectrumCorrect(xfw,3,2);
XfCorrectW(:,1)=XfCorrectW(:,1)*fs/N;
XfCorrectW
%离散频谱比值校正法 by yangzj 2007.4.28
%
%xf为FFT后的复数谱
%CorrectNum为校正的谱线条数,即校正最大的CorrectNum条
%WindowType为加窗类型,1为矩形窗,2为Hanning窗
%
%SpectrumCorrect.m
function XfCorrect=SpectrumCorrect(xf,CorrectNum,WindowType)
XfCorrect=zeros(CorrectNum,3);
for i=1:CorrectNum
A=abs(xf);
[Amax,index]=max(A);
phmax=angle(xf(index));
%比值法
%加矩形窗
if (WindowType==1)
indsecL=A(index-1)>A(index+1);
df=indsecL.*A(index-1)./(Amax+A(index-1))-(1-indsecL).*A(index+1)./(Amax+A(index+1));
XfCorrect(i,1)=index-1-df;
XfCorrect(i,2)=Amax/sinc(df);
XfCorrect(i,3)=(phmax+pi*df)*180/pi;
xf(index-2:index+2)=zeros(1,5);
end
%比值法
%加Hanning窗
if (WindowType==2)
indsecL=A(index-1)>A(index+1);
df=indsecL.*(2*A(index-1)-Amax)./(Amax+A(index-1))-(1-indsecL).*(2*A(index+1)-Amax)./(Amax+A(index+1));
XfCorrect(i,1)=index-1-df;
XfCorrect(i,2)=(1-df^2)*Amax/sinc(df);
XfCorrect(i,3)=(phmax+pi*df)*180/pi;
xf(index-4:index+4)=zeros(1,9);
end
XfCorrect(i,3)=mod(XfCorrect(i,3),360);
XfCorrect(i,3)=XfCorrect(i,3)-(XfCorrect(i,3)>180)*360;
end |
|