Convolution in Matlab

I got the following matrix:

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 core:

-0.5+0.8662i 1 -0.5-0.8662i

I am trying to convolution using a valid mode:

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

Return Matlab:

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

My question is how can I achieve the same results as matlab. I try to do in matlab in the first paragraph, but the results are 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 imaginary sign is positive with convolution. Why?

+5
source share
2 answers

I believe that convolution is usually done by β€œflipping” the kernel (from left to right, up and down), and then shifting it along the matrix to perform the sum of multiplications.

In other words, what the matrix actually calculates:

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

In the process of convolution, the core is upside down. So you have to flip it too on the check; i.e. swap kernel(1) and kernel(3) as shown below:

 >> a = matrix(1,1) * kernel(3); >> a = a + matrix(1,2) * kernel(2); >> a = a + matrix(1,3) * kernel(1) a = 27.0000 +15.5916i 

This corresponds to the result of the convolution:

 >> A = conv2(matrix,kernel,'valid'); >> A(1,1) ans = 27.0000 +15.5916i 
+6
source

Source: https://habr.com/ru/post/1207898/


All Articles