Вы находитесь на странице: 1из 7

EYE on EDUCATION

A Linear Control System Simulation Toolbox Using Spreadsheets


By Ali El-Hajj, Karim Y. Kabalan, and Shahwan V. Khoury

S
ystem simulation serves as a tool for managing the parameters, and the Excel plotting facilities are used to dis-
complexity of the mathematical expressions used to play the simulation results.
represent systems and as a means of detailing their This article presents a new method for simulating linear
performance. Simulation tools are always measured by their control systems with spreadsheets. The interface makes
effectiveness, complexity, cost, and, most of all, their contri- use of a “linear control toolbox” toolbar whose aim is to
bution to the understanding of the problem. make simulation simple and user friendly. The basic blocks
Spreadsheets are basic software packages available in al- used are an adder, an integrator, and first- and second-order
most all institutions; they are easy to learn, allow step-by- step systems. The procedure for simulating the adder and inte-
study of the behavior of a system and the influence of changing grator is similar in concept to the ones used in [3] and [6].
one or more parameters related to this behavior, are equipped The first- and second-order system blocks are introduced in
this work to add more power and flexibility to the simula-
with graphical display tools, and, most important, do not re-
tion. Each of these basic blocks can be obtained by clicking a
quire much programming effort. Hence, spreadsheet pro-
corresponding button on the toolbar. Additional toolbar
grams have been used as a simulation tool in many
buttons are created for connecting these blocks in a manner
engineering problems. Lately, spreadsheets have been used to
specified by the user. Other buttons are added to initialize
simulate logic networks in [1]-[2] and control systems in
the system and to run it for a specified number of iterations.
[3]-[4]. These simulations allow the generation and intercon-
This package can be obtained, at no cost, from http://www.
nection of basic building blocks. The results have been very at-
aub.edu.lb/~elhajj.
tractive, simple, and useful for educational purposes.
To illustrate this method, in the next section we pres-
In the case of logic circuits, the basic blocks simulated
ent the block generation and connection tools. Then we
are logic gates, flip-flops [1], the clock, and some medium-
describe the simulation of the integrator and the first-or-
scale integration circuits [2]. This method can simulate
der block, followed by a description of the second-order
combinational, sequential, synchronous, and asynchron-
block. After providing some illustrative examples, we dis-
ous networks. In the case of a linear control system, the ba-
cuss the simulation method in detail, followed by con-
sic blocks simulated are an adder and an integrator. Any
cluding remarks.
transfer function can be simulated in the s domain by con-
necting several integrators and adders with appropriate Simulation Tools
scaling coefficients. An overall control system is conse- The spreadsheet tools used in the simulation are graphics,
quently simulated by connecting the constituent transfer formulas, macros, and toolbars. To simulate a basic block
functions. Nonlinear control systems are also simulated in [5], the drawing toolbar is used to represent this block us-
[4] using nonlinear elements as some of the basic blocks. ing, in some cases, its conventional drawing found in text-
Sampled data control systems can be simulated using the books. Formulas are then used to calculate the block output
delay z −1 as the basic block and where connecting several as a function of the inputs and other parameters. These two
z −1 blocks using appropriate scaling coefficients allows the steps are recorded in a macro whose code (in Visual Basic)
simulation of any transfer function in the z domain. Such is edited to ensure that all references are relative to the cur-
simulations allow calculation of the time response of a con- rent active worksheet cell, which is considered the first in-
trol system for any input signal. put cell. The macro is next attached to a toolbar button. By
In recent work [5], [6], improvements in the simulation clicking on this button, the macro will be executed, causing
method exploited the new advanced features of the Micro- the block to be generated at the location of the active cell.
soft Excel spreadsheet program. With these improvements, To create an adder, for example, the drawing toolbar is
simulation menus and toolbars were constructed, and a used to draw the adder with three inputs (C6, C7, and C8)
graphical interface was used to represent a block using Ex- and one output (E7) as shown in Fig. 1. The inputs are multi-
cel’s standard drawing tools. It is possible to generate a plied with scale factors stored at cells D6, D7, and D8 and ini-
block or to connect two blocks by selecting a corresponding tialized to one. These scaling factors can be directly
menu item or by clicking on the corresponding toolbar but- modified on the worksheet by the user. The formula
ton. Dialog sheets are used to input some of the simulation = C6*D6 + C7*D7 + C8*D8, which relates the output to the in-

El-Hajj (elhajj@aub.edu.lb), Kabalan, and Khoury are with the American University of Beirut, Faculty of Engineering and Architecture,
Electrical and Computer Engineering Department, P.O. Box 11-0236, Beirut, Lebanon.

0272-1708/00/$10.00©2000IEEE
8 IEEE Control Systems Magazine December 2000
put, is written at cell E7. This process of drawing and writing address of the destination cell, writes in this cell a formula
formulas is recorded in a macro called “Adder” and linked to equal to the source cell address, and draws a line that con-
a button called “Adder” that is included in a toolbar called nects the centers of the source and destination cells. The
“linear control toolbox.” This toolbar is constructed to Destination button will be active if clicked directly after the
graphically simulate any linear control system. As shown in Source button.
Fig. 1, to generate the second adder, cell H9 is made the ac- As an example, to connect the first adder output to the
tive cell and the Adder button is clicked. second adder input, as shown in Fig. 1, cell E7 is made the ac-
To manage the simulation process, a resetting and a tive cell, the Source button is clicked, then cell H9 is made
running mechanism is implemented. This is done using the active cell, and the Destination button is clicked.
some variables stored in the upper rows of the worksheet.
An initialization flag stored in cell B1 is set to zero when no Integrator and First-Order System Simulations
calculation is required and is set to one when a calcula- A first-order system is defined in the s domain by the trans-
tion is requested. Some blocks use this flag to reset their fer function
states to preset initial conditions. A counter is stored in
cell B2 to indicate the number of iterations (i.e., spread- Y ( s) 1
= .
sheet calculations) that are performed. This counter is in- X( s) s + a (1)
itialized to zero and incremented for each worksheet
calculation. This is done by writing at cell B2 the formula An integrator has the same transfer function as in (1) with
= IF ($B$1 = 0;0;B2 + 1). The integration step is stored in cell a =0. The output y(t ) is obtained as a function of the input
B3, and the time is calculated and stored in cell B4 using the x(t ) by solving
formula =$B$2 *$B$3. A spinner is used in cells F1-F2 to set
the number of worksheet calculations to be performed in a dy
= f ( x, y ) = −ay + x
single run. The resetting mechanism is created using the dt (2)
Reset button. The underlying macro resets the initializa-
tion flag and the counter to zero. Resetting is needed be- with y(0) = y0 = 0. Equation (2) can be written in discrete form
fore any new run, and the running mechanism is created using the integration step h as follows:
using the Run button. The underlying macro sets the initial-
ization flag to one and recalculates the worksheet the num- yi + 1 = yi + f ( xi , yi )h = yi + ( −ayi + xi )h.
ber of times indicated by the spinner. The “Run” macro can
be executed many consecutive times using different spin-
Many methods discussed in [7] can be used to calculate
ner values.
the output sequence yi given an input sequence xi . An ap-
The simulation requires connecting an output cell of
proach similar to the Heun method is used in this simula-
one block (source) to an input cell of another block (desti-
tion, but other methods can be used as well when more or
nation). This is done in two steps by drawing a line that
less accuracy is needed. In this method, the value of yi +1 is
connects the centers of the two cells and by writing in the
predicted using the predictor equation
destination cell a formula equal to the source cell address.
In the first step, the source cell is made active and the
Source button is clicked. The underlying macro calculates yi0+ 1 = yi + f ( xi , yi )h. (3)
and saves the address of the source cell. In the second
step, the destination cell is made active and the Destina- An improved value of yi +1 is next obtained using the
tion button is clicked. The underlying macro calculates the corrector equation

f ( xi , yi ) + f (xi + 1 , yi0+ 1 )
yi + 1 = yi + h.
2
(4)

In the case of the first-order system (1),


the predictor and corrector equations
become

Predictor: yi0+ 1 = yi + ( −ayi + xi )h,


Figure 1. Simulation tools. (5)

December 2000 IEEE Control Systems Magazine 9


Corrector: yi + 1 = yi +
(−ay + x − ay
i i
0
i +1 + xi + 1 )
h.
the case a =0 gave the same results as the integrator. This
simulation was also tested on more complicated examples
2 (6)
as discussed in the “Illustrative Examples” section.

In the case of an integrator, a =0 and the two previous equa- Second-Order System Simulation
tions are reduced to the trapezoidal rule [7] In this section, we define the simulation of the second-order
system. This system is defined in the s domain by the trans-
( xi + xi + 1 ) fer function
yi + 1 = yi + h.
2 (7)
Y ( s) as + b as −1 + bs −2
= 2 = −2 .
To simulate an integrator with input D6 and output F6, U ( s ) s + cs + d ds + cs −1 + 1 (8)
the drawing toolbar is used as shown in Fig. 2. For the cor-
rect operation of the integrator, xi and yi must be stored in A function X ( s ) is defined as
two cells used to calculate the output yi +1 and then updated
to new values used in the next iteration. Due to the row-wise Y ( s) U ( s)
calculation of the Excel worksheet, xi and yi are stored in X( s) = = .
as −1 + bs −2 ds −2 + cs −1 + 1
cells calculated after F6 (for example, cells D7 and E7). The
previous input value xi is stored in cell D7 by writing the for-
Defining the functions X1 = s −2 X and X2 = s −1 X , the follow-
mula = IF($B$1 = 0;0;D6) in this cell. The previous output
ing expressions are then obtained:
value yi is stored in cell E7 by writing = IF($B$1 = 0;0;F6) in
this cell . The output yi +1 is obtained at cell F6 by implement-
Y ( s ) = aX2 + bX1
ing (7) as follows:
U ( s ) = dX1 + cX2 + X . (9)
= IF($B$1 = 0;0;E7 + 0.5*$B$3*(D6 + D7)).
Using the definitions of X1 , X2 and (9), X1 , X2 , and U will then
As in the case of the adder, this process is automated us- satisfy the following equations:
ing the Integrator toolbar button that is attached to the “Inte-
grator” macro that draws and writes the integrator formulas sX1 = X2
using the active cell as the input cell of the integrator. sX2 = X = −dX1 − cX2 + U .
Consider the simulation of a first-order system with the
transfer function given in (1) using cell D6 as input and cell
F6 as output. The drawing toolbar is used to draw it as
shown in Fig. 3. The parameter a is stored in cell E5, initial-
ized to zero, and can be changed at any time by the user. As
in the case of the integrator, the previous input value xi is
stored in cell D7 by writing = IF($B$1 = 0;0;D6) in this cell.
The previous output value yi is stored in cell E7 by writing
the formula = IF($B$1 = 0;0;F6) in this cell. The predicted out-
put value yi0+1 of (5) is stored at cell E6 using
Figure 2. Integrator simulation.
= E7 + $B$3*( −E5*E7 + D7).

The corrected output yi +1 is obtained at cell F6 by imple-


menting (6) as follows:

= IF($B$1 = 0;0;E7 + 0.5*$B$3*( −E5*E7 + D7 − E5*E6 + D6)).

As in the case of the adder and the integrator, the


first-order system is customized using the First toolbar
button. To test this simulation, many runs were consid-
ered. Examples with known analytical solutions were tried,
and it was found that the simulation result matches the ex-
act solution. On the other hand, the first-order system with Figure 3. First-order system simulation.

10 IEEE Control Systems Magazine December 2000


Fig. 4 shows a second-order system block with transfer func-
tion given in (8) using cell D6 as input and cell G6 as output.
The drawing toolbar is used to draw it, and the parameters a,
b, c, and d are stored in cells E4, F4, E5, and F5, respectively.
All these parameters are initialized to zero, but their values
can be changed at any time by the user. In Fig. 4, the parame-
ter values are:a =1, b = 2, c = 6, andd =5. As in the case of the in-
tegrator, the previous input value ui is stored in cell D7 by
writing = IF($B$1 = 0;0;D6) in this cell. To implement (14)-(18),
Figure 4. Second-order system simulation. x10,i + 1 is stored in cell D5, x 20,i + 1 in cell G5, x1 ,i + 1 in cell E6, x 2 ,i + 1 in
cell F6, x1,i in cell E7, and x 2,i in cell F7. x10,i + 1 is calculated by im-
(10) plementing formula (14) in cell D5 as follows:
Assuming that x1 (0) = x 2 (0) = 0, (10) can be written in the time
domain as = E7 + $B$3*F7.

dx1 x 20,i + 1 is calculated by implementing formula (15) in cell G5 as


= f1 ( x1 ,x 2 ,u ) = x 2
dt (11) follows:

= F7 + $B$3*( −F5*E7 − E5*F7 + D7).


dx 2
= f2 ( x1 ,x 2 ,u ) = −dx1 − cx 2 + u.
dt (12)
x1 ,i + 1 is calculated by implementing formula (16) in cell E6 as
The output y(t ) is found to be follows:

y(t ) = ax 2 (t ) + bx1 (t ). (13) = E7 + 0.5*$B$3*(F7 + G5).

Equations (11)-(13) can be written in discrete form using x 2 ,i + 1 is calculated by implementing formula (17) in cell F6 as
the integration step h. The same method used in the case of follows:
the first-order system is used to solve (11) and (12). The
variables x1 and x 2 are predicted using an equation similar to = F7 + 0.5*$B$3*( −F5*E7 − E5*F7 + D7 − F5*D5 − E5*G5 + D6).
(3):
x1,i is calculated by implementing in cell E7
x10,i + 1 = x1 ,i + x 2 ,i h, (14)
= IF($B$1 = 0;0;E6).

x 20,i + 1 = x 2 ,i + ( −dx1 ,i − cx 2 ,i + ui )h. x 2,i is calculated by implementing in cell F7 the formula


(15)

The corrected values x1 ,i + 1 and x 2 ,i + 1 are obtained using equa- = IF($B$1 = 0;0;F6).
tions similar to (4):
The output yi +1 is finally obtained by implementing formula
x 2 ,i + x 20,i + 1 (18) in cell G6 as
x1 ,i + 1 = x1 ,i + h,
2 (16)
= E4*F6 + F4*E6.

x 2 ,i + 1 = x 2 ,i +
(
( −dx1 ,i − cx 2 ,i + ui ) + −dx10,i + 1 − cx 20,i + 1 + ui +1 ) h. As in the case of the previous blocks, the second-order sys-
tem is customized using the Second toolbar button and then
2
tested.
(17)
The output yi +1 with the initial condition y(0) = y0 = 0 is then Illustrative Examples
given by To illustrate the method, two examples are considered, and
the results are compared with the actual values. In the first
yi + 1 = ax 2 ,i + 1 + bx1 ,i + 1 . (18) example, a unity feedback linear control system, the plant

December 2000 IEEE Control Systems Magazine 11


transfer function is a sec-
ond-order system represented
by the following transfer func-
tion [8, Ex. 10-3]:

4500K
G( s ) = .
s( s + 361.2)

This system is controlled


by a proportional integral (PI)
controller with gain K=181.2.
The spreadsheet simulation of
this linear system is shown in
Fig. 5. In this simulation, the
controller is represented by an
integrator and an adder con-
nected in a parallel/cascaded
fashion. The parameters KI Figure 5. Spreadsheet simulation of example 1.
and KP are stored in cells I2
and I3, respectively, and referenced at the adder’s inputs us- values are stored in range [B14-B114] by multiplying the
ing formulas. A second-order block is used to simulate the counter values in range [A14-A114] by the step in cell B3.
plant transfer function with appropriate coefficients. The Successive outputs at cell M6 (named OUTPUT) are stored
output of the second-order block is used as input to the first in range [C14-C114] by writing in cell C14 the formula
adder for the next iteration. Since Excel calculates its cells
by rows from left to right, the ordering and placement of de- = IF($B$1 = 0;0;IF(A14 = $B$2;OUTPUT;C14)).
vices should be done carefully and the output formulas of
some adders should be edited. In this example, the formula This formula is copied to the range [C15-C114]. The Excel
at the second adder’s output is edited to refer to cell F6 in- chart toolbar is then used for plotting the system responses
stead of H7, since H7 represents the value of F6 at the previ- as shown in Fig 6. Good agreement with the results in [8] is
ous iteration at the time when J6 is calculated. For the same obtained.
reason, the input to the first adder at cell D7 is edited to refer As a second example, consider the compensated system
directly to the system output =M6. An alternative would be shown in Fig. 7. A spreadsheet simulation of this system is
to change the connection path (M6, M9, D9, D7) to another shown in Fig. 8. The simulation of the linear transfer function is
path such as (M6, M3, D4, D6). In this last path, the input D6 done in the same way as in the previous example. The re-
is used instead of D7, and due to the cal-
culation of the worksheet by rows, the
present value of D6 is equal to the value
of M6 at the previous worksheet calcu-
lation. In this case, it is not necessary to
edit the content of D6 to refer directly to
the content of M6.
The unit step response is calculated
by applying a unit step function at the
input of the system, as indicated in cell
D5. For comparison, the same values
considered in [8] are also considered in
this case; that is, KP = 0.08 and KI = 0.08,
0.8, and 1.6. The corresponding system
responses are arranged in adjacent col-
umns. To record the output values for
counter values 0,5,10..., the range
[A14-A114] is filled with multiples of five
from 0 to 500. The corresponding time Figure 6. Unit step response of the system shown in Fig. 5.

12 IEEE Control Systems Magazine December 2000


The size of the worksheet containing the code and the
K(s+2)
______ 1
___________ toolbar is on the order of 75 kb. Thus only limited computer
r(t ) c(t )
s+1 s2+2s+4 resources are needed to run the application. Furthermore,
this method is easy to use and simply requires learning the
function of each of the eight toolbar buttons. To analyze and
plot the results, the spreadsheet data processing facilities
can be used, which allows an iterative step-by-step or con-
Figure 7. Block diagram of example 2.
tinuous run of the simulated
system. This procedure shows
the values at the output of any
block in the worksheet. The
outputs with different parame-
ter value(s) can be simply ob-
tained and plotted using the
what-if feature of spread-
sheets.
This method is also suffi-
ciently accurate for a large
number of practical applica-
tions, since Excel stores num-
bers and performs calcul-
ations using 15 digits of preci-
sion. To increase the accuracy
Figure 8. Spreadsheet simulation of the system shown in Fig. 7.
of the results, the integration
sponse of the system is plotted in Fig. 9 by following an ap- step can be reduced or more sophisticated formulas can be
proach similar to that in the previous example. The results are used in simulating some blocks [7]. Reducing the integra-
in agreement with those obtained in [9] for the same example. tion step may lead to an increase in the number of iterations
(worksheet calculations), however, which makes this
Discussion method slow in simulating large control systems.
The method presented has its advantages and limitations In summary, this method is low in cost and suitable for
when compared with related simulation packages. As an ex- quick simulation when the user lacks the time or means to
ample, MATLAB-Simulink is an advanced software package write a sophisticated program or access a more sophisti-
widely used by engineers, students,
and instructors for simulating control
systems. Several undergraduate and
graduate students in our university
have copies of the package and had to
spend some time learning it.
The main advantage of the current
simulation method is its use of spread-
sheets that are widely available on
most computers (definitely more than
MATLAB) and are familiar to a large
class of users. Due to our familiarity
with spreadsheets, it was possible to
develop this application using macros
and formulas. This approach consider-
ably reduced the programming effort
that is usually required to develop sim-
ilar applications (see the “Simulation
Tools” section). The code obtained (in
Visual Basic) consists of a few pages
that can be directly accessed by users. Figure 9. Unit step response of the system shown in Fig. 7.

December 2000 IEEE Control Systems Magazine 13


cated package (i.e., MATLAB). It is useful in educational Ali El-Hajj was born in Aramta, Lebanon. He received the
settings where budgets and resources are sometimes lim- B.S. degree in physics from the Lebanese University, Leba-
ited, especially since a worksheet copy of this package can non, in 1979; the degree of “Ingenieur” from L’Ecole Super-
be obtained from the Web (http://www.aub.edu.lb/~elhajj) ieure d’Electricite, France, in 1981; and the “Docteur
at no cost. Ingenieur” degree from the University of Rennes I, France, in
1983. From 1983 to 1987, he was with the Electrical Engi-
Conclusion neering Department at the Lebanese University. In 1987, he
A new method has been presented for simulating linear con- joined the American University of Beirut where he is cur-
trol systems using modern spreadsheet programs. The rently Professor of Electrical and Computer Engineering. His
method is characterized by its flexibility, simplicity, and research interests are numerical solution of electromag-
availability. It has been verified for various cases, and exam- netic field problems and engineering education.
ples were given for illustration. It is particularly useful for
educational exercises that require calculations to be re- Karim Y. Kabalan was born in Jbeil, Lebanon. He received
peated with different parameters and values. the B.S. degree in physics from the Lebanese University in
1979 and the M.S. and Ph.D. degrees in electrical engineering
Acknowledgment from Syracuse University in 1983 and 1985, respectively. Dur-
This work is supported by the American University of Beirut ing the 1986 fall semester, he was a visiting Assistant Profes-
Research Board. sor of Electrical Engineering at Syracuse University.
Currently, he is a Professor of Electrical Engineering with the
References Electrical and Computer Engineering Department, Faculty of
[1] A. El-Hajj and K.Y. Kabalan, “A spreadsheet simulation of logic networks,” Engineering and Architecture, American University of Beirut.
IEEE Trans. Educ., vol. 34, pp. 43-46, 1991. His research interests are numerical solution of electromag-
[2] A. El-Hajj, K.Y. Kabalan, and M. Yehia, “Simulation of a class of integrated netic field problems and software development.
circuits using spreadsheets,” Proc. Inst. Elect. Eng., vol. 139, pt. G, no. 5, pp.
607-610, 1992.
Shahwan V. Khoury was born in Lebanon. He received his
[3] A. El-Hajj and K.Y. Kabalan, “Time domain analysis of linear control sys-
tems using spreadsheets,” IEEE Trans. Educ., vol. 38, no. 4, pp. 317-320, 1995. B.E. degree in electrical engineering from Youngstown State
[4] K.Y. Kabalan, A. El-Hajj, and W. Smari, “Nonlinear and sampled data con- University in 1960 and his M.S. and Ph.D. degrees from Car-
trol systems analysis using spreadsheets,” Proc. Inst. Elect. Eng., vol. 143, pt. A, negie Mellon University in 1961 and 1964, respectively. He
no. 1, pp. 52-56, 1996. was a member of the Technical Staff (AT&T), Technical Di-
[5] A. El-Hajj and M. Hazim, “On using spreadsheets for logic networks simula-
rector at Projects Studies and Implementation, San Fran-
tion,” IEEE Trans. Educ., vol. 41, no. 4, pp. 311-319, 1998.
[6] A. El-Hajj, “Functional simulation using spreadsheets,” Simulation, vol. 73, cisco; Manager of Electromechanical Contracts with
no. 2, pp. 80-90, Aug. 1999. Kettaneh, Lebanon; General Manager, Debbas Enterprise,
[7] S.C. Chapra and R.P. Canale, Numerical Methods for Engineers. New York: Lebanon; and Consultant, SDI, London. Currently, he is an
McGraw-Hill, 1990.
Associate Professor of Electrical and Computer Engineering
[8] B.C. Kuo, Automatic Control Systems, 7th ed. Englewood Cliffs, NJ: Prentice
Hall, 1995.
at the American University of Beirut. His research interests
[9] R.C. Dorf and R.H. Bishop, Modern Control Systems. Reading, MA: Addison are in numerical solution of electromagnetic field problems
Wesley, 1995. and software development.

14 IEEE Control Systems Magazine December 2000

Вам также может понравиться