Scipy:找到两个不同长度信号之间的转换

时间:2018-01-31 17:01:15

标签: python scipy signals signal-processing

在python中,我有两个不同长度的相似信号,我想找到它们之间的偏移量。

我发现了这篇文章:find time shift between two similar waveforms

但我不理解不同长度信号的解释。

例如:

a=[0,0,1,2,3]
b=[0,0,0,0,1,2,3,0]

numpy.argmax(scipy.signal.correlate(a,b))提供5,我不明白。 numpy.argmax(scipy.signal.correlate(b,a))给出了6,这似乎是b应该向右移动的数量,假设是环绕式的。有人可以解释一下吗?

1 个答案:

答案 0 :(得分:0)

The post "find time shift between two similar waveforms" uses the mathematical "correlate" which is only meaningful for equally sized arrays.

For your application, the following code will give the desired shift

import numpy as np
a=[0,0,1,2,3]
b=[0,0,0,0,1,2,3,0]
np.argmax(np.convolve(a[::-1],b,mode='valid'))

~~~~~~~~~~~~~~~~~~~~~ for the follow up comment question. Try

from scipy.linalg import circulant
b=[0,1,2,3,0]
a=[0,0,1,2,3]
[ i for i in range(len(b)) if not False in (a==circulant(b)[:,i])]

the problem is convolve doesn't recognize circular matrices