0% found this document useful (0 votes)
108 views

Examples: Using Matlab For Solutions: Transfer It To The Partial Fraction Form)

This document provides examples of using Matlab to analyze and simulate linear time-invariant (LTI) systems. Some key examples include using Matlab commands to: 1) convert transfer functions to partial fraction form and vice versa; 2) find poles, zeros, and gains of a transfer function; 3) simulate and analyze unit step, impulse, and ramp responses of systems; and 4) plot response curves and analyze response characteristics like rise time and settling time. A variety of transfer functions and Matlab code snippets are presented to demonstrate these LTI system analysis techniques.

Uploaded by

Adel Elnabawi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views

Examples: Using Matlab For Solutions: Transfer It To The Partial Fraction Form)

This document provides examples of using Matlab to analyze and simulate linear time-invariant (LTI) systems. Some key examples include using Matlab commands to: 1) convert transfer functions to partial fraction form and vice versa; 2) find poles, zeros, and gains of a transfer function; 3) simulate and analyze unit step, impulse, and ramp responses of systems; and 4) plot response curves and analyze response characteristics like rise time and settling time. A variety of transfer functions and Matlab code snippets are presented to demonstrate these LTI system analysis techniques.

Uploaded by

Adel Elnabawi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

Examples: Using Matlab for Solutions

Consider R(s) / C(s) = ( 2 s^3 + 5 s^2 + 3 s +6 ) / ( s^3 + 6 s^2 + 11 s + 6 )

Transfer it to the partial fraction form


R (s) / C (s) = r(1) / (s p(1) + r(2) / (s-p (2) + .. + r(n) / (s-p(n) + k

num = [ 2 5 3 6 ]
den = [ 1 6 11 6 ]

[ r , p , k ] = residue (num , den)

Answers :
r = - 6.0 - 4.0 3.0
p = -3.0 -2,0 -1.0
K = 2.0

So, R(s) / C(s) = ( 2 s^3 + 5 s^2 + 3 s +6 ) / ( s^3 + 6 s^2 + 11 s + 6 )

R(s) / C(s) = - 6.0 / (s + 3) - 4.0 / (s+2) + 3.0 / (s + 1) + 2

num = [2 5 3 6]
p=

num =
2

den = [1 6 11 6];
[r,p,k] = residue(num,den)
r=
-6.0000
-4.0000
3.0000

-3.0000
-2.0000
-1.0000
k=
2

You can use Matlab in the other direction


By giving the residues and ask for the overall Transfer
Function, Consider :

Use : r = [ - 6 - 4 3 ];
And, p = [ -3 -2 -1 ];
K= 2
Use the Matlab Commands:
[ num, den ] = residue ( r ,p ,k);
printsys (num , den ,s)

r = [-6 -4 3]
r=
-6 -4

p = [-3 -2 -1]
p=
-3 -2 -1
k = [2];
[num,den] = residue(r,p,k);
printsys (num,den,'s');
num/den =
2 s^3 + 5 s^2 + 3 s + 6
----------------------s^3 + 6 s^2 + 11 s + 6

Examples
1- Expand the following into partial fraction using Matlab:
C(s) / R(s) = ( s^2 + 2 s + 3) / ( s + 1 )^3
num = [ 0 1 2 3]
den = [ 1 3 3 1 ]

(r , p , k] = residue (num , den)

C (s) / R (s) = 1 / (s + 1 ) + 0 / ( s + 1 )^2 + 2 / ( s + 1 )^3

num = [ 0 1 2 3 ];
den = [ 1 3 3 1 ];
[ r , p , k ] = residue ( num , den )
r=
1.0000
0.0000
2.0000
p=
-1.0000
-1.0000
-1.0000
k=
[]

To obtain the original function C (s) / R (s) from r , p , k


Enter the following program to the computer

[ num , den ] = residue ( r , p , k )


printsys ( num , den , s )

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


printsys (num , den , 's')
num/den =
s^2 + 2 s + 3
--------------------s^3 + 3 s^2 + 3 s + 1

Finding zeros and poles of C (s) / R (s) using Matlab

[ z , p , k ] = tf2zp ( num , den )

Consider the system defined by :


C (s) / R (s) = ( 4 s^2 + 16 s + 12 ) / ( s^4 + 12 s^3 + 44 s^2 +48 s
To obtain the zeros , poles ,and gain k of C(s) / R (s)

num = [ 0 0 4 16 12 ] ;
den = [ 1 12 44 48 0] ;
[ z , p . K ] = tf2zp ( num , den )

num = [ 0 0 4 16 12 ];

den = [ 1 12 44 48 0 ];
[ z , p , k ] = tf2zp (num ,den)
z=
-3
-1
p=
0
-5.5803 + 1.4302i
-5.5803 - 1.4302i
-0.4197 + 1.1271i
-0.4197 - 1.1271i
k=

If the zeros , poles , and gain are given then the


following Matlab program will yield the original
num / den

Z = [ -1 ; -3 ]
P = [ 0 ; -2 ; -4 ; -6 ];
K=4
[ num , den ] = zp2tf (z , p , k )
Printsys ( num , den , s )

z=
-1
-3
p = [ 0 ; -2 ; -4 ; -6 ];
k=4
k=
4
[ num , den ] = zp2tf ( z , p , k );
printsys (num , den , 's' )

num / den =
4 s^2 + 16 s + 12
---------------------------s^4 + 12 s^3 + 44 s^2 + 48 s

Unit step response

num = [ 0 0 25 ];
den = [ 1 4 25 ];
% ***** Enter the following step response command
step ( num , den )
% ***** Enter grid and title of the plot *************
Grid
Title ( Unit Step Response of G (s) = 25 / ( s^2 + 4s +25) )

% **** unit-step response ******


num = [ 0 0 25 ];
den = [ 1 4 25 ];
step (num , den)
grid
title ( Unit-Step Response of
G (s) = 25 / ( s^2 + 4s + 25) ')

Obtaining Rise Time, Peak Time, Maximum Time


And Settling Time with Matlab.

Consider the system defined by


C (s) / R (s) = 25 / ( s^2 + 6s + 25)

num = [ 0 0 25];
den = [ 1 6 25 ];
step( num , den)

num = [0 0 25];
den = [1 6 25];
t = 0:0.005:5;
[y, x, t] = step (num, den, t);
r =1; while y (r) < 1.0001; r = r + 1; end;
risen _ time = (r - 1) * 0.005

rise _ time =
0.5550
[ymax, tp ] = max (y);
peak _ time = (tp - 1) * 0.005
peak _ time =
0.7850

s = 1001; while y (s) > 0.98 & y (s) < 1.02; s = s - 1; end;
settling _ time = (s - 1) * 0.005
settling _ time =
1.1850

Produce the unit-impulse response


And the resulting plot

Num = [ 0 0 1];
den = [1 0.2 1];
Impulse (num , den )
Grid
Title (Unit-Impulse Response of
G (s) = 1 / ( s^2 + 0.2 s + 1))

num = [ 0 0 1 ];
den = [ 1 0.2 1 ];
impulse (num , den);
grid
title ( Unit - Impulse Response of G (s) = 1
/ ( s^2 + 0.2 s + 1 ) )

Consider the closed loop system defined by :


G (s) = C (s) / R (s) = 1 / ( s^2 + 2 zeta * s + 1)

Zeta = 0, 0.2, 0.4, 0.6, 0.8, 1

% ***** Two dimensional plot and three dimensional plot of unit-step


% response curves for the standard second order system with wn = 1
% and zeta = 0, 0.2, 0.4, 0.6,0.8, 1. ******
t = 0 : 0.2 :10;
zeta = [ 0 0.2 0.4 0.6 0.8 1.0 ];
for n = 1:6;
num = [ 0 0 1 ];
den = [ 1 2*zeta (n) 1];

t = 0 : 0.2 : 10;
zeta = [ 0 0.2 0.4 0.6 0.8 1.0 ];
for n = 1 : 6;
num = [ 0 0 1 ];
den = [ 1 2*zeta(n) 1 ];
[y(1:51,n),x,t] = step(num,den,t);
end
Plot (t,y)
grid

Xlabel ('t (Sec.)')


Ylabel ('Response')
text (4.1,1.86,'/zeta = 0')
text (3.5,1.5,'0.2')
text (3.5,1.24,'0.4')
text (3.5,1.08,'0.6')
text (3.5,0.95,'0.8')

text (3.5,0.86,'1.0')

% To plot a three -dimensional diagram, enter the command mesh (t, zeta, y').
Mesh (t, zeta, y')

title ( 'Three -Dimensional Plot of Unit-Step Response Curves )


xlabel ('t Sec.')
ylabel ('/zeta')
Zlabel ( Response ')

Unit-Impulse Response Matlab program for


G (s) = 1 / ( s^2 + 0.2 s + 1 )

num = [ 0 0 1 ];
den = [ 1 0.2 1 ];
impulse ( num, den );
grid
title (' Unit-Step Response of G (s) = 1 / ( s^2 + 0.2 s +1 )')

Ramp Response

There is no Ramp command in Matlab, So we can use the step command


Instead as follows :

C (s) / R (s) = 1 / ( s^2 + s +1 )


For unit-ramp input R (s) = 1 / s^2
So C (s) = 1 / ( s^2 + s +1 ) . 1 / s^2
To obtain the Unit-ramp Response of this system
Enter the following numerator and denominator

Num = [ 0 0 0 1 ]
Den = [ 1 1 1 0 ]

num = [ 0 0 0 1 ];
den = [ 1 1 1 0 ];

t = 0 : 0.1 : 7;
c = step (num, den, t);

Plot (t, c, 'o ,t, t, '-')


% ******** Add Grid, Title, xlable, ylabel. ********
Grid
title (' Unit-Ramp Response Curve of G(s) = 1 / (s^2 +s + 1)')
Xlabel ('t Sec.')
ylabel ('Input and Output')

You might also like