0% found this document useful (0 votes)
22 views

2-Introduction To Simulink

This document provides an introduction to using Simulink to model and simulate dynamic systems. It discusses how Simulink allows users to create block diagram models of systems and observe their response over time. Specific blocks like integrators, gains, constants, and scopes are introduced. The document also explains how Simulink models can interface with MATLAB for parameter initialization and response plotting. As an example, it describes using Simulink to model a mass-spring-damper system and observe its dynamic behavior.

Uploaded by

Faiza Jamil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

2-Introduction To Simulink

This document provides an introduction to using Simulink to model and simulate dynamic systems. It discusses how Simulink allows users to create block diagram models of systems and observe their response over time. Specific blocks like integrators, gains, constants, and scopes are introduced. The document also explains how Simulink models can interface with MATLAB for parameter initialization and response plotting. As an example, it describes using Simulink to model a mass-spring-damper system and observe its dynamic behavior.

Uploaded by

Faiza Jamil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

_________________________________________________________________________

SUBJECT : CONTROL SYSTEMS LAB


SUBJECT CODE :
LAB NO : 02

TITLE : INTRODUCTION TO SIMULINK


THROUGH IMPLEMENTATION OF
MASS SPRING DAMPER DYNAMIC

SUBMITTED TO :
SEMESTER :
SECTION :

________________________________________________________________________
Experiment # 02 Page 1 of 13
Control Systems Lab
_________________________________________________________________________

Title: IMPLEMENTATION OF DYNAMIC SYSTEMS (Mass Spring


Damper) IN SIMULINK
 Mathematical Modeling of Physical Systems
 Implementation in Simulink
During this course a sequence of experiments treating the step-by-step design and test
procedures for typical classical controllers will be performed. Here we encounter a valuable
tool: simulation. Simulation is a means of predicting the quantitative and qualitative
behavior of a physical system by using a mathematical model of the system. Often it is
impractical to design a controller for a specific piece of equipment without careful
preliminary testing. For example, an incorrectly designed process controller for a paper or
chemical manufacturing plant could result in a cost of millions in damage. A faulty auto-
pilot for a commercial aircraft could likewise cost in money as well as lives. Therefore,
with the exception of simple isolated systems, we seldom design and test controllers on
systems directly. Rather, a mathematical model of a dynamic system is constructed, and
then somehow simulated.
That is, the system’s time response is predicted for arbitrary inputs. For many cases the
simulation phase can be done by means of digital computers, particularly when high
numerical accuracy is required. We will be using Simulink: a simulation package that
operates inside of Matlab. With Simulink, a model of the system is first defined in block-
diagram form, and then it is analyzed by injecting signals and observing the outcome.

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.

SUM (Math library)


A dialog box obtained by double-clicking on the SUM block performs the configuration of
the Sum block, allowing any number of inputs and the sign of each. The sum block can be
represented in two ways in Simulink, by a circle or by a rectangle. Both choices are shown

Figure 1: Two Simulink blocks for a summer representing y = x1+ x2 – x3

________________________________________________________________________
Experiment # 02 Page 3 of 13
Control Systems Lab
_________________________________________________________________________

GAIN (Math library)


A gain block is shown by a triangular symbol, with the gain expression written inside if it
will fit. If not, the symbol - k - is used. The value used in each gain block is established in
a dialog box that appears if the user double-clicks on its block.

Figure 2: Simulink block for a gain of K.

INTEGRATOR (Continuous library)


The block for an integrator as shown below looks unusual. The quantity 1/s comes from
the Laplace transform expression for integration. When double-clicked on the symbol for
an integrator, a dialog box appears allowing the initial condition for that integrator to be
specified. Initial conditions may be specific numerical values, literal variables, or algebraic
expressions.

Figure 3: Simulink block for an integrator.

CONSTANTS (Source library)


Constants are created by the Constant block, which closely resembles Figure 4. Double-
clicking on the symbol opens a dialog box to establish the constant’s value. It can be a
number or an algebraic expression using constants whose values are defined in the
workspace and are therefore known to MATLAB.

Figure 4: A constant block


________________________________________________________________________
Experiment # 02 Page 4 of 13
Control Systems Lab
_________________________________________________________________________

STEP (Source library)


A Simulink block is provided for a Step input, a signal that changes (usually from zero) to
a specified new, constant level at a specified time. These levels and time can be specified
through the dialog box, obtained by double-clicking on the Step block.

Figure 5: A step block

SIGNAL GENERATOR (Source library)


One source of repetitive signals in Simulink is called the Signal Generator. Double-clicking
on the Signal Generator block opens a dialog box, where a sine wave, a square wave, a
ramp (sawtooth), or a random waveform can be chosen. In addition, the amplitude and
frequency of the signal may be specified. The signals produced have a mean value of zero.
The repetition frequency can be given in Hertz (Hz), which is the same as cycles per
second, or in radians/second.

Figure 6: A signal generator block

SCOPE (Sinks library)


The system response can be examined graphically, as the simulation runs, using the Scope
block in the sinks library. This name is derived from the electronic instrument,
oscilloscope, which performs a similar function with electronic signals. Any of the
variables in a Simulink diagram can be connected to the Scope block, and when the
simulation is started, that variable is displayed. It is possible to include several Scope
blocks. Also it is possible to display several signals in the same scope block using a MUX
block in the signals routing library. The Scope normally chooses its scales automatically
to best display the data.

________________________________________________________________________
Experiment # 02 Page 5 of 13
Control Systems Lab
_________________________________________________________________________

Figure 7: A scope block with MUX block

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.

CLOCK (Sources library)


The clock produces the variable “time” that is associated with the integrators as MATLAB
calculates a numerical (digital) solution to a model of a continuous system. The result is a
string of sample values of each of the output variables. These samples are not necessarily
at uniform time increments, so it is necessary to have the variable “time” that contains the
time corresponding to each sample point. Then MATLAB can make plots versus “time.”
The clock output could be given any arbitrary name; we use “t” in most of the cases.

Figure 8: A clock block

To Workspace (Sinks library)


The To Workspace block is used to return the results of a simulation to the MATLAB
workspace, where they can be analyzed and/or plotted. Any variable in a Simulink diagram
can be connected to a ToWorkspace block. In our exercises, all of the state variables and
the input variables are usually returned to the workspace. In addition, the result of any
output equation that may be simulated would usually be sent to the workspace. In the block
parameters drop down window, change the save format to ‘array’.

Figure 9: A To Workspace block

________________________________________________________________________
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.

MASS SPRING DAMPER SYSTEM EXAMPLE

In class we have learned how to model different physical systems. Consider the mass spring
damper system shown in Figure 10.

Figure 10: Mass, spring, damper system

The equation of motion describing the systems can be written as

𝑚𝑥̈ = 𝑢(𝑡) − 𝑏𝑥̇ − 𝑘𝑥

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

10𝑥̈ = 𝑢(𝑡) − 2𝑥̇ − 5𝑥

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
_________________________________________________________________________

Figure 11: Block Diagram

 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’)

Questions for Lab Report


Task 1:
Consider the following mass-spring damper

a. Model the system.


b. Solve the equation obtained in part (a) in SIMULINK and obtain the position
response with a unit step input for 0 ≤ 𝑡 ≤ 50 𝑠.

Task 2:
Consider the following mass-spring damper

________________________________________________________________________
Experiment # 02 Page 12 of 13
Control Systems Lab
_________________________________________________________________________

Initial Conditions: 𝑥1 (0) = 𝑥2 (0) = 𝑥̇ 1 (0) = 𝑥̇ 2 (0) = 0


𝑁
𝑚1 = 𝑚2 = ( + 1) 𝑘𝑔
100
𝑘1 = 7.5 𝑁𝑚−1
𝑘2 = 35 𝑁𝑚−1
𝑁
𝑏=( + 0.6) 𝑁𝑠𝑚−1
100

where 𝑁 is the mean/average of the last two digits of the registration number of the
individual student.

a. Model the system.


b. Implement the system in SIMULINK with unit step input at 𝑡 = 0 and obtain
graphs for 𝑥1 and 𝑥2 with time separately (0 ≤ 𝑡 ≤ 20).

________________________________________________________________________
Experiment # 02 Page 13 of 13
Control Systems Lab

You might also like