# conv

Convolution and polynomial multiplication of fi objects

## Description

example

c = conv(a,b) returns the convolution of input vectors a and b, at least one of which must be a fi object.

example

c = conv(a,b,shape) returns a subsection of the convolution, as specified by shape.

## Examples

collapse all

Find the convolution of a 22-sample sequence with a 16-tap FIR filter.

x is a 22-sample sequence of signed values with a word length of 16 bits and a fraction length of 15 bits. h is the 16-tap FIR filter.

u = (pi/4)*[1 1 1 -1 -1 -1 1 -1 -1 1 -1];
x = fi(kron(u,[1 1]));
h = firls(15, [0 .1 .2 .5]*2, [1 1 0 0]);

Because x is a fi object, you do not need to cast h into a fi object before performing the convolution operation. The conv function does this automatically using best-precision scaling.

Use the conv function to convolve the two vectors.

y = conv(x,h);

The operation results in a signed fi object y with a word length of 36 bits and a fraction length of 31 bits. The default fimath properties associated with the inputs determine the numerictype of the output. The output does not have a local fimath.

Create two fi vectors. Find the central part of the convolution of a and b that is the same size as a.

a = fi([-1 2 3 -2 0 1 2]);
b = fi([2 4 -1 1]);
c = conv(a,b,'same')
c =

15     5    -9     7     6     7    -1

DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 34
FractionLength: 25

c has a length of 7. The full convolution would be of length length(a)+length(b)-1, which in this example would be 10.

## Input Arguments

collapse all

Input vectors, specified as either row or column vectors.

If either input is a built-in data type, conv casts it into a fi object using best-precision rules before the performing the convolution operation.

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

Subset of convolution, specified as one of these values:

• 'full' — Returns the full convolution. This option is the default shape.

• 'same' — Returns the central part of the convolution that is the same size as input vector a.

• 'valid' — Returns only those parts of the convolution that the function computes without zero-padded edges. Using this option, the length of output vector c is max(length(a)-max(0,length(b)-1),0).

Data Types: char

collapse all

### Convolution

The convolution of two vectors, u and v, represents the area of overlap under the points as v slides across u. Algebraically, convolution is the same operation as multiplying polynomials whose coefficients are the elements of u and v.

Let m = length(u) and n = length(v). Then w is the vector of length m+n-1 whose kth element is

$w\left(k\right)=\sum _{j}u\left(j\right)v\left(k-j+1\right).$

The sum is over all the values of j that lead to legal subscripts for u(j) and v(k-j+1), specifically j = max(1,k+1-n):1:min(k,m). When 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)

## Algorithms

The fimath properties associated with the inputs determine the numerictype properties of output fi object c:

• If either a or b has a local fimath object, conv uses that fimath object to compute intermediate quantities and determine the numerictype properties of c.

• If neither a nor b have an attached fimath, conv uses the default fimath to compute intermediate quantities and determine the numerictype properties of c.

If either input is a built-in data type, conv casts it into a fi object using best-precision rules before the performing the convolution operation.

The output fi object c always uses the default fimath.

## Version History

Introduced in R2009b