## Timing concerning certain functions, in this case a convolution.

### Logan Betts (view profile)

on 20 Apr 2019
Latest activity Edited by Image Analyst

on 20 Apr 2019

### Image Analyst (view profile)

I'm having a little trouble with my program at the moment. My professor has asked us to create our own convolution function. What iv'e written works, but it runs unbelieveably slowly. I'm unaware of the effeciency of doing a convolution this way. I've compared the time the built in conv() takes to my own and its horrid. Any pointers could help me find a better alternative if there is any.
for i = 1:N% this loop will happen N times
sum = 0;%place holder for our matrix sum
for j = 1:i%were going to be adding the multiplications i times
multi = (A(1,N -(i-1)+(j-1))*B(1,j));%
sum = sum + multi;%this will sum every time we multiply
end
final(1,i) = sum;
end
for i = 1:N
sum = 0;
for j = 1:(N-(i-1))
multi = (A(1, N-(j-1)-(i-1))*B(N-(j-1)));
sum = sum + multi;
end
final(1,N+i-1) = sum;
end
The first nested for loop does the convolution untill Nth place, then the second finishes untill the matrices are exausted. A & B are similar sized matrices, N is the size of the matrices, sum is a placeholder, and final holds the final convolution. I'm not sure what part of this is causing it to run so slow. As I said, it gives the corerct answer every time, it just doesnt run with any speed.

### Tags ### Image Analyst (view profile)

on 20 Apr 2019
Edited by Image Analyst

on 20 Apr 2019