I'm using python, but this is a generic question (more related to algorithms etc) and thus I skip some steps to get to the gist of the matter:
I generate a sine signal like this:
import math as m
signal = [m.sin(2*m.pi*1*(t/n-d)) for t in range(n)]
So a sine signal, normalized so, that frequency is 1, and time goes from 0 to 1 second (so basically a simple one cycle of sine wave). There is also a delay term d, that delays the signal (causes a phase shift). The n is only the number of samples
I also create another signal, with another delay. Let's say I use delay of 0 for the first signal, and delay of x for the second signal (I abbreviate previous for the sake of clarity):
signal1 = signal(delay=0)
signal2 = signal(delay=x)
and then I do a correlation:
from scipy import signal as sgn
corr11 = sgn.correlate(signal1, signal1, mode = 'full')
corr12 = sgn.correlate(signal1, signal2, mode = 'full')
I also know that the signal delay correlates to the maximum of the correlation point, so I take out two points:
import numpy as np
a1 = np.argmax(corr11)
a2 = np.argmax(corr12)
So I've found that correlation of signal with itself has the max peak in the middle of the correlation array (or plot/function). But the other peak is weird:
- At delay 0 and 1: a2 is same as a1
- At delay 0.5: distance of a2 from a1 is 0.5 of a1 (inverted signal)
- At delay 0.28328: a2 is 0.75 of a1
- At delay 0.1: a2 is 0.90888 of a1
So the question is, how the delay d relates to the peak location after correlating the signals?
nop
? Also, issgn
here referring toscipy.signal
? – Jake Levi