Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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 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).
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).
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
4500K
G( s ) = .
s( s + 361.2)