Corr

Description

The corr(vx, vy, k[, n]) function returns the correlation between two datasets using a lag size of k and an optional number of points n. For example, let f and g be two datasets. The cross correlation between the two datasets for the first N points using a lag size of k is defined as:

corr(f, g,,k,N)=Sigma(....)

If f and g are identical datasets, then the result is the auto-correlation.

Syntax

//when k is a scalar
double corr(dataset vx, dataset vy, int k[, int n])

//when k is a vector
dataset corr(dataset vx, dataset vy, dataset k[, int n])

Parameter

vx

a dataset

vy

a dataset

k

a lag size
Note: The lag argument k can be a scalar or a vector. When k is a vector, the correlation function returns a vector. Similarly, when k is a scalar, the correlation function returns a scalar.

n

the number of points of vx to take into account.

Return

Returns the correlation between two datasets using a lag size of k

Examples

The following script results in the cross correlation of the first 50 points of col(1) with col(2) using lag sizes from 1 to 10.

col(3) = corr(col(1), col(2), data(1, 10), 50);