Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import scipy.signal as dsp
- import matplotlib.pyplot as plt
- b = np.array([0.0089, -0.0045, -0.0045, 0.0089])
- a = np.array([1, -2.5641, 2.2185, -0.6456])
- w, h = dsp.freqz(b, a)
- fig = plt.figure()
- ax1 = fig.add_subplot(211)
- plt.title('Digital filter frequency response')
- plt.plot(w, 20 * np.log10(abs(h)), 'b')
- plt.ylabel('Amplitude [dB]', color='b')
- plt.xlabel('Frequency [rad/sample]')
- ax2 = ax1.twinx()
- angles = np.unwrap(np.angle(h))
- plt.plot(w, angles, 'g')
- plt.ylabel('Angle (radians)', color='g')
- plt.grid()
- plt.axis('tight')
- ax3 = fig.add_subplot(212)
- gdelay = -np.diff(np.unwrap(np.angle(h)))/np.diff(w)
- gdelay = np.append(gdelay, gdelay[-1])
- plt.plot(w, gdelay)
- plt.ylabel('Group delay [samples]', color='b')
- plt.xlabel('Frequency [rad/sample]')
- plt.grid()
- plt.axis('tight')
- plt.ylim(ymin=0)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement