2
$\begingroup$

Using numpy's np.correlate() am trying to find the lag position of two data sets of different length.

When I use this operation by its own I find a lag position between my two data sets of 957. However when i implement a normalized cross correlation this changes to a lag of 1126. Can anyone explain why this is the case I would expect them to give the same lag.

My code for finding the lag in the "normal" cross correlation is:

corrs = np.correlate(a, b, mode="full") # a and b are pandas DataFrames
lag = (corrs.argmax() - corrs.size/2)

For the normalised correlation:

a = (a - np.mean(a)) / (np.std(a) * len(a)
b = (b - np.mean(b)) / (np.std(b)

norm_corrs = np.correlate(a, b, mode="full")
lag_norm = (norm_corrs.argmax() - norm_corrs.size/2)

In my case i get lag = 9 and lag_norm = 178!

Any pointers would be Great!

$\endgroup$
0
$\begingroup$

There are problems with cross-correlation:

It is difficult to understand the scoring value and both metrics must have the same amplitude : https://anomaly.io/understand-auto-cross-correlation-normalized-shift/ check this out for an example !

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.