Question

I'm iterating a single-input-single-output linear system by sending inputs to it and getting outputs from it. The nominator and denominator of the transfer function of the system are represented by Nom and Den in the code respectively.

Nom and Den are calculated after some complex operations on some polynomials, so I don't have prior information on the degree of these polynomials. The only thing I know is that the system is proper (i.e.; the degree of Den is greater than or equal to the degree of Nom).

My code goes like this:

% ...

Nom = (...);  % calculated after some complex operations
Den = (...);  % calculated after some complex operations

[A, B, C, D] = tf2ss(Nom, Den);
x = zeros(size(B));  % state vector
xp = x;              % derivative of the state vector

% ...

for t = 0 : SAMPLING_PERIOD : TIME_END
    % ...
    xp = A * x + B * u;    % 'u' is some scalar input, calculated in the code previously
    y  = C * x + D * u;    % 'y' is some irrelevant output signal, to be used in somewhere else in the code
    x  = xp * SAMPLING_PERIOD;
    % ...
end

% ...

When Den is 0th order (which requires Nom to be 0th order as well), tf2ss() returns empty matrices for A, B, C and D. This is somewhat problematic in my other parts of code. I need these matrices to be at least 1-by-1.

So, my question is, what equivalent non-empty matrices can I use instead of A, B, C and D for those who return empty? For example, can I assume that all empty matrices are 1-by-1 zero matrices?


Example:

[A, B, C, D] = tf2ss([1], [2])
returns
A = [] % Empty matrix
B = [] % Empty matrix
C = [] % Empty matrix
D = 0.5 % 1-by-1 matrix

Was it helpful?

Solution

Ultimelty, you need to understand what the output is providing.

The way the code is written for tf2ss, if size(den) = 1 then a = b =c =[]

The reason for that is because you are no longer providing a differential equation, and are separating the differential equation component from the output.

For your purposes, knowing it's a Single Input Single Output system, A and B can be random matrices, and as long as you have x*C = [0], you should be fine. The idea is there is no real "state to the equation". However, for your purposes, you should instruct Matlab that there is only a single state which is not influenced by it's derivative (i.e. the present state, which is accurate for a pure gain system) with A = B = C = 0

While Matlab may see a difference when building the system, the reality is they are the same:

[A, B, C, D] = tf2ss([1], [2]);
H2 = ss(0,0,0,D);
H1 = ss(A,B,C,D);
bode(H1/ H2)

OTHER TIPS

Empty matrixes are definitely not 1x1 zeros. If you need to mark somehow that the result is not a number, but still have size of 1x1, try returning NaN instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top