Matlab下FFT和IFFT的实现


clear all;
close all;
Fs=128;%采样率
N=128;%采样点数
n=0:1:N-1;
t=n/Fs;%时间序列
f=n/N*Fs;%频率序列
x=2*cos(2*pi*6*t)+5*cos(2*pi*10*t);%余弦曲线
%
y=fft(x,N);
Amp=abs(y)*2/N;%对应频率的赋值
Amp(1)=abs(y(1))/N;
Phase=angle(y)*360/(2*pi);%对应频率的相位
%
%三角函数形式
% for m=1:1:N
%     Fx(m)=0;
% end
% for n=1:1:N
%     for m=1:1:N
%         Fx(n)=Fx(n)+Amp(m)*cos(2*pi*(m-1)*(n-1)/N + Phase(m)*(2*pi/360));
%     end
% end
%Fx=Fx/2;
%复指数形式
for m=1:1:N
    Fx(m)=0;
end
for n=1:1:N
    for m=1:1:N
        Fx(n)=Fx(n)+y(m)*exp( (-1*j*2*pi/N)*(-1*(m-1)*(n-1)) );
    end
end
Fx=Fx/N;
%
plot(t,x);
figure;
plot(t,Fx);
figure;
plot(t,Fx-x);

猜你喜欢

转载自blog.csdn.net/Zhangchen9091/article/details/39589341