[Numpy-discussion] numpy.correlate with phase offset 1D data series

Ray Schumacher subscriber100@rjs....
Tue Mar 4 12:47:39 CST 2008


Thank you for the input!
It sounds like Fourier methods will be fastest, by design, for sample 
counts of hundreds to thousands.

I currently do steps like:
Im1 = get_stream_array_data()
Im2 = load_template_array_data(fh2)
##note: len(im1)==len(im2)
Ffft_im1=fftpack.rfft(Im1)
Ffft_im2=fftpack.rfft(Im2)
R1= (Ffft_im1 * Ffft_im2.conjugate())
R2= (abs(Ffft_im1) * abs(Ffft_im2))
R = R1 / R2
IR=fftpack.irfft(R)
flat_IR = numpy.ravel(numpy.transpose(IR)).real
I= numpy.argmax(flat_IR)
phase_offset = (I % len(Im1))


At 09:29 AM 3/4/2008, Anne Archibald wrote:
 > * What do you want to happen at the endpoints? Without padding, only a
 > small interval (the difference in lengths plus one) is valid.
 > Zero-padding works, but guarantees a fall-off at the ends. Circular
 > correlation is easy to implement but not appropriate most of the time.

How much should I be concerned?, since the only desired information 
from this is the scalar best-fit phase value, presumably the argmax() 
of the xcorr.

In current operation, imagine a tone pattern/template of n samples 
which we want to align to streaming data; the desired result (at 
least in my current FFT code) is the sample number of recent ADC data 
where the zero'th sample of the pattern best aligns. Since it is a 
repeating pattern, we know that it will always align somewhere in the 
latest n samples.

 > * Do you care about sub-sample alignment? How much accuracy do you
 > really need?

Integer alignment is sufficient, due both to electronic noise, and 
desired phase

 > The other common application is to have a template (that presumably
 > falls to zero at its endpoint) and to want to compute a running
 > correlation against a stream of data. This too can be done both ways,
 > depending on the size of the template; all that is needed is to think
 > carefully about overlaps.

This is very much what the application is, although the template does 
not terminate at zero. It does terminate at a value near the zero'th 
value however, and I assumed the FFTs would be well-behaved.

Ray


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.516 / Virus Database: 269.21.4/1310 - Release Date: 3/4/2008 8:35 AM




More information about the Numpy-discussion mailing list