查找两个相似波形之间的时移 [英] find time shift between two similar waveforms

查看:389
本文介绍了查找两个相似波形之间的时移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须比较两个时间-电压-电压波形.由于这些波形的源的特殊性,其中一个可以是另一个的时移形式.

I have to compare two time-vs-voltage waveforms. Because of the peculiarity of the sources of these waveforms, one of them can be a time shifted version of the other.

我如何查找是否存在时移?如果是的话,多少钱.

How can i find whether there is a time shift? and if yes, how much is it.

我正在Python中执行此操作,并希望使用numpy/scipy库.

I am doing this in Python and wish to use numpy/scipy libraries.

推荐答案

scipy提供了一个相关函数,该函数对于较小的输入以及如果您需要非圆形相关意味着信号不会回绕,也可以很好地工作.请注意,在mode='full'中,由signal.correlation返回的数组的大小是信号大小的总和减一(即len(a) + len(b) - 1),因此 argmax中的值被关闭(信号大小-1) = 20).

scipy provides a correlation function which will work fine for small input and also if you want non-circular correlation meaning that the signal will not wrap around. note that in mode='full' , the size of the array returned by signal.correlation is sum of the signal sizes minus one (i.e. len(a) + len(b) - 1), so the value from argmax is off by (signal size -1 = 20) from what you seem to expect.

from scipy import signal, fftpack
import numpy
a = numpy.array([0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 0, 0, 0, 0])
b = numpy.array([0, 0, 0, 0, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0])
numpy.argmax(signal.correlate(a,b)) -> 16
numpy.argmax(signal.correlate(b,a)) -> 24

两个不同的值对应于移位是在a还是b中.

The two different values correspond to whether the shift is in a or b.

如果需要循环相关并且信号较大,则可以使用卷积/傅立叶变换定理,但要注意的是,相关性与卷积非常相似,但不完全相同.

If you want circular correlation and for big signal size, you can use the convolution/Fourier transform theorem with the caveat that correlation is very similar to but not identical to convolution.

A = fftpack.fft(a)
B = fftpack.fft(b)
Ar = -A.conjugate()
Br = -B.conjugate()
numpy.argmax(numpy.abs(fftpack.ifft(Ar*B))) -> 4
numpy.argmax(numpy.abs(fftpack.ifft(A*Br))) -> 17

同样,

这两个值对应于您解释的是a的移位还是b的移位.

again the two values correspond to whether your interpreting a shift in a or a shift in b.

负共轭归因于卷积翻转功能之一,但相关没有翻转.您可以通过反转信号之一然后进行FFT来恢复翻转,或者对信号进行FFT然后再采用负共轭来取消翻转.即满足以下条件:Ar = -A.conjugate() = fft(a[::-1])

The negative conjugation is due to convolution flipping one of the functions, but in correlation there is no flipping. You can undo the flipping by either reversing one of the signals and then taking the FFT, or taking the FFT of the signal and then taking the negative conjugate. i.e. the following is true: Ar = -A.conjugate() = fft(a[::-1])

这篇关于查找两个相似波形之间的时移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆