LCS LAB 05 Asfar
LCS LAB 05 Asfar
In this lab, we will be using both MATLAB and LabVIEW to create state space models of
systems and find the responses of systems to various inputs. State space is a method to model
dynamic systems in time-domain and is an alternative to modeling in frequency domain using
Laplace. We will also learn functions in MATLAB that are used to interconnect multiple
systems together.
2. Objectives:
For attempting this lab, we need to remember the things that we learnt in previous labs. We
will be working with the transfer functions of motor and pendulum that we already made in
MATLAB and the DC motor model we made in LabVIEW.
It is expected that after finishing this lab, we will have learnt the basics of state space
modeling in MATLAB and LabVIEW. We will be familiar with how to convert
between frequency domain and state space representations of systems in MATLAB,
how to know the response of various inputs to a system using functions in MATLAB
and blocks in Simulink, determine system response using LabVIEW, and interconnect
systems together.
After completing the lab, the objectives we had set were reasonably achieved. We learnt
new concepts in system modeling.
2|Page
EXERCISE 1
MATLAB CODE
J=1.84*(exp(-6));
m=0.027;
r=0.0826;
Kg=1;
Jm=1.8*exp(-4);
ng=1;
nm=0.69;
L=0.0955;
g=9.8;
Kt=0.0334;
R=8.7;
e=2.178;
a=J+m*(r^2)+ng*J*(Kg^2);
b=m*L*r;
c=(4*m*(L^2))/3;
d=m*g*L;
f=(ng*nm*Kg*Kt)/R;
numS=[f*c 0 -d*f];
denS=[(a*c-b^2) e*c -a*d -e*d];
ms_tf=tf(numS, denS)
ms_ss = ss(ms_tf)
OUTPUT
3|Page
4|Page
MATLAB CODE
OUTPUT
5|Page
6|Page
7|Page
MATLAB CODE
OUTPUT
8|Page
9|Page
Example 2 ( State Space representation of RLC circuit in LabVIEW)
10 | P a g e
EXERCISE 2
MATLAB CODE
num = 11.624;
den = [1 1.193e04];
G_s = tf(num,den);
MATLAB CODE
num = 11.409;
den = [1 1.193e04 0];
G_s = tf(num,den);
MATLAB CODE
a = 3.6605e-04;
b = 2.1298e-04;
c = 3.2833e-04;
d = 0.0253;
e = 2.718;
f = 0.0026;
11 | P a g e
EXERCISE 3
BLOCK DIAGRAM
BLOCK DIAGRAM
12 | P a g e
13 | P a g e
BLOCK DIAGRAM
14 | P a g e
EXERCISE 4
15 | P a g e
EXERCISE 5 (IMPULSE RESPONSE)
MATLAB CODE
num = 11.624;
den = [1 1.193e04];
G_s = tf(num,den);
impulse(G_s);
MATLAB CODE
clear all;
num = 11.409;
den = [1 1.193e04 0];
G_s = tf(num,den);
impulse(G_s);
16 | P a g e
MATLAB CODE
17 | P a g e
EXERCISE 6
MATLAB CODE
num = 11.624;
den = [1 1.193e04];
G_s = tf(num,den);
t = 0:0.1:5;
u = t;
lsim(G_s,u,t);
MATLAB Code
num = 11.624;
den = [1 1.193e04];
G_s = tf(num,den);
T = 5;
[u,t] = gensig("square", T,30,0.1);
18 | P a g e
MATLAB CODE
num = 11.624;
den = [1 1.193e04];
G_s = tf(num,den);
EXERCISE 7
MATLAB CODE
syms s;
step_input = 1/s ; G1 = 11.62/(s+11930);
Gs = G1 * step_input;
res = ilaplace(Gs);
19 | P a g e
OUTPUT
This expression obtained for step response agrees with the plots we had obtained earlier for step
response. The response eventually settles to the value 9.7402e-04 and our plots verify this.
MATLAB CODE
syms s;
ramp_input = 1/(s^2) ; G1 = 11.62/(s+11930);
Gs = G1 * ramp_input;
res = ilaplace(Gs);
OUTPUT
20 | P a g e
21 | P a g e
MATLAB CODE
syms s;
impulse_input = 1; G1 = 11.62/(s+11930);
Gs = G1 * impulse_input;
res = ilaplace(Gs);
OUTPUT
EXERCISE 8
MATLAB CODE
22 | P a g e
num1 = (5);
den1 = (1);
H_s = tf(num1,den1);
num = 11.624;
den = [1 1.193e04];
G_s = tf(num,den);
sys = feedback(G_s,H_s);
23 | P a g e
OUTPUT
24 | P a g e
Conclusion
In this lab, we were presented with novel ideas in system modeling. We developed
state-space models using MATLAB and LabVIEW, and gained insights into the
different responses achievable by implementing diverse inputs in dynamical systems.
The theoretical understanding we acquired regarding state space modeling and
system interconnection can be effectively utilized for modeling systems in software
applications like MATLAB and LabVIEW.
25 | P a g e