You are on page 1of 14

LABORATORY

FACULTY OF MANUFACTURING ENGINEERING


UNIVERSITI TEKNIKAL MALAYSIA MELAKA

INSTRUMENTATION & CONTROL

DMFD 2433 SEMESTER 2 SESSION 2022/2023

LO3: Demonstrate control system with the aid of MATLAB software

PO3: The skill of engineering and management which are based on practice and application
oriented

LABORATORY TASK 1
PART 1: INTRODUCTION TO MATLAB

1. OBJECTIVES

At the end of the experiment, students should be able to


1) Use MATLAB’s Control System Toolbox
2) Analyze control systems problems

2. INTRODUCTION

Before you begin the next sections, it would be a good idea to run the MATLAB Control
System Toolbox demo. This is done by typing “demo(’toolbox’,’control’)” at the
MATLAB prompt. Aside from the basic MATLAB plotting commands, you should
become familiar with the following commands:

 tf (transfer function)– This command is used to enter transfer functions. For example,
s2
to enter the transfer function H ( s)  2 you would type “H=tf([1 2],[1 0 5])”.
s 5
The first parameter is a row vector of the numerator coefficients. Similarly, the
second parameter is a row vector of the denominator coefficients.

 series or * – This command is used to combine two transfer functions that are in
series.
For example, if H(s) and G(s) are in series, they could be combined with the
command “T=G*H” or “T=series(G,H)”.

 feedback – This command is used to combine two transfer functions that are in
feedback.
For example, if G(s) is in the forward path and H(s) is in the feedback path, they
could be combined with the command “T=feedback(G,H)”.
1
 step – This command is used to plot the step response of a system. For example,
“step(T)” would plot the step response of the system T (s).

3. PROCEDURES

3.1 Open the MATLAB’s icon from the Desktop.


3.2 Select Home > New Script
3.3 Write down the codes from Exercise#1.

Example #1: Display the required task


Bit strings will be used to identify parts of this tutorial on the computer output. Bit strings
are represented by the text enclosed in apostrophes, such as 'ab'. Comments begin with %
and are ignored by MATLAB. Numbers are entered without any other characters.
Arithmetic can be performed using the proper arithmetic operator. Numbers can be
assigned using a left-hand argument and an equal sign.

'Ex1' % Display label.


'How are you?' % Display string.
-3.96 % Display scalar number -3.96.
-4+7i % Display complex number -4+7i.
-5-6j % Display complex number -5-6i.
(-4+7i)+(-5-6i) % Add two complex numbers and display sum.
(-4+7j)*(-5-6j) % Multiply two complex numbers and display product.
M=5 % Assign 5 to M and display.
N=6 % Assign 6 to N and display.
P=M+N % Assign M+N to P and display.

3.4 Select File > Save As. Save the file as Lab1Ex1.
3.5 Select Editor > Run to run the program.
3.6 Repeat above steps for the following exercises and save files appropriately.

Example #2: Display a polynomial


Polynomials in s can be represented as row vectors containing the coefficients. Thus
P1 = s3 + 7s2 -3s + 23 can be represented by the vector shown below with elements
separated by a space or comma. Bit strings can be used to identify each section of this
tutorial.

'Ex2' % Display label.


P1=[1 7 -3 23] % Store polynomial s^3 + 7s^2 -3s + 23 as P1 and display.

Example #3: Assign and Display


Running the previous statements causes MATLAB to display the results. Ending the
command with a semicolon suppresses the display. Typing an expression without a left-
hand assignment and without a semicolon causes the expression to be evaluated and the
result displayed. Enter P2 in the MATLAB
Command Window after execution.

'Ex3' % Display label.


P2=[3 5 7 8]; % Assign 3s^3 + 5s^2 +7s + 8 to P2 without displaying.
3*5 % Evaluate 3*5 and display result.

2
Example #4: Display coefficient of a polynomial
An F(s) in factored form can be represented in polynomial form. Thus P3 =
(s+2)(s+5)(s+6) can be transformed into a polynomial using poly(V), where V is a row
vector containing the roots of the polynomial and poly(V) forms the coefficients of the
polynomial.

'Ex4' % Display label.


P3=poly([-2 -5 -6]) % Store polynomial (s+2)(s+5)(s+6) as P3 and display the
coefficients

Example #5: Display Roots of a polynomial


We can find roots of polynomials using the roots(V) command. The roots are returned as
a column vector. For example, find the roots of 5s4+7s3+9s2-3s+2 = 0.

'Ex5' % Display label.


P4=[5 7 9 -3 2] % Form 5s^4+7s^3+9s^2-3s+2 and display.
rootsP4=roots(P4) % Find roots of 5s^4+7s^3+9s^2-3s+2, assign to roots P4, and
display.

Example #6: Multiply polynomial


Polynomials can be multiplied together using the conv(a,b) command (standing for
convolve). Thus, P5=(s3+7s2+10s+9)(s4-3s3+6s2+2s+1) is generated as follows:

'Ex 6' % Display label.


P5=conv([1 7 10 9],[1 -3 6 2 1]) % Form (s^3+7s^2+10s+9)(s^4-
3s^3+6s^2+2s+1), assign to P5, % and display.

Example #7: Vector Method

Vector Method, Polynomial Form:

A transfer function can be expressed as a numerator polynomial divided by a denominator


polynomial, i.e. F(s) = N(s)/D(s). The numerator, N(s), is represented by a row vector,
numf, that contains the coefficients of N(s). Similarly, the denominator, D(s), is
represented by a row vector, denf, that contains the coefficients of D(s). We form F(s)
with the command, F = tf(numf,denf). F is called a linear time-invariant (LTI) object.
This object, or transfer function, can be used as an entity in other operations, such as
addition or multiplication. We demonstrate with F(s) = 150(s2+2s+7)/[s(s2+5s+4)].
Notice after executing the tf command, MATLAB prints the transfer function.

3
'Ex7:Vector Method, Polynomial Form' % Display label.
numf=150*[1 2 7] % Store 150(s^2+2s+7) in numf and display.
denf=[1 5 4 0] % Store s(s+1)(s+4) in denf and display.
'F(s)' % Display label.
F=tf(numf,denf) % Form F(s) and display.
clear

Vector Method, Factored Form:

We also can create LTI transfer functions if the numerator and denominator are expressed
in factored form. We do this by using row vectors containing the roots of the numerator
and denominator. Thus G(s) = K*N(s)/D(s) can be expressed as an LTI object using the
command, G = zpk(numg,deng,K), where numg is a row vector containing the roots of
N(s) and deng is a row vector containing the roots of D(s). The expression zpk stands for
zeros (roots of the numerator), poles (roots of the denominator), and gain, K. We
demonstrate with G(s) = 20(s+2)(s+4)/[(s+7)(s+8)(s+9)]. Notice after executing the zpk
command, MATLAB prints the transfer function.

'Vector Method, Factored Form' % Display label.


numg=[-2 -4] % Store (s+2)(s+4) in numg and display.
deng=[-7 -8 -9] % Store (s+7)(s+8)(s+9) in deng and display.
K=20 % Define K.
'G(s)' % Display label.
G=zpk(numg,deng,K) % Form G(s) and display.
clear % Clear previous variables from workspace.

Example #7: Connected block diagram

Assume that G1(s) and G2(s) are as follows:

To obtain the transfer function of cascaded system, parallel system or feedback (closed
loop) system, following commands are used:

'Ex 7'
num1 = [10];
den1 = [1 2 10];
num2 = [5];
den2 = [1 5];
[num, den] = series(num1, den1, num2, den2);
printsys(num,den)
-----------------------------
[num,den] = parallel (num1, den1, num2, den2);
printsys(num,den)
-----------------------------
[num,den]= feedback (num1, den1, num2, den2);
printsys(num,den)
4
4. DISCUSSION

Consider the following system:

C (s)
Find T ( s )  . Using MATLAB, verify your result of the closed-loop transfer
R(s)
function. Show the MATLAB commands required to calculate T (s). Make use of the
commands tf, conv, and feedback.

5. CONCLUSION

List out what you have learned from this experiment.

6. REFERENCES

[1] Nise, Norman S., Control Systems Engineering, 4rd editions, John Wiley, 2000.
ISBN: 0471366013
[2] Dorf, R.C. & Bishop, R.H. Modern Control Systems, Addison Wesley (1995)
(7th. Edn,) ISBN: 0201845598
[3] Using Simulink Version 6
[4] Using MATLAB Version 6

5
LABORATORY TASK 1
PART 2: INTRODUCTION TO SIMULINK

1. OBJECTIVES

At the end of the experiments, students should be able to:


1) Build simulation models using Simulink Version 6.0.
2) Model, simulate and analyze dynamic systems.
3) Obtain a system step response from Simulink’s simulation.

2. INTRODUCTION

Simulink is a software package that integrated with MATLAB that enables us to model,
simulate and analyze systems whose outputs change over time (Dynamic Systems). Simulink
can be used to explore the behavior of a wide range of real-world dynamic systems, including
electrical circuits, shock absorbers, braking systems, and many other electrical, mechanical,
and thermodynamic systems.

3. THEORY

Simulating a dynamic system is a two-step process with Simulink:

1) First, a graphical model of the dynamic system is created by using the Simulink’s
model editor. The model depicts the time-dependent mathematical relationships
among the system's inputs, states, and outputs.

2) Then, Simulink is used to simulate the behavior of the system over a specified time
span. Simulink uses information that has been entered into the model to perform the
simulation.

Simulink provides a library browser that allows you to select blocks from libraries of
standard blocks and a graphical editor that allows you to model virtually any real-world
dynamic system by selecting and interconnecting the appropriate Simulink blocks.

4. TOOL / EQUIPMENT

I) PC
2) MATLAB Simulink Version 4.0

6
5. PROCEDURES

Exercise

Build a simple model that integrates a sine wave and displays the result in Simulink.

Please follow the steps below to build a model as shown in Figure 1 above.

STEP 1
Type Simulink in the MATLAB command window. Simulink Library Browser will appear
as shown in Figure 2.

STEP2
Create a new model by selecting Blank Model button on the Simulink start page as shown in
Fig 1.

Fig. 1 Fig 2

Simulink opens a new model window as shown in Fig. 2. Open the Simulink library browser
by clicking the library browser icon.

STEP 3
To create the model, you will need to copy blocks into the model window from the following
Simulink block libraries:
 Sources library (the Sine Wave block)
 Sinks library (the Scope block)
 Continuous library (the Integrator block)
7
 Signals Routing library (the Mux block)

You can copy a Sine Wave block from the Sources library, using the Library Browser.

Method 1 - To copy the Sine Wave block from the Library Browser, first expand the Library
Browser tree to display the blocks in the Sources library. Do this by clicking on the Sources
node to display the Sources library blocks. Finally click on the Sine Wave node to select the
Sine Wave block. Figure 4 is how the Library Browser should look after you have done this.

Fig. 4

STEP 5

Now click and drag the Sine Wave block from the browser and drop it in the model window.
Simulink creates a copy of the Sine Wave block at the point where you dropped the node icon
as in Figure 5.

Method 2 - To copy the Sine Wave block from the Sources library window, open the Sources
window by double-clicking on the Sources icon in the Simulink library window. (On

8
Windows, you can open the Simulink library window by right-clicking the Simulink node in
the Library Browser and then clicking the resulting Open Library button.)

Simulink displays the Sources library window as in Figure 6.

STEP 6
Now click and drag the Sine Wave block from the Sources window to your model window as
in Figure 5. (Note: If you need to copy any existing blocks from the model window, just press
right click on you mouse button, hold the click and drag it to the required position or
location).

STEP 7
Copy the rest of the blocks in a similar manner from their respective libraries into the model
window. You can move a block from one place in the model window to another by dragging
the block. You can move a block a short distance by selecting the block, then pressing the
arrow keys. With all the blocks copied into the model window, the model should looks
something like Figure 7 below.

If you examine the block icons, you see an angle bracket on the right of the Sine Wave block
and two on the left of the Mux block. The > symbol pointing out of a block is an output port;
if the symbol points to a block, it is an input port. A signal travels out of an output port and

9
into an input port of another block through a connecting line. When the blocks are connected,
the port symbols disappear.

STEP 8
Connect the Sine Wave block to the top input port of the Mux block. Position the pointer over
the output port on the right side of the Sine Wave block. Notice that the cursor shape changes
to crosshairs as shown in Figure 8 below.

Hold down the left mouse button and move the cursor to the top input port of the Mux block.
Notice that the line is dashed while the mouse button is pressed and the cursor shape changes
to double-lined crosshairs as it approaches the Mux block as shown in Figure 9.

Now release the mouse button. The blocks are connected as shown in Figure 10. You can also
connect the line to the block by releasing the mouse button while the pointer is inside the
icon. If you do, the line is connected to the input port closest to the cursor's position.

STEP 9
If you look again at the model at the beginning of this section (see Figure 1), you will notice
that, most of the lines connect output ports of blocks to input ports of other blocks. Also, a
line could connect to another line. This line, called a branch line, connects the line Wave
output to the Integrator block, and carries the same signal that passes from the Sine Wave
Lock to the Mux block.

Drawing a branch line is slightly different from drawing the line you just drew. To create a
connection to an existing line, follow the following steps:

10
i) First, position the pointer on the line between the Sine Wave and the Mux block as
shown in Figure 11.

ii) Press and hold down the Ctrl key (or click the right mouse button). Press the mouse
button, then drag the pointer to the Integrator block's input port or over the Integrator
block itself as shown in Figure 12.

iii) Release the mouse button. Simulink draws a line to the Integrator block's input port as
shown in Figure 13.

iv) Complete the other lines so that your model looks as in Figure 14.

STEP 10
Now, open the Scope block by double-click the block to view the simulation output. Keeping
the Scope window opens, set up Simulink to run the simulation for 10 seconds. First, set the
simulation parameters by changing the Stop time to 10.0 as shown in Fig 15.

11
Fig. 15

STEP 11
Close the Simulation. Parameters dialog box by clicking on the OK button.

Choose Start from the Simulation menu and watch the traces of the Scope block's input as in
Figure 16.

Click on the binocular symbol (Auto scale) for graph automatic scaling. Figure 17 will appear
(ignore the format of window's appearance).

12
The simulation stops when it reaches the stop time specified in the Simulation Parameters
dialog box or when you choose Stop from the Simulation menu or press the Stop button on
the model window's) toolbar (Windows only).

STEP 12
To save this model, choose Save from the File menu and enter a filename and location. That
file contains the description of the model.

STEP 13
To terminate Simulink and MATLAB, choose Exit MATLAB or type quit in the MATLAB
command window. If you want to leave Simulink but do not want to terminate MATLAB,
just close all Simulink windows.

SIMULATION RESULTS

1. Obtain the output amplitude values of the original Sine Wave and its integratio
respectively.
2. Set the simulation stop time parameter to 20 seconds. Record the results.
3. Set the amplitude of Sine Wave to 5. Record the results.

13
ACTIVITY

Obtain the system step response by using Simulink.

1 1
14.145
s2 +1.204s+2.829 s+5
Step Scope
Gain Transfer Fcn Transfer Fcn1

Figure 18

STEPS

1) By using Simulink, build a model as shown in Figure 18 above.

2) Simulate the model and record your results.

6.0 DISCUSSION

SlMULATION RESULT

1. Set the simulation stop time parameter to 20 seconds. Record the results.

2. Set the source to Sine Wave. Record the results.

7.0 CONCLUSION

List out what you have learned from this experiment.

10.0 REFERENCES

[1] Nise, Norman S., Control Systems Engineering, 4rd editions, John Wiley, 2000.
ISBN: 0471366013

[2] Dorf, R.C. & Bishop, R.H. Modern Control Systems, Addison Wesley (1995) (7th.
Edn,) ISBN: 0201845598

14

You might also like