Convolution of two signals

The `dsp.Convolver`

System
object™ convolves the first dimension of an *N*-D input array,
*u*, with the first dimension of an *N*-D input array,
*v*. You can convolve the inputs in the time domain or frequency domain. In
the time domain, the object convolves the first input with the second input. In the frequency
domain, the object multiplies the Fourier transforms of both the inputs, and computes the
inverse Fourier transform of the product. In this domain, depending on the input length, the
object can require fewer computations. For more information on the two computation methods,
see Algorithms.

To convolve two inputs:

Create the

`dsp.Convolver`

object and set its properties.Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

creates a convolution
System
object, `cnv`

= dsp.Convolver`cnv`

, to convolve two inputs in the time domain or
frequency domain.

creates a convolution System object, `cnv`

= dsp.Convolver(`Name,Value`

)`cnv`

, with each specified property set
to the specified value. Enclose each property name in single quotes.

```
cnv = dsp.Convolver('Method','Frequency
Domain')
```

Unless otherwise indicated, properties are *nontunable*, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
`release`

function unlocks them.

If a property is *tunable*, you can change its value at
any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

`Method`

— Domain for computing convolutions`'Time Domain'`

(default) | `'Frequency Domain'`

| `'Fastest'`

Domain in which the System object computes convolutions, specified as one of the following:

`'Time Domain'`

–– Computes the convolutions in the time domain, which minimizes memory usage. For more information, see Time-Domain Computation.`'Frequency Domain'`

–– Computes the convolutions in the frequency domain, which can require fewer computations depending on the input length. For more information, see Frequency-Domain Computation.`'Fastest'`

–– Computes the convolutions in the domain that minimizes the number of computations.

Fixed-point signals are supported for the time domain only. To use the following
fixed-point properties, set `Method`

to ```
'Time
Domain'
```

.

`FullPrecisionOverride`

— Full-precision override for fixed-point arithmetic`true`

(default) | `false`

Flag to use full-precision rules for fixed-point arithmetic, specified as one of the following:

`true`

–– The object computes all internal arithmetic and output data types using the full-precision rules. These rules provide the most accurate fixed-point numerics. In this mode, other fixed-point properties do not apply. No quantization occurs within the object. Bits are added, as needed, to ensure that no roundoff or overflow occurs.`false`

–– Fixed-point data types are controlled through individual fixed-point property settings.

For more information, see Full Precision for Fixed-Point System Objects and Set System Object Fixed-Point Properties.

`RoundingMethod`

— Rounding method`'Floor'`

(default) | `'Ceiling'`

| `'Convergent'`

| `'Nearest'`

| `'Round'`

| `'Simplest'`

| `'Zero'`

Select the rounding mode for fixed-point operations.

This property applies when you set the `FullprecisionOverride`

property to `false`

and at least one of the
`ProductDataType`

, `AccumulatorDataType`

, and
`OutputDataType`

properties to any option other than
`'Full precision'`

.

`OverflowAction`

— Overflow action`'Wrap'`

(default) | `'Saturate'`

The overflow action for fixed-point operations, specified as one of the following:

`'Wrap'`

–– The object wraps the result of its fixed-point operations.`'Saturate'`

–– The object saturates the result of its fixed-point operations.

For more details on overflow actions, see overflow mode for fixed-point operations.

This property applies when you set the `FullprecisionOverride`

property to `false`

and at least one of the
`ProductDataType`

, `AccumulatorDataType`

, and
`OutputDataType`

properties to any option other than
`'Full precision'`

.

`ProductDataType`

— Product output data type`'Full precision'`

(default) | `'Custom'`

| `'Same as first input'`

Data type of the output of a product operation in the
`dsp.Convolver`

object, specified as one of the following:

`'Full precision'`

–– The object computes the product output data type using the full-precision rules. These rules provide the most accurate fixed-point numerics. No quantization occurs. Bits are added, as needed, to ensure that no roundoff or overflow occurs.`'Custom'`

–– The product output data type is specified as a custom numeric type through the`CustomProductDataType`

property. The rounding method and the overflow action are specified through the`RoundingMethod`

and`OverflowAction`

properties.`'Same as first input'`

–– The object specifies the product output data type to be the same as the first input data type.

For more information on the product output data type, see the Fixed Point section.

`CustomProductDataType`

— Product word and fraction lengths`numerictype([],32,30)`

(default)The product output data type, specified as an autosigned numeric type with a word length of 32 and a fraction length of 30.

This property applies only when you set `ProductDataType`

to
`'Custom'`

.

`AccumulatorDataType`

— Accumulator data type`'Full precision'`

(default) | `'Custom'`

| `'Same as first input'`

| `'Same as product'`

Data type of the output of an accumulation operation in the
`dsp.Convolver`

object, specified as one of the following:

`'Full precision'`

–– The object computes the accumulator data type using the full precision rules. These rules provide the most accurate fixed-point numerics. No quantization occurs. Bits are added, as needed, to ensure that no roundoff or overflow occurs.`'Custom'`

–– The accumulator data type is specified as a custom numeric type through the`CustomAccumulatorDataType`

property. The rounding method and the overflow action are specified through the`RoundingMethod`

and the`OverflowAction`

properties.`'Same as first input'`

–– The object specifies the accumulator data type to be the same as the first input data type.`'Same as product'`

–– The object specifies the accumulator data type to be the same as the product data type.

For more information on the accumulator data type, see the Fixed Point section.

`CustomAccumulatorDataType`

— Accumulator word and fraction lengths`numerictype([],32,30)`

(default)The accumulator data type, specified as an auto signed numeric type with a word length of 32 and a fraction length of 30.

This property applies only when you set `AccumulatorDataType`

to `'Custom'`

.

`OutputDataType`

— Output data type`'Same as accumulator'`

(default) | `'Custom'`

| `'Same as first input'`

| `'Same as product'`

Data type of the output of the `dsp.Convolver`

object, specified as
one of the following:

`'Same as accumulator'`

–– The object specifies the output data type to be the same as the accumulator data type. For more details on the accumulator data type, see the AccumulatorDataType property.`'Custom'`

–– The output data type is specified as a custom numeric type through the`CustomOutputDataType`

property. The rounding method and the overflow action are specified through the`RoundingMethod`

and the`OverflowAction`

properties.`'Same as first input'`

–– The object specifies the output data type to be the same as the first input data type.`'Same as product'`

–– The object specifies the output data type to be the same as the product data type.

For more information on the output data type, see the Fixed Point section.

`CustomOutputDataType`

— Output word and fraction lengths`numerictype([],16,15)`

(default)The output data type, specified as an autosigned numeric type with a word length of 16 and a fraction length of 15.

This property applies only when you set `OutputDataType`

to
`'Custom'`

.

`input1`

— First data inputvector | matrix |

First data input, specified as a vector, matrix, or *N*-D array.
If the input is a matrix or an array, all the dimensions of both the inputs, except
for the first dimension, must be the same.

**Example: **ones(10,3,2)

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `fi`

**Complex Number Support: **Yes

`input2`

— Second data inputvector | matrix |

Second data input, specified as a vector, matrix, or *N*-D array.
If the input is a matrix or an array, all the dimensions of both the inputs, except
for the first dimension, must be the same.

**Example: **randn(4,3,2)

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `fi`

**Complex Number Support: **Yes

`cnvOut`

— Convolved outputvector | matrix |

The convolved output of the two inputs, returned as a vector, matrix, or
*N*-D array.

When both inputs are

*N*-D arrays, the size of their first dimension can differ, but the size of all other dimensions must be equal. For example, when*u*is an*M*-by-_{u}*N*-by-*P*array, and*v*is an*M*-by-_{v}*N*-by-*P*array, the output is an (*M*–1)-by-_{u}+M_{v}*N*-by-*P*array.When one input is a column vector and the other is an

*N*-D array, the object independently convolves the vector with the first dimension of the*N*-D input array. For example, when*u*is an*M*-by-1 column vector and_{u}*v*is an*M*-by-_{v}matrix, the output is an (*N**M*–1)-by-_{u}+M_{v}*N*matrix.When

*u*and*v*are column vectors with lengths*M*and_{u}*M*, the object performs the vector convolution. The output is an (_{v}*M*–1)-by-1 column vector._{u}+M_{v}

When both the inputs are real, the output is real. When one or both inputs are complex, the output is complex.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `fi`

**Complex Number Support: **Yes

To use an object function, specify the
System
object as the first input argument. For
example, to release system resources of a System
object named `obj`

, use
this syntax:

release(obj)

**Note**: If you are using R2016a or earlier, replace each call to the object with the equivalent step syntax. For example, `obj(x)`

becomes `step(obj,x)`

.

Create a `dsp.Convolver`

object.

conv = dsp.Convolver

conv = dsp.Convolver with properties: Method: 'Time Domain' Show all properties

Convolve two rectangular sequences.

x = ones(10,1); y = conv(x,x);

Plot the resulting convolved sequence, which is a triangular sequence.

plot(y)

The *convolution* of two signals is the integral
that measures the amount of overlap of one signal as it is shifted over another
signal.

The convolution of two discrete time sequences,
*u*[*n*] and *v*[*n*],
is given by the following equation:

$$y(k)={\displaystyle \sum _{n}^{}u(n-k)v(k)}$$

When you set the computation domain to *time*, the algorithm computes
the convolution of the two inputs in the time domain.

When the two inputs, *u* and *v*, are of size
*M _{u}*-by-

$$\begin{array}{cc}{y}_{i,j}={\displaystyle \sum _{k=0}^{\mathrm{max}({M}_{u},{M}_{v})-1}{u}_{k,j}{v}_{\left(i-k\right),j}}& 0\le i\le \left({M}_{u}+{M}_{v}-2\right)\end{array}$$

Inputs *u* and *v* are zero when they are indexed
outside their valid ranges.

When *u* is an *M _{u}*-by-1 column
and

$$\begin{array}{cc}{y}_{i,j}={\displaystyle \sum _{k=0}^{\mathrm{max}({M}_{u},{M}_{v})-1}{u}_{k}{v}_{\left(i-k\right),j}}& 0\le i\le \left({M}_{u}+{M}_{v}-2\right)\end{array}$$

When both the inputs are column vectors with lengths
*M _{u}* and

$$\begin{array}{cc}{y}_{i}={\displaystyle \sum _{k=0}^{\mathrm{max}({M}_{u},{M}_{v})-1}{u}_{k}{v}_{\left(i-k\right)}}& 0\le i\le \left({M}_{u}+{M}_{v}-2\right)\end{array}$$

The output is an
(*M*_{u}+*M*_{v}–1)-by-1
column vector.

When you set the computation domain to *frequency*, the algorithm
computes the convolution in the frequency domain.

In this domain, the algorithm computes the convolution sequence by taking the Fourier transform of both the input signals, multiplying the Fourier transforms, and taking the inverse Fourier transform of the product. In this domain, depending on the input length, the algorithm can require fewer computations.

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

See System Objects in MATLAB Code Generation (MATLAB Coder).

Design and simulate fixed-point systems using Fixed-Point Designer™.

The following diagram shows the data types used within the
`dsp.Convolver`

System
objectfor fixed-point signals.

Fixed-point signals are supported for the time domain only.

The output of the multiplier is in the product output data type when the input is real. When the input is complex, the result of the multiplication is in the accumulator data type. For details on the complex multiplication performed, see Multiplication Data Types.

When one or both of the inputs are signed fixed-point signals, all internal object data
types are signed fixed point. The internal data types are unsigned fixed point only when
*both* inputs are unsigned fixed-point signals.

A modified version of this example exists on your system. Do you want to open this version instead?

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

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: .

Select web siteYou can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

- América Latina (Español)
- Canada (English)
- United States (English)

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)