%%%%% Scrap of Matlab code to simulate AR(1)

clear all;
close all;

randn('state',0);   % reset seed of random number generator

%%%%% parameters

S      = 500;   %% length of simulation

phi    = 0.95;  %% AR(1) coefficient
sigeps = 0.015; %% innovation standard deviation

x0     = 0;     %% initial condition

%%%%% draw S realizations from N(0,sigeps^2)

epsilons = sigeps*randn(S,1);

%%%%% iteratively construct sample path

xt    = zeros(S,1);

for s=2:S,

xt(1) = x0;
xt(s) = phi*xt(s-1)+epsilons(s);

end

time = (1:1:S)';

figure(1)
plot(time,xt,'b-',time,zeros(S,1),'k--')
xlabel('time')
ylabel('x(t)')
axis([min(time) max(time) 1.2*min(xt) 1.2*max(xt)])
legend('sample path of AR(1) process')







