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

4 Ansichten (letzte 30 Tage)
eddie ball
eddie ball am 17 Jun. 2020
Kommentiert: eddie ball am 17 Jun. 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 Kommentare
Rajiv Singh
Rajiv Singh am 17 Jun. 2020
You can directly do sys2 = ss(sys1);
eddie ball
eddie ball am 17 Jun. 2020
That works too! Thanks for the tip!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

M
M am 17 Jun. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Linear Model Identification finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by