Accelerating the pace of engineering and science

# Convolution

Convolution of two inputs

## Library

Signal Operations

dspsigops

## Description

The Convolution block convolves the first dimension of an N-D input array u, with the first dimension of an N-D input array v. The block can also independently convolve a column vector with the first-dimension of an N-D input array.

### Convolution with DSP System Toolbox Blocks

The general equation for convolution is

$y\left(k\right)=\sum _{n}^{}u\left(n-k\right)h\left(k\right)$

There are two DSP System Toolbox™ blocks that can be used for this purpose:

The Convolution block assumes that all of u and h are available at each Simulink® time step, and computes the entire convolution at every one.

The Discrete FIR Filter block can be used for convolving signals in situations where all of h is available at each time step, but u is a sequence that comes in over the life of the simulation. When you use the Discrete FIR Filter block, the convolution is computed only once.

How many convolutions do you intend to perform?

Many convolutions, one at each time step

• Convolution block

One convolution over the life of the simulation

• Convolution block

• Discrete FIR Filter block

How long are your input sequences?

Both sequences have a finite length

• Convolution block

• Discrete FIR Filter block

One sequence has an infinite (not predetermined) length

• Discrete FIR Filter block

How many of the inputs are scalar streams?

None

• Convolution block

• Discrete FIR Filter block

One or both

• Buffer block followed by the Convolution block

• Discrete FIR Filter block

### Convolving Two N-D Arrays

The block always computes the convolution of two N-D input arrays along the first dimension. 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 Mu-by-N-by-P array, and v is an Mv-by-N-by-P array, the output is an (Mu+Mv–1)-by-N-by-P array.

When the input to the Convolution block is a Mu-by-N matrix u and an Mv-by-N matrix v, the output, y, is a (Mu+Mv–1)-by-N matrix whose jth column has the following elements

$\begin{array}{cc}{y}_{i,j}=\sum _{k=0}^{\mathrm{max}\left({M}_{u},{M}_{v}\right)-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 indexed outside of their valid ranges. When both inputs are real, the output is real; when one or both inputs are complex, the output is complex.

### Convolving a Column Vector with an N-D Array

When one input is a column vector and the other is an N-D array, the block independently convolves the vector with the first dimension of the N-D input array. For example, when u is a Mu-by-1 column vector and v is an Mv-by-N matrix, the output is an (Mu+Mv–1)-by-N matrix whose jth column has the following elements

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

### Convolving Two Column Vectors

The Convolution block also accepts two column vector inputs. When u and v are column vectors with lengths Mu and Mv, the Convolution block performs the vector convolution

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

The output is a (Mu+Mv–1)-by-1 column vector.

### Fixed-Point Data Types

The following diagram shows the data types used within the Convolution block for fixed-point signals (time domain only).

You can set the product output, accumulator, and output data types in the block dialog as discussed in the next section.

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.

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

## Dialog Box

The Main pane of the Convolution block dialog appears as follows.

Computation domain

Set the domain in which the block computes convolutions:

• Time — The block computes in the time domain, which minimizes memory use.

• Frequency — The block computes in the frequency domain, which might require fewer computations than computing in the time domain, depending on the input length.

• Fastest — The block computes in the domain, which minimizes the number of computations.

The Data Types pane of the Convolution block dialog appears as follows.

 Note:   Fixed-point signals are only supported for the time domain. To use the parameters on this pane, make sure Time is selected for the Computation domain parameter on the Main pane.
Rounding mode

Select the rounding mode for fixed-point operations.

 Note:   The Rounding mode and Overflow mode settings have no effect on numerical results when all the following conditions exist:Product output data type is Inherit: Inherit via internal ruleAccumulator data type is Inherit: Inherit via internal ruleOutput data type is Inherit: Same as accumulatorWith these data type settings, the block is effectively operating in full precision mode.
Overflow mode

Select the overflow mode for fixed-point operations.

Product output data type

Specify the product output data type. See Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the product output data type in this block. You can set it to:

• A rule that inherits a data type, for example, Inherit: Inherit via internal rule

• An expression that evaluates to a valid data type, for example, fixdt([],16,0)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Product output data type parameter.

Accumulator data type

Specify the accumulator data type. See Fixed-Point Data Types for illustrations depicting the use of the accumulator data type in this block. You can set this parameter to:

• A rule that inherits a data type, for example, Inherit: Inherit via internal rule

• An expression that evaluates to a valid data type, for example, fixdt([],16,0)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Accumulator data type parameter.

Output data type

Specify the output data type. See Fixed-Point Data Types for illustrations depicting the use of the output data type in this block. You can set it to:

• A rule that inherits a data type, for example, Inherit: Same as accumulator

• An expression that evaluates to a valid data type, for example, fixdt([],16,0)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Output data type parameter.

Minimum

Specify the minimum value that the block should output. The default value is [] (unspecified). Simulink software uses this value to perform:

• Simulation range checking (see Signal Ranges)

• Automatic scaling of fixed-point data types

Maximum

Specify the maximum value that the block should output. The default value is [] (unspecified). Simulink software uses this value to perform:

• Simulation range checking (see Signal Ranges)

• Automatic scaling of fixed-point data types

Lock data type settings against changes by the fixed-point tools

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block mask.

## Supported Data Types

PortSupported Data Types

Input

• Double-precision floating point

• Single-precision floating point

• Fixed point (signed and unsigned)

• 8-, 16-, and 32-bit signed integers

• 8-, 16-, and 32-bit unsigned integers

Output

• Double-precision floating point

• Single-precision floating point

• Fixed point (signed and unsigned)

• 8-, 16-, and 32-bit signed integers

• 8-, 16-, and 32-bit unsigned integers