You are on page 1of 10

Tutorial 5 Week 5

Introduction to Simulink Aim To get started with Simulink and dynamic simulation Create simple Simulink models

Introduction Block diagram: Simulink software has been designed based on the technical term block diagram. Therefore, a Simulink model consists of blocks and lines that connect blocks together. A dynamic system with input/s (u) and output/s (y) is represented with a functional block (rectangle) as shown in the following figure. Input (u) Output (y)

System (F)

Figure 1 A block with input, output and functional function The relationship between the output and input is as follows: y = Fu where F is a mathematical function (namely, transfer function) in the block. A block diagram is a combination of blocks and lines connected between blocks. The following figure illustrates a closed-loop (feedback) control system (we will deal with the block diagram in Module 8).

R(s) +_

E(s)

G(s)

Y(s)

B(s) H(s) Figure 2 A block diagram of a feedback control system Simulink library browser: In Simulink, data/information from various blocks is sent to another block by lines connecting the relevant blocks. Signals can be generated and fed into blocks (dynamic / static). Data can be fed into functions. Data can then be dumped into sinks, which could be scopes, displays or could be saved to a file. Data can be connected from one block to another, can be branched, multiplexed etc. In simulation, data is processed and transferred only at 1

Discrete times, since all computers are discrete systems. Thus, a SIMULATION time step (otherwise called an INTEGRATION time step) is essential, and the selection of that step is determined by the fastest dynamics in the simulated system. Figure 3 shows the overview of the Simulink libraries available.

Figure 3 Simulink library browser (MATLAB 7.0)

Connecting Blocks: To connect blocks, left-click and drag the mouse from the output of one block to the input of another block. Figure 4 shows the steps involved. Tips for branches and quick connections are provided at the end of this document.

Figure 4 Connecting blocks Sources and Sinks: The sources library contains the sources of data/signals that one would use in a dynamic system simulation. One may want to use a constant input, a sinusoidal wave, a step, a repeating sequence such as a pulse train, a ramp etc. One may want to test disturbance effects, and can use the random signal generator to simulate noise. The clock may be used to create a time index for plotting purposes. The ground could be used to connect to any unused port, to avoid warning messages indicating unconnected ports. The sinks are blocks where signals are terminated or ultimately used. In most cases, we would want to store the resulting data in a file, or a matrix of variables. The data could be displayed or even stored to a file. The STOP block could be used to stop the simulation if the input to that block (the signal being sunk) is non-zero. Figures 5 and 6 shows the available blocks in the sources and sinks libraries. Unused signals must be terminated, to prevent warnings about unconnected signals.

Figure 5 Sources in Simulink library

Figure 6 Sinks in Simulink library

Structure of a Simulink model: A Simulink model consists of at least a Sources block, a Math Operation block (for system dynamics) and a Sinks block. The Sources block generates a signal as an input. The Math Operation block (or a subsystem) is an algorithm for modelling the dynamic performance of a system under investigation and the Sinks block displays simulated results. Figure 7 illustrates a Simulink model. Input (u) Output (y) Sinks block

Sources block

Math Operation block

Simulation of input signal/s

Simulation of dynamic system

Simulation of output signal/s

Figure 7 Illustration of a simple Simulink model I/O interfaces in Simulink: Source blocks for inputs and Sink blocks for outputs are I/O interfaces in a Simulink model. When running a Simulink model, variables used in blocks can be declared by running M-file scripts. After running a Simulink model one can save all data in Workspace into a MAT-formatted file by using the command >> save in the MATLAB Command Window. Task 1 (Quick Start with Simulink) Run the SIMULINK program by: ; or a. Clicking on Simulink icon b. Entering the command simulink in the MATLAB command window. Do the following exercises: 1. Make a simple Simulink model to convert Celsius to Fahrenheit and Fahrenheit to Celsius using the following formulas: 9 5 F = C + 32 and C = (F 32) 5 9 Save the model as <MyFirstModel.mdl>. Select simulation parameters (Simulation menu Configuration Parameters) Run this model we can obtain results as in Figure 8. Figure 8 The Simulink model MyFirstModel 6

Task 2 A temperature-measuring system incorporates a platinum resistance thermometer, a Wheatstone bridge, a voltage amplifier, and a pen recorder. The individual sensitivities are as follows: Transducer: Wheatstone bridge: Amplifier gain: Pen recorder: 0.45 /oC 0.02V/ 100V/V 0.2cm/V

Create a simple Simulink model to calculate (a) the overall system sensitivity (b) temperature change corresponding to a recorder pen movement of 5cm. A sample Simulink model is as follows:

Figure 9 Sample Simulink model for Task 2

Task 3 Solving differential equations with Simulink Let us consider the following differential equation that represents the dynamic performance of a thermocouple with a protective sheath:

6x + x = 5 106 u
where x is output voltage (V) and u is input temperature in Celsius degrees. We will create a Simulink model to simulate the thermocouple. The above equation can be rewritten in the following form:

5 106 1 x= u x 6 6 or
x = k1u k 2 x where k1 =

5 106 1 and k 2 = 6 6

In the Simulink library, the Integrator block integrates its input (u) and produces its output (x). Other blocks needed in this model include (see Figure 10): Two Gain blocks (one for k1 and the other for k2) A Sum block (for summing k1u and k2x) A Signal Generator block (to generate a sine wave or a square wave or a sawtooth wave or a random signal) A Scope block (to view the output).

Figure 10 Simulink model for Task 3

Running this Simulink model (with ode23tb solver, a square wave: amplitude of 2.5 and frequency of 2f , f = 0.01 Hertz) we have the following result (see Figure 11).

Figure 11 Simulated result for Task 3


Activity Create a Simulink model for a piezo-electric accelerometer whose dynamic performance is expressed in the following differential equation:
y + 3.2 103 y + 2.56 1010 y = 12 1010 u where y is the output charge in pC and u is the input acceleration in m/s2.

Notes: 1. An ODE can be written in form of either a transfer function or a state space model. Therefore one can use either the Transfer Function block or State Space block (as in Figures 12 and 13) instead of the Integrator block as in Task 3. See Module 7 and Module 8.

Figure 12 Transfer Fcn block and State-Space block in the Simulink library browser

Figure 12 Transfer Fcn block and State-Space block 2. You may run Demos for MATLAB and Simulink by selecting Help menu Demos (see Figure 14).

Figure 14 MATLAB/Simulink Demos programs

Learning Resources
Getting Started with Simulink: http://www.mathworks.com/access/helpdesk/help/pdf_doc/simulink/sl_gs.pdf Using Simulink Version 6.0: http://www.mathworks.com/access/helpdesk/help/pdf_doc/simulink/sl_using.pdf More Simulink documents from MathWorks Inc: http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/

10

You might also like