Home » Uncategorized » Matlab Simulink

Matlab Simulink

Matlab Simulink

6. SIMULINK –MODELING AND ANALYSIS (In the process of editing)

Starting SIMULINK , Model Files,, Basic Elements, Constructing simple files, Building Systems and
Changing the block parameters, Labeling blocks and Signals, Running Simulations, Saving/opening a model

SIMULINK provides an environment where you model your physical system and controller as a block diagram.

6.1.    What Is SIMULINK?
SIMULINK is a software package for modeling, simulating, and analyzing dynamic systems.
It supports linear and nonlinear systems, modeled in continuous time, sampled time, or a hybrid of the two. Systems can also be multirate, i.e., have different parts that are sampled or updated at different rates
6.2.    Goal of SIMULINK
A goal of SIMULINK is to give you 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.
SIMULINK is also practical. With thousands of engineers around the world using it to model and solve real problems, knowledge of this tool will serve you well throughout your professional career.
6.3.    SIMULINK a tool for Model-Based Design
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.
SIMULINK 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.
For modeling, SIMULINK provides a graphical user interface (GUI) for building models as block diagrams, using click-and-drag mouse operations.
SIMULINK also includes a comprehensive block library of sinks, sources, linear and nonlinear components, and connectors.
Models are hierarchical, so you can build models using both top-down and bottom-up approaches.
After you define a model, you can simulate it, using a choice of integration methods, either from the SIMULINK menus or by entering commands in the MATLAB Command Window.
The menus are particularly convenient for interactive work, while the command-line approach is very useful for running a batch of simulations.
Using scopes and other display blocks, you can see the simulation results while the simulation is running.
6.4.    To open the SIMULINK block library

On Microsoft Windows, SIMULINK or SIMULINK('open') opens the SIMULINK block library browser. On UNIX, the command opens the SIMULINK library window. SIMULINK('close') closes the library window.
6.5.    SIMULINK Components
SIMULINK components can report on four levels of a SIMULINK model:
    model
    system
    block
    signal
6.6.    SIMULINK components have the following parent/child relationships

6.7.    SIMULINK Blocks Components
SIMULINK Blocks components can be used in model, system, or block loops to report on block types in context.  The block components are:
Creates  a list of all signals exiting from a Bus Selector block. The list can contain only those signals leaving from the reported block or it can be hierarchical and display downstream buses and signals.
Inserts text extracted from doc blocks in SIMULINK models. The Documentation component can have the Model Loop, the System Loop, or the Block Loop as its parent.
Reports on lookup table blocks; it inserts a figure and/or table into the report. The table contains input and output numeric values, and the figure is a plot of the values.
Inserts a snapshot of all scope blocks and XY plots in your report. The Scope Snapshot component can have any SIMULINK looping component as its parent.
Basic Elements
There are two major classes of items in SIMULINK:
1.    Blocks
Blocks are used to generate, modify, combine, output, and display signals and
2.    Lines
Lines are used to transfer signals from one block to another.
6.8.    Blocks
There are several general classes of blocks:
Sources: Used to generate various signals
Sinks: Used to output or display signals
Discrete: Linear, discrete-time system elements (transfer functions, state-space models, etc.)
Linear: Linear, continuous-time system elements and connections (summing junctions, gains, etc.)
Nonlinear: Nonlinear operators (arbitrary functions, saturation, delay, etc.)
Connections: Multiplex, Demultiplex, System Macros, etc.
Blocks have zero to several input terminals and zero to several output terminals.  Unused input terminals are indicated by a small open triangle. Unused output terminals are indicated by a small triangular point

6.9.    Lines
Lines transmit signals in the direction indicated by the arrow.
Lines must always transmit signals from the output terminal of one block to the input terminal of another block.
On exception to this is a line can tap off of another line, splitting the signal to each of two destination blocks, as shown below

NOTE: Lines can never inject a signal into another line; lines must be combined through the use of a block such as a summing junction.
A signal can be either a scalar signal or a vector signal.
For Single-Input, Single-Output systems, scalar signals are generally used.
For Multi-Input, Multi-Output systems, vector signals are often used, consisting of two or more scalar signals.
The lines used to transmit scalar and vector signals are identical. The type of signal carried by a line is determined by the blocks on either end of the line.
6.10.    Modifying Blocks
A block can be modified by double-clicking on it. For example, if you double-click on the "Transfer Fcn" block in the simple model, you will see the following dialog box.

6.11.    Running Simulations

6.12.    Parameters from the Simulation menu
There are many simulation parameter options; we will only be concerned with the start and stop times, which tell SIMULINK over what time period to perform the simulation.
Change Start time from 0.0 to 0.8 (since the step doesn't occur until t=1.0. Change Stop time from 10.0 to 2.0, which should be only shortly after the system settles.
Close the dialog box and rerun the simulation.
After hitting the auto scale button, the scope window should provide a much better display of the step response as shown.

6.13.    Building Systems

Gathering Blocks
Follow the steps below to collect the necessary blocks:
Create a new model (New from the File menu or Ctrl-N). You will get a blank model window.

Double-click on the Sources icon in the main SIMULINK window.
This opens the Sources window which contains the Sources Block Library. Sources are used to generate signals.

Drag the Step block from the sources window into the left side of your model window.

Double-click on the Linear icon in the main SIMULINK window to open the Linear Block Library window.
Drag the Sum, Gain, and two instances of the Transfer Fcn (drag it two times) into your model window arranged approximately as shown below. The exact alignment is not important since it can be changed later. Just try to get the correct relative positions. Notice that the second Transfer Function block has a 1 after its name. Since no two blocks may have the same name, SIMULINK automatically appends numbers following the names of blocks to differentiate between them.

Double-click on the Sinks icon in the main SIMULINK window to open the Sinks window.
Drag the Scope block into the right side of your model window.

6.14.    Modify Blocks

Follow these steps to properly modify the blocks in your model.
Double-click your Sum block. Since you will want the second input to be subtracted, enter + - into the list of signs field. Close the dialog box.
Double-click your Gain block. Change the gain to 2.5 and close the dialog box.
Double-click the leftmost Transfer Function block. Change the numerator to [1 2] and the denominator to [1 0]. Close the dialog box.
Double-click the rightmost Transfer Function block. Leave the numerator [1], but change the denominator to [1 2 4]. Close the dialog box. Your model should appear as:

Change the name of the first Transfer Function block by clicking on the words "Transfer Fcn". A box and an editing cursor will appear on the block's name as shown below. Use the keyboard (the mouse is also useful) to delete the existing name and type in the new name, "PI Controller". Click anywhere outside the name box to finish editing.

Similarly, change the name of the second Transfer Function block from "Transfer Fcn1" to "Plant". Now, all the blocks are entered properly. Your model should appear as:

Example 1
After connecting as per our requirement
Finally, you will place labels in your model to identify the signals. To place a label anywhere in your model, double click at the point you want the label to be. Start by double clicking above the line leading from the Step block. You will get a blank text box with an editing cursor as shown below
To save your model, select Save As in the File menu and type in any desired model name

6.15.    Simulation
Now that the model is complete, you can simulate the model.
Select Start from the Simulation menu to run the simulation.
Double-click on the Scope block to view its output. Hit the autoscale button (binoculars) and you should see as shown.

Example 2: a simple model

Build a SIMULINK model that solves the differential equation

Initial condition

First, sketch a simulation diagram of this mathematical model (equation) (3 min.)

Simulation diagram

Input is the forcing function 3sin(2t)
Output is the solution of the differential equation x(t)

Now build this model in SIMULINK
Step1. Select an input block
Drag a Sine Wave block from the Sources library to the model window

Select an operator block
Drag an Integrator block from the Continuous library to the model window

Select an output block
Drag a Scope block from the Sinks library to the model window

Step2.Connect blocks with signals
Place your cursor on the output port (>) of the Sine Wave block
Drag from the Sine Wave output to the Integrator input
Drag from the Integrator output to the Scope input

Arrows indicate the direction of the signal flow.

Step.3 Select simulation parameters

Double-click on the Sine Wave block to set amplitude = 3 and freq = 2.
This produces the desired input of 3 sin (2t)

Select simulation parameters
Double-click on the Integrator block to set initial condition = -1.
This sets our IC x(0) = -1.

Double-click on the Scope to view the simulation results

Step.4. Run the simulation
In the model window, from the  Simulation pull-down menu, select Start
View the output x(t) in the Scope window.

Step.5. Simulation results

To verify that this plot represents the solution to the problem, solve the equation analytically.
The analytical result, matches the plot (the simulation result) exactly as

Example 3
Build a SIMULINK model that solves the following differential equation

•    2nd-order mass-spring-damper system
•    zero ICs
•    Input f(t) is a step with magnitude 3
•    Parameters: m = 0.25, c = 0.5, k = 1

Create the simulation diagram
On the following slides:
•    The simulation diagram for solving the ODE is created step by step.
•    After each step, elements are added to the SIMULINK model.
Optional exercise: first, sketch the complete diagram (5 min.)

First, solve for the term with highest-order derivative

Make the left-hand side of this equation the output of a summing block

Drag a Sum block from the Math library
Double-click to change the block parameters to rectangular and + - -

Add a gain (multiplier) block to eliminate the coefficient and produce the highest-derivative alone

Drag a Gain block from the Math library
The gain is 4 since 1/m=4.
Double-click to change the block parameters.
Add a title.

Add integrators to obtain the desired output variable

Drag Integrator blocks from the Continuous library
ICs on the integrators are zero.
Add a scope from the Sinks library.
Connect output ports to input ports.
Label the signals by double-clicking on the leader line.

Connect to the integrated signals with gain blocks to create the terms on the right-hand side of the EOM

Drag new Gain blocks from the Math library
To flip the gain block, select it and choose Flip Block in the Format pull-down menu.
Double-click on gain blocks to set parameters
Connect from the gain block input backwards up to the branch point.
Re-title the gain blocks.

Complete the model
Bring all the signals and inputs to the summing block.
Check signs on the summer.

Double-click on Step block to set parameters. For a step input of magnitude 3, set Final value to 3

Final SIMULINK model

Run the simulation


Underdamped response.
Overshoot of 0.5.
Final value of 3.
Is this expected?
Paper-and-pencil analysis based on the equations of motion

Standard form

Nat’l freq.

Damping ratio

Static gain
Check simulation results
Damping ratio of 0.5 is less than 1.
•    Expect the system to be under damped.
•    Expect to see overshoot.
Static gain is 1.
•    Expect output magnitude to equal input magnitude.
•    Input has magnitude 3, so does output.
Simulation results conform to expectations.
Example 4 (your turn)
Create a simulation diagram model that solves the following 1st-order ODE
IC: x (0) = 2
Solve for the term with highest-order derivative
Make the left-hand term the output of a summing block
Make the right-hand term(s) the input(s) to the summing block
Does the output of the summer have a coefficient?
Add a gain (multiplier) block to eliminate the coefficient and produce the highest-derivative alone
Add integrators to obtain the desired output variable
Add initial conditions to the integrators
Do any signals feedback to the summer?
Yes. Connect to the integrated signals with gain blocks to create the necessary signals
Identify inputs and outputs
All done!
Simulation diagram is complete