Dynamic Systems:

Representations of LTI System

By Prof. Seungchul Lee
http://iai.postech.ac.kr/
Industrial AI Lab at POSTECH

# 1. Transfer Function¶

$$G(s) = \frac{Y(s)}{X(s)}$$

• Equation of motion

$$m\ddot{y} + c\dot{y} + ky = x(t)$$

• Laplace Transform

$$(ms^2 + cs + k)Y(s) = X(s)$$
$$\implies \quad {Y(s)\over X(s)} = {1 \over ms^2 + cs + k} = G(s)$$

• Block Diagram

• Example

$$G(s) = \frac{s+5}{s^4+2s^3+3s^2+4s+5}$$
In [1]:
num = [1,5];
den = [1,2,3,4,5];

G = tf(num,den)

G =

s + 5
-----------------------------
s^4 + 2 s^3 + 3 s^2 + 4 s + 5

Continuous-time transfer function.



# 2. State Space Representation¶

\begin{align*} \dot{x} & = Ax + Bu \\ y & = Cx + Du \end{align*}
In [2]:
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 =
x1     x2     x3     x4
x1   2.25     -5  -1.25   -0.5
x2   2.25  -4.25  -1.25  -0.25
x3   0.25   -0.5  -1.25     -1
x4   1.25  -1.75  -0.25  -0.75

B =
u1  u2
x1   4   6
x2   2   4
x3   2   2
x4   0   2

C =
x1  x2  x3  x4
y1   0   0   0   1
y2   0   2   0   2

D =
u1  u2
y1   0   0
y2   0   0

Continuous-time state-space model.


In [3]:
G.A

ans =

2.2500   -5.0000   -1.2500   -0.5000
2.2500   -4.2500   -1.2500   -0.2500
0.2500   -0.5000   -1.2500   -1.0000
1.2500   -1.7500   -0.2500   -0.7500


$$D(s) = s^4+4s^3+6.25s^2+5.25s + 2.25$$
In [4]:
D = poly(G.A)

D =

1.0000    4.0000    6.2500    5.2500    2.2500



# 3. Three Representations of Linear Systems¶

1) Time domain

2) Frequency domain

3) State space

• In linear system, convolution operation can be converted to product operation through Laplace transform.

## 3.1. Converting from State Space to a Transfer Function¶

• State Space can be represented as below.

\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.

\begin{align*} (sI-A)X(s) &= BU(s) \\ \therefore X(s) &= (sI-A)^{-1}BU(s) \end{align*}

• Substituting equation $X(s)$ into second equation Laplace transformed yields
\begin{align*} Y(s) &= C(sI-A)^{-1}BU(s) + DU(s) \\ &= \left[C(sI-A)^{-1}B + D\right]U(s) \end{align*}

$$\therefore \; T(s) = G(s) = {Y(s) \over U(s)} = C(sI-A)^{-1}B + D$$

• We call the matrix $\left[C(sI-A)^{-1}B + D\right]$ the transfer function matrix.
• Series expansion of $(I - C)^{-1}$

$$(I-C)^{-1} = I + C + C^2 + C^3 + \cdots \;\text{(if series converges)}$$

• Series expansion of $(sI - A)^{-1}$

$$(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$$

• Inverse Laplace transform of $(sI - A)^{-1}$

$$\mathcal{L}^{-1} \left( \frac{I}{s} + \frac{A}{s^2} + \frac{A^2}{s^3} + \cdots \right) = I + At + \frac{(At)^2}{2!} + \cdots = e^{At}$$

• therefore

$$\mathcal{L}\left( e^{At}\right) = (sI - A)^{-1}$$
• Note

• the output in time
$$y(t) = Ce^{At}x(0) + C\int^t_0e^{A(t-\tau)}Bu(\tau)d\tau + Du(t)$$

## 3.2. Transformation of State-Space¶

• State space representations are not unique because we have a lot of freedom in choosing the state vector.
• Selection of the state is quite arbitrary, and not that important
• In fact, given one model, we can transform it to another model that is equivalent in terms of its input-output properties
• To see this, define model of $G_1(s)$ as
\begin{align*} \dot{x} &= Ax + Bu \\ y &= Cx + Du \end{align*}
• Now introduce the new state vector $z$ related to the first state $x$ through the transformation $x = Tz$
• $T$ is an invertible(similarity) transform matrix
\begin{align*} \dot{z} &= T^{-1}\dot{x} = T^{-1}(Ax + Bu) \\ &= T^{-1}(ATz + Bu) \\ &= (T^{-1}AT)z + T^{-1}Bu = \bar{A}z + \bar{B}u \end{align*}$$y = Cx + Du = CTz + Du = \bar{C}z + \bar{D}u$$
• So the new model $G_2(s)$ is
\begin{align*} \dot{z} &= \bar{A}z + \bar{B}u \\ y &= \bar{C}z + \bar{D}u \end{align*}

Give the same transfer function?

• Consider the two transfer functions :
$$G_1(s) = C(sI-A)^{-1}B + D \\ G_2(s) = \bar{C}(sI-\bar{A})^{-1}\bar{B} + \bar{D} \\$$
• Does $G_1(s) \equiv G_2(s)$?
\begin{align*} G_1(s) &= C(sI-A)^{-1}B + D \\ &= C\left(TT^{-1}\right)(sI-A)^{-1}\left(TT^{-1}\right)B+D \\ &= (CT)\left[T^{-1}(sI-A)^{-1}T\right]\left(T^{-1}B\right) + \bar{D} \\ &= \left(\bar{C}\right)\left[T^{-1}(sI-A)T\right]^{-1}\left(\bar{B}\right)+\bar{D} \\ &= \bar{C}(sI-\bar{A})^{-1}\bar{B} + \bar{D} = G_2(s) \end{align*}
• So the transfer function is not changed by putting the state-space model through a similarity transformation
• If $T=S$, transformation to diagonal matrix

## 3.3. Converting a Transfer Function to State Space¶

• How to convert the transfer function to state space?

• We can redraw block diagram like the below

\begin{align*} U(s) &= \left(s^3+a_2s^2+a_1s+a_0 \right)X(s)\\ \\ Y(s) &= \left(b_2s^2+b_1s+b_0 \right)X(s) \end{align*}

• Reverse Laplace transform
\begin{align*} u(t) &= \dddot{x}+a_2\ddot{x}+a_1\dot{x}+a_0x\\ \\ y(t) &= b_2\ddot{x}+b_1\dot{x}+b_0x \end{align*}

• Choose state variable:
A convenient way to choose state variables is to choose the output, $y(t)$, and its $(n-1)$ derivatives as the state variables.

$$\begin{array}{} x_1 = x\\ x_2 = \dot{x}\\ x_3 = \ddot{x} \end{array}$$

\begin{align*} \begin{bmatrix} \dot{x_1}\\ \dot{x_2}\\ \dot{x_3} \end{bmatrix} &= \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ -a_0 & -a_1 & -a_2 \end{bmatrix} \begin{bmatrix} x_1\\ x_2\\ x_3 \end{bmatrix} + \begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix} u(t)\\ \\ y(t) &= \begin{bmatrix} b_0 & b_1 & b_2 \end{bmatrix} \begin{bmatrix} x_1\\ x_2\\ x_3 \end{bmatrix} \end{align*}

• Draw this into a block diagram

# 4. MATLAB Implementation¶

## 4.1. Step Response¶

$$\dot{y} + 5y = 1 \quad \text{for} \quad t \geq 0, \qquad y(0) = 0$$

or

$$\dot{y} + 5y = u(t), \qquad y(0) = 0$$

The solution is given:

$$y(t) = \frac{1}{5}\left( 1-e^{-5t} \right)$$
In [5]:
% 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*}

In [6]:
% 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*}

In [7]:
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*}

In [8]:
% 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')


## 4.2. Impulse Response¶

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$$

In [9]:
% 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*}

In [10]:
% 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*}

In [11]:
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')


## 4.3. Response to a General Input¶

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$$
In [12]:
%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*}

In [13]:
%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')


# 5. The Second ODE Example¶

## 5.1. Step Response¶

$$G(s) = \frac{\omega_{n}^{2}}{s^2+2\zeta \omega_{n}s + \omega_{n}^{2}}$$
In [14]:
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')

G =

1
-----------
s^2 + s + 1

Continuous-time transfer function.


In [15]:
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)


## 5.2. Impulse Response¶

$$G(s) = \frac{10s + 20}{10s^4 + 23s^3 + 26s^2 + 23s + 10}$$
In [16]:
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')

G =

10 s + 20
------------------------------------
10 s^4 + 23 s^3 + 26 s^2 + 23 s + 10

Continuous-time transfer function.



## 5.3. General Response using lsim¶

In [17]:
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


In [18]:
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')


In [19]:
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.

In [20]:
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')


# 6. Model Conversion¶

In [21]:
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)

Gss =

A =
x1  x2  x3  x4
x1   0   1   0   0
x2   0   0  -1   0
x3   0   0   0   1
x4   0   0   5   0

B =
u1
x1   0
x2   1
x3   0
x4  -2

C =
x1  x2  x3  x4
y1   1   0   0   0

D =
u1
y1   0

Continuous-time state-space model.

Gtf =

s^2 - 5.551e-15 s - 3
---------------------
s^4 - 5 s^2

Continuous-time transfer function.


In [22]:
[num,den] = ss2tf(A,B,C,D)

num =

0         0    1.0000   -0.0000   -3.0000

den =

1.0000         0   -5.0000         0         0


In [23]:
[A,B,C,D] = tf2ss(num,den)

A =

0    5.0000         0         0
1.0000         0         0         0
0    1.0000         0         0
0         0    1.0000         0

B =

1
0
0
0

C =

0    1.0000   -0.0000   -3.0000

D =

0


In [24]:
%%javascript
\$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')