def getSlidingWindow(x, dim, Tau, dT):
"""
A function that computes the sliding window embedding of a
discrete signal. If the requested windows and samples do not
coincide with sampels in the original signal, spline interpolation
is used to fill in intermediate values
:param x: The discrete signal
:param dim: The dimension of the sliding window embedding
:param Tau: The increment between samples in the sliding window
:param dT: The hop size between windows
:returns: An Nxdim Euclidean vector of sliding windows
"""
N = len(x)
NWindows = int(np.floor((N-dim*Tau)/dT))
X = np.zeros((NWindows, dim))
idx = np.arange(N)
for i in range(NWindows):
idxx = dT*i + Tau*np.arange(dim)
start = int(np.floor(idxx[0]))
end = int(np.ceil(idxx[-1]))+2
if end >= len(x):
X = X[0:i, :]
break
X[i, :] = interp.spline(idx[start:end+1], x[start:end+1], idxx)
return X
评论列表
文章目录