convfft.m
来自「该程序为matlab进行傅立叶变换的快书算法FFT」· M 代码 · 共 21 行
M
21 行
%利用FFT计算两个有限长序列的线性卷积
%并用传统计算法计算卷积,比较两种方法的速度
L=5000;
N=L*2-1;
n=0:(L-1);
x1=0.5*n;
x2=2*n;
%Compute convotion x1 * x2 using function CONV in traditional way
t0=clock;
yc=conv(x1,x2);
tc=etime(clock,t0)
%Compute convotion x1 * x2 using FFT
%Principle:product in time region equals convotion in frequency
t0=clock;
yf=ifft(fft(x1,N).*fft(x2,N));
tf=etime(clock,t0)
n1=0:length(yf)-1;
plot(n1,yc,'r',n1,abs(yf),'b')
%Conclusion:
% 1. the results from both computing methods are same
% 2. computing convotion using FFT is much faster than that using CONV
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?