function r = nacf(y,M) % This function computes the normalized autocovariance function of a signal y using % the lagged product algorithm for the biased estimator; maximum lag is % M time units, r is an M+1 dimensional vector. Remember a large bias is % induced when M > 0.1N! r = zeros(M+1,1); N = length(y); m = mean(y); var = std(y).^2 *(N-1)/N; for k = 0:M y1 = y(1:N-k) - m; y2 = y(1+k:N) - m; vecsq = y1 .* y2; r(k+1) = (sum(vecsq)/N) / var; % covariance/variance end