Skip to content

Instantly share code, notes, and snippets.

@jfsantos
Created April 14, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsantos/886757b13d84ab5b61a6 to your computer and use it in GitHub Desktop.
Save jfsantos/886757b13d84ab5b61a6 to your computer and use it in GitHub Desktop.
LMS fit
import numpy as np
import scipy.signal as sig
from adaptfilt import lms
if __name__ == '__main__':
import matplotlib.pyplot as plt
from scipy.io import wavfile
sigma = 0.1
order = 100
fs, y = wavfile.read('shh.wav')
y = y/2.0**15
x = sigma*np.random.randn(len(y))
# y_hat_lms is the vector of estimated samples computed
# during the optimization process
# e is the per-sample error
# h is the estimated filter
y_hat_lms, e, h = lms(x, y, order, 0.01)
# y_hat is the "real" model output (noise filtered by the
# estimated filter)
y_hat = sig.lfilter(h, 1, x)
plt.subplot(311)
plt.plot(y, 'b')
plt.subplot(312)
plt.plot(y_hat, 'g')
plt.subplot(313)
plt.plot(e, 'r')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment