Definition function: Lag two datasets, so as to maximise their cross-correlation
def.lag2.RdFunction definition. Lag two datasets, so as to maximise their cross-correlation. Modified to expose freqThsh (cutoff frequency for high pass filter as an argument)
Usage
def.lag2(
refe,
meas,
freq,
freqThsh = (1/(2 * lagMax/freq)),
dataRefe = refe,
dataMeas = meas,
measVar = NULL,
lagMax = 2 * freq,
lagCnst = TRUE,
lagNgtvPstv = c("n", "p", "np")[3],
lagAll = TRUE,
hpf = TRUE,
fracMin = 0.1
)Arguments
- refe
A vector with variable in reference time frame. Of class numeric. (-)
- meas
A vector with variable in time frame to be adjusted. Of class numeric. (-)
- freq
Acquisition frequency of refe and meas. Of class ingeter. (Hz)
- freqThsh
cutoff frequency for the low end of the high pass filter. Defaults to 1 / (2 * lagMax / freq), the same as
eddy4r.base::def.lag()(Hz)- dataRefe
A matrix or data.frame with all data that carries the time frame of refe. Defaults to refe. Of any class. (-)
- dataMeas
A matrix or data.frame with all data that carries the time frame of meas. Defaults to meas. Of any class. (-)
- measVar
A vector specifying if only several columns in dataMeas shall be lagged. Defaults to NULL. Of class integer or character. (-)
- lagMax
Maximum lag, by default 2 x freq. Of class integer. (-)
- lagCnst
TRUE - interpret lagMax as maximum permissible lag; FALSE - start with lagMax as first estimate and increase iteratively. Defaults to TRUE. Of class logical. (-)
- lagNgtvPstv
"n" - consider negative lag times only, i.e. meas is expected to lag behind refe; "p" - consider positive lag times only, i.e. refe is expected to lag behind meas; "np" - consider negative and positive lag times. Defaults to "np". Of class character. (-)
- lagAll
TRUE - consider positive and negative correlations when finding lag time; FALSE - consider positive correlations only when finding lag time. Defaults to TRUE. Of class logical. (-)
- hpf
TRUE - apply Butterworth high-pass filter; FALSE - use raw data. Defaults to TRUE. Of class logical. (-)
- fracMin
Minimum fraction of data to attempt lag determination. Defaults to 0.1. Of class numeric. (-)
Value
Lagged input data and calculation results in a list consisting of:
dataRefe The reference data.
dataMeas The data that was lagged to coincide with the reference data.
lag The number of data points by which the lag correction was performed.
corrCros The cross-correction coefficient between refe and meas for the determined lag time.
Author
Stefan Metzger eddy4R.info@gmail.com