你可以爲每個陣列創建時間值的陣列,並利用它們作爲x
值interp1d
:
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](https://i.stack.imgur.com/Fh87r.png)
來源
2015-01-05 12:51:31
xnx
你知道採樣率嗎?或者所有的陣列都跨越相同的已知時間間隔? – xnx
是的,它是50赫茲。陣列沒有相同的時間間隔,這是下一步,填補空白,以便讓陣列具有相同的時間間隔 – CatarinaCM
然後,您需要爲每個陣列創建一個時間值數組,例如: 'np.arange'或'np.linspace'。 – xnx