Engee documentation

conv

Convolution and polynomial multiplication.

Library

EngeeDSP

Syntax

Function call

  • w = conv(u,v) — returns convolution of vectors u and v. If u and v They are vectors of polynomial coefficients, their convolution is equivalent to multiplying two polynomials.

  • w = conv(u,v,shape) — returns the part of the convolution specified by the parameter shape. For example, conv(u,v,'same') returns only the central part of the convolution of the same size as u, and conv(u,v,'valid') returns only the part of the convolution calculated without the borders padded with zeros.

Arguments

Input arguments

# u is the input vector

+ vector

Details

The input vector, specified as a row vector or column vector. Vectors u and v they can have different length and data type.

If u has a type Float32, then the output data is also of type Float32. Otherwise, the function conv converts the input data to a type Float64 and returns the type Float64.

Data types

Float64, Float32, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Bool

Support for complex numbers

Yes

# v is the input vector

+ vector

Details

The input vector, specified as a row vector or column vector. Vectors u and v they can have different length and data type.

If v has a type Float32, then the output data is also of type Float32. Otherwise, the function conv converts the input data to a type Float64 and returns the type Float64.

Data types

Float64, Float32, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Bool

Support for complex numbers

Yes

# shape — the convolution subsection

+ 'full' (by default) | 'same' | 'valid'

Details

The convolution subsection, defined as 'full', 'same' or 'valid'.

'full'

Full convolution (by default).

'same'

The central part of the convolution is the same size as u.

'valid'

Only those parts of the convolution that are calculated without zero-padded borders. When using this option length(w) equal to max(length(u)-length(v)+1,0), except when length(v) it is equal to zero. If length(v)=0 Then length(w)=length(u).

Output arguments

# w — output vector

Details

The output vector that returns the convolution of two vectors u and v.

Additional Info

Convolution

Convolution of two vectors u and v it represents the area of overlap under the points when sliding v by u. From an algebraic point of view, convolution is the same operation as multiplying polynomials whose coefficients are elements. u and v.

Let m = length(u) and n = length(v). Then w — length vector m+n-1, `k`the th element of which is equal to

The sum is taken for all values j which lead to valid indexes for u(j) and v(k-j+1), namely j=max(1,k+1-n):1:min(k,m). By m=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)

Using this definition, the function conv calculates a direct convolution of two vectors, not an FFT-based convolution.