How do you extract the state space model from ssest()?
5 次查看(过去 30 天)
显示 更早的评论
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!
采纳的回答
M
2020-6-17
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Model Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!