Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pylab as plt
- import padasip as pa
- import matplotlib.pyplot as plt
- from scipy.io import wavfile
- N = 500
- x = np.random.normal(0, 1, (N, 4)) # input matrix
- v = np.random.normal(0, 0.1, N) # noise
- d = 2*x[:,0] + 0.1*x[:,1] - 4*x[:,2] + 0.5*x[:,3] + v # target
- fs1, data1 = wavfile.read('szumwsamraz.wav')
- fs2, data2 = wavfile.read('result.wav')
- fs3, data3 = wavfile.read('szum.wav')
- d = data2[:,1]
- x = data1[:,1]
- print (len(d))
- print (len(x))
- # identification
- f = pa.filters.AdaptiveFilter(model="NLMS", n=4, mu=0.1, w="random")
- y, e, w = f.run(d, x)
- ## show results
- plt.figure(figsize=(15,9))
- plt.subplot(211);plt.title("Adaptation");plt.xlabel("samples - k")
- plt.plot(d,"b", label="d - target")
- plt.plot(y,"g", label="y - output");plt.legend()
- plt.subplot(212);plt.title("Filter error");plt.xlabel("samples - k")
- plt.plot(10*np.log10(e**2),"r", label="e - error [dB]");plt.legend()
- plt.tight_layout()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement