Advertisement
grizlik

IIR filter freq response

May 10th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import numpy as np
  2. import scipy.signal as dsp
  3. import matplotlib.pyplot as plt
  4.  
  5. b = np.array([0.0089, -0.0045, -0.0045, 0.0089])
  6. a = np.array([1, -2.5641, 2.2185, -0.6456])
  7.  
  8. w, h = dsp.freqz(b, a)
  9.  
  10. fig = plt.figure()
  11. ax1 = fig.add_subplot(211)
  12. plt.title('Digital filter frequency response')
  13.  
  14. plt.plot(w, 20 * np.log10(abs(h)), 'b')
  15. plt.ylabel('Amplitude [dB]', color='b')
  16. plt.xlabel('Frequency [rad/sample]')
  17.  
  18. ax2 = ax1.twinx()
  19. angles = np.unwrap(np.angle(h))
  20. plt.plot(w, angles, 'g')
  21. plt.ylabel('Angle (radians)', color='g')
  22. plt.grid()
  23. plt.axis('tight')
  24.  
  25. ax3 = fig.add_subplot(212)
  26. gdelay = -np.diff(np.unwrap(np.angle(h)))/np.diff(w)
  27. gdelay = np.append(gdelay, gdelay[-1])
  28. plt.plot(w, gdelay)
  29. plt.ylabel('Group delay [samples]', color='b')
  30. plt.xlabel('Frequency [rad/sample]')
  31. plt.grid()
  32. plt.axis('tight')
  33. plt.ylim(ymin=0)
  34. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement