Difference between revisions of "EGR 224/RC Measurements"
(Created page with "The following page provides some supplemental information for the '''Basic Electrical Measurements III''' lab for EGR 224L. It has been updated for Spring, 2020....") |
(→Plotting) |
||
Line 47: | Line 47: | ||
==== Maple ==== | ==== Maple ==== | ||
<source lang=text> | <source lang=text> | ||
− | plot([t^2 | + | plot([t^2, t^2-t, t], t = 0 .. 3, thickness = [7, 5, 3], legend = ['v[Total]', 'v[R]', 'v[C]']) |
</source> | </source> | ||
− | === All MATLAB === | + | ==== 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. | 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. | ||
<source lang=matlab> | <source lang=matlab> | ||
Time = linspace(0, 3, 100); | Time = linspace(0, 3, 100); | ||
− | plot(Time, Time.^2, '-', | + | plot(Time, Time.^2, '-', 'LineW', 7, 'Color', [0.5 0 0]) |
hold on | hold on | ||
− | plot(Time, Time, | + | plot(Time, Time.^2-Time, '-', 'LineW', 5, 'Color', [0 0 0.5]) |
− | plot(Time, Time | + | plot(Time, Time , '-', 'LineW', 3, 'Color', [0 0.5 0]) |
hold off | hold off | ||
legend('Total', 'v_{R}', 'v_{C}', 'location', 'best') | legend('Total', 'v_{R}', 'v_{C}', 'location', 'best') | ||
Line 66: | Line 66: | ||
<source lang=matlab> | <source lang=matlab> | ||
Time = linspace(0, 3, 100); | Time = linspace(0, 3, 100); | ||
− | p=plot(Time, Time.^2, '-', Time, Time, '-', Time, | + | p=plot(Time, Time.^2, '-', Time, Time.^2-Time, '-', Time, Time, '-'); |
− | p(1).Color = [0.5 0 0]; p(1).LineWidth = | + | p(1).Color = [0.5 0 0]; p(1).LineWidth = 7; |
− | p(2).Color = [0 0 0.5]; p(2).LineWidth = | + | p(2).Color = [0 0 0.5]; p(2).LineWidth = 5; |
− | p(3).Color = [0 0.5 0]; p(3).LineWidth = | + | p(3).Color = [0 0.5 0]; p(3).LineWidth = 3; |
legend('Total', 'v_{R}', 'v_{C}', 'location', 'best') | legend('Total', 'v_{R}', 'v_{C}', 'location', 'best') | ||
</source> | </source> | ||
− | 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 | + | 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==== | ||
− | Python's default colors are darker than MATLAB's, so the code: | + | Python's default colors are darker than MATLAB's (though not as dark as Maple's), so the code: |
<source lang=python> | <source lang=python> | ||
import numpy as np | import numpy as np | ||
Line 85: | Line 85: | ||
ax.plot(time, time**2, 'r-', linewidth=7, label='Total') | ax.plot(time, time**2, 'r-', linewidth=7, label='Total') | ||
− | ax.plot(time, time, 'b-', linewidth=5, label='$v_{R}$') | + | ax.plot(time, time**2 - time, 'b-', linewidth=5, label='$v_{R}$') |
− | ax.plot(time, | + | ax.plot(time, time, 'g-', linewidth=3, label='$v_{C}$') |
ax.legend(loc='best') | ax.legend(loc='best') | ||
</source> | </source> | ||
− | works without having to directly specify the colors. If you want to make the colors | + | 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: |
<source lang=python> | <source lang=python> | ||
import numpy as np | import numpy as np | ||
Line 99: | Line 99: | ||
ax.plot(time, time**2, 'r-', linewidth=7, label='Total', color=[0.5, 0, 0]) | ax.plot(time, time**2, 'r-', linewidth=7, label='Total', color=[0.5, 0, 0]) | ||
− | ax.plot(time, time, 'b-', linewidth=5, label='$v_{R}$', color=[0, 0, 0.5]) | + | ax.plot(time, time**2 - time, 'b-', linewidth=5, label='$v_{R}$', color=[0, 0, 0.5]) |
− | ax.plot(time, | + | ax.plot(time, time, 'g-', linewidth=3, label='$v_{C}$', color=[0, 0.5, 0]) |
ax.legend(loc='best') | ax.legend(loc='best') | ||
</source> | </source> | ||
Line 106: | Line 106: | ||
=== Examples Using Different Line Styles === | === 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 | 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 === | + | |
+ | ==== Maple ==== | ||
+ | Use the linestyle option (shown at end of the plot command) | ||
<source lang=text> | <source lang=text> | ||
− | plot([t^2 | + | 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]) |
</source> | </source> | ||
− | === All MATLAB === | + | ==== All MATLAB ==== |
− | + | Use the format specifier for the different line styles (i.e. replace '-' with '-,' for dash-dot and ':' for dotted): | |
<source lang=matlab> | <source lang=matlab> | ||
Time = linspace(0, 3, 100); | Time = linspace(0, 3, 100); | ||
− | plot(Time, Time.^2, ' | + | plot(Time, Time.^2, '-', 'LineW', 7, 'Color', [0.5 0 0]) |
hold on | hold on | ||
− | plot(Time, Time, | + | plot(Time, Time.^2-Time, '-.', 'LineW', 5, 'Color', [0 0 0.5]) |
− | plot(Time, Time | + | plot(Time, Time , ':', 'LineW', 3, 'Color', [0 0.5 0]) |
hold off | hold off | ||
− | legend('Total', 'v_{ | + | legend('Total', 'v_{R}', 'v_{C}', 'location', 'best') |
</source> | </source> | ||
− | ===Newer MATLAB=== | + | |
− | + | ====Newer MATLAB==== | |
+ | Use the format specifier for the different line styles (i.e. replace '-' with '-,' for dash-dot and ':' for dotted): | ||
<source lang=matlab> | <source lang=matlab> | ||
Time = linspace(0, 3, 100); | Time = linspace(0, 3, 100); | ||
− | p=plot(Time, Time.^2, ' | + | p=plot(Time, Time.^2, '-', Time, Time.^2-Time, '-.', Time, Time, ':'); |
− | p(1).Color = [0.5 0 0]; p(1).LineWidth = | + | p(1).Color = [0.5 0 0]; p(1).LineWidth = 7; |
− | p(2).Color = [0 0 0.5]; p(2).LineWidth = | + | p(2).Color = [0 0 0.5]; p(2).LineWidth = 5; |
− | p(3).Color = [0 0.5 0]; p(3).LineWidth = | + | p(3).Color = [0 0.5 0]; p(3).LineWidth = 3; |
− | legend('Total', 'v_{ | + | legend('Total', 'v_{R}', 'v_{C}', 'location', 'best') |
</source> | </source> | ||
− | + | ||
− | ===Python=== | + | ====Python==== |
− | + | Use the format specifier for the different line styles (i.e. replace '-' with '-,' for dash-dot and ':' for dotted): | |
<source lang=python> | <source lang=python> | ||
import numpy as np | import numpy as np | ||
Line 140: | Line 143: | ||
time = np.linspace(0, 3, 100) | time = np.linspace(0, 3, 100) | ||
− | fig | + | fig = plt.figure(num=1, clear=True) |
− | fig. | + | ax = fig.add_subplot(1, 1, 1) |
− | |||
− | ax.plot(time, time**2, ' | + | ax.plot(time, time**2, 'r-', linewidth=7, label='Total') |
− | ax.plot(time, time, ' | + | ax.plot(time, time**2 - time, 'b-.', linewidth=5, label='$v_{R}$') |
− | ax.plot(time, | + | ax.plot(time, time, 'g:', linewidth=3, label='$v_{C}$') |
− | + | ax.legend(loc='best') | |
</source> | </source> | ||
− | + | or: | |
<source lang=python> | <source lang=python> | ||
import numpy as np | import numpy as np | ||
Line 155: | Line 157: | ||
time = np.linspace(0, 3, 100) | time = np.linspace(0, 3, 100) | ||
− | fig | + | fig = plt.figure(num=1, clear=True) |
− | fig. | + | ax = fig.add_subplot(1, 1, 1) |
− | |||
− | ax.plot(time, time**2, 'r-', linewidth= | + | ax.plot(time, time**2, 'r-', linewidth=7, label='Total', color=[0.5, 0, 0]) |
− | ax.plot(time, time, 'b-.', linewidth= | + | ax.plot(time, time**2 - time, 'b-.', linewidth=5, label='$v_{R}$', color=[0, 0, 0.5]) |
− | ax.plot(time, | + | ax.plot(time, time, 'g:', linewidth=3, label='$v_{C}$', color=[0, 0.5, 0]) |
− | + | ax.legend(loc='best') | |
</source> | </source> | ||
− | |||
− | |||
− | |||
[[Category:EGR 224]] | [[Category:EGR 224]] |
Revision as of 22:04, 2 March 2020
The following page provides some supplemental information for the Basic Electrical Measurements III lab for EGR 224L. It has been updated for Spring, 2020.
Contents
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
DaqError: The specified resource is reserved. The operation could not be completed as specified.
Task Name: _unnamedTask<6>
- 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
- The files for this assignment can be downloaded from http://classes.pratt.duke.edu/FILES/EGR224/DAQS/ElecMeasRC
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\), and \(t^2-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')