You are on page 1of 8

Laboratory Activities in EC 117/ES 117 | Engr. Victorino R. Tobias, Jr.

, MEP-ECE - Instructor

MATLAB ACTIVITIES IN CONTROL SYSTEMS


LAPLACE TRANSFORMATION
The Laplace Transform of a time domain function can be determined in Matlab by using the laplace,
ilaplace and syms commands. The syms instruction tells the matlab to construct symbolic objects.
Example:
The Matlab codes to determine the Laplace transform of et, e-t and sin at are as follows:
In M-file create the following:
syms s a t
% creating symbols s a and t
L1=laplace(exp(t)) % determining laplace of e^t
L2=laplace(exp(-t)) % determining laplace of e^-t
L3=laplace(sin(a*t))% determining laplace of sin at
When the program is run, the output should be:
L1 =
1/(s-1)
L2 =
1/(1+s)
L3 =
a/(s^2+a^2)
The ilaplace command is used to determine the inverse Laplace transform of an s-domain function.
To illustrate the process, create the following codes in M-file. The code determines the inverse
laplace transform of cos 2t and t2.
syms s a t
I1=ilaplace(s/(s^2+4))
I2=ilaplace(2/s^3)
Activity 1
Write a Matlab code to determine the Laplace Transform of the following:
1. cos at
4. t3cos 2t
-2t
2. e
3. e-3t sin 5t
Note: Write your Matlab codes at the back of this page together with the output.

Laboratory Activities in EC 117/ES 117 | Engr. Victorino R. Tobias, Jr., MEP-ECE - Instructor

Activity 2
Write a Matlab code to determine the Inverse Laplace Transform of the following:
4. a/s2+a2

6. 2/(s+2)2

5.
Note: Write your Matlab codes at the back of this page together with the output.

Polynomials (Source: ee.gwnu.ac.kr/bbs/board/down.php?file=13032847790.doc)


In Matlab, a polynomial is represented by a vector. To create a polynomial in Matlab, simply enter
each coefficient of the polynomial into the vector in descending order. For instance, let's say you
have the following polynomial:

s 4 3s 3 15s 2 2s 9
To enter this into Matlab, just enter it as a vector in the following manner
x = [1 3 -15 -2 9]
x=
1 3 -15 -2 9
Matlab can interpret a vector of length (n+1) as an nth order polynomial. Thus, if your polynomial is
missing any coefficients, you must enter zeros in the appropriate place in the vector. For example,

s4 1
would be represented in Matlab as:
y = [1 0 0 0 1]
You can find the value of a polynomial using the polyval( ) function. For example, to find the value
of the above polynomial at s=2,
z = polyval([1 0 0 0 1], 2)
z=
17

Laboratory Activities in EC 117/ES 117 | Engr. Victorino R. Tobias, Jr., MEP-ECE - Instructor

You can also extract the roots of a polynomial. This is useful when you have a high-order
polynomial such as

s 4 3s 3 15s 2 2s 9
Finding the roots would be as easy as entering the following command;
roots([1 3 -15 -2 9])
ans =
-5.5745
2.5836
-0.7951
0.7860
You can also construct a polynomial using poly( ) function.
r = [-1, -2];
p = poly(r);
ans = 1 3 2
You can interpret that the resulting polynomial is given by

s 2 3s 2
Activity 3
1. Write a Matlab code to store the 7th order polynomial:
s7 + 2s6 + s5 + 2s4 + 4s3 + 8s2 + 4s + 2
Also, write a code to determine the value of the polynomial when s = -2.
2. What is the code to determine the roots of the polynomial in no. 1? Record your result.
3. The roots of a certain polynomial are :
0
0.9974 + 1.9667i
0.9974 - 1.9667i
-0.5103 + 2.1782i
-0.5103 - 2.1782i
-1.7668
-1.1036 + 0.9600i
-1.1036 - 0.9600i
Write a Matlab code to display the polynomial.
Note: Write your Matlab codes at the back of this page together with the output.
3

Laboratory Activities in EC 117/ES 117 | Engr. Victorino R. Tobias, Jr., MEP-ECE - Instructor

Partial fraction expansion to perform inverse transform


In Matlab, you can perform partial fraction expansion using residue( ) function. The following is
how to use the residue( ) function:

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


r is PFE coefficients
p is poles
k is direct term

Example
You would like to find the inverse Laplace Transform of F(s) given by

F ( s)

s 2 12
s 3 5s 2 6 s

For this you have to decompose F(s) into simple terms uing partial fraction expansion:
Matlab code
num =[1 0 12];
den = [1 5 6 0];

% Generate numerator polynomial


% Generate denominator polynomial

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


This gives the following answer:
% Result:
r=
7.0000
-8.0000
2.0000
p=
-3.0000
-2.0000
0
k=
[]

Laboratory Activities in EC 117/ES 117 | Engr. Victorino R. Tobias, Jr., MEP-ECE - Instructor

Example
Find the inverse Laplace Transform of

I L ( s)

384 10 5
s( s 2 64,000s 16 108 )

In order to find it, we need to perform partial fraction expansion. The following Matlab M-File
provides us with the partial fraction expansion coefficients.
Matlab code
num = [38400000];
den = [1 64000 1600000000 0];
[r, p, k] = residue(num, den)

This gives the following answer:


r=
-0.0120 + 0.0160i
-0.0120 - 0.0160i
0.0240
p=
1.0e+004 *
-3.2000 + 2.4000i
-3.2000 - 2.4000i
0
k=
[]

24 10 3
20 10 3 126.87
20 10 3 126.87
I L ( s)

s
s 32,000 j 24,000 s 32,000 j 24,000
The above results indicate that we have the following expression for I L (s) : Simple manipulation
shown in the class ends up with the current in the time domain :

i L (t ) 24 10 3 40 10 3 e 32,000t cos(24,000t 126.87 ) [A]


5

Laboratory Activities in EC 117/ES 117 | Engr. Victorino R. Tobias, Jr., MEP-ECE - Instructor

Activity 4
Write a Matlab code to determine the poles of the function below. After which, based from the
poles obtained, find the inverse Laplace transform of the function.

Note: Write your Matlab codes and your answer at the back of this page together with the output.

Time Domain Responses from Transfer Function G(s)


System responses and associated commands
Consider a transfer function shown below:
G(s) = p(s)/q(s) = num(s)/den(s).
We can create a LTI system by using
sys = tf(num,den)
where output sys is the tf object. (Type "help ltiprops" for details.)
Now, we can compute the various time domain responses from the transfer function object using
the following commands:
1) Impulse response
yi = impulse(sys,t)
2) Step response
ys = step(sys,t)
3) Responses to general inputs
yg = lsim(sys,u,t)
Note: t represents time (column) vector, u represents input (column) vector, and yi, ys, and yg are
all column vectors.
Example
Compute the impulse and step response from t = 0 to t = 10 of the following transfer function:
Matlab code

G( s)

10
s 2s 10
2

Laboratory Activities in EC 117/ES 117 | Engr. Victorino R. Tobias, Jr., MEP-ECE - Instructor

t=[0:0.1:10]';
num=10;
den=[1 2 10];
sys = tf(num,den);

% Generate time vector


% Assign numerator polynomial
% Assign denominator polynomial

y_i = impulse(sys,t);
y_s = step(sys,t);

% Compute impulse response


% Compute step response

title('Output of Example')
subplot(2,1,1), plot(t,y_i), ylabel('Impulse response') % plot impulse response
subplot(2,1,2), plot(t,y_s), ylabel('Step response') % plot step response
xlabel('time in seconds')
This gives you the plot below:

In order to compute the response to ramp function and noise, we can do the following procedures.
ramp=t;
noise=rand(101,1);

% Generate ramp function


% Generate 101 by 1 random vector

y_g = lsim(sys,ramp,t);
y_n = lsim(sys,noise,t);

% Compute the response to ramp function


% Compute the response to random noise

figure
7

Laboratory Activities in EC 117/ES 117 | Engr. Victorino R. Tobias, Jr., MEP-ECE - Instructor

title('Output of Example LSIM( )')


subplot(2,1,1), plot(t,y_g), ylabel('Ramp response') % plot response to ramp input
subplot(2,1,2), plot(t,y_n), ylabel('Noise response') % plot response to noise
xlabel('time in seconds')
This gives you the following plot.

Note: Perform all the given examples.

Activity 5
1. Write a Matlab code to determine the impulse and step response from t = 0 to t = 10 of
the system with the following transfer function. Sketch the all the figures generated.

2. Write a Matlab code to generate a ramp and noise signals and sketch the response of the
system with these inputs.
Note: Write your Matlab codes and your answer at the back of this page together with the output.

You might also like