MATLAB实现的FFT函数时间:2021-10-06 17:22:48写于09年08月29日,函数功能,用MATLAB实现的FFT函数。 完整程序 function xn=myfft(xn,N,M) mybitrevorder(xn,N); for m=1:M B=2^(m-1); for r=0:B-1 P=2^(M-m)*r; for k=r:2^m :N-1 f= xn(k+1); xn(k+1)= xn(k+1)+ xn(k+B+1)*exp(-i*pi*P/N); xn(k+B+1)= f-xn (k+B+1)*exp(-i*pi*P/N); end end end 倒序 function xn=mybitrevorder(xn,N) LH=N/2; r=LH; N1=N-2; for t=1:N1 if t<r T=xn(t+1); xn(t+1)=xn(r+1); xn(r+1)=T; end K=LH; while r>=K r=r-K; K=K./2; end r=r+K; end 综合起来是: fft程序 function xn=myfft(xn,N,M) LH=N/2; r=LH; N1=N-2; for t=1:N1 if t<r T=xn(t+1); xn(t+1)=xn(r+1); xn(r+1)=T; end K=LH; while r>=K r=r-K; K=K./2; end r=r+K; end for m=1:M B=2^(m-1); for r=0:B-1 P=2^(M-m)*r; for k=r:2^m :N-1 f= xn(k+1); xn(k+1)= xn(k+1)+ xn(k+B+1)*exp(-i*pi*P/N); xn(k+B+1)= f-xn(k+B+1)*exp(-i*pi*P/N); end end end