Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

**MathWorks Machine Translation**

The automated translation of this page is provided by a general purpose third party translator tool.

MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.

Cross-correlation of two *N*-D arrays

**Library:**DSP System Toolbox / Statistics

The Correlation block computes the cross-correlation
of two *N*-D input arrays along the first-dimension.
The computation can be done in the time domain or frequency domain.
You can specify the domain through the **Computation domain** parameter.
In the time domain, the block convolves the first input signal, *u*,
with the time-reversed complex conjugate of the second input signal, *v*.
In the frequency domain, to compute the cross-correlation, the block:

Takes the Fourier transform of both input signals,

*U*and*V*.Multiplies

*U*and*V*, where * denotes the complex conjugate.^{*}Computes the inverse Fourier transform of the product.

If you set **Computation domain** to `Fastest`

,
the block chooses the domain that minimizes the number of computations.
For information on these computation methods, see Algorithms.

`Port_1`

— First data input signalvector | matrix |

The block accepts real-valued or complex-valued multichannel
and multidimensional inputs. The input can be a fixed-point signal
when you set the **Computation domain** to `Time`

.
When one or both of the input signals are complex, the output signal
is also complex.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `fixed point`

**Complex Number Support: **Yes

`Port_2`

— Second data input signalvector | matrix |

The block accepts real-valued or complex-valued multichannel
and multidimensional inputs. The input can be a fixed-point signal
when you set the **Computation domain** to `Time`

.
When one or both of the input signals are complex, the output signal
is also complex.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `fixed point`

**Complex Number Support: **Yes

`Port_1`

— Cross-correlated outputvector | matrix |

Cross-correlated output of the data input.

When the inputs are *N*-D arrays, the block
outputs an *N*-D array, where all the dimensions,
except for the first dimension, match with the input array. For example,

When the inputs

*u*and*v*have dimensions*M*-by-_{u}*N*-by-*P*and*M*-by-_{v}*N*-by-*P*, respectively, the Correlation block outputs an (*M*+_{u}*M*– 1)-by-_{v}*N*-by-*P*array.When the inputs

*u*and*v*have the dimensions*M*-by-_{u}*N*and*M*-by-_{v}*N*, the block outputs an (*M*+_{u}*M*– 1)-by-_{v}*N*matrix.

If one input is a column vector and the other input is an *N*-D
array, the Correlation block computes the cross-correlation
of the vector with each column in the *N*-D array.
For example,

When the input

*u*is an*M*-by-1 column vector and_{u}*v*is an*M*-by-_{v}*N*matrix, the block outputs an (*M*+_{u}*M*– 1)-by-_{v}*N*matrix.Similarly, when

*u*and*v*are column vectors with lengths*M*and_{u}*M*, respectively, the block performs the vector cross-correlation._{v}

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `fixed point`

**Complex Number Support: **Yes

`Computation domain`

— Domain in which the block computes the cross-correlation`Time`

(default) | `Frequency`

| `Fastest`

`Time`

— Computes the cross-correlation in the time domain, which minimizes the memory usage.`Frequency`

— Computes the cross-correlation in the frequency domain. For more information, see Algorithms.`Fastest`

— Computes the cross-correlation in the domain that minimizes the number of computations.

To cross-correlate fixed-point signals, set this parameter to `Time`

.

Fixed-point signals are supported for the time domain only.
To use these parameters, on the **Main** tab, set **Computation
domain** to `Time`

.

`Rounding mode`

— Method of rounding operation`Floor`

(default) | `Ceiling`

| `Convergent`

| `Nearest`

| `Round`

| `Simplest`

| `Zero`

Specify the rounding mode for fixed-point operations as one of the following:

`Floor`

`Ceiling`

`Convergent`

`Nearest`

`Round`

`Simplest`

`Zero`

For more details, see rounding mode.

The **Rounding mode** and **Saturate
on integer overflow** parameters have no effect on numerical
results when all these conditions are met:

**Product output**data type is`Inherit: Inherit via internal rule`

.**Accumulator**data type is`Inherit: Inherit via internal rule`

.**Output**data type is`Inherit: Same as accumulator`

.

With these data type settings, the block operates in full-precision mode.

`Saturate on integer overflow`

— Method of overflow actionoff (default) | on

When you select this parameter, the block saturates the result of its
fixed-point operation. When you clear this parameter, the block wraps
the result of its fixed-point operation. For details on
`saturate`

and `wrap`

, see overflow
mode for fixed-point operations.

The **Rounding mode** and **Saturate on
integer overflow** parameters have no effect on numeric
results when all these conditions are met:

**Product output**data type is`Inherit: Inherit via internal rule`

.**Accumulator**data type is`Inherit: Inherit via internal rule`

.

With these data type settings, the block operates in full-precision mode.

`Product output`

— Product output data type`Inherit: Inherit via internal rule`

(default) | `Inherit: Same as input`

| `fixdt([],16,0)`

**Product output** specifies the data type
of the output of a product operation in the Correlation block.
For more information on the product output data type, see Multiplication Data Types and
the 'Fixed-Point Conversion' section in Extended Capabilities.

`Inherit: Inherit via internal rule`

— The block inherits the product output data type based on an internal rule. For more information on this rule, see Inherit via Internal Rule.`Inherit: Same as input`

— The block specifies the product output data type to be the same as the input data type.`fixdt([],16,0)`

— The block specifies an autosigned, binary-point, scaled, fixed-point data type with a word length of 16 bits and a fraction length of 0.

Alternatively, you can set the **Product output** data
type by using the **Data Type Assistant**. To use
the assistant, click the **Show data type assistant** button.

For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).

`Accumulator`

— Accumulator data type`Inherit: Inherit via internal rule`

(default) | `Inherit: Same as input`

| `Inherit: Same as product output`

| `fixdt([],16,0)`

**Accumulator** specifies the data type of
output of an accumulation operation in the Correlation block.
For illustrations on how to use the accumulator data type in this
block, see the 'Fixed-Point Conversion' section in Extended Capabilities.

`Inherit: Inherit via internal rule`

— The block inherits the accumulator data type based on an internal rule. For more information on this rule, see Inherit via Internal Rule.`Inherit: Same as input`

— The block specifies the accumulator data type to be the same as the input data type.`Inherit: Same as product output`

— The block specifies the accumulator data type to be the same as the product output data type.`fixdt([],16,0)`

— The block specifies an autosigned, binary-point, scaled, fixed-point data type with a word length of 16 bits and a fraction length of 0.

Alternatively, you can set the **Accumulator** data
type by using the **Data Type Assistant**. To use
the assistant, click the **Show data type assistant** button.

For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).

`Output`

— Output data type`Inherit: Same as accumulator`

(default) | `Inherit: Same as input`

| `Inherit: Same as product output`

| `fixdt([],16,0)`

**Output** specifies the data type of the output
of the Correlation block. For more information on the
output data type, see the 'Fixed-Point Conversion' section in Extended Capabilities.

`Inherit: Same as input`

— The block specifies the output data type to be the same as the input data type.`Inherit: Same as product output`

— The block specifies the output data type to be the same as the product output data type.`Inherit: Same as accumulator`

— The block specifies the output data type to be the same as the accumulator data type.`fixdt([],16,0)`

— The block specifies an autosigned, binary-point, scaled, fixed-point data type with a word length of 16 bits and a fraction length of 0.

Alternatively, you can set the **Output** data
type by using the **Data Type Assistant**. To use
the assistant, click the **Show data type assistant** button.

For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).

`Output Minimum`

— Minimum value block can output`[]`

(default) | scalarSpecify the minimum value the block can output. Simulink^{®} software
uses this minimum value to perform:

Simulation range checking. See Signal Ranges (Simulink).

Automatic scaling of fixed-point data types.

`Output Maximum`

— Maximum value the block can output`[]`

(default) | scalarSpecify the maximum value the block can output. Simulink software uses this maximum value to perform:

Simulation range checking. See Signal Ranges (Simulink).

Automatic scaling of fixed-point data types.

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

— Prevent fixed-point tools from overriding data typesoff (default) | on

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

Cross-correlation is the measure of similarity of two discrete-time sequences as a function of the lag of one relative to the other.

For two length *N* deterministic inputs, or
realizations of jointly WSS random processes, *x* and *y*,
the cross-correlation is computed using the following relationship:

$$\begin{array}{l}{r}_{xy}(h)=\{\begin{array}{ll}{\displaystyle \sum _{n=0}^{N-h-1}x}(n+h){y}^{*}(n)\hfill & 0\le h\le N-1\hfill \\ {r}_{yx}^{*}(h)\hfill & -(N-1)\le h\le 0\hfill \end{array}\\ \end{array}$$

$${\rho}_{xy}(h)=E\{x(n+h){y}^{*}(n)\}$$

where E{ } is the expectation operator.

When you set the computation domain to time, the algorithm computes the cross-correlation of two signals in the time domain. The input signals can be fixed-point signals in this domain.

**Correlate Two 2-D Arrays**

When the inputs are two 2-D arrays, the *j*th
column of the output, *y _{u,v}*,
has these elements:

$$\begin{array}{l}{y}_{uv(i,j)}={\displaystyle \sum _{k=0}^{\mathrm{max}({M}_{u},{M}_{v})-1}{u}_{k,j}^{*}{v}_{(k+i),j}^{}}\text{}0\le i{M}_{v}\\ \\ {y}_{uv(i,j)}={y}_{vu(-i,j)}^{*}\text{}-{M}_{u}i0\end{array}$$

`*`

denotes the complex conjugate.*u*is an*M*-by-_{u}*N*input matrix.*v*is an*M*-by-_{v}*N*input matrix.*y*is an (_{u,v}*M*+_{u}*M*– 1)-by-_{v}*N*matrix.

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

**Correlate a Column Vector with a 2-D Array**

When one input is a column vector and the other input is a 2-D
array, the algorithm independently cross-correlates the input vector
with each column of the 2-D array. The *j*th column
of the output, *y _{u,v}*, has
these elements:

$$\begin{array}{l}{y}_{uv(i,j)}={\displaystyle \sum _{k=0}^{\mathrm{max}({M}_{u},{M}_{v})-1}{u}_{k}^{*}{v}_{(k+i),j}^{}}\text{}0\le i{M}_{v}\\ \\ {y}_{uv(i,j)}={y}_{vu(-i,j)}^{*}\text{}-{M}_{u}i0\end{array}$$

`*`

denotes the complex conjugate.*u*is an*M*-by-1 column vector._{u}*v*is an*M*-by-_{v}*N*matrix.*y*is an (_{u,v}*M*+_{u}*M*– 1)-by-_{v}*N*matrix.

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

**Correlate Two Column Vectors**

When the inputs are two column vectors, the *j*th
column of the output, *y _{u,v}*,
has these elements:

$$\begin{array}{l}{y}_{uv(i)}={\displaystyle \sum _{k=0}^{\mathrm{max}({M}_{u},{M}_{v})-1}{u}_{k}^{*}{v}_{(k+i)}^{}}\text{}0\le i{M}_{v}\\ \\ {y}_{uv(i)}={y}_{vu(-i)}^{*}\text{}-{M}_{u}i0\end{array}$$

`*`

denotes the complex conjugate.*u*is an*M*-by-1 column vector._{u}*v*is an*M*-by-1 column vector._{v}*y*is an (_{u,v}*M*+_{u}*M*– 1)-by-1 column vector._{v}

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

When you set the computation domain to frequency, the algorithm computes the cross-correlation in the frequency domain.

To compute the cross-correlation, the algorithm:

Takes the Fourier transform of both input signals,

*U*and*V*.Multiplies

*U*and*V*, where * denotes the complex conjugate.^{*}Computes 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 Simulink® Coder™.

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

The following diagram shows the data types the Correlation block uses for fixed-point signals (time domain only).

You can set the product output, accumulator, and output data
types on the **Data Types** tab of the block.

When the input is real, the output of the multiplier is in the product output data type. When the input is complex, the output of the multiplier 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 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.

Was this topic helpful?

You can also select a location from the following list:

- America 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)