1
$\begingroup$

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)

enter image description here

enter image description here

enter image description here

If you can help me out I would REALLY appreciate it. Thanks.

$\endgroup$
4
  • $\begingroup$ Hi! Welcome here and: thanks for the well-illustrated question. This might just be a language problem on my end (I didn't learn signal processing in English but in German), but what is the Bode constant? $\endgroup$ Mar 28, 2022 at 21:22
  • $\begingroup$ The bode constant is what we usually name as: H (s) = H (jω) = K $\endgroup$ Mar 28, 2022 at 21:55
  • 1
    $\begingroup$ nice job with the control library -- Same question as Marcus but I assume it is the gain? If so set s to mid band and compute |H(s)| which should match the -60dB when converted to dB using 20Log(). High pass corner and lowpass corner are likely the -3 dB points so frequency where magnitude crosses -63 dB, but sometimes at -6 dB so must be specified. You can just say the -3 dB points are... $\endgroup$ Mar 28, 2022 at 21:58
  • 1
    $\begingroup$ (I'm not confident in that for K however; I could argue K is 0.01 just from the transfer function provided--- in other words K H(s)) $\endgroup$ Mar 29, 2022 at 1:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.