EGR 224/RC Measurements

From PrattWiki
Jump to navigation Jump to search

The following page provides some supplemental information for the Basic Electrical Measurements III lab for EGR 224L. It has been updated for Spring, 2020.

Clarifications / Troubleshooting

  • Instead of using measuring the resistance or capacitance values, just use the nominal values in each case.
  • If you get a "specified device not found" or something like that, try using 'Dev2' instead of 'Dev1' in the test_function code.
  • If one of your figures looks wrong, it probably is! Be sure to have a TA check your figures so that you leave the lab with a valid data set.
  • If you get an error:
DaqError: The specified resource is reserved. The operation could not be completed as specified.
Task Name: _unnamedTask<6>
You will need to restart the kernel and re-run the program. To restart the kernel, go to the $$\equiv$$ menu at the top right of the iPython console, click it, and select Restart kernel. This happens when Python tells the DAQ card to do something but doesn't tell it to stop doing something...
  • The warning
The PostScript backend does not support transparency; partially transparent artists will be rendered opaque.
is normal and can be ignored

Element Values

  • Resistances:
    • 1, 9, 17: 2.2 k\(\Omega\)
    • 2, 3, 10, 11, 18, 19: 4.7 k\(\Omega\)
    • 4, 5, 12, 13, 20, 21: 10 k\(\Omega\)
    • 6, 14, 16, 22: 15 k\(\Omega\)
    • 7, 8, 15, 23, 24: 22 k\(\Omega\)
  • Capacitances
    • 7, 15, 23: 2.2 \(\mu\)F
    • 4, 6, 8, 12, 14, 16, 20, 22, 24: 4.7 \(\mu\)F
    • 2, 5, 10, 13, 18, 21: 10 \(\mu\)F
    • 1, 3, 9, 11, 17, 19: 22 \(\mu\)F

Links


Plotting

For your plots, the total voltage should be a thick dark red line, the resistor voltage should be a medium width dark blue line, and the capacitor voltage should be a thin 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^2-t\), and \(t\). Note that you will need to add code for the axis labels and titles.

Examples of Different Colors and Widths

Maple

plot([t^2, t^2-t, t], t = 0 .. 3, thickness = [7, 5, 3], legend = ['v[Total]', 'v[R]', 'v[C]'])

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,      '-', 'LineW', 7, 'Color', [0.5 0 0])
hold on
plot(Time, Time.^2-Time, '-', 'LineW', 5, 'Color', [0 0 0.5])
plot(Time, Time        , '-', 'LineW', 3, 'Color', [0 0.5 0])
hold off
legend('Total', 'v_{R}', 'v_{C}', '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, '-', Time, Time.^2-Time, '-', Time, Time, '-');
p(1).Color = [0.5 0 0]; p(1).LineWidth = 7;
p(2).Color = [0 0 0.5]; p(2).LineWidth = 5;
p(3).Color = [0 0.5 0]; p(3).LineWidth = 3;
legend('Total', 'v_{R}', 'v_{C}', '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 now has MATLAB 2019a.

Python

Python's default colors are darker than MATLAB's (though not as dark as Maple's), so the code:

import numpy as np
import matplotlib.pyplot as plt

time = np.linspace(0, 3, 100)
fig = plt.figure(num=1, clear=True)
ax = fig.add_subplot(1, 1, 1)

ax.plot(time, time**2, 'r-', linewidth=7, label='Total')
ax.plot(time, time**2 - time, 'b-', linewidth=5, label='$v_{R}$')
ax.plot(time, time, 'g-', linewidth=3, label='$v_{C}$')
ax.legend(loc='best')

works without having to directly specify the colors. If you want to make the colors the same as Maple and/or MATLAB, you can do that with the color kwarg in the plot command:

import numpy as np
import matplotlib.pyplot as plt

time = np.linspace(0, 3, 100)
fig = plt.figure(num=1, clear=True)
ax = fig.add_subplot(1, 1, 1)

ax.plot(time, time**2, 'r-', linewidth=7, label='Total', color=[0.5, 0, 0])
ax.plot(time, time**2 - time, 'b-', linewidth=5, label='$v_{R}$', color=[0, 0, 0.5])
ax.plot(time, time, 'g-', linewidth=3, label='$v_{C}$', color=[0, 0.5, 0])
ax.legend(loc='best')

Examples Using Different Line Styles

If just changing the color and width is insufficient for you do tell the difference between the three lines, you can also employ different line styles. The example code below will replicate the graphs above, only the code will also use a solid line for the total voltage, a dash-dot line for the resistor voltage, and a dotted line for the capacitor voltage

Maple

Use the linestyle option (shown at end of the plot command)

plot([t^2, t^2-t, t], t = 0 .. 3, thickness = [7, 5, 3], legend = ['v[Total]', 'v[R]', 'v[C]'], linestyle = [1, 4, 2])

All MATLAB

Use the format specifier for the different line styles (i.e. replace '-' with '-,' for dash-dot and ':' for dotted):

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

Newer MATLAB

Use the format specifier for the different line styles (i.e. replace '-' with '-,' for dash-dot and ':' for dotted):

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

Python

Use the format specifier for the different line styles (i.e. replace '-' with '-,' for dash-dot and ':' for dotted):

import numpy as np
import matplotlib.pyplot as plt

time = np.linspace(0, 3, 100)
fig = plt.figure(num=1, clear=True)
ax = fig.add_subplot(1, 1, 1)

ax.plot(time, time**2, 'r-', linewidth=7, label='Total')
ax.plot(time, time**2 - time, 'b-.', linewidth=5, label='$v_{R}$')
ax.plot(time, time, 'g:', linewidth=3, label='$v_{C}$')
ax.legend(loc='best')

or:

import numpy as np
import matplotlib.pyplot as plt

time = np.linspace(0, 3, 100)
fig = plt.figure(num=1, clear=True)
ax = fig.add_subplot(1, 1, 1)

ax.plot(time, time**2, 'r-', linewidth=7, label='Total', color=[0.5, 0, 0])
ax.plot(time, time**2 - time, 'b-.', linewidth=5, label='$v_{R}$', color=[0, 0, 0.5])
ax.plot(time, time, 'g:', linewidth=3, label='$v_{C}$', color=[0, 0.5, 0])
ax.legend(loc='best')