Calculating computational time for convolution fft vs. linear convolution
Show older comments
I have written a code on matlab in order to compute the time required for linear convolution vs. fft. I wanted to ask how I can edit the code so that i can plot the graphs specified in the question below
Generate random signals x[n] and h[n], each of length N, and measure the time it
takes to compute the linear convolution of x[n] using the linear convolution denition and
using the FFT method.
Plot a graph of the results for N = 104 to 105 in steps of 104.
This is my code
>> prompt= ' Input # of elements for each row vector' ;
>> N=input(prompt)
Input # of elements for each row vector100000
N =
100000
>> m=rand(1,N); %generating two random row vectors which contain five elements each
b=rand(1,N);
tic; %starting the timer to measure computation time required for matlab to compute the typical linear convolution
clin=conv(m,b); %computing the linear convolution for the row vectors m and b
toc; %stopping the timer
mz=[m,zeros(1,N-1)]; %creating zero padding in order to compute the convolution through fast fourier transform
bz=[b,zeros(1,N-1)];
tic; %starting the timer to compute the fast fourier transform
covolutionfft=ifft(fft(mz).*fft(bz)); %convolving zero padded vectors m and b
toc;
Answers (0)
Categories
Find more on Transforms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!