Skip to article frontmatterSkip to article content

In this experiment, we are not fitting functions to our data. So, we only need the first two libraries that we used in previous chapters.

import numpy as np
import matplotlib.pyplot as plt
Matplotlib is building the font cache; this may take a moment.

Constants

You’ll need to enter some constants from your experiment. These are VoV_o, RR, and CC.

Creating Model Functions

Instead of fitting, you will plot the expected model function over your data. To do this we need to create a list of frequencies. In the code cell below, the frequencies are defined as f and numpy will create a list or array of frequencies from 0 to 5000 in steps of 1 Hz. Then, the code calculates the corresponding angular frequencies, ω\omega. The code will do this for you. However, you will need to use your constants and this array of angular frequencies, omega, to calculate the theoretical or model functions VR and VC, which are the expected voltages on the resistor and capacitor, respectively.

Enter Your Data

Next, you’ll enter the data you collected for VRV_R and VCV_C. You will need to enter the frequencies for which you took these measurements too. The code will calculate the angular frequencies for you. As always, there is uncertainty that you need to enter into V_unc. This is done as a single value that is a percentage. However, you are free to make a list of uncertainties for each voltage you measured since you may have changed oscilloscope settings for each measurement.

Plotting

The code will plot everything for you and save a figure for you.

#Constants
Vo = #peak-to-peak voltage
R =  #resistor value
C = #capacitor value

# Frequencies
f = np.linspace(0, 5000, 5001)#range of frequencies
omega = 2*np.pi*f #range of omegas

#Model Functions
VR = #Use values above for R,C,omega to plot theoretical curves
VC = 

#Enter your data below for f, VR, VC
f_meas = np.array([10, 100, 200, 300, 400, 500, 600, 800, 1000, 2000, 5000])
w_meas = f_meas * 2 * np.pi
VR_meas = np.array([0.5, 1.96, 3.16, 3.76, 4.2, 4.64, 4.6, 4.78, 5, 5.16, 5.1])
VC_meas = np.array([5, 4.72 ,4, 3.36, 2.8, 2.36, 2, 1.6, 1.28, 0.656, 0.27])
V_unc = np.ones(11)*0.15

plt.plot(omega, VR, '-.c', label=r'$V_R$')
plt.plot(omega, VC, '-m', label=r'$V_C$')
plt.errorbar(w_meas, VR_meas, yerr=V_unc, fmt='oc', label=r'$V_C$ measured')
plt.errorbar(w_meas, VC_meas, yerr=V_unc, fmt='*m', label=r'$V_C$ measured')
plt.xlabel(r'$\omega$ (rad/s)')
plt.ylabel('Voltage')
plt.legend()
plt.savefig('RCfilter.svg')
plt.show()