|
楼主 |
发表于 2007-5-14 22:32
|
显示全部楼层
回复 #1 xingliu2008 的帖子
为什么我把这个输进matlab老是不能实现呀?:@L
spectrumcorrect无定义?:@o
大牛们告诉一下怎么定义呀~~~:@(
%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
运行结果
XfCorrect =
80.0014 4.0016 29.8261
150.2333 2.9981 79.7127
253.5397 0.9996 -118.7272
XfCorrectW =
80.0000 4.0000 30.0000
150.2320 3.0000 80.0000
253.5453 1.0000 -120.0002 |
|