This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

dsp.Crosscorrelator System object

Cross-correlation of two inputs

Description

The dsp.Crosscorrelator System object™ 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 Method property. In the time domain, the object convolves the first input signal, u, with the time-reversed complex conjugate of the second input signal, v. To compute the cross-correlation in the frequency domain, the object:

  1. Takes the Fourier transform of both input signals, resulting in U and V.

  2. Multiplies U and V*, where * denotes the complex conjugate.

  3. Computes the inverse Fourier transform of the product.

If you set Method to 'Fastest', the object chooses the domain that minimizes the number of computations. For information on these computation methods, see Algorithms.

To obtain the cross-correlation for two discrete-time deterministic inputs:

  1. Create the dsp.Crosscorrelator object and set its properties.

  2. 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).

Creation

Syntax

xcorr = dsp.Crosscorrelator
xcorr = dsp.Crosscorrelator(Name,Value)

Description

example

xcorr = dsp.Crosscorrelator returns a cross-correlator object, xcorr, that computes the cross-correlation of two inputs in the time domain or frequency domain.

example

xcorr = dsp.Crosscorrelator(Name,Value) returns a cross-correlator object with each specified property set to the specified value. Enclose each property name in single quotes.

Properties

expand all

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

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

  • 'Time Domain' –– Computes the cross-correlation in the time domain, which minimizes the memory usage.

  • 'Frequency Domain' –– 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 property to 'Time Domain'.

Fixed-Point Properties

Note

Fixed-point signals are supported for the time domain only. To use these properties, set Method to 'Time Domain'.

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.

Rounding method for fixed-point operations. For more details, see rounding mode.

Dependencies

This property is not visible and has no effect on the numerical results when the following conditions are met:

  • FullPrecisionOverride set to true.

  • FullPrecisionOverride set to false, OutputDataType set to 'Same as accumulator', ProductDataType set to 'Full precision', and AccumulatorDataType set to 'Full precision'

Under these conditions, the object operates in full precision mode.

In addition, if Method is set to either 'Frequency Domain' or 'Fastest', the RoundingMethod property does not apply.

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.

Dependencies

This property is not visible and has no effect on the numerical results when the following conditions are met:

  • FullPrecisionOverride set to true.

  • FullPrecisionOverride set to false, OutputDataType set to 'Same as accumulator', ProductDataType set to 'Full precision', and AccumulatorDataType set to 'Full precision'

Under these conditions, the object operates in full precision mode.

In addition, if Method is set to either 'Frequency Domain' or 'Fastest', the OverflowAction property does not apply.

Data type of the product output in this object, specified as one of the following:

  • 'Full precision' –– The product output data type has full precision.

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

  • 'Custom' –– The product output data type is specified as a custom numeric type through the CustomProductDataType property.

For more information on the product output data type, see Multiplication Data Types and the Fixed Point section.

Dependencies

This property applies when you set FullPrecisionOverride to false.

Word and fraction lengths of the product data type, specified as an autosigned numeric type with a word length of 32 and a fraction length of 30.

Dependencies

This property applies only when you set FullPrecisionOverride to false and ProductDataType to 'Custom'.

Data type of an accumulation operation in this object, specified as one of the following:

  • 'Full precision' –– The accumulation operation has full precision.

  • 'Same as product' –– The object specifies the accumulator data type to be the same as that of the product output data type.

  • 'Same as first input' –– The object specifies the accumulator data type to be the same as that of the first input data type.

  • 'Custom' –– The accumulator data type is specified as a custom numeric type through the CustomAccumulatorDataType property.

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

Dependencies

This property applies when you set FullPrecisionOverride to false.

Word and fraction lengths of the accumulator data type, specified as an autosigned numeric type with a word length of 32 and a fraction length of 30.

Dependencies

This property applies only when you set FullPrecisionOverride to false and AccumulatorDataType to 'Custom'.

Data type of the object output, specified as one of the following:

  • 'Same as accumulator' –– The output data type is the same as that of the accumulator output data type.

  • 'Same as first input' –– The output data type is the same as that of the first input data type.

  • 'Same as product' –– The output data type is the same as that of the product output data type.

  • 'Custom' –– The output data type is specified as a custom numeric type through the CustomOutputDataType property.

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

Dependencies

This property applies when you set FullPrecisionOverride to false.

Word and fraction lengths of the output data type, specified as an autosigned numeric type with a word length of 16 and a fraction length of 15.

Dependencies

This property applies only when you set FullPrecisionOverride to false and OutputDataType to 'Custom'.

Usage

For versions earlier than R2016b, use the step function to run the System object algorithm. The arguments to step are the object you created, followed by the arguments shown in this section.

For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Syntax

y = xcorr(u,v)

Description

example

y = xcorr(u,v) computes the cross-correlation of the two input signals, u and v.

Input Arguments

expand all

First data input signal, specified as a vector, matrix, or an N-D array. The object accepts real-valued or complex-valued multichannel and multidimensional inputs. The input can be a fixed-point signal when you set the Method property to 'Time Domain'. When one or both of the input signals are complex, the output signal is also complex. Both data inputs must have the same data type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Second data input signal, specified as a vector, matrix, or an N-D array. The object accepts real-valued or complex-valued multichannel and multidimensional inputs. The input can be a fixed-point signal when you set the Method property to 'Time Domain'. When one or both of the input signals are complex, the output signal is also complex. Both data inputs must have the same data type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Output Arguments

expand all

Cross-correlated output of the two input signals.

When the inputs are N-D arrays, the object outputs an N-D array. All the dimensions of the output array, except for the first dimension, match the input array. For example:

  • When the inputs u and v have dimensions Mu-by-N-by-P and Mv-by-N-by-P, respectively, the object outputs an (Mu + Mv – 1)-by-N-by-P array.

  • When the inputs u and v have the dimensions Mu-by-N and Mv-by-N, the object outputs an (Mu + Mv – 1)-by-N matrix.

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

  • When the input u is an Mu-by-1 column vector and v is an Mv-by-N matrix, the object outputs an (Mu + Mv – 1)-by-N matrix.

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Object Functions

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)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

expand all

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

Compute the cross-correlation between two sinusoidal signals using the dsp.Crosscorrelator object. Perform the computation in the time domain, which is the object's default setting.

xcorr = dsp.Crosscorrelator;
t = 0:0.001:1;
x1 = sin(2*pi*2*t)+0.05*sin(2*pi*50*t);
x2 = sin(2*pi*2*t);
y = xcorr(x1,x2);
figure
plot(t,x1,'b',t,x2,'g')
xlabel('Time')
ylabel('Signal Amplitude')
legend('Input signal 1','Input signal 2')

Plot the correlated output.

figure, 
plot(y)
title('Correlated output')

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

Compute the cross-correlation of a noisy input signal with its delayed version. The peak of the correlation output occurs at the lag, which corresponds to the delay between the signals.

Use randn to create the white Gaussian noisy input, x. Create a delayed version of this input, x1, using the dsp.Delay object.

S = rng('default');
x = randn(100,1);
delay = dsp.Delay(10);
x1 = delay(x);

Compute the cross-correlation between the two inputs. Plot the correlation output with respect to the lag between the inputs.

xcorr = dsp.Crosscorrelator;
y = xcorr(x1,x);
lags = 0:99;
stem(lags,y(100:end),'markerfacecolor',[0 0 1])
axis([0 99 -125 125])
xlabel('Lags')
title('Cross-Correlation of Input Noise and Delayed Version')

The correlation sequence peaks when the lag is 10, indicating that the correct delay between the two signals is 10 samples.

More About

expand all

Algorithms

expand all

Extended Capabilities

See Also

System Objects

Blocks

Introduced in R2012a