SlidingWindow.py 文件源码

python
阅读 82 收藏 0 点赞 0 评论 0

项目:Math412S2017 作者: ctralie 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号