Exercise 4 Modeling transient currents and voltages Basic A circuit elements In a D circuit, the electro-motive forces push the electrons along the circuit and resistors remove that energy by conversion to heat. In A circuits, currents vary in time, so we have to consider variations in the energy stored in electric and magnetic fields of capacitors and inductors, respectively. apacitance: the capacitance between two opposite charged surfaces is defined by: Q V Where: Q is the magnitude of the charge distributed on either surface, and V is the potential difference between the surfaces. Differentiating Eq. (1) and using I = dq/dt, we obtain: (1) dv dt I () Inductance: The usual model for an inductor is a coil (solenoid). By Faraday s Law of self-inductance, a changing current in a coil induces a back electro-motive force (emf) that opposes the change in current: Where V is the back emf across the inductor, di/dt is the derivative of the current through the inductor and L is the inductance. The R ircuit Figure 1a) shows a circuit with no signal source, but we assume the capacitor to be initially charged. The voltage across the charged capacitor is: Q V di V L dt This voltage produces an initial loop current (3) (4) V I (5) R 1
Figure 1 a) The R circuit; b) Exponential decay of voltage as a function of time (R circuit). dv V By using Kirchhoff s loop rule and the derivative of Ohm s law:, the dt R voltage across the resistor (and capacitor) is given by: V ( t) V e t / R V e t / (6) The constant τ = R is called the time constant of this circuit. It defines the time needed for V(t) to fall to 1/e of its initial value. The voltage decay as a function of time is presented in Figure 1b). The Exercise You will use a circuit board with several resistors, capacitors and inductors. You may use Box A, below: BOX A
Alternatively, your group may work on Box B: BOX B A Data Acquisition System (DAQ) will provide the A voltages needed in your experiment. At the same time, the DAQ will collect data from the circuit (Voltage, Time) and send them to the computer. Some of the DAQ ports are already connected. Do not change them. You will use the Analog Output (a o ) port as the A voltage source for your circuit. onnect the BN wire at the top of the T-connector on a o. You will also collect the data from the circuit through the Analog Input (a i ) port. Data in real time will be displayed through a Lab View application. a o a i Figure : ircuit diagram 3
Build a R circuit according to Figure, using = 1.μF and an R of your choice. If you use Box A, connect the R var (Potentiometer 5-5kΩ). If you have Box B, choose any of the two resistors provided. Open the Desktop folder: nd Yr Lab Files and select harge and Discharge of a apacitor (Lab View Application). The Analog Output works as a function generator. Use the Square Wave form and vary the frequency until you observe -3 cycles of charging/discharging of the capacitor. In the background of the charge/discharge, you may notice the square wave (light grey). The whole dataset will have about 1 data points, which is a little too much for your Python program. Trimming the dataset is possible with Export Data, by confirming the length editing. ursors are now available. Place them at the two ends of one decay (or rise) and click on Export Data again. Save the text file on your memory stick. The dataset has Time(s) in the first column and Amplitude (Volt) in the second. Scroll down and examine the file. You will notice that some of the amplitude values are negative and also that the file has a header. Remove the header. Data was acquired as with an oscilloscope: zero amplitude is at the middle of the graph. You have to adjust (lift) all the amplitude values so that all are positive: find the largest negative amplitude and add its absolute value to all the data. The fitting program You will write the code for a nonlinear least squares fit, and will estimate the uncertainties and the correlations. alculation of fit statistics from the output of leastsq provides: - Goodness of fit parameters - onfidence intervals in fit parameters - orrelation (covariance) of variables Here is the plan of your program: - Import all the needed packages. - Define the fitting function, named peval(x,p)or else, where x is the independent variable (time) and p is the generic name of the parameters. You have to define what each component of p represents. The fitting function is the exponential from Eq.6. - Define residuals. - Load the file into an array. You have to specify the location of independent variable (x) and that of the dependent variable (y) in your array. You also have to define the uncertainty in y. - Estimate an initial guess of the parameters. - all leastsq to do the work. List the input arguments: residuals, initial guess of parameters, extra arguments (args). full_output has to be non-zero in order to return all optional outputs. Request the following outputs of leastsq: final values of parameters (p_final), estimate of covariance of x,y (cov_x), optional outputs (info), a string message giving information about the cause of failure of calculation (mesg), a flag indicating if solution was found or not (success). - Write a conditional loop linking success==1 to printing the result of the fit. - Define and the number of degrees of freedom. 4
- Output the statistical results. In order to output the errors in parameters, you have to use the cov_x output of leastsq. Look at the definitions from SciPy documentation: http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html?highlight =leastsq#scipy.optimize.leastsq cov_x : ndarray Uses the optional outputs to construct an estimate of the jacobian around the solution. This matrix must be multiplied by the residual variance to get the covariance of the parameter estimates. The residual variance is given by: dof heck the Notes on Error Analysis for basic definitions: http://www.physics.utoronto.ca/~phy5h/web-pages/notes_error.pdf - Plot the graph of data with error bars and the fitting function. Python Programming: Write a fitting program with statistical output to fit the R transient voltage. Output the time constant τ and calculate R (R var ). Estimate uncertainties. ompare the calculated value with a direct measurement of R or R var using a multimeter. Note: disconnect R (R var ) from the circuit before connecting the instrument! Write the code, debug it. Print the graph and statistical output. Analyze the output according to the goodness of fit criteria: - Good fit: 1. - If: 1, there are too large deviations from the assumed distribution, which indicate an underestimation of uncertainties. - If: 1, too small deviations from the assumed distribution indicate an overestimation of uncertainties. Analyze the goodness of the fit and comment on uncertainties. Written by Ruxandra Serbanescu (1-13). The Data Acquisition System was built by Larry Avramidis. Larry also wrote the LabView application. References: L.R. Fortney Principles of Electronics: Analog and Digital, Harcourt Brace Jovanovich 1987 5