Sunteți pe pagina 1din 37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

Circuit Analysis with Octave, Maxima and PSpice


Adopted from the article [1]

Introduction
Circuit analysis can be thought of as a two step process; the first step is the conceptual one and the second step is a mechanical one. The conceptual step consists of converting a circuit description into a set of mathematical equations which relates the currents and voltages in different parts of the circuit. The mechanical step consists of solving the derived set of equations. This is illustrated using a sketch in Figure 1. Generally students give too much importance to the mechanical step, i.e., in solving the mathematical equations, and consequently they lack confidence in the concepts of circuit theory. In phasor analysis, students learn phasor analysis just when they are learning about complex numbers, so very soon they forget the theory behind phasor analysis and all their energy goes into mastering the complex number calculations.
Wrong Way

Start

Circuit Analysis
fig1-OMP.m4

Conceptual Step

Mechanical step

Solution

Figure 1: A Pictorial Guide to Circuit Analysis

As a remedy to this situation you are encouraged to use computers as much as possible to carry out the (second) mechanical step of the circuit analysis. Concentrate all your energies on the conceptual step and very soon circuit analysis will be that reasonably easy. The conceptual step consists in using KCL (node equations) or KVL (loop equations) to mathematically describe a circuit plus some initial conditions for the transient analysis part. It is the intention in this article to firstly show you how circuit analysis can be always broken into the above two steps and secondly to get you to use computers to ease your burden in carrying out the mechanical step. In the following we discuss three general purpose packages you are encouraged to use to help you with the mechanical manipulations in the circuit analysis. After a brief introduction to the three general purpose packages we will see how we analyze four circuits with the assistance of these three packages.

Matlab/Octave
Matlab/Octave is a calculator on a computer. To start the Matlab program you double-click on the icon Matlab or Octave. Once the Matlab or Octave program is running it prompts for an input; the most common prompt is >. When you want to calculate 2*2 on a calculator you press the following key sequence: 2 * 2 = and the answer is displayed on the screen. A Matlab or Octave session to do the same looks like: > 2*2 E N T E R ans=4
Most calculators have a one line display but Matlab/Octave has almost an endless display and ability to recall previous calculations. Moreover the output of calculations can be stored in variables and used later. For example the above session can be: > c=2*2 E N T E R

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

1/37

EE210/EE316
c=4

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

A big difference between a calculator and Matlab or Octave is that most calculators can only store real numbers while with Matlab or Octave variables can be more general like complex numbers and matrices. This means that after giving a numerical value to a matrix variable you can be used just like any other variable. For example try: > a=[1,0;0,1] Enter > b=[2,0;0,2] Enter > c=a*b E N T E R Matlab and Octave also have hundreds of predefined functions which make it possible to write short scripts to perform complex calculations. In fact Matlab has a powerful programming language (C-like) that includes for loop, if statement, open and close files, dynamic arrays, and graphics along with specialized toolboxes such as Signal Processing, Neural Networks, Control, and Image Processing toolboxes. Matlab as well as Octave are available on the department computers. Start using Matlab or Octave as early as possible as a general computation tool will pay rich dividends later. We will discuss more about Matlab and Octave along with the four examples later. Octave can be downloaded freely from:

http://surfnet.dl.sourceforge.net/sourceforge/octave/octave-2.1.73-1-inst.exe
Matlab is not free.

Maxima
Maxima will do most of the things Matlab does and it will do more; Maxima will perform symbolic computations for you. Once you learn to use Maxima you can replace the traditional pencil and paper note
taking. Many times while taking notes or solving a problem you would want to keep some variables in symbolic form and not assign any numerical value to them. With programs like Matlab which only do numerical computation it is not possible to keep anything in a symbolic form and hence a computer cant be turned into a note book (note that Matlab added a symbolic toolbox which is a derivative from Maple but with some alterations made on the Maple style of writing but originally Matlab is NOT a symbolic manipulator as (Maxima, Maple, Mathematica, Derive, etc) . With Maxima you can turn your computer into a computing machine and a traditional note book. The latest version of Maxima (version 5.10.0b Oct 2006) is freely available from

http://mesh.dl.sourceforge.net/sourceforge/maxima/maxima-5.10.0b.exe
We will see more of Maxima while solving the circuits later.

PSpice
PSpice is a port of the legendary SPICE (simulation program with integrated circuit emphasis) package to micro computers. This program performs all the circuit analysis you will need to perform and much more. The text-book has a good introduction to PSpice. An evaluation copy can be found at:

http://www.engr.uky.edu/~cathey/pspice/Ps8_0.zip

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

2/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

2 Sample Problems
We will solve problems on DC analysis, AC analysis, Transient analysis, and Frequency Response. Each problem will be addressed using PSPICE, Matlab/Octave, and Maxima. (2-a) DC Analysis In this problem we need to find the voltages at nodes 1 and 2 in the circuit shown in Figure 2. Node numbers are shown next to the nodes.
3 + R1 1 R3 2

vin = 10V

R2

1A

R4

example1.m4

Figure 2: Circuit Example 1

The Conceptual Step


To analyze the circuit in Figure 2 the first step is to use KCL and write node voltage equations.

-(V1-10)/R1-V1/R2-(V1-V2)/R3=0 -(V2-V1)/R3-V2/R4+1=0

(KCL@ node 1) (1) (KCL@ node 2) (2)

The most important part of the solution is to write node voltage equations (1) and (2); rest is mechanical. To get the values of V1, and V2 we have to solve equations (1) and (2). (i) Matlab/Octave M a t l a b ( O c t a v e ) understands the language of matrices. Equations (1) and (2) have to be rewritten in a matrix form before we can use M a t l a b to solve them. A matrix equivalent of equations (1) and (2) is:
Av=b With A being the matrix of coefficients, v the unknown vector, and b the right-hand side A=[1/R1+1/R2+1/R3, -1/R3; -1/R3, 1/R3+1/R4]; b=[10/R1; 1]; v=inv(A)*b;

The above relationship is solved using Matlab as shown below. Double click on the Octave (or Matlab) icon and wait for the interactive session to start. Type each line as shown below, terminating them with E N T E R %Example1.m 2006-11-26
J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

3/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

R1=2; R2=2; R3=3; R4=4; A=[1/R1+1/R2+1/R3, -1/R3; -1/R3, 1/R3+1/R4] b=[10/R1;1] vnode=inv(A)*b v1=vnode(1) v2=vnode(2) % and the output will be %A =[1.33333, -0.33333; -0.33333, 0.58333] %b =[5; 1] %vnode =[4.8750; 4.5000] %v1 = 4.8750 %v2 = 4.500 Everything following a % sign on a line is ignored by Matlab/Octave; in other words comments should be preceded by %. The second line above assigns numerical values to the resistors. The third line defines a as the required matrix. In Matlab, matrices are enclosed in square brackets [ ]; row 1 is input first with entries separated by a coma , or a space and then row 2 is entered and so on. Rows are separated by either a semicolon ; or a new-line character. The fourth line in the script above solves for the vector with voltages V, and V2; inv is a built-in Matlab function. To see what it does type help inv and Matlab tells you the entire story. Incidentally to learn more about any function funname ' just say help funname and Matlab will tell you what its all about. If you want to know if Matlab has a built-in function for what you want to do just type lookfor funIwant. For example if you wanted to know if there is a function which will perform matrix inversion type lookfor inverse. To learn more about Matlab just type expo or help and follow the direction. Instead of typing all the instructions (commands) in an interactive Matlab session one by one (interactive mode) you can store them in a file and get Matlab to execute it all in one step (batch mode). Use your favorite editor (emacs, vi, notepad, crimson, pfe among other text editors) to create a file example1.m. Type in the entire sequence of instructions as shown above in the file and save it. Start a Matlab session from the same directory where you created the file and when Matlab prompts you for a command, type example1. There is nothing special about the name example1.m you can use any name; remember that the file should have an extension .m; if you dont want the output of a command to be displayed on the screen, terminate the command with a semi-colon, ;. Try help diary. Matlab keeps a command history of all the commands entered in the session; to scan forward and backward in the command history, type (up arrow) for backward, and (down arrow) for forward. (ii) Maxima To solve the circuit in Example 1 the first step was a conceptual one leading to node voltage equations (1) and (2). To use Matlab in solving these equations we had to convert the equations to matrix form. With Maxima we can avoid even that step; problems can be presented to Maxima just the way you formulate it. Start a Maxima session by double clicking on its icon. Once a Maxima session starts, type the following lines one at a time and terminate them by pressing E N T E R
/*Example 1 */ restart; eqn1: (v1-10)/R1+v1/R2+(v1-v2)/R3=0; eqn2: (v2-v1)/R3+v2/R4=1; sol: ev(solve([eqn1,eqn2],[v1,v2]),R1=2, R2=2, R3=3, R4=4); float(sol); /* answer v1=4.875, v2=4.5 */

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

4/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

The first line in the script is a comment line; comments should be between /* */. Second and third lines tell Maxima the equations describing the circuit. The next line is a command to solve both these equations for the variables v1 and v2. The next statement verifies that Maxima has indeed generated a correct solution; it substitutes the solution sol in the equations to make sure that there has been no error in the computation. The line following it tells Maxima to assign values to the variables v1 and v2 as computed by the solve command. The last part of the script assigns numerical values to these parameters. Every Maxima command should end with a semi-colon, ; and if you want Maxima not to display the result on the terminal, terminate the command by a colon $. Maxima also has an option to read in script files. Use your favorite editor or pfe and create a file example1.mac. Type in all of the Maxima script shown above. Start a new Maxima session from within the directory where the file example1.mac lives. From the file menu, batch file and pick your file
example1.mac which will enable Maxima to run it immediately. It is a good practice to start your session (or batch file) with the command: restart;

If at any time you feel that Maxima is not behaving as it should, then close it and restart it and try again.
(iii) PSpice Start the editor textedit, type in the script shown below and save the file as example1.cir. After creating and saving the file, double-click on the PSpice application. Then go to the open under file menu; select the file example1.cir and PSp ice will perform the simulation. If there are any errors then an error description can be found in the file example1.out; correct them in the original file example1.cir and then try again, i.e. go to PSpice, open the file, etc. PSpice comes with another program Probe which is used to display and plot the results from PSpice. Double-click on Prob e icon and again go to open in the file menu and open the file example1.dat and follow the steps (from the menu Trace, Add, V(1)). Example1.cir
v1 3 0 DC 10V R1 3 1 2 R2 1 0 2 R3 1 2 3 R4 2 0 4 I1 0 2 1A * next are the commands (start with dot) .DC v1 0 20 .2 .PRINT DC I(R1) V(1) V(2) I(R4) .PROBE .END

The first line of every PSpice script has to be a title line and it will be considered as a comment or title line. Every circuit should have a node 0, the reference node. Rest of the nodes can have any arbitrary number but the reference node has to be numbered 0. The second line declares that the circuit has a voltage source between the nodes 3 and 0 of 10V DC. The following four lines tell resistor values. Voltage sources have to have v as the first letter, resistors have to have R as the first letter etc. PSpice is case insensitive, i.e. vsrc10 is the same as VSRC10.

Line #8 starts with an asterisk * (the comment indicator in PSpice scripts). Comment lines are ignored by SPICE. All commands are preceded by a dot, .. 2006-11-26
J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

5/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

The command .DC v1 0 20 0.2 tells PSpice to calculate various voltages and currents in the circuit when v1 varies between 0 and 20V in the steps on 0.2V; .DC means perform a DC analysis; more about this later. The .PRINT command prints the values of all the parameters listed on the same .PRINT line in a file having extension .out; I(R1) means current through the resistor R1 and V(2) means the voltage at node 2, etc. The command .PROBE tells PSpice to create a .dat file suitable to be read by P r o b e f o r p l o t t i n g . All P S p i c e scripts must terminate with a .END line. A .cir file is automatically created from .sch to be fed into PSpice. Alternatively a .cir file can be created using an editor (TextEdit) as discussed above and then read into PSpice. On completing the simulation, from PSPICEAD-File- Run Probe program, and on Probe TraceAdd-V(2). The Design Centre also has good help features.
Also from PSPICEAD- File- Examine Output to view the printed output (.out file produced as a result of the simulation). (2-b) AC Analysis

The example in the last section was meant to get you familiar with three very useful packages. In this example we will do something meaningful from the circuit analysis point of view and consolidate what we have already learnt about the three packages. The problem here is to find the steady-state output voltage for the circuit shown in Figure 3 for a 1000 Hz sinusoidal input.

The Conceptual Step


The problem asks for a steady-state output to a circuit with a sinusoidal input and this is where we use phasor analysis. Remember that in phasor analysis all the elements are replaced by their equivalent impedances. After replacing all the capacitors by their impedances, the following two nodal equations describing the circuit can be written.
rb vin + sin(2 1000t) + cv1 r c gm v1 ro rc Rl + vout

fig3-OMP.m4

Figure 3: Circuit Example 2


-(v1-vin)/rb-v1/rpi-j*w*cpi*v1-j*w*cpi*(v1-v2)=0

(KCL @ node 1) (3) -v2/r0-v2/(rc+Rl)-gm*v1-j*w*cmu*(v2-v1)=0 (KCL @ node 2) (4) In the following Matlab and Maxima scripts the above two equations are solved for the output voltage, vout.

(i) Matlab

First rewrite the equations (3) and (4) in a matrix form and see that the following M a t l a b script correctly encodes the matrix. Either create a file example2.m with the following script or execute this script interactively and note down the output voltage. What is the physical significance of the complex number you get as the output voltage?
%Example2.m
rb=10;

cpi=0.01*10(-6); r p i = 2 6 0 0 ; cmu=1*10(-12);
J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

2006-11-26

6/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

gm=40*10(-3); r0=100*10(3); r c = 1 0 0 ; w=2*pi*1000; Rl=5000; v i n =1; A=[1/rb+1/rpi+i*w*cpi+i*w*cmu, - i * w * c m u ; gm-i*w*cmu, 1/r0+1/(rc+Rl)+i*w*cmu] b=[vin/rb;0] vnode= inv(a)*b
Vout=vnode(2)*Rl/(rc+Rl) And the output A = 0.10038 + 0.00006i 0.00000 - 0.00000i 0.04000 - 0.00000i 0.00021 + 0.00000i b = 0.10000 0.00000 vnode = 0.99617 -193.35709 +

0.00064i 0.12931i 0.12678i

Vout = -189.56578 + (ii) Maxima

The Maxima script given below should by now begin to mean something to you. Either save the following script in a file example2.mac or interactively execute the commands and note the output voltage. The last command float in the following script is requesting from Maxima to evaluate the variable in floating point arithmetic. /*Example2.mac */ restart; eqn1: -(v1-vin)/rb - v1/rpi - %i*w*cpi*v1-(v1-v2)*%i*w*cmu=0; eqn2: -v2/r0-v2/(rc+Rl) - gm*v1 - (v2-v1)*%i*w*cmu=0; rb:10; cpi:0.01*10^(-6); rpi:2600; cmu:1*10^(-12); gm:40*10^(-3); r0:100*10^(3); rc:100; w:2*%pi*1000; vin:1; Rl:5000; sol:solve([eqn1,eqn2],[v1,v2]); float(sol); Vout: v2*Rl/(rc+Rl); float(Vout);
(iii) PSpice

Create a n d save the following PSpice script in a file called example2.cir. Use PSpice and Probe to simulate the circuit behavior.
*Example2.cir v1 3 0 AC 1V rb 3 1 10

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

7/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

cpi 1 0 0.01uF rpi 1 0 2600 cmu 1 2 1pF r0 2 0 100K rc 2 4 100 Rl 4 0 5000 G1 2 0 1 0 40m .AC LIN 10 100 2000 ; 100= # of points between 100Hz and 2000Hz .PROBE
.END

Most of the commands in the above script should be clear. The declaration
G1 2 0 1 0 40m tells PSpice that this is a voltage dependent current source between the nodes 20,

controlled by the voltage across the nodes 10, with a gain of 40milli=40e-3). The command .AC LIN 10 100 2000 tells PSpice to perform phasor analysis for input sinusoids with frequencies between 100 and 2000 Hz, varying linearly in 10 Hz intervals. Finally use Probe to see the frequency response.

By default, Probe produces plots on a black background. To change the background color of plots produced by probe from black to white and the plotting to be in black, blue, red, you need to open the file C:\MSimEv_8\Bin\package.ini using notepad.exe (or any other text editor) and add the following lines in the indicated locations: [Probe Display Colors] background=brightwhite foreground=blue trace_1=black trace_2=blue trace_3=red trace_4=green 2006-11-26
J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

8/37

EE210/EE316 trace_5=brown trace_6=magenta trace_7=darkgray and save the file.

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

2-c Transient Analysis: (i) PSPICE


Consider a series RLC circuit with DC voltage of 10 volts as described in the following .CIR files 1k 1H

10V

0.5

RLC.transient.m4

Transient in RLC circuit *RLC.Transient.cir V10 1 0 dc 10V R12 1 2 8k; 1k, 2k, 4k, 8k L23 2 3 1H ic=0 C30 3 0 0.5u ic=0 .tran 20m 20m 0 0.01m UIC .op .probe .end

The above .tran command will cause PSpice to carry out circuit analysis from t=0 to 20 milliseconds, using the initial conditions (UIC) on inductors and capacitors which are given elsewhere. The first 20m is the print step, and the second 20m is the final time for simulation and 0.01m is the step ceiling, i.e. simulation time steps should not exceed 0.01milli seconds. The 0 means the no print time, i.e. PSpice ignores results from time 0 to no print time and in our example all results will be collected and nothing omitted since no print time is zero. L23 description has ic=0 which means that the initial condition which is the current in the inductor L23 is 0. C30 description line has ic=0 which means that the initial condition which is the voltage across the capacitor C30 is zero.

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

9/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

10/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

(ii) Maxima:
The following is a Maxima batch file that solves for the voltage across the capacitor vc(t). /* rlc_transient.mac */ restart; kill(all); globalsolve:true; Vs:10; R:1000; L:1; C:0.5e-6; de1: -Vs+R*C*diff(vc(t),t,1)+L*C*diff(vc(t),t,2)+vc(t)=0; /* 2nd order ODE */ atvalue(vc(t),t=0,0); /* first initial condition */ atvalue(diff(vc(t),t),t=0,0); /* second initial condition */ sol:desolve(de1,vc(t)); plot2d(rhs(sol),[t,0,20e-3]);

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

11/37

EE210/EE316
14

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

%e^-(500*t)*(-10*sin(500*sqrt(7)*t)/sqrt(7)-10*cos(500*sqrt(7)*t))+10

12

10

0 0 0.005 0.01 0.015 0.02

/* R:2000 */ Vs:10; R:2000; L:1; C:0.5e-6; de1: -Vs+R*C*diff(vc(t),t,1)+L*C*diff(vc(t),t,2)+vc(t)=0; atvalue(vc(t),t=0,0); atvalue(diff(vc(t),t),t=0,0); sol:desolve(de1,vc(t)); plot2d(rhs(sol),[t,0,20e-3]);
12 %e^-(1000*t)*(-10*sin(1000*t)-10*cos(1000*t))+10

10

0 0 0.005 0.01 0.015 0.02

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

12/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

/* R:4000 */ Vs:10; R:4000; L:1; C:0.5e-6; de1: -Vs+R*C*diff(vc(t),t,1)+L*C*diff(vc(t),t,2)+vc(t)=0; atvalue(vc(t),t=0,0); atvalue(diff(vc(t),t),t=0,0); sol:desolve(de1,vc(t)); plot2d(rhs(sol),[t,0,20e-3]);
10 9 8 7 6 5 4 3 2 1 0 0 0.005 0.01 0.015 0.02 %e^-(2000*t)*(-20*sinh(1000*sqrt(2)*t)/sqrt(2)-10*cosh(1000*sqrt(2)*t))+10

/* R:8000 */ Vs:10; R:8000; L:1; C:0.5e-6; de1: -Vs+R*C*diff(vc(t),t,1)+L*C*diff(vc(t),t,2)+vc(t)=0; atvalue(vc(t),t=0,0); atvalue(diff(vc(t),t),t=0,0); sol:desolve(de1,vc(t)); plot2d(rhs(sol),[t,0,20e-3]);
10 9 8 7 6 5 4 3 2 1 0 0 0.005 0.01 0.015 0.02 %e^-(4000*t)*(-40*sinh(1000*sqrt(14)*t)/sqrt(14)-10*cosh(1000*sqrt(14)*t))+10

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

13/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

The FOR statement available in Maxima for programming will repeat a compound statement as long as some logical condition is valid. Here we have for R in [1000,2000,4000,8000] do compound statement (simple statements are comma separated and all are enclosed in parenthesis): /* rlc_transient_for.mac */ restart; kill(all); globalsolve:true; for R in [1000,2000,4000,8000] do ( /* begin of a compound statement. Inside it, statements separated by commas */ Vs:10, L:1, C:0.5e-6, de1: -Vs+R*C*diff(vc(t),t,1)+L*C*diff(vc(t),t,2)+vc(t)=0, atvalue(vc(t),t=0,0), atvalue(diff(vc(t),t),t=0,0), sol:desolve(de1,vc(t)), /* solve for vc(t) */ plot2d(rhs(sol),[t,0,20e-3]) /* last simple statement in a compound statement NO Comma*/ ); /* end of compound statement */ the same program written using ode2 rather than desolve: /* rlc.ode2.transient_for.mac */ restart; kill(all); /* globalsolve:true; */ Vs:10; L:1; C:0.5e-6; for R in [1000,2000,4000,8000] do ( de1: -Vs+R*C*'diff(vc,t,1)+L*C*'diff(vc,t,2)+vc=0, sol:ode2(de1,vc,t), sol1:ic2(sol,t=0,vc=0,'diff(vc,t)=0), /* t=0, vc(0)=0, vc'(0)=0 */ sol2:ratsimp(sol1), plot2d(rhs(sol2),[t,0,20e-3]) ); /* compound statement */ desolve can be used to solve a system of first-order ordinary differential equations. Below is the solution of two first-order ODE using desolve which is a direct translation of the hand solution(natural way of writing the ODEs with little arrangements): /* rlc.2eqns.transient_for.mac */ kill(all); restart; Vs:10; L:1; C:0.5e-6; for R in [1000,2000,4000,8000] do ( de1: L*diff(i(t),t)=Vs-R*i(t)-vc(t), /* first ode via KVL */ de2: C*diff(vc(t),t)=i(t), /* second ode, capacitor current = i(t) */ atvalue(vc(t),t=0,0), atvalue(i(t),t=0,0), sol:desolve([de1,de2],[vc(t),i(t)]), plot2d(rhs(sol[1]),[t,0,20e-3]), /* sol[1] is vc(t) */ plot2d(rhs(sol[2]),[t,0,20e-3]) /* sol[2] is i(t) */ ); /* end of compound statement */

(iii) Matlab/Octave
We need to write the set of first-order differential equations that govern the functionality of the circuit. For the RLC circuit, we have two unknown quantities, namely, the voltage across the capacitor vc(t) and the current through the inductor i(t), call them x(1)=vc(t) and x(2)=i(t) with x is a 2 by 1 column vector. Define a new 2 by 1 column vector xprime with xprime(1)=dx(1)/dt and xprime(2)=dx(2)/dt.

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

14/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

Then we can write: xprimet(1)=dvc(t)/dt=i(t)/C=x(2)/C and xprime(2)=di(t)/dt=-vc(t)/L-R*i(t)/L+Vs/L=-x(1)/L-R*x(2)/L+Vs/L write the following matlab function, save it under the name odes4seriesrlc.m function xprime=odes4seriesrlc (t,x) Vs=10; R=1000; L=1; C=0.5e-6; xprime=zeros(2,1); xprime(1)=x(2)/C; % dvc(t)/dt=i/C xprime(2)=-x(1)/L-R*x(2)/L+Vs/L; % di(t)/dt=-vc(t)/L-(R/L)*i-Vs/L return and on the Matlab/Octave command line type [t,x]=ode23('odes4seriesrlc',[0,20e-3],[0,0]);% [t0=0, tf=20e-3], [vc(0)=0, i(0)=0] plot(t,x); xlabel('time t0=0, tf=20e-3'); ylabel('x(1)=vc(t) and x(2)=i(t) with initial conditions vc(0)=0, i(0)=0'); and the Octave output will be
x(1)=vc(t) and x(2)=i(t) with initial conditions vc(0)=0, i(0)=0 14 12 10 8 6 4 2 0 -2 0 0.005 0.01 time t0=0, tf=20e-3 0.015 0.02

line 1 line 2

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

15/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

(2-d) Frequency Response


Find the frequency response of the 4th order Butterworth filter shown below
1mH 2F + + Vs 4H 50F 1 Vout
Butterworth.4.m4

(i) PSPICE
The following is the .CIR file that computes the frequency response 4-th order Butterworth BPF Vs 1 0 ac 1 L12 1 2 100uH C23 2 3 2uF C30 3 0 50uF L30 3 0 4uH R30 3 0 1 .ac dec 200 6k 25k; dec=decades, 200 points pr decade, vary frequency 6K to 25K Hz .probe .end And the response is as shown below

(ii) Maxima Vout=Vs/(jwL1+1/(jwC1)+ZP)*ZP with ZP=L2||C2||R The Butterworth.mac file to simulate the filter is shown below: /* Butterworth.4.mac */ restart; /* define a function to compute Z or two impedances in parallel ZPZ=Z1||Z2 */ ZPZ(Z1,Z2):=Z1*Z2/(Z1+Z2); L1: 100e-6; C1: 2e-6; L2: 4e-6; C2: 50e-6; R: 1; 2006-11-26
J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

16/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

freq:[]; H:[]; for f:300 step 100 thru 30000 do ( w:2*%pi*f, Vs:1, /* phasor = 1 angle 0 */ Zp1:ZPZ(%i*w*L2,1/(%i*w*C2)), ZP:ZPZ(Zp1,R), Zall: %i*w*L1+1/(%i*w*C1)+ZP, Vout: Vs*ZP/Zall, freq:append(freq,[f]), H:append(H,[abs(Vout)]) )$ plot2d([discrete,float(freq),float(H)]);
1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 5000 10000

/* parallel L and C */ /* parallel R, L and C */ /* overall Z as seen by Vs */ /* voltage on parallel branch=Vout */ /* add f to list freq */ /* add magnitude of Vout to list H */ /* compound statement. $==> no echo */ /* plot list H versus list freq */
discrete1

15000

20000

25000

30000

(iii) Matlab/Octave Write a function ZPZ.m and the main file Butterworth.m % zed=Z1 parallel with Z2 function zed=ZPZ(Z1,Z2) zed=Z1*Z2/(Z1+Z2); return and type the following in a file called butterworth.m % 4rth order Butterworth.m Band Pass Filter (BPF) L1= 100e-6; C1= 2e-6; L2= 4e-6; C2= 50e-6; R= 1; freq=[]; H=[]; for f=300:100:30000 w=2*pi*f; Vs=1; % phasor = 1 angle 0 2006-11-26
J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

17/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

Zp1=ZPZ(j*w*L2,1/(j*w*C2)); ZP=ZPZ(Zp1,R); Zall= j*w*L1+1/(j*w*C1)+ZP; Vout= Vs*ZP/Zall; freq=[freq,f]; H=[H,abs(Vout)]; end %for statement plot(freq,H); xlabel('Frequency in Hz'); ylabel('Relative amplitude'); title('Frequency Response of Butterworth 4rth order BP filter'); and the output will be (from Matlab)
Frequency Response of Butterworth 4rth order BP filter

1 0.9 0.8 0.7 Relative amplitude 0.6 0.5 0.4 0.3 0.2 0.1 0 0

0.5

1.5 Frequency in Hz

2.5 x 10

3
4

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

18/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

4 Miscellaneous Examples
4.1 HKD6eCh5P60: Find Rin:
Is 1 12 2 4 4

6 Vs = 1 + Rin 12

3 6

3 18

hkd6ech5p60.m4

The solution as supplied by the author,

We begin by converting the -connected network consisting of the 4-, 6-, and 3- resistors to an equivalent Y-connected network:

RA

RB

RC

D = 6 + 4 + 3 = 13 R R 6 4 R1 = A B = = 1.846 D 13 R R 43 R2 = B C = = 923.1m D 13 R R 3 6 R3 = C A = = 1.385 D 13 Then network becomes:


1.846 0.9231

1.385

Then we may write

Rin = 12 [13.846 + (19.385 6.9231)] = 7.347

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

19/37

EE210/EE316
Matlab

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

Insert a 1 volt voltage source (Vs=1) at the input side between nodes 1 and 0, and write KVL by inspection,

% H K D 6e C h 5 P 6 0 . m %writin g the RI=V equations b y inspection Vs=1; V=[Vs; 0; 0; 0]; R=[12, -12, 0, 0; -12, (12+12+6+18), -6, -18; 0, -6, (6+4+3), -3; 0, -18, -3, (18+3+6)]; I=R\V; Rin=Vs/I(1) And the answer: Rin = 7.3469
Maxima

/* Find Rin problem 60 page 142 HKD6e. */ restart; globalsolve:true; Vs:1; kvl1: -Vs+12*(i1-i2)=0; kvl2: 12*(i2-i1)+12*i2+6*(i2-i3)+18*(i2-i4)=0; kvl3: 6*(i3-i2)+4*(i3)+3*(i3-i4)=0; kvl4: 18*(i4-i2)+3*(i4-i3)+6*(i4)=0; sol1:float(solve([kvl1,kvl2,kvl3,kvl4 ] , [ i 1 , i 2 , i 3 , i 4 ] ) ) ; / * i 1 = 0 . 1 3 6 1 , i2=0.05277, i3=0.0333, i4=0.03888 */ Rth: float(Vs/i1); /* answer 7.3469 */
PSpice
HKD6eCh5P60.cir * find Rin * insert Vs=1 volts at the input, find Is the source current, Rin=Vs/Is Vs 1 0 dc 1 r10 1 0 12 r12 1 2 12 r23 2 3 6 r30 3 0 18 r24 2 4 4 r43 4 3 3 r40 4 0 6 .tf I(Vs) Vs * I(Vs)/Vs = -1.361E-01 * INPUT RESISTANCE AT Vs = 7.347E+00 .op .end

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

20/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

4.2 Maximum Power Transfer: consider a one loop circuit having Vs, Rs, and Rl in series. We want to derive the condition on the value of Rl that absorbs maximum power from Rs. Write kvl: -Vs+i*Rs+i*Rl=0; i=Vs/(Rs+Rl); and the dissipated power in Rl= P=i^2*Rl; Differentiate P w.r.to Rl and equate the derivative to zero, we get Rl=Rs In Maxima, /* max_power_transfer.mac --- Vs, Rs, Rl circuit */ restart; kcl: -Vs+i*(Rs+Rl)=0; sol1:solve(kcl,i); /* answer i=Vs/(Rs+Rl) */ p:ev(i^2*Rl,i=rhs(sol1[1])); /* answer p=(Vs^2*Rl)/(Rs+Rl)^2 */ solr:solve([diff(p,Rl)=0],[Rl]);/* answer Rl=Rs */ Vs:1; Rs:1; plot2d(p,[Rl,0,5]);

Example: Consider the circuit below, find RL that dissipates maximum power. Definitely the solution is to find Thevenins equivalent circuit as seen by the load Rl, then set Rl to Thevenins resistance. Open circuit condition (Rl= open circuit=infinite resistor), Kcl at node 2: -(v2-20)/4-v2/6-10=0; and -5v2-60=0; and v2=-12 volts. Short circuit condition (Rl=short circuit=0), Kcl at node 2: -(v2-20)/4-v2/6-10-Isc=0, and v2=0 (due to the short circuit), hence Isc=-5A Rth=Voc/Isc=(-12)/(-5)=2.4 Ohms

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

21/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim


4

Dr. A. M. Jaradat

20V

10A

RL

max-power2.m4

Maxima
/* max_power2.mac */ restart; kcl2: -(v2-20)/4-v2/6-10-v2/R; sol1:solve(kcl2,v2); p:ev(v2^2/R,v2=rhs(sol1[1])); solr:solve([diff(p,R)=0],[R]); float(rhs(solr[1])); /* to plot p vs R */ plot2d(p,[R,0,10]); and the plot
16 14 12 10 8 6 4 2 0 0 2 4 6 8 10

/* /* /* /*

v2=-60R/(5R+12) */ p=(3600R)/(5R+12)^2; */ R=12/5 */ R=2.4 */

3600*R/(5*R+12)^2

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

22/37

EE210/EE316
PSPICE

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

The circuit file containing the commands to find (graphically) maximum power and the corresponding RL: Max_power2.cir v10 1 0 20 i20 2 0 10 r12 1 2 4 r20 2 0 6 ;vary RL load resistor 0.1 upto 100 RL 2 0 {R}; variable load resistor .param R=2.4 ;used by .op, ignored by .dc ;.dc param R list .1 .2 .4 .7 1 2 4 7 10 20 40 70 100 .dc param R 2 3 0.01 .op .print dc v(2) I(RL) .probe .end

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

23/37

EE210/EE316
Matlab

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

The m-file that does the plotting: %max_power2.m P=[]; R=[]; for r=0:0.01:5 p=3600*r/(5*r+12)^2; P=[P p]; R=[R r]; end plot(R,P); xlabel('Resistor'); ylabel('Power'); title('Max\_Power2.m');
15 Max_Power2.m

10

Power 5 0 0

0.5

1.5

2.5 Resistor

3.5

4.5

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

24/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

4.3 Diode: Half-Wave and Full-Wave Rectifier

rectifierhw.cir * Half-Wave rectifier without C v 1 0 sin(0 12 60) da 1 2 D1 r 2 0 1k *c 2 0 25uF .model d1 d .tran 0.1ms 33.33ms .probe .end

; 0 offset, 12V peak, freq=60Hz ; diode

If we insert a 25uF capacitor C between 2 and 0, then V(2) becomes

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

25/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

rectifierfw.cir * Full-Wave rectifier with C v1 1 0 sin(0 12 60) v2 0 3 sin(0 12 60) d1 1 2 da d2 3 2 da r 2 0 1k c 0 2 25uF .model da d .tran 0.1ms 25ms .probe .end

; offset voltage=0, amplitude=12V, freq=60Hz ; offset voltage=0, amplitude=12V, freq=60Hz ; diode

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

26/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

27/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

4.4 OPAMP Examples using PSPICE


Several examples are taken from [3]. Notes on OP-AMP analysis: Ideal case: ========== 1- Voltage across the input terminals of the op-amp is approximately zero. 2- Currents into the op-amp input terminals are approximately zero. Modelling Opamp needs four nodes: (v-), (v+), (vOut), (ground)

(a) OPAMP Inverting Amplifier


opamp10.1.cir: Inverting Amplifier-Rashid Example 10.1 *input voltage is 1.5 volts dc vin 1 0 dc 1.5v r1 2 3 10k r2 4 0 6.67k rf 3 5 20k *calling subcircuit OPAMP XA1 2 1 2 0 OPAMP XA2 3 4 5 0 OPAMP * subcircuit definition for OPAMP- DC model fig. 10-1(a) page 269 .subckt opamp 1 2 5 4 ri 1 2 2meg ro 3 5 75 *vcvs with gain 2e+5. ea 3 4 1 2 (-2e+5) .ends opamp ; end of subcircuit definition * transfer function analysis function calculates and prints the dc gain, input Res., output Res. .tf v(5) vin .end (b) - OPAMP Integrator: input square wave, output triangular wave opamp10.2.cir: An integrator circuit * input voltage square wave-piecewise linear waveform * input voltage have a finite slope vin 1 0 pwl(0 0 1ns -1v 1ms -1v 1.0001ms 1v + 2.0001ms -1v 3ms -1v 3.0001ms 1v 4ms 1v) r1 1 2 2.5k rf 2 4 1meg rx 3 0 2.5k rl 4 0 100k c1 2 4 0.1uf * calling subcircuit opamp xa1 2 3 4 0 opamp *subcircuit definition for opamp * AC linear model Rashid page 269: 1VCVS, 1VCCS. Model has a single break frequency .subckt opamp 1 2 7 4 ri 1 2 2e6 * vccs with gain of 0.1m gb 4 3 1 2 0.1m r1 2 3 10k c1 3 4 1.5619uf * vcvs with gain of 2e+5 ea 4 5 4 3 (-2e+5) ro 5 7 75 .ends ;end of subcircuit opamp *transient analysis 0 to 4 ms with 50 mu sec increment .tran 50us 4ms

2ms

1v

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

28/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

* plot the results of transient analysis .plot tran v(4) v(1) .plot ac vm(4) vp(4) .probe .end

Input square, output triangular (c) -OPAMP Differentiator Rashid Example 10-3 page 275 opamp10.3.cir: A practical differentiator circuit * input voltage triangular wave-piecewise linear waveform * maximum no of points is changed to 410 (default no=201) .options nopage noecho limpts=410 vin 1 0 pwl(0 0 1ms 1v 2ms 0v + 3ms 1v 4ms 0v) r1 1 2 100 rf 3 4 10k rx 5 0 10k rl 4 0 100k c1 2 3 0.4uf * calling subcircuit opamp xa1 3 5 4 0 opamp * subcircuit definition for opamp * AC linear model Rashid page 269: 1VCVS, 1VCCS. *Model has a single break frequency .subckt opamp 1 2 7 4 ri 1 2 2e6 * vccs with gain of 0.1m gb 4 3 1 2 0.1m r1 2 3 10k c1 3 4 1.5619uf * vcvs with gain of 2e+5 ea 4 5 4 3 (-2e+5) ro 5 7 75 .ends opamp ;end of subcircuit opamp *transient analysis 0 to 4 ms with 50 mu sec increment .tran 10us 4ms * plot the results of transient analysis .plot tran v(4) v(1) .probe .end

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

29/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

Input triangular, output square

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

30/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

(d)- Frequency response (Magnitude and Phase) of a filter opamp10.4.cir: Frequency response of a filter circuit. 10Hz < f< 100 MHz, step 1 decade and 10 points per decade. * input voltage sinusoidal vin 1 0 ac 1 r1 1 2 20k r2 2 4 20k r3 3 0 10k r4 1 5 10k r5 4 5 10k r6 6 7 100k *r7 6 0 100k rl 7 0 100k c1 2 4 0.01uf * calling subcircuit opamp xa1 2 3 4 0 opamp xa2 5 6 7 0 opamp * subcircuit definition for opamp * AC linear model Rashid page 269: 1VCVS, 1VCCS. Model has a single break frequency .subckt opamp 1 2 7 4 ri 1 2 2e6 * vccs with gain of 0.1m gb 4 3 1 2 0.1m r1 3 4 10k c1 3 4 1.5619uf * vcvs with gain of 2e+5 ea 4 5 4 3 (-2e+5) ro 5 7 75 .ends opamp ;end of subcircuit opamp *AC analysis for 10Hz to 100 MHz, decade increment, 10 pts/decade .ac dec 10 10Hz 100MegHz * plot the results of AC analysis .plot ac vm(7) vp(7) ;magnitude and phase .probe .end First magnitude of V(7)

Next Phase of V(7)

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

31/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

(e)- OPAMP-Active filter using UA741. Frequency response.


opamp10.5.cir: BP active-filter use UA741 from .lib vin 1 0 ac 1 r1 1 2 5k r2 3 4 1.5k r3 2 0 265k c1 2 4 0.01uf c2 2 3 0.01uf rl 4 0 15k vcc 6 0 dc 12v vee 0 7 dc 12v * subcircuit call for UA741 X1 0 3 6 7 4 UA741 * Vi+ ViVp+ VpVout *call library file eval.lib .lib c:\msimev_8\lib\eval.lib * AC analysis for 100Hz to 1MHz with a decade increment and 10 points per decade .ac dec 10 100Hz 1MegHz *plot the results of the ac analysis: magnitude of voltage at node 4 .plot ac vm(4) .probe .end

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

32/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

33/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

4.5 Transistors using PSPICE:


(a) opamp10.7.cir: Differential Amplifier using 5 transistors vcc 11 0 dc 12v vee 0 10 dc 12v vin 1 0 dc 0.25V rc1 11 3 10k rc2 11 5 10k re1 4 12 150 re2 7 12 150 rs1 1 2 1.5k rs2 6 0 1.5k rx 11 8 20k * model for NPN BJTs with model name QN .model QN NPN (BF=50 RB=70 RC=40) Q1 3 2 4 QN ;Collector Base Emitter Q2 5 6 7 QN Q3 12 8 9 QN Q4 9 9 10 QN Q5 8 9 10 QN * DC transfer function analysis .tf V(3,5) vin .end **** BJT MODEL PARAMETERS QN NPN IS 100.000000E-18 BF 50 NF 1 BR 1 NR 1 RB 70 RC 40 **** SMALL SIGNAL BIAS SOLUTION NODE VOLTAGE ( ( ( 1) .2500 NODE VOLTAGE ( ( 2) 6) .2190 -.0020

TEMPERATURE = 27.000 DEG C NODE VOLTAGE ( ( 3) 7) 1.6609 -.7057 NODE VOLTAGE ( ( 4) -.5575

5) 11.3460 9) -11.2220

8) -10.4430 -.7157

( 10) -12.0000

( 11) 12.0000

( 12)

VOLTAGE SOURCE CURRENTS NAME CURRENT vcc -2.221E-03 vee -2.243E-03 vin -2.068E-05 TOTAL POWER DISSIPATION 5.36E-02 WATTS **** SMALL-SIGNAL CHARACTERISTICS V(3,5)/vin = -2.534E+01 INPUT RESISTANCE AT vin = 3.947E+04 OUTPUT RESISTANCE AT V(3,5) = 2.000E+04 JOB CONCLUDED

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

34/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

4.6 Linearity and Superposition: Here we want to show by examples that any node voltage or branch current in any linear circuit can be represented as a linear combination of the independent sources in the circuit. (1) Verify superposition theorem for the following circuit:

Maxima: /* Superosition1.mac */ kill(all); restart; globalsolve:true; kvl1: -v1+R1*i1-v2+R3*(i1-i2)+R2*i1=0; kvl2: R3*(i2-i1)+v2+R4*i2=0; solve([kvl1,kvl2],[i1,i2]); /* i1=(v2 R4 + v1 R4 + v1 R3)/(R3 (R4 + R2 + R1) + R2 R4 + R1 R4) */ /* i2=(v1 R3 - v2 R2 - v2 R1)/(R3 (R4 + R2 + R1) + R2 R4 + R1 R4) */ expand(float(ev(i1,[R1=10, R2=5, R3=7, R4=8]))); /* i1=0.02846975088968 v2+0.053380782918149 v1*/ expand(float(ev(i2,[R1=10, R2=5, R3=7, R4=8]))); /* i2=0.02491103202847 v1-0.053380782918149 v2*/ (2) Verify superposition theorem for the following circuit: Superposition2: Lab manual example.

Maxima: /* Superosition1.mac */ kill(all); restart; globalsolve:true; kvl1: R3*i1+R2*(i1-i3)+R1*(i1-i2)=0; kvl2: -vb1+R1*(i2-i1)+Rl*(i2-i3)=0; kvl3: Rl*(i3-i2)+R2*(i3-i1)+R4*i3+vb2=0; solve([kvl1,kvl2,kvl3],[i1,i2,i3]); expand(float(ev(i1,[R1=3300,R2=270,R3=1000,R4=680,Rl=150]))); /* 7.739E-4vb1-3.008E-4 vb2 */ expand(float(ev(i2,[R1=3300, R2=270, R3=1000, R4=680, Rl=150]))); /* 0.001 vb1 - 3.324E-4 vb2 */ expand(float(ev(i3,[R1=3300, R2=270, R3=1000, R4=680, Rl=150]))); /* 3.324E-4 vb1 - 0.001 vb2 */

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

35/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

(3) Verify superposition theorem for the following circuit:

Maxima: kill(all); restart; globalsolve:true; kvl2: R1*(i2-i1)+R2*i2+3*ix+R3*(i2-i3)=0; eq1: i1=-I; eq2: i4-i3=2*vy; eq3: i4=-ix; eq4: vy=R1*(i1-i2); kvlsm: -v+R3*(i3-i2)-3*ix+R4*i4=0; sol:solve([eq1,kvl2,eq2,eq3,eq4,kvlsm],[i1,i2,i3,i4,ix,vy]); sol1:ev(sol,[R1=4,R2=5,R3=2,R4=8]); sol2:float(ev([sol1],[I=3,v=12])); the output in symbolic form interms of I and v: i1 = - I, i2 = (I(R1R3(2R4-1)+R1(-R4-3))+vR3+3v)/(R3(R4+R1(1-2R4)+R2)+R2(R4+3)+R1(R4+3)) i3=(I(R1R2(2R4+6)+R1R3(2R4-1))+vR3+vR2+7vR1)/(R3(R4+R1(1-2R4)+R2)+R2(R4+3)+R1(R4+3)) i4=(I(2R1R2+R1)R3+(2vR1-v)R3-vR2-vR1)/(R3(R4+R1(1-2R4)+R2)+R2(R4+3)+R1(R4+3)) ix=(I(2R1R2+R1)R3+(2vR1-v)R3-vR2-vR1)/(R3(R4+R1(1-2R4)+R2)+R2(R4+3)+R1(R4+3)) vy=(I(R3(R1R4+R1R2)+R1R2(R4+3))+vR1R3+3vR1)/(R3(R4+R1(1-2R4)+R2)+R2(R4+3)+R1(R4+3)) substitute for the resistors the values R1 = 4, R2 = 5, R3 = 2, R4 = 8 we get i1=-I, i2=(76I+5v)/5, i3=(560I+35v)/5, i4=-(88I+5v)/5, ix=(88I+5v)/5, vy=-(324I+20v)/5 substitute for I=3A, v=12 volts we get i1=- 3.0, i2=57.6, i3=420.0, i4=-64.8, ix=64.8, vy=-242.4 PSPICE solution: numerical values are presented here superposition3.cir I 1 0 dc 3 r12 1 2 4 v20 2 0 dc 12 r13 1 3 5 r24 2 4 2 h30 3 4 v0x 3 g04 0 4 1 2 2 r30 3 x 8 v0x 0 x dc 0 .op .end ****************************************************************************** NODE VOLTAGE NODE VOLTAGE NODE VOLTAGE ( 1) -230.4000 ( 2) 12.0000 ( 3) -518.4000 VOLTAGE SOURCE CURRENTS NAME CURRENT v20 -4.230E+02 v0x 6.480E+01

NODE VOLTAGE ( 4) -712.8000

NODE VOLTAGE ( x) 0.0000

Note that the current into v20 =-423A=i1-i3, and the current into v0x=64.8=-i4 which are the same values found by Maxima above. Other values can be checked. 2006-11-26
J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

36/37

EE210/EE316

C ma aa an nd dP PS Sp piic ce e Ciir rc cu uiitt A An na ally ys siis sw wiitth hO Oc ctta av ve e,, M Ma ax xiim

Dr. A. M. Jaradat

5 Conclusion
We analyzed four circuits; DC, AC, Transient, and Frequency Response. If you master the concepts in circuit analysis, then using the packages PSpice, Matlab/Octave, and Maxima will speed up your progress since the mechanical part will be almost totally removed. In fact, writing KVL or KCL, and the necessary conditions (initial or boundary), then using Maxima you only need to worry about the Maxima syntax. Using Matlab/Octave requires little re-arrangement of the equations in order to put them in a suitable form for the Matlab/Octave. The use of PSPICE in circuit analysis enables the student to analyze electric circuits and give him/her better understanding of the circuit behavior under different loading conditions. Making changes and re-simulating the circuit enables the student to study the effect of changing the components and/or modifying their values. Examples on the second-order system transient were made and changes of the resistor (1K, 2K, 4K, and 8K) R forced the circuit to change its response from underdamped to critically damped and to overdamped were easily verified. The intention behind distributing this note is to make you realize that once you master a simple thing like writing node equations you have indeed mastered circuit theory; rest is all mechanical and can be taken care of by programs like Matlab/Octave and Maxima.

References
[1] Hemanshu Roy Pota, Circuit Analysis with Matlab, Maple, and PSpice, 1998.
http://boronia.ee.adfa.edu.au/staff/hrp/teaching/docs/packagesIntro/ [2] Ney de Souza, P., Fateman, R., Moses, J. and Yapp, C., The maxima Book, 2003. http://www.math.psu.edu/glasner/Max_doc/maximabook-19-Sept-2004.pdf [3] Rashid, M. H., SPICE for Circuits and Electronics using PSPICE, Prentice-Hall, 1995. [4] Part-Enander, E., Sjoberg, A., Melin, B. and Isaksson, P., The MATLAB Handbook, Addison-Wesley, 1998.

2006-11-26

J J o r d a n U n v e r s t y o f S c e n c e a n d T e c h n o o g y Jo or rd da an nU Un niiiv ve er rs siiit ty yo of fS Sc ciiie en nc ce ea an nd dT Te ec ch hn no olllo og gy y

37/37

S-ar putea să vă placă și