%% Hanning FFT hw=hann(N,'periodic'); Xh=fft(x.*hw'); Xh=Xh(1:N/2)*2; Xhabs=abs(Xh); for i= 1 : m [Amax,index]=TriFind(Xhabs,floor((i*f0-15)/fsN),ceil((i*f0+15)/fsN)); % 搜索区域极大值及其下标 if(index==-1) Fn(i,4) = 0; An(i,4) = 0; Pn(i,4) = 0; else % 下面是插值部分 if(Xhabs(index-1) > Xhabs(index+1)) a2 = Xhabs(index-1) / Xhabs(index); r2 = (2-a2)/(1+a2); k02 = index -1; else a2 = Xhabs(index) / Xhabs(index+1); r2 = (2-a2)/(1+a2); k02 = index; end Fn(i,4) = (k02+r2-1)*fs/N; An(i,4) = 2*pi*r2*(1-r2*r2)*Xhabs(k02)/(N*sin(r2*pi)); Pn(i,4) = phase(Xh(k02))-pi*r2; Pn(i,4) = mod(Pn(i,4),pi); if(abs(r2)<0.000001)||(abs(r2-1)<0.000001) % Fn(i,4) = (index-1)*fs/N; An(i,4) = 2*Amax/N; end Fn_err(i,4) = (Fn(i,4) - Fn(i,2))/Fn(i,4); An_err(i,4) = (An(i,4) - An(i,2))/An(i,4); Pn_err(i,4) = (Pn(i,4) - Pn(i,2))/Pn(i,4); end end % 这是我写的部分代码,你参考下吧