Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pylab as plt
  3. import padasip as pa
  4. import matplotlib.pyplot as plt
  5. from scipy.io import wavfile
  6.  
  7. N = 500
  8. x = np.random.normal(0, 1, (N, 4)) # input matrix
  9. v = np.random.normal(0, 0.1, N) # noise
  10. d = 2*x[:,0] + 0.1*x[:,1] - 4*x[:,2] + 0.5*x[:,3] + v # target
  11.  
  12.  
  13.  
  14. fs1, data1 = wavfile.read('szumwsamraz.wav')
  15. fs2, data2 = wavfile.read('result.wav')
  16. fs3, data3 = wavfile.read('szum.wav')
  17.  
  18. d = data2[:,1]
  19. x = data1[:,1]
  20. print (len(d))
  21. print (len(x))
  22.  
  23. # identification
  24. f = pa.filters.AdaptiveFilter(model="NLMS", n=4, mu=0.1, w="random")
  25. y, e, w = f.run(d, x)
  26.  
  27. ## show results
  28. plt.figure(figsize=(15,9))
  29. plt.subplot(211);plt.title("Adaptation");plt.xlabel("samples - k")
  30. plt.plot(d,"b", label="d - target")
  31. plt.plot(y,"g", label="y - output");plt.legend()
  32. plt.subplot(212);plt.title("Filter error");plt.xlabel("samples - k")
  33. plt.plot(10*np.log10(e**2),"r", label="e - error [dB]");plt.legend()
  34. plt.tight_layout()
  35. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement