I tried using np.correlate and signal.correlate functions to compute the time delay between two time series. But the lag is not corresponding to actual time delay that can be inferred from the graph.
x = 0.4
# x = 0.25
# x = 0.1
# n = 100000
# n_repeats = 100
n = 100
n_repeats = 1
# Get correlations
t = np.linspace(0, n_repeats,n)
sin_delay = lambda delay: np.sin(2.0 * np.pi * (t - delay))
signal1 = sin_delay(delay=0)
signal2 = sin_delay(delay=x)
corr11 = signal.correlate(signal1, signal1, mode='full')
corr12 = signal.correlate(signal1, signal2, mode='full')
a1 = np.argmax(corr11)
a2 = np.argmax(corr12)
# Print output
print(a1, a2, x, n_repeats * (a1 - a2) / n)
I used the code from https://stackoverflow.com/a/64030308/5235490 to test it on time shifted sine waves. But I don't see any similarity in a2 and x values. How do we get the time delay value from signal.correlate?