2-Introduction To Simulink
2-Introduction To Simulink
SUBMITTED TO :
SEMESTER :
SECTION :
________________________________________________________________________
Experiment # 02 Page 1 of 13
Control Systems Lab
_________________________________________________________________________
Simulink is a powerful graphical user interface (GUI) of Matlab. This software is used for
solving the modeling equations and obtaining the response of a system to different inputs.
Both linear and nonlinear differential equations can be solved numerically with high
precision and speed, allowing system responses to be calculated and displayed for many
input functions. To provide an interface between a system’s modeling equations and the
digital computer, block diagrams drawn from the system’s differential equations are used.
A block diagram is an interconnection of blocks representing basic mathematical
operations in such a way that the overall diagram is equivalent to the system’s
mathematical model. The lines interconnecting the blocks represent the variables
describing the system behavior. These may be inputs, outputs, state variables, or other
related variables. The blocks represent operations or functions that use one or more of these
variables to calculate other variables. Block diagrams can represent modeling equations in
both input-output and state variable form.
The operations that we generally use in block diagrams are summation, gain, and
integration. Other blocks, including nonlinear elements such as multiplication, square root,
exponential, logarithmic, and other functions, are available. Provisions are also included
for supplying input functions, using a signal generator block, constants etc and for
displaying results, using a scope block.
An important feature of a numerical simulation is the ease with which parameters can be
varied and the results observed directly. MATLAB is used in a supporting role to initialize
________________________________________________________________________
Experiment # 02 Page 2 of 13
Control Systems Lab
_________________________________________________________________________
parameter values and to produce plots of the system response. Also MATLAB is used for
multiple runs for varying system parameters.
SIMULINK
Simulink provides access to an extensive set of blocks that accomplish a wide range of
functions useful for the simulation and analysis of dynamic systems. The blocks are
grouped into libraries, by general classes of functions.
• Mathematical functions such as summers and gains are in the Math library.
• Integrators are in the Continuous library.
• Constants, common input functions, and clock can all be found in the Sources library.
• Scope, To Workspace blocks can be found in the Sinks library.
Simulink allows the user to create programs that are actually run in MATLAB. When these
programs run, they create arrays of the variables defined in Simulink that can be made
available to MATLAB for analysis and/or plotting. The variables to be used in MATLAB
must be identified by Simulink using a “To Workspace” block, which is found in the Sinks
library. (When using this block, open its dialog box and specify that the save format should
be Matrix, rather than the default, which is called Structure.) The Sinks library also contains
a Scope, which allows variables to be displayed as the simulated system responds to an
input. This is most useful when studying responses to repetitive inputs.
Simulink uses blocks to write a program. Blocks are arranged in various libraries according
to their functions. Properties of the blocks and the values can be changed in the associated
dialog boxes. Some of the blocks are given below.
________________________________________________________________________
Experiment # 02 Page 3 of 13
Control Systems Lab
_________________________________________________________________________
________________________________________________________________________
Experiment # 02 Page 5 of 13
Control Systems Lab
_________________________________________________________________________
Two additional blocks will be needed if we wish to use MATLAB to plot the responses
versus time. These are the Clock and the To Workspace blocks.
________________________________________________________________________
Experiment # 02 Page 6 of 13
Control Systems Lab
_________________________________________________________________________
In the Simulink diagram, the appearance of a block can be changed by changing the
foreground or background colours, or by drop shadow or other options available in the
format drop down menu. The available options can be reached in the Simulink window by
highlighting the block, then clicking the right mouse button. The Show Drop Shadow
option is on the format drop-down menu.
You are encouraged to browse the Simulink libraries and consult the online Help facility
provided with MATLAB.
In class we have learned how to model different physical systems. Consider the mass spring
damper system shown in Figure 10.
Where m is the mass, b is the damper, and k is the spring constant. For instance we take the
following values
𝑚 = 10𝑘𝑔
𝑏 = 2𝑁𝑠𝑚−1
𝑘 = 5𝑁𝑚−1
x is the position displacement, 𝑥̇ is the time derivative of position i.e., velocity and 𝑥̈ is the
acceleration of the mass
The above equation can be re-written as
Now this equation is to be implemented in Simulink with a unit step input, and position of
the mass taken as the output.
________________________________________________________________________
Experiment # 02 Page 7 of 13
Control Systems Lab
_________________________________________________________________________
IMPLEMENTATION IN SIMULINK
To create a simulation in Simulink, follow the steps:
Start MATLAB.
Start Simulink. Type Simulink in the command window and press enter.
This will open the Simulink start page. Click on Blank model.
Following window will appear. Click on the highlighted icon to open Simulink
library browser.
________________________________________________________________________
Experiment # 02 Page 8 of 13
Control Systems Lab
_________________________________________________________________________
Open the libraries that contain the blocks you will need. These usually will include
the Sources, Sinks, Math and Continuous libraries, and possibly others.
Write sum in the search bar. Drag the block to the Simulink window. Similarly drag
following blocks to the Simulink window.
1. Step
2. Integrator
3. Gain
4. Scope
To duplicate any block, click on the block, press ctrl and while keeping it pressed,
drag the block. This would add an identical block. In the current case, do this twice
for the Gain block and once for the Integrator block. This would add 1 integrator
block and 2 gain blocks.
To flip any block, select the block and press ctrl+I OR right click on the block and
in the Rotate and Flip tab select Flip Block. Similarly, to rotate any block, press
ctrl+R OR right click on the block and in the Rotate and Flip tab select Clockwise
or Counterclockwise. In the current case, flip two Gain blocks and leave one as it
is.
Arrange these blocks in an orderly way corresponding to the equations to be solved.
To arrange the blocks you must understand the equation. The equation is given as
𝑚𝑥̈ = 𝑢(𝑡) − 𝑏𝑥̇ − 𝑘𝑥
________________________________________________________________________
Experiment # 02 Page 9 of 13
Control Systems Lab
_________________________________________________________________________
This means that the result of the Sum block is 𝑚𝑥̈ and there are 3 inputs to the Sum
block i.e. 𝑢(𝑡), −𝑏𝑥̇, 𝑎nd – 𝑘𝑥. To implement this, double click on the Sum block
and in the List of Signs section, enter 1 ‘+’ sign and 2 ‘-‘ signs as shown in the
figure below.
Now, connect the Step block to the ‘+’ sign input of the Sum block. We know that
the output of the Sum block is 𝑚𝑥̈ , so to obtain 𝑥̈ , we will Multiply this output
with a factor 1/𝑚. This is done by using the Gain block. Connect the output of
the Sum block to the input of the Gain block (which is not flipped). Double click
on the Gain block, and under the Gain section write ‘1/𝑚’. The output of this Gain
block is giving 𝑥̈ . To produce 𝑥̇ , from 𝑥̈ , the Integrator block will be used.
Connect the output of this Gain block to the input of one Integrator block. Again,
to produce 𝑥 from 𝑥̇ , an Integrator block will be used. Connect the output of the
first Integrator block to the input of the second Integrator block. The output of the
second Integrator block is giving 𝑥. Since in the current case, we are interested
in observing the distance covered by the mass. So connect the output of the second
Integrator block to the Scope block (If you want to observe the velocity, you can
connect the output of the 1st Integrator block to another Scope block. The two
negative inputs of the Sum block are still to be connected. We know that the one
of the inputs to the Sum block is −𝑏𝑥̇ , so to obtain this term, connect the input
of one flipped Gain block to the output of the first Integrator block which is
actually 𝑥̇ . Double click on this Gain block and under the Gain section write ‘𝑏’.
The output of this Gain block is 𝑏𝑥̇ . Connect this output to one of the negative
inputs of the Sum block. Similarly, we know that the second input to the Sum
block is −𝑘𝑥, so to obtain this term, connect the input of the second flipped Gain
block to the output of the second Integrator block which is actually 𝑥. Double click
on this Gain block and under the Gain section write ‘k’. The output of this Gain
block is 𝑘𝑥. Connect this output to the only unconnected input of the Sum block.
Interconnection of the blocks is done by dragging the cursor from the output of one
block to the input of another block. Interconnecting branches can be made by right-
clicking on an existing branch.
Double-click on any block having parameters that must be established, and set these
parameters. For example, the gain of all Gain blocks must be set. The number and
signs of the inputs to a Sum block must be established. The parameters of any
source blocks should also be set in this way.
The block diagram should look like following
________________________________________________________________________
Experiment # 02 Page 10 of 13
Control Systems Lab
_________________________________________________________________________
Double click on the 1st Integrator block. You can give an initial velocity value by
editing the value under the Initial Value section. However, for the current case, we
consider the initial velocity to be 0 𝑚/s and the default value under the Initial
Value section is also 0. Similarly, Double click on the 2nd Integrator block. You
can give an initial position value by editing the value under the Initial Value section.
However, for the current case, we consider the initial position to be 0 𝑚 and the
default value under the Initial Value section is also 0. This completes the
implementation.
________________________________________________________________________
Experiment # 02 Page 11 of 13
Control Systems Lab
_________________________________________________________________________
The model is ready to be simulated now. The simulation time can be changed, by
editing the time in the model window as highlighted (green color) in the figure
below:
To run the simulation, press the run button as highlighted (red color) in the above
figure.
To observe the position plot, Double Click on the Scope block.
Linmod Command:
The models which we make on the SIMULINK design window can be converted and
manipulated in the MATLAB command window by using the LINMOD command,
The Syntax of command is as:
Linmod(‘File Name’)
Task 2:
Consider the following mass-spring damper
________________________________________________________________________
Experiment # 02 Page 12 of 13
Control Systems Lab
_________________________________________________________________________
where 𝑁 is the mean/average of the last two digits of the registration number of the
individual student.
________________________________________________________________________
Experiment # 02 Page 13 of 13
Control Systems Lab