I am calculating the autocorrelation of some signals. Specifically I am using the attached octave code.
This seems to work and is pretty fast, the only problem I think is my normalising. I always understood that after normalising the autocorrelation should be between (inclusively) 1 and -1. However, some of my autocorrelations for some signals will go below -1! Is this possible ... if not ... anyone got any ideas what is wrong with my code.
edit: I think my problem arises with subtracting the means ... whether this should be the mean of all the signal or just 1:end-delta, and if the latter whether it is the signal or the lagged signal.
edit2: I am using the estimate part from wikipedia: http://en.wikipedia.org/wiki/Autocorrelation#Estimation
signal = my signal!
signal = signal - mean(signal);
% Produce a lagged signal
signalLag = shift(signal, numel(signal)-delta);
% Calculate autocorrelation
corr(delta+1) = sum(signal(1:end-delta) .* signalLag(1:end-delta));
corr(delta+1) = corr(delta+1) * (1/ ( (numel(signal)-delta)*var(signal) ) );