You are on page 1of 109

Information Technology University

Department of Electrical Engineering

Control Systems Lab

Lab Manual

Created by: Mr. Yasir Manzoor


Date: January 28, 2017

Reviewed & Approved by: Mr. Usama Bin Sikandar


Contents
LIST OF FIGURES ........................................................................................................................................................... 5
LIST OF TABLES ............................................................................................................................................................. 7
STUDENT LEARNING OUTCOMES .................................................................................................................................. 8
GRADING CRITERIA ....................................................................................................................................................... 9
SOFTWARE RESOURCES ...............................................................................................................................................10
LAB-1 SYSTEM MODELING USING SIMULINK .........................................................................................................11
1.1 OBJECTIVE ............................................................................................................................................................ 12
1.2 INTRODUCTION TO SIMULINK .................................................................................................................................... 12
1.3 INTRODUCTION TO SOLVERS ..................................................................................................................................... 12
1.4 SYSTEM MODELING EXAMPLE .................................................................................................................................... 13
1.4.1 Steps to implement differential equaitons in Simulink.................................................................................. 14
1.5 EXERCISE # 1 ......................................................................................................................................................... 15
1.5.1 Task 1 ............................................................................................................................................................ 15
1.5.2 Task 2 ............................................................................................................................................................ 16
1.5.3 Task 3 ............................................................................................................................................................ 16
1.5.4 Task 4 ............................................................................................................................................................ 16
1.5.5 Task 5 ............................................................................................................................................................ 17
1.6 EXERCISE # 2 ......................................................................................................................................................... 18
1.6.1 Task 5 ............................................................................................................................................................ 19
1.6.2 Task 6 ............................................................................................................................................................ 19
1.6.3 Task 7 ............................................................................................................................................................ 19
LAB-2 NUMERICAL SOLUTIONS OF ODES USING MATLAB ....................................................................................22
2.1 OBJECTIVE ............................................................................................................................................................ 22
2.2 EULER METHOD TO SOLVE FIRST ORDER ODE ............................................................................................................. 23
2.3 SOLVING ODE USING EULERS METHOD ..................................................................................................................... 23
2.3.1 First function file ........................................................................................................................................... 23
2.3.2 Second function file ....................................................................................................................................... 23
2.3.3 Executing Eulers Function ............................................................................................................................ 24
2.4 LAB EXERCISE ........................................................................................................................................................ 24
2.4.1 Newtons Law of Cooling............................................................................................................................... 24
2.4.2 Lab Task 1 ..................................................................................................................................................... 24
2.5 SOLVING ODE USING ODE 45 IN MATLAB ............................................................................................................... 25
2.5.1 First Order Equations using ODE 45 .............................................................................................................. 25
2.5.1.1 Example ................................................................................................................................................................. 25
2.5.1.2 Lab Task 2 .............................................................................................................................................................. 26
2.5.2 Second Order Equations ................................................................................................................................ 27
2.5.3 Lab Task 3 ..................................................................................................................................................... 27
2.5.4 Lab Task 3 ..................................................................................................................................................... 29
LAB-3 TRANSFER FUNCTION & STATE-SPACE REPRESENTATIONS..........................................................................30
3.1 OBJECTIVE ............................................................................................................................................................ 31
3.2 EQUIPMENT/APPARATUS......................................................................................................................................... 31
3.3 CONDUCT OF LAB ................................................................................................................................................... 31
3.4 THEORY OF TRANSFER FUNCTION AND STATE SPACE ..................................................................................................... 31
3.4.1 Example of Creating Transfer Function Models in MATLAB:......................................................................... 32
3.4.2 Example of PoleZero Map in MATLAB ......................................................................................................... 32
3.4.3 Statespace.................................................................................................................................................... 33

1|Page
3.4.4 State Space Representation using MATLAB .................................................................................................. 34
3.5 LAB EXERCISE ........................................................................................................................................................ 34
3.5.1 Task 1 ............................................................................................................................................................ 34
3.5.2 Task 2 ............................................................................................................................................................ 34
3.5.3 Task 3 ............................................................................................................................................................ 35
3.5.4 Task 4 ............................................................................................................................................................ 36
3.5.5 Task 5 ............................................................................................................................................................ 37
LAB-4 STEP AND IMPULSE RESPONSE OF SYSTEM .................................................................................................38
4.1 OBJECTIVE ............................................................................................................................................................ 39
4.2 EQUIPMENT/APPARATUS......................................................................................................................................... 39
4.3 THEORY BACKGROUND ............................................................................................................................................ 39
4.3.1 Unit impulse Response .................................................................................................................................. 39
4.3.1.1 Impulse response using MATLAB command .......................................................................................................... 39
4.3.1.2 Impulse response using Simulink ........................................................................................................................... 40
4.3.2 Step Response ............................................................................................................................................... 41
4.3.2.1 Step response using MATLAB command ............................................................................................................... 41
4.3.2.2 Step response using Simulink ................................................................................................................................ 41
4.3.3 Lab Task 1 ..................................................................................................................................................... 42
4.3.4 Relationship between unit step and unit impulse function ........................................................................... 44
4.3.5 Relationship between unit step and unit impulse response .......................................................................... 45
4.3.5.1 Lab Task 2 .............................................................................................................................................................. 45
4.3.6 Lab Task 3 ..................................................................................................................................................... 46
LAB-5 PERFORMANCE SPECIFICATIONS OF FIRST ORDER SYSTEM .........................................................................48
5.1 OBJECTIVE ............................................................................................................................................................ 49
5.2 EQUIPMENT/APPARATUS......................................................................................................................................... 49
5.3 THEORY OF FIRST ORDER SYSTEM .............................................................................................................................. 49
5.3.1 Time Constant ............................................................................................................................................... 49
5.3.2 System speed (exponential frequency).......................................................................................................... 49
5.3.3 Rise time ........................................................................................................................................................ 50
5.3.4 Settling time .................................................................................................................................................. 50
5.3.5 Lab Task 1 ..................................................................................................................................................... 50
5.3.6 Lab Task 2 ..................................................................................................................................................... 51
5.3.7 Lab Task 3 ..................................................................................................................................................... 53
5.3.8 Lab Task 4 ..................................................................................................................................................... 55
5.3.9 Lab Task 5 ..................................................................................................................................................... 55
LAB-6 PERFORMANCE SPECIFICATIONS OF SECOND ORDER SYSTEM ....................................................................57
6.1 OBJECTIVE ............................................................................................................................................................ 58
6.2 THEORY OF SECOND ORDER SYSTEM .......................................................................................................................... 58
6.2.1 Natural Frequency ( ) .............................................................................................................................. 59
6.2.2 Damping Ratio ( ) ........................................................................................................................................ 59
6.2.3 Task 1: Finding effect on system due to poles location ................................................................................. 59
6.2.4 Task 2: Spring mass system with damper ..................................................................................................... 61
6.3 FEEDBACK SYSTEM AND STABILITY.............................................................................................................................. 64
6.3.1 Negative Feed back ....................................................................................................................................... 64
6.3.2 Positive feed back ......................................................................................................................................... 64
6.3.3 Unity Feedback System ................................................................................................................................. 65
6.3.4 Lab Task 3 ..................................................................................................................................................... 65
LAB-7 STEADY STATE ERROR ANALYSIS OF SYSTEM ..............................................................................................68
7.1 OBJECTIVE ............................................................................................................................................................ 69

2|Page
7.2 TASKS 1 STEP RESPONSE AND STEADY STATE ERROR....................................................................................................... 69
7.3 TASK 2 EFFECT OF CONTROLLER ................................................................................................................................ 70
7.4 TASK 3 EFFECT OF DISTURBANCE AND UNITY FEEDBACK ................................................................................................. 71
7.5 TASK 4 UNITY FEEDBACK ......................................................................................................................................... 72
7.6 TASK 5 STEADY STATE ERROR CALCULATIONS............................................................................................................... 73
7.7 TASK 6 STEADY STATE ERROR USING MATLAB ........................................................................................................... 74
LAB-8 EFFECT OF CONTROLLERS ON SYSTEM PARAMETERS ..................................................................................77
8.1 OBJECTIVE ............................................................................................................................................................ 78
8.2 CONTROLLERS TYPES ............................................................................................................................................... 78
8.2.1 OnOff Control ............................................................................................................................................... 78
8.2.2 Proportional Control ..................................................................................................................................... 78
8.2.3 Proportional + Derivative Control ................................................................................................................. 79
8.2.4 Proportional + Integral + Derivative Control ................................................................................................. 79
8.2.5 Proportional + Integral Control ..................................................................................................................... 80
8.3 PID CONTROLLER USING MATLAB ........................................................................................................................... 80
8.4 LAB EXERCISE ........................................................................................................................................................ 80
8.4.1 Task 1 Open loop step response and performance parameters.................................................................... 81
8.4.2 Task 2 Effect of Proportional Controller ........................................................................................................ 81
8.4.3 Task 3 Effect of ProportionalDerivativeController ...................................................................................... 82
8.4.4 Task 4 Effect of ProportionalIntegral Controller .......................................................................................... 83
8.4.5 Task 5 Effect of ProportionalIntegralDerivative Controller......................................................................... 84
LAB-9 ACTIVE REALIZATION OF PI CONTROLLER (TWO WEEKS) .............................................................................85
9.1 OBJECTIVE ............................................................................................................................................................ 86
9.2 COMPONENTS REQUIRED......................................................................................................................................... 86
9.3 OPAMP BASIC CIRCUIT REVIEW ............................................................................................................................... 86
TASK 1 .............................................................................................................................................................................. 87
9.4 TASK 2 ................................................................................................................................................................. 87
9.5 HARDWARE REALIZATION OF PI CONTROLLER ............................................................................................................... 88
9.5.1 Task 4 ............................................................................................................................................................ 88
9.5.2 Arduino setup (as server) .............................................................................................................................. 89
9.5.3 MATLAB Package Installation ....................................................................................................................... 89
9.5.4 Hardware software setup ............................................................................................................................. 89
9.5.5 Task 3 ............................................................................................................................................................ 90
LAB-10 LEVITATING A BALL IN AIR USING PID CONTROLLER (TWO WEEKS) ............................................................91
10.1 OBJECTIVE ............................................................................................................................................................ 92
10.2 COMPONENTS REQUIRED......................................................................................................................................... 92
10.3 BLOCK DIAGRAM.................................................................................................................................................... 92
10.4 SETUP DIAGRAM .................................................................................................................................................... 92
LAB-11 ANTI-WINDUP CONTROL AND DESIGNING VIA ROOT LOCUS ......................................................................93
11.1 OBJECTIVE ............................................................................................................................................................ 94
11.2 ANTIWINDUP CONTROLLER...................................................................................................................................... 94
11.2.1 Performance without Using AntiWindup................................................................................................. 94
11.2.2 Configuring the Block for AntiWindup Based on BackCalculation ......................................................... 96
11.2.3 Configuring the Block for AntiWindup Based on Integrator Clamping .................................................... 97
11.3 DESIGNING VIA MATLAB ROOT LOCUS ...................................................................................................................... 98
11.3.1 How to sketch root locus .......................................................................................................................... 98
11.3.2 Problem: ................................................................................................................................................... 98
11.3.3 Part 1 ........................................................................................................................................................ 98
11.3.4 Part 2 ........................................................................................................................................................ 99

3|Page
11.3.5 Part 3 ...................................................................................................................................................... 100
11.3.6 Part 4 ...................................................................................................................................................... 100
LAB-12 IDENTIFY BLACK-BOX MODELS USING SYSTEM IDENTIFICATION APP (ACTIVITY) ......................................101
12.1 OBJECTIVES ......................................................................................................................................................... 102
12.2 DATA DESCRIPTION .............................................................................................................................................. 102
12.3 WHAT ARE NONLINEAR BLACKBOX MODELS? .......................................................................................................... 102
12.3.1 Types of Nonlinear BlackBox Models..................................................................................................... 102
12.4 PREPARING DATA ................................................................................................................................................. 102
12.4.1 Loading Data into the MATLAB Workspace............................................................................................ 102
12.4.2 Creating iddata Objects .......................................................................................................................... 103
12.5 STARTING THE SYSTEM IDENTIFICATION APP .............................................................................................................. 103
12.5.1 Importing Data Objects into the System Identification App ................................................................... 104
12.6 ESTIMATING NONLINEAR ARX MODELS ................................................................................................................... 105
12.6.1 Estimating a Nonlinear ARX Model with Default Settings ...................................................................... 105
12.7 ESTIMATING TRANSFER FUNCTION ........................................................................................................................... 107

4|Page
List of Figures
Figure 11 RL series circuit ................................................................................................................................. 13
Figure 12 MATLAB plot for solution of diff equation ....................................................................................... 14
Figure 13 Invoking Simulink ............................................................................................................................. 14
Figure 14 Simulink model ................................................................................................................................. 14
Figure 15 Simulink plot ..................................................................................................................................... 15
Figure 16 RLC Series Circuit .............................................................................................................................. 15
Figure 17 SpringMass System ......................................................................................................................... 18
Figure 21RLC series circuit................................................................................................................................ 27
Figure 22 SpringMass System ......................................................................................................................... 29
Figure 31 poles zero map ................................................................................................................................. 32
Figure 32 Mechanical System........................................................................................................................... 33
Figure 33 Circuit diagram for task 2 ................................................................................................................. 34
Figure 34 Circuit diagram for task 3 ................................................................................................................. 35
Figure 35 System for task 4 .............................................................................................................................. 36
Figure 41 RL Circuit for example 1 ................................................................................................................... 39
Figure 42 Impulse response of circuit .............................................................................................................. 40
Figure 43 Simulink model for above example .................................................................................................. 40
Figure 44 Simulink impulse response ............................................................................................................... 40
Figure 45 Impulse response of circuit .............................................................................................................. 41
Figure 46 Simulink model for step response. ................................................................................................... 42
Figure 47 Simulink Step Response ................................................................................................................... 42
Figure 48 RLC circuit for lab task 1 ................................................................................................................... 42
Figure 49 Simulink result and current wave form on oscilloscope .................................................................. 42
Figure 410 step and impulse function .............................................................................................................. 45
Figure 411 System for task 4 ............................................................................................................................ 46
Figure 51 First order system pole plot ............................................................................................................. 49
Figure 52 Performance specifications for fist order system ............................................................................ 50
Figure 53 Step Response for task 1 .................................................................................................................. 50
Figure 54 Circuit Diagram. ................................................................................................................................ 53
Figure 61 Parameters of second order response ............................................................................................. 58
Figure 62 Spring mass system with damper..................................................................................................... 61
Figure 63 (a) pzmap of the systems (b) Step response for all systems ......................................... 62
Figure 64 (a) pzmap of all three systems (b) Step response for all system .................................. 63
Figure 65 System with Feedback Combination ................................................................................................ 64
Figure 66 System with Feedback Combination ................................................................................................ 64
Figure 67 System with Unity Negative Feedback ............................................................................................. 65
Figure 68 System with Unity Positive Feedback............................................................................................... 65
Figure 69 (a) Step response of open loop transfer function (b) Step response of close loop transfer
function with unity feedback............................................................................................................................. 66
Figure 71 Car cruise model ............................................................................................................................... 69
Figure 72Model for task 1 ................................................................................................................................ 69
Figure 73 Velocity response under step input ................................................................................................. 70
Figure 74Model for observing difference b/w input and output ..................................................................... 70
Figure 75 Effect of Controller ........................................................................................................................... 70
Figure 76 Model for velocity response for different disturbance .................................................................... 71

5|Page
Figure 77 Model for open loop and closed loop feedback .............................................................................. 72
Figure 78 Unity feedback system ..................................................................................................................... 73
Figure 79 Response due to input 5 , and K =1 .............................................................................................. 74
Figure 710 Response due to input 5t u(t), and K = 1 ........................................................................................ 74
Figure 711 Response due to input 5 ut2(t), and K = 1 ...................................................................................... 74
Figure 712 Response due to input 5 , and K =1 ............................................................................................ 75
Figure 713 Response due to input 5t u(t), and K = 1 ........................................................................................ 75
Figure 714 Response due to input 5 ut2(t), and K = 1 ...................................................................................... 75
Figure 715 Response due to input 5 , and K =1 ............................................................................................ 76
Figure 716 Response due to input 5t u(t), and K = 1 ........................................................................................ 76
Figure 717 Response due to input 5 ut2(t), and K = 1 ...................................................................................... 76
Figure 81 OnOff control .................................................................................................................................. 78
Figure 82 Proportional (P) control.................................................................................................................... 79
Figure 83 Proportional + derivative (PD) control ............................................................................................. 79
Figure 84 Proportional + integral + derivative (PID) control ............................................................................ 80
Figure 91 Opamp basic configuration review ................................................................................................. 86
Figure 92 System and its block diagram ........................................................................................................... 87
Figure 93 Block diagram of plant with PI controller ......................................................................................... 87
Figure 94 Circuit diagram of plant with PI controller ....................................................................................... 88
Figure 111 Simulink model of PID control of a plant with input saturation .................................................... 94
Figure 112 Enabling the backcalculation antiwindup method ...................................................................... 96
Figure 113 Undermask view of the PID Controller block with backcalculation............................................. 96
Figure 114 Aircraft ............................................................................................................................................ 98
Figure 115 Pitch Rate Control System .............................................................................................................. 98
Figure 121 Two Tank System.......................................................................................................................... 102

6|Page
List of Tables
Table 11 Solver options in Simulink ................................................................................................................. 12
Table 12 Comparison between Simulink and experimental result .................................................................. 17
Table 41 Impulse Response using MATLAB ...................................................................................................... 39
Table 42 Step Response using MATLAB ........................................................................................................... 41
Table 51 Nominal and Measured Value of Capacitors ..................................................................................... 53
Table 52 Observations...................................................................................................................................... 53
Table 61 Observations...................................................................................................................................... 60
Table 62 observation table for springmass system ........................................................................................ 62
Table 63 observation table for springmass system ........................................................................................ 63
Table 71 Calculated and observed errors for task 5 and task 6 ....................................................................... 73
Table 91 Nominal and calculated value ........................................................................................................... 89
Table 92 PI gain using nominal and measured values ..................................................................................... 89

7|Page
Student learning outcomes

Control Systems lab has been designed to enhance students ability of system modeling
and system designing. In this lab students will get insight of control systems. Student will learn
desired response generation of a system and how to change system response according to
need. It will be a motivational lab along with learning and hands on Experience. Overview of
each lab session is given below.

1. In first lab student will learn how to model a system using Simulink, to give practical
view, Simulink result will be verified with obtained result in hardware
implementation. (Hardware + Software)
2. Second lab will be conducted on numerical solution of ODE using MATLAB. System
will be considered to understand the solution. (Software)
3. Third lab deals with transfer function and state space representation of systems.
(Software)
4. Step and impulse response of system is covered in lab 4. (Hardware + Software)
5. First order system specifications will be analyzed using MATLAB and practical
setup. (Hardware + Software)
6. Second order system specifications will be analyzed using MATLAB. (Software)
7. Effect of system type, controller gain and type of input on system error. (Software)
8. Different controllers are used and effect of each controller will be demonstrated
(Software)
9. Design and Implementation PI controller using op-amp will be done according to
desired performance parameters for an RC circuit. (Hardware)
10. A ball will be levitated in air according to desired height by user, PID controller for
motor will be used to control air pressure on ball to achieve desired goal.
(Hardware)
11. Root locus for system designing and Anti-windup control will be learnt in this lab.
(Software)
12. How to Identity transfer function of a black box system. (Software)

8|Page
Grading Criteria
Total Credit hours 01
Total Labs 15

Each Lab has equal weightage and each lab Marks will contain marks according to
nature of the lab. Relevant grading policy will be adopted. A letter grade will be
awarded to each student based on his/her overall relevant performance in a lab.

9|Page
Supporting Staff
Course Instructor
Mr. Usama Bin Sikandar usama.sikandar@itu.edu.pk
Lab Instructors
1. Mr.Yasir Manzoor yasir.manzoor@itu.edu.pk
2. Mr.Zafarullah zafarullah@itu.edu.pk
Teaching Assistant
1. Mr. Muhammad Awais
2. Mrs. Amna Maqbool amna.maqbool@itu.edu.pk
Lab Technician
1. Mr.Muhammad Faisal muhammad.faisal@itu.edu.pk
2. Mr. Faisal Azmi faisal.azmi@itu.edu.pk
Lab Attendant
1. Mr.Awais Zaheer awais.zaheer@itu.edu.pk

Software resources
MATLAB,
Multisim

10 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 30 Jan, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Sanan Ahmad Session: BSEE2014

LAB1 System Modeling using Simulink

Name Reg. No. Total Marks

11 | P a g e
1.1 Objective
In this lab student will learn how to model a system using Simulink.

1.2 Introduction to Simulink


Simulink is a block diagram environment for multidomain simulation and ModelBased Design. It
supports systemlevel design, simulation, automatic code generation, and continuous test and verification of
embedded systems. Simulink provides a graphical editor, customizable block libraries, and solvers for
modeling and simulating dynamic systems. It is integrated with MATLAB, enabling you to incorporate
MATLAB algorithms into models and export simulation results to MATLAB for further analysis.

1.3 Introduction to Solvers


Mathematically systems are modeled using integrodifferential equations and usually its time
consuming activity to solve differential equations as you learnt in Differential Course. Simulink provides set
of blocks to implement differential equations. Whenever, differential equations are modeled we have
different solver options in Simulink to solve the equation. To get an overview some of solvers used in
Simulink are listed in table 11.

Solver Method Order of Accuracy When to Use


Most of the time. This should be the first solver
ode45 RungeKutta Medium
you try.
For problems with crude error tolerances or for
ode23 RungeKutta Low
solving moderately stiff problems.
For problems with stringent error tolerances or
ode113 Adams Low to High
for solving computationally intensive problems.
ode15s NDFs (BDFs) Low to Medium If ode45 is slow because the problem is stiff.
If using crude error tolerances to solve stiff
ode23s Rosenbrock Low
systems and the mass matrix is constant.
Trapezoidal For moderately stiff problems if you need a
ode23t Low
rule solution without numerical damping.
If using crude error tolerances to solve stiff
ode23tb TRBDF2 Low
systems.
Table 11 Solver options in Simulink

Simulink solves Ordinary Differential Equations (ODE) numerically. The whole idea is to break the
ODE into small time segments and to calculate the solution numerically for only a small segment. The length
of each segment is called step size. Since the method is numerical and not analytical there will be an error
in the solution. The error depends on the specific method and on the step size (usually denoted by h).

There are various formulas that can solve these equations numerically. Hence higher the order of
method, smaller the error is. Unfortunately the high order methods are very slow. To overcome this problem
variable step size solvers are used. When the systems states change very slowly then the step size can
increase and hence the simulation is faster. On the other hand if the states change rapidly then the step size
must be sufficiently small.

12 | P a g e
1.4 System modeling example
Given electric network shown in Figure 11.

a. Write differential equation for the nework. If source is unit step function.
b. Plot solution of differential equation for i(t) if R/L = 1.
c. Use simulink to model the differential equaiton and plot current if R/L = 1.

Figure 11 RL series circuit

We can write differential equation using KVL.

+ = ( )

If we solve above differential equation with zero initial conditions, we will get following equation
1
( )= (1 )

Plot above equation in MATLAB using follwing command assuming = 1,

>> t=linspace(0,10,500);
>> plot(t,(1-exp(-t)))
>> grid on

13 | P a g e
Figure 12 MATLAB plot for solution of diff equation

1.4.1 Steps to implement differential equaitons in Simulink


1. Open MATLAB and write simulink in command window and press enter.

Figure 13 Invoking Simulink

2. Click library browser.


3. Insert follwing blocks in new model.
a. Integrator from commonly used blocks
b. Gain from commonly used blocks
c. Sum from commonly used blocks
d. Scope from sink
e. Step from sources
4. Connect and rename the blocks according to equation as shown in Figure 14.

Figure 14 Simulink model

14 | P a g e
5. Run Simulink model and double click on scope. Normally ODE (45) solver is used in
Simulink; Solver configuration can be changed in Model Configuration Parameter.

Figure 15 Simulink plot

6. You can compare Figure 15 and Figure 12, both are exactly same.
1.5 Exercise # 1
Consider a series RLC circuit show in figure.

Figure 16 RLC Series Circuit

1.5.1 Task 1
1. Use digital multimeter to measure value of each component.
Measured value of C1______ ____________

Measured value of R1______ ____________

Measured value of L1______ ____________

Measured value of R2______ ____________

2. Write differential Equation for the network if, ( ) = 10 ( ), a unit step. (Hint: use KVL)

________________________________________________________________________________

15 | P a g e
1.5.2 Task 2
Model the differential equation using Simulink. Paste snap shot of model here. Use measured values for
accurate results.

1.5.3 Task 3
Run Simulink model and take snap shot of current wave form obtained.

1.5.4 Task 4
1. Connect the circuit shown in figure 16 on bread board.
2. Set function generator
a. Frequency 1.5 KHz
b. Amplitude 10 V pp
c. Offset 5V
d. Mode High Impedance (HighZ), using shift + output
3. Set oscilloscope
a. Xaxis 50us
b. Yaxis 10mV
c. Coupling AC

16 | P a g e
[Hint: Use Run/Stop button to make waveform still]

4. Connect oscilloscope across R2 to get current wave form in terms of voltage. as


= If =1 then we will get = .

5. Take snap shot of oscilloscope wave form and paste it here.

6. Compare experimental result and Simulink result according to following attributes:

Parameter Simulink Using Digital Scope


Peak current of first peak (mA)
Peak current of second peak (mA)
Peak current of third peak (mA)
Total time of first half cycle
Total time of First + Second half cycle
Table 12 Comparison between Simulink and experimental result

1.5.5 Task 5
1. Remove resistances R1 and R2 from your circuit on bread board, connect function generator
across series combination of L1 and C1. Connect oscilloscope across inductor and paste
wave form here. (Other configuration remains same as stated in task 4).

17 | P a g e
2. What is the effect of removing resistance from the circuit?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
3. Calculate frequency of oscillation (called resonant frequency or undamped natural
frequency) from the oscilloscope?
___________________________________________________________________________
___________________________________________________________________________
4. Formula for undamped natural frequency for a series RLC circuit is = ( / ),

compare result obtained in above question (3) with answer from equation and comment on
result. [Keeping in view rad/sec vs Hertz]
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
1.6 Exercise # 2
1. A springmass system is shown in Figure 17.

Figure 17 SpringMass System

2. Differential equation that can explain motion of mass is given below


( ) 1 ( )
= ( ( ) )

18 | P a g e
1.6.1 Task 5
Model above equation in Simulink, use ( ) as unit step function, B =1, K=1 and m=2, Paste model here.

1.6.2 Task 6
Plot wave form of ( ).

1.6.3 Task 7
1. Remove source (unit step) from above model. Put | = 0, and | =0 = 0, in integrator
blocks. Plot wave form of ( ).

19 | P a g e
2. Put | = 1, and | =0 = 0 in integrator blocks. Plot wave form of ( ).

3. Put | = 0, and | =0 = 1 in integrator blocks. Plot wave form of ( ).

20 | P a g e
4. Put | = 1, and | =0 = 1 in integrator blocks. Plot wave form of ( ).

21 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 6 Feb, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Sanan Ahmad Session: BSEE2014

LAB2 Numerical Solutions of ODEs using MATLAB

Name Reg. No. Total Marks

2.1 Objective
In this lab student will learn Numerical Solution of ODEs using MATLAB.

22 | P a g e
2.2 Euler Method to Solve First Order ODE
In order to use Euler's Method to generate a numerical solution to an initial value problem of the
form:

= ( , ), ( )=

We decide upon what interval and initial conditions, we desire to find the solution. We chop this interval
into small subdivisions of length h. Then, using the initial condition as our starting point, we generate the
rest of the solution by using the iterative formulas:

= +
= + ( , )

To find numerical solution using Eulers method. Following information is needed.


1. Initial values of x and y.
2. Step size
3. Interval for which solution is needed
2.3 Solving ODE using Eulers Method
You have to create two functions to solve ODE using Eulers method in MATLAB. Follow steps below:

2.3.1 First function file


1. Write differential equation in the form

2. Create m file for function ( , ) and save it with any name say ode1st.m.
3. For example,
a. to numerically solve

b. By making ( ) the subject of equation we get:


( )= ( , )= ( +3 )
c. Create a MATLAB script with name ode1st.m and save file for the function.

function dydt=ode1st(t,y)
dydt=(1/t^2)*(y+3*t);
end
2.3.2 Second function file
1. Create second function file with name euler_func.m for solution of above function using
Eulers method. In this program first function will be invoked.
2. You can use or update following MATLAB function.

function euler=euler_func(step_size,time_length,t_ini,y_ini)
h=step_size;
T=time_length;

23 | P a g e
n=T/h;
t(1)=t_ini;
y(1)=y_ini;
for i=1:1:n
y(i+1)=y(i)+h*ode1st(t(i),y(i))
t(i+1)=t(i)+h;
end
plot(t,y,'r')
xlabel('time')
ylabel('fucn value')
hold on
grid on
2.3.3 Executing Eulers Function
To solve example stated in 2.3.1, write following command in command window:
euler_func(0.1,4,1,-2)

Here, Initial value of t and y are 1 and 2 respectively, and final value of x is 4. Where, we have taken step
size of 0.1. You can choose any step size you want.

2.4 Lab Exercise


2.4.1 Newtons Law of Cooling
It states that

The rate of loss of heat/temperature change in in a body is directly proportional to the temperature
difference between body and surroundings, provided the difference is small

Let is temperature of body, and is temperature of surrounding then

= ( )

2.4.2 Lab Task 1


Heat transfer in a mass is very important for a number of objects such as cooling of electronic parts or the
fabrication of large beams. Consider a CPU that is turned on for a long time, if temperature of surrounding is
23 degree centigrade and constant of proportionality is 0.1 then according to Newtons law of cooling:

= 0.1(23 ),

1. Solve above differential equation for following step sizes and Plot Temperature of processor
vs time for time period 0 t 50, if (0) = 60,
a. Step size h = 10;
b. Step size h = 5;
c. Step size h = 1;
d. Step size h = 0.1;
2. Create first function file and name it Lab2_1f_16_15.m. Replace 16 and 15 with your group
members roll no.(file and function name should be same) Points 5

24 | P a g e
Do not delete TEXT BOX
Replace Only TEXT with your MATLAB function code.

3. Update above Euler function, and edit legends accordingly. Points 10


4. Function name and file name should be Lab2_1e_16_15.m.(replace 16,15 with your group
members roll no) Points 5
Do not delete TEXT BOX
Replace Only TEXT with your MATLAB function code.

5. Title of plot should be your roll no Lab2_1_16_15. replace 16,15 with your group members
roll no) Points 5
6. Use same figure to plot all four graph. Points 10

Do not delete This text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot, legends and tilte of plot
should be visible

7. From graphs, observe temperature of CPU at time 10 second for: Points 4


a. Step size 10 _____________
b. Step size 5 _____________
c. Step size 1 _____________
d. Step size 0.1 _____________
2.5 Solving ODE using ODE 45 in MATLAB
This routine uses a variable step RungeKutta Method to solve differential equations numerically. The syntax
for ode45 for first order differential equations and that for second order differential equations are basically
the same. However, the .m files are quite different.

2.5.1 First Order Equations using ODE 45


1. Repeat section 2.3.1.
2. Basic syntax for ode45. At a MATLAB prompt type :
[t,y]=ode45(@function_name,[initial_x,final_x],initial_y);
2.5.1.1 Example
For example stated in section 2.3.1

25 | P a g e
1. Initial values of t and y are 1 and 2 respectively, and domain is 1 to 4.
2. At MATLAB command window type:
[t,y]=ode45(@ode1st,[1,4],-2);% ode1st is function created in sec 2.3.1
3. To print results type : [t,y]
4. To plot results type : plot(t,y)
Other commands:
hold on %% to plot another graph on previous graph
plot(t,y,r) %% color red, blue, green, use r,b,g
2.5.1.2 Lab Task 2
1. Solve lab task 1 using ODE45 method and plot graph between temperature of processor and
time. Points 10
2. Use proper legends. Points 5
3. Title of plot should be your roll no Lab2_2_ODE45_16_15. replace 16,15 with your group
members roll no) Points 5

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot, legends and tilte of plot
should be visible

4. Analytical solution of Newtons law of cooling is given by


( )= +( )
5. At time = 10 second, Compare Eulers method (@step size 5) and ODE 45 method with
analytical solution. Comments on observed results. Points 10

______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

26 | P a g e
2.5.2 Second Order Equations
1. Suppose we have second order differential equation in the form

2. First convert 2nd order equation to an equivalent system of 1st order equations.

3. Create and save a .m file which will return a vectorvalued function. This is a little tricky so
here is a specific example. Suppose the system is as below for 0 t 4,

4. Create the following function file and save it as ode2nd.m :


function xp=ode2nd(t,x)
xp=zeros(2,1); % since output must be a column vector
xp(1)=x(2);
xp(2)=-t*x(1)+exp(t)*x(2)+3*sin(2*t);
5. At MATLAB command window type:
[t,x]=ode45(@ode2nd,[t0,tf],[x10,x20]);

6. For above example use : [t,x]=ode45(@ode2nd,[0,4],[2,8]);


7. Since = , to print out the values of the solution y for , at a MATLAB prompt
type:[t,x(:,1)]
8. To plot the solution on a graph t vs y, type: plot(t,x(:,1))
(Since the vector x has 1st component 1 = and 2nd component 2 =
2.5.3 Lab Task 3
Consider a series RLC circuit shown below

Figure 21RLC series circuit

27 | P a g e
1. Write second order differential equation associated with it. (Use KVL and then take its
derivative). Consider (0) = 7 (0) = 28 Points 5

_________________________________________________________________________

2. Convert second order system to equivalent first order system and write equations
below. Points 5

_________________________________________________________________________

3. Write a function in MATLAB to implement system of differential equations calculated


above. Function name should be Lab2_3RLC_ODE45_16_15. Replace 16, 15 with your
group members roll no). Points 10
Do not delete TEXT BOX
Replace Only TEXT with your MATLAB function code.

4. To solve above system using ODE45 for 0 < t < 10. Write MATLAB command here.
Points 5
Do not delete TEXT BOX
Replace Only TEXT with your MATLAB function code.

5. Plot current vs time using command plot(t,x(:,1)). Points 10

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot, legends and tilte of plot
should be visible

6. What is voltage across resistor at t = 0. Points 2

_______________________________________________________________

28 | P a g e
2.5.4 Lab Task 3
1. A springmass system is shown in Figure 21.

Figure 22 SpringMass System

2. Where B is friction constant, K is spring constant, F is force applied and y is distance traveled
by body of mass m from its mean point.
3. Differential equation that can explain motion of mass is given below
( ) 1 ( )
= ( ) , (0) = 0 (0) = 0

4. If B =1, K=1, m=2 and F(t) = 1, Solve differential equation using ODE 45 method as stated
above, for following conditions. Plot y, t for time 0 t 20
a. (0) = 0 (0) = 0 Points 10

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot, legends and tilte of plot
should be visible

a. (0) = 0.3 (0) = 0 Points 10

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot, legends and tilte of plot
should be visible

7. What is the position of mass at time = 20 second. Points 2


__________________________________________________________________

29 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 13 Feb, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Sanan Ahmad Session: BSEE2014

LAB3 Transfer Function & StateSpace representations

Name Reg. No. Total Marks

30 | P a g e
3.1 Objective
To obtain a transfer function from given RLC circuit and plot its poles and zeroes using MATLAB.

3.2 Equipment/Apparatus
1. Software: MATLAB
3.3 Conduct of Lab
1. Students are required to perform this experiment using the equipment provided.
2. Students are required to work in groups specified by lab engineers.
3. Students are advised to seek help from the course instructor, lab engineers, assigned teaching
assistants (TA) and lab attendants.
3.4 Theory of Transfer Function and State Space
A transfer function is also known as the network function is a mathematical representation, in terms
of spatial or temporal frequency, of the relation between the input and output of a (linear time invariant)
system. The transfer function is the ratio of the output Laplace Transform to the input Laplace Transform
assuming zero initial conditions. Many important characteristics of dynamic or control systems can be
determined from the transfer function.

The transfer function is commonly used in the analysis of singleinput singleoutput electronic system, for
instance. It is mainly used in signal processing, communication theory, and control theory. The term is often
used exclusively to refer to linear timeinvariant systems (LTI). In its simplest form for continuous time input
signal x(t) and output y(t), the transfer function is the linear mapping of the Laplace transform of the input,
X(s), to the output Y(s).

Zeroes are the value(s) where the numerator of the transfer function equals zero (The complex frequencies
that make the overall gain of the filter transfer function zero). Poles are the value(s) where the denominator
of the transfer function equals zero (The complex frequencies that make the overall gain of the filter transfer
function infinite).

The transfer function provides a basis for determining important system response characteristics without
solving the complete differential equation. As defined, the transfer function is a rational function in the
complex variable = + j that is
+ + ++
( )=
+ + + +
It is often convenient to factor the polynomials in the numerator and the denominator, and to write the
transfer function in terms of those factors:
( ) ( )( )( )( )( )
( )= =
( ) ( )( )( )( )( )
As written in the above equation,

The zs are the roots of the equation N(s) = 0 and are defined to be the system zeroes and The ps are the
roots of the equation D(s)=0 and are defined to be the system zeroes.

31 | P a g e
3.4.1 Example of Creating Transfer Function Models in MATLAB:
You can create transfer function (TF) models by specifying numerator and denominator coefficients. For
example,

MATLAB Commands:

>> num = [1 0];


>> den = [1 2 1];
>> sys = tf(num,den)
MATLAB Results of Transfer Function:

s
-------------
s^2 + 2 s + 1
We can plot the poles and zeroes of an LTI system using pzmap command.

pzmap(sys)
[p,z] = pzmap(sys)
pzmap(sys) plots the polezero map of the continuous or discretetime LTI model sys.
[p,z] = pzmap(sys) returns the system poles and zeroes in the column vectors p and z.
No plot is drawn on the screen.
3.4.2 Example of PoleZero Map in MATLAB
Plot the poles and zeroes of the continuoustime system.

2 +5 +1
( )=
+2 +3
>> H = tf([2 5 1],[1 2 3]);
>> pzmap(H);

Figure 31 poles zero map

32 | P a g e
3.4.3 Statespace
Consider the mechanical system shown in Figure 32. We assume that the system is linear. The
external force u(t) is the input to the system, and the displacement y(t) of the mass is the output. The
displacement y(t) is measured from the equilibrium position in the absence of the external force. This system
is a singleinput, singleoutput system. From the diagram, the system equation is

+ + =

Figure 32 Mechanical System

Let suppose m=1, b=0.9, k=1; Then

+ 0.9 + =
Its Transfer Function is given as

( + 0.9 + 1) ( ) = 1 ( )
( ) 1
=
( ) ( + 0.9 + 1)
This system is of second order. This means that the system involves two integrators. Let us define state
variables x1(t) and x2(t) as
( )= ( ) ( ) = ( )
Then we obtain
= = = 0.9 +
The output of the Equation is
=
State Space is given as
= +
= +
0.9 1 1
= +
1 0 0

= [0 1] + [0]

33 | P a g e
3.4.4 State Space Representation using MATLAB
The MATLAB code is given as below. Compare the theoretical results with MATLAB results
num=[1] %numerator
den=[1 0.9 1] %denominator
transf=tf(num, den) %transfer Function
[A,B,C,D]=tf2ss(num, den) % transfer function to State Space
3.5 Lab Exercise
3.5.1 Task 1
Consider the transfer function

6 +1
( )=
+3 +3 +7
a. Write the poles and zero values Points 6
Poles: __________, _____________, ___________
Zeros: __________, _____________, ___________
b. Plot pole zero map of the system Points 4

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot, legends and title of plot
should be visible

3.5.2 Task 2
Consider the following circuit

Figure 33 Circuit diagram for task 2


a. Write Transfer Function Points 3

( )=

34 | P a g e
b. Write the poles and zero values Points 3
Poles: _______________________
Zeros: _______________________
c. Plot pole zero map of the system Points 4

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot, legends and title of plot
should be visible

3.5.3 Task 3
Consider the following circuit

Figure 34 Circuit diagram for task 3

a. Write Transfer Function Points 3

( )=

b. Write the poles and zero values Points 3


Poles: _______________________
Zeros: _______________________
c. Plot pole zero map of the system Points 4

35 | P a g e
Do not delete this text box
Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot, legends and title of plot
should be visible

3.5.4 Task 4
Consider a DC Motor, shown in figure below, we can derive the following governing equations based on
Newton's 2nd law and Kirchhoff's voltage law.
+ =

+ + =

Figure 35 System for task 4

Considered the output is rotational speed and armature voltage as input. With parameters as follows
J = 0.01; b = 0.1; K = 0.01; R = 1; L = 0.5;

a. Write Transfer Function Points 6


= , =

( )
( )= =
( )
b. Write the poles and zero values Points 4

36 | P a g e
Poles: _____________, _____________
Zeros: _____________, _____________

3.5.5 Task 5
Consider the following differential equation of a system. Consider ( ) is input and ( ) is output

+ 14 + 56 + 160 = ( )

a. Write Transfer Function Points 2

( )=

b. Find the state space model of the system (Theoretical and MATLAB) Points 8

= +

=[ ] + [0]

37 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 20 Feb, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Sanan Ahmad Session: BSEE2014

LAB4 Step and Impulse Response of System

Name Reg. No. Total Marks

38 | P a g e
4.1 Objective
In this lab, we will use MATLAB and Simulink library to find the output of the systems with subjected
to different type of inputs and to know how system act under different types of inputs.

4.2 Equipment/Apparatus
1. Software: MATLAB
4.3 Theory Background
Simulation means studying the system behavior without actually constructing the system. We will
start by understanding some of the useful commands for system simulation and then we will apply these
commands on our developed systems.

Some commonly used responses are

1. Unit impulse Response


2. Unit step Response
4.3.1 Unit impulse Response
The impulse response of any LTI system is of utmost importance because the Laplace transform of
impulse response describes the transfer function of the LTI system. An impulse is a signal of arbitrary
magnitude that lasts for very short interval of time. Ideally an impulse has infinite magnitude and the time
span for which it lasts is zero.

4.3.1.1 Impulse response using MATLAB command


If we have an LTI system described by its transfer function tf, we can use following commands to get
impulse response.

MATLAB Command Explanation


LTI_sys = tf(num ,den) LTI system described by its transfer function
impulse(LTI_sys) Used to plot impulse response of system LTI_sys
impulse(LTI_sys,t) To observe the impulse response over a specified duration of time t.
t=0 : dt : Tfinal We can specify either a final timet or a vector of evenly spaced time samples.
impulse(LTI_sys,r,*) To specify a particular color, line marker of plot.

Table 41 Impulse Response using MATLAB

Example 1:

1. Consider a RLC circuit shown in figure 41.

Figure 41 RL Circuit for example 1

2. We are interested in finding out voltage , Then transfer function for above circuit is:
( )=
+ +1

39 | P a g e
3. Following commands will execute impulse response of above system for time 0 to 15
second with step size 0.01.
LTI_sys = tf([1 0 0] ,[1 1 1])
t=0 : 0.01 : 15;
impulse(LTI_sys,t,'r');
grid on
4. Impulse response for above circuit is shown in figure 42.

Figure 42 Impulse response of circuit

4.3.1.2 Impulse response using Simulink


Open Simulink and insert following blocks in new model:
1. Simulink >> continuous >> Transfer fcn
2. DSP System Toolbox >> Sources >> Discrete Impulse
Note: Amplitude of discrete Impulse is 1 at t = 0. You have to model discrete impulse into
continuous time impulse whose area under the curve should be 1.
3. Simulink >> Commonly used blocks >> Scope
Connect blocks as shown in figure 43 and double click on Transfer fcn block; enter numerator and
denominator of transfer functions for above circuit.

Figure 43 Simulink model for above example

Figure 44 Simulink impulse response

40 | P a g e
4.3.2 Step Response
From a practical standpoint, knowing how the system will respond to a sudden input is important
because large and possibly fast deviations from the long term steady state may have extreme effects on the
component itself and on other portions of the overall system dependent on this component. Normally,
knowing the step response of a dynamical system gives information on the stability of such a system, and on
its ability to reach one stationary state when starting from another.

4.3.2.1 Step response using MATLAB command


If we have an LTI system described by its transfer function tf, we can use following commands to get step
response.

MATLAB Command Explanation


LTI_sys = tf(num ,den) LTI system described by its transfer function
step(LTI_sys) Used to plot step response of system LTI_sys
step(LTI_sys,t) To observe the step response over a specified duration of time t.
t=0 : dt : Tfinal We can specify either a final timet or a vector of evenly spaced time samples.
impulse(LTI_sys,r,*) To specify a particular color, line marker of plot.
Table 42 Step Response using MATLAB

For RLC circuit in example 1, following commands will execute step response of above system for time 0 to
15 second with step size 0.01.
LTI_sys = tf([1 0 0] ,[1 1 1])
t=0 : 0.01 : 15;
step(LTI_sys,t,'r');
grid on
Step response for above circuit is shown in figure 45.

Figure 45 Impulse response of circuit

4.3.2.2 Step response using Simulink


Procedure for step response is same as described for impulse response in section 4.3.1.2. Use step function
instead of discrete impulse. Step function can be found:

Simulink >> Sources >> Step

41 | P a g e
For above example Simulink model is

Figure 46 Simulink model for step response.

Simulink step response shown in figure 47.

Figure 47 Simulink Step Response

4.3.3 Lab Task 1


A simple series RLC circuit is shown in figure 48. In lab 1, we have modeled differential equation of the
circuit for current in Simulink and observed behavior of current under step input. We also verified the result
by constructing the circuit on bread board.

Figure 48 RLC circuit for lab task 1

Current wave forms obtained on Simulink and oscilloscope are shown below.

Figure 49 Simulink result and current wave form on oscilloscope

42 | P a g e
1. Write transfer function for current of circuit shown in figure 48. 2 Points

( )
=
( )

2. What should be minimum simulation time required to observe transient and steady
state response of circuit. _____________(Hint: Observe from figure 49) 1 Point

3. Use Simulink to plot impulse response of circuit. Title of plot should be Task1.3Rollno1
Rollno2. Label the axis as well. 6 Points
(Hint) Right click on scope plot and print display to figure, where you can edit title etc.

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot.

4. What happens to current when we suddenly apply a voltage of 1 volt at t = 0. Plot circuit
current vs time for above circuit. Title of plot should be Task1.4Rollno1Rollno2. Label
the axis as well. Points 6

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot

43 | P a g e
5. Signal generator can be found in Simulink >> sources >> signal generator.
6. Use signal generator to attain following response of circuit shown in figure 48.

7. What setting is needed to get above response Points 6


a. Signal generator settings
Wave form type: ____________________

Amplitude: ____________________

Frequency: ____________________

Unit: ____________________

b. Simulator setting
Simulation Time: ___________________
Solver: ___________________
4.3.4 Relationship between unit step and unit impulse function
The unit step function, also known as the Heaviside function, is defined as such:
0, 0
( )=
1, >0
Whereas, an ideal impulse function is a function that is zero everywhere but at the origin, where it is
infinitely high.
0, 0
( )=
1, ( ) =0
The unit step function is level in all places except for a discontinuity at t = 0. For this reason, the derivative of
the unit step function is 0 at all points t, except where t = 0. Where t = 0, the derivative of the unit step
function is infinite. The derivative of a unit step function is called an impulse function. Since we can't show
the height of the impulse on our graph, we use the vertical axis to show the area. The unit impulse has
area=1.

44 | P a g e
Figure 410 step and impulse function

4.3.5 Relationship between unit step and unit impulse response


For liner systems, output is dependent on type of input. By analogy we can say that response of impulse
input is derivative of response of step input because impulse is derivative of step input.

4.3.5.1 Lab Task 2


1. Write MATLAB script to plot impulse and step response on same figure (use subplot), use
commands mentioned in table 41 and table 42. 6 Points

Copy MATLAB script here

2. Use snipping tool and paste plot here.

Copy and paste MATLAB plot in text box

45 | P a g e
3. From figure prove that impulse response is derivative of step response. 4 Points

Replace text with your answer

4.3.6 Lab Task 3


Consider a DC Motor, shown in figure 411, we can derive the following governing equations based on
Newton's 2nd law and Kirchhoff's voltage law.
+ =

+ + =

Figure 411 System for task 4

Considered the output is rotational speed and armature voltage as input. With parameters as follows
J = 0.01; b = 0.1; K = 0.01; R = 1; L = 0.5;

1. Write Transfer Function Points 6


= =

( )
( )= =
( )

46 | P a g e
2. Use Simulink to plot impulse response of motor. Title of plot should be Task3.2
Rollno1Rollno2. Label the axis as well. 6 Points
(Hint) Right click on scope plot and print display to figure, where you can edit title etc.

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot.

3. Determine value of rotational speed at t = 1 sec, if we apply armature voltage of 1


volt at t=0. ____________________________________________ 4 Points

4. If we apply armature voltage of 1 volt at t = 0, Make a plot that shows how


rotational speed varies with respect to time. Title of plot should be Task3.3
Rollno1Rollno2. Label the axis as well. 6 Points

Do not delete this text box


Use snipping tool to copy your MATLAB figure Replace Only
TEXT with your MATLAB plot.

47 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 27 Feb, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Sanan Ahmad Session: BSEE2014

LAB5 Performance Specifications of first order system

Name Reg. No. Total Marks

48 | P a g e
5.1 Objective
In this lab, student will learn performance parameters of first order and second order systems.
MATLAB will be used for analysis and modeling.

5.2 Equipment/Apparatus
1. Software: MATLAB
5.3 Theory of First Order System
Consider a first order system without zero (or zero at infinity), that has transfer function given below

( )=
+
Response of system can be calculated using ( )= ( ) ( )

Let ( )= ( )

If step input is applied to above system then, we can write response of system

( )=

By taking inverse Laplace transform we get

( )= ( )+ ( )=1

Where, input pole due to step function generated forced response ( ) = 1 and pole due to transfer
function at generated natural response ( )= . The value of " " is only parameter that
describes transient response of first order system.

5.3.1 Time Constant


Time constant is time it takes for step response to rise to 63% of its final value.

( ) =1

If we put =1 ( ) = 0.63 63%

Hence time constant for first order system will be =1

5.3.2 System speed (exponential frequency)


The reciprocal of time constant has the unit (1 ) or frequency. We call the parameter exponential
frequency that tells us initial rate of change of exponential at = 0. The derivative of ( ) = 1 @ =
0 . So value of " " tells us speed of the system when step input is applied. We can predict time constant
and speed of system from pole plot.

Figure 51 First order system pole plot

We can say pole is located reciprocal of time constant; farther is the pole from imaginary axis faster is
transient response.

49 | P a g e
5.3.3 Rise time
Rise time is defined as the time for the wave form to go from 0.1 to 0.9 of its final value.

5.3.4 Settling time


Settling time is defined as time required for the response to reach and stay above then 98% of its final value.

Figure 52 Performance specifications for fist order system

5.3.5 Lab Task 1


Response of an arbitrary first order system is shown in figure 53.

Figure 53 Step Response for task 1

If form of transfer function is , then calculate performance specifications for the system shown in figure.

1. Time constant ( ) _______________ 1 Point


2. System speed _______________ 1 Point
3. Rise time ( ) _______________ 1 Point
4. Settling time( ) _______________ 1 Point

50 | P a g e
5.3.6 Lab Task 2
a) A system has transfer function +
, let a = 50, Use MATLAB to Find the time constant ,
Settling time and Rise time from its step response curve.
i. Time constant ( ) _______________ 1 Point
ii. Rise time ( ) _______________ 1 Point
iii. Settling time( ) _______________ 1 Point
b) For system considered above, use MATLAB to plot step response of system on same figure
considering a = 50, a = 100, a= 200. 9 Points

c) Observe following parameters from plot. 9 Points

Performance Specifications a = 50 a = 100 a = 200


Time Constant
Rise Time
Settling time
d) Write observations regarding position of pole w.r.t origin and performance parameters?
5 Points

51 | P a g e
e) Based on above observation, if system pole becomes very close to origin will be effect on
system response? 5 Points

f) Plot impulse response of system for a = 1, and a = +1, Transfer function is given below.

6 Points
g) Comment about stability of both systems. 4 Points

52 | P a g e
5.3.7 Lab Task 3
1. You have provided a capacitor and a resistor. Measure value of capacitor and
resistors using digital multimeter and record in table51. 2 Points

S. No Nominal Values Measured Values


C 10 uF
R 2.2 K Ohm
Table 51 Nominal and Measured Value of Capacitors

2. We know that charge time for capacitor is five time constant and discharge time is
approximately (because of source resistance) five time constant, so to show total
charging and discharging, our applied wave should have time period > 10 time
constant. Calculate frequency required to apply and record in table 52. 3 Points

Combination Time Constant 10 Time Constant Frequency Required to apply

Table 52 Observations

3. Construct the circuit as shown in figure 5.4.


4. Apply square wave having frequency = 1 / (10 Time Constant).
5. Set VPP = 5V and Offset= 2.5V.
6. Use AC coupling in oscilloscope.

Figure 54 Circuit Diagram.

7. Steady state behavior means voltage across capacitor become stable.


8. Set oscilloscope so that step response for only positive half cycle should be visible on
scope.
9. Draw observed waveform here (use proper scaling). 9 Points

53 | P a g e
10. Find following parameters using oscilloscope. 3 Points
i. Time constant ( ) _______________
ii. Rise time ( ) _______________
iii. Settling time ( ) _______________
11. Write transfer function for above circuit? 3 Points

( )= =
+

12. Find value of capacitance from above information. ___________ 2 Points


13. Calculate rise time using formula 1 Point
2.2
= = __________

14. Calculate settling time using formula 1 Point


4
= = _________

15. Compare calculate values of rise and settling time with values obtained in point g,
and comment on argument that only time constant is = 1 is enough to calculate
all specifications parameters of first order system. 5 Points

54 | P a g e
5.3.8 Lab Task 4
1. How can we get settling time of 22ms for above circuit, if frequency and capacitor is
kept constant? 5 Points

2. Construct RC circuit to get 22mS rise time and observe following values using
oscilloscope.
3. Find following parameters using oscilloscope.
i. Time constant ( ) _______________ 2 Points
ii. Rise time ( ) _______________ 2 Points
iii. Settling time ( ) _______________ 2 Points
4. Draw wave form here. 6 Points

5.3.9 Lab Task 5


p = poly(r), where r is a vector, returns the coefficients of the polynomial whose roots are the
elements of r.

Consider a system having poles


Zeros at -.06
Poles at -0.9, 0.1, -2

55 | P a g e
1. Find the polynomial for numerator and denominator

2. Find the transfer Function from the polynomials found in Part 1

3. Comment about the stability by observing the unit impulse and step response

Consider a system having poles


Zeros at -.06, -0.2, 2
Poles at 0.9, 0.1
4. Find the polynomial for numerator and denominator

5. Find the transfer Function from the polynomials found in Part 1

6. Comment about the stability by observing the unit impulse and step response

56 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 6 March, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Zafarullah Session: BSEE2014

LAB6 Performance specifications of second order system

Name Reg. No. Total Marks

57 | P a g e
6.1 Objective
In this lab, student will learn performance parameters of second order systems. MATLAB will be used for
analysis and modeling.

6.2 Theory of Second Order System


Just as time constant describes performance of first order system, for second order system there are
following four performance parameters.

1. Rise Time( ): Time to reach from 10% of steady state to 90% of steady state value.
1.8
=

2. Peak Time( ): Time to get first peak of response


=
2
1

3. Settling Time ( ): Time to settle output between (0.98%1.02%) of steady state value.
4
=

4. % age overshoot: % age of final value by which the signal initially rises above the final.

1 2
% . = 100

Figure 61 Parameters of second order response

58 | P a g e
Based on poles locations, we can categorize second order system in four types:

Over damped Both Poles at real axis


Underdamped Complex conjugate poles
Undamped Two pure imaginary poles
Critically damped Poles at same location

The standard secondorder transfer function has the form


( )
( )= =
( ) +2 +
Above mentioned four parameters depends upon following two quantities.

6.2.1 Natural Frequency ( )


The natural frequency of a second order system is frequency of oscillation of the system without damping.

6.2.2 Damping Ratio ( )


The quantity that compares the exponential decay frequency of the envelope to the natural frequency. This
quantity remains same regardless of timescale.

The properties of response of second order system depend on the values of the parameters and . How,
these parameters affects the system, lets have a lab activity.

6.2.3 Task 1: Finding effect on system due to poles location


1. Plot step response for 8 sec and pole zero map of the systems. Highlight poles using data
cursor.
2. To fit all figures on single page, size for each figure should not exceed (2.2 X 2.7) inches.

Transfer Poles Location Step Response


Function pzmap(system) step(system)

System 1

9
+9 +9

59 | P a g e
System 2

9
+2 +9

System 3

9
+0 +9

System 4

9
+6 +9

3. Data cursor will show different parameters of system response on pole zero map of the
system. Observe values and write in observation table 61.
System Response Pole 1 Pole 2 Damping Ratio Overshoot
System 1
System 2
System 3
System 4
Table 61 Observations

4. Based on observations, can you describe relation between poles location and %age
overshoot of step response of the system?

60 | P a g e
[Write here]

5. Based on observations, can you describe relation between poles location and damping ratio
of step response of the system?
[Write here]

6. Observe overdamped and critical damped responses of system obtained in point 2, How can
you differentiate between two responses?
[Write here]

7. If you have a system of series RLC circuit where R = 0, what type of step response of current
your will get and explain its reason?
[Write here]

6.2.4 Task 2: Spring mass system with damper


The motion of body attached to spring as (shown in figure 62) is governed by the following differential
equation:

+ + = ( )
Figure 62 Spring mass system with damper

Where mass of body is damping coefficient and is spring constant.

Transfer function for above system is

61 | P a g e
( )
( )= =
( ) +( ) +

Note: if you have pole locations you can use following commands to plot pzmap and step response.

>> exp=poly([p1,p2]);
>> sys1=tf([num],[den]);
>> pzmap(sys1,sys2,..)
>> step(sys1,sys2,.)

1. A mass is attached to a spring, by analysis we found following poles locations.


Pole 1 Pole 2 m b k % .
Sys 1 1 + 2i 1 2i
Sys 2 2 + 3i 2 3i
Sys 3 3 + 4i 3 4i
Table 62 observation table for springmass system

2. Find value of m, b, k using poly (p1,p2) command.


3. Find transfer function using standard equation mentioned above.
4. Use pzmap and step to find all parameters mentioned in table 62.
5. Plot pzmap(sys1,sys2,sys3) of three systems on same figure and paste it figure 63
(a). Adjust figure in designated area.
6. Plot step(sys1,sys2,sys3)response of three systems on same figure write click on
figure to normalize the scale and highlight peak response. Paste in figure 63 (b). Adjust
figure in designated area.

Figure 63 (a) pzmap of the systems (b) Step response for all systems

7. If poles of system moves on straight having angle ( = tan ( )) then overshoot of


system will:
Remain unchanged __________
Decrease _________
Increase __________

62 | P a g e
8. If poles of system moves on straight having angle ( = tan ( )) then damping ratio of
system will:
Remain unchanged __________
Decrease _________
Increase __________

9. If system poles are at following locations.

Pole 1 Pole 2 m b k % .
Sys 1 1 + 2i 1 2i
Sys 2 1 + 3i 1 3i
Sys 3 1 + 4i 1 4i
Table 63 observation table for springmass system

1. Find value of m, b, k using poly (p1,p2) command.


2. Find transfer function using standard equation mentioned above.
3. Use pzmap and step to find all parameters mentioned in table 63.
4. Plot pzmap(sys1,sys2,sys3) of three systems on same figure and paste it figure 64
(a). Adjust figure in designated area.
5. Plot step(sys1,sys2,sys3)response of three systems on same figure write click on
figure to normalize the scale and highlight peak response. Paste in figure 64 (b). Adjust
figure in designated area.

Figure 64 (a) pzmap of all three systems (b) Step response for all system

1. If poles of system moves up (only imaginary part changes) then rise time, peak time will:
Remain unchanged __________
Decrease _________
Increase __________
2. Observe table 63 and write your observation.

63 | P a g e
[Write here]

3. [do yourself] If poles of system moves towards left (only real part changes) then what will
happen to natural frequency;
Remain unchanged __________
Decrease _________
Increase __________

6.3 Feedback System and stability


Feedback paths are present in every control systems. They enable us to continuously monitor the
response of a system and make necessary changes in the reference input to get the desired output.

6.3.1 Negative Feed back


Figure 65 shows a typical control system with G2(s) in negative feedback path.

U(s) + G1(s) Y(s)


_

G2(s)

Figure 65 System with Feedback Combination

The overall transfer function of this system can be calculated as,


( ) ( )
( )= =
( ) 1+ ( ) ( )

6.3.2 Positive feed back


Figure 66 shows a typical control system with G2(s) in positive feedback path.

U(s) + G1(s) Y(s)


+

G2(s)

Figure 66 System with Feedback Combination

The overall transfer function of this system can be calculated as,


( ) ( )
( )= =
( ) 1 ( ) ( )

MATLAB command feedback is used to resolve transfer functions connected in feedback style.

= ( 1, 2)

64 | P a g e
Note: By default, feedback ( 1, 2) assumes negative feedback and is equivalent to
( 1, 2, 1). For positive feedback +1 has to be written explicitly as third argument.

6.3.3 Unity Feedback System


Now assume that 2( ) = 1, that means we have connected output back to the input directly without any
transfer function involved. It would result in a special feedback loop, called unity feedback, as shown in
Figure 67.

U(s) + G(s) Y(s)


_

Figure 67 System with Unity Negative Feedback

U(s) + G(s) Y(s)


+

Figure 68 System with Unity Positive Feedback

Total transfer function, T(s), in this case would then be,


( ) ( )
( )= =
( ) 1 ( )

Now we can use the same feedback command to calculate T(s),

= ( 1, 1)

Here 1 represents unity negative feedback. To get the unity Positive feedback use 1 instead.

6.3.4 Lab Task 3


Consider a transfer function
1
( )=
+
1. Find open loop poles of the system.
a. ____________________ b. __________________
2. Find step response of the system and paste it in figure 69(a). Adjust figure in designated area.

65 | P a g e
Figure 69 (a) Step response of open loop transfer function (b) Step response of close loop transfer function with unity feedback

3. Comment about stability of the system from open loop step response.
[Write here]

4. Use MATLAB command (sys1=feedback(sys,1))to calculate close loop transfer function


with unity ve feedback and write here:
( )=
5. Find close loop poles of unity ve feedback system (transfer function obtained in 4).
a. __________
b. _________

6. Find step response of the close loop unity ve feedback system and paste it in figure 69(b).
Adjust figure in designated area.
7. Comment about stability of the close loop unity ve feedback system by observing its step
response.
[Write here]

8. Use MATLAB command (sys1=feedback(sys,-1))to calculate close loop transfer


function with unity +ve feedback and write here:
( )=
9. Find close loop poles of unity positive feedback system (transfer function obtained in 8).
a. __________
b. _________

10. Find step response of the close loop system (+ve feedback) and paste it in figure 610. Adjust
figure in designated area.

66 | P a g e
Paste your figure here

11. Comment about stability of the system from close loop with positive feedback step response.
[Write here]

12. How feedbacks effect the system?


[Write here]

67 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 13 March, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Zafarullah Session: BSEE2014

LAB7 Steady state Error Analysis of system

Name Reg. No. Total Marks

68 | P a g e
7.1 Objective
In this lab, student will learn effect of different parameters of the system on system steady state error.
Following parameters have been covered system type, controller, disturbance, feedback and type of input.

7.2 Tasks 1 Step response and steady state error


For car cruise model shown in figure 71, suppose engine imparts a force , is distance covered, is mass
of the car, is car velocity and is friction proportionality constant.

Figure 71 Car cruise model

1. Find transfer function between the input and the velocity .


( ) ( )
( )= = =
( ) ( )
2. Let for car, input jumps from being u =0 at time t = 0 to a constant u = 500 N thereafter.
Assume that the car mass m is 1000 kg and viscous drag coefficient, b = 50 Nsec/m.
3. Transfer function between the input and the velocity .
( ) ( )
( )= = =
( ) ( )
4. Use Simulink to find velocity behavior over time 0 to 100 sec, under conditions stated in
point 2. Keep in mind that your step input is ( ) = 500.

Figure 72Model for task 1

5. Take snap shot of velocity response and past here.

69 | P a g e
Paste plot here

Figure 73 Velocity response under step input

6. Applied force is _________________.


7. Final value of achieved velocity is ___________.
8. Difference between input and output is ___________.
9. Verify the difference between input and output, you can use following model.

Figure 74Model for observing difference b/w input and output

7.3 Task 2 Effect of controller


1. Place a controller in between input force and transfer function as shown in figure below.

Figure 75 Effect of Controller

2. Change numerator value of controller and observe difference between input and
output, find value of K to get steady state error zero._____________.

70 | P a g e
3. Use snipping tool and past your velocity response here for proposed value of k.

4. Comment about error between input and output as controller gain increases.

Write your comment here

7.4 Task 3 Effect of disturbance and Unity Feedback


1. Consider that velocity is affected by heavy wind blowing in to direction of car motion.
2. To see effect of disturbance on systems response, Include disturbance value (final value
of step) d1 = 1000 and d2 = 5000, plot it on same figure. You can use figure below:

Figure 76 Model for velocity response for different disturbance

3. Paste your figure here.

71 | P a g e
4. Our applied set point (input force) is 500 unit, As disturbance Increases car velocity
__________________ set point. (increases from, decreases from, remains at)
5. So, we conclude that if only controller is used, then error will be increase/decrease in
proportion with disturbance.
7.5 Task 4 Unity Feedback
1. Till now we were dealing with open loop system with controller and disturbance, Know
suppose that car velocity is fed back by unity negative feedback system.
2. To observe effect of ve feedback on system response. Create a model in Simulink as
shown below:

Figure 77 Model for open loop and closed loop feedback

3. Set force 500 and disturbance value = 1.


4. Change your feedback controller 2 value till you get approx. zero error. Write value here
____________________.
5. Put different disturbance values and observe the error between set point and steady
state value.(Use simulation for 70 second)
Plot for disturbance = 1000 Plot for disturbance = 5000

72 | P a g e
6. What effect did you noticed after applying ve feedback in the system, regarding steady
state error.
Write your comment here

7.6 Task 5 Steady State Error calculations


Type 0 system and steady state error calculations

1. For the negative feedback system of shown in figure 78.

Figure 78 Unity feedback system

( + 6)
( )= ( )=1
( + 4)( + 7)( + 9)( + 12)

Calculate steady state error in terms of K for following inputs: 5 ( ), 5 ( ), 5 ( )

Type 1 system and steady state error calculations

2. For the negative feedback system of shown in figure 78.


( + 6)( + 8)
( )= ( )=1
( + 4)( + 7)( + 9)( + 12)
Calculate steady state error in terms of K for following inputs: 5 ( ), 5 ( ), 5 ( )

Type 2 system and steady state error calculations

3. For the negative feedback system of shown in figure 78.


( + 1)( + 6)( + 8)
( )= ( )=1
( + 4)( + 7)( + 9)( + 12)

Calculate steady state error in terms of K for following inputs: 5 ( ), 5 ( ), 5 ( )

System Type Calculated Error Observed Error Using Simulink


and Input
Type 5 ( ) 5 ( ) 5 ( ) 5 ( ) 5 ( ) 5 ( )

( )

( )

( )
Table 71 Calculated and observed errors for task 5 and task 6

73 | P a g e
7.7 Task 6 Steady State Error Using MATLAB
1. Using Simulink set up the negative feedback system for type 0 system G0(s). Plot input and
response on same graph to so that steady state error could be observed in the system for
an input of 5 ( ) and K = 1, Repeat for inputs of 5 ( ), and 5 ( ). Observe error from
graph and write in table 71.

Figure 79 Response due to input 5 ( ), and K =1

Figure 710 Response due to input 5t u(t), and K = 1

Figure 711 Response due to input 5 ut2(t), and K = 1

74 | P a g e
2. Using Simulink set up the negative feedback system for type 0 system G1(s). Plot input and
response on same graph to observe error in the system for an input of 5 ( ) and K = 1,
Repeat for inputs of 5 ( ), and 5 ( ). Observe error from graph and write in table 71.

Figure 712 Response due to input 5 ( ), and K =1

Figure 713 Response due to input 5t u(t), and K = 1

Figure 714 Response due to input 5 ut2(t), and K = 1

75 | P a g e
3. Using Simulink set up the negative feedback system for type 0 system G2(s). Plot input and
response on same graph to observe error in the system for an input of 5 ( ) and K = 1,
Repeat for inputs of 5 ( ), and 5 ( ). Observe error from graph and write in table 71.

Figure 715 Response due to input 5 ( ), and K =1

Figure 716 Response due to input 5t u(t), and K = 1

Figure 717 Response due to input 5 ut2(t), and K = 1

76 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 20 March, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Zafarullah Session: BSEE2014

LAB8 Effect of controllers on system parameters

Name Reg. No. Total Marks

77 | P a g e
8.1 Objective
In this lab, we will use MATLAB to see effect of different types of controllers on system performance
parameters.

8.2 Controllers Types


Following are the most used controllers
1. OnOff Control
2. Proportional Control
3. Proportional + Derivative Control
4. Proportional + Integral + Derivative Control (ThirdOrder Systems)
5. Proportional + Integral Control
[Note: All the graphs shown in this section use parameter values for the thermal model that are typical of a small
domestic thermostat and the setpoint temperature is Ts. Furthermore, the PID used in the explanation is of standard
form rather than Parallel form]

8.2.1 OnOff Control


This is the simplest form of control, used by almost all domestic thermostats. When the oven is
cooler than the setpoint temperature the heater is turned on at maximum power, M, and once the oven is
hotter than the setpoint temperature the heater is switched off completely. The turnon and turnoff
temperatures are deliberately made to differ by a small amount, known as the hysteresis H, to prevent noise
from switching the heater rapidly and unnecessarily when the temperature is near the set point.

The fluctuations in temperature (Green line) as shown on the graph in Figure 81 are significantly large.

Figure 81 OnOff control

8.2.2 Proportional Control


A proportional controller attempts to perform better than the OnOff type by applying power, W, to
the heater in proportion to the difference in temperature between the oven and the set point,

= P (Ts To)
Where P is known as the proportional gain of the controller. As its gain is increased the system responds
faster to changes in set point but becomes progressively underdamped and eventually unstable. Where P is
known as the proportional gain of the controller. As its gain is increased the system responds faster to
changes in set point but becomes progressively underdamped and eventually unstable. The final oven

78 | P a g e
temperature lies below the set point for this system because some difference is required to keep the heater
supplying power.

Figure 82 Proportional (P) control

8.2.3 Proportional + Derivative Control


The stability and overshoot problems that arise when a proportional controller is used at high gain
can be mitigated by adding a term proportional to the time derivative of the error signal,

d
= P (Ts To) + D (Ts To)
dt

This technique is known as PD control. The value of the damping constant, D, can be adjusted to achieve a
critically damped response to changes in the set point temperature, as shown in the figure 83.

Figure 83 Proportional + derivative (PD) control

Too little damping results in overshoot and ringing, too much causes an unnecessarily slow response.

8.2.4 Proportional + Integral + Derivative Control


Although PD control deals neatly with the overshoot and ringing problems associated with
proportional control it does not cure the problem with the steadystate error. Fortunately, it is possible to

79 | P a g e
eliminate this while using relatively low gain by adding an integral term to the control function which
becomes

d
W = P (Ts To) + D (Ts To) + I (Ts To) dt
dt

where I, the integral gain parameter is sometimes known as the controller reset level. This form of function
is known as proportional + integral + differential, or PID, control. The effect of the integral term is to change
the heater power until the timeaveraged value of the temperature error is zero. The method works quite
well but complicates the mathematical analysis slightly because the system is now third order.

Figure 84 Proportional + integral + derivative (PID) control

8.2.5 Proportional + Integral Control


Sometimes, particularly when the sensor measuring the oven temperature is susceptible to noise or
other electrical interference, derivative action can cause the heater power to fluctuate wildly. In these
circumstances it is often sensible use a PI controller or set the derivative action of a PID controller to zero.

8.3 PID Controller using MATLAB

>>my_tf=tf([num],[den])
>>pid_sys= pid (Kp, Ki, Kd)
>>pid_contrlr=tf (pid_sys) % to get PID controller
>>my_tf_with_pid=feedback ((pid_contrlr*my_tf), 1) % for feedback
>>step (my_tf_with_pid, 7) % for step response
>>grid on
>>stepinfo(my_tf_with_pid) % to show performance parameters
8.4 Lab Exercise
Suppose we have a simple mass, spring, and. damper problem. The transfer function between the
displacement ( ) and the input ( )
1
( )=
+ +
Let, M = 1 kg, b = 2.5 N s/m, k = 20 N/m, F = 1 N
The goal of this problem is to obtain
Fast rise time
Minimum overshoot
No steadystate error
80 | P a g e
8.4.1 Task 1 Open loop step response and performance parameters
1. Plot the OpenLoop Step Response of the system for 7 seconds.
[Copy your figure here]

2. Write down performance parameters you got from step response.


Parameters Values
Rise Time
Settling Time
Overshoot
Peak value
Steady state value
Steady State error
8.4.2 Task 2 Effect of Proportional Controller
3. Now, introduce a Proportional Controller with unity feedback. Plot step response on
same graph for Kp=10 and Kp=100.

[Copy your figure here]

81 | P a g e
4. Note down the performance Parameters
Parameters Values for Kp = 10 Values for Kp = 100
Rise Time
Settling Time
Overshoot
Peak value
Steady state value
Steady State error
5. What are the observations when Proportional controller is introduced and what
happens when we increase the Kp?
_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

8.4.3 Task 3 Effect of ProportionalDerivativeController


6. Now, introduce a derivative controller with unity feedback. Plot step response for Kd=5
and Kd=10 in same plot. (Set proportional gain to 100 for both values of Kd)
[Copy your figure here]

Note down the performance Parameters

Parameters Values for Kd = 5 Values for Kd = 10


Rise Time
Settling Time
Overshoot
Peak value
Steady state value
Steady State error
7. What are the observations when Proportional controller is introduced and what
happens when we increase the Kd?
_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

82 | P a g e
8.4.4 Task 4 Effect of ProportionalIntegral Controller
8. Introduce an integral controller with unity feedback. Plot step response for Ki=5 and
Ki=20 in same plot, simulate step response for 80 seconds. (Set proportional gain to 100
for both values of Ki)
[Copy your figure here]

Note down the performance Parameters

Parameters Values for Ki = 5 Values for Ki = 20


Rise Time
Settling Time
Overshoot
Peak value
Steady state value
Steady State error
9. What are the observations when Proportional controller is introduced and what
happens when we increase the Ki?
_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

10. Can you make difference between effect of proportionalderivative and proportional
_Integral controller?
_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

11. If changing is needed in system transient response, which controller is better, PI or PD?
_________________________________________________________________________________

12. If changing is needed in system steady state error, which controller is better, PI or PD?
__________________________________________________________________________________
__________________________________________________________________________________

83 | P a g e
8.4.5 Task 5 Effect of ProportionalIntegralDerivative Controller
13. You have to use PID controller to get following parameters for the system. Choose any
value: Kp must be less than 100, Kd and Ki must be less than 40. Minimum values will be
preferred.

Parameters Values Kp Ki Kd
Settling Time Less than 7.2 sec
Overshoot 0%
Steady state > 0.99
value
Steady State < 0.1 %
error

84 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 03 & 10 April, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Zafarullah Session: BSEE2014

LAB9 Active Realization of PI controller (Two weeks)

Name Reg. No. Total Marks

85 | P a g e
9.1 Objective
In this lab, we will design a PI controller to get desired performance parameters for a first order
system.

9.2 Components Required


1. Bread board with jumper wires
2. Arduino Uno with cable
3. Three channel power supply
4. Digital Multimeter
5. Resistors (4.7K X 4, 1K X 2, 10K)
6. Variable resistors 100K and 10K
7. Capacitor (100uF, 1uF)
8. IC (LM741 X 3)
9.3 OpAmp Basic Circuit Review

Figure 91 Opamp basic configuration review

86 | P a g e
Task 1
1. Consider following first order system, a simple RC circuit shown in figure 91, in which
output across capacitor is matter of interest. We can call it our plant .

Figure 92 System and its block diagram

2. Measure value of components of plant i.e R & C and write here:


a. R = ___________
b. C = ___________
3. Use measured value of component and find transfer function ( ) for above system and
write here.
1
( )= =
+ +1
4. Use MATLAB to find step info from step response, write down values of following
parameters:
a. Settling time ______________3.9121 sec
b. % overshoot (M.P) ______________0%
c. Peak time ______________10.5458 sec
9.4 Task 2
1. You have to design a PI controller to achieve following performance parameters for above
system.
a. Settling time < 1 sec
b. % overshoot(M.P) < 25 %
c. Peak time < 0.35 sec
d. Control effort < 7 volt

Figure 93 Block diagram of plant with PI controller

2. Control effort is value of voltage (u = ei) after controller ( ), also shown in block diagram.
3. Calculated value of is ____________________
4. Calculated value of is ____________________

87 | P a g e
5. Now, overall system become second order, for this system performance parameters are:
a. Settling time ____________
b. % overshoot (M.P) ____________
c. Peak time ____________
d. Control effort ____________
9.5 Hardware realization of PI controller
Now, you can use following circuit diagram to implement plant with controller,

Figure 94 Circuit diagram of plant with PI controller

1. Difference amplifier will be used to add up applied reference input and feedback signal from
output. You can choose Ro = 4.7 K Ohm.
2. To implement PI controller opamp with inverting configuration will be used, we have to use
another inverting amplifier with gain 1 to get original signal.
3. Formula for gain of inverting amplifier:
=

4. Overall gain of cascaded amplifier is product of gain of both amplifier i.e


= 1 2

5. From above circuit diagram proportional gain will be:


2 4 2 4
= =
1 3 1 3
6. When opamp is used as integrator the gain for integrator
1 4
=
1 1 3
7. Use variable resistors for R1 and R2 to achieve desired value of Kp and Ki.
8. You can choose R3 and R4 to be 1 K Ohm.
9.5.1 Task 4
1. Find value R1 and R2 against your calculated value of Kp and Ki.
R1 = __________ R2 = __________
2. Fill the table below

88 | P a g e
Parameter Nominal Value Measured Value
R1
R2
R3
R4
R
C
Table 91 Nominal and calculated value

Components value Kp Ki Ts %M.P Tp Control effort


Using nominal value
Using measured value
Table 92 PI gain using nominal and measured values

3. Construct the circuit using +/ 9V power supply for opamp 741.


4. You will use Arduino for interfacing between hardware (circuit) and software (Simulink).
9.5.2 Arduino setup (as server)
1. Download arduinoIO folder from google class room in your E drive.
2. From the Arduino IDE toolbar menu, select File > Open and locate the file adioes.pde (in the
ArduinoIO/pde/adioes folder) and open it.
3. Connect the Arduino board and make sure that the correct board and serial port are
selected in the IDE (check menus Tools/Board: and Tool/Port:), then select File > Upload and
wait for the "Done Uploading" message.
4. Close Arduino IDE.
9.5.3 MATLAB Package Installation
1. Run MATLAB as administrator. Then set the current MATLAB directory to the location of the
file install_arduino.m (in the ArduinoIO/ folder).
2. Finally, type install_arduino at the MATLAB command line to run the script.
3. If you proceed to open Simulink, you will see the Library now includes the Arduino IO
Library.
9.5.4 Hardware software setup
1. Use jumper wires to connect reference signal (input 1 V) to A1 (analog one) pin and to
connect output signal to A0 (analog zero) pin of Arduino Uno board.
2. Connect any one ground of Arduino board with your circuit ground.
3. Run Simulink and build following program.

89 | P a g e
4. The Sample Time for the two Analog read blocks will be 0.01.
5. The Gain blocks are included to convert the 10 bit data into units of Volts (by multiplying
the data by 5/1023).
6. The given Simulink model then plots the commanded reference voltage and recorded
output voltage on a scope and also writes the output data to the MATLAB workspace for
further analysis.
7. Once the potentiometers have been set and the Simulink model has been created, the
model can then be run. During the running of the model, you must give one volt step
reference for the circuit using jumper.
8. Observe performance parameter form scope and write in following table.

Kp Ki Ts %O.S Tp Control effort


Form Simulink Scope
9. Verify your circuit and results from Lab Engineer and get signed.

Circuit ______________5 Marks

Simulink Result ______________5 Marks


9.5.5 Task 3
Calculate rate of change of reference input for which output can trace it. For example our reference input 1V
can be changed to 0.5 V within any time (1 sec, 0.2 sec, 1 msec). Output requires some time to trace
reference input. Can you tell what is minimum time required to trace input for our system.

90 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 17 & 24 April, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Zafarullah Session: BSEE2014

LAB10 Levitating a ball in air using PID controller (Two weeks)

Name Reg. No. Total Marks

91 | P a g e
10.1 Objective
In this lab, student will design and implement a PID controller to levitate a ball in air using Arduino and
Matlab.

10.2 Components Required


1. Arduino Uno with cable
2. Setup for levitation of ball
3. IR sensor
4. 12 Volt brushless blower cooling fan
10.3 Block Diagram

10.4 Setup diagram

1. Clear tube should be scaled from bottom 0 cm to top 40 cm.


2. Tube diameter should be slightly (1mm) greater then ball diameter otherwise air
pressure will be released.
3. Diameter of air outlet should be less then ball diameter for proper insertion of pressure
to the ball.
Reference:
https://create.arduino.cc/projecthub/DanDoherty/levitateapingpongballusingarduinoandsimulink
c403c6
https://www.mathworks.com/matlabcentral/fileexchange/58427levitatingapingpongballusingarduino
andsimulink

92 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 8 May, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Zafarullah Session: BSEE2014

LAB11 Antiwindup control and Designing via root locus

Name Reg. No. Total Marks

93 | P a g e
11.1 Objective
In this lab, student will understand effect of antiwindup controller using PID and designing via root
locus using MATLAB.

11.2 Antiwindup controller.


1. We will use a builtin model of MATLAB to see the effect.
2. To open model, type sldemo_antiwindup in a MATLAB command window.
3. You will see following model.

Figure 111 Simulink model of PID control of a plant with input saturation

4. Here
( ) is set point.
( ) is difference between feedback and set point.
( ) is PID controller output.
( ) is input to the plant (saturation block output).
( ) is output of the plant.

5. The controlled plant is a saturated firstorder process with deadtime of 2 second described by
1
( )=
10 + 1
6. The plant has known input saturation limits of [10, 10], which are accounted for in the Saturation block
labeled Plant Actuator.
7. The PID Controller has been tuned with saturation ignored using the PID tuner of Simulink Control
Design.
8. PID Controller block in Simulink has two builtin antiwindup methods backcalculation & clamping.

11.2.1 Performance without Using AntiWindup

1. First, we examine the effect of saturation on the closedloop when the saturation model is not
considered by the PID Controller block.
2. Simulate the model.
3. Click on scope attached with PID controller block. This will show you Controller output ( ) and
saturated input ( ). Plot waveform below in left side.
4. Click on scope attached with dead time block. This will show you set point ( ) and output of system
( ). Plot waveform below in right side.

94 | P a g e
Copy wave form of control effort Copy wave form of system output
u(t)here y(t)here

Controller output and saturated


input
Setpoint vs. measured output
5. What should be maximum & minimum value of controller output? _____________&__________.
6. Explain reason for your above answer.

7. Ideally Time delay between set point and system output should be _______________________.
8. There are two problems associated with the system. Analyze above figures and highlight two of the
problems that arise when controlling a system with input saturation:
Problem # 1

Problem # 2

95 | P a g e
Designing the PID controller to account for the effect of saturation will improve its performance by allowing
it to operate in the linear region most of the time and recover quickly from nonlinearity. Antiwindup
circuitry is one way to achieve this.
11.2.2 Configuring the Block for AntiWindup Based on BackCalculation

1. The backcalculation antiwindup method uses a feedback loop to discharge the PID Controller's internal
integrator when the controller hits specified saturation limits and enters nonlinear operation.
2. To enable antiwindup, go to the PID Advanced tab in the block's dialog; select Limit output; and enter
the plant's saturation limits. Then, select back-calculation from the Anti-windup method menu and
specify the backcalculation gain Kb=1.

Figure 112 Enabling the backcalculation antiwindup method

3. Once backcalculation is enabled, the block has an internal tracking loop that discharges the Integrator
output.

Figure 113 Undermask view of the PID Controller block with backcalculation

4. Now simulate the model again.


5. Click on scope attached with PID controller block. This will show you Controller output ( ) and
saturated input ( ) plot waveform below in left side.
6. Click on scope attached with dead time block. This will show you set point ( ) and output of system
( ). Plot waveform below in right side.

96 | P a g e
Copy wave form of system ouput
y(t)here
Copy wave form of control effort
u(t)here

Controller output and saturated Setpoint vs. measured output


input

7. Observe the above figures and comment about problems highlighted in 11.2.1.

11.2.3 Configuring the Block for AntiWindup Based on Integrator Clamping

1. Another commonly used antiwindup strategy is based on conditional integration.


2. To enable antiwindup, go to the PID Advanced tab in the block's dialog; select Limit output; and
enter the plant's saturation limits. Then, select clamping from the Anti-windup method menu.
3. Repeat point 5 and 6 of section 11.2.2.

Copy wave form of system ouput


y(t)here
Copy wave form of control effort
u(t)here

97 | P a g e
11.3 Designing via MATLAB root locus
11.3.1 How to sketch root locus

>>h = tf([2 5 1],[1 2 3]); // where h is open loop transfer function.


>>rlocus(h)

11.3.2 Problem:
A highperformance aircraft, shown in Figure 11.4.

Figure 114 Aircraft

It uses the ailerons, rudder, and elevator to steer through a threedimensional flight path. The pitch rate
control system for a fighter aircraft at 10,000 m and Mach 0.9 can be represented by the system in Figure
11.5,

Figure 115 Pitch Rate Control System

Where
18( + 0.015)( + 0.45)
( )=
( + 1.2 + 12)( + 0.01 + 0.0025)

11.3.3 Part 1
Sketch the root locus when the controller ( ) = , and determine when for the roots with > is
larger than 0.15 (seek a maximum ).

1. Write down characteristic equation for system shown in figure 115.

=0

2. Sketch the root locus using MATLAB. Highlight the point where > 0.15 and >2

98 | P a g e
3. Find value of gain K at that point and write here. _______
11.3.4 Part 2
Plot step response of the system with observed K in part 1.

1. Find % age overshoot from step response plotted above and write here._____________________

11.3.5 Part 3
A designer suggests an anticipatory controller with ( ) = + = ( + ). Sketch the root locus
for this system as K varies and determine a K so that the of all the closed-loop roots is > 0.8.

1. Write down characteristic equation for anticipatory controller.

99 | P a g e
=0

2. Sketch the root locus using MATLAB. Highlight the point where > 0.90.

3. Find value of gain K at that point and write here. _______


11.3.6 Part 4
Plot the response ( ) for a step input ( ), with K as in part 3.

Compare step response found in part 2 and as in part 4, what conclusion can be drawn.
________________________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________
________________________________________________________________________________________

100 | P a g e
Department of Electrical Engineering
Control Systems

Course Instructor: Mr. Usama Bin Sikandar Dated: 15 May, 2017

Lab Instructor 1: Mr. Yasir Manzoor Semester: 6th

Lab Instructor 2: Mr. Zafarullah Session: BSEE2014

LAB12 Identify BlackBox Models Using System Identification App


(Activity)

Name Reg. No. Total Marks

101 | P a g e
12.1 Objectives
Estimate and validate nonlinear models from singleinput/singleoutput (SISO) data to find the one
that best represents your system dynamics. After completing this tutorial, you will be able to accomplish the
following tasks using the System Identification app:
1. Import data objects from the MATLAB workspace into the app.
2. Estimate and validate nonlinear models from the data.
3. Plot and analyze the behavior of the nonlinearities.
12.2 Data Description
This tutorial uses the data file twotankdata.mat, which contains SISO timedomain data for a
twotank system, shown in the following figure.

Figure 121 Two Tank System

In the twotank system, water pours through a pipe into Tank 1, drains into Tank 2, and leaves the
system through a small hole at the bottom of Tank 2. The measured input u(t) to the system is the voltage
applied to the pump that feeds the water into Tank 1 (in volts). The measured output y(t) is the height of the
water in the lower tank (in meters).
Based on Bernoulli's law, which states that water flowing through a small hole at the bottom of a
tank depends nonlinearly on the level of the water in the tank, you expect the relationship between the
input and the output data to be nonlinear. twotankdata.mat includes 3000 samples with a sample time of
0.2 s.
12.3 What Are Nonlinear BlackBox Models?
12.3.1 Types of Nonlinear BlackBox Models
You can estimate nonlinear discretetime blackbox models for both singleoutput and multipleoutput time
domain data. You can choose from two types of nonlinear, blackbox model structures:
1. Nonlinear ARX models
2. HammersteinWiener models
12.4 Preparing Data
12.4.1 Loading Data into the MATLAB Workspace
Load sample data in twotankdata.mat by typing the following command in the MATLAB Command
Window:
load twotankdata
This command loads the following two variables into the MATLAB Workspace browser:
u is the input data, which is the voltage applied to the pump that feeds the water into Tank 1 (in volts).
y is the output data, which is the water height in Tank 2 (in meters).
12.4.2 Creating iddata Objects
System Identification Toolbox data objects encapsulate both data values and data properties into a
single entity. You can use the System Identification Toolbox commands to conveniently manipulate these

102 | P a g e
data objects as single entities. Use the following commands to create two iddata data objects, ze and zv,
where ze contains data for model estimation and zv contains data for model validation. Ts is the sample
time.
Ts = 0.2; % Sample time is 0.2 sec
z = iddata(y,u,Ts);
% First 1000 samples used for estimation
ze = z(1:1000);
% Remaining samples used for validation
zv = z(1001:3000);

To modify data properties, use dot notation. For example, to assign channel names and units that label plot
axes, type the following syntax in the MATLAB Command Window:
% Set time units to minutes
ze.TimeUnit = 'sec';
% Set names of input channels
ze.InputName = 'Voltage';
% Set units for input variables
ze.InputUnit = 'V';
% Set name of output channel
ze.OutputName = 'Height';
% Set unit of output channel
ze.OutputUnit = 'm';
% Set validation data properties
zv.TimeUnit = 'sec';
zv.InputName = 'Voltage';
zv.InputUnit = 'V';
zv.OutputName = 'Height';
zv.OutputUnit = 'm';

12.5 Starting the System Identification App


To open the System Identification app, type the following command in the MATLAB Command Window:
systemIdentification
The default session name, Untitled, appears in the title bar.

12.5.1 Importing Data Objects into the System Identification App


You can import the data objects into the app from the MATLAB workspace. To import data objects:

103 | P a g e
1. In the System Identification app, select Import data > Data object.

2. This action opens the Import Data dialog box.

3. Enter ze in the Object field to import the estimation data. Press Enter.
4. This action enters the object information into the Import Data fields.
5. Click More to view additional information about this data, including channel names and units.
6. Click Import to add the icon named ze to the System Identification app.
7. In the Import Data dialog box, type zv in the Object field to import the validation data.
Press Enter.
8. Click Import to add the icon named zv to the System Identification app.
9. In the Import Data dialog box, click Close.
10. In the System Identification app, drag the validation data zv icon to the Validation
Data rectangle. The estimation data ze icon is already designated in the Working Data rectangle.

The System Identification app now resembles the following figure.

104 | P a g e
12.6 Estimating Nonlinear ARX Models
12.6.1 Estimating a Nonlinear ARX Model with Default Settings
In this portion of the tutorial, you estimate a nonlinear ARX model using default model structure and
estimation options.
1. In the System Identification app, select Estimate > Nonlinear models.

This action opens the Nonlinear Models dialog box.

105 | P a g e
The Configure tab is already open and the default Model type is Nonlinear ARX.
1. Click Estimate. This action adds the model nlarx1 to the System Identification app, as shown in the
following figure.

The Nonlinear Models dialog box displays a summary of the estimation information in the Estimate tab.
The Fit (%) is the mean square error between the measured data and the simulated output of the model:
100% corresponds to a perfect fit (no error) and 0% to a model that is not capable of explaining any of the
variation of the output and only the mean level.

In the System Identification app, select the Model output check box. This action simulates the model using
the input validation data as input to the model and plots the simulated output on top of the output
validation data.

106 | P a g e
The Best Fits area of the Model Output plot shows that the agreement between the model output and the
validationdata output.
12.7 Estimating Transfer Function
To estimate transfer function

1. Click estimate >> Transfer function models.

2. You will see following window. For instance set default setting i.e no. of poles 2 and no of zeros 1
and click estimate.

107 | P a g e
3. An additional icon with name tf will be generated in system identification window. As shown in
figure below:

4. Double click on tf icon. You will see following widow.

5. You will see transfer function in the window that will satisfy the system.

108 | P a g e

You might also like