Skip to article frontmatterSkip to article content

You might start to notice the repetition with imports. We will again import numpy and matplotlib.pyplot so we can deal with arrays of numbers and plotting. Shift-Enter the code cell below before getting started.

import matplotlib.pyplot as plt
import numpy as np

Part 1 - Multistage RC Circuits

We want to plot the gain and the phase, ϕ\phi as functions of the signal frequency, ω\omega. You will plot your experimental resutls and overlay the theoretical model. We will not do any fitting of the model to the data. In the code cell below

  • ω\omega is calculated to be an array from 0 to 100 000 in steps of 1 rad/s.
  • Constants for the resistors and capacitors are entered, but you may need to change the values if you used different resistor and capacitor values.
  • The theoretical gain and phase are calculated for you.
  • Enter your measured angular frequencies, ω\omega.
  • Enter your measured gain.
  • Enter your measured phase, ϕ\phi.

The code will plot your data and the theoretical model. A figure image will be saved for you.

# theoretical data
omega = np.linspace(0,100000, 100001)
#experimental constants
R1 = 1000
R2 = 10000
C1 = 1e-7 #100 nF
C2 = 1e-8 #1nF

print(1/R1/C1, 1/R2/C2) #print the 1/RC values

#theoretical functions
gain_theory = omega*R1*C1/np.sqrt(1+(omega*R1*C1)**2) * omega*R2*C2/np.sqrt(1+(omega*R2*C2)**2)
phase_theory = np.atan(1/(omega*R1*C1)) + np.atan(1/(omega*R2*C2))

# experimental data
omega_exp = np.array([])
gain_exp = np.array([])
phase_exp = np.array([])

#Plotting the functions and measurements
fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)

ax1.semilogx(omega, gain_theory, '-k', label='Theoretical Gain')
ax1.semilogx(omega_exp, gain_exp, 'ob', label='Experimental Gain')
ax1.set_ylabel('Theoretical Gain')
ax1.legend()
ax2.semilogx(omega, phase_theory, '-k', label='Theoretical Phase')
ax2.semilogx(omega_exp, phase_exp, 'ob', label='Experimental Phase')
ax2.set_ylabel(r'Phase, $\phi$ (rad)')
ax2.legend()
plt.xlabel(r'log($\omega$)')
plt.savefig('multiRC.png')
plt.show()

Part 2 - RLC Circuits

  • Copy the code above and paste it in the code cell below.
  • Delete the second resistor and capacitor values.
  • Add a constant for your inductor value.
  • Delete the print statement.
  • Change the theoretical gain_theory to current_theory, and enter the math for the theoretical function
  • Edit the theoretical phase phase_theory with the RLC phase function.
  • Add your experimental frequencies (rad/s) to omega_exp.
  • Change the experimental gain_exp to current_exp and enter your measurements.
  • Add your experimental phase measurements to phase_exp.
  • Change the array names in the plotting section to match your new names.
  • Change the filename that is saved.

Run the code to get a graph of your data with the theoretical models overlaid.