You are on page 1of 22

GALANG, ATHALIA ISSIRA G. ECE131L – A21 OCT.

26, 2010

2007100139 / BS ECE – 4 LAB EXER 3

M- FILE FOR ACTIVITIES 1-3(TRANSFER FUNCTION, UNIT-STEP AND IMPULSE


RESPONSE)

%I = inv(A)*A;
if (nz == 1)
syms Y
R = 1/s;
X = ((I)^-1)*(xzero + (B*R));
Y = C*X + D*R;
x = ilaplace(X)
disp('(a.) State Variable, x1(t): ')
x1=x(1);
x1=simple(x1)
subplot(1,4,1)
ezplot (x2, [0 1])
axis tight
title('x1(t)')
%----
disp('(b.) State Variable, x2(t): ')
x2=x(2);
x2=simple(x2)

subplot(1,4,2)
ezplot (x2, [0 1])

axis tight
title('x2(t)')
%---
disp('(c.) State Variable, x3(t): ')
x3=x(3);
x3=simple(x3)

subplot(1,4,3)
ezplot (x3, [0 1])
axis tight
title('x3(t)')

disp('(c.) Y(t): ')


R = 1/t
Y = C*x + D*R
subplot(1,4,4)
ezplot (Y, [0 1]);
axis tight
title('Y(t)')
%-------------------------------------------
else
T = C*((I)^-1)*B +D;
display('T = ')
pretty (T)
display('================================================================')
g = ilaplace(T);
display('Impulse Response= ')
pretty(g)
display('================================================================')
U = (1/s)*(T);
U = ilaplace(U);
display('Step Response= ')
pretty(U)
end

M-FILES(STATE SPACE) and OUTPUT FOR ACTIVITY 1

1.1)

clc
syms s
nz = 0;
A = [-100 1 0; 0 -1.71 1; 0 0 0];
B= [0;0;1325];
C = [1 0 0];
D = 0;
a= eye(3) * s;
I = a - A;

display(' |-100 1 0||x1| | 0|| |')


display(' | 0 -1.71 1||x2| + | 0||r(t)|')
display(' | 0 0 0||x3| |1325|| |')
display(' ')
display(' y = |1 0 0||x1|')
display(' |x2|')
display(' |x3|')
1.2)

clc
syms s
nz = 0;
A = [0 1 0 0 0; 0 0 1 0 0; 0 0 0 1 0; 0 0 0 0 1; -600 -118100 -33480 -3229
-130];
B= [0;0;0;0;10000];
C = [0.06 6.01 1 0 0];
D = 0;
a= eye(5) * s;
I = a - A;

display(' | 0 1 0 0 0||x1| | 0|| |')


display(' | 0 0 1 0 0||x2| + | 0||r(t)|')
display(' | 0 0 0 1 0||x3| | 0|| |')
display(' | 0 0 0 0 1||x4| | 0|| |')
display(' |-600 -118100 -33480 -3229 -130||x5| |10000|| |')
display(' ')
display(' y = |0.06 6.01 1 0 0||x1|')
display(' |x2|')
display(' |x3|')
1.3)

clc
syms s
nz = 0;
A = [0 1 0; 0 0 1; -2 -104 -5];
B= [0;0;1];
C = [2 100 0];
D = 0;
a= eye(3) * s;
I = a - A;

display(' | 0 1 0||x1| | 0|| |')


display(' | 0 0 1||x2| + | 0||r(t)|')
display(' | -2 -104 -5||x3| | 1|| |')
display(' ')
display(' y = |2 100 0||x1|')
display(' |x2|')
display(' |x3|')
1.4)

clc
syms s
nz = 0;
A = [0 1 0 0; 0 0 1 0; 0 0 0 1; -750 -448 -94 -12];
B= [0;0;0;50];
C = [15 8 1 0];
D = 0;
a= eye(4) * s;
I = a - A;
display(' | 0 1 0 0||x1| | 0|| |')
display(' | 0 0 1 0||x2| + | 0||r(t)|')
display(' | 0 0 0 1||x3| | 0|| |')
display(' |-750 -448 -94 -12||x3| | 50|| |')
display(' ')
display(' y = |15 8 1 0||x1|')
display(' |x2|')
display(' |x3|')
1.5)

clc
syms s
nz = 0;
A = [- 20
-500; 1 0];
B = [1; 0];
C = [-0.002 -0.05];
D = [1/10000];
a= eye(2) * s;
I = a - A;

display(' |-20 -500||x1| | 1|| |')


display(' | 1 0||x2| + | 0||v(t)|')
display(' ')
display(' y = |-0.002 -0.05 0||x1|')
display(' |x2|')
M-FILES(STATE SPACE) and OUTPUT FOR ACTIVITY 2

2.1)

clc
syms s
nz = 0;
A = [0 1 0; 0 0 1; 0 -171 -101.71];
B= [0;0;1];
C = [1325 0 0];
D = 0;
a= eye(3) * s;
I = a - A;

display(' | 0 1 0||x1| | 0|| |')


display(' | 0 0 1||x2| + | 0||r(t)|')
display(' | 0 -171 -101.71||x3| | 1|| |')
display(' ')
display(' y = |1325 0 0||x1|')
display(' |x2|')
display(' |x3|')
2.2)

clc
syms s
nz = 0;
A = [-2 0 1; 0 -2 0; 0 0 -3];
B= [0;1;1];
C = [5 5 5];
D = 0;
a= eye(3) * s;
I = a - A;

display(' | -2 0 1||x1| | 0|| |')


display(' | 0 -2 0||x2| + | 1||r(t)|')
display(' | 0 0 -3||x3| | 1|| |')
display(' ')
display(' y = |5 5 5||x1|')
display(' |x2|')
display(' |x3|')
2.3)

clc
syms s
nz = 0;
A = [-2 1 0; 0 -2 0; 0 0 -3];
B= [0;1;1];
C = [5 0 5];
D = 0;
a= eye(3) * s;
I = a - A;

display(' | -2 1 0||x1| | 0|| |')


display(' | 0 -2 0||x2| + | 1||r(t)|')
display(' | 0 0 -3||x3| | 1|| |')
display(' ')
display(' y = |5 0 5||x1|')
display(' |x2|')
display(' |x3|')
2.4)

clc
syms s
nz = 0;
A = [-4 1 0; 0 0 1; 0 0 -3];
B= [0;2;1];
C = [1 0 0];
D = 0;
a= eye(3) * s;
I = a - A;

display(' | -4 1 0||x1| | 0|| |')


display(' | 0 0 1||x2| + | 2||r(t)|')
display(' | 0 0 -3||x3| | 1|| |')
display(' ')
display(' y = |1 0 0||x1|')
display(' |x2|')
display(' |x3|')

2.5)

clc
syms s
nz = 0;
A = [-4 1 0; 0 0 1; -5 0 -3];
B= [1;0;1];
C = [1 0 0];
D = 0;
a= eye(3) * s;
I = a - A;

display(' | -4 1 0||x1| | 1|| |')


display(' | 0 0 1||x2| + | 0||r(t)|')
display(' | -5 0 -3||x3| | 1|| |')
display(' ')
display(' y = |1 0 0||x1|')
display(' |x2|')
display(' |x3|')
M-FILES(STATE SPACE) and OUTPUT FOR ACTIVITY 3

3.1 ) clc
syms s
nz = 1;
A = [0 1 0; 0 0 1; -24 -26 -9];
B= [0;0;1];
C = [1 1 0];
D = 0;
a= eye(3) * s;
I = a - A;
xzero= [1;0;2];

display(' | 0 1 0||x1| | 0|| |')


display(' | 0 0 1||x2| + | 0||r(t)|')
display(' | -24 -26 -9||x3| | 1|| |')
display(' ')
display(' y = |1 1 0||x1|')
display(' |x2|')
display(' |x3|')
display(' ')
display(' | x1(0)| = |1|')
display(' | x2(0)| = |0|')
display(' | x3(0)| = |2|')
M-FILES(STATE SPACE) and OUTPUT FOR ACTIVITY 4

clc
syms t s r R T X Y IR SR plot SV yn yes no

test = [t s];
disp('Note:enter u(t) in s-domain');
disp('Input Variable');
X = input ('Select Domain (Enter t or s): ');
test1 = isequal (X, test(1));
test2 = isequal (X, test(2));
test3 = test1 + test2;
while test3==0
'Input Variable'
X = input ('Select Domain (Enter t or s): ');
test1 = isequal (X, test(1));
test2 = isequal (X, test(2));
test3 = test1 + test2;
end

if X == t
r = input ('Enter R in time domain: ');
R = laplace (r)
T = C*((I)^-1)*B +D;
T = simple(T);
X = ((I)^-1)*(xzero+B*R);
X = simple(X);
x=ilaplace(X);
Y = C*x+D*R;
Y = simple(Y);
IR = ilaplace(T);
SR = ilaplace(T*(1/s));

display('Input')
pretty(R)
disp('Transfer Function')
pretty(T)
disp('State Variables')
pretty(x)
disp('Output')
pretty(Y)
disp('Impulse Response')
pretty(IR)
disp('Step Response')
pretty(SR)
plot = input('What do you want to plot?[R TF Y IR SR SV]: ')
if plot == R
ezplot (r, [0 20]);
elseif plot == TF
ezplot (T, [0 20]);
elseif plot == SV
disp('(a.) State Variable, x1(t): ')
x1=x(1);
x1=simple(x1)
subplot(1,3,1)
ezplot (x2, [0 5])
axis tight
title('x1(t)')
%----
disp('(b.) State Variable, x2(t): ')
x2=x(2);
x2=simple(x2)

subplot(1,3,2)
ezplot (x2, [0 5])

axis tight
title('x2(t)')
%---
disp('(c.) State Variable, x3(t): ')
x3=x(3);
x3=simple(x3)

subplot(1,3,3)
ezplot (x3, [0 5])
axis tight
title('x3(t)')
elseif plot == Y
ezplot (Y, [0 20]);
elseif plot == IR
ezplot (IR, [0 20]);
elseif plot == SR
ezplot (SR, [0 20]);
end
yn = input('Do you want to try again?[yes or no]: ');
if yn == yes;
activity4
elseif yn == no;
end
elseif X == s
R = input ('Enter R in s-domain: ')
T = C*((I)^-1)*B +D;
T = simple(T);
X = ((I)^-1)*(xzero+B*R);
X = simple(X);
x=ilaplace(X);
Y = C*X+D*R;
Y = simple(Y);
IR = ilaplace(T);
SR = ilaplace(T*(1/s));
display('Entered R in s-domain')
pretty(R)
display('Transfer Function')
pretty(T)
display('State Variables')
pretty(x)
display('Output equation')
pretty(Y)
display('Impulse Response')
pretty(IR)
display('Step Response')
pretty(SR)
plot = input('What do you want to plot?[R TF Y IR SR SV]: ')
if plot == R
ezplot (R, [0 20]);
elseif plot == TF
ezplot (T, [0 20]);
elseif plot == SV
disp('(a.) State Variable, x1(t): ')
x1=X(1);
x1=simple(x1)
subplot(1,3,1)
ezplot (x2, [0 5])
axis tight
title('x1(t)')
%----
disp('(b.) State Variable, x2(t): ')
x2=X(2);
x2=simple(x2)

subplot(1,3,2)
ezplot (x2, [0 5])

axis tight
title('x2(t)')
%---
disp('(c.) State Variable, x3(t): ')
x3=X(3);
x3=simple(x3)

subplot(1,3,3)
ezplot (x3, [0 5])
axis tight
title('x3(t)')
elseif plot == Y
ezplot (Y, [0 20]);
elseif plot == IR
ezplot (IR, [0 20]);
elseif plot == SR
ezplot (SR, [0 20]);
end
yn = input('Do you want to try again?[yes or no]: ');
if yn == yes;
activity4
elseif yn == no;
end
else
'Error'
end
SAMPLE OUTPUT FOR T DOMAIN
CONCLUSION:

 Transfer functions can be


represented by using the two
equations, depending if the condition is zero or non-zero.
 Matrices are used to represent the electric system, state space representation and the
signal flow, which were used in the equation of obtaining the transfer function.
 while and if – else function are introduced in this exercise. These were used for choosing
between the t and s-domain condition. These were also used for choosing between the
zero and non-zero condition.
 Same as the previous exercises, ezplot() command was used for plotting the equations.
 MATLAB is very useful for solving and plotting the different equations.

You might also like