function [acM] = autocor(xV, ts, tmax)
% [acM] = autocor(xV, ts, tmax)
% This function computes the autocorrelation of a given time
% series 'xV' and sampling time 'ts' for lags up to 'tmax'. 
% The results are stored in the matrix 'acM' of dimension 
% (1+floor(tmax/ts)) x 2, where at the first column are the 
% lag times and at the second column the corresponding
% autocorrelation.

acM = zeros(tmax+1,2);
acM(:,1) = [0:tmax]'*ts;
n = length(xV);
xm = mean(xV);
yV = xV - xm;
tmpV = xcorr(yV,tmax);
xcovV = tmpV(tmax+1:2*tmax+1);
acM(:,2) = xcovV / xcovV(1);
