Sei sulla pagina 1di 44

BTE 4225 Computer Simulations of Biological Systems

Introduction to Simulink

Assoc. Prof. Dr. Ibrahim Ali Noorbatcha Department of Biotechnology Engineering Faculty of Engineering, IIUM
1

Process simulation and modeling is the application of a range of software tools to analyze individual unit operations (or process stages) and their relationships within the overall process. This relationship includes assessing the resource and utility requirements available from the host facility. Once simulations (or models) are constructed, process engineers and scientists can investigate complex and integrated biochemical processes and unit operations, without the need for extensive experimentation or disruption to existing operations 2

BTE 4225 SIMULINK

BTE 4225 SIMULINK

These tools can be used at all stages of process development, from conceptual design, through process operation and optimization. In the tightly regulated field of biopharmaceuticals the primary concern is production throughput and optimum use of limited facilities. Demanding questions arise from the increasing use of flexible multi-product facilities and contract manufacturing. Methods are required to effectively and economically allocate resources and utilities for competing parallel processes.

Applying process simulation to maximize the utilization of resource-constrained multi-product facilities can therefore yield profound economic 3 benefits for biotechnology companies.

Modelling Tools
Today the largest supplier of simulation software to the biotech and pharmaceutical industry is Microsoft (Redmond, WA), which offers several basic software tools that can be used for simulation: Visio - Constructs flow sheets with a drawing package Excel - Process calculations are performed with spreadsheets and reported graphically Project - Constructs process schedules and labor assignments The disadvantage of these tools is that they are not designed for bioprocess simulation. 4

BTE 4225 SIMULINK

Icons for the various operations are not readily available and simulations using Exceloften result in rather large and often unwieldy spreadsheets, which are difficult to maintain and document. The popularity of these tools is due to their low cost and familiarity to users. Using these tools for simulation of multi-product resource constrained facilities can become extremely time-consuming. There are several process simulation software packages available commercially. Of these, only a few are directly applicable to bioprocessing. Still fewer combine simulation with the capability to provide scheduling of competing parallel processes within the same facility.
5

BTE 4225 SIMULINK

Aspen Technology (www.aspentech.com) originally created a dedicated Bioprocess Simulator (BPS), which was eventually phased out and replaced by Batch Plus, a recipedriven modeling environment for batch processes. Batch Plus can perform complex simulations on multiple batches in a manufacturing plant to determine the total demand

SIMULINK BTE 4225 SIMULINK


SIMULINK uses a graphical user interface (GUI) for solving process simulations. Instead of writing MATLAB code, we simply connect the necessary ``icons'' together to construct the block diagram. The ``icons'' represent possible inputs to the system, parts of the systems, or outputs of the system. SIMULINK allows the user to easily simulate systems of linear and nonlinear ordinary differential equations. A good background in matrix algebra and lumped parameter systems as well as an understanding of MATLAB is required.
7

BTE 4225 SIMULINK

Simulink is widely used for modeling and simulating dynamical systems.

Simulink encourages you to try things out. You can easily build models from scratch, or take an existing model and add to it. Simulations are interactive, so you can change parameters "on the fly" and immediately see what happens. You have instant access to all of the analysis tools in MATLAB, so you can take the results and analyze and visualize them. We hope that you will get a sense of the fun of modeling and simulation, through an environment that encourages you to pose a question, model it, and see what happens.
8

BTE 4225 SIMULINK

With Simulink, you can move beyond idealized linear models to explore more realistic nonlinear models, factoring in friction, air resistance, gear slippage, hard stops, and the other things that describe real-world phenomena. It turns your computer into a lab for modeling and analyzing systems that simply wouldn't be possible or practical otherwise, whether the behavior of an automotive clutch system, the flutter of an airplane wing, the dynamics of a predator-prey model, or the effect of the monetary supply on the economy.
9

In addition, you can change parameters and immediately see what happens, for "what if" exploration. The simulation results can be put in the MATLAB workspace for post-processing and visualization. Model analysis tools include linearization and trimming tools, which can be accessed from the MATLAB command line, plus the many tools in MATLAB and its application toolboxes. And because MATLAB and Simulink are integrated, you can simulate, analyze, and revise your models in either environment at any point.
10

BTE 4225 SIMULINK

BTE 4225 SIMULINK

Many of the features of SIMULINK are userfriendly due to the icon-driven interface, yet it is important to spend some time experimenting with SIMULINK and its many features. Dynamic simulation packages (such as MATLAB, SIMULINK, etc.) are being used more and more frequently in the chemical process industries for process simulation and control system design. After completing this tutorial, the student should be able to ``build'' and simulate block diagram representations of dynamic systems.
11

SIMULINK INTRODUCTION
BTE 4225 SIMULINK
SIMULINK is an extension to MATLAB which uses a icon-driven interface for the construction of a block diagram representation of a process. A block diagram is simply a graphical representation of a process (which is composed of an input, the system, and an output).

12

GETTING STARTED IN SIMULINK


SIMULINK is an icon-driven state of the art dynamic simulation package that allows the user to specify a block diagram representation of a dynamic process. Assorted sections of the block diagram are represented by icons which are available via various "windows" that the user opens (through double clicking on the icon). The block diagram is composed of icons representing different sections of the process (inputs, statespace models, transfer functions, outputs, etc.) and connections between the icons (which are made by "drawing" a line connecting the icons).
13

BTE 4225 SIMULINK

BTE 4225 SIMULINK

Once the block diagram is "built", one has to specify the parameters in the various blocks, for example the gain of a transfer function. Once these parameters are specified, then the user has to set the integration method (of the dynamic equations), stepsize, start and end times of the integration, etc. in the simulation menu of the block diagram window.

14

BTE 4225 SIMULINK

In order to use SIMULINK the student must ``start'' a MATLAB session (click on the MATLAB button). Once MATLAB has started up, type simulink (SMALL LETTERS!) at the MATLAB prompt (>>) followed by a carriage return (press the return key). A SIMULINK window should appear shortly, with the following icons: Sources, Sinks, Discrete, Linear, Nonlinear, Connections, Extras (this window is shown in Figure 2). Next, go to the file menu in this window and choose New in order to begin building the block diagram representation of the system of interest.

15

Modeling in SIMULINK
Linear Systems Nonlinear Systems

Modeled in Continuous time Sampled time (single rate or Multi-rate) Hybrid of the two.
Identify the System Input signals Output Signals Intermediate Signals Parameters Continuous States Discrete states

16

TO START SIMULINK

To start Simulink, on the command prompt, type >>simulink

or
Click here

17

SIMULINK WINDOW

18

SOURCES

Sources library contains the sources of data signals to be used in the dynamic system simulation. E.g. Constant signal, signal generator, sinusoidal waves, step input, repeating sequences like pulse trains and ramps etc.

19

SINKS
Sinks library contains blocks where the signal terminates. You may store data in a file, display it. Use the terminator block to terminate unused signals. STOP block is used to stop the simulation if the input to the block is non-zero.

20

CONTINUOUS AND DISCRETE

Analyze your dynamic system as continuous or discrete. Simulink lets you represent your system using transfer functions, integration blocks, delay blocks etc.

21

BLOCK DIAGRAM CONSTRUCTION

Basically, one has to specify the model of the system (state space, discrete, transfer functions, nonlinear ODE's, etc), the input (source) to the system, and where the output (sink) of the simulation of the system will go.
Open up the Sources, Sinks, and Linear windows by clicking on the appropriate icons. Note the different types of sources (step function, sinusoidal, white noise, etc.), sinks (scope, file, workspace), and linear systems (transfer function, state space model, etc.). The next step is to connect these icons together by drawing lines connecting the icons using the left-most mouse button (hold the button down and drag the mouse to draw a line).
22

SIMPLE EXAMPLE

23

NONLINEARITIES
In simulation, systems with non-linearities such as saturation, signum function, limited slew rates etc. are analyzed by numerical differentiation. You may use a saturation block to indicate a limitation on a voltage signal to a motor.

Manual switches can be used for simulations with different cases. Switches are logically equivalent to If-then statements. Slow rates using the rate limiter control the rate of change of a physical parameter such as the speed of a DC motor etc.
24

SIMPLE EXAMPLE
E.g. Consider a Sine wave of amplitude 1 (signal varies between +1 and -1). A saturation block is used to limit the output to an amplitude of 0.5 and the saturated and original signals are compared.

25

SOLVERS
A solver determines the next time step your simulation will take to meet the accuracy tolerances you specify. Simulink has Variable step solver Fixed step solver. Variable step solver; the time step added to the current time can vary depending on the dynamics of the system. If your model contains discontinuities or rapidly changing states use this solver. Eg: ODE45, ODE23, ODE11s (stiff solver)

Fixed Step Solver: Step size remains constant. They do not control integration errors or detect discontinuities. The are faster.
26

Eg. ODE1

BTE 4225 SIMULINK

For example, you may be interested in simulating a step input to a first-order transfer function in the Laplace domain and viewing the result graphically in MATLAB. The resulting block diagram is shown in Figure 3. To do this, you would "drag" a step function icon from the Sources window, a transfer function icon from the Linear window, two to workspace icons from the Sinks window, and a clock icon from the Source window to the blank block diagram window.

27

BTE 4225 SIMULINK

The next step is to connect these icons together by drawing lines connecting the icons using the left-most mouse button (hold the button down and drag the mouse to draw a line).

Connect the step function icon to the input of the transfer function icon,
then connect the output of the transfer function icon to first to workspace icon. Then, connect the clock icon to the second to workspace icon.

28

BTE 4225 SIMULINK

Open'' the icons (by double clicking on them with the left-most mouse button) and set the values of the various parameters; for example the step size and step time in the step function icon, the transfer function coefficients in the transfer function icon, and the variable names in the to workspace icons (generally, the clock variable is denote as time, whereas the output variable is denoted y). Select the parameter field from the simulation menu (in the block diagram window). set the proper integration details (min and max stepsizes, start and stop integration times, 29 integration code, etc.).

Finally, select start from the simulation menu to start the simulation.

BTE 4225 SIMULINK

The output of the simulation will be sent to the MATLAB command line interface (CLI) (MATLAB prompt, >>). The result can be plotted as one would normally plot ( e.g. plot(time,y) ), since the variables time and y are now defined in the MATLAB workspace.

The result is shown in Figure 4, for a first-order transfer function with a time constant = 2, and a unit step input at time = 1. 30

BTE 4225 SIMULINK

31

GENERAL SIMULINK TIPS 1. In order to the file that you want to save a name (or choose an old name if you are ``writing over'' an old version), click the ok button (using the left-most mouse button). Realize that you have a choice of the ``folder'' that the file is saved in. 2. The PID Controller block parameters are entered in as:

BTE 4225 SIMULINK

32

BTE 4225 SIMULINK

3. The following transfer function (in the Laplace domain) gave your work, select Save from the file menu and give.

is entered into the transfer function icon by double clicking on the transfer function icon and entering the numerator and denominator polynomial coefficients. The numerator coefficients would be entered as [2 1] and the denominator coefficients are entered as [10 5 1].
33

4. The following state-space A matrix

BTE 4225 SIMULINK

is entered into the state space icon as [1.0 -2.8;-3.1 0.2].

5. The results of a simulation can be sent to the MATLAB window by the use of the to workspace icon from the Sinks window. Open the to workspace icon and select the variable name that you want the results stored in the MATLAB workspace.
34

BTE 4225 SIMULINK

6. If your simulation has n state (or output) variables and you want to save them as different names, then you have to use a special connection called a Demux (as in demultiplexer) icon which is found in the Connections window. Basically, it takes a vector input and converts it into several scalar lines. You can set the number of outputs (scalar lines) by double clicking on the icon and changing the number of outputs. A Mux icon takes several scalar inputs and multiplexes those in a vector (useful sometimes in transferring the results of a simulation to the MATLAB workspace, for example).
35

7. You can generate white (random) noise by selecting the white noise icon from the Source window. 8. You can use a Gain icon from the Linear window if you need to multiple a signal by a constant number. 9. You can convert back to physical variables after a state-space or transfer function simulation by using the Constant icon from the Sources window and a Sum icon from the Sources window. To do this for a scalar output signal, just enter the value of the steady-state into the Constant icon and add this to the scalar output using the Sum icon. For a vector output, you must first "break-up" the vector into scalar outputs using the Demux icon and then add the steady-state value to each scalar output.
36

BTE 4225 SIMULINK

BTE 4225 SIMULINK

10.The signs of the Sum icon may be changed to negative (in order to subtract) by double clicking on the Sum icon and changing the sign from a positive to a negative sign. The number of inputs to the Sum icon may be changed by double clicking on the Sum icon and setting the number of inputs in the window. 11.Make sure to set the integration parameters in the simulation menu. In particular, the default minimum and maximum step sizes must be changed (they should be around 1/100 to 1/10 of the dominant (slowest) time constant of your system).

37

BTE 4225 SIMULINK

12.Parameters can be "passed" to SIMULINK from the MATLAB window by using the parameter in a SIMULINK block or parameter box and defining the parameter in the MATLAB window. For example, say that one wants to run the simulation with many different process gains, then in the transfer function icon the gain (in the numerator) can be given the symbol k (or any symbol) and then at the MATLAB prompt define k = 1.0. Run the simulation, then at the MATLAB prompt redefine k = 1.5, etc. This is very useful if the student wants to study the influence of a parameter on the dynamic behavior of a process (important in determining stability).

38

BTE 4225 SIMULINK

13.In order to print the block diagram, first save the block diagram. Then, at the MATLAB prompt, type: print -sname-of-simulink-block where name-of-simulink-block is the name that you saved the block diagram under. For example, if you saved the block diagram as homework1.m, then you would type: print -shomework1

39

BTE 4225 SIMULINK

14.Time delays (deadtimes) can be simulated in SIMULINK easily by using a transport delay icon from the Nonlinear window. Double click on the transport delay icon to set the value of the deadtime. 15.Nonlinear systems can be simulated in SIMULINK using an s-function icon from the Extras window. The nonlinear ordinary differential equations must be specified in an m-file, and the name of this m-file is specified in the s-function by the user. We will generally supply the student with the m-file containing the nonlinear ordinary differential equations.

40

TABLE OF SIMULINK BLOCKS


BTE 4225 SIMULINK

41

BTE 4225 SIMULINK

42

BTE 4225 SIMULINK

43

BTE 4225 SIMULINK

44

Potrebbero piacerti anche