I am writing LMS filter to suppress noise in wav file (I know there are many modules to do this but I need to write LMS manually now as I will translate it into C later).

According to this answer[1], the inputs will be the noisy voice and a shifted version of it here is my python code:

import numpy as np
from scipy.io import wavfile

#Reading wav
fs, data = wavfile.read('te.wav')
#d= vector of first channel samples
d = np.transpose(data)[0]
#delay= 2 seconds
xd= np.roll(d,2*fs)


for i in range(0,L-M):
    w = w+ meu*e[i]*xPart


now, the final value if filter is [nan,nan,...,nan] and a lot of overflows happens.

I don't know what is wrong.

  • is this implementation right?

[1] Noise removal using adaptive noise cancellation algorithms in real time systems

  • $\begingroup$ I see good reason to implement things yourself; but there's a lot of signal processing libraries for C, so C shouldn't be the reason you've got to do this in python first (makes so little sense). $\endgroup$ – Marcus Müller Feb 28 '19 at 16:16
  • $\begingroup$ I have to do it totally without using any external library even in C. So, I work first in python close to what I will do in C $\endgroup$ – Mahiro Feb 28 '19 at 16:18
  • $\begingroup$ I'm all for you doing it in Python to understand how the algorithm works. I'm just telling you that Python is not a good practice ground to learn how to write C. $\endgroup$ – Marcus Müller Feb 28 '19 at 16:33
  • $\begingroup$ You might be running into stability issues. make sure 0 < mu < 2/max(y(t)^2), where y(t) is your received signal $\endgroup$ – BigBrownBear00 Feb 28 '19 at 16:37
  • $\begingroup$ Marcus Müller u r right $\endgroup$ – Mahiro Feb 28 '19 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.