📄 example8_4.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% example8_4.m - This program compare the linear convolution in time
% domain and fast convolution in frequency domain
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all, clear all;
x = randn(1,1024);
h = hanning(64)';
total_length = length(x)+length(h)-1;
% Linear convolution in time domain
t0 = clock;
y_t = conv(x,h);
t_t = etime(clock,t0)
% Linear convolution in time domain
t1 = clock;
X = fft(x,total_length);
H = fft(h,total_length);
Y = X.*H;
y_f = ifft(Y,total_length);
t_f=etime(clock,t1)
% Plot the results
figure;
subplot(211), stem(y_t); title('Time domain linear convolution');
subplot(212), stem(real(y_f));title('Frequency domain fast convolution');
fprintf('Time taken in time domain %d \n',t_t);
fprintf('Time taken in freq domain %d \n',t_f);
% This portion computes the number of Nh that is required for efficient
% FFT-based linear convolution.
% Assumption Nh < Nx
Nx = 128; % number of input samples,Nx(fixed)
point = 0;
for Nh = 1:1:Nx % number of coefficient samples,Nh (increasing)
N = Nh+Nx-1;
lfft = 6*N*log2(N)+4*N; % computation load using FFT-based linear convolution
lc = Nx*Nh; % computation load using linear convolution
if lc>lfft % Only when the linear conv load > FFT load
point = [point Nh]; % note the value of point(2) which indicates
end % the minimum value of Nh that provides efficient
end % FFT-based linear convolution
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -