Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convolution in Matlab hands on

I got the matrix below:

 9 18 27 36 45
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0
 0  0  0  0  0

and the kernel:

-0.5+0.8662i 1 -0.5-0.8662i

I'm trying to perform the convolution using valid mode:

ans = conv2(matrix,kernel,'valid');

The matlab returns:

0.0000+15.5916i 0.0000+15.5916i 0.0000+15.5916i

My question is how I can achieve the same results like matlab. I'm trying to do in the matlab in the first point, but the results is different.

a =     matrix(1,1) * kernel(1);
a = a + matrix(1,2) * kernel(2);
a = a + matrix(1,3) * kernel(3);

Result: 0-15.5916i

For some reason the sign of the imaginary is positive using convolution. Why ?

like image 862
Diego Catalano Avatar asked Nov 28 '14 16:11

Diego Catalano


1 Answers

I believe convolution is usually performed by "flipping" the kernel (left-right, up-down) and then sliding it across the matrix to perform a sum of multiplications.

In other words, what matlab is actually computing is:

a =     matrix(1,1) * kernel(3);
a = a + matrix(1,2) * kernel(2);
a = a + matrix(1,3) * kernel(1);
like image 85
eigenchris Avatar answered Sep 22 '22 20:09

eigenchris