lms.py 文件源码

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

项目:Spherical-robot 作者: Evan-Zhao 项目源码 文件源码
def lms(x1: numpy.array, x2: numpy.array, N: int):
    # Verify argument shape.
    s1, s2 = x1.shape, x2.shape
    if len(s1) != 1 or len(s2) != 1 or s1[0] != s2[0]:
        raise Exception("Argument shape invalid, in 'lms' function")
    l = s1[0]

    # Coefficient matrix
    W = numpy.mat(numpy.zeros([1, 2 * N + 1]))
    # Coefficient (time) matrix
    Wt = numpy.mat(numpy.zeros([l, 2 * N + 1]))
    # Feedback (time) matrix
    y = numpy.mat(numpy.zeros([l, 1]))
    # Error (time) matrix
    e = numpy.mat(numpy.zeros([l, 1]))

    # Traverse channel data
    for i in range(N, l-N):
        x1_vec = numpy.asmatrix(x1[i-N:i+N+1])
        y[i] = x1_vec * numpy.transpose(W)
        e[i] = x2[i] - y[i]
        W += mu * e[i] * x1_vec
        Wt[i] = W

    # Find the coefficient matrix which has max maximum.
    Wt_maxs = numpy.max(Wt, axis=1)
    row_idx = numpy.argmax(Wt_maxs)
    max_W = Wt[row_idx]
    delay_count = numpy.argmax(max_W) - N

    plot(l, x1, x2, y, e)

    return delay_count
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号