Timing concerning certain functions, in this case a convolution.
이전 댓글 표시
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.
Thanks you for your time.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Parallel Computing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!