%% 2-D Convolution
% In applications such as image processing, it can be useful to compare the input of a convolution directly to the output.  The conv2 function allows you to control the size of the output.
% Create a 3-by-3 random matrix A and a 4-by-4 random matrix B. Compute the full convolution of A and B, which is a 6-by-6 matrix.

A = rand(3);
B = rand(4);
Cfull = conv2(A,B)

%
% Compute the central part of the convolution Csame, which is a submatrix of Cfull with the same size as A.  Csame is equal to Cfull(3:5,3:5).

Csame = conv2(A,B,'same')

% Copyright 2012 The MathWorks, Inc.