Home > database >  Understanding the ss() and tf2ss() functions and their differences
Understanding the ss() and tf2ss() functions and their differences

Time:02-24

Following this question, I am trying to comprehend the functionality of MATLAB's ss() and tf2ss() functions and their differences. Consider the code below:

Kf = 0.2;   
J = 0.02; 

h2 = tf(1, [J Kf]);

dcm1 = ss(h2);
dcm2 = tf2ss(h2.Numerator{1}, h2.Denominator{1}); 

partially copied from here. Now I expect the dcm1 and dcm2 to be identical but here is what I get:

>> dcm1

dcm1 =
 
  A = 
        x1
   x1  -10
 
  B = 
       u1
   x1   8
 
  C = 
         x1
   y1  6.25
 
  D = 
       u1
   y1   0
 
Continuous-time state-space model.

>> dcm2

dcm2 =

   -10

I would appreciate it if you could help me understand why am I getting two different results? how I can have identical results using the tf2ss() function? In other words, I want to create a dcm2 which is identical to dcm1 but using the tf2ss() function.

CodePudding user response:

ss returns a state-space system, similar to tf they both return continuous systems in ss and tf representation respectively.

ss2tf returns the A, B, C, D matrices which are the result of converting the transfer function tf into its state-space representation.

There's one caveat though, the state-space representation of a transfer function is not unique. It seems like Matlab uses two different algorithms for ss and tf2ss. You can verify that both systems return the same transfer function:

Kf = 0.2;   
J = 0.02; 

h2 = tf(1, [J Kf]);

dcm1 = ss(h2);
[A, B, C, D] = tf2ss(h2.Numerator{1}, h2.Denominator{1}); 

dcm1 =

  A = 
        x1
   x1  -10
 
  B = 
       u1
   x1   8
 
  C = 
         x1
   y1  6.25
 
  D = 
       u1
   y1   0

[A, B, C, D]

A = -10
B = 1
C = 50
D = 0

Now let's compare transfer functions:

[b, a] = ss2tf(A, B, C, D)
% yields
b = [0 50]
a = [1 10]

[b, a] = ss2tf(dcm1.a, dcm1.b, dcm1.c, dcm1.d)
% yields
b = [0 50]
a = [1 10]
  • Related