LCR Band Pass Filter in Python

49 views Asked by At

LCR Circuit: LCR Circuit

Problem Description: Problem Description

For my Signals and Systems class, we are supposed to use Python and matplotlib to plot the frequency responses of a variety of different circuits, including an LCR band pass filter.

Calculating the transfer function was easy, and can obviously be checked with a simple google search as $H(ω)=\frac{R}{\frac{1}{jωC}+jωL+R}$. In order to plot it, we were told to put it in terms of the frequency, and this is where I've run into trouble. I've tried several ways of getting the equations into terms without using R, L, or C, and my latest attempt has given me

def H(F):
    out = 1 / ((1j*2*np.pi*F / BW) + (w0**2 / (1j*2*np.pi*F*BW)) + 1)
    return out

To plot the function, I have this:

BW = 0.1 #The bandwidth in kHz
F0 = 21 #The resonant frequency in kHz
w0 = 2*np.pi*F0 #The resonant frequency in radians
F = np.arange(20.5,21.5, 0.1)
plt.figure(figsize=(10,5) )       #The size of the graph
plt.suptitle('Plot of the Magnitude of the Frequency Response of an LRC Band Pass Filter')  #The title of the graph
plt.plot(F,abs(H(F)))                  #The plotting of function
plt.ylabel('|H(F)|', color="blue")  #Labeling of the y axis
plt.xlabel('F kHz',horizontalalignment='right', x=1.0, color="blue")  #Labelling of the x axis
plt.yticks([0,1/np.sqrt(2),1], color="red")       #The values of the y axis
plt.xticks([21], color="red") #The values of the x axis
plt.grid(True)  #Shows the graph 

Which outputs this: Plot

I know this can't be correct, can anyone tell me why this is happening?

0

There are 0 answers