You are on page 1of 17

S1

What is SIMULINK?

SIMULINK is a software package with a graphical user interface for modelling,


simulating and analysing dynamical systems. We can implement the block diagrams of
the models and the control systems we study in this book and see how see how they
perform. In this section we learn about the basic operation of SIMULINK.
Firstly, we study an example, which shows how SIMULINK uses icons to
represent common systems and signals in control engineering. The example below is a
model of the thermodynamic behaviour of a house whose interior temperature changes
due to heat supplied by the heating system. The house temperature is also affected by
external environmental changes, such as the change in daily temperature.

To
Ti

Parameters:
House Volume:
Specific heat:
Central Heating efficiency:
Variables
Central heating input:
Outdoor temperature:
Indoor temperature:

V
cp
Kch
Qi
To
Ti

When we enter a simulation model of a system, we must use some form of representation,
or model, for each of the systems or subsystems. These models may already have been
provided from previous analysis or information from other engineers. However, the
production of a model may require some preliminary analysis. For the house heating
system, we can form a representation using Laplace transforms.
Simple House Model
Equation for conservation of heat energy:
Rate of change of heat content = heat from central heating + heat loss to environment
dQ
dt = Kch Qi + Qe
We note that the heat content, Q, is given by:
Q = cp V Ti
and that the heat loss to the environment can be expressed as
Qe = Ke (To-Ti)

22

where Ke is the parameter which represents the energy loss per oC difference in outdoor
and indoor temperature. (This equation shows that if the outdoor temperature is greater
than the indoor temperature, then there is a net heat gain (Qe is positive). Similarly, if To
< Ti, there is a net heat loss , Qe <0. )
The conservation equation can now be written as
dTi
cpV dt = Kch Qi + Ke (To Ti)
Manipulating this equation gives:
cpV dTi Kch
= K Qi + (To Ti)
Ke dt
e
or
cpV dTi
Kch
+
T
i=
Ke dt
Ke Qi + To
This is a first order differential equation and can be written in Laplace transforms as:
(s + 1)Ti(s) = KQi(s) + To(s)
or
Ti(s) =

K
1
Q (s) +
T (s)
(s + 1) i
(s + 1) o

The equation shows how the outdoor temperature is affected by both the heat input due to
the central heating system and the outdoor temperature. This can be shown as a block
diagram:
outdoor
temperature, To

indoor
temperature, Ti

House Model
Heat input, Qi

23

Simulink model of house heating control system


The house model and the control for the heating system can be modelled in Simulink as
follows:
DISTURBANCE

Outdoor Temp

DISPLAY OUTPUT
Set Point

Outdoor Temp

20
Mux
THERMOSTAT

HOUSE
MODEL

Relay (On/Off)
Heating Control

Indoor Temp

Mux

Scope

Indoor Temp

This Simulink model of the thermodynamic behaviour of a house can be divided into four
subsystems:
A.

B.
C.
D.

The House Model which contains


(i)
the effect of the central heating system on the indoor temperature
(ii)
the effect of the outdoor temperature on the indoor temperature
The Disturbance which models the variation of the outdoor temperature
The Thermostat which provides the control for the central heating system
based on the reading of the indoor temperature
The Display output which produces a graph against time of the indoor
and outdoor temperatures.

A. The House Model


(i) The Effect of a Heat Source on Indoor Temperature
The house is heated by a central heating system or a heater whose output energy is
represented by Qi. As we have seen from our simple house model analysis, we can model
the effect of the heat source on the indoor temperature of the house as a first order system
with system gain of K and a time constant of minutes.
Heat energy,
Qi

K
s + 1

Indoor
temperature, Ti

24

(ii) The Effect of the Outdoor Temperature on the Indoor Temperature


We model the indoor temperature of the house as the summation of the outdoor effect
(outdoor temperature) and the heat supplied by the heat source. From the house model
analysis, the effect of the outdoor temperature on energy supplied to the building has first
order dynamics, unity system gain and a time constant of minutes.
Outdoor
temperature, To
1
s + 1
Indoor temperature change due
to outdoor environment

Total Change in Indoor temperature


We can now connect this block to the indoor temperature block and create a new icon to
represent the combined house model.

Outdoor
temperature, To
1
s + 1

becomes

Heat input, Qi,


due to heating
system

K
s + 1

+
Indoor
Temperature Ti

25

HOUSE
MODEL

B. The Outdoor Temperature


We assume the outdoor temperature has an average value, which is subject to some
variations.
Disturbance model

Average
Outdoor
Temperature

Outdoor
temperature, To

+
+
Outdoor
Temperature
Variation

A representation of this model in SIMULINK is:


Disturbance
10
Avg OutdoorTemp

Outdoor Temp

Outdoor Temp
Daily TempVariation

SIMULINK has the capability to group the sub-blocks of this model into a new block for
better visualisation of the overall structure of the complicated models.

C. The Thermostat
The control of the heating system is performed by a thermostat which produces an on/
off signal depending on the size of the incoming signal. This is represented by a relay.

Set Point
Measured

Qi, Heat output

20

Relay (On/Off)
Heating Control
Thermostat
Indoor temperature transducer
(Gain =1)
Measured
Indoor Temp

Indoor Temp

We usually set a desired temperature (the reference temperature) on the thermostat . This
value is compared with the measured level of indoor temperature. If the indoor
temperature is too low, the error is positive and the thermostat switches on the heater.
When the error reduces below a certain threshold, the thermostat switches off the heater.

26

Note that most thermostats have a sensor to measure the temperature and a knob or dial to
set the reference. For simplicity, we have assumed that the sensor has unity gain and the
reference is as shown in the block diagram.

The Overall Model


The overall model brings together the above component models (A,B and C) and has the
following structure:
Outdoor
Temperature, To

Average Outdoor
Temperature (10 0C)
Outdoor
Temperature
Variation

+
1
s + 1

Set point
+
Thermostat

Relay

Heat
Input
(Qi)

K
s + 1

+
+

Indoor
Temperature Ti

These three subsystems (A, B and C) provide the model for the simulation. However we
add the fourth sub system (display output) in order that we can monitor the change in
indoor and outdoor temperatures visually on a plot.
D. Display output
When running a simulation, we usually monitor several variables, such as the indoor and
outdoor temperatures so that we can determine if the simulation model is working. To do
this we use a 'multiplexing' unit which, in this example, receives two signals and
produces a single vector, containing these signals, as the output. This output vector is
used as the input to a scope which can show graphs against time of the input signals.

27

The resulting Simulink diagram looks like:


Disturbance
Outdoor Temp

Outdoor Temp

Set Point
20
Mux

Terr

House

Relay1

Mux

Scope

Indoor Temp

We will return to this model at the end of this study and examine it in more detail.

S2Building a Simple SIMULINK Model


We use the example in this section to build a model using many of the model building
commands available in SIMULINK.
The block diagram of the model is shown below. This is the model of a first order system
with a proportional controller of gain Kp.

Setpoint
R(s)

Controller Process
error
U(s)
Kp
K
s+1

28

Y(s)

SIMULINK libraries
To construct a SIMULINK simulation for the closed loop system, we use the following
steps.
1. Type SIMULINK in the Matlab command window to display the SIMULINK library
browser. The SIMULINK library browser window looks like this:

2. Double click on SIMULINK and a number of SIMULINK Libraries appear which


can be used to build a model.

3. Double click on Continuous and a number of specific SIMULINK blocks will appear.

29

4. To open a modelling window (called untitled), click on

4. Click on Transfer Fcn, hold the mouse and drag the block onto the modelling window
and release the mouse. The transfer function block will appear on the window.

Example
Each signal and block of the control system can be represented by one of the SIMULINK
blocks. There are many SIMULINK blocks that we can use, but for this example we need
only the blocks shown in the following figure. The libraries where the blocks can be
found have also been shown in the figure.

Gain block
in Math

Sum Block
in Math

Process

Controller
Setpoint, r(t)

Transfer function
block in Continuous

Output, y(t)

error

K
G( s ) =
s + 1

Kp

Constant
Block in
Sources

The Scope
block in Sinks

The blocks needed are summarised here.


1.
2.
3.
4.
5.

Constant Block in Sources Library


Sum Block in Math Library
Gain block in Math Library
Transfer function block in Continuous Library
The Scope block in Sinks Library

We need to copy all these blocks into the untitled window. Follow these steps to copy the
blocks.

30

1. Open the Sources library to access the Constant block. To open a block library,
double-click on the library menu. SIMULINK displays a list that contains all the
blocks in the library.
2. To copy the Constant block, click over the Constant block, then press and hold down
the mouse button.
3. Now, drag the block into the model window.
4. When the pointer is where you want the block to be in the model window, release the
mouse button. A copy of the Constant block is now in the model window. Close the
Sources Window.
5. In the same way copy the rest of the blocks in the model window. The model window
should contain these components:
1
Constant

1
Sum

s+1
Transfer Fcn

Gain

Scope

Note that a block can be moved from one place in the model window to another using the
same technique that was used to copy the block.
The addition or subtraction operations for the Sum symbol can be changed by double
clicking on the icon. The default values are given as '| + +' which can be changed to '| + -'
to provide the comparator needed in the example for negative feedback. The string
provides the number and entry positions (anticlockwise) for the incoming signals on the
summation icon, with the '|' symbol indicating no entry point. For example, entering the
string '+ | - +' produces the following icon:

Sum
The summation symbol can also be changed to a rectangular shape by choosing the
appropriate option after double clicking on the summation icon.
If we examine the block icons, we can see an angle bracket on the right of the Gain block
or two on the left of the Sum block. The > symbol pointing to a block is an input port; if
the symbol points out of a block, it is an output port. A signal travels out from an output
port and to the input port of another block through a connecting line.
When the blocks are connected, the port symbol disappears.

Connecting the Blocks


To connect the Constant block to the top input port of the Sum block, we use the
following steps:

31

= Position the pointer over the output port on the right side of the Constant block. Note
that the cursor shape changes to cross hairs.
= Hold down the mouse button and move the cursor to the input port of the Sum block.
= Release the mouse button. The blocks are connected

Now connect the other blocks as follows:


1. Output port of the Sum block to the input port of the Gain block.
2. Output port of the Gain block to the input port of the Transfer function block.
3. Output port of the Transfer function block to the input port of the Scope block.
4. To connect the feedback path, follow these steps:
= Position the pointer on the line between the Transfer function block and the Scope
block.
= Press and hold down the Ctrl key while pressing the left hand mouse button (or,
alternatively, do not use the Ctrl key but hold down the right hand mouse button)
= Drag the pointer down for about 2 cm.
= Release the mouse button, and the line No 1 appears.

Constant

s+1
Sum

Gain

Transfer Fcn

Scope

4
1
3
2
= Starting from the end of line No 1, draw line No 2. Use the same technique.
= Draw line No.3.
= Draw line No.4. The feedback loop is now connected.

Model Data
The block diagram of the simulation model is now complete. Before running the model,
we need to enter the model parameters for all blocks. Follow these steps:
= Double-click on the Constant block: change 1 to 10. Close the window.
= Double-click on the Sum block, change |++ to |+- . Note is for the negative
feedback.
= Double-click on the Gain block: change 1 to 2. Close the window.

32

= Double-click on the Transfer function, change the numerator polynomial to [0.5].


This is the gain K. Change the denominator to [10 1]. This is for s+1. Close the
window.
= Double-click on the Scope block. Change Ymax to 10 and Ymin to 0. Close window.

Simulation
From Simulation menu choose Parameters. Change Stop time to 10. Close the window.
To run the simulation, choose Start from the Simulation menu and run the simulation.
When the simulation is completed, click on the scope. We can now examine how the
system output, y(t), tracks the set point, r(t), in the Scope block.

S3Exercises
Using the block diagram that we have just entered, we will change the controller gains
and notice the effect on the output response.
1. For the controller gains given in the table, measure the time constant and the steady
state error of the closed-loop system.
Controller gain
10
9
7
5
3
1
Time Constant
SS Error

2. Discuss the effect of changing the controller gain on the system output response.

33

3. A pacemaker to regulate the speed of a human heart has a block diagram as shown
below.
Pacemaker
R(s)
Desired heart rate +

(i)
(ii)

Heart
1
s

K
0.05s + 1

Y(s)
Actual heart
rate

Implement the model in SIMULINK.


Use transfer function analysis to determine the value of K to give a closed loop
response with a damping factor of 0.35.

34

(iii)

The overshoot of a second order system is related to the damping by the following
equation

% overshoot = exp

2
1
By changing the value of K in the SIMULINK model, find a value for which the
closed-loop response has a damping factor of 0.35.

S4

Working with the House Model


Build the house model in SIMULINK. Let = 1 and K = 0.5.
Temperature Set point and control
The demo models the thermodynamics of a house using a simple model. We need to be
able to change the temperature reference of the system.
Set Point
20 0C

To change the set point follow these steps:


(i)
Double-click on the set point box and the following window appears:

(ii)
(iii)
(iv)
(v)
(vi)

Move the pointer to the white box and click the left mouse button.
Use backspace to clear 20.
Type in the new set point, say 18.
Close the window.
Run the simulation.

35

The thermostat block represents the controller used to control the indoor temperature. To
see how the controller is implemented, double-click on the thermostat block. The heating
control is a relay. The input signal to the relay is the deviation, or error, from the
tempeature setpoint and the output signal is the output energy from the heating system
which works on an on/off switch. Hence the thermostat switches on and off the heating
system dependent on the input and the relay parameters.
Exercise: Temperature set point and control
a. Run the simulation again and explain the behaviour of the room temperature in terms
of the varying outdoor temperature signal.

b. Double-click on the Relay block and change the limits to 5. Run the simulation and
comment on the difference with the previous response.

Disturbance (Outdoor Temperature)


The temperature of the house is affected by the outside temperature, which varies by
applying a sine wave with amplitude of 8 0C to a base temperature of 15 C. This
simulates daily temperature fluctuations. To see how this is implemented, follow these
steps:
1. Double-click on the Disturbance block.
Disturbance

Outdoor Temp

The following window will open.

36

15
Avg OutdoorTemp

1
Outdoor Temp

Daily TempVariation

2. Double-click on the Daily Temp Variation to see how the sine wave is generated.
3. Change the value of the frequency of the sine wave by a factor of two. Close the
window.
4. Run the simulation to see the effect of the changes made. Comment.

Exercise: Modelling diagrams


a. Draw the block diagram of the house model section of the simulation model.

37

b. Identify the controller, the actuator, and the process. Is there a temperature transducer
in the diagram? If there is, what does it measure? Note that the thermostat effectively
contains a temperature transducer and an on-off controller.

On finishing running the simulation, we close all the models by choosing Close from the
file menu. We can also save the model by choosing Save from the file menu.

38