[Numpy-discussion] help using np.correlate to produce correlograms.
Pierre Haessig
pierre.haessig at crans.org
Tue Dec 9 11:23:31 EST 2014
Hi,
Le 08/12/2014 22:02, Jose Guzman a écrit :
> I'm trying to compute the cross correlation and cross correlograms from
> some signals. For that, I'm testing first np.correlate with some
> idealized traces (sine waves) that are exactly 1 ms separated from each
> other. You can have a look here:
>
> http://nbviewer.ipython.org/github/JoseGuzman/myIPythonNotebooks/blob/master/Signal_Processing/Cross%20correlation.ipynb
>
> Unfortunately I am not able to retrieve the correct lag of 1 ms for the
> option 'full'. Strange enough, if I perform an autocorrelation of any of
> the signals,I obtain the correct value for a lags =0 ms. I' think I'm
> doing something wrong to obtain the lags.
I looked at your Notebook and I believe that you had an error in the
definition of the delay. In you first cell, you were creating of delay
of 20ms instead of 1ms (and because the sine is periodic, this was not
obvious).
In addition, to get a good estimation of the delay with cross
correlation, you need many perdiods.
Here is a modification of your notebook :
http://nbviewer.ipython.org/gist/pierre-haessig/e2dda384ae0e08943f9a
I've updated the delay definition and the number of periods.
Finally, you may be able to automate a bit your plot by using
matplotlib's xcorr (which uses np.correlate)
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xcorr
best,
Pierre
More information about the NumPy-Discussion
mailing list