Building a 2nd Order system
A 2nd order system in Simulink can be built in 2 ways:
1. Using the available transfer function Block from the Simulink Library
2. Using the concept of simulation diagram to draw our block diagram.
1. Using the Transfer Function Block
Model to be implemented in this exercise is shown in the diagram below. The
1
transfer function taken here is in the form of 𝐺(𝑠) = 2
𝑠 +2𝑠+9
• From the directory of tools select the following:
▪ From Directory
Select Items
▪ Sources
Step, Clock
▪ Continuous
Transfer Function
▪ Sinks
Scope, To Workspace (Output and Time)
• Step Input. Double click on Step function block and a window will appear
as in Figure, to set the parameters for the step function that will be applied to
the input of the system under test. Set the
following parameters: Step time= 0; Initial value=0; Final value=1; Sample
time=0.
• Setup Transfer Function. Double click on the transfer function block and
the window will open as in Figure. Enter the coefficients in the order of the
highest exponent to the lowest that is [1 2 9]. Since our transfer function is:
1
𝐺(𝑠) = 2
𝑠 + 2𝑠 + 9
• Output To Workspace Block Parameter Settings. The “To Workspace”
blocks will each create an array in the MATLAB workspace with the name that
you specify in the appropriate parameter block. This allows you to plot using
MATLAB’s extensive plotting capabilities (Simulink’s plotting capabilities are
somewhat limited) and to use MATLAB routines to analyze and manipulate the
data resulting from the simulation. Double click on one of the “To Workspace”
blocks to open the parameter window as in Figure, and give it an appropriate
name, such as Output or Time. The Save format needs to be set to Array. Use
the default parameters for the remaining items in the windows. Do this for each
of the two blocks in your model.
• Setup Simulation Parameters. Select from top menu, Simulation
>Simulation parameters to get the window shown in Figure below. Under the
solver tab, set Start Time=0.0, Stop Time= 10.0. Solver Options: This sets the
numerical integration or differential equation solution parameters. Set type=
Variable Step; ode45 (Dormand- Prince); use default settings for all other
parameters. If the result appears somewhat edgy in the scope, we can improve
the result by decreasing the Max Step Size to any desirable value from the predefined auto.
• Simulation Results: The results obtained in scope can also be replicated in
the MATLAB’s workspace, since when we run our Simulink program, we
store two variables Output and Time in MATLAB’s workspace. The
corresponding plot command in MATLAB is: plot (Time, Output)
Fig. Plotting in Scope
Fig. Plotting in MATLAB’s Workspace
2. Using Simulation Diagram
In this exercise, we will solve a simple Spring-Mass system as given below in
the diagram by drawing its simulation diagram.
Taking Laplace of the above equation of motion , with the additional
information that all the initial conditions are zero ,we will get the transfer
function below:
𝐺(𝑠) =
1
𝑋(𝑠)
=
(𝑀𝑠 2 + 𝑏𝑠 + 𝑘) 𝐹(𝑠)
Here, the problem if converted to state space equations, would have state
variables as x1=x and x2=d(x1)/dt. So, corresponding state space equations for
this problem would be,
Now, since our no. of state variables are 2, we create two integration blocks in
Simulink as shown below,
Fig. The names beside the blocks can be
created with the help of annotations.
The block for x2 has initial condition as
“v0” variable and the block for x1 has
initial condition as “x0” variable.
The initial conditions are set by double
clicking the blocks
Having done that, we then move to the 2nd equation of motion and branch both
the x1 and x2 branches to create b*x2 and k*x1, by using Gain Blocks in math
operations from the Simulink Library as shown in the figure below,
Fig. The gain blocks will have
variables “K” and “c” as gains which
will be imported from a MATLAB
file.
• As, we can see from the 2nd equation, all the terms sum up to become
d(x2)/dt.
So, we choose Add Block, from Math Operations from the Simulink library and
then double click on the Add Block, and change the list of signs to +-- .
Then, we connect the branches of our diagram correspondingly as shown in the
figure below,
• Finally, we add a Gain block of gain (1/M), “M” being a variable, and a sine
wave block with frequency as “w” and amplitude as “F0”.
• A scope is also added to the branch of x1 to show the output graph.
The resulting simulation diagram obtained is:
Fig. The red colour
around the boxes
disappear once we
load the values of
variables from our
MATLAB file
• Save the Simulink file with the desired name, let’s say “SImulink1.slx”
• Now, open a new MATLAB file in the same folder where our Simulink file
is saved and assign the values to the variables inside the Simulink block
diagram and then finally make a call to the corresponding Simulink file as
shown in the figure below.
• Simulation Results:
When we Run the MATLAB file, the corresponding values for the variables
gets uploaded to our Simulink file. Then, running our Simulink file produces the
output as shown below.
Fig. Configuration
Parameter settings:
Max Step Size: 0.05
Start Time: 0
Stop Time: 100