How to convert a transfer function into state space representation?

94 Ansichten (letzte 30 Tage)
Hind Aljallaf
Hind Aljallaf am 1 Mai 2023
Kommentiert: Paul am 23 Feb. 2026 um 23:12
I was trying to convert a transfer function into state space representation, but the matrices in the output are not quiet correct. The numbers are flipped like how in B 0 should be up and 1 should be down, or in C where 2 should be right and 3 should be left. How can I fix this issue?

Antworten (2)

Paul
Paul am 1 Mai 2023
Bearbeitet: Paul am 2 Mai 2023
The state space realization of a transfer function is not unique. In fact, there are infinitely many state space realizations to choose from.
num = [0 3 2];
den = [1 4 4];
The Control System Toolbox uses one methodology
G = ss(tf(num, den))
G = A = x1 x2 x1 -4 -2 x2 2 0 B = u1 x1 2 x2 0 C = x1 x2 y1 1.5 0.5 D = u1 y1 0 Continuous-time state-space model.
and the Signal Processing Toolbox uses another
[A,B,C,D] = tf2ss(num,den)
A = 2×2
-4 -4 1 0
B = 2×1
1 0
C = 1×2
3 2
D = 0
Each realization has the same transfer function
tf(G)
ans = 3 s + 2 ------------- s^2 + 4 s + 4 Continuous-time transfer function.
[b,a] = ss2tf(A,B,C,D)
b = 1×3
0 3.0000 2.0000
a = 1×3
1 4 4
Any other realization can be obtained via similarity transformation. The CST provides a function ss2ss to do that
ss2ss(ss(A,B,C,D),[0 1;1 0])
ans = A = x1 x2 x1 0 1 x2 -4 -4 B = u1 x1 0 x2 1 C = x1 x2 y1 2 3 D = u1 y1 0 Continuous-time state-space model.
tf(ans)
ans = 3 s + 2 ------------- s^2 + 4 s + 4 Continuous-time transfer function.
  1 Kommentar
Paul
Paul am 23 Feb. 2026 um 23:12
It appears that the Control System Toolbox finds a realization with a balance(d) A-matrix, at least in this case. I speculate that such a realization has better numerical properties for operations that are typically performed on such models.
Define a simple transfer function
num = [1,2,3];
den = [1,11,12,13];
The Signal Processing Toolbox returns a realization in a canonical form (offhand, I forget what this form is called). It's easy to convert a transfer function into a canonical form and canonical forms are useful from a theoretical perspective, but, IIRC, they are not preferred numerically.
[a,b,c,d] = tf2ss(num,den);a,b,c
a = 3×3
-11 -12 -13 1 0 0 0 1 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
b = 3×1
1 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
c = 1×3
1 2 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Now balance the a-matrix and get the corresponding transformation matrix.
[T,a] = balance(a);
a
a = 3×3
-11.0000 -3.0000 -1.6250 4.0000 0 0 0 2.0000 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Apply the transformation to the b- and c-matrix
b = T\b
b = 3×1
1 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
c = c*T
c = 1×3
1.0000 0.5000 0.3750
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Show that the transfer function is unaffected (as must be the case with a similarity transformation)
[bb,aa] = ss2tf(a,b,c,0)
bb = 1×4
0 1.0000 2.0000 3.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
aa = 1×4
1.0000 11.0000 12.0000 13.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The CST returns the same result.
sys = ss(tf(num,den))
sys = A = x1 x2 x3 x1 -11 -3 -1.625 x2 4 0 0 x3 0 2 0 B = u1 x1 1 x2 0 x3 0 C = x1 x2 x3 y1 1 0.5 0.375 D = u1 y1 0 Continuous-time state-space model.

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 1 Mai 2023
num = [0 3 2];
den = [1 4 4];
G = tf(num, den);
S = ss(G)
S = A = x1 x2 x1 -4 -2 x2 2 0 B = u1 x1 2 x2 0 C = x1 x2 y1 1.5 0.5 D = u1 y1 0 Continuous-time state-space model.
S.A
ans = 2×2
-4 -2 2 0
S.B
ans = 2×1
2 0
S.C
ans = 1×2
1.5000 0.5000
S.D
ans = 0
[A, B, C, D] = tf2ss(num, den)
A = 2×2
-4 -4 1 0
B = 2×1
1 0
C = 1×2
3 2
D = 0
At the moment I do not kow why the values do not match.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by