convn
N-D convolution
Description
Examples
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)
C = 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 C(:,:,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 C(:,:,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 = 1×3
3 4 3
Return the central part of the convolution, which is the same size as A
.
C = convn(A,B,'same')
C = C(:,:,1) = 1.3772 1.2052 0.4645 0.8327 0.7366 0.2670 C(:,:,2) = 0.6869 0.7627 0.2821 0.3779 0.4839 0.2426
Input Arguments
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 with A
. The array B
does
not have to be the same size as A
.
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
N-D convolution, returned as a vector, a matrix, or a multidimensional
array. If A
and B
have the same
number of dimensions, the full convolution C = convn(A,B)
has
size size(A)+size(B)-1
.
When one or both of A
and B
are
of type single
, then the output is of type single
.
Otherwise, convn
converts inputs to type double
and
returns type double
.
Data Types: double
| single
More About
For discrete, N-dimensional arrays A and B, the following equation defines the convolution of A and B:
Each ki runs over all values that lead to legal subscripts of A and B.
Using this definition, convn
calculates the direct convolution
of two N-dimensional arrays, rather than the FFT-based
convolution.
Extended Capabilities
The
convn
function supports tall arrays with the following usage
notes and limitations:
If
shape
is'full'
(default), then the inputsA
andB
must not be empty and only one them can be a tall array.If
shape
is'same'
or'valid'
, thenB
cannot be a tall array.
For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
The convn
function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray
(Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)