1
votes

I was trying to convert using the command ss2tf but the sintax of this command shows where to type the number of inputs of the system, but not the number of outputs. Nevertheless I tried to obtain my matrix transfer function with

[num,den]=ss2tf(Ac,Bc,Cc,Dc,4) where '4' it's the number of inputs.

As a result, the vector "num" has 4x9 dimension and my vector "den" has 1x9 dimension, so I got an error using

F=tf(num,den)

because "den" should have 4x9 dimension aswell.

So, is there another way to obtain transfer function from state space (with the option of including number of inputs and outputs)??

obs: the dimmensions of Ac, Bc, Cc and Dc are, respectively, 8x8; 8x4, 4x8 and 4x4.

edit: figured it out how to solve it. There's an answer below.

4

4 Answers

3
votes

Here is how I should do it. The code is self explaining.

clear all;
close all;
clc;

% Generate random state-space system
sys = rss(2,2,2);

%% Generate transfer function matrix with Matlab tf
% For each output
for i = 1:size(sys,1)

    % For each input
    for j = 1:size(sys,2)

        % Get SISO transfer function
        [num,den] = ss2tf(sys(i,j).A,sys(i,j).B,sys(i,j).C,sys(i,j).D);

        % Compute tf
        Gtf(i,j) = tf(num,den);
    end
end

%% Generate transfer function matrix symbolic
% Laplace variable
s = sym('s');

% For each output
for i = 1:size(sys,1)

    % For each input
    for j = 1:size(sys,2)

        % Get SISO transfer function
        [num,den] = ss2tf(sys(i,j).A,sys(i,j).B,sys(i,j).C,sys(i,j).D);

        % Compute tf
        Gsym(i,j) = poly2sym(num,s);
    end
end

% Den is the same for all elements
Gsym = Gsym / poly2sym(den,s);

% Numeric vectors is transformed to symbolic vector, to make everything
% readable change the variable precision arithmetic to 4 digits for output
pretty(vpa(Gsym,4))

-Edit- I have to say that I am actually a bit surprised that Matlab does not have this functionality incorporated in the function ss2tf itself.

1
votes

If your system has p inputs and q outputs, then the tranfer function matrix G(s) has p lines and qcolumns. Each element pq of G(s) is a SISO transfer function with respect to entrie p and output q.

Let n be the system order. So, if you enter with [b,a] = ss2tf(A,B,C,D,1) you will get b with dimension qx(n+1) and a with dimension 1x(n+1). To obtain the element 1x1 of G(s), you have to obtain the SISO transfer function from the first line of b and the vector a. Similarly, for the element 1x2, you have to obtain the transfer function from the second line of b and the vector a. After you obtain the transfer functions using all lines of b you will have the first line of G(s).

For the other lines you have to enter [b,a] = ss2tf(A,B,C,D,2) (and obtain all SISO transfer functions again), then do [b,a] = ss2tf(A,B,C,D,3) and so on.

Finally, use matrix concatenation to obtain the compact form of G(s), like:

G_s=[g11 g12 g13 ... g1q;g21 g22 ..g2q; ....;gp1 gp2 .. gpq]

0
votes

I think you misunderstood the syntax of the function. Here's what the documentation says:

[b,a] = ss2tf(A,B,C,D) converts a state-space representation of a system into an equivalent transfer function. ss2tf returns the Laplace-transform transfer function for continuous-time systems and the Z-transform transfer function for discrete-time systems. [b,a] = ss2tf(A,B,C,D,ni) returns the transfer function that results when the nith input of a system with multiple inputs is excited by a unit impulse.

So you don't need to specify the number of inputs/outputs, they are implied by the respective sizes of your state-space matrices. Use the first syntax and you should be fine.

0
votes

You don't need to use tf2ss or ss2tf. You just can use

G_s = tf(G);

directly converting from one system representation to the other.