circuit analysis using octave, maxima, and pspiceamjaradat/_ee210/_doc/circuit analysis...circuit...

37
EE210/EE316 C C C i i i r r r c c c u u u i i i t t t A A A n n n a a a l l l y y y s s s i i i s s s w w w i i i t t t h h h O O O c c c t t t a a a v v v e e e , , , M M M a a a x x x i i i m m m a a a a a a n n n d d d P P P S S S p p p i i i c c c e e e Dr. A. M. Jaradat 2006-11-26 J J J o o o r r r d d d a a a n n n U U U n n n i i i v v v e e e r r r s s s i i i t t t y y y o o o f f f S S S c c c i i i e e e n n n c c c e e e a a a n n n d d d T T T e e e c c c h h h n n n o o o l l l o o o g g g y y y 1/37 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. Start Circuit Analysis Conceptual Step Mechanical step Solution Wrong Way fig1-OMP.m4 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 ENTER 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 ENTER

Upload: doannhan

Post on 17-Mar-2018

244 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 1/37

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.

Start CircuitAnalysis

ConceptualStep

Mechanicalstep Solution

Wrong Way

fig1-OMP.m4

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

Page 2: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 2/37

c = 4 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 can’t 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

Page 3: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 3/37

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.

−+vin = 10V

R1

R2

R3

1A R4

example1.m4

31 2

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 (KCL@ node 1) (1) -(V2-V1)/R3-V2/R4+1=0 (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 Matlab(Octave)understands the language of matrices. Equations (1) and (2) have to be rewritten in a matrix form before we can use Matlab to solve them. A matrix equivalent of equations (1) and (2) is: A v = 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

Page 4: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 4/37

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 it’s 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 don’t 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 */

Page 5: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 5/37

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 PSpice 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 Probe 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, ‘.’.

Page 6: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 6/37

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 Probe for plot t ing. All PSpice 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 Trace-

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

−+vin sin(2π1000t)

rb

+v1

−rπ

gmv1 ro

rc

+vout

−Rl

fig3-OMP.m4

Figure 3: Circuit Example 2 - ( v 1 - v i n ) / r b - v 1 / r p i - j * w * c p i * v 1 - j * w * c p i * ( v 1 - v 2 ) = 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 Matlab 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); rpi=2600; cmu=1*10ˆ(-12);

Page 7: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 7/37

gm=40*10ˆ(-3); r0=100*10ˆ(3); rc=100; w=2*pi*1000; Rl=5000; vin=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 - 0.00064i -193.35709 + 0.12931i Vout = -189.56578 + 0.12678i

(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 and 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

Page 8: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 8/37

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 . E N D

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 2–0, controlled by the voltage across the nodes 1–0, 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

Page 9: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 9/37

trace_5=brown trace_6=magenta trace_7=darkgray and save the file. 2-c Transient Analysis: ( i ) P S P I C E C o n s i d e r a s e r i e s R L C c i r c u i t w i t h D C v o l t a g e o f 1 0 v o l t s a s d e s c r i b e d i n t h e f o l l o w i n g . C I R f i l e s

−+10V

1kΩ 1H

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. L 2 3 d e s c r i p t i o n h a s i c = 0 w h i c h me a n s t h a t t h e i n i t i a l co n d i t i o n w h i c h i s t h e c u r r en t i n t h e i n duc t o r L 2 3 i s 0 . C 3 0 d e s c r i p t i o n l i n e h a s i c = 0 w h i c h me a n s t h a t t h e i n i t i a l co n d i t i o n w h i c h i s t h e v o l t a g e a c r o s s t he c a p a c i t o r C 3 0 i s z e r o .

Page 10: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 10/37

Page 11: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 11/37

( i i ) Maxima: T h e f o l l o w i n g i s a M a x i m a b a t c h f i l e t h a t s o l v e s f o r t h e v o l t a g e a c r o s s t h e c a p a c i t o r v c ( t ) . / * r l c _ t r a n s i e n t . m a c * / r e s t a r t ; k i l l ( a l l ) ; g l o b a l s o l v e : t r u e ; V s : 1 0 ; R : 1 0 0 0 ; L : 1 ; C : 0 . 5 e - 6 ; d e 1 : - V s + R * C * d i f f ( v c ( t ) , t , 1 ) + L * C * d i f f ( v c ( t ) , t , 2 ) + v c ( t ) = 0 ; / * 2 n d o r d e r O D E * / a t v a l u e ( v c ( t ) , t = 0 , 0 ) ; / * f i r s t i n i t i a l c o n d i t i o n * / a t v a l u e ( d i f f ( v c ( t ) , t ) , t = 0 , 0 ) ; / * s e c o n d i n i t i a l c o n d i t i o n * / s o l : d e s o l v e ( d e 1 , v c ( t ) ) ; p l o t 2 d ( r h s ( s o l ) , [ t , 0 , 2 0 e - 3 ] ) ;

Page 12: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 12/37

0

2

4

6

8

10

12

14

0 0.005 0.01 0.015 0.02

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

/ * R : 2 0 0 0 * / V s : 1 0 ; R : 2 0 0 0 ; L : 1 ; C : 0 . 5 e - 6 ; d e 1 : - V s + R * C * d i f f ( v c ( t ) , t , 1 ) + L * C * d i f f ( v c ( t ) , t , 2 ) + v c ( t ) = 0 ; a t v a l u e ( v c ( t ) , t = 0 , 0 ) ; a t v a l u e ( d i f f ( v c ( t ) , t ) , t = 0 , 0 ) ; s o l : d e s o l v e ( d e 1 , v c ( t ) ) ; p l o t 2 d ( r h s ( s o l ) , [ t , 0 , 2 0 e - 3 ] ) ;

0

2

4

6

8

10

12

0 0.005 0.01 0.015 0.02

%e -̂(1000*t)*(-10*sin(1000*t)-10*cos(1000*t))+10

Page 13: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 13/37

/ * R : 4 0 0 0 * / V s : 1 0 ; R : 4 0 0 0 ; L : 1 ; C : 0 . 5 e - 6 ; d e 1 : - V s + R * C * d i f f ( v c ( t ) , t , 1 ) + L * C * d i f f ( v c ( t ) , t , 2 ) + v c ( t ) = 0 ; a t v a l u e ( v c ( t ) , t = 0 , 0 ) ; a t v a l u e ( d i f f ( v c ( t ) , t ) , t = 0 , 0 ) ; s o l : d e s o l v e ( d e 1 , v c ( t ) ) ; p l o t 2 d ( r h s ( s o l ) , [ t , 0 , 2 0 e - 3 ] ) ;

0

1

2

3

4

5

6

7

8

9

10

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 : 8 0 0 0 * / V s : 1 0 ; R : 8 0 0 0 ; L : 1 ; C : 0 . 5 e - 6 ; d e 1 : - V s + R * C * d i f f ( v c ( t ) , t , 1 ) + L * C * d i f f ( v c ( t ) , t , 2 ) + v c ( t ) = 0 ; a t v a l u e ( v c ( t ) , t = 0 , 0 ) ; a t v a l u e ( d i f f ( v c ( t ) , t ) , t = 0 , 0 ) ; s o l : d e s o l v e ( d e 1 , v c ( t ) ) ; p l o t 2 d ( r h s ( s o l ) , [ t , 0 , 2 0 e - 3 ] ) ;

0

1

2

3

4

5

6

7

8

9

10

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

Page 14: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 14/37

T h e F O R s t a t e m e n t a v a i l a b l e i n M a x i m a f o r p r o g r a m m i n g w i l l r e p e a t a c o m p o u n d s t a t e m e n t a s l o n g a s s o m e l o g i c a l c o n d i t i o n i s v a l i d . H e r e w e h a v e f o r R i n [ 1 0 0 0 , 2 0 0 0 , 4 0 0 0 , 8 0 0 0 ] d o c o m p o u n d s t a t e m e n t ( s i m p l e s t a t e m e n t s a r e c o m m a s e p a r a t e d a n d a l l a r e e n c l o s e d i n p a r e n t h e s i s ) : / * r l c _ t r a n s i e n t _ f o r . m a c * / r e s t a r t ; k i l l ( a l l ) ; g l o b a l s o l v e : t r u e ; f o r R i n [ 1 0 0 0 , 2 0 0 0 , 4 0 0 0 , 8 0 0 0 ] d o ( / * b e g i n o f a c o m p o u n d s t a t e m e n t . I n s i d e i t , s t a t e m e n t s s e p a r a t e d b y c o m m a s * / V s : 1 0 , L : 1 , C : 0 . 5 e - 6 , d e 1 : - V s + R * C * d i f f ( v c ( t ) , t , 1 ) + L * C * d i f f ( v c ( t ) , t , 2 ) + v c ( t ) = 0 , a t v a l u e ( v c ( t ) , t = 0 , 0 ) , a t v a l u e ( d i f f ( v c ( t ) , t ) , t = 0 , 0 ) , s o l : d e s o l v e ( d e 1 , v c ( t ) ) , / * s o l v e f o r v c ( t ) * / p l o t 2 d ( r h s ( s o l ) , [ t , 0 , 2 0 e - 3 ] ) / * l a s t s i m p l e s t a t e m e n t i n a c o m p o u n d s t a t e m e n t ‘ N O C o m m a ’ * / ) ; / * e n d o f c o m p o u n d s t a t e m e n t * / t h e s a m e p r o g r a m w r i t t e n u s i n g o d e 2 r a t h e r t h a n d e s o l v e : / * r l c . o d e 2 . t r a n s i e n t _ f o r . m a c * / r e s t a r t ; k i l l ( a l l ) ; / * g l o b a l s o l v e : t r u e ; * / V s : 1 0 ; L : 1 ; C : 0 . 5 e - 6 ; f o r R i n [ 1 0 0 0 , 2 0 0 0 , 4 0 0 0 , 8 0 0 0 ] d o ( d e 1 : - V s + R * C * ' d i f f ( v c , t , 1 ) + L * C * ' d i f f ( v c , t , 2 ) + v c = 0 , s o l : o d e 2 ( d e 1 , v c , t ) , s o l 1 : i c 2 ( s o l , t = 0 , v c = 0 , ' d i f f ( v c , t ) = 0 ) , / * t = 0 , v c ( 0 ) = 0 , v c ' ( 0 ) = 0 * / s o l 2 : r a t s i m p ( s o l 1 ) , p l o t 2 d ( r h s ( s o l 2 ) , [ t , 0 , 2 0 e - 3 ] ) ) ; / * c o m p o u n d s t a t e m e n t * / d e s o l v e c a n b e u s e d t o s o l v e a s y s t e m o f f i r s t - o r d e r o r d i n a r y d i f f e r e n t i a l e q u a t i o n s . B e l o w i s t h e s o l u t i o n o f t w o f i r s t - o r d e r O D E u s i n g d e s o l v e w h i c h i s a d i r e c t t r a n s l a t i o n o f t h e h a n d s o l u t i o n ( n a t u r a l w a y o f w r i t i n g t h e O D E s w i t h l i t t l e a r r a n g e m e n t s ) : / * r l c . 2 e q n s . t r a n s i e n t _ f o r . m a c * / k i l l ( a l l ) ; r e s t a r t ; V s : 1 0 ; L : 1 ; C : 0 . 5 e - 6 ; f o r R i n [ 1 0 0 0 , 2 0 0 0 , 4 0 0 0 , 8 0 0 0 ] d o ( d e 1 : L * d i f f ( i ( t ) , t ) = V s - R * i ( t ) - v c ( t ) , / * f i r s t o d e v i a K V L * / d e 2 : C * d i f f ( v c ( t ) , t ) = i ( t ) , / * s e c o n d o d e , c a p a c i t o r c u r r e n t = i ( t ) * / a t v a l u e ( v c ( t ) , t = 0 , 0 ) , a t v a l u e ( i ( t ) , t = 0 , 0 ) , s o l : d e s o l v e ( [ d e 1 , d e 2 ] , [ v c ( t ) , i ( t ) ] ) , p l o t 2 d ( r h s ( s o l [ 1 ] ) , [ t , 0 , 2 0 e - 3 ] ) , / * s o l [ 1 ] i s v c ( t ) * / p l o t 2 d ( r h s ( s o l [ 2 ] ) , [ t , 0 , 2 0 e - 3 ] ) / * s o l [ 2 ] i s i ( t ) * / ) ; / * e n d o f c o m p o u n d s t a t e m e n t * / ( i i i ) M at l a b / O c t a ve W e n e e d t o w r i t e t h e s e t o f f i r s t - o r d e r d i f f e r e n t i a l e q u a t i o n s t h a t g o v e r n t h e f u n c t i o n a l i t y o f t h e c i r c u i t . F o r t h e R L C c i r c u i t , w e h a v e t w o u n k n o w n q u a n t i t i e s , n a m e l y , t h e v o l t a g e a c r o s s t h e c a p a c i t o r v c ( t ) a n d t h e c u r r e n t t h r o u g h t h e i n d u c t o r i ( t ) , c a l l t h e m x ( 1 ) = v c ( t ) a n d x ( 2 ) = i ( t ) w i t h x i s a 2 b y 1 c o l u m n v e c t o r . D e f i n e a n e w 2 b y 1 c o l u m n v e c t o r x p r i m e w i t h x p r i m e ( 1 ) = d x ( 1 ) / d t a n d x p r i m e ( 2 ) = d x ( 2 ) / d t .

Page 15: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 15/37

T h e n w e c a n w r i t e : x p r i m e t ( 1 ) = d v c ( t ) / d t = i ( t ) / C = x ( 2 ) / C a n d x p r i m e ( 2 ) = d i ( t ) / d t = - v c ( t ) / L - R * i ( t ) / L + V s / L = - x ( 1 ) / L - R * x ( 2 ) / L + V s / L w r i t e t h e f o l l o w i n g m a t l a b f u n c t i o n , s a v e i t u n d e r t h e n a m e o d e s 4 s e r i e s r l c . m f u n c t i o n x p r i m e = o d e s 4 s e r i e s r l c ( t , x ) V s = 1 0 ; R = 1 0 0 0 ; L = 1 ; C = 0 . 5 e - 6 ; x p r i m e = z e r o s ( 2 , 1 ) ; x p r i m e ( 1 ) = x ( 2 ) / C ; % d v c ( t ) / d t = i / C x p r i m e ( 2 ) = - x ( 1 ) / L - R * x ( 2 ) / L + V s / L ; % d i ( t ) / d t = - v c ( t ) / L - ( R / L ) * i - V s / L r e t u r n a n d o n t h e M a t l a b / O c t a v e c o m m a n d l i n e t y p e [ t , x ] = o d e 2 3 ( ' o d e s 4 s e r i e s r l c ' , [ 0 , 2 0 e - 3 ] , [ 0 , 0 ] ) ; % [ t 0 = 0 , t f = 2 0 e - 3 ] , [ v c ( 0 ) = 0 , i ( 0 ) = 0 ] p l o t ( t , x ) ; x l a b e l ( ' t i m e t 0 = 0 , t f = 2 0 e - 3 ' ) ; y l a b e l ( ' x ( 1 ) = v c ( t ) a n d x ( 2 ) = i ( t ) w i t h i n i t i a l c o n d i t i o n s v c ( 0 ) = 0 , i ( 0 ) = 0 ' ) ; a n d t h e O c t a v e o u t p u t w i l l b e

-2

0

2

4

6

8

10

12

14

0 0.005 0.01 0.015 0.02

x(1)

=vc(

t) an

d x(

2)=i

(t) w

ith in

itial

con

ditio

ns v

c(0)

=0, i

(0)=

0

time t0=0, tf=20e-3

line 1line 2

Page 16: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 16/37

( 2 - d ) F r eq u e n c y R e s p o n s e F i n d t h e f r e q u e n c y r e s p o n s e o f t h e 4 t h o r d e r B u t t e r w o r t h f i l t e r s h o w n b e l o w

−+

V s

1mH2μF

4μH 50μF 1Ω

+

Vout

−Butterworth.4.m4

( i ) P S P I C E T h e f o l l o w i n g i s t h e . C I R f i l e t h a t c o m p u t e s t h e f r e q u e n c y r e s p o n s e 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 A n d t h e r e s p o n s e i s a s s h o w n b e l o w

(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;

Page 17: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 17/37

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)), /* parallel L and C */ ZP:ZPZ(Zp1,R), /* parallel R, L and C */ Zall: %i*w*L1+1/(%i*w*C1)+ZP, /* overall Z as seen by Vs */ Vout: Vs*ZP/Zall, /* voltage on parallel branch=Vout */ freq:append(freq,[f]), /* add f to list freq */ H:append(H,[abs(Vout)]) /* add magnitude of Vout to list H */ )$ /* compound statement. $==> no echo */ plot2d([discrete,float(freq),float(H)]); /* plot list H versus list freq */

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 5000 10000 15000 20000 25000 30000

discrete1

(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

Page 18: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 18/37

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)

0 0.5 1 1.5 2 2.5 3

x 104

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Frequency in Hz

Rel

ativ

e am

plitu

de

Frequency Response of Butterworth 4rth order BP filter

Page 19: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 19/37

4 Miscel laneous Examples 4 . 1 H K D 6 e C h 5 P 6 0 : F i n d R i n :

−+Vs = 1 Rin →

Is

12Ω

12Ω 4Ω

hkd6ech5p60.m4

6Ω 3Ω

18Ω

0

1 2

3

4

T h e s o l u t i o n a s s u p p l i e d b y t h e a u t h o r , We begin by converting the Δ-connected network consisting of the 4-, 6-, and 3-Ω resistors to an equivalent Y-connected network:

1

2

3

6 4 3 136 4 1.846134 3 923.1m13

3 6 1.38513

= + + = Ω×

= = = Ω

×= = = Ω

×= = = Ω

A B

B C

C A

DR RR

DR RR

DR RR

D

Then network becomes: Then we may write

12 [13.846 (19.385 6.9231)]7.347

= +

= ΩinR

RA RB

RC

1.846 Ω 0.9231 Ω

1.385 Ω

Page 20: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 20/37

M a t l a b I n s e r t a 1 v o l t v o l t a g e s o u r c e ( V s = 1 ) a t t h e i n p u t s i d e b e t w e e n n o d e s 1 a n d 0 , a n d w r i t e K V L b y i n s p e c t i o n , %HKD6eCh5P60.m %writ ing the RI=V equat ions by inspect ion 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 M a x i m a /* Find Rin problem 60 page 142 HKD6e. */ res tar t ; g lobalsolve: t rue; 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:f loat(solve([kvl1,kvl2,kvl3,kvl4] , [ i1 , i2 , i3 , i4])) ; /* i1=0.1361, i2=0.05277, i3=0.0333, i4=0.03888 */ Rth: f loat(Vs/ i1) ; /* answer 7.3469 */ P S p i c e 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

Page 21: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 21/37

4 . 2 M a x i m u m P o w e r T r a n s f e r : c o n s i d e r a o n e l o o p c i r c u i t h a v i n g V s , R s , a n d R l i n s e r i e s . W e w a n t t o d e r i v e t h e c o n d i t i o n o n t h e v a l u e o f R l t h a t a b s o r b s m a x i m u m p o w e r f r o m R s . W r i t e k v l : - V s + i * R s + i * R l = 0 ; i = V s / ( R s + R l ) ; a n d t h e d i s s i p a t e d p o w e r i n R l = P = i ^ 2 * R l ; D i f f e r e n t i a t e P w . r . t o R l a n d e q u a t e t h e d e r i v a t i v e t o z e r o , w e g e t R l = R s I n M a x i m a , /* 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]);

E x a m p l e : C o n s i d e r t h e c i r c u i t b e l o w , f i n d R L t h a t d i s s i p a t e s m a x i m u m p o w e r . D e f i n i t e l y t h e s o l u t i o n i s t o f i n d T h e v e n i n ’ s e q u i v a l e n t c i r c u i t a s s e e n b y t h e l o a d R l , t h e n s e t R l t o T h e v e n i n ’ s r e s i s t a n c e . O p e n c i r c u i t c o n d i t i o n ( R l = o p e n c i r c u i t = i n f i n i t e r e s i s t o r ) , K c l a t n o d e 2 : - ( v 2 - 2 0 ) / 4 - v 2 / 6 - 1 0 = 0 ; a n d - 5 v 2 - 6 0 = 0 ; a n d v 2 = - 1 2 v o l t s . S h o r t c i r c u i t c o n d i t i o n ( R l = s h o r t c i r c u i t = 0 ) , K c l a t n o d e 2 : - ( v 2 - 2 0 ) / 4 - v 2 / 6 - 1 0 - I s c = 0 , a n d v 2 = 0 ( d u e t o t h e s h o r t c i r c u i t ) , h e n c e I s c = - 5 A R t h = V o c / I s c = ( - 1 2 ) / ( - 5 ) = 2 . 4 O h m s

Page 22: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 22/37

−+20V

6Ω 10A RL

max-power2.m4 M a x i m a / * m a x _ p o w e r 2 . m a c * / r e s t a r t ; k c l 2 : - ( v 2 - 2 0 ) / 4 - v 2 / 6 - 1 0 - v 2 / R ; s o l 1 : s o l v e ( k c l 2 , v 2 ) ; / * v 2 = - 6 0 R / ( 5 R + 1 2 ) * / p : e v ( v 2 ^ 2 / R , v 2 = r h s ( s o l 1 [ 1 ] ) ) ; / * p = ( 3 6 0 0 R ) / ( 5 R + 1 2 ) ^ 2 ; * / s o l r : s o l v e ( [ d i f f ( p , R ) = 0 ] , [ R ] ) ; / * R = 1 2 / 5 * / f l o a t ( r h s ( s o l r [ 1 ] ) ) ; / * R = 2 . 4 * / / * t o p l o t p v s R * / p l o t 2 d ( p , [ R , 0 , 1 0 ] ) ; a n d t h e p l o t

0

2

4

6

8

10

12

14

16

0 2 4 6 8 10

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

Page 23: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 23/37

PSPICE 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

Page 24: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 24/37

M a t l a b T h e m - f i l e t h a t d o e s t h e p l o t t i n g : % m a x _ p o w e r 2 . m P = [ ] ; R = [ ] ; f o r r = 0 : 0 . 0 1 : 5 p = 3 6 0 0 * r / ( 5 * r + 1 2 ) ^ 2 ; P = [ P p ] ; R = [ R r ] ; e n d p l o t ( R , P ) ; x l a b e l ( ' R e s i s t o r ' ) ; y l a b e l ( ' P o w e r ' ) ; t i t l e ( ' M a x \ _ P o w e r 2 . m ' ) ;

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50

5

10

15

Resistor

Pow

er

Max_Power2.m

Page 25: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 25/37

4.3 Diode: Half-Wave and Full-Wave Rectifier

rectifierhw.cir * Half-Wave rectifier without C v 1 0 sin(0 12 60) ; 0 offset, 12V peak, freq=60Hz da 1 2 D1 ; diode r 2 0 1k *c 2 0 25uF .model d1 d .tran 0.1ms 33.33ms .probe .end

I f w e i n s e r t a 2 5 u F c a p a c i t o r C b e t w e e n 2 a n d 0 , t h e n V ( 2 ) b e c o m e s

Page 26: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 26/37

rectifierfw.cir * Full-Wave rectifier with C v1 1 0 sin(0 12 60) ; offset voltage=0, amplitude=12V, freq=60Hz v2 0 3 sin(0 12 60) ; offset voltage=0, amplitude=12V, freq=60Hz d1 1 2 da ; diode d2 3 2 da r 2 0 1k c 0 2 25uF .model da d .tran 0.1ms 25ms .probe .end

Page 27: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 27/37

Page 28: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 28/37

4.4 OPAMP Examples using PSPICE S e v e r a l e x a m p l e s a r e t a k e n f r o m [ 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 2ms 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

Page 29: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 29/37

* 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

Page 30: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 30/37

Input triangular, output square

Page 31: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 31/37

(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)

Page 32: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 32/37

(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+ Vi- Vp+ Vp- Vout *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

Page 33: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 33/37

Page 34: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 34/37

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 TEMPERATURE = 27.000 DEG C NODE VOLTAGE NODE VOLTAGE NODE VOLTAGE NODE VOLTAGE ( 1) .2500 ( 2) .2190 ( 3) 1.6609 ( 4) -.5575 ( 5) 11.3460 ( 6) -.0020 ( 7) -.7057 ( 8) -10.4430 ( 9) -11.2220 ( 10) -12.0000 ( 11) 12.0000 ( 12) -.7157 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

Page 35: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 35/37

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 */

Page 36: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 36/37

(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 NODE VOLTAGE NODE VOLTAGE ( 1) -230.4000 ( 2) 12.0000 ( 3) -518.4000 ( 4) -712.8000 ( x) 0.0000 VOLTAGE SOURCE CURRENTS NAME CURRENT v20 -4.230E+02 v0x 6.480E+01 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.

Page 37: Circuit Analysis using Octave, Maxima, and PSPICEamjaradat/_ee210/_DOC/Circuit Analysis...Circuit Analysis with Octave, Maxima and PSpice Adopted from the article [1] Introduction

EE210/EE316 CCC iii rrr ccc uuu iii ttt AAA nnn aaa lll yyy sss iii sss www iii ttt hhh OOOccctttaaavvveee ,,, MMMaaaxxxiiimmmaaa aaa nnn ddd PPPSSSpppiii ccceee Dr. A. M. Jaradat

2006-11-26 JJJ ooo rrr ddd aaa nnn UUU nnn iii vvv eee rrr sss iii ttt yyy ooo fff SSS ccc iii eee nnn ccc eee aaa nnn ddd TTT eee ccc hhh nnn ooo lll ooo ggg yyy 37/37

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.