7/30/2019 Matlab Stabiliy Analysis
1/40
MATLAB and Stability Analysis
DEPARTMENT OF BIOTECHNOLOGY ENGINEERING
NASSERELDEEN AHMED KABASHI
[email protected], Tel : Ext. 4524
Sem I, 2012-2013
mailto:[email protected]:[email protected]7/30/2019 Matlab Stabiliy Analysis
2/40
The issue of ensuring the stability of a closed-loop feedback system is central to
control system design. Knowing that an unstable closed-loop system is generally
of no practical value, we seek methods to help us analyze and design stable
systems. A stable system should exhibit a bounded output if the corresponding
input is bounded. This is known as bounded-input, bounded-output stability and
is one of the main topics of this chapter.
The stability of a feedback system is directly related to the location of the rootsof the characteristic equation of the system transfer function. The Routh
Hurwitz method is introduced as a useful tool for assessing system stability. The
technique allows us to compute the number of roots of the characteristic
equation in the right half-plane without actually computing the values of the
roots. Thus we can determine stability without the added computational burden
of determining characteristic root locations. This gives us a design method for
determining values of certain system parameters that will lead to closed-loop
stability. For stable systems we will introduce the notion of relative stability,
which allows us to characterize the degree of stability.
The Stability of Linear Feedback Systems
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
3/40
The Concept of Stability
A stable system is a dynamic system with a bounded response to a
bounded input.
Absolute stability is a stable/not stable characterization for a closed-
loop feedback system. Given that a system is stable we can further
characterize the degree of stability, or the relative stability.
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
4/40
The Concept of Stability
The concept of stability can be
illustrated by a cone placed on
a plane horizontal surface.
A necessary and
sufficient condition for afeedback system to be
stable is that all the
poles of the system
transfer function have
negative real parts.
A system is considered marginally stable if only certain bounded
inputs will result in a bounded output.
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
5/40
BTE 4415Dr. Nassereldeen A. Kabashi
Overview
Linear SISO Control Systems
Differential Equations
Pole Zero Plots
Transfer Equations Routh-Hurwitz Criterion
Root Locus
Bode Plots Nyquist Criterion and Plots
7/30/2019 Matlab Stabiliy Analysis
6/40
BTE 4415 Dr. Nassereldeen A. Kabashi
Linear SISO Control Systems
Closed Loop Control System
Controll
er
+--
+setpoint
load
G1
7/30/2019 Matlab Stabiliy Analysis
7/40
Dr.Nassereldeen A.
Kabashi
Differential Equations
Laplace Transforms
Time-Domain to Frequency-Domain
Use Tables or MATLAB
Sample MATLAB code:syms a s t w x
laplace(t^5) returns 120/s^6
laplace(exp(a*s)) returns 1/(t-a)
laplace(sin(w*x),t) returns w/(t^2+w^2)
laplace(cos(x*w),w,t) returns t/(t^2+x^2)
laplace(x^sym(3/2),t) returns 3/4*pi^(1/2)/t^(5/2)
laplace(diff(sym('F(t)'))) returns laplace(F(t),t,s)*s-F(0)
BTE 4415 Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
8/40
Transient Response Analysis(1)
Transient response refers to the process generated
in going from the initial state to the final state
Transient responses are used to investigate the time
domain characteristics of dynamic systems
Common responses: step response, impulse response,
and ramp response
BTE 4415 Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
9/40
Transient Response Analysis(2)
Unit step response of the transfer function system
Consider the system: 254
252
ss
sH
%*****Numerator & Denominator of H(s)
>>num = [0 0 25];den = [1 4 25];
%*****Specify the computing time
>>t=0:0.1:7;
>>step(num,den,t)
%*****Add grid & title of plot
>>grid
>>title(Unit Step Response of H(s))
7/30/2019 Matlab Stabiliy Analysis
10/40
Transient Response Analysis(3)
Unit step response ofH(s)
Unit Step Response of H(s)
Time (sec)
Amplitude
0 1 2 3 4 5 6 70
0.2
0.4
0.6
0.8
1
1.2
1.4
BTE 4415 Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
11/40
Transient Response Analysis(4)
Alternative way to generate Unit step response of the
transfer function, H(s)
If step input is , then step response is generated
with the following command:
%*****Numerator & Denominator of H(s)
>>num = [0 0 25];den = [1 4 25];%*****Create Model
>>H=tf(num,den);
>>step(H)
>>step(10*H)
)(10 tu
BTE 4415 Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
12/40
Transient Response Analysis(5)
Impulse response of the transfer function system
Consider the system: 254
252
ss
sH
%*****Numerator & Denominator of H(s)
>>num = [0 0 25];den = [1 4 25];
%*****Specify the computing time
>>t=0:0.1:7;
>>impulse(num,den,t)
%*****Add grid & title of plot
>>grid
>>title(Impulse Response of H(s))
7/30/2019 Matlab Stabiliy Analysis
13/40
Transient Response Analysis(6)
Impulse response ofH(s)
Impulse Response of H(s)
Time (sec)
Amplitude
0 1 2 3 4 5 6 7-1
-0.5
0
0.5
1
1.5
2
2.5
3
BTE 4415 Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
14/40
Transient Response Analysis(7)
Ramp response of the transfer function system
Theres no ramp function in Matlab
To obtain ramp response of H(s), divideH(s)by s
and use step function
Consider the system:
For unit-ramp input, . Hence
254
252
ss
sH
2
1)( s
sU
254
251
254
251222
ssssssssY
Indicate Step response
NEW H(s)
7/30/2019 Matlab Stabiliy Analysis
15/40
Transient Response Analysis(8)
Example: Matlab code for Unit Ramp Response
%*****Numerator & Denominator of NEW H(s)
>>num = [0 0 0 25];den = [1 4 25 0];
%*****Specify the computing time
>>t=0:0.1:7;
>>y=step(num,den,t);
%*****Plot input & the ramp response curve
>>plot(t,y,.,t,t,b-)
%*****Add grid & title of plot
>>grid
>>title(Unit Ramp Response Curve of H(s))
7/30/2019 Matlab Stabiliy Analysis
16/40
Transient Response Analysis(9)
Unit Ramp response ofH(s)
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7Unit Ramp Response Curve of H(s)
BTE 4415 Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
17/40
BTE 4415 Dr. Nassereldeen A.Kabashi
Poles & Zeros
In the s-domain a function isplotted on the imaginary axis (y)and the real axis (x)
Roots of q(s) give poles Roots of p(s) give zeros
)()(
)5)(3(210)(
sqsp
sssssY
Sample MATLAB code:>> Y=tf([10 20],[1 8
15 0])
Transfer function:
10 s + 20------------------
s^3 + 8 s^2 + 15 s
>> pzplot(Y)
-6 -5 -4 -3 -2 -1 0 1-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1Pole-Zero Map
Real Axis
ImaginaryAxis
7/30/2019 Matlab Stabiliy Analysis
18/40
BTE 4415Dr. Nassereldeen A. Kabashi
Transfer Functions
10
S+1
1
2s+0.5
0.1
Td
_
+_
+V2
G1 G2
1.0212 VGTG d75.025.1
52
2
ssV
7/30/2019 Matlab Stabiliy Analysis
19/40BTE 4415 Dr. Nassereldeen A. Kabashi
Step Response of TF
Sample MATLAB code:
>> T=tf(5,[1 1.25 0.75]);
>> g=feedback(T,0.1);
>> step(g)
>> h=feedback(T,1);
>> step(h)
0 1 2 3 4 5 6 7 8 90
0.5
1
1.5
2
2.5
3
3.5
4
4.5Step Response
Time (s ec)
Amplitude
0 1 2 3 4 5 6 7 8 90
0.2
0.4
0.6
0.8
1
1.2
1.4Step Response
Time (s ec)
Amplitude
7/30/2019 Matlab Stabiliy Analysis
20/40
BTE 4415Dr. Nassereldeen A. Kabashi
[kd,poles] = rlocfind(numD,denD) and find the stepresponse (the open-loop transfer function is K(s)
H(s)):
numOL = [kd 2]; denOL = [1 1 4 0];
[numCL,denCL] = cloop(numOL,denOL);
step(numCL,denCL)
7/30/2019 Matlab Stabiliy Analysis
21/40
Continue
Compute the poles of G(s)=(3s+1)/(s^2+2s+1) and the response of the system
described by G(s) to a step change of magnitude 2. Plot the response.
% Computation of the poles of G(s)=(3s+1)/(s^2+2s+1)
% Enter the denominator
>>den=[1 2 1];
% Find roots of denominator. They are the poles of G(s)
>>poles=roots(den)
% You may also enter the transfer function and compute the poles directly
>>g1=tf([3 1], [1 2 1])
>>poles2=pole(g1)% Generate the time vector
>>t=0:0.1:20;
% Method 1: Use the function "step".
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
22/40
Then the commands would be:% y=step(g1,t)% xlabel('time')% ylabel('Output')% title('Plot of output as a function of time to a stepinput of magnitude 2')% plot(t,y)step(g1,t);input('After inspecting the figure, close it and pressENTER to continue');pause
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
23/40
Continue
% Clear the current figureclf% Method 2: Use the general simulation function "lsim".
=2*ones(size(t));y=lsim(g1,u,t);
y=step(g1,t);plot(t,y)xlabel('time')ylabel('Output')title('Plot of output as a function of time to a step input of
magnitude 2')% If you use lsim without the left side argument, Matlabgenerates the plot automatically
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
24/40
Continuous Time Transfer Function(1)
Function: Use tffunction create transfer function of
following form:
Example 23
12
)( 2
ss
s
sH
>>num = [2 1];
>>den = [1 3 2];
>>H=tf(num,den)
Transfer function:2 s + 1
-------------
s^2 + 3 s + 2
Matlab Output
7/30/2019 Matlab Stabiliy Analysis
25/40
Continuous Time Transfer Function(2)
Include delay to continuous time Transfer Function
Example
23
12)(
2
2
ss
sesH
s
Transfer function:
2 s + 1
exp(-2*s) * -------------s^2 + 3 s + 2
%*****Numerator & Denominator of H(s)>>num = [2 1];>>den = [1 3 2];
%*****Specify the computing time
>>H=tf(num,den,inputdelay,2)
%*****Add grid & title of plot
Matlab Output
7/30/2019 Matlab Stabiliy Analysis
26/40
Continuous Time Transfer Function(3)
Function: Use zpk function to create transfer function
of following form:
Example 21
5.02
23
12)(
2
ss
s
ss
ssH
>>num = [-0.5];
>>den = [-1 -2];>>k = 2;
>>H=zpk(num,den,k)
Zero/pole/gain:2 (s+0.5)
-----------
(s+1) (s+2)
Matlab Output
7/30/2019 Matlab Stabiliy Analysis
27/40
BTE 4415Dr. Nassereldeen A. Kabashi
MATLAB with PID Controller
BTE
4415
(Biop
rocessControl)
C(S)=Kp
For PI C(S)=Kp + Ki/S
PID C(S)=Kp + Ki/S + Kd S
7/30/2019 Matlab Stabiliy Analysis
28/40
>>Kp=50;>>Ki=1;
>>Kd=10;
>>num=[Kd Kp Ki];
>>den=[1 10 20 0 0];
>>step(num,den)
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
29/40
Continue
>>Kp=500;
>>Ki=1;
>>Kd=100;
>>num1=[Kd Kp Ki];>>den1=[1 0];
>>num2=1;
>>den2=[1 10 20 0];
>>[numc,numd]=cloop(conv(num1,num2),conv(den1,den2),-1);
>>step(numc,denc)
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
30/40
Stability analysis based on the location of the
closed loop poles:
The stability of the closed-loop system can easily be
determined by analyzing the location of the poles
of the closedloop
transfer function. A system is stable if the real partsof the closed-loop poles are negative, i.e. all the
poles are in
the left-hand complex s-plane.
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
31/40
Is the system stable? num=[1, 5]
den=[1, -3, 4, 10, 5, -10]
T=tf(num,den)
poles=roots(den)
poles = 2.1150 + 2.1652i
2.1150 - 2.1652i
-0.9824 + 0.7214i
-0.9824 - 0.7214i
0.7348 Note that the same result is obtained using the LTI structure
[z,p,k]=zpkdata(T,'v')
The system is unstable, since there are poles with positive real part.
Plot the pole locations in the complex s-plane:
pzmap(T)
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
32/40
System Stability Using MATLAB
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
33/40
System Stability Using MATLAB
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
34/40
System Stability Using MATLAB
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
35/40
System Stability Using MATLAB
(a) Stability region for a and K
(b) Matlab Script
BTE 4415Dr. Nassereldeen A. Kabashi
A l th N i t t bilit
7/30/2019 Matlab Stabiliy Analysis
36/40
Apply the Nyquist stability
criterion:
The stability of a feedback system can also be determined
by the behaviour of the open-loop:
a. The open-loop does not have unstable poles; all poles
are in the left-hands-plane.
The closed-loop system is stable if the Nyquist curve of the
open-loop system does not encircle the (1+0j) point.
b. The open-loop does have unstable poles:
The closed-loop system is stable if for the Nyquist curve ofthe open-loop system, the number of counterclockwise
encirclements of the (1+0j) point is equal to the number of
unstable open-loop poles.
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
37/40
The loop transfer function of a system is
The system is in a negative unity feedback control loop. Determine the stability of the closed-loop based on the
Nyquist criterion.
s=tf('s')
L=10/((1+10*s)*(1+s))
[z,p,k]=zpkdata(L,'v')
Does the open-loop have unstable poles? Does the Nyquist diagram ecircle the (1+0j) point? Is the closed-loop
system stable? What happens with stability if the gain 10 in the numerator of the above transfer funcion is increased?
nyquist(L),grid
Verify the result by calculating the poles of the closed-loop system. In the feedback command 1 means unity
feedback and -1 indicates the negative feedback. (The -1 can be ignored since that is the default value)
T=feedback(L,1,-1)
or
T=L/(1+L); T=minreal(T)
The minreal command cancels the zero-pole pairs:
[z,p,k]=zpkdata(T,'v')
Plot the pole locations:
pzmap(T)
As seen the system is structurally stable. The poles are left-side poles, the Nyquist diagram does not encircle the
(1+0j) point even with increased gains.
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
38/40
Phase margin, Gain margin
If the system is stable the degree of stability is an
important system property. The phase margin and gain
margin tells
how far is the system from being marginally stable. The phase margin can be calculated from the phase at
the cut-off frequency
Th t f f ti f t i
7/30/2019 Matlab Stabiliy Analysis
39/40
The transfer function of a system is
BTE 4415Dr. Nassereldeen A. Kabashi
7/30/2019 Matlab Stabiliy Analysis
40/40
Routh Array Matlab
The characteristic polynomial is
There are two sign changes positive to negative and negative to positive
As we go from row to row 3 to row 4 to row 5
Thus there are two roots in the right half plane This is verified by the
MATLAB dialogure: