Teaching AC Circuit Analysis with Matlab

John Okyere Attia
Department of Electrical Engineering
Prairie View A&MUniversity
P.O. Box 397, Prairie View, Texas 77446

Abstract:

MATLAB is a numeric computation software for engineering and scientific calculations. MATLAB is primarily a tool for matrix computations. MATLAB is being used to teach filter design, random processes, control systems and Communication Theory. The paper presents an approach to teaching circuit analysis topics using specially designed exercises that can be done using MATLAB running on personal computers or modern workstations.

The MATLAB exercises cover sinusoidal ac analysis, network characteristics and frequency response. Some MATLAB functions that are useful in teaching ac circuit analysis are introduced. The MATLAB programs for doing the exercises have been provided. In addition, SPICE circuit analysis software program is compared to MATLAB. The interactive programming and versatile graphics of MATLAB is especially effective in enhancing the teaching topics in electrical engineering.

1 Introduction

MATLAB is a numeric computation software for engineering and scientific calculations. MATLAB is primarily a tool for matrix computations. It was originally written to provide easy access to LINPACK and EISPACK software packages [1]. MATLAB is a high level language whose basic data type is a matrix that does not require dimensioning. There is no compilation and linking of programs as it is normally done in other high level languages, such as C or Fortran.

In MATLAB, all computations are done in complex valued double precision arithmetic to guarantee high accuracy. MATLAB has a rich set of plotting capabilities. The graphics are integrated into MATLAB. Since MATLAB is also a programming environment, a user can extend the functional capabilities of MATLAB by writing new modules.

MATLAB has a large collection of toolboxes for variety of applications. A toolbox consists of functions that can be used to perform some computations in the toolbox domain. Some examples of MATLAB toolboxes are: signal processing, image processing, neural network, control system, statistics, symbolic mathematics, optimization and system identification. At present, there is no MATLAB toolbox for circuit analysis and communication theory. MATLAB is being used to teach filter design [2], random processes [3], control systems [4] and Communication Theory [5,6].

This paper presents an approach to teaching ac circuit analysis topics using specially designed exercises that can be done using MATLAB running on personal computers or modern workstations. The interactive programming feature and versatile graphics of MATLAB is especially effective in demonstrating some of the principles of ac circuit analysis. The network theory exercises, discussed in this paper, are in the areas of (1) sinusoidal ac circuit analysis, (2) Network characteristics and (3) Frequency response. There are other topics in circuit analysis that can be taught using MATLAB; the three examples represent what can be done using MATLAB. The following three sections will describe the examples.

2 Sinusoidal Steady State Analysis

A time domain circuit can be transformed into the frequency domain using phasor transformation [7]. Nodal or loop analysis can then be used to get simultaneous equations, that can be solved using MATLAB. Given a circuit, nodal equations can be written and be expressed in matrix form as: where [Y] is the admittance matrix, [V] is a vector of the unknown nodal voltages and [I] is a current vector. The nodal voltage is given as: where [Y] is the inverse of the admittance matrix [Y]

In MATLAB, we can compute [V] by using the command In the case of loop analysis, if [I] is a vector of the unknown currents, and [Z] is the impedance matrix of the circuit, and [V] is the voltage vector, then the loop equations can be expressed in matrix form as: In MATLAB, we can solve for the loop currents by using the command:

As an example, suppose we want to use MATLAB to analyze the three-phase circuit shown in figure 1. It is assumed that R1 = R2 = R3 = 1 Ohm, R4 = 10 Ohms, R5 = 4 Ohms, R6 = 8 Ohms, C1 = 1000e-6 F and L1 = 0.01 H. Assuming a balanced positive phase sequence source voltage with frequency of 60 Hz and rms value of 120 V, the circuit is transformed into the frequency domain, and loop analysis was performed.

A MATLAB program that can be used to obtain the voltage across the resistor R4 is:


%
% Three phase circuit
z = [12 -1       -10;
   -1  6-2.65*j  -4+2.65*j;
   -10 -4+2.65*j   22+1.12*j];
v1 = 120; v2 = -60-103.92*j;
v3 = -60+103.92*j;
v =[v1-v2; v2-v3; 0];
% loop current vector is given as
i = inv(z)*v;
% Voltage across R4 is given as
vr4 = 10*(i(1) - i(3));
vr4mag = abs(vr4)
vr4ang = angle(vr4)*180/pi

One can analyze a circuit using SPICE [8] without understanding the principles of circuit analysis. However, one cannot blindly use MATLAB to solve problems. In the above example, MATLAB is being used to solve simultaneous equations. The student is forced to learn the principles and concepts needed to solve the problem.

3 Network Characteristics

The network function of a circuit can be written as

MATLAB functions that can be use to determine the characteristics of networks are roots, residue, and polyval. The MATLAB function roots can be used to determine the roots of a polynomial. The poles and zeros of a network function can be plotted using the MATLAB function zplane. The function polyval is used for polynomial evaluation and the function residue can be used to perform partial fraction expansion.

As an example, suppose that we have a circuit with a network function, H (s)

and we want to find the poles and zeros and evaluate the function at . A MATLAB program that can be used to find the zeros and poles and perform the polynomial evaluation is:


% poles and zeros of network function
% coefficients of rational function
num = [1 4 16 4];
den = [1 3 5 6 4];
% determination of zeros
disp('zeros are')
z = roots(num)
% determination of poles
p = roots(den)
% network function evaluation
s1 = -0.5-1*j
disp('value of function at
 s = -0.5 + j1 is')
value = polyval(num,s1)/polyval(den,s1)
        zplane(z,p)

Figure 2 shows the pole-zero plot.