clc;
close all;
clear;
load ltiexamples
%% tf model
system = Gcl1  ;
Poles = esort(pole(system)) ; 
Zeros = zero(system) ; 
DCgain = dcgain(system) ; 
% pzmap(system) ; 
damp(system) ; 
%% ss model
size(gasf)
% system  = gasf(1 , 2) ;
% system =  ss(Gcl1) ;
system = ss(tf([0.1 1] , poly([-1 -2 -3 -4]))) ; 
system.statename = {'x1','x2','x3','x4'} ; 
A = system.a ; 
B = system.b ; 
C = system.c ;
D = system.d ; 

EIG = eig(A) ;
CTRB = ctrb(A , B) ;
det(CTRB) ; 
OBSV = obsv(A , C) ; 
det(OBSV) ;

T = [1 1 0 0;0 1 1 0;0 0 1 1;-1 0 0 1] ;
system_new = ss2ss(system , T) ; 
system_new.statename = {'z1','z2','z3','z4'}  ; 
Anew = system_new.a ; 

[system_modal , Tmodal] = canon(system , 'modal') ; 
% [system_com , Tcom] = canon(system , 'campanion') ; 

Amodal = system_modal.a  ; 
% Acom = system_com.a 
[system_bal , ~ , Tbal] = balreal(system) ; 
%%
A = [-5 8  0 0;-4 7 0 0;0 0 0 4;0 0 -2 6] ; 
B = [4 -2 2 1]' ; 
C = [2 -2 -2 2] ; 
D = 0 ; 
system = ss(A , B , C , D) ; 
system_tf = zpk(tf(system)) ; 

system_mr = minreal(system) ; 
zpk(system_mr); 

%% order reduction    balred(system , Order)
system = gasf(2,2);
hsvd(system)
system_red = tf(balred(system , 2)) ; 
step(system ,system_red) ;










