将LMS功能应用于硬盘上的wave文件

时间:2015-09-25 08:20:17

标签: python filter fft noise wave

我找到了this function online,我希望将它与保存在硬盘上的wave文件一起使用。 你能帮我搞清楚怎么做吗?应该使用哪些参数作为函数的输入,以及如何从波形文件中获取它们?通过FFT?

def lms(x, d, p, mu, w0=None):
""" Finds the LMS adaptive filter w based on the inputs

Adapted from the Hayes MATLAB code.

Inputs:
    x: input data to the filter, Nx1 vector
    d: desired output signal, Nx1 vector
    p: filter order
    mu: step size, scalar or Nx1 vector
    w0: initial guess (optional)

Outputs:
    w: filter coefficient matrix: w[n,p] where 
        n is the time index and 
        p is the filter tap index
    e: error sequence e(n): Nx1 vector

"""
# Initialize
N = len(x)
X = convm.convm(x, p)
if not w0:
    w0 = np.zeros(p)
# Promote mu to be a vector if it's not already
if not isinstance(mu, np.ndarray):
    mu = np.ones(N) * mu
w = np.zeros((N,p))
e = np.zeros(N)
w[0,:] = w0

# Run the filter
for n in xrange(N-1):
    y = np.dot(w[n,:], X[n,:])
    e[n] = d[n] - y
    w[n+1,:] = w[n,:] + mu[n] * e[n] * X[n,:].conj()

return w, e

0 个答案:

没有答案