CS182 -- Lab 5: Tolerance Testing



->Courses
->CS182
-->Objectives
-->Homework
-->Quiz 1
-->Lab 1
-->Lab 2
-->Lab 3
-->Lab 4
->Lab 5
-->Lab 6
-->Project
->Electronic Submission
->Old Exams
->C++ Examples
->MSVC Info
->Software
->Tentative Schedule
->Support Forum
->Course Policies

[Courses]
[Rich][Home][Rich]
[Author]

Winter Quarter 2002-2003

It's been my observation that 90% of statisticians pretty much ruin it for the other 30%.
Keith Sullivan

Overview

In this lab, you should develop skills using functions.

Acknowledgement

This assignment was developed by Dr. Eric Durant.

Procedures

The following electrical circuit takes an input function (Vi) and produces an output function (Vo).

[RC lowpass filter]

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...

[RC lowpass gain equation]

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

  • R = 1 kΩ
  • C = 1 μF

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.

  • the proportion of gains less than 0.9 * gnom
  • the proportion of gains between 0.9 * gnom and gnom
  • the proportion of gains between gnom and 1.1 * gnom
  • the proportion of gains above 1.1 * gnom

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:

  • Which functions you chose to write and why.
  • Sample program output and histogram image file (save as 182msoeloginL5.png where msoelogin is your msoe login) which may be created using the output of your program and MS Excel or some other graphing tool.
  • Discussion including problems you encountered (and how they were overcome), etc.
  • An activity log indicating how much time you spent on each phase of the assignment. You should use the format found in the template XML file and report the time in the following categories:
    • Design
    • Coding
    • Debug (before you think it's working)
    • Test (after you think it's working)
    • Writing Report
    • Other
  • Conclusions (what you learned, suggestions of how the assignment could be improved, things you would have done differently, etc.)
  • Documented source code for your program.

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.