2016-12-07 31 views
-1

我有這樣的數據: [1,3,3,....1]〜500個數字。Python中的信號處理。查找系列數據移位

每1毫秒,我有一個新的,但有一些轉變(5-10分)+小噪音。

E.g: 
[1 2 3 4 3 21 4 5...] 
[0 4 3 1 2 3 4 19 7 5 ...] 

在這種情況下轉變爲3

我想知道這種轉變。 我怎樣才能得到它?

傅里葉的方式是慢..因爲我每秒有很多行。 find time shift between two similar waveforms

可能有一些快速的方法嗎? 或者可能我應該使用傅里葉僅用於我的部分數據(因爲它們大致如整體移位)。 非常感謝。

回答

0

如果您知道滯後只是幾個樣本5-10,那麼您可以使用自相關來找到它。如果只計算這個有限的小範圍滯後,它應該很快。如果你計算了所有可能的滯後時間,那麼它可能會很慢。

這裏是一個修改AMDF算法已被使用的例子:

import numpy as np 

def modified_amdf(x1, x2, steps): 
    N = min(len(x1), len(x2)) 
    res = [] 
    for step in steps: 
     sm = 0 
     for n in range(0, N - step): 
      sm += np.abs(x1[n] - x2[n + step]) 
     sm = sm * (1.0/(N - step - 1)) 
     res.append(sm) 
    return res 

#x1 = [1, 2, 3, 4, 3, 21, 4, 5] 
#x2 = [0, 4, 3, 1, 2, 3, 4, 19, 7, 5] 
x1 = np.sin(np.linspace(0, 10*np.pi, 500)) 
x2 = np.r_[[0,0], x1] # add two lag entries 
penalties = modified_amdf(x1, x2, range(5)) 
print "Found lag:", np.argmin(penalties) 

可以提高速度有點如果你改變了計算,只使用numpy的,但這應該僅500個樣本多久有一些滯後。

+0

你能舉一個計算的例子嗎? –

+0

它適合你嗎? –