# Autocorrelation

on
Hi *,

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.

Any thoughts?

Many thanks,
James

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);
for delta=0:maxDelta
% Produce a lagged signal
signalLag = shift(signal, numel(signal)-delta);
% Calculate autocorrelation
corr(delta+1) = sum(signal(1:end-delta) .* signalLag(1:end-delta));
% Normalise
corr(delta+1) = corr(delta+1) * (1/ ( (numel(signal)-delta)*var(signal) ) );
end
``````
Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Awarded 2010
Top Expert 2013

Commented:
Usually when you normalize something, you fix the range. After you subtract the means, divide all signals by the max absolute value of all the signals. This will give you a more standard normalization and should fix the numbers into the range you are looking for.

Commented:
Why don't you want to use xcorr function in Octave?
http://octave.sourceforge.net/signal/function/xcorr.html

Commented:
Hi,

Thanks for quick responses.

Tommy: I am not sure if this applys here as the normalisation should be specific to the autocorrelation!?

yuk99: I have looked at this and just tried it a second ago. It is useless and gives me complete rubbish results.

Cheers,
James
Commented:
Have you tried to use option argument for scaling options? For example:
xcorr(signal,maxDelta,'coeff')

Probably you can find more informatino in MATLAB's doc (I believe they are compatible):
http://www.mathworks.com/help/toolbox/signal/xcorr.html

Commented:
Thanks.

The matlab help was much better!

Do more with