Engee documentation

Correlation

A cross-correlation function of two input data.

blockType: Correlation

Path in the library:

/Signal Operations/Statistics/Correlation

Description

Block Correlation calculates the mutual correlation function of two input arrays of dimension N along the first dimension. The calculation can be performed in the time or frequency domain. You can specify an area using the Computation domain parameter.

In the time domain, the block convolves the first input signal with time-reversed complex conjugation of the second input signal .

In the frequency domain, to calculate the cross-correlation, the block:

  1. Performs the Fourier transform of both input signals, and .

  2. Multiplies and , where — complex coupling.

  3. Calculates the inverse Fourier transform for the product.

If you set the value for Computation domain Fastest, the block selects the area with the minimum number of calculations.

Ports

Entrance

Port_1 — first input of pass data:q[<br>] vector | the matrix

The block accepts multi-channel and multidimensional input data with a real or complex value. The input signal can be a fixed-point signal when you set the Computation domain value to Time. When one or both input signals are complex, the output signal is also complex.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Fixed

Support for complex numbers: Yes

Port_2 — second data input
vector | the matrix

The block accepts multi-channel and multidimensional input data with a real or complex value. The input signal can be a fixed-point signal when you set the Computation domain value to Time. When one or both input signals are complex, the output signal is also complex.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Fixed

Support for complex numbers: Yes

Output

Port_1 — cross-correlated output signal
vector | the matrix

The cross-correlated output of two input signals.

When the input data is a multidimensional array, the block outputs a multidimensional array where all dimensions, with the exception of the first dimension, match the input array. For example,

  • When the entrances and they have dimensions Mu by N by P and Mv by N by P, respectively, the block Correlation outputs an array Mu+Mv-1 to N to P.

  • When the input signals and they have dimensions Mu by N and Mv by N. The block outputs the matrix Mu+Mv-1 by N.

If one input signal represents a column vector and the other input signal represents a multidimensional array, the correlation unit calculates the cross-correlation of the vector with each column in the multidimensional array. For example:

  • When is the entrance represents the column vector Mu by 1, and — the matrix Mv on N, the block outputs the matrix Mu+Mv-1 on N.

  • Similarly, when and these are column vectors with lengths Mu and Mv, respectively, the block performs vector cross-correlation.

Data types: Float64

Support for complex numbers: Yes

Parameters

Main

Calculation domain — the area in which the block calculates the autocorrelation of
Time (default) | Frequency | Fastest
  • Time — Calculates cross-correlation in the time domain, which minimizes memory usage.

  • Frequency — calculates the cross-correlation in the frequency domain. For more information, see Algorithms.

  • Fastest — calculates the cross-correlation with a minimum number of calculations.

To process fixed-point signals, set this parameter to Time.

Data Types

Rounding mode - rounding mode
Floor (by default) | Ceiling | Convergent | Nearest | Round | Simplest | Zero

Select the rounding mode for fixed point operations. You can select:

  • Floor - rounds both positive and negative numbers to negative infinity.

  • Ceiling - rounds both positive and negative numbers to positive infinity.

  • Convergent - rounds a number to the nearest representable value. If the fractional part of a number ends in 5, the number is rounded to the nearest even integer.

  • Nearest - rounds the number to the nearest imaginable value. If the fractional part of the number ends in 5, the number is rounded to the nearest even integer.

  • Round - rounds the number to the nearest imaginable value. If the fractional part of a number ends in 5, positive numbers are rounded to positive infinity and negative numbers to negative infinity.

  • Simplest - automatically selects between rounding Floor and rounding Zero, to generate a rounding code that is as efficient as possible.

  • Zero - rounds a number to zero.

The block parameters are always rounded to the nearest representable value.

The settings Rounding mode and Saturate on integer overflow do not affect the numerical results if the conditions are met:

  • Product output is set to Inherit: Inherit via internal rule.

  • The parameter Accumulator is set to Inherit: Inherit via internal rule.

  • The Output setting is set to Inherit: Same as accumulator.

With these data type settings, the unit operates in full accuracy mode.

Saturate on integer overflow - saturation to integer on overflow
выключено (by default) | включено

A checkbox which, when selected, uses saturation arithmetic for integers and fixed-point numbers: when an overflow occurs, the result is automatically replaced by the maximum possible (modulo) value for the data type.

Action Rationale Effect on overflow Example

The checkbox Saturate on integer overflow is checked (enabled).

Overflow is possible for your model and you want the generated code to have an explicit overflow protection.

If an overflow occurs, the result is automatically replaced by the maximum possible (modulo) value for the data type.

The maximum value that can be represented by the data type Int8 (signed, 8-bit integer) is 127.

Any result of a block operation that exceeds this maximum value results in an 8-bit integer overflow. When checked, the block output is saturated to 127. Similarly, the block output is saturated at a minimum output value of -128.

The Saturate on integer overflow checkbox is unchecked (disabled).

You want to optimise the efficiency of your generated code.

You want to avoid over-determining how the block handles out-of-range signals.

Overflows are carried in an appropriate value that can be represented by a data type.

The maximum value that can be represented by the data type Int8 (signed, 8-bit integer) is 127.

Any result of a block operation that exceeds this maximum value results in an 8-bit integer overflow. If the check box is unchecked, software interprets the value causing the overflow as Int8, which may cause an unintended result. For example, the result of block 130 (binary code 1000 0010) expressed as Int8, is -126.

When you select this check box, saturation is applied to all internal operations in the block, not just the input/output data or the result.

Usage in program code

Block parameter

SaturateOnIntegerOverflow

Value

выключено | включено

By default

выключено

Product output - work output type
Inherit: Same as input (by default) | fixdt([],16,0)

Specify the output data type of the work. You can set this parameter to the following values:

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

  • An expression that results in a valid data type, for example, fixdt([],16,0).

Accumulator - battery data type
Inherit: Inherit via internal rule (by default) | Inherit: Same as input | fixdt([],16,0)

Accumulator specifies the data type of the output of the accumulation operation in the block. You can set this parameter to the following values:

  • Inherit: Inherit via internal rule - the block inherits the output data type of the work based on an internal rule.

  • Inherit: Same as input - block sets the accumulator data type to the same as the input data type.

  • fixdt(1,16,0) - block specifies an autosigned, binary, scaled fixed-point data type with a word length of 16 bits and a fractional length of 0.

Output data type - output data type
Float16 | Float32 | Float64 | Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | | UInt64 | UInt128 | Inherit: auto | Fixed point

Specify the type of output data.

The type can be inherited, specified directly, or expressed as a datatype object.

Usage in program code

Block parameter:

OutDataTypeStr

Value:

Float16 | Float32 | Float64 | Int8 | Int16 | Int32 | Int64 | Int128 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128 | Fixed

By default:

Float64

Output minimum - minimum output data value
[] (by default) | скаляр

The default minimum output data value is [], which is equivalent to -Inf.

This number must be a finite real double scalar value.

If an object with the bus type is specified as the data type for this block, do not specify a minimum value for the data in this block. Engee ignores this setting. Instead, set minimum values for the elements of the object specified as the data type.

Engee uses this value for execution:

  • Simulation range checks.

  • Automatic scaling of fixed point data types.

  • Optimising the code you generate from the model. This optimisation can remove algorithmic code and affect the results of some simulation modes.

The parameter does not saturate or trim the actual output signal. Instead, use the block Saturation.

Usage in program code

Block parameter

OutMin

Value

[ ] | скаляр

By default

[ ]

Output maximum - maximum output data value
[] (by default) | скаляр

The default maximum output data value is [], which is equivalent to Inf.

This number must be a finite real double scalar value.

If an object with the bus type is specified as the data type for this block, do not specify a maximum value for the data in this block. Engee ignores this setting. Instead, set the maximum values for the elements of the object specified as the data type.

Engee uses this value for execution:

  • Simulation range checks.

  • Automatic scaling of fixed point data types.

  • Optimising the code you generate from the model. This optimisation can remove algorithmic code and affect the results of some simulation modes.

The parameter does not saturate or trim the actual output signal. Instead, use the block Saturation.

Usage in program code

Block parameter

OutMax

Value

[ ] | скаляр

By default

[ ]

Lock data type settings against changes by the fixed-point tools - block automatic scaling of data types
выключено (by default) | включено

A check box that blocks automatic scaling of fixed-point data types.

Usage in program code

Block parameter

LockScale

Value

выключено | включено

By default

выключено

Additional Info

The cross-correlation function

The cross—correlation function is a measure of the similarity of two discrete-time sequences depending on the delay of one relative to the other.

For two deterministic inputs of length N or implementations of jointly stationary wide range random processes (WSS), and , the cross-correlation is calculated using the following relation:

where:

  • — delay

  • — complex coupling.

If the input data are implementations of shared stationary random processes, It is an irregular estimate of the theoretical cross-correlation:

ρ ,

where:

  • — the mathematical expectation operator.

Algorithms

Calculations in the time domain

When you set the value for the calculation area Time the algorithm calculates the cross-correlation of two signals in the time domain. The input signals can be fixed-point signals in this area.

Correlation of two two-dimensional arrays

When the input data is two two-dimensional arrays, -th column of output data, , contains these elements:

where:

  • — complex coupling.

  • — the input matrix is Mu by N.

  • — the input matrix is Mv by N.

  • — the matrix Mu+Mv-1 on N.

Input data and are equal to zero if they are indexed outside their acceptable ranges.

Correlation of a column vector with a two-dimensional array

When one input signal represents a column vector and the other input signal represents a two-dimensional array, the algorithm independently cross-correlates the input vector with each column of the two-dimensional array. -th column of output data, contains these elements:

where:

  • — complex coupling.

  • — the input matrix is Mu by 1.

  • — the input matrix is Mv by N.

  • — the matrix Mu+Mv-1 on N.

Input data and are equal to zero if they are indexed outside their acceptable ranges.

Correlation of two column vectors

When the input data is two column vectors, -th column of output data, , contains these elements:

where:

  • — complex coupling.

  • — the input matrix is Mu by 1.

  • — the input matrix is Mv by 1.

  • — the matrix Mu+Mv-1 by 1.

Input data and are equal to zero if they are indexed outside their acceptable ranges.

Calculations in the frequency domain

When you set the value for the calculation area frequency the algorithm calculates the cross-correlation in the frequency domain.

To calculate the cross-correlation, the algorithm:

  • Accepts the Fourier transform of both input signals, and .

  • Multiplies and , where — complex coupling.

  • Calculates the inverse Fourier transform for the product.

In this area, depending on the length of the input data, the algorithm may require fewer calculations.