close all
clear all
clc

% Data Generation

load AR_data

% T=500;
% s=sqrt(40);
% 
% y=14.7*ones(1,2);
% for t=3:T
%    d(t)=s*randn;
%    y(t)=14.7+1.425*y(t-1)-0.731*y(t-2)+d(t);   
% end
% 
% figure(1), hold on
% plot(y,'b')

% Identification

Y=y(3:end);
N=length(Y);

L=[ones(N,1) y(2:end-1) y(1:end-2)];

% Y=Lp+D, p=[k a1 a2] 

p=L\Y;
k=p(1)
a1=p(2)
a2=p(3)

plot(Y)
hold on
plot(L*p,'r')

