Documentation

convn

N-D convolution

Syntax

C = convn(A,B)
C = convn(A,B,shape)

Description

example

C= convn(A,B)returns theN-dimensional convolutionof arraysAandB.

example

C= convn(A,B,shape)returns a subsection of the convolution according toshape. For example,C = convn(A,B,'same')returns the central part of the convolution, which is the same size asA.

Examples

collapse all

You can control the size of the output of theconvnfunction. 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 arrayAwith a 2-by-2-by-2 kernelB. The result is a 3-by-4-by-3 array, which is尺寸(a) +大小(b)-1.

A = rand(2,3,2); B = 0.25*ones(2,2,2); C = convn(A,B)
C = (:,:,1) = 0.2037 0.2354 0.1898 0.1581 0.4301 0.6902 0.4426 0.1825 0.2264 0.4548 0.2527 0.0244 (:,:,2) = 0.2733 0.5444 0.4686 0.1975 0.6365 1.3772 1.2052 0.4645 0.3632 0.8327 0.7366 0.2670 (:,:,3) = 0.0696 0.3090 0.2788 0.0394 0.2063 0.6869 0.7627 0.2821 0.1367 0.3779 0.4839 0.2426
sizec = size(a) + size(b)-1
sizeC =3 4 3

Return the central part of the convolution, which is the same size asA.

C = convn(A,B,'same')
c =(:, :,:1)= 1.3772 1.2052 0.4645 0.8327 0.7366 0.2670(:, :, :,2)= 0.6869 0.7627 0.2821 0.2821 0.3779 0.4839 0.2426

Input Arguments

collapse all

Input array, specified as vector, a matrix, or a multidimensional array.

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical
Complex Number Support:Yes

Second input array, specified as a vector, a matrix, or a multidimensional array to convolve withA. The arrayBdoes not have to be the same size asA.

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical
Complex Number Support:Yes

Subsection of the convolution, specified as one of these values:

  • 'full'— Return the full N-D convolution.

  • 'same'— Return the central part of the convolution, which is the same size asA.

  • 'valid'— Return only parts of the convolution that are computed without zero-padded edges.

Output Arguments

collapse all

N-D convolution, returned as a vector, a matrix, or a multidimensional array. IfAandBhave the same number of dimensions, the full convolutionC = convn(A,B)has sizesize(A)+size(B)-1.

When one or both ofAandBare of typesingle, then the output is of typesingle. Otherwise,convnconverts inputs to typedoubleand returns typedouble.

Data Types:double|single

More About

collapse all

N-D Convolution

For discrete,N-dimensional variablesAandB, this equation defines the convolution ofAandB:

C ( j 1 , j 2 , ... , j N ) = k 1 k 2 ... k N A ( k 1 , k 2 , ... , k N ) B ( j 1 k 1 , j 2 k 2 , ... , j N k N )

每一个kiruns over all values that lead to legal subscripts ofAandB.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

|

Introduced before R2006a

Was this topic helpful?