Lab Matlab
Lab Matlab
Bernard B. Munyazikwiye
Lecturer
University of Rwanda, College of Science and Technology
email: [email protected]
1
Control System Toolbox
2
Outline
• Pole-Zero maps
• Excercises
Transfer Function Model Using Numerator & Denominator
Coefficients
100
G( s )
s 2 14 s 10
This transfer function can be stored into the MATLAB
num = 100;
den = [1 14 10];
sys=tf(num,den)
printsys(num,den);
3/15/2025
Transfer Function Model Using Zeros, Poles and Gain
(ZPK model)
100 ( s 3) K ( s z1 )
G( s )
( s 1)( s 2) ( s p1 )( s p2 )
This transfer function can be stored into the MATLAB
Zeros=-3;
Poles= [-1 -2];
K=100;
sys=zpk(Zeros,Poles,K)
3/15/2025
Poles & Zeros
s 2 3s 5
G( s )
s 2 4s 10
To plot the poles and zeros of any transfer function there is a
built in function pzmap in the MATLAB
pzmap(num,den)
3/15/2025
Series Blocks
• Blocks in series can be simplified by using series command
S 9(S+3)
9S + 17 2S2 + 9s + 27
num1 = [1 0];
den1 = [9 17];
num2 = 9*[1 3];
den2 = [2 9 27];
[num12, den12] = series (num1,den1,num2,den2);
printsys(num12,den12);
3/15/2025
Contd… Series Blocks
S 9(S+3)
9S + 17 2S2 + 9s + 27
num1 = [1 0];
den1 = [9 17];
num2 = 9*[1 3];
den2 = [2 9 27];
num12 =conv(num1,num2);
den12 = conv(,den1,den2);
printsys(num12,den12);
3/15/2025
Parallel Block
num1 = [1 2];
den1 = [1 2 3];
num2 = [1 3];
den2 = [1 -4 1];
[num, den]=parallel(num1,den1,num2,den2);
printsys(num,den);
3/15/2025
Closed-loop transfer function
R(S) 1
- C(S)
S+1
2
num1 = 1; S
den1 = [1 1];
num2 = 2;
den2 = [1 0];
[numcl,dencl] = feedback(num1,den1,num2,den2,-1);
printsys(numcl,dencl)
3/15/2025
Time Response of 1st order Systems
• The first order system has only one pole.
C( s ) K
R( s ) Ts 1
• Where K is the D.C gain and T is the time constant of the system.
• D.C Gain of the system is ratio between the input signal and the
steady state value of output.
Step Response
10
G( s )
3s 1
To obtain the step response of the system
num = 10;
den = [3 1];
step(num,den)
or
num = 10;
den = [3 1];
sys=tf(num, den)
step(sys)
Impulse Response
10
G( s )
3s 1
num = 10;
den = [3 1];
impulse(num,den)
3/15/2025
Ramp Response
10
G( s )
3s 1
3/15/2025
Time Response of 2nd Order Systems
C( s ) n2
2
R( s ) s 2 n s n2
Undamped Natural Frequency &
Damping ratio
• Determine the un-damped natural frequency and damping ratio of
the following second order system.
C( s ) 4
2
R( s ) s 2s 4
To find the undamped natural frequency and damping
ratio in matlab
num=4
den=[1 2 4]
sys=tf(num, den)
damp(sys)
Bode Plots
10( s 10)
G( s)
s( s 2)( s 5)
To obtain the bode plot use following MATLAB code
-50
-100
-90
Phase (deg)
-135
-180
-225
-1 0 1 2
10 10 10 10
Frequency (rad/s)
Bode Plots (for specific Frequency range)
10( s 10)
G( s)
s( s 2)( s 5)
To obtain the bode plot for specific frequency range
w=0.1:0.1:100;
num =10*[1 10];
den1= [1 0];
den2=[1 2];
den3=[1 5];
den12=conv(den1,den2);
den=conv(den12,den3);
bode(num,den,w)
grid on
3/15/2025 19
Bode Plots (for specific Frequency range)
Bode Diagram
50
Magnitude (dB)
-50
-100
-90
Phase (deg)
-135
-180
-225
-1 0 1 2 3
10 10 10 10 10
Frequency (rad/s)
Bode Plots (with left hand arguments)
2500
G( s)
s( s 5)( s 50)
To obtain the Nyquist plot use the following MATLAB code
num =2500;
den1= [1 0];
den2=[1 5];
den3=[1 50];
den12=conv(den1,den2);
den=conv(den12,den3);
nyquist(num,den)
3/15/2025 22
Polar plots or Nyquist plot
Nyquist Diagram
40
30
20
-w
10
Imaginary Axis
-10
-20 w
-30
-40
-2.5 -2 -1.5 -1 -0.5 0
Real Axis
3/15/2025 23
Polar plots or Nyquist plot
2500
G( s)
s( s 5)( s 50)
To adjust the default axes of Nyquist plot use axis command
num =2500;
den1= [1 0];
den2=[1 5];
den3=[1 50];
den12=conv(den1,den2);
den=conv(den12,den3);
nyquist(num,den)
axis([-2.5 0 -2 2])
3/15/2025 24
grid on
Polar plots or Nyquist plot
Nyquist Diagram
2
2 dB 0 dB
1.5
-2 dB
4 dB
1 -4 dB
6 dB
-6 dB
0.5 10 dB -10 dB
Imaginary Axis
20 dB -20 dB
0
-0.5
-1
-1.5
-2
-2.5 -2 -1.5 -1 -0.5 0
3/15/2025 25
Real Axis
Nyquist plot (Open-loop & Closed Loop Frequency Response )
Nyquist Diagram
2
2 dB 0 dB
1.5
-2 dB
4 dB
1 -4 dB
6 dB
-6 dB
0.5 10 dB -10 dB
Imaginary Axis
20 dB -20 dB
0
-1.5
-2
-2.5 -2 -1.5 -1 -0.5 0
Real Axis
Magnitude-Phase plot or Nichols Chart
2500
G( s)
s( s 5)( s 50)
To obtain the Nichols plot use following MATLAB code
num =2500;
den1= [1 0];
den2=[1 5];
den3=[1 50];
den12=conv(den1,den2);
den=conv(den12,den3);
nichols(num,den)
3/15/2025
ngrid 27
Magnitude-Phase plot or Nichols Chart
Nichols Chart
40
0 dB
0.25 dB
0.5 dB
20 1 dB -1 dB
3 dB -3 dB
6 dB
0 -6 dB
-12 dB
-20 dB
Open-Loop Gain (dB)
-20
-40 -40 dB
-60 -60 dB
-80 -80 dB
-100 -100 dB
-120 -120 dB
-140 dB
-140
-360 -315 -270 -225 -180 -135 -90 -45 0
Open-Loop Phase (deg)
Magnitude-Phase plot or Nichols Chart
2500
G( s)
s( s 5)( s 50)
To obtain the Nichols plot use following MATLAB code
num =2500;
den1= [1 0];
den2=[1 5];
den3=[1 50];
den12=conv(den1,den2);
den=conv(den12,den3);
nichols(num,den)
3/15/2025
ngrid; axis([-220 -90 -40 40]) 29
Magnitude-Phase plot or Nichols Chart
Nichols Chart
40
0 dB
30 0.25 dB
0.5 dB
20 1 dB
Open-Loop Gain (dB)
10 3 dB
6 dB
0
-10
-20
-30
-40
-180 -135 -90
Open-Loop Phase (deg)
Nichols Chart
100
40
0 dB
0.25 dB
0.5 dB
20 1 dB -1 dB
Open-Loop Gain (dB)
3 dB
6 dB System: sys -3 dB
Gain (dB): 14.3
0 -6 dB
Phase (deg): -112
Frequency (rad/s): 1.82 -12 dB
-20 -20 dB
-40 -40 dB
-60 -60 dB
-80 -80 dB
-100 dB
-100
-270 -225 -180 -135 -90 -45 0
Open-Loop Phase (deg) -13o
Phase & Gain Margins
To obtain the gain margin and phase use the following mat
lab code.
2500
G( s)
s( s 5)( s 50)
num =2500;
den1= [1 0];
den2=[1 5];
den3=[1 50];
den12=conv(den1,den2);
den=conv(den12,den3)
[GM, PM, wp, wg]=margin(num,den)
Phase & Gain Margins
To obtain the gain margin and phase use the following mat lab code.
2500
G( s)
s( s 5)( s 50)
GM =
5.5000
num =2500;
PM =
den1= [1 0];
31.7124
den2=[1 5];
den3=[1 50];
wp =
den12=conv(den1,den2);
15.8114
den=conv(den12,den3)
[GM, PM, wp, wg]=margin(num,den)
wg =
6.2184
Phase & Gain Margins
To obtain the gain margin and phase use the following mat
lab code.
2500
G( s)
s( s 5)( s 50)
num =2500;
den1= [1 0];
den2=[1 5];
den3=[1 50];
den12=conv(den1,den2);
den=conv(den12,den3)
margin(num,den)
Phase & Gain Margins
Bode Diagram
Gm = 14.8 dB (at 15.8 rad/s) , Pm = 31.7 deg (at 6.22 rad/s)
0
Magnitude (dB)
-50
-100
-90
-135
Phase (deg)
-180
-225
-270
-1 0 1 2 3
10 10 10 10 10
Frequency (rad/s)
System Characteristics (Bode Plot)
System Characteristics (Nyquist Plot)
System Characteristics (Nichol’s Chart)
Root Locus of 1st Order System
R(S ) K C (S )
G(S )
S
Matlab Code
num=1;
den=[1 0];
G=tf(num,den);
rlocus(G)
sgrid
Root Locus of 1st Order System
R(S ) KS C (S )
S 1
num=[1 0];
den=[1 1];
G=tf(num,den);
rlocus(G)
sgrid
Continued…..
Root Locus 2nd order systems
R(S ) K C (S )
S ( S 3)
num=1;
den1=[1 0]; Determine the location of closed
den2=[1 3]; loop poles that will modify the
den=conv(den1,den2); damping ratio to 0.8 and natural
G=tf(num,den);
undapmed frequency to 1.7
r/sec. Also determine the gain K
rlocus(G)
at that point.
sgrid
Root Locus of Higher Order Systems
R(S ) K C (S )
num=1; S ( S 1)( S 2)
den1=[1 0];
den2=[1 1];
den3=[1 2];
den12=conv(den1,den2);
den=conv(den12,den3); Determine the closed loop gain
G=tf(num,den); that would make the system
rlocus(G) marginally stable.
sgrid
Root Locus of a Zero-Pole-Gain Model
R(S ) 3( S 5) C (S )
S ( S 1)( S 2)
k=2;
z=-5;
p=[0 -1 -2];
G=zpk(z,p,k);
rlocus(G)
sgrid
Root Locus of a State-Space Model
x1 5 1 x1 1
x 3 1 x 0u (t )
2 2
x1
y (t ) 1 0 D, where D 0
x2
A=[-5 -1;3 -1];
B=[1;0];
C=[1 0];
D=0;
sys=ss(A,B,C,D);
rlocus(sys)
sgrid
Choosing Desired Gain
2S 3
G(S ) 2
3S 4 S 1
num=[2 3];
den=[3 4 1];
G=tf(num,den);
[kd,poles]=rlocfind(G)
sgrid
Please attach the hard copy of following exercises under the title solution
to lab-6 in your practical book.
EXERCISES
Exercise#1
• Simplify the following block diagram and determine the following
(Assume K=10).
– Closed loop transfer function (C/R)
– Poles
– Zeros
– Pole-zero-map
1
s2
1
s
Exercise#2
• Simplify the following block diagram and determine the following.
– Closed loop transfer function (C/R)
– Poles
– Zeros
1
– Pole-Zero-map
( s 1) 2
+ + 7( s 1) -+
R 10 C
- - s( s 3)
1
( s 1) 2
Exercise-3: Obtain the step and ramp responses
of the following 1st order system for T=1, 2, 3 5,
10 seconds.
2
G( s )
Ts 1
3/15/2025
Exercise-4: Obtain the step and ramp responses
of the following 1st order system for K=1, 5, 10
and 15.
K
G( s )
3s 1
3/15/2025
Exercise-5: Obtain the step response of the
following 1st order system with zero for
(i) K=1, α=4 and T=3 sec
(ii) K=1, α=3 and T=4 sec
(iii) K=1, α=3 and T=3 sec
C ( s ) K (1 s )
R( s ) Ts 1
(iv) And compare the results with system w/o zero
C( s ) K
3/15/2025 R( s ) Ts 1
Exercise#6
Describe the nature of the second-order system response via the value
of the damping ratio for the systems with transfer function
12
1. G ( s ) 2
s 8s 12
16
2. G ( s) 2
s 8s 16
20
3. G ( s ) 2
s 8s 20
52
Exercise-7: Obtain the pole zero map and step response
of the 2nd order system and determine the mode of
damping in the system. If the system is underdamped
obtain the time domain specifications. On the pole zero
map show that corresponding damping ratio and natural
undamped frequency of the poles.
(i) ωn=3 r/s and ζ=1
(ii) ωn=3 r/s and ζ=2
C( s ) n2
(iii) ωn=3 r/s and ζ=0.1 2
R( s ) s 2 n s n2
(iv) ωn=3 r/s and ζ=0.5
(v) ωn=3 r/s and ζ=0
Exercise-8: Obtain the step response of the 2nd order
system if
(i) ωn=0.1 r/s and ζ=0.5
(ii) ωn=0.3 r/s and ζ=0.5
(iii) ωn=0.6 r/s and ζ=0.5
(iv) ωn=1 r/s and ζ=0.5
(v) ωn=1.5 r/s and ζ=0.5
C( s ) n2
2
R( s ) s 2 n s n2
Exercise#9
s 10
2
G( s) 2
5s 2s 25
Polar plots or Nyquist plot
10( s 10)
G( s)
s( s 2)( s 5)
(i) Obtain the Nyquist plot of the following system (when w>0).
(ii) Determine the open-loop & closed-loop magnitude responses
when w=2.5 rad/sec
3/15/2025 58
Exercise-13: - For the following Transfer Function
10( s 10)
G( s)
s( s 2)( s 5)
(i) Obtain the Nichols Chart
(ii) Determine the open-loop as well as closed-loop magnitude and
phase when w=1.39 rad/sec.
3/15/2025 59
Exercise#14
R(S ) KS C (S )
S 1
R(S ) K ( S 2) C (S )
S 1
Exercise#17
R(S ) K ( S 3) C (S )
(1) S ( S 1)
R(S ) K ( S 2)( S 3) C (S )
(2)
S ( S 1)
Exercise#18
Plot the root locus of following systems.
R(S ) K ( S 3) C (S )
S ( S 1)( S 2)
(1)
R(S ) K ( S 3)( S 5) C (S )
S ( S 1)( S 2)
(2)
Exercise#19
4(S 3)
G(S )
(S 1)(S 4)(S 6)
Plot the root Loci for the above ZPK model and find out the
location of closed loop poles for =0.505 and n=8.04 r/sec.
b=0.505;
wn=8.04;
sgrid(b, wn)
axis equal
Exercise#20:
K
G( S )
( S 1)( S 4)
R(S ) K C (S )
S ( S 3)(S 5)(S 7)
3 5S
i) Plot the root Loci for the above system
ii) Determine the gain K at which the system produces sustained
oscillations with frequency 8 rad/sec.