[Numpy-discussion] numpy.correlate with phase offset 1D data series
Anne Archibald
peridot.faceted@gmail....
Mon Mar 3 16:08:00 CST 2008
On 03/03/2008, Ray Schumacher <subscriber100@rjs.org> wrote:
>
> I'm trying to figure out what numpy.correlate does, and, what are people
> using to calculate the phase shift of 1D signals?
I use a hand-rolled Fourier-domain cross-correlation, but then, I'm
using a Fourier-domain representation of my signals.
> (I coded on routine that uses rfft, conjugate, ratio, irfft, and argmax
> based on a paper by Hongjie Xie "An IDL/ENVI implementation of the FFT Based
> Algorithm for Automatic Image Registration" - but that seems more intensive
> than it could be.)
Sounds familiar. If you have a good signal-to-noise ratio, you can get
subpixel accuracy by oversampling the irfft, or better but slower, by
using numerical optimization to refine the peak you found with argmax.
> In numpy, an identity import numpy from pylab import *
> l=[1,5,3,8,15,6,7,7,9,10,4] c=numpy.correlate(l,l, mode='same') plot(c)
> peaks at the center, x=5, and is symmetric
You have revealed several flaws in numpy's correlate. First of all,
the docstring gives no indication of how to interpret the result:
neither the zero-shift position nor the direction of the result is at
all clear (if I shift the first vector to the left, does the
correlation peak shift left or right?). Second, the mode "same" gives
results which are rather difficult to understand. Third, there is no
way to get a "circular" correlation.
I would be inclined to use convolve (or scipy.ndimage.convolve, which
uses a Fourier-domain method), since it is somewhat better specified.
Anne
More information about the Numpy-discussion
mailing list