Dynamic Systems:
Representations of LTI System
Table of Contents
$$m\ddot{y} + c\dot{y} + ky = x(t)$$
$$(ms^2 + cs + k)Y(s) = X(s)$$
$$\implies \quad {Y(s)\over X(s)} = {1 \over ms^2 + cs + k} = G(s)$$
num = [1,5];
den = [1,2,3,4,5];
G = tf(num,den)
A = [2.25,-5,-1.25,-0.5;
2.25,-4.25,-1.25,-0.25;
0.25,-0.5,-1.25,-1;
1.25,-1.75,-0.25,-0.75];
B = [4,6;
2,4;
2,2;
0,2];
C = [0,0,0,1;
0,2,0,2];
D = zeros(2,2);
G = ss(A,B,C,D)
G.A
D = poly(G.A)
1) Time domain
2) Frequency domain
3) State space
$$
\begin{align*}
\dot{x} &= Ax + Bu \\
y &= Cx + Du
\end{align*}
$$
Laplace Transform
$$
\begin{align*}
sX(s) &= AX(s) + BU(s) \\
Y(s) &= CX(s) + DU(s)
\end{align*}
$$
Solving for $X(s)$ in the first equation Laplace transformed.
$$(sI - A)^{-1} = \left(\frac{1}{s}\right) \left(I - \frac{A}{s}\right)^{-1} = \frac{I}{s} + \frac{A}{s^2} + \frac{A^2}{s^3} + \cdots$$
Note
Give the same transfer function?
% method 1
% define a system first
num = 1;
den = [1 5];
G = tf(num,den);
[y,tout] = step(G,2);
plot(tout,y,tout,0.2*ones(size(tout)),'k--')
ylim([0,0.3])
xlabel('time')
$$
\begin{align*}
\dot{x} &= -5x + u \\
y &= x
\end{align*}
$$
% method 2
% define a system first
A = -5;
B = 1;
C = 1;
D = 0;
G = ss(A,B,C,D);
t = linspace(0,2,100);
u = ones(size(t));
x0 = 0;
[y,tout] = lsim(G,u,t,x0);
plot(tout,y,tout,0.2*ones(size(tout)),'k--')
ylim([0,0.3])
xlabel('time')
$$
\begin{align*}
&\ddot{y} + 2\zeta\omega_n\dot{y} + \omega^2_n y = \omega^2_n u(t) \\ \\ \implies
&\;G(s) = \frac{\omega^2_n}{s^2 + 2\zeta\omega_n s + \omega^2_n }
\end{align*}
$$
z = 0.2;
wn = 1;
G = tf(wn^2,[1,2*z*wn,wn^2]);
[y,tout] = step(G,16);
plot(tout,y,tout,ones(size(tout)),'k--')
ylim([-0.1 1.6])
xlabel('time')
$$
\begin{align*}
\left[ {\begin{matrix}
\dot{x}_1 \\
\dot{x}_2 \\
\end{matrix} } \right]
&=
\left[ {\begin{matrix}
0 & 1 \\
-\omega_n^2 & -2\zeta \omega_n \\
\end{matrix} } \right]
\left[ {\begin{array}{cc}
x_1 \\
x_2 \\
\end{array} } \right] + \begin{bmatrix}0\\\omega_n^2\end{bmatrix}u \\ \\y & =
\left[ {\begin{matrix}
1 & 0
\end{matrix} } \right]
\left[ {\begin{array}{cc}
x_1 \\
x_2 \\
\end{array} } \right]
\end{align*}
$$
% method 2
% define a system first
zeta = 0.2;
wn = 1;
A = [0, 1;-wn^2, -2*zeta*wn];
B = [0; wn^2];
C = [1, 0];
D = 0;
G = ss(A,B,C,D);
t = linspace(0,16,100);
u = ones(size(t));
x0 = [0; 0];
[y,tout] = lsim(G,u,t,x0);
plot(tout,y,tout,ones(size(tout)),'k--')
ylim([-0.1 1.6])
xlabel('time')
Now think about the impulse response
$$ \dot{y} + 5y = \delta(t), \qquad y(0) = 0 $$The solution is given: (why?)
$$ y(t) = h(t) = e^{-5t},\quad t\geq0$$% method 1
% define a system first
num = 1;
den = [1 5];
G = tf(num,den);
[h,tout] = impulse(G,2);
plot(tout,h), ylim([0,1])
xlabel('time')
$$
\begin{align*}
\dot{x} &= -5x + u \\
y &= x
\end{align*}
$$
% method 2
% define a system first
A = -5;
B = 1;
C = 1;
D = 0;
G = ss(A,B,C,D);
t = linspace(0,2,100);
u = zeros(size(t));
x0 = 1;
[h,tout] = lsim(G,u,t,x0);
plot(tout,h), ylim([0,1])
xlabel('time')
$$
\begin{align*}
&\ddot{y} + 2\zeta\omega_n\dot{y} + \omega^2_n y = \omega^2_n \delta(t) \\ \\ \implies
&\;G(s) = \frac{\omega^2_n}{s^2 + 2\zeta\omega_n s + \omega^2_n }
\end{align*}
$$
z = 0.2;
wn = 1;
G = tf(wn^2,[1,2*z*wn,wn^2]);
[y,tout] = impulse(G,16);
plot(tout,y,tout,zeros(size(tout)),'k--')
ylim([-1 1])
xlabel('time')
Response to a general input
$$ \dot{x} + 5x = u(t), \qquad x(0) = 0 $$The solution is given:
$$ x(t) = h(t)*u(t),\quad t\geq0$$%plot -s 560,350
% generate a general input
[f,t] = gensig('square',4,10,0.01);
plot(t,f), axis([0,9.9,-0.1,1.1])
xlabel('t')
$$
\begin{align*}
\dot{x} &= -5x + u \\
y &= x
\end{align*}
$$
%plot -s 560,350
% use lsim
A = -5;
B = 1;
C = 1;
D = 0;
G = ss(A,B,C,D);
x0 = 0;
[f,t] = gensig('square',4,10,0.01);
[y,tout] = lsim(G,f,t,x0);
plot(t,f), hold on
plot(tout,y), hold off, axis([0,9.9,-0.1,1.1])
xlabel('t')
z = 0.5;
wn = 1;
G = tf(wn^2,[1,2*z*wn,wn^2])
[y,tout] = step(G,12);
plot(tout,y,tout,ones(size(tout)),'--'), ylim([0 1.3])
title('Step response','fontsize',12)
xlabel('time')
wn = 1;
yy = [];
t = 0:.1:12;
zet = [0:0.2:0.9, 1+eps,2,3];
for i = 1:length(zet)
G = tf(wn^2,[1 2*zet(i)*wn,wn^2]);
[y,tout] = step(G,t);
yy = [yy; y'];
end
plot(tout,yy)
G = tf([10 20],[10 23 26 23 10])
[y,tout] = impulse(G, 30);
plot(tout,y,tout,zeros(size(tout)),'--'), ylim([-1.1 1.1])
title('Impulse response', 'fontsize', 12)
xlabel('time')
lsim
¶A = [-20 -40 -60
1 0 0
0 1 0];
B = [1 0 0]';
C = [0 0 1];
D = 0;
sys = ss(A,B,C,D); % construct a system model
t = 0:0.01:10; % simulation time = 10 seconds
u = zeros(size(t)); % no input
X0 = [0.1 0.1 0.1]; % initial conditions of the three states
[y,tout] = lsim(sys, u, t, X0); % simulate and plot the response (the output)
plot(tout,y,tout,zeros(size(tout)),'--'), ylim([-0.1 0.2])
title('Response to Non-Zero Initial Conditions and no Input','fontsize',12)
xlabel('time')
t = 0:0.01:10; % simulation time = 10 seconds
u = ones(size(t)); % u = 1, a step input
[y, tout, X] = lsim(sys,u,t); % simulate
plot(tout,y), ylim([0, 0.02])
title('Step Response with Zero Initial Conditions','fontsize',12)
xlabel('time')
LTI systems have the extremely important property that if the input to the system is sinusoidal, then the output will also be sinusoidal with the same frequency as the input, but with possibly different magnitude and phase. These magnitude and phase differences are a function of frequency and capture what is known as the frequency response of the system.
t = 0:0.01:10; % simulation time = 10 seconds
u = 10*sin(5*t+1); % input as a function of time
[y, tout, X] = lsim(sys,u,t); % simulate
plot(tout,y), ylim([-0.05,0.05])
title('Response to a Sinusoid Input with Zero Initial Conditions','fontsize',12)
xlabel('time')
A = [0 1 0 0;
0 0 -1 0;
0 0 0 1;
0 0 5 0];
B = [0 1 0 -2]';
C = [1 0 0 0];
D = 0;
Gss = ss(A,B,C,D)
Gtf = tf(Gss)
[num,den] = ss2tf(A,B,C,D)
[A,B,C,D] = tf2ss(num,den)
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')