Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One of the links you provided has the right idea (in fact I am doing pretty much the same thing here)</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from scipy.signal import correlate a,b, N = 0, 10, 1000 #Boundaries, datapoints shift = -3 #Shift, note 3/10 of L = b-a x = np.linspace(a,b,N) x1 = 1*x + shift time = np.arange(1-N,N) #Theoritical definition, time is centered at 0 y1 = sum([np.sin(2*np.pi*i*x/b) for i in range(1,5)]) y2 = sum([np.sin(2*np.pi*i*x1/b) for i in range(1,5)]) #Really only helps with large irregular data, try it # y1 -= y1.mean() # y2 -= y2.mean() # y1 /= y1.std() # y2 /= y2.std() cross_correlation = correlate(y1,y2) shift_calculated = time[cross_correlation.argmax()] *1.0* b/N y3 = sum([np.sin(2*np.pi*i*(x1-shift_calculated)/b) for i in range(1,5)]) print "Preset shift: ", shift, "\nCalculated shift: ", shift_calculated plt.plot(x,y1) plt.plot(x,y2) plt.plot(x,y3) plt.legend(("Regular", "Shifted", "Recovered")) plt.savefig("SO_timeshift.png") plt.show() </code></pre> <p>This has the following output:</p> <pre><code>Preset shift: -3 Calculated shift: -2.99 </code></pre> <p><img src="https://i.stack.imgur.com/CPG0R.png" alt="enter image description here"></p> <p>It might be necessary to check </p> <ol> <li><a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.correlate.html" rel="nofollow noreferrer">Scipy Correlate</a></li> <li><a href="http://en.wikipedia.org/wiki/Cross-correlation#Time_delay_analysis" rel="nofollow noreferrer">Time Delay Analaysis</a></li> </ol> <p>Note that the the argmax() of the correlation shows the position of the alignment, it has to be scaled by the length of <code>b-a = 10-0 = 10</code> and N to get the actual value.</p> <p>Checking the source of correlate <a href="https://github.com/scipy/scipy/blob/v0.11.0/scipy/signal/signaltools.py#L55" rel="nofollow noreferrer">Source</a> it is not entirely obvious what the imported function from sigtools behaves. For large datasets circular correlation (via Fast Fourier Transforms) is much faster than the straight-forward method. I suspect this is what is implemented in sigtools but I cannot tell for sure. A search for the file in my python2.7 folder only returned the compiled C pyd file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload