Admin Production ni-theme
Current Publication

NormalizedCorrelate

LabWindows/CVI

NormalizedCorrelate

Advanced Analysis Library Only

AnalysisLibErrType NormalizedCorrelate (double arrayX[], ssize_t sizeOfX, double arrayY[], ssize_t sizeOfY, int algorithm, int normalization, double outputArray[]);

Purpose

Finds the correlation of the input arrays.

National Instruments recommends that you use this function instead of CorrelateEx. NormalizedCorrelate includes the normalization parameter, which makes NormalizedCorrelate more versatile than CorrelateEx.

The cross correlation Rxy(t) of the sequences x(t) and y(t) is defined by the following equation:

where the symbol denotes correlation.

The discrete implementation of this function is as follows. Let h represent a sequence whose indexing can be negative, let N be the number of elements in the input sequence arrayX, let M be the number of elements in the sequence arrayY, and assume that the indexed elements of arrayX and arrayY that lie outside their range are equal to zero, as shown by the following equations:

xj = 0, j < 0 or jN

and

yj = 0, j < 0 or jM.

Then NormalizedCorrelate obtains the elements of h using the following equation:

for j = -(N–1), -(N–2), ..., -1, 0, 1, ..., (M–2), (M–1)

The elements of the output sequence outputArray are related to the elements in the sequence h by

Rxyi = hi – (N–1)

for i = 0, 1, 2, ..., N+M–2.

Because you cannot index LabWindows/CVI arrays with negative numbers, the corresponding cross correlation value at t = 0 is the Nth element of the output sequence outputArray. Therefore, outputArray represents the correlation values that NormalizedCorrelate shifts N times in indexing.

In order to make the cross correlation calculation more accurate, normalization is required in some situations. This function provides biased and unbiased normalization.

  • Biased normalization

    If normalization is ALGORITHM_CONCOR_BIASED_NORMALIZATION, LabWindows/CVI applies biased normalization as follows:

    for j = 0, 1, 2, ..., M+N–2

    where Rxy is the cross correlation between x and y with no normalization.

  • Unbiased normalization

    If normalization is ALGORITHM_CONCOR_UNBIASED_NORMALIZATION, LabWindows/CVI applies unbiased normalization as follows:

    for j = 0, 1, 2, ..., M+N–2

    where Rxy is the cross correlation between x and y with no normalization. f(j) is:

    noloc_eps_croscor3.gif

Note Note  This function temporarily allocates memory for use as a work area. If NormalizedCorrelate cannot allocate memory, the function returns an error code.

Parameters

Input
Name Type Description
arrayX double [] First input array.
sizeOfX ssize_t Number of elements in arrayX.
arrayY double [] Second input array.
sizeOfY ssize_t Number of elements in arrayY.
algorithm int Specifies the correlation method to use. algorithm must be one of the following values. Note that slight numerical differences can exist between the two methods.

Constant Value Description
ALGORITHM_CONCOR_DIRECT 0 Computes the correlation using the direct method of linear correlation. If arrayX and arrayY are small, the ALGORITHM_CONCOR_DIRECT correlation method is typically faster.
ALGORITHM_CONCOR_FREQ_DOMAIN 1 Computes the correlation using an FFT-based technique. If arrayX and arrayY are large, the ALGORITHM_CONCOR_FREQ_DOMAIN correlation method is typically faster.
normalization int Specifies the normalization method to use to compute the cross correlation between arrayX and arrayY. normalization must be one of the following values:

Constant Value Description
ALGORITHM_CORCOR_NO_NORMALIZATION 0 No normalization is used in correlation computation.
ALGORITHM_CONCOR_UNBIASED_NORMALIZATION 1 Use max(n, m) to normalize the correlation result.
ALGORITHM_CONCOR_BIASED_NORMALIZATION 2 Use the number of elements in arrayX and arrayY for computing Rxy[j] to normalize Rxy[j], j = 0, 1, ..., (n+m–2).
Output
Name Type Description
outputArray double [] The correlation of arrayX and arrayY. This array must be at least (n + m – 1) elements long.

Return Value

Name Type Description
status AnalysisLibErrType A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants.

Additional Information

Library: Advanced Analysis Library

Include file: analysis.h

LabWindows/CVI compatibility: LabWindows/CVI 2009 and later