Learn R Programming

imagefx (version 0.4.1)

cor.mat: Correlate Matrix Rows

Description

Wrapper function of ccf used to find best lag time between two vectors.

Usage

cor.mat(x, y, ...)

Arguments

x

Vector.

y

Vector.

Additional arguments to pass to ccf (e.g. max.lag)

Value

Scalar indicating the lag associated with the maximum correlation value between x and y.

See Also

ccf

Examples

Run this code
# NOT RUN {
## generate a time axis
tax = seq(0,10,by=0.1)

## generate two signals with a phase offset
sig1 <- sin(2*pi*1/2*tax)
sig2 <- sin(2*pi*1/2*tax + pi/2)

best.lag <- cor.mat(sig1,sig2)

################
### PLOTTING ###
################

plot(sig1,type='l',col='blue',main=paste('lag is: ',best.lag,sep=''))
lines(sig2,col='green')

# }

Run the code above in your browser using DataLab