Compute the frequency response of a digital filter.
Given the numerator b and denominator a of a digital filter compute its frequency response:
jw -jw -jmw
jw B(e) b[0] + b[1]e + .... + b[m]e
H(e) = ---- = ------------------------------------
jw -jw -jnw
A(e) a[0] + a[1]e + .... + a[n]e
Parameters : | b : ndarray
a : ndarray
worN : {None, int}, optional
whole : bool, optional
plot : callable
|
---|---|
Returns : | w : ndarray
h : ndarray
|
Notes
Using Matplotlib’s “plot” function as the callable for plot produces unexpected results, this plots the real part of the complex transfer function, not the magnitude.
Examples
>>> import scipy.signal
>>> b = sp.signal.firwin(80, 0.5, window=('kaiser', 8))
>>> h, w = sp.signal.freqz(b)
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> plt.title('Digital filter frequency response')
>>> ax1 = fig.add_subplot(111)
>>> plt.semilogy(h, np.abs(w), 'b')
>>> plt.ylabel('Amplitude (dB)', color='b')
>>> plt.xlabel('Frequency (rad/sample)')
>>> plt.grid()
>>> plt.legend()
>>> ax2 = ax1.twinx()
>>> angles = np.unwrap(np.angle(w))
>>> plt.plot(h, angles, 'g')
>>> plt.ylabel('Angle (radians)', color='g')
>>> plt.show()