crossCorrelationMetric: Correlation between channels

View source: R/crossCorrelationMetric.R

crossCorrelationMetricR Documentation

Correlation between channels


The crossCorrelationMetric() function calculates the maximum absolute correlation (polarity_check) and lag at maximum correlation (timing_drift) associated with two streams of seismic data.


crossCorrelationMetric(st1, st2, maxLagSecs=10, filter)



a Stream object containing a seismic signal


a Stream object containing a seismic signal


maximum number of seconds of lag to use


a signal package filter to be applied before cross-correlating, optional


Details of the algorithm are as follows:

  • Both signals are demeaned and detrended

  • If one signal has a higher sampling rate, it is decimated to the lower sampling rate using an IIR filter if it is a multiple of the lower sample rate. See (signal::decimate).

  • Both signals are filtered, by default with a Butterworth 2-pole low pass filter with a 0.1 Hz (10 second) corner frequency. See (signal::filter).

  • Signals are cross-correlated using the stats::ccf() function.

The maximum absolute correlation is saved as polarity_check while the lag at peak correlation is saved as timing_drift.

Note: For cross-correlation, seismic signals must not have any gaps – they must be contained in a single Trace object.


A list with one GeneralValueMetric object is returned. The metric names is polarity_check.


The metricList generated for this two-channel metric will have an additional sncl2 attribute identifying the SNCL in st2.


Jonathan Callahan (R code), Mary Templeton (algorithm)


  ## Not run: 
# Open a connection to IRIS DMC webservices
iris <- new("IrisClient")

# Get the same signal, shifted by 3 seconds
starttime <- as.POSIXct("2013-11-12 07:09:45",tz="GMT")
endtime <- starttime + 600
st1 <- getSNCL(iris,"NM.SLM.00.BHZ",starttime,endtime)
st2 <- getSNCL(iris,"NM.SLM.00.BHZ",starttime+3,endtime+3)

# Cross-correlate
## End(Not run)

IRISMustangMetrics documentation built on April 28, 2022, 1:06 a.m.