How to Calculate the Convolution?

Hello and Greetings,
i have learning from Andrew NJ how to calculate the convolution manually say we have an array like:
array([ [ 3, 3, 2, 1, 0],
[0, 0, 1, 3, 1],
[3, 1, 2, 2, 3],
[2, 0, 0, 2, 2],
[2, 0, 0, 2, 1]
])
convoluted with a filter like :
array([ [0, 1, 2],
[2, 2, 0],
[0, 1, 2]]
)

so the result should be :
array([ [12, 12, 17],
[10, 17, 19],
[9, 6, 14]]
)

==>I applied the rule that : n-f+1=the output size .In this case 5-3+1=3 ,hence 3 by 3 is the shape of the output size.
Actually i am confused , when i applied the algorithm here in the screen shot i get another result .

Could someone help me, please?



here the video of Andrew Nj about calculating the convolution manually :

here the example i used here :

Thank you in advance

Hi there,

I can recommend this excellent video to get familiar with 1D conv from a perspective of system and control theory:

Especially the interpretation of results from min 25 on is quite helpful.

Afterwards 2D convolution is straight forward.
As you are pointing out correctly, there are different ways how to deal with the size / boundary areas. This is a question of definition, e.g. with respect to ‘zero padding’, meaning filling in zeros till size requirements are fulfilled. Feel free to take a look at this source: 2-D convolution - MATLAB conv2
Under input argument ‘shape options’ are outlined on how to get:

  • full 2-D convolution.
  • central part of the convolution
  • only parts of the convolution that are computed without zero-padded edges.

When comparing results, please ask yourself which definition of conv is meant / applied and what you need.

Hope that helps!

Best regards
Christian

1 Like