INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

38
INTRODUCTION TO SIMULINK INTRODUCTION TO SIMULINK by by Yasmin Hanum Md Thayoob Yasmin Hanum Md Thayoob & & Aidil Azwin Zainul Abidin Aidil Azwin Zainul Abidin

Transcript of INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Page 1: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

INTRODUCTION TO INTRODUCTION TO SIMULINKSIMULINK

byby

Yasmin Hanum Md ThayoobYasmin Hanum Md Thayoob&&

Aidil Azwin Zainul AbidinAidil Azwin Zainul Abidin

Page 2: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

TABLE OF CONTENTSTABLE OF CONTENTS What Is Simulink?What Is Simulink? Starting SimulinkStarting Simulink Simulink WindowsSimulink Windows Simulink LibrarySimulink Library Creating A New ModelCreating A New Model Entering Simulink Entering Simulink

CommandsCommands Connecting BlocksConnecting Blocks Modeling In Simulink Modeling In Simulink

Example 1Example 1 Example 2Example 2

Creating Subsystems Creating Subsystems Simulation ParametersSimulation Parameters Running A SimulationRunning A Simulation Getting OutputGetting Output Using ScopeUsing Scope Further ConsiderationsFurther Considerations Ending A Simulink Ending A Simulink

SessionSession Case StudyCase Study ReferencesReferences

Page 3: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

What Is SimulinkWhat Is Simulink

Simulink is a graphical method of modeling and Simulink is a graphical method of modeling and simulating a mathematical equation or a system in simulating a mathematical equation or a system in Matlab.Matlab.

Simulink is not a stand alone program which Simulink is not a stand alone program which means that it could not be run without running means that it could not be run without running Matlab.Matlab.

Whatever variable defined in Matlab can be used Whatever variable defined in Matlab can be used in Simulink.in Simulink.

Page 4: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Starting SimulinkStarting Simulink

To start Simulink, you must first start MATLAB. Consult To start Simulink, you must first start MATLAB. Consult your MATLAB documentation for more information. You your MATLAB documentation for more information. You can then start Simulink in two ways:can then start Simulink in two ways:

Click the Click the Simulink iconSimulink icon on the MATLAB toolbar. on the MATLAB toolbar.

Enter the simulink command at the MATLAB prompt.Enter the simulink command at the MATLAB prompt.

On Microsoft Windows platforms, starting Simulink On Microsoft Windows platforms, starting Simulink displays the displays the Simulink Library BrowserSimulink Library Browser

Page 5: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Simulink WindowsSimulink Windows Simulink uses separate windows to display:Simulink uses separate windows to display:

a block library browsera block library browser a block librarya block library a modela model graphical (scope) simulation outputgraphical (scope) simulation output

These windows are not MATLAB figure These windows are not MATLAB figure windows and cannot be manipulated using windows and cannot be manipulated using HandleGraphics® commands.HandleGraphics® commands.

Page 6: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Simulink LibrarySimulink Library

The Library Browser displays a The Library Browser displays a tree-structured view of the tree-structured view of the Simulink block librariesSimulink block libraries installed installed on your system. You can build on your system. You can build models by copying blocks from models by copying blocks from the Library Browser into a model the Library Browser into a model window.window.

Page 7: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Sources and SinksSources and Sinks

Page 8: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Continuous and Discrete SystemsContinuous and Discrete Systems All dynamic systems can be analyzed as continuous or discrete time All dynamic systems can be analyzed as continuous or discrete time

systems. Simulink allows you to represent these systems using transfer systems. Simulink allows you to represent these systems using transfer functions, integration blocks, delay blocks etc.functions, integration blocks, delay blocks etc.

Page 9: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Simulink ExtrasSimulink Extras Figure 5 contains some advanced linear blocks, available in the Figure 5 contains some advanced linear blocks, available in the

““Simulink ExtrasSimulink Extras” ibrary. They contain certain advanced blocks, such ” ibrary. They contain certain advanced blocks, such as a PID control block, transfer functions with initial conditions, etc.as a PID control block, transfer functions with initial conditions, etc.

Page 10: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Non-linear operatorsNon-linear operators

Page 11: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Functions and TablesFunctions and Tables

Page 12: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Math Block (Mathematical tools)Math Block (Mathematical tools)

Page 13: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Signals & Systems BlockSignals & Systems Block ( (Signals and data transfer)Signals and data transfer)

In complicated block diagrams, In complicated block diagrams, there may arise the need to there may arise the need to transfer data from one portion transfer data from one portion to another portion of the block. to another portion of the block. They may be in different They may be in different subsystems. That signal could subsystems. That signal could be dumped into a GOTO block, be dumped into a GOTO block, which is used to send signals which is used to send signals from one subsystem to another.from one subsystem to another.

Multiplexing Multiplexing helps us remove helps us remove clutter due to excessive clutter due to excessive connectors, and makes matrix connectors, and makes matrix (column/row) visualization (column/row) visualization easier.easier.

Page 14: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Subsystems BlockSubsystems Block

Page 15: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Creating a New ModelCreating a New Model

Click the Click the NewNew button on the button on the Simulink Library Browser’sSimulink Library Browser’s toolbartoolbar (Windows only) or choose (Windows only) or choose NewNew from the library from the library window’s File menuwindow’s File menu and select Model. You can move the and select Model. You can move the window as you do other windows.window as you do other windows.

You can build models by copying blocks from the Library You can build models by copying blocks from the Library Browser into a model window (this procedure is described Browser into a model window (this procedure is described later in the modeling example ).later in the modeling example ).

Page 16: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

• Simulink opens a new model window as below.

Page 17: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Entering Simulink CommandsEntering Simulink Commands You run Simulink and work with your model by entering You run Simulink and work with your model by entering

commands. You can enter commands by:commands. You can enter commands by:••Selecting items from the Simulink menu barSelecting items from the Simulink menu bar

••Selecting items from a context-sensitive Simulink menu (Windows Selecting items from a context-sensitive Simulink menu (Windows only)only)

• Clicking buttons on the Simulink toolbar (Windows only)Clicking buttons on the Simulink toolbar (Windows only)

••Entering commands in the MATLAB command windowEntering commands in the MATLAB command window

Page 18: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

• Using Context-Sensitive Menus to Enter Using Context-Sensitive Menus to Enter Commands:Commands:

Simulink displays a context-sensitive menu when you Simulink displays a context-sensitive menu when you click the right mouse button over a model or block library click the right mouse button over a model or block library window. The contents of the menu depend on whether a window. The contents of the menu depend on whether a block is selected. If a block is selected, the menu displays block is selected. If a block is selected, the menu displays commands that apply only to the selected block. If no commands that apply only to the selected block. If no block is selected, themenu displays commands that apply block is selected, themenu displays commands that apply to a model or library as a whole.to a model or library as a whole.

Page 19: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Connecting BlocksConnecting Blocks To connect blocks, To connect blocks, left-click left-click and drag the mouse from the output of and drag the mouse from the output of

one block to the input of another block. The figure below shows the one block to the input of another block. The figure below shows the steps involved.steps involved.

Page 20: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Modeling In SimulinkModeling In SimulinkExample 1: Modeling EquationsExample 1: Modeling Equations

Converting Celsius to Fahrenheit:Converting Celsius to Fahrenheit:To model the equation that converts Celsius temperature to To model the equation that converts Celsius temperature to Fahrenheit Fahrenheit

TTF F = 9/5(T= 9/5(TCC) + 32) + 32

First, consider the blocks needed to build the model:First, consider the blocks needed to build the model:••A A Ramp blockRamp block to input the temperature signal, from the Sources library to input the temperature signal, from the Sources library••A A Constant blockConstant block to define a constant of 32, also from the Sources to define a constant of 32, also from the Sources librarylibrary••A A Gain blockGain block to multiply the input signal by 9/5, from the Math library to multiply the input signal by 9/5, from the Math library••A A Sum blockSum block to add the two quantities, also from the Math library to add the two quantities, also from the Math library••A A Scope blockScope block to display the output, from the Sinks library to display the output, from the Sinks library

Page 21: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Next, gather the blocks into your model window.Next, gather the blocks into your model window.

Assign parameter values to the Gain and Constant blocks by openingAssign parameter values to the Gain and Constant blocks by opening

(double-clicking) each block and entering the appropriate value. Then, (double-clicking) each block and entering the appropriate value. Then, click the Close button to apply the value and close the dialog box.click the Close button to apply the value and close the dialog box.

Now, connect the blocks.Now, connect the blocks.

Page 22: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

The The Ramp blockRamp block inputs Celsius temperature. Open that block inputs Celsius temperature. Open that block and change the and change the Initial output Initial output parameter to 0.parameter to 0.

The The Gain blockGain block multiplies that temperature by the constant multiplies that temperature by the constant 9/5. The Sum block adds the value 32 to the result and outputs 9/5. The Sum block adds the value 32 to the result and outputs the Fahrenheit temperature.the Fahrenheit temperature.

Open the Open the Scope blockScope block to view the output. Now, choose to view the output. Now, choose Start Start from the from the Simulation Simulation menu to run the simulation. The menu to run the simulation. The simulation runs for 10 seconds.simulation runs for 10 seconds.

Page 23: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Example 2: Modeling A Simple Continuous SystemExample 2: Modeling A Simple Continuous System

To model the differential equation To model the differential equation

xx′ (′ (tt) = – 2) = – 2x x ((tt) + ) + u u ((tt))

where where u(t) u(t) is a square wave with an amplitude of 1 and a is a square wave with an amplitude of 1 and a frequency of 1 rad/sec. The frequency of 1 rad/sec. The Integrator blockIntegrator block integrates its integrates its input input xx′ to produce ′ to produce xx. Other blocks needed in this model . Other blocks needed in this model include a include a Gain blockGain block and a and a Sum blockSum block. To generate a square . To generate a square wave, use a wave, use a Signal Generator blockSignal Generator block and select the Square and select the Square Wave form but change the default units to radians/sec. Wave form but change the default units to radians/sec.

Again, view the output using a Again, view the output using a Scope blockScope block. Gather the . Gather the blocks and define the gain.blocks and define the gain.

Page 24: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

An important concept in this model is the loop that An important concept in this model is the loop that includes the Sum block, the Integrator block, and the includes the Sum block, the Integrator block, and the Gain block. In this equation, Gain block. In this equation, x x is the output of the is the output of the Integrator block. It is also the input to the blocks that Integrator block. It is also the input to the blocks that compute compute xx′, on which it is based. This relationship is ′, on which it is based. This relationship is implemented using a loop.implemented using a loop.

Page 25: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

• The Scope displays The Scope displays x x at each time step. For a simulation at each time step. For a simulation lasting 10 seconds, the output looks like this:lasting 10 seconds, the output looks like this:

Page 26: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

The equation you modeled in this example can also be The equation you modeled in this example can also be expressed as a transfer function. The model uses the expressed as a transfer function. The model uses the Transfer Fcn block, which accepts Transfer Fcn block, which accepts u u as input and outputs as input and outputs xx. So, the block implements . So, the block implements x/ux/u. If you substitute . If you substitute sx sx for for xx′ ′ in the above equation, you getin the above equation, you get

sx = -sx = -22x + x + u u

Solving for Solving for x x givesgives

x = u /(s + x = u /(s + 2) 2) or,or,

x x ⁄ ⁄ u u = 1 ⁄ ( = 1 ⁄ ( s s + 2) + 2)

Page 27: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

The results of this simulation are identical to those of the previous The results of this simulation are identical to those of the previous

model.model.

• The Transfer Fcn block uses parameters to specify the numerator and denominator coefficients. In this case, the numerator is 1 and the denominator is s+2. Specify both terms as vectors of coefficients of successively decreasing powers of s. In this case the numerator is [1] (or just 1) and the denominator is [1 2]. The model now becomes quite simple.

Page 28: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Creating Sub SystemCreating Sub System

It helps reduce the number of blocks displayed in It helps reduce the number of blocks displayed in your model window. your model window.

It allows you to keep functionally related blocks It allows you to keep functionally related blocks together. together.

It enables you to establish a hierarchical block It enables you to establish a hierarchical block diagram, where a Subsystem block is on one layer diagram, where a Subsystem block is on one layer and the blocks that make up the subsystem are on and the blocks that make up the subsystem are on another. another.

Page 29: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Before - AfterBefore - After

Check with model browser in Simulink windowCheck with model browser in Simulink window Label subsytem PortsLabel subsytem Ports

Page 30: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Simulation ParametersSimulation Parameters

You can set the simulation parameters for each simulation You can set the simulation parameters for each simulation such as run time or solver optionsuch as run time or solver option

Page 31: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Simulation Parameters (Continue)Simulation Parameters (Continue)

Setting simulation timeSetting simulation time Setting solverSetting solver

Step Size

Solver type

Page 32: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Running A SimulationRunning A Simulation

A simulation can be run A simulation can be run using 3 ways:using 3 ways: Clicking the start word on the Clicking the start word on the

simulation tabsimulation tab Clicking the “play” button on Clicking the “play” button on

the windowthe window Pressing Ctrl+T.Pressing Ctrl+T.

Page 33: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

When a simulation is running, the status bar displays the status of the simulation, including the current simulation time and the name of the current solver. You can display or hide the status bar by selecting or clearing the Status Bar option on the Simulink View menu.

Page 34: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Getting OutputGetting Output You can save scope data You can save scope data

into workspace (you can do into workspace (you can do this with “save to this with “save to workspace” block in “sinks” workspace” block in “sinks” catagory)catagory)

You can view more than You can view more than one signal in scope either on one signal in scope either on the same axis or in the the same axis or in the separate axis.separate axis.

Data can also be exported to Data can also be exported to the workspace using the the workspace using the scope.scope.

Parameters

Page 35: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Using ScopeUsing Scope

Setting the number of axes for the scope (Figure 1)Setting the number of axes for the scope (Figure 1) Saving the data to workspace (Figure 2)Saving the data to workspace (Figure 2)

Page 36: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Further ConsiderationsFurther Considerations

This lecture can’t possibly look upon all the blocks.This lecture can’t possibly look upon all the blocks.

Another way is to get Another way is to get ““helphelp”” concerning the block. concerning the block. This can be done by double clicking on the block. A This can be done by double clicking on the block. A

window will appear where a window will appear where a helphelp button is available. button is available.

Click on that button to know what is the potential of Click on that button to know what is the potential of the block.the block.

Page 37: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

Ending A Simulink SessionEnding A Simulink Session

Terminate a Simulink session by closing all Terminate a Simulink session by closing all Simulink windows.Simulink windows.

Terminate a MATLAB session by choosing Terminate a MATLAB session by choosing the command below from the the command below from the File File menu:menu:

••Exit MATLABExit MATLAB

Page 38: INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.

ReferencesReferences

SIMULINK – Model-Based and System-Based DesignSIMULINK – Model-Based and System-Based Design

Matlab Documentation, The MathWorks.Matlab Documentation, The MathWorks. www.mathworks.com http://sts.bwk.tue.n1/7y530/readers/.%5CSimuLinkTutorihttp://sts.bwk.tue.n1/7y530/readers/.%5CSimuLinkTutori

al.pdfal.pdf http://www.eng.warwick.ac.uk/staff/msl/progs/http://www.eng.warwick.ac.uk/staff/msl/progs/

simulinklab1.pdfsimulinklab1.pdf http://www.engin.umich.edu/group/ctm/working/mac/http://www.engin.umich.edu/group/ctm/working/mac/

simulink_basics/simulink_basics/