import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
def dB(x):
return 20.0*np.log10(np.abs(x) + 5*np.finfo(float).eps)
fc = 132.0
order = 1
butterHPF = signal.butter(order, fc, 'high', analog=True)
w = np.logspace(np.log10(10), np.log10(2e5), 200)
_, Hb = signal.freqs(*butterHPF, w)
fig, (ax0, ax1) = plt.subplots(2, 1, figsize=(8, 8), sharex=True)
ax0.semilogx(w, dB(Hb))
ax0.grid(True, which='both', axis='both')
ax0.set_xlim(w[0], w[-1])
ax0.set_ylabel('Response Magnitude, dB')
ax0.set_ylim(-5, 5)
ax0.set_yticks(np.r_[-5.0:5.5:0.5], [ '' if x%1 > 1e-8 else '{:3.0f}'.format(x) for x in np.r_[-5.0:5.5:0.5] ])
ax1.semilogx(w, dB(Hb))
ax1.grid(True, which='both', axis='both')
ax1.set_xlabel('Frequency, Hz')
ax1.set_ylabel('Response Magnitude, dB')
ax1.set_ylim(-25, 5)
fig.suptitle('HPF Response Magnitude, Filter Order: {:d}, Cutoff: {:.1f} Hz'.format(order, fc))
fig.tight_layout()
plt.show()