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, 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) print(data.shape) #delay= 2 seconds xd= np.roll(d,2*fs) M=5 L=d.size w=np.zeros(M) y=np.zeros(L-M) e=np.zeros(L-M) meu=0.1 for i in range(0,L-M): xPart=xd[i:i+M] #print(xPart.shape) y[i]=xPart.dot(w) e[i]=d[i]-y[i] w = w+ meu*e[i]*xPart print(w)
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?