%% 3-D Convolution
% You can control the size of the output of the convn function.  For example, the 'same' option trims the outer part of the convolution and returns only the central part, which is the same size as the input.
% Convolve a random 2-by-3-by-2 array A with a 2-by-2-by-2 kernel B. The result is a 3-by-4-by-3 array, which is size(A) + size(B) - 1.

A = rand(2,3,2);
B = 0.25*ones(2,2,2);
C = convn(A,B)

%

sizeC = size(A) + size(B) - 1

%
% Return the central part of the convolution, which is the same size as A.

C = convn(A,B,'same')

% Copyright 2012 The MathWorks, Inc.