clc;
close all;
%%
t = Data.time ; 
u = Data.signals.values(: , 1) ;
x = Data.signals.values(: , 2) ;

figure(1) ;
plot(t , u , t , x , 'LineWidth' , 2) ; 
grid on
xlabel('Time'); ylabel('Amp') ;
title('Input - Output Data') ;
legend('U','X')

%%
y  = x ;
N = numel(t) ; 
M = 4 ;
PHI = zeros(N , M);
Y = zeros(N , 1) ;

for i = 3:N
   PHI(i , :) = [-y(i-1) ,-y(i-2) , u(i-1) , u(i-2)] ; 
   Y(i) = y(i) ;
end

Teta_opt = (PHI'*PHI)^(-1)*PHI'*Y ;

a1 = Teta_opt(1) ;
a2 = Teta_opt(2) ;
b1 = Teta_opt(3) ;
b2 = Teta_opt(4) ;

