How do you extract the state space model from ssest()?

7 vues (au cours des 30 derniers jours)
eddie ball
eddie ball le 17 Juin 2020
Commenté : eddie ball le 17 Juin 2020
How do you extract the state space model from ssest()? Please see the below code :
%% Construct SISO System with input u
A = -1;
B = 1;
C = 1;
D = 0;
time = [0:0.001:10]';
sysTrue = ss(A,B,C,D);
u = ones(length(time),1);
%% Generate output data y
[y] = lsim(sysTrue,u,time);
%% Use ssest() to identify the SISO system
id=iddata(y,u,mean(diff(time)));
A0 = 0;
B0 = 0;
C0 = 1;
D0 = 0;
m = idss(A0,B0,C0,D0);
S=m.Structure;
S.C.Free=false;
S.D.Free=false;
m.Structure=S;
opt = ssestOptions;
opt.EnforceStability=true;
sys1 = ssest(id,m,opt);
%% Extract the A, B, C, and D matricies from sys1 to to put the state space model in a ss class
sys2 = ss(sys1.A,sys1.B,sys1.C,sys1.D);
%% Simulate sys1 and sys2 and compare results to y:
out1 = lsim(sys1,u,time);
out2 = lsim(sys2,u,time);
plot(time,y,time,out1,time,out2)
legend({'y','sys1','sys2'})
xlabel('time (s)')
ylabel('y')
The produces the following plot:
Why do I get different results for sys1 and sys2? Am I not extracting the state space model correctly?
Thanks!
  2 commentaires
Rajiv Singh
Rajiv Singh le 17 Juin 2020
You can directly do sys2 = ss(sys1);
eddie ball
eddie ball le 17 Juin 2020
That works too! Thanks for the tip!

Connectez-vous pour commenter.

Réponse acceptée

M
M le 17 Juin 2020
sys1 is a discrete-time state space model.
If you want to compare the results with sys2, replace your code with:
%% Extract the A, B, C, and D matricies from sys1 to to put the state space model in a ss class
sys2 = ss(sys1.A,sys1.B,sys1.C,sys1.D,sys1.Ts);
You should obtain similar plots for both sys1 and sys2.

Plus de réponses (0)

Catégories

En savoir plus sur Linear Model Identification dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by