Correlation
Crosscorrelation of two inputs
Libraries:
DSP System Toolbox /
Statistics
Description
The Correlation block computes the crosscorrelation of two ND input arrays along the firstdimension. 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 timereversed complex conjugate of the second input signal, v. In the frequency domain, to compute the crosscorrelation, 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.
Ports
Input
Port_1 — First data input signal
vector  matrix  ND array
The block accepts realvalued or complexvalued multichannel and
multidimensional inputs. The input can be a fixedpoint 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
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Complex Number Support: Yes
Port_2 — Second data input signal
vector  matrix  ND array
The block accepts realvalued or complexvalued multichannel and
multidimensional inputs. The input can be a fixedpoint 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
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Complex Number Support: Yes
Output
Port_1 — Crosscorrelated output
vector  matrix  ND array
Crosscorrelated output of the two input signals.
When the inputs are ND arrays, the object outputs an ND 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_{u}byNbyP and M_{v}byNbyP, respectively, the Correlation block outputs an (M_{u} + M_{v} – 1)byNbyP array.
When the inputs u and v have the dimensions M_{u}byN and M_{v}byN, the block outputs an (M_{u} + M_{v} – 1)byN matrix.
If one input is a column vector and the other input is an ND array, the Correlation block computes the crosscorrelation of the vector with each column in the ND array. For example,
When the input u is an M_{u}by1 column vector and v is an M_{v}byN matrix, the block outputs an (M_{u} + M_{v} – 1)byN matrix.
Similarly, when u and v are column vectors with lengths M_{u} and M_{v}, respectively, the block performs the vector crosscorrelation.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
 fixed point
Complex Number Support: Yes
Parameters
Main Tab
Computation domain — Domain in which the block computes the crosscorrelation
Time
(default)  Frequency
 Fastest
Time
— Computes the crosscorrelation in the time domain, which minimizes the memory usage.Frequency
— Computes the crosscorrelation in the frequency domain. For more information, see Algorithms.Fastest
— Computes the crosscorrelation in the domain that minimizes the number of computations.
To crosscorrelate fixedpoint signals, set this parameter to
Time
.
Data Types Tab
Note
Fixedpoint 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 fixedpoint operations as one of the following:
Floor
Ceiling
Convergent
Nearest
Round
Simplest
Zero
For more details, see rounding mode.
Note
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 fullprecision mode.
Saturate on integer overflow — Method of overflow action
off (default)  on
When you select this parameter, the block saturates the result of its
fixedpoint operation. When you clear this parameter, the block wraps
the result of its fixedpoint operation. For details on
saturate
and wrap
, see overflow
mode for fixedpoint operations.
Note
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 fullprecision 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 FixedPoint Data Types.
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, binarypoint, scaled, fixedpoint 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 FixedPoint Data Types.
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, binarypoint, scaled, fixedpoint 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 FixedPoint Data Types.
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, binarypoint, scaled, fixedpoint 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)  scalar
Specify the minimum value the block can output. Simulink^{®} software uses this minimum value to perform:
Simulation range checking. See Specify Signal Ranges (Simulink).
Automatic scaling of fixedpoint data types.
Output Maximum — Maximum value the block can output
[]
(default)  scalar
Specify the maximum value the block can output. Simulink software uses this maximum value to perform:
Simulation range checking. See Specify Signal Ranges (Simulink).
Automatic scaling of fixedpoint data types.
Lock data type settings against changes by the fixedpoint tools — Prevent fixedpoint tools from overriding data types
off
(default)  on
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify in the block dialog box.
Block Characteristics
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

More About
CrossCorrelation
Crosscorrelation is the measure of similarity of two discretetime sequences as a function of the lag of one relative to the other.
For two lengthN deterministic inputs or realizations of jointly widesense stationary (WSS) random processes, x and y, the crosscorrelation is computed using the following relationship:
$$\begin{array}{l}{r}_{xy}(h)=\{\begin{array}{ll}{\displaystyle \sum _{n=0}^{Nh1}x}(n+h){y}^{*}(n)\hfill & 0\le h\le N1\hfill \\ {r}_{yx}^{*}(h)\hfill & (N1)\le h\le 0\hfill \end{array}\\ \end{array}$$
where h is the lag and * denotes the complex conjugate. If the inputs are realizations of jointly WSS stationary random processes, r_{xy}(h) is an unnormalized estimate of the theoretical crosscorrelation:
$${\rho}_{xy}(h)=E\{x(n+h){y}^{*}(n)\}$$
where E{ } is the expectation operator.
FixedPoint Data Types
The following diagram shows the data types the Correlation block uses for fixedpoint 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.
Note
When one or both of the inputs are signed fixedpoint 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 fixedpoint signals.
Algorithms
TimeDomain Computation
When you set the computation domain to time, the algorithm computes the crosscorrelation of two signals in the time domain. The input signals can be fixedpoint signals in this domain.
Correlate Two 2D Arrays
When the inputs are two 2D arrays, the jth column of the output, y_{uv}, 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}$$
where:
*
denotes the complex conjugate.u is an M_{u}byN input matrix.
v is an M_{v}byN input matrix.
y_{u,v} is an (M_{u} + M_{v} – 1)byN matrix.
Inputs u and v are zero when indexed outside their valid ranges.
Correlate a Column Vector with a 2D Array
When one input is a column vector and the other input is a 2D array, the algorithm independently crosscorrelates the input vector with each column of the 2D array. The jth 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}$$
where:
*
denotes the complex conjugate.u is an M_{u}by1 column vector.
v is an M_{v}byN matrix.
y_{uv} is an (M_{u} + M_{v} – 1)byN 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 jth column of the output, y_{uv}, 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}$$
where:
*
denotes the complex conjugate.u is an M_{u}by1 column vector.
v is an M_{v}by1 column vector.
y_{uv} is an (M_{u} + M_{v} – 1)by1 column vector.
Inputs u and v are zero when indexed outside their valid ranges.
FrequencyDomain Computation
When you set the computation domain to frequency, the algorithm computes the crosscorrelation in the frequency domain.
To compute the crosscorrelation, 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.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
FixedPoint Conversion
Design and simulate fixedpoint systems using FixedPoint Designer™.
Version History
Introduced before R2006a
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
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: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 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)