Main Content

conv

Convolution and polynomial multiplication of fi objects

Description

c = conv(a,b) returns the convolution of 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.

example

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. The vectors a and b can be different lengths or data types.

At least one input must be a fi object. If either input is a built-in data type, the conv function 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' — Full convolution. This option is the default shape.

  • 'same' — Central part of the convolution of the same size as a.

  • 'valid' — Only those parts of the convolution that are computed without zero-padded edges.

Data Types: char

Output Arguments

collapse all

Convolved vector, returned as a row or column vector.

In R2026a: The orientation of the output does not depend on the length of the input. When shape is set to 'full', the output is a column vector if and only if both inputs are column vectors. The conv function returns a row vector otherwise.

More About

collapse all

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.

Extended Capabilities

expand all

Version History

Introduced in R2009b

expand all

See Also