Sie sind auf Seite 1von 37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

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 Circuit Conceptual Mechanical Start Analysis Step step fig1-OMP.m4
Wrong Way
Circuit
Conceptual
Mechanical
Start
Analysis
Step
step
fig1-OMP.m4

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

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

1/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

Dr. A. M. Jaradat

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

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

2/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

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.

1
1
2
2
R 1 3 + R 2 −
R 1
3
+
R 2

R

3

1A
1A

v in = 10V

example1.m4

R 4

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 ENTER

%Example1.m

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

3/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

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;

should be preceded by %. The second line above assigns numerical values to the resistors. The third line

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

defines ‘a’ as the required matrix. In Matlab,

in other words comments

tells you the entire story. Incidentally to learn more about any function ‘funname’ ' just say help

and Matlab

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

mode) you can store them in a file and get Matlab

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

from the same directory where you created the file and when Matlab

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

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.

session one by one (interactive

funname

will tell you what it’s all about. If you want to know if Matlab has a built-in function for

to execute it all in one step (batch mode). Use your

session

prompts you for a command, type

diary. Matlab keeps a command history of all

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

/*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 o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

4/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

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

follow the steps (from the menu Trace, Add, V(1)).

icon and again go to ‘open’ in the ‘file’ menu and open the file example1.dat and

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

is case insensitive, i.e.

have ‘v’ as the first letter, resistors have to have ‘R’ as the first letter etc. PSpice 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 o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

5/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

Dr. A. M. Jaradat

The command .DC v1

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

All PSpice

A .cir file is automatically created from .sch to be fed into PSpice.

0 20 0.2 tells PSpice to calculate various voltages and currents in the

to create a .dat file suitable to be read by Probe for plotting.

scripts must terminate with a .END line.

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

program, and on Probe Trace-

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

v in

r b r c c μ + + + − sin(2π1000t) c π v 1
r b
r c
c μ
+
+
+ − sin(2π1000t)
c π v 1
r π
g m v 1
r o
R l
v out
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

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

First rewrite the equations (3) and (4) in a matrix form and see that the following Matlab

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

6/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

Dr. A. M. Jaradat

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*cmu; 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 +

(ii) Maxima

0.12678i

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

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

7/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

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

Finally use Probe to see the frequency response. By default, Probe produces plots on a black

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 o r r d d a a
trace_1=black
trace_2=blue
trace_3=red
trace_4=green
2006-11-26
J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y
J o r d a n
U n i v e r s i t y
o o f f S S c c i i e e n n c c e e
o f
S c i e n c e
a a a n n n d d d
T T e e c c h h n n o o l l o o g g y y
T e c h n o l o g y
8/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

P

SSp

ppi iic cce ee

Dr. A. M. Jaradat

trace_5=brown

trace_6=magenta

trace_7=darkgray

and save the file.

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

+ −
+
 

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

0.5μ

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 o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

9/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

Dr. A. M. Jaradat

S S p P p p i i i c c c e e e Dr.

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

10/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

Dr. A. M. Jaradat

S S p P p p i i i c c c e e e Dr.

(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; /* 2 n d order ODE */

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]);

*/

/* first initial condition */ /* second initial condition */

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

11/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

Dr. A. M. Jaradat

14 %e^-(500*t)*(-10*sin(500*sqrt(7)*t)/sqrt(7)-10*cos(500*sqrt(7)*t))+10 12 10 8 6 4 2 0 0 0.005 0.01 0.015
14
%e^-(500*t)*(-10*sin(500*sqrt(7)*t)/sqrt(7)-10*cos(500*sqrt(7)*t))+10
12
10
8
6
4
2
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 8 6 4 2 0 0 0.005 0.01
plot2d(rhs(sol),[t,0,20e-3]);
12
%e^-(1000*t)*(-10*sin(1000*t)-10*cos(1000*t))+10
10
8
6
4
2
0
0
0.005
0.01
0.015
0.02
2006-11-26
J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y
J o r d a n
U n i v e r s i t y
o o f f S S c c i i e e n n c c e e
o f
S c i e n c e
a a a n n n d d d
T T e e c c h h n n o o l l o o g g y y
T e c h n o l o g y
12/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

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 %e^-(2000*t)*(-20*sinh(1000*sqrt(2)*t)/sqrt(2)-10*cosh(1000*sqrt(2)*t))+10 9 8 7 6
plot2d(rhs(sol),[t,0,20e-3]);
10
%e^-(2000*t)*(-20*sinh(1000*sqrt(2)*t)/sqrt(2)-10*cosh(1000*sqrt(2)*t))+10
9
8
7
6
5
4
3
2
1
0
0
0.005
0.01
0.015
0.02

/* 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 %e^-(4000*t)*(-40*sinh(1000*sqrt(14)*t)/sqrt(14)-10*cosh(1000*sqrt(14)*t))+10 9 8 7
plot2d(rhs(sol),[t,0,20e-3]);
10
%e^-(4000*t)*(-40*sinh(1000*sqrt(14)*t)/sqrt(14)-10*cosh(1000*sqrt(14)*t))+10
9
8
7
6
5
4
3
2
1
0
0
0.005
0.01
0.015
0.02
2006-11-26
J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y
J o r d a n
U n i v e r s i t y
o o f f S S c c i i e e n n c c e e
o f
S c i e n c e
a a a n n n d d d
T T e e c c h h n n o o l l o o g g y y
T e c h n o l o g y
13/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

Dr. A. M. Jaradat

The FOR

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

plot2d(rhs(sol),[t,0,20e-3])

); /* end of compound statement */

statement available in Maxima for programming will repeat a compound statement as

*/

/* solve for vc(t) */ /* last simple statement in a compound statement ‘NO Comma’*/

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)-v c(t), d e 2 : C*d iff (v c ( t), t) = 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]),

*/

/* first ode via KVL */

/*

s e cond ode, capacitor current = i(t) */

/* sol[1] is vc(t) */

plot2d(rhs(sol[2]),[t,0,20e-3])

/*

sol[2] is i(t) */

) ;

/*

e nd of

co mp o un d sta te me n t * /

(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

Define a new 2 by 1 column vector xprime with xprime(1)=dx(1)/dt and xprime(2)=dx(2)/dt.

is

a

2

by

1

column vector.

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

14/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

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

14 line 1 line 2 12 10 8 6 4 2 0 -2 0 0.005
14
line 1
line 2
12
10
8
6
4
2
0
-2
0
0.005
0.01
0.015
0.02
x(1)=vc(t) and x(2)=i(t) with initial conditions vc(0)=0, i(0)=0

time t0=0, tf=20e-3

2006-11-26

J J o o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

15/37

EE210/EE316

CC ii rr cc uu ii tt AA nn aa yy ss ii ss ww tt hh OOc cct tta aav vve ee, ,, MMa

C i r c u i t

ll

A n a l y s i s

ii

w i t h

O

M

aax

xxi iim mma aa aa nn dd PPS

a n d

SSp

P

ppi iic cce ee

Dr. A. M. Jaradat

(2-d) Frequency Response

Find the frequency response of the 4 th order Butterworth filter shown below

2μF 1mH + + V s 4μH 50μF 1Ω − V out − Butterworth.4.m4
2μF
1mH
+
+
V s
4μH
50μF
V out
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

Hz .probe .end And the response is as shown below (ii) Maxima Vout=Vs/(jwL1+1/(jwC1)+ZP) *ZP with

(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 o r r d d a a n n U U n n i i v v e e r r s s i i t t y y

J o r d a n

U n i v e r s i t y

o o f f S S c c i i e e n n c c e e

o f

S c i e n c e

a a a n n n d d d

T T e e c c h h n n o o l l o o g g y y

T e c h n o l o g y

16/37

EE210/EE316

CC i