Professional Documents
Culture Documents
2
4
6
3
Figure 1: The main window in MATLAB with labels for each partition.
Where;
1. Menu bar: This is where you can save, undo, create new script or function, etc.
2. Current folder: The directory where your MATLAB files (.m) or Simulink files
(.mdl) is saved or opened for the current session.
1
MEC522/FKM-UiTM/OCT2014
3. Details: A description of your file will be displayed here (when the individual file in
the current folder partition is highlighted).
4. Command window: This part will display the operation(s) performed by MATLAB,
including matrices, calculations, errors, warnings, etc. You can also define variables
and type some commands here, which is effective only for the current session.
5. Workspace: This space shows the stored data/variables defined in the current session.
They can be saved as well as imported.
6. Command history: As the name suggests, it displays the commands ran at previous
sessions. Useful in recalling the commands used previously. They can be deleted to
save some clutter when no longer required.
Creating and Running a Script
In the menu bar, click the New script (Ctrl+N) icon or File > New > Script. A new window
should pop-up:
MEC522/FKM-UiTM/OCT2014
2. Text editor: This is where you define all variables and type all commands to be used
(programming). The file must be saved before it can be run.
3. Text checker: Fully automated, it checks for any error real-time as you move on to
type a new line.
In order to run a script, look for the green Save and run (F5) icon in the editor menu bar
and click it. Alternatively, you can also click Debug > Save File and Run.
Example 1: Obtaining Cascaded, Parallel and Feedback (Closed-loop) Transfer
Functions [1]
Consider the following transfer functions:
G1 ( s)
10
num1
,
s 2s 10 den1
2
G2 ( s)
5
num 2
s 5 den 2
Figure 3: (a) cascaded/series, (b) parallel and (c) feedback (closed-loop) systems.
MEC522/FKM-UiTM/OCT2014
50
s 7 s 20s 50
3
5s 2 20s 100
(b) G( s) 3
s 7 s 2 20s 50
(c) G( s)
10s 50
s 7 s 2 20s 100
3
Note that the command printsys(num,den) displays the transfer function (num/den) of
the system considered.
MEC522/FKM-UiTM/OCT2014
2
U (s) ( s 10)(s 4s 16)
s
3
2
s 14s 56s 160
MEC522/FKM-UiTM/OCT2014
MATLAB will produce the matrices A, B, C and D (look in the command window):
14 56 160
A 1
0
0
0
1
0
1
B0
0
C0 1 0
D0
The state-space representation can then be written as follows:
x1 14 56 160 x1 1
x 1
0
0 x2 0 u
2
x3 0
1
0 x3 0
x1
y 0 1 0 x2 0 u
x3
Note that the state-space representation for any system is not unique. There are infinitely
many state-space representations for the same system. The MATLAB command gives one
possible such state-space representation.
MEC522/FKM-UiTM/OCT2014
Y ( s)
25s 5
3
U (s) s 5s 2 25s 5
Note that the percentage symbol % is used to insert comments/explanations. MATLAB will
ignore the line(s) that begins with such symbol.
The semicolon ; at the end of each line is used to suppress output in the command window.
7
MEC522/FKM-UiTM/OCT2014
MEC522/FKM-UiTM/OCT2014
2. Library tree: Libraries available for use is listed here, where they are further divided
into subcategories when expanded.
3. Graphical display: Simulink blocks available for use are displayed here as a
subcategory (any) is selected.
The main elements used in MATLAB/Simulink are blocks and lines. Blocks have the
function to generate, modify, combine, output and display signals [3]. Lines on the other
hand, are simply used to transfer signals from one block to another [3].
Creating and Simulating a Model
In the Library Browser menu bar, click the New model icon or File > New > Model. A
new window will open:
MEC522/FKM-UiTM/OCT2014
Figure 10: Multiplied sinusoidal waves generated by the model after auto-scaled.
10
MEC522/FKM-UiTM/OCT2014
You might need to click the Autoscale button (a black pair of binoculars icon) in the scope
window to get the exact scale as Figure 10.
For comparison purposes, you would want to add another scope to the system:
Figure 11: The same Simulink model with another scope added.
You can now compare between the original signal and the multiplied one by viewing both
Scope and Scope1 side by side.
Modify the gain and see what happens. Remember to re-run the simulation each time you
modify the gain value.
Note that the functions of each block are explained in its properties. Double-click (or Rightclick > Gain parameters) the block to edit its properties.
11
MEC522/FKM-UiTM/OCT2014
body mass
2500 kg
suspension mass
320 kg
spring constant of suspension system
80,000 N/m
spring constant of wheel and tire
500,000 N/m
damping constant of suspension system
350 N.s/m
damping constant of wheel and tire
15,020 N.s/m
control force = force from the controller we are going to design
The following statement describes the design requirements for this particular system:
A good automotive suspension system should have satisfactory road holding
ability, while still providing comfort when riding over bumps and holes in
the road. When the vehicle is experiencing any road disturbance (i.e. pot
holes, cracks, and uneven pavement), the vehicle body should not have large
oscillations, and the oscillations should dissipate quickly. Since the
distance X1-W is very difficult to measure, and the deformation of the tire
(X2-W) is negligible, we will use the distance X1-X2 instead of X1-W as the
output in our problem. Keep in mind that this is an estimation.
The road disturbance (W) in this problem will be simulated by a step input.
This step could represent the vehicle coming out of a pothole. We want to
design a feedback controller so that the output (X1-X2) has an overshoot
less than 5% and a settling time shorter than 5 seconds. For example, when
the vehicle runs onto a 10 cm high step, the vehicle body will oscillate
within a range of +/- 5 mm and return to a smooth ride within 5 seconds.
12
MEC522/FKM-UiTM/OCT2014
Create a script that defines the system parameters, i.e. m1, m2, k1, k2, b1 and b2. We will
be using this (saved) script in order to run the simulation.
The integrals of the masses accelerations will be modelled first:
d 2 x1
dx
dt 2 dt dt1 dt x1
d 2 x2
dx
dt 2 dt dt2 dt x2
Insert the Integrator blocks (drag them from the Library Browser or Right-click > Add to
untitled) in the modelling space (new model) as follows:
d 2 x1
1
F
M1 1
dt 2
1
M2
2 F
d 2 x2
dt 2
13
MEC522/FKM-UiTM/OCT2014
Insert two Gain blocks and two Sum blocks to represent the equations:
14
MEC522/FKM-UiTM/OCT2014
We will now model the forces acting on each mass, starting with the first spring (k1). Its
force is equal to k1(X1-X2) refer Figure 12.
Insert a Sum block to connect the x1 and x2 signals. Remember to change the signs to
+- beforehand:
Figure 15: Simulink suspension model with the first spring added.
Insert a Gain block and edit its value to k1. Also, label this block as Spring 1.
To flip a block: Right-click > Format > Flip Block.
Connect the input and output of the Spring 1 block exactly as shown in Figure 15.
15
MEC522/FKM-UiTM/OCT2014
Next is the suspensions damper b1. Its force is equal to b1(V1-V2) refer Figure 12.
First, insert a Sum block as shown in the figure below:
Figure 16: Simulink suspension model with the first damper added.
Flip the Sum block left-to right after labelling it Sum5. Its signs should also be +-.
The input for Sum5 block is tapped from v1 (positive sign) and v2 (negative sign) line.
This is achieved by dragging a line from the input of Sum 5 block to the respective v1
and v2 lines.
Insert a Gain block and edit its value to b1. Also, label this block as Damper 1 and flip
it left-to-right.
Connect the input and output of the Damper 1 block exactly as shown in Figure 16.
16
MEC522/FKM-UiTM/OCT2014
The force from the second spring (k2) will now be added. Its force is equal to X2-W (refer
Figure 12).
Insert a Step block (a type of sources) and label it W as follows:
Figure 17: Simulink suspension model with the second spring added.
For the W block, change the value of the Step time and Final value to zero. This is to
assume that the road is flat.
Insert yet another Sum block and label it Sum3. Connect its input as shown in Figure 17.
The output of Sum3 block connects to another Gain block. This block should have k2
as the value and labelled Spring 2.
Proceed to connect the Spring 2 block to the fourth (positive sign) input of Sum1 block.
17
MEC522/FKM-UiTM/OCT2014
It is now time to add the second damper b2 to the model. Based on Figure 12, this damper
has a force of b2(dW/dt).
Locate a derivative block in the Library Browser and insert it as in the figure below:
18
MEC522/FKM-UiTM/OCT2014
19
MEC522/FKM-UiTM/OCT2014
Double-click the Scope block and the following graph should open up:
20
MEC522/FKM-UiTM/OCT2014
References
[1]
[2]
O. Hinton, Chapter 5: Introduction to Simulink, class notes for EEE 305, School
of Electrical, Electronic and Computer Engineering, University of Newcastle Upon
Tyne, August 1, 2002.
[3]
R. D. M., Simulink Basics Tutorial, class notes for EECS 401, Department of
Electrical Engineering and Computer Science, University of Michigan, May 18,
2000.
[4]
21