Control Systems: Lab Manual
Control Systems: Lab Manual
Control Systems: Lab Manual
Control Systems
Lab Manual
Submitted by: Matloob Anwar Shad10Es184 Waleed Raza.10Es160 Saad Sarwar Cheema10Es165 Muhammad Sohail10Es174 6th Semester Electronics Section(C) Submitted to: Engr. S.M Fasih-ur-Rehman
List of Experiments
Sr No. 01 02 03 04 05 06 07 08 09 10 11 Name An Introduction to MATLAB Symbolic Math Function and Transfer Function Partial Fraction using MATLAB Inverse Laplace using MATLAB Block Diagram Reduction Transfer Function to State Space State Space to Transfer Function Step/Impulse response of 1st and 2nd order Systems Introduction to Simulink Ramp Response using Simulink Introduction to Root Locus Page No. 02 06 10 13 15 19 22 25 30 34 37
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
LAB NO.01
An Introduction to MATLAB
Introduction to MATLAB:
MATLAB (matrix laboratory) is a numerical computing environment. It is the language of technical computing. It is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, we can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable us to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages. MATLAB provides a number of features for documenting and sharing our work. We can integrate our MATLAB code with other languages and applications, and distribute our MATLAB algorithms and applications. Features include:
High-level language for technical computing Development environment for managing code, files, and data Interactive tools for iterative exploration, design, and problem solving Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, and numerical integration 2-D and 3-D graphics functions for visualizing data Tools for building custom graphical user interfaces Functions for integrating MATLAB based algorithms with external applications and languages, such as C, C++, Fortran, Java, COM, and Microsoft Excel
Some General Used Commands: Command window is used to type the commands and some input values if required to get with the immediate results. The command window in MATLAB appears as follows:
We write the commands and get desired results based on our requirement. Some simple commands are shown below: Way of declaring a variable in MATLAB: x=20 x = 20 Way of creating an Arithmetic series: To create an arithmetic series we write the command as follows: Starting number: Increment/Decrement: Ending Number >> z=-2:1:3 z = -2 -1 0 1 2 3
The way of declaring a geometric series: Suppose we want to declare a geometric series as this 3 9 27 81 243 We see that the constant ratio of the series is 3 and it consists of 5 elements so we first declare an arithmetic series from 1 to 5 and then take this arithmetic series as the power if the constant ratio which is 3 as follows: >> y=1:1:5 y = 1 2 >> x=3; >> z=x.^y z = 3 9 Way of declaring a matrix: The way of declaring a matrix is as follows: matrix= [a11 a12 a13..a1n ; a21 a22 a23..a2n ;.; an1 an2
27
81
243
an3..ann]
Example: >> matrix=[1 2 3 pi;1 2 pi 4;1 pi 3 4; pi 2 3 4] matrix = 1.0000 2.0000 3.0000 3.1416 1.0000 2.0000 3.1416 4.0000 1.0000 3.1416 3.0000 4.0000 3.1416 2.0000 3.0000 4.0000
Moreover, there are many built-in matrices such as identity matrix magic matrix etc. they can be called by writing eye(m,n) for identity matrix where m and n are no. of rows and columns. magic(m) for magic matrix. The way to take natural log of a number series or a matrix: log command is used to take natural log of a number. The syntax of the command is log(number, series or matrix) Example: >> log(10) ans = 2.3026 We can also take the natural log of a series or a matrix. The way to take base-10 log of a number series or a matrix: The log10 command is used to take the base-10 log of a number series or a matrix. The syntax of the command is log10(number, series or matrix) Example: >> log10(10000) ans = 4
******************************************************************
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
LAB NO.02
Differentiation Integration Linear algebraic operations Simplification Transforms Variable-precision arithmetic Equation solving
Symbolic Math Toolbox software also includes the MuPAD language, which is optimized for handling and operating on symbolic math expressions. In addition to covering common mathematical tasks, the libraries of MuPAD functions cover specialized areas such as number theory and combinatorics. We can extend the built-in functionality by writing custom symbolic functions and libraries in the MuPAD language. We can access the Symbolic Math Toolbox functionality directly from the MATLAB Command Window.
>> syms x y z
Differentiation: The syntax of differentiation is as follows: diff(name of a defined variable which is the function of a symbolic object/s, name of symbolic object w.r.t differentiate) Example: >> syms x % Define x as a symbolic object % Define a function of x
>> y=3*(x^2)-(4*x); >> z=diff(y,x) z= 6*x - 4 Integration: The syntax of integration is as follows:
% Differentiate y w.r.t x
int(name of a defined variable which is the function of a symbolic object/s, name of symbolic object w.r.t integrate) Example: >> syms x % define x as a symbolic object >> y=x; % define a function of x % integrate y w.r.t x
There are also some other commands such as pretty and simplify that corresponds to Symbolic Math Toolbox of MATLAB.
Transfer Function:
Transfer function is the ratio of o/p of a system and i/p of a system in frequency domain (usually in Laplace domain) provided that the system is linear.
Transfer function: s^2 - 2 ------s + 1 The transfer function object G now is created by above code and is now ready to be used to analyze the system with t.f G(s). The transfer function object can then be used to check the impulse, step or ramp response of the system and pole zero map of the system etc.
******************************************************************************
10
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
11
LAB NO.03
12
Partial Fraction to Polynomial form: [num,den]=residue(r,p,k) Example: Consider the following partial fraction:
******************************************************************************
13
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
14
LAB NO.04
******************************************************************************
15
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
16
LAB NO.05
The overall transfer function of this system is calculated using MATLAB by a command series whose syntax is as follows: series(G1,G2) Where G1 and G2 both are transfer function objects of two systems. Parallel command: parallel connects two LTI models in parallel. This function accepts any type of LTI model. The two systems must be either both continuous or both discrete with identical sample time. Let a system be the combination of two LTI systems G1 and G2 in parallel as shown below:
17
The overall transfer function of this system is calculated using MATLAB by a command parallel whose syntax is as follows: parallel(G1,G2) Where G1 and G2 both are transfer function objects of two systems. Feedback command: feedback connects two LTI models in feedback. This function accepts any type of LTI model. The two systems must be either both continuous or both discrete with identical sample time. The syntax for negative feedback is as follows: feedback(sys1,sys2) The syntax for positive feedback is as follows: feedback(sys1,sys2,+1) Where sys1 and sys2 are two t.f objects of two LTI systems. Example of Reduction: Consider the following system which is to be reduced to a single transfer function:
18
The coding in MATLAB that is used to do this is as follows: G1a=tf([1 0],1); G1b=tf([1 0],1); G1=series(G1a,G1b); G2a=tf(1,[1 0]); G2=parallel(G1,G2a); G3a=tf(1,1); G3=feedback(G2,G3a); G4a=tf(1,[1 0]); G4=series(G3,G4a); G5a=tf([1 0],1); G=feedback(G4,G5a) Transfer function: s^3 + 1 ----------------2 s^4 + s^2 + 2 s
******************************************************************************
19
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
20
LAB NO.06
21
B1 = 1 0 0 0 0 C1 = 1 D1 = 0 2 12 7 3
******************************************************************************
22
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
23
LAB NO.07
24
A2 = 3 1 -3 5 0 1 -7 6 -6 0 B2=[2;7;6;5;4] B2 = 2 7 6 5 4 C2=[1 -2 -9 7 6] C2 = 1 D2=0 D2 = 0 [num2,den2]=ss2tf(A2,B2,C2,D2); Hs2=tf(num2,den2) Transfer function: -7 s^4 - 408 s^3 + 1708 s^2 + 1.458e004 s + 2.767e004 ----------------------------------------------------s^5 - 4 s^4 - 32 s^3 + 148 s^2 - 1153 s - 4480 -2 -9 7 6 0 -5 -1 -3 4 4 2 2 -4 -3 -2 -1 8 0 1
*************************************************************************************
25
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
26
LAB NO.08
Amplitude
0.6 0.5 0.4 0.3 0.2 0.1 0 0 0.2 0.4 0.6 Time (sec) 0.8 1 1.2
27
Example of Step Response of 2nd order systems: Consider the following Transfer Functions: ( ) ( ) ( ) ( ) Code to find Step Responses of above systems: >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> Response:
2.5 H1 2 H2 H3 H4 1.5
num1=[1]; den1=[1 8 1]; num2=[1]; den2=[1 1 1]; num3=[1]; den3=[1 2 1]; num4=[1]; den4=[1 0 1]; H1=tf(num1,den1); H2=tf(num2,den2); H3=tf(num3,den3); H4=tf(num4,den4); step(H1,H2,H3,H4) axis([0 30 -0.5 2.5]) grid on legend('H1','H2','H3','H4')
Step Response
Amplitude
0.5
-0.5
10
15 Time (sec)
20
25
30
28
Response:
Impulse Response 5 4.5 4 3.5
Amplitude
3 2.5 2 1.5 1 0.5 0 0 0.2 0.4 0.6 Time (sec) 0.8 1 1.2
Example of Impulse Response of 2nd order systems: Consider the following Transfer Functions: ( )
29
( ) ( ) ( ) Code to find Impulse Responses of above systems: >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> num1=[1]; den1=[1 8 1]; num2=[1]; den2=[1 1 1]; num3=[1]; den3=[1 2 1]; num4=[1]; den4=[1 0 1]; H1=tf(num1,den1); H2=tf(num2,den2); H3=tf(num3,den3); H4=tf(num4,den4); impulse(H1,H2,H3,H4) axis([0 30 -1.5 1.5]) grid on legend('H1','H2','H3','H4')
Impulse Response
Response:
1.5 H1 1 H2 H3 H4 0.5
Amplitude
-0.5
-1
-1.5
10
15 Time (sec)
20
25
30
************************************************************************
30
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
31
LAB NO.09
Introduction to Simulink
What is Simulink? Simulink is a block diagram environment for multidomain simulation and Model-Based Design. Simulink provides a graphical user interface (GUI) that is used in building block diagrams, performing simulations, as well as analyzing results. Simulink provides a graphical editor, customizable block libraries, and Solvers for modeling and simulating dynamic systems. When we open the Simulink the following window appears which is called Simulink library browser:
32
The Simulink library consists of a lot of devices, elements, instruments and many more equipment related to almost any field of science and engineering. All of them are represented in the form of blocks. We are able to add these blocks while designing a model according to our requirement.
We are going to design a simple model on Simulink which shows the graph of sine wave along with its derivative and integration The modeling consists of the following steps: (i) (ii) Click on the New Model icon Add the following blocks into the New Model window by right clicking on each and adding them: (i) Signal Generator (used to generate sine wave) (ii) Derivative (performs derivation) (iii) Integrator (performs integration) (iv) Gain (used to produce gain) (v) Scope(used to get output) Connect all the blocks as shown in block diagram below The properties of blocks are set by double clicking on them according to followings: (i) (ii) Signal Generator (amplitude=1, frequency=1) Gain (1/(2*pi) for the gain block following derivative block and 2*pi for the gain block following integrator block. This is done to get the same amplitude of the derivative and integration of the sine wave as that of original sine wave Scope (number of axis= 3)
(iii) (iv)
(iii)
After all of the above steps click the Run Simulation button and then double click on the scope the output graph is shown in figure below. Subsystem: By selecting more than one block we can make a subsystem which shows the no. of inputs and outputs as equal to contain by all the blocks closed in it. The subsystem shows a single block the blocks enclosed by it are hidden. The block diagram with subsystems is also shown below.
33
Block Diagram:
Output:
******************************************************************************
34
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
35
LAB NO.10
By double clicking on the Transfer Fcn block set the parameter values as follows:
Now double click the scope and observe the response of the system. The response is shown as follows:
36
******************************************************************************
37
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
38
LAB NO.11
What is Root Locus? Root Locus is the graphical representation of the path of movement of poles in s-plane of a system with feedback when its gain is varied. The root locus gives the closed-loop pole trajectories as a function of the feedback gain k (assuming negative feedback). Root loci are used to study the effects of varying feedback gains on closed-loop pole locations. In turn, these locations provide indirect information on the time and frequency responses.
Command to find Root Locus: The command used to find Root Locus is as follows: rlocus(sys) Where sys is the Transfer Function object of a system in MATLAB.
39
Imaginary Axis
-1
-2
-3
-4 -16
-14
-12
-10
-8
-6
-4
-2
Real Axis
******************************************************************************