| CS182 -- Lab 5: Tolerance Testing |
|
|
OverviewIn this lab, you should develop skills using functions. AcknowledgementThis assignment was developed by Dr. Eric Durant. ProceduresThe following electrical circuit takes an input function (Vi) and produces an output function (Vo).
The "gain" of this circuit, which can be thought of as the ratio of output amplitude to input amplitude when the input is a sine wave, is given by...
where ω is the frequency of an input sine wave (radians/s), and R and C measure relevant quantities of the 2 electrical components in the circuit (resistance in Ohms [Ω] and capacitance in Farads [F]). For this problem, assume that ω is exactly 1000 radians/s. The components have the following nominal (ideal) values
So, the nominal gain is gnom = 1 / sqrt((1000 * 1000 * 0.000001)^2+1) = 1 / sqrt(2) = 0.707... But, the real components available never meet these nominal values exactly. Instead, they have a tolerance which is given as a percentage. For example, consider a 1 kΩ resistor with 20% tolerance. 20% of 1 kΩ is 0.2 kΩ, so the resistor's value should be between 0.8 and 1.2 kΩ. Assume that both components have 20% tolerance and that component parameter values are evenly distributed within the tolerance range. Write a program that generates 10,000 pairs of random R and C values within the tolerance range. For each pair, calculate the gain of the circuit ("g" in the first equation above). Your program must output the following values that will be used by a graphing program to generate a histogram of gains.
You will need to use a pseudorandom number generator to solve this problem. One possible such generator was part of the old C standard library and is still included in standard C++. This generator consists of two functions. One, void srand(int), "seeds" the random number generator. That is, it starts the generator at a specified point. The other, int rand(), returns an effectively random value. Note that srand should only be called once in a program. After this, rand may be called each time a new random value is needed. The function rand() returns integer values between 0 and RAND_MAX where RAND_MAX is a constant defined in the cstdlib header. To use the srand/rand functions you must #include <cstdlib> (or stdlib.h). The random integer can be converted to a random double in the range 0 to 1 by the following code... static_cast<double>(rand()) / RAND_MAX Lab report (due 11:00pm, the day prior to week 7 lab)The lab report should be in your own words but need not be self-contained. Your report should include:
As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well. Your grade will depend on quality of design, clarity of code and documentation, as well as whether your program produces the correct results. If you have any questions, consult your instructor. |
| © 2002 Dr. Christopher C. Taylor | Office: CC-27C | Phone: 277-7339 | Last Updated: Mon Jan 27 06:09:15 2003 |
| I am responsible for all content posted on these pages; MSOE is welcome to share these opinions but may not want to. | |||