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);
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值