www.pudn.com > fft.zip > Untitled100.m, change:2015-10-19,size:1823b

```close all;
fs=1600;N=128;   %采样频率和数据点数
f0=50;
n=0:N-1;
t=n/fs;   %时间序列
s=220*sin(2*pi*f0*n./fs)+5*sin(2*pi*2*f0*n./fs-0.27)+13.5*sin(2*pi*3*f0*n./fs+2.2)+4*sin(2*pi*4*f0*n./fs+0.9)+9*sin(2*pi*5*f0*n./fs-1.9)+1.5*sin(2*pi*6*f0*n./fs-0.6)+5*sin(2*pi*7*f0*n./fs+0.3)+1.3*sin(2*pi*8*f0*n./fs+0.15)+3*sin(2*pi*9*f0*n./fs+1.8)+sin(2*pi*10*f0*n./fs-0.3)+1.9*sin(2*pi*11*f0*n./fs-1.3)+0.6*sin(2*pi*12*f0*n./fs+1.05)
w =0.2935579-0.45193577*cos(2*pi*n/N)+0.20141647*cos(4*pi*n/N)-0.0047926109*cos(6*pi*n/N)+0.0050261964*cos(8*pi*n/N)-0.00013755557*cos(10*pi*n/N);%窗函数
yx = conv(w, w); % yx即为所求的卷积函数;
plot(yx)
x = s.*yx;%加窗
y=fft(x,N);    %对信号进行快速Fourier变换
vz=abs(y)/64*2;
subplot(2,1,1);
plot(vz);
subplot(2,1,2);
u=abs(y);%准备
plot(u);
A=zeros(1,12);%幅值存储
F=zeros(1,12);%频率
Ph=zeros(1,12);%相位
k1=zeros(1,12);
k2=zeros(1,12);
%插值运算
for I=0:11
y1=u(5+4*I);%原来是y1=u(5+4*I);
y2=u(6+4*I);%原来是y1=u(6+4*I);
y3=u(4+4*I);%原来是y1=u(4+4*I);
k1(I+1)=5+4*I;
k2(I+1)=k1(I+1)-1;
k3(I+1)=k1(I+1)+1;
max=y2;
if y3>y2
max=y3;
end
if max==y3;
t=y1;
y1=max;
y2=t;
k1(I+1)=k1(I+1)-1;%根据公式，谱线谁在前谁是y1，对应的就是k1
k2(I+1)=k1(I+1)+1;%根据公式，谱线谁在后谁是y2，对应的就是k2
k3(I+1)=k2(I+1)+1;%根据公式，谱线谁在后谁是y2，对应的就是k2
k3(I+1)=k2(I+1)-1;%根据公式，谱线谁在后谁是y2，对应的就是k2
end
b=(y3-y2)/y1;
a=0.94130085*b-0.64216621*b^3+0.01575483*b^5-0.00331462*b^7;
A(I+1)=(y2+2*y1+y3)*(1.94125632+0.74584289*a^2+0.061454525*a^4+0.00725097*a^6)/N;%原来少除了128
F(I+1)=(k1(I+1)+a+0.5)*fs/N;%频率
Ph(I+1)=angle(y(k1(I+1)))+pi/2-pi*a;%相位
fprintf(' %5.6f %5.6f %5.6f\n',A(I+1),F(I+1),Ph(I+1));
end```