Main Content

conv

Convolution and polynomial multiplication

Description

example

w = conv(u,v)returns theconvolutionof vectorsuandv. Ifuandvare vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials.

example

w = conv(u,v,shape)returns a subsection of the convolution, as specified byshape. For example,conv(u,v,'same')returns only the central part of the convolution, the same size asu, andconv(u,v,'valid')returns only the part of the convolution computed without the zero-padded edges.

Examples

collapse all

Create vectorsuandvcontaining the coefficients of the polynomials x 2 + 1 and 2 x + 7 .

u = [1 0 1]; v = [2 7];

Use convolution to multiply the polynomials.

w = conv(u,v)
w =1×42 7 2 7

wcontains the polynomial coefficients for 2 x 3 + 7 x 2 + 2 x + 7 .

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 ofwislength(u)+length(v)-1, which in this example is9.

Create two vectors. Find the central part of the convolution ofuandvthat 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

whas a length of7. The full convolution would be of lengthlength(u)+length(v)-1, which in this example would be 10.

Input Arguments

collapse all

Input vectors, specified as either row or column vectors. The vectorsuandvcan be different lengths or data types.

Whenuorvare of typesingle, then the output is of typesingle. Otherwise,convconverts inputs to typedoubleand returns typedouble.

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

Subsection of the convolution, specified as'full','same', or“有效”.

'full'

满convolution (default).

'same'

Central part of the convolution of the same size asu.

“有效”

Only those parts of the convolution that are computed without the zero-padded edges. Using this option,length(w)ismax(length(u)-length(v)+1,0), except whenlength(v)is zero. Iflength(v) = 0, thenlength(w) = length(u).

More About

collapse all

Convolution

The convolution of two vectors,uandv, represents the area of overlap under the points asvslides acrossu. Algebraically, convolution is the same operation as multiplying polynomials whose coefficients are the elements ofuandv.

Letm = length(u)andn = length(v). Thenwis the vector of lengthm+n-1whosekth element is

w ( k ) = j u ( j ) v ( k j + 1 ) .

The sum is over all the values ofjthat 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

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

See Also

||||(Signal Processing Toolbox)|

Introduced before R2006a