You are on page 1of 67

V R SIDDHARTHA ENGINEERING COLLEGE

EEE DEPARTMENT

MATLAB Applications to
electrical Engineering

S.V.R.LAKSHMI KUMARI P.VENKATESH


ASSOCIATE PROFFSSOR ASSISTANT PROFESSOR

10/2/2015 6:15:50 PM MATLAB PRESENTATION 1


Transfer Function representation

Y (s ) 25
Given: G (s )   2
U (s ) s  4s  25

Matlab function: tf

Method (a) Method (b)

num = [25]; G=tf([25],[1 4 25])


den = [1 4 25];
G = tf(num,den)

2
Transfer Function representation from Zero-Pole-Gain

Y (s ) 3 ( s  1)
H (s )  
U (s ) (s  2  i )(s  2  i )

Matlab function: zpk

zeros = [1];
poles = [2-i 2+i];
gain = 3;
TF = zpk(zeros,poles,gain)

3
Transfer Function from Block
diagram
Series configuration
• To reduce the general feedback system
to a single transfer function:
T(s) = G(s)/(1+G(s)H(s))
[numT,denT]=feedback(numG,denG,numH,denH);
Cont…

• To reduce the series system to a single transfer


function, T(s) = G(s)H(s)
[numT,denT] = series(numG,denG,numH,denH);
• To reduce the parallel system to a single transfer
function, T(s) = G(s) + H(s)
[numT,denT] = parallel(numG,denG,numH,denH);
EXAMPLES :
TRANSFER FUNCTION FROM ZEROS AND POLES

MATLAB PROGRAM :

clc;
z=input('enter zeros');
p=input('enter poles');
k=input('enter gain');
[num,den]=zp2tf(z,p,k)
Tf(num,den)
POLES AND ZEROS FROM TRANSFER FUNCTION

• Command
[z,p,k]=tf2zp(num,den)
Example :

MATLAB program :
clc;
num=[6];
den=[1 6 11 6];
[z,p,k]=tf2zp(num,den)
Partial fraction expansion
2s  3s  2
2
Given:
G (s) 
s  3s  2
2

num=[2 3 2];
den=[1 3 2];
[r,p,k] = residue(num,den)

r= Answer:
-4
1 r (1 ) r (n)
p= G (s)  k (s)   
s  p (1 ) s  p (n)
-2
-1  4 1
 2s  
0
k=
2 s  (2) s  (  1)

21
Transfer Function to State Space representation
Transfer Function to State Space representation

num=[35 7];
den=[1 5 36 7];
g=tf(num,den)
[A,B,C,D]=tf2ss(num,den)

Output :
A=

-5 -36 -7
1 0 0
0 1 0

B=

1
0
0
C=

0 35 7
D=

0
Transfer function from State Space representation
Transfer function from State Space representation
Transfer function from State Space representation
Transfer function from State Space representation
Transfer function from State Space representation

Output:
Program: num =
clc;
a=[8 -3 4;-7 1 0;3 4 -7]; 1.0e+003 *
b=[1;3;8];
c=[1 7 -2]; 0 0.0060 0.0730 -2.8770
d=0;
[num,den]=ss2tf(a,b,c,d)
g=tf(num,den) den =

1.0000 -2.0000 -88.0000 33.0000

Transfer function:
6 s^2 + 73 s - 2877
-----------------------
s^3 - 2 s^2 - 88 s + 33
Response of a system
• First store the numerator and denominator of the
transfer function in num and den, respectively.
• To plot the step response:
step(num,den)
• To plot the impulse response:
impulse(num,den)
Poles and zeros from transfer function
clc;
clear all;
num1=[6 4 3];
denum1=[2 1 3 1];
sys1=tf(num1,denum1)
z=zero(sys1)
p=pole(sys1)
pzmap(sys1)
Output :
Transfer function:
6 s^2 + 4 s + 3
---------------------
2 s^3 + s^2 + 3 s + 1

z=

-0.3333 + 0.6236i
-0.3333 - 0.6236i

p=

-0.0772 + 1.2003i
-0.0772 - 1.2003i
-0.3456
• Program:
clc;
g=tf(3,[1 2])
m=tf([1 1],[1 0])
gc1=feedback(g,1)
gc2=feedback(gc1*m,1)
[y,t]=step(gc2)
plot(t,y)
clc;
g=tf(0.5,[1 1]);
m=2*tf([1 0.4],[1 0]);
h=0.1*tf([1 10],[1 1]);
gc1=feedback(g,h)
gc2=feedback(gc1*m,1)
[y,t]=step(gc2)
plot(t,y)
Program :
clc;
numg=[150];
deng=poly([-5 -7 -9 -11]);
g=tf(numg,deng)
pole(g)
t=feedback(g,1);
pole(t)
Output :
Transfer function:
150
--------------------------------------
s^4 + 32 s^3 + 374 s^2 + 1888 s + 3465

ans =

-11.0000
-9.0000
-7.0000
-5.0000

ans =
-10.9673 + 1.9506i
-10.9673 - 1.9506i
-5.0327 + 1.9506i
-5.0327 - 1.9506i
Obtain the step response for the following system using MATLAB
Program :
clc;
numg=12*[1 3 9];
deng=conv([1 3 9],poly([-1 -5]));
g=tf(numg,deng)
t=feedback(g,1)
step(t)
Step Response for different damping
factors

clc;
fprintf('a=0 for undamped case\n a=1 underdamped case\n a=4 critical damped case\n a=5 overdamped case\n')
a=input('enter the value of a')
g=tf([4],[1 a 4])
step(g)
Step response
clc;
wn=1.0;
t=0:0.1:20;
num=(wn^2);
z1=0; den1=[1 2*z1*wn wn^2];
z2=0.2; den2=[1 2*z2*wn wn^2];
z3=1; den3=[1 2*z3*wn wn^2];
z4=5; den4=[1 2*z4*wn wn^2];
[y1,x,t]=step(num,den1,t);
[y2,x,t]=step(num,den2,t);
[y3,x,t]=step(num,den3,t);
[y4,x,t]=step(num,den4,t);
plot(t,y1,t,y2,t,y3,t,y4);
xlabel('wn--------->');
ylabel('y(t);--------->');
title('Plot for the step response with different damping factors ');
grid
legend('z1=0','z2=0.2','z3=1','z4=5')
Observability and controllability from state model
representation
clc;
A = [0 1; -2/3 -8/3]
B = [0; 1/3]
C = [1 0]
D=0
%To create this state-space system within Matlab, use the ss() function,
%which generates a SYS object, just like the tf() command
sys= ss(A, B, C, D)
% to convert state model into transfer function
sys2 = tf(sys)
%to check controllability
U1 = [B A*B]
U2 = ctrb(sys)
%to chekc observability
U3=obsv(sys)
U4=[C C*A]'
%step response
step(sys)
MATLAB COMMANDS
• -
ss Specify state-space models or convert LTI model to state space
• tf - Create or convert to transfer function model
• zpk - Create or convert to zero-pole-gain model
• bodeplot - Plot Bode frequency response and return plot handle
• impulseplot - Plot impulse response and return plot handle
• nicholsplot - Plot Nichols frequency responses and return plot handle
• nyquistplot - Plot Nyquist frequency responses and return plot handle
• pzplot - Plot pole-zero map of LTI model and return plot handle
• rlocusplot - Plot root locus and return plot handle
• stepplot - Plot step response of LTI systems and return plot handle
• ctrb - Controllability matrix
• obsv - Observability matrix
• rlocus - Evans root locus
MATLAB COMMANDS
• allmargin - All crossover frequencies and corresponding stability margins
• bode - Bode diagram of frequency response
• bodemag - Bode magnitude response of LTI models
• margin - Gain and phase margins and associated crossover frequencies
• nyquist - Nyquist plot of LTI models
• impulse - Impulse response of LTI model
• Step - Step response of LTI systems
• pole - Compute poles of LTI system
• zero - Transmission zeros of LTI model
• pzmap - Compute pole-zero map of LTI models
• ss2tf - Convert state-space filter parameters to transfer function form
• tf2ss - Convert transfer function filter parameters to state-space form
PLOTS

1. For Root Locus plots ------ rlocus(num,den)


2. For Bode plots ------- Bode(num,den)
3. For Nyquist plots -------- nyquist(num,den)
nyquist(A,B,C,D)
Frequency Response Methods Using MATLAB
Gain and Phase Margin

-180
For example,
Obtain the bode plot for the given Transfer function using MATLAB

Tranfer function =50 / (s^3 + 9 s^2 + 30 s + 40)


Program :
sys=tf(50,[ 9 30 40])
bode(sys)
margin(sys)
[Gm,Pm,Wcg,Wcp]=margin(sys)
Output :
Transfer function:
50
-----------------------
s^3 + 9 s^2 + 30 s + 40

Gm = 4.6019

Pm =100.6674

Wcg = 5.4782

Wcp = 1.8483
The Nyquist Stability Criterion

and that the Nyquist diagram can be viewed by typing:


nyquist (50, [1 9 30 40 ])
Root Locus Design GUI (rltool)

The Root Locus Design GUI is an interactive


graphical tool to design compensators using
the root locus method. This GUI plots the
locus of the closed-loop poles as a function of
the compensator gains. You can use this GUI
to add compensator poles and zeros and
analyze how their location affects the root
locus and various time and frequency domain
responses. Click on the various controls on
the GUI to see what they do.
The Characteristics of P, I, and D Controllers
Note that these correlations may not be exactly accurate, because Kp, Ki, and Kd are dependent of each other. In fact,
changing one of these variables can change the effect of the other two. For this reason, the table should only be used
as a reference when you are determining the values for Ki, Kp and Kd.

Response Rise Time Overshoot Settling SS Error


Time
Small
KP Decrease Increase Change Decrease

KI Decrease Increase Increase Eliminate

Small Small
KD Change Decrease Decrease Change

62
Tips for Designing a PID Controller

1. Obtain an open-loop response and determine what needs to be


improved
2. Add a proportional control to improve the rise time
3. Add a derivative control to improve the overshoot
4. Add an integral control to eliminate the steady-state error
5. Adjust each of Kp, Ki, and Kd until you obtain a desired overall response.

Lastly, please keep in mind that you do not need to implement all three controllers
(proportional, derivative, and integral) into a single system, if not necessary. For
example, if a PI controller gives a good enough response (like the above
example), then you don't need to implement derivative controller to the system.
Keep the controller as simple as possible.
Open-Loop Control - Example

1
G( s )
2
s  10 s  20

num=1;
den=[1 10 20];
step(num,den)
Proportional Control - Example

The proportional controller (Kp) reduces the rise time, increases the overshoot, and
reduces the steady-state error.

MATLAB Example
Kp
T(s)
2
s  10  s  ( 20  Kp )

Step Response
From: U(1)
1.4

Kp=300; 1.2 Step Response


From: U(1)
1

num=[Kp]; 1
0.9
Amplitude

0.8 0.8
den=[1 10 20+Kp];
To: Y(1)

0.7
0.6

0.6
t=0:0.01:2;
Amplitude

To: Y(1)
0.4
0.5

K=300 K=100
step(num,den,t) 0.2 0.4

0.3
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0.2
Time (sec.)
0.1

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

Time (sec.)
Proportional - Derivative - Example

The derivative controller (Kd) reduces both the overshoot and the settling time.

MATLAB Example

Kd  s  Kp
T(s)
2
s  ( 10  Kd )  s  ( 20  Kp )
Step Response
From: U(1)
1.4

1.2

Kp=300; 1 Step Response


From: U(1)
1

Kd=10;
Amplitude

0.8
To: Y(1)

0.9

0.6 0.8

num=[Kd Kp]; 0.7


0.4
Kd=10 0.6

Amplitude
den=[1 10+Kd 20+Kp];
To: Y(1)
0.2 0.5

0.4
0

t=0:0.01:2; 0 0.2 0.4 0.6 0.8 1

Time (sec.)
1.2 1.4 1.6 1.8
0.3
2

0.2 Kd=20
step(num,den,t) 0.1

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

Time (sec.)
Proportional - Integral - Example

The integral controller (Ki) decreases the rise time, increases both the overshoot and the
settling time, and eliminates the steady-state error

MATLAB Example
Kp  s  Ki
T(s)
3 2
s  10  s  ( 20  Kp )  s  Ki
Step Response
From: U(1)
1.4

Kp=30;
1.2
Step Response
From: U(1)
1 1.4

Ki=70; 1.2
Amplitude

0.8
To: Y(1)

1
0.6

num=[Kp Ki];
Ki=70
Amplitude
0.8

To: Y(1)
0.4

den=[1 10 20+Kp Ki]; 0.2


0.6

0.4
0

t=0:0.01:2; 0 0.2 0.4 0.6 0.8 1

Time (sec.)
1.2 1.4 1.6 1.8
0.2
2
Ki=100

step(num,den,t) 0
0 0.2 0.4 0.6 0.8 1

Time (sec.)
1.2 1.4 1.6 1.8 2

You might also like