EGR 224/RC Analysis

From PrattWiki
Jump to navigation Jump to search

The following page provides some supplemental information for the RC Analysis lab for EGR 224L. It has been updated for Summer, 2020.

Element Values

Take the number attached to your NetID (use 0 if no number), calculate that number modulo 8 (i.e. the remainder after dividing by the largest whole number of 8's), and add 1. Use the resistor and capacitor values based on that number:

  • Resistances:
    • 1: 2.2 k\(\Omega\)
    • 2, 3: 4.7 k\(\Omega\)
    • 4, 5: 10 k\(\Omega\)
    • 6: 15 k\(\Omega\)
    • 7, 8: 22 k\(\Omega\)
  • Capacitances
    • 1, 3: 22 \(\mu\)F
    • 2, 5: 10 \(\mu\)F
    • 4, 6, 8: 4.7 \(\mu\)F
    • 7: 2.2 \(\mu\)F

Tinkercad

Use a small breadboard, a function generator (not a power supply), a resistor, a capacitor, and whatever wires you need to model the circuit.

  • Put in three oscilloscopes - one to show the total voltage across the RC circuit, one to show just the voltage across the capacitor, and one to show just the voltage across the resistor. Change the time scale of the scopes so that the time per division is approximately equal to the time constant $$\tau=RC$$ of your circuit.
  • Set the function generator to make a square wave with an amplitude of 2.5 V, a DC Offset of 1.25 V, and a frequency equal to $$f=\frac{1}{8\tau}$$ where again $$\tau=RC$$ for your circuit. This will make a wave that is "on" for four time constants and then "off" for four time constants. Take a screen shot of your simulation in action.
  • Note that the scopes are not triggered in sync - the time axes for each are shifted and generally centered where a wave is equal to half its maximum amplitude and rising. Given that, we will not be able to use Tinkercad to get phase information but you can at least get an idea about amplitude.
  • Set the function generator to generate a sinusoid instead of a rectangular pulse. Note that the amplitudes of the voltages across the resistor and capacitor are just about equal. This is because $$f=\frac{1}{8\tau}$$ is very close to the cutoff frequency $$f_{co}=\frac{\omega_{co}}{2\pi}=\frac{1}{2\pi\tau}$$. At exactly the cutoff frequency, we would expect the amplitude of both signals to be $$\frac{1}{\sqrt{2}}$$ of the total amplitude. Take a screen shot of your simulation in action.
  • Change the frequency of the function generator (which should still generate a sinusoid) to 10 times its current value (that is $$f=\frac{1.25}{\tau}$$) and change the time per division to $$\tau/10$$. Take a screen shot of this simulation as well. Carefully note the voltage ranges on the oscilloscopes. You should see that the voltage across the resistor now has a significantly larger amplitude than the voltage across the capacitor. Take a screen shot of your simulation in action.

Multisim

Single Frequency Sinusoids

  • Build the same circuit in Multisim but use an AC Voltage source for the source (Multisim does not have a function generator). Be sure to include a ground and set your capacitor and resistor values to your specific values. Set the frequency to $$f=\frac{1}{2\pi\tau}$$
  • Put one probe at the top of the voltage source, a second probe at the top of the capacitor, and a third probe on the left side of the resistor (i.e. on the wire connecting the resistor to the source). Click on this third probe and then set the reference (V-) to the right side of the resistor. This will allow the probe to take a voltage measurement across the resistor.
  • Run the simulator, then click on Grapher. (horrible, isn't it?)
  • Click on Schematic again, then where it says Interactive, change this to Transient. This will allow us to graph for a particular period of time. Open the settings by clicking the gear on the top right. In the simulation settings, change the end time to $$20\tau$$ for your circuit and then press play to run the simulation. You should have three curves and each should have four peaks (though one of the initial peaks for the resistor voltage will not be full height. The capacitor voltage (probe 2) and resistor voltage (probe 3) should eventually have peaks of equal height that are $$\pm45^o$$ out of phase from the total voltage and at a height that is approximately 70% of the total voltage. You can hover over the curves to pick off specific values.
  • The time domain here is a little jagged. To make it smoother, go back to the schematic and in the settings section, open the Maximum time step section. Change it to manual time step and set this to 1e-5 which is the largest possible manual time step. Re-run the simulation and look at the graphs now - much smoother!
  • When you hover over a curve to pick off values, there may be times that the two curves intersect. Note that the cursor color indicates which curve you are looking at. If you need to turn a curve off so that it does not interfere, uncheck the box next to its name in the Plots part of the settings box.
  • Go back to the schematic editor and change the frequency to 0.159 Hz (1 rad/s). In the Document settings, change the end time to 62.83 (10 times the period of the sinusoid). Unclick the Manual time step option. Run the simulation. This is a relatively low frequency so the capacitor voltage (probe 2) should be very close to the total voltage and nearly in phase, while the resistor voltage will be small and almost $$90^o$$ ahead. Export this data set using the export button at the top right. The file will be saved to an "Untitled Circuit" file; find that file and change its name to "Data001.csv"
  • You are now going to repeat this process for frequencies of $$\omega=2, 5, 12, 25, 60, 130, 300$$ rad/s. Each time, change the frequency of the source to the correct value $$f=\frac{\omega}{2\pi}$$ and change the end time to 10 times the period of the sinusoid ($$T=\frac{1}{f}$$ so use $$\frac{20\pi}{\omega}$$. If the higher frequency graphs start to look jagged, you can change the minimum time step back to manual. Save the data set each time where the numerical part will be a three digit representation of the frequency in rad/s. Note how the peak value and locations for the resistor and capacitor voltage change with frequency.

AC Sweep

  • Next you are going to have Multisim analyze the AC Steady State for the circuit as a function of the frequency. Change from a Transient Analysis to an AC Sweep using the dropdown at the top left of the screen. In the Document Settings, change the Start frequency to 0.016 Hz ($$\approx$$0.1 rad/s) and the Stop frequency to 480 Hz ($$\approx$$3000 rad/s). Note that this range is a decade before and a decade beyond the frequencies you just used. Run the simulation. The grapher will now be showing you the Bode magnitude and phase plots for the three voltages we are measuring. Confirm that the capacitor voltage looks like a low pass filter, the resistor voltage looks like a high pass filter, and that the two magnitudes are equal at the cutoff frequency $$f_{co}=\frac{\omega_{co}}{2\pi}=\frac{1}{2\pi RC}$$ for your filter. If you want a higher resolution sweep, go back to the Document settings and change the Points per decade setting and rerun the simulation. Note that if you hover over the magnitude curves you get the multiplicative values by default. If you want readings in dB, you will need to go to the Document settings and change the Vertical scale to Decibel. Be sure to change it back to Logarithmic and re-run the simulation before the next step.
  • Export the Schematic Image, the Grapher Image, and the Grapher Data for this circuit.

Maple

Python / MATLAB

Plotting

For your plots, the total voltage should be a solid (dark) red line, the capacitor voltage should be a dash-dot (dark) blue line, and the resistor voltage should be a dashed (dark) green line. Here are some examples of how to do that in Maple, (less efficiently) in all versions of MATLAB, more efficiently in newer versions of MATLAB, and in Python, that shows plotting \(t^2\), \(t\), and \(t^2-t\). Note that you will need to add code for the axis labels and titles.

Maple

plot([t^2, t, t^2-t], t = 0 .. 3, linestyle = [1, 4, 3], legend = ['Total', 'vC', 'vR'])

All MATLAB

The following set the line widths to 1 for each plot and then sets the color based on a value for red, green, and blue -- these need to be between 0 and 1 for each component. [0.5 0 0] is thus dark red, [0 0 0.5] is dark blue, and [0 0.5 0] is dark green. These need to be darker than MATLAB's defaults because, for example, the default green is too light.

Time = linspace(0, 3, 100);
plot(Time, Time.^2,      'k-',  'LineW', 1, 'Color', [0.5 0 0])
hold on
plot(Time, Time,         'k-.', 'LineW', 1, 'Color', [0 0 0.5])
plot(Time, Time.^2-Time, 'k--', 'LineW', 1, 'Color', [0 0.5 0])
hold off
legend('Total', 'v_{C}', 'v_{R}', 'location', 'best')

Newer MATLAB

For MATLAB 2014b or newer, there is a more efficient way to use the plot object to do the same work:

Time = linspace(0, 3, 100);
p=plot(Time, Time.^2, 'k-', Time, Time, 'k-.', Time, Time.^2-Time, 'k--');
p(1).Color = [0.5 0 0]; p(1).LineWidth = 1;
p(2).Color = [0 0 0.5]; p(2).LineWidth = 1;
p(3).Color = [0 0.5 0]; p(3).LineWidth = 1;
legend('Total', 'v_{C}', 'v_{R}', 'location', 'best')

The p object has information about each of the items that were plotted; you can then set them individually rather than having to have multiple plot commands. Note that Duke's UNIX system has MATLAB 2014a (so close!) so this will not work as yet on that system.

Python

Python's default colors are darker, so the code:

import numpy as np
import matplotlib.pyplot as plt

time = np.linspace(0, 3, 100)
fig, ax = plt.subplots(num=1)
fig.clf()
fig, ax = plt.subplots(num=1)

ax.plot(time, time**2, 'k-', linewidth=1, color=[0.5, 0, 0])
ax.plot(time, time, 'k-.', linewidth=1, color=[0, 0, 0.5])
ax.plot(time, time**2 - time, 'k--', linewidth=1, color=[0, 0.5, 0])
ax.legend(['Total', '$v_{C}$', '$v_{R}$'], loc='best')

could be simplified a little to be:

import numpy as np
import matplotlib.pyplot as plt

time = np.linspace(0, 3, 100)
fig, ax = plt.subplots(num=1)
fig.clf()
fig, ax = plt.subplots(num=1)

ax.plot(time, time**2, 'r-', linewidth=1)
ax.plot(time, time, 'b-.', linewidth=1)
ax.plot(time, time**2 - time, 'g--', linewidth=1)
ax.legend(['Total', '$v_{C}$', '$v_{R}$'], loc='best')

to use the format string versus the color kwarg.