% eda09_03
% load the neuse.txt data set
% compute and plot autocorrelation

D=load('neuse.txt');
t=D(:,1);
d=D(:,2);
N=length(d);
Dt=1;

% demean the data
d=d-mean(d);

% compute the auto-correlation
a = xcorr(d);
tau = Dt*[-N+1:N-1]';
Nk = [1:N, N-1:-1:1]';

% correction for length of timeseries
a = a ./ Nk;

figure(1);
clf;

subplot(2,1,1);
set(gca,'LineWidth',2);
hold on;

axis( [ -30, 30, 0, 1.1*max(a) ] );
plot( tau, a, 'k-', 'LineWidth', 2 );
xlabel('lag, days');
ylabel('autocorrelation');

subplot(2,1,2);
set(gca,'LineWidth',2);
hold on;

axis( [ -365.25*10, 365.25*10, -1.1*max(a), 1.1*max(a) ] );
plot( tau, a, 'k-', 'LineWidth', 2 );
xlabel('lag, days');
ylabel('autocorrelation');

