2015-01-05 36 views
0

我有幾個具有不同採樣率的1D陣列。我想重新採樣所有的陣列。 你有什麼建議嗎?使用python進行數組插值

數組是這樣的:

a=[-9494 -9496 -9498 ..., -9513 -9516 -9514] 

b=[-9494 -9498 -9502 ..., -9506 -9510 -9514] 

我讀過scipy.interpolate.interp1d文檔。但是我沒有找到任何方法來處理採樣率。

你有任何消化?

在此先感謝!

+0

你知道採樣率嗎?或者所有的陣列都跨越相同的已知時間間隔? – xnx

+0

是的,它是50赫茲。陣列沒有相同的時間間隔,這是下一步,填補空白,以便讓陣列具有相同的時間間隔 – CatarinaCM

+0

然後,您需要爲每個陣列創建一個時間值數組,例如: 'np.arange'或'np.linspace'。 – xnx

回答

0

你可以爲每個陣列創建時間值的陣列,並利用它們作爲xinterp1d

import numpy as np 
from scipy.interpolate import interp1d 

a = np.array([-9494, -9496, -9498, -9513, -9516, -9514]) 
b = np.array([-9494, -9498, -9502, -9506, -9510, -9514]) 

dta, dtb = 1/4., 1/5. # example sampling rates 

na = len(a) 
nb = len(b) 
amax, bmax = (na-1)*dta, (nb-1)*dtb 
ta = np.linspace(0, amax, na) 
tb = np.linspace(0, bmax, nb) 
ainterp = interp1d(ta, a) 
binterp = interp1d(tb, b) 

tmax = min(ta[-1], tb[-1]) 
target_sampling = 50 
ngrid = int(tmax * target_sampling + 1) 
tgrid = np.linspace(0, tmax, ngrid) 
afine = ainterp(tgrid) 
bfine = binterp(tgrid) 

import pylab 
pylab.plot(ta, a, 'o') 
pylab.plot(tgrid, afine,'.') 
pylab.plot(tb, b, 'o') 
pylab.plot(tgrid, bfine,'.') 
pylab.show() 

這是你需要什麼? enter image description here