1 year ago

#296871

test-img

Ferus

Cross correlation gives incorrect result in scipy, python

I have a vector x with numbers and then I create a shifted copy and perform cross correlation, but yet I get that the lag with highest correlation is 0. I've tried to do the same with a vector with normally distributed numbers of the same size and then it works. I've also noticed that if I just use a smaller part of the vector it also works...

def align_time_series(a, b):
    mode="full"
    correlation = signal.correlate(a, b, mode=mode)
    lags = correlation_lags(a.size, b.size, mode=mode)
    lags_corr = pd.Series(correlation, lags)
    lags_corr.plot()
    print(lags_corr.idxmax())
    plt.axvline(lags_corr.idxmax())
    plt.show()

y = x[2000:]
align_time_series(x, y)
# => best lag is 0?

python

scipy

cross-correlation

0 Answers

Your Answer

Accepted video resources