Python Cross-Correlation – How to Estimate the Delay Between Two Signals

cross correlationpythontime series

I have two voltage time series from two sides of a battery with 20 seconds resolution. The signals are non-periodic and voltage2 is usually half the voltage. There are reasons to believe that there may be a slight delay in the signals and I wonder how I can estimate it.

Example of the data:

Data example

Best Answer

To estimate the time delay between two signals you can use the cross-correlation (np.correlate) between them and find the argmax of the cross-correlation function

$$\tau_{\text{delay}} = \text{argmax }((f * g)(t)),$$

this will estimate the time offset where the signals are best aligned.

Another possible way is to use peak-detection (scipy.signal.find_peak) and find matching peaks (e.g. with max or min in each signal or more sophisticated methods) and calculate the offset.

Related Question