State space system gives different bode plot then transfer function matrix

562 Views Asked by At

I have a discrete state space system with matrices $A$,$B$,$C$ and $D$ with sampling period $T_s$.

I can either create a state space system, sys1 = ss(A,B,C,D,Ts), of it or compute the transfer function matrix, sys2 = C*inv(z*I - A)*B + D

However when I draw the bode plot of both systems, they are different while they should be the same.

What is going wrong here? Does anyone have a clue? I know btw that the bodeplot generated by sys1 and sys3 is correct.

clear all;
close all;
clc;

Ts = 0.01;
z = tf('z',Ts);

% Discrete system
A = [0 1 0; 0 0 1; 0.41 -1.21 1.8];
B = [0; 0; 0.01];
C = [7 -73 170];
D = 1;

% Set as state space
sys1 = ss(A,B,C,D,Ts);

% Compute transfer function
sys2 = C*inv(z*eye(3) - A)*B + D;

% Compute the actual transfer function
[num,den] = ss2tf(A,B,C,D);
sys3 = tf(num,den,Ts);

% Show bode
bode(sys1,'b',sys2,'r--',sys3,'g--');

I have noticted that when I compute the denominator by myself, it is correct.

syms z;
collect(det(z*eye(3) - A),z)
1

There are 1 best solutions below

5
On BEST ANSWER

I think (I'm not completely sure) it is related to the numerical inaccuracy of the inverse function used in sys2 and the extra pole/zero pairs introduced by this function. You can check this with the command pole(sys2) and zero(sys2) where you'll notice that there are uncancelled pole/zero pairs. To avoid this if you use the command minreal for minimal realization of the transfer function of your system for sys2 as sys2 = minreal(C*inv(z*eye(3) - A)*B + D); and then run the code you'll see that all bode plots match.