% Identification simple
generate_trajectory;
data = dlmread('data.txt');
[~,n]=size(data);
nu = n/2;
ny = n/2;

[A,B,C,result] = scident(data,nu,ny,0.75);
if result>=1 % see "scident.m" for details
    fprintf('From rank condition, n=%d\n\n',result);
else
    fprintf('The dimension being fixed, cos(theta)\n')
    disp(result(1:10))
end
disp([A,B;C,zeros(l,m)])
% Validation
n=size(A,1);
x=zeros(n,1);
for t=1:1000
    u=randn(nu,1);
    x=A*x+B*u;
end
L = 500;
yest = zeros(L,l);
for t=1:L
    u=data(t,1:nu)';
    yest(t,:)=(C*x)';
    x=A*x+B*u;
end
for s=1:ny
    subplot(l,1,s);
    plot(1:L,data(1:L,nu+s),'r',1:L,yest(:,s),'b')
end
