Created
April 14, 2015 18:38
-
-
Save jfsantos/886757b13d84ab5b61a6 to your computer and use it in GitHub Desktop.
LMS fit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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