I need to create a bandpass filter amplifier in python; and determine the transfer function, graph the bode diagram, and print the highcut frequency, lowcut frequency, the bode constant and the transfer function.
So far, I've been able to create a bandpass filter, graph the bode diagram and print the transfer fuction, but I don't know how to obtain and print the highcut frequency, lowcut frequency, and the bode constant.
The code I'm using is below:
import numpy as np
import control
import matplotlib.pyplot as plt
# Low-pass Transfer Function
wl = 0.1 #rad/s
Tfl = 1/wl
num = np.array([1])
den = np.array([Tfl , 1])
HL = control.tf(num, den)
# High-pass Transfer Function
wh = 100 #rad/s
Tfh = 1/wh
num = np.array([Tfh, 0])
den = np.array([Tfh, 1])
HH = control.tf(num, den)
# Band-pass Transfer Function
HBP = control.series(HL, HH)
# Frequencies
w_start = 0.01
w_stop = 1000
step = 0.01
N = int ((w_stop-w_start )/step) + 1
w = np.linspace (w_start , w_stop , N)
# Frequency Response Plot
mag , phase_rad , w = control.bode_plot(HBP, w, dB=True,
plot=False)
# Convert to dB
mag_db = 20 * np.log10(mag)
plt.figure(1)
plt.semilogx(w, mag_db)
plt.title("Bandpass Filter")
plt.grid(b=None, which='major', axis='both')
plt.grid(b=None, which='minor', axis='both')
plt.ylabel("Magnitude (dB)")
phase_deg = (180/np.pi) * phase_rad
plt.figure(2)
plt.semilogx(w, phase_rad)
plt.title("Bandpass Filter")
plt.grid(b=None, which='major', axis='both')
plt.grid(b=None, which='minor', axis='both')
plt.ylabel("Phase (deg)")
print('H(s) = ', HBP)
If you can help me out I would REALLY appreciate it. Thanks.