0
$\begingroup$

I just realized this forum existed, posted my question on the wrong forum.

Sorry about the formatting, please don't hesitate to ask if any part of this post is unclear. This is my first post.

I'm trying to implement a simulation of an ANC system with python, using this model here, but that's not the main point. My simulation keeps diverging, so I'm trying to figure out if it's my system is unstable or did I implement the NLMS algorithm wrong. Below is my code for the NLMS update. I'm using a source from Mathworks here.

x is input vector--------------------------------------------dimension(N * 1)

error is (desired vector - NLMS prediction)---------dimension(N * 1)

w_prev is the previous iteration's weight vector---dimension(1 * m)

def lms_update(x,error,w_prev,mu):

    ep = 0

    w_prev = np.array(w_prev)
    error = np.array(error)

    x_normal = np.dot(np.conjugate(x),np.linalg.inv((ep+np.dot(np.transpose(np.conjugate(x)),x))))


    w_update = w_prev + 2*mu*np.dot(error,x_normal)
    w_update = w_update.tolist()

    return w_update

then from above dimensions, after applying the update formula,

w(n)=αw(n−1)+f(u(n),e(n),μ) and f(u(n),e(n),μ)=μe(n)u'(n)

the update would be a 1 * 1 constant, and the weight would all be updated with the same value, which doesn't make too much sense to me.

So I adjust the input vector x into a (N * m) matrix, using vectors from current and previous iterations, so I can get the update to be a (1 * m) matrix. But I'm not sure if this is the correct way. From what I gathered from papers and google searches, nothing pops up indicating dimensions of the input. But I did implement a gradient descent algorithm before which input is a matrix, not a vector.

$\endgroup$

1 Answer 1

1
$\begingroup$

The output of an FIR filter is

$$ y(n) = \sum_{i=0}^{N-1}w_i(n)x(n-i) $$

Say the weight vector $\mathbf{w}(n)$ has a length of $N$, i.e.,

$$\mathbf{w}(n) = [w_0(n), w_1(n), \ldots, w_{N-1}(n)]^T$$

and the input vector $\mathbf{x}(n)$ should have the same length as $\mathbf{w}(n)$:

$$\mathbf{x}(n) = [x(n), x(n-1), \ldots, x(n-N+1)]^T$$

Therefore the output $y(n)=\mathbf{w}^T(n)\mathbf{x}(n)$ is a scalar, and the error signal $e(n)$ and disired signal $d(n)$ are also scalar. They represent the signals at discrete time $n$. You should update the filter weights sample by sample.

$\endgroup$
2
  • $\begingroup$ Thanks for the answer, it makes so much more sense now. You sound you have a lot of experience, mind I ask would you recommend implementing a for loop in the function to iterate through every error value, or a stochastic way just choosing one error from the bunch and go to the next batch for an application such as ANC? I know it depends, just want to know your preference. $\endgroup$
    – Vincent Lu
    Commented Feb 25, 2021 at 3:14
  • $\begingroup$ The former you mention is traditional adaptive filtering which requires a relatively high computational complexity but has a faster convergence rate. The latter is known as Partial Update LMS, whose advantages and disadvantages are just the opposite of LMS. Which one is better depends on your specific needs for the balance of performance and the complexity. $\endgroup$
    – ZR Han
    Commented Feb 25, 2021 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.