How do you extract the state space model from ssest()?
5 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
M
on 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.
More Answers (0)
See Also
Categories
Find more on Linear Model Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!