conv
Convolution and polynomial multiplication
Syntax
Description
w = conv(
returns theconvolutionof vectorsu,v
)u
andv
. Ifu
andv
are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials.
Examples
Polynomial Multiplication via Convolution
Create vectorsu
andv
containing the coefficients of the polynomials
and
.
u = [1 0 1]; v = [2 7];
Use convolution to multiply the polynomials.
w = conv(u,v)
w =1×42 7 2 7
w
contains the polynomial coefficients for
.
Vector Convolution
Create two vectors and convolve them.
u = [1 1 1]; v = [1 1 0 0 0 1 1]; w = conv(u,v)
w =1×91 2 2 1 0 1 2 2 1
The length ofw
islength(u)+length(v)-1
, which in this example is9
.
Central Part of Convolution
Create two vectors. Find the central part of the convolution ofu
andv
that is the same size asu
.
u = [-1 2 3 -2 0 1 2]; v = [2 4 -1 1]; w = conv(u,v,'same')
w =1×715 5 -9 7 6 7 -1
w
has a length of7
. The full convolution would be of lengthlength(u)+length(v)-1
, which in this example would be 10.
Input Arguments
u,v
—Input vectors
vectors
Input vectors, specified as either row or column vectors. The vectorsu
andv
can be different lengths or data types.
Whenu
orv
are of typesingle
, then the output is of typesingle
. Otherwise,conv
converts inputs to typedouble
and returns typedouble
.
Data Types:double
|single
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|logical
Complex Number Support:Yes
shape
—Subsection of convolution
'full'
(default) |'same'
|“有效”
Subsection of the convolution, specified as'full'
,'same'
, or“有效”
.
'full' |
满convolution (default). |
'same' |
Central part of the convolution of the same size as |
“有效” |
Only those parts of the convolution that are computed without the zero-padded edges. Using this option, |
More About
Convolution
The convolution of two vectors,u
andv
, represents the area of overlap under the points asv
slides acrossu
. Algebraically, convolution is the same operation as multiplying polynomials whose coefficients are the elements ofu
andv
.
Letm = length(u)
andn = length(v)
. Thenw
is the vector of lengthm+n-1
whosek
th element is
The sum is over all the values ofj
that lead to legal subscripts foru(j)
andv(k-j+1)
, specificallyj
=
max(1,k+1-n):1:min(k,m)
. Whenm
=
n
, this gives
w(1) = u(1)*v(1) w(2) = u(1)*v(2)+u(2)*v(1) w(3) = u(1)*v(3)+u(2)*v(2)+u(3)*v(1) ... w(n) = u(1)*v(n)+u(2)*v(n-1)+ ... +u(n)*v(1) ... w(2*n-1) = u(n)*v(n)
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
Usage notes and limitations:
输入
u
andv
must be column vectors.If
shape
is'full'
(default), then only one ofu
orv
can be a tall array.If
shape
is'same'
or“有效”
, thenv
cannot be a tall array.
For more information, seeTall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
For information about C/C++ code generation limitations, seeVariable-Sizing Restrictions for Code Generation of Toolbox Functions(MATLAB Coder).
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Thread-Based Environment
Run code in the background using MATLAB®backgroundPool
or accelerate code with Parallel Computing Toolbox™ThreadPool
.
This function fully supports thread-based environments. For more information, seeRun MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, seeRun MATLAB Functions on a GPU(Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, seeRun MATLAB Functions with Distributed Arrays(Parallel Computing Toolbox).
Apri esempio
如果dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)
- 意大利(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- 联合王国(English)