# XCORR

## Purpose:

Calculates the cross-correlation using the convolution method.

## Syntax:

XCORR(series1, series2, norm)

series1

-

A series or array.

series2

-

A series or array.

norm

-

Optional. An integer, the normalization method:

 0: None (default) 1: Unity (-1 to 1) 2: Biased 3: Unbiased

A series.

## Example:

W1: gsin(1000, .001, 4)

W2: gsin(1000, .001, 4)

W3: xcorr(W1, W2)

Performs the cross-correlation of two sine waves. The peaks of the result indicate the two series are very similar at the time intervals where the peaks occur.

## Example:

W1: gsin(1000, .001, 4)

W2: gnorm(1000, .001)

W3: xcorr(W1, W1, 1)

W4: xcorr(W1, W2, 1) W3 displays the cross-correlation of a sine wave normalized to -1 and 1. W4 shows the cross-correlation between a sine wave and random noise. The normalized maximum of W3 is 1.0, indicating perfect correlation at time t = 0. Although the series of W4 displays some peaks, the normalized maximum is roughly 0.04 indicating little correlation between W1 and W2. For a graphical representation, OVERPLOT W4 in W3.

## Remarks:

The cross-correlation for a random process is defined as: where E is the expected value operator, x[n] and y[n] are a stationary random processes and * indicates complex conjugate. In practice, the cross-correlation is estimated because only a finite sample of an infinite duration random process is available. The estimate of the cross-correlation function for series of length N is defined as: XCORR performs cross-correlation by computing the direct convolution of the input series.

The output length L is:

L = length(series1) + length(series2) - 1

The zeroth lag component is the mid point of the series.

The BIASED normalization divides the result by N, the maximum length of the input series. The UNBIASED normalization divides the result by

N - abs(N - i - 1) + 1

where i is the index of the result with a start value of 1. For a 0 start index, the unbiased estimate becomes: The cross-correlation is used to determine how similar two series are to each other.

See FXCORR for the frequency domain implementation.

See XCOV to remove the mean from the input series before calculating the cross-correlation.

ACORR

ACOV

CONV

FACORR

FACOV

FCONV

FXCORR

FXCOV

XCOV