Link to home
Start Free TrialLog in
Avatar of Member_2_2394978
Member_2_2394978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Autocorrelation

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

Open in new window

Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

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.
Why don't you want to use xcorr function in Octave?
http://octave.sourceforge.net/signal/function/xcorr.html
Avatar of Member_2_2394978

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of yuk99
yuk99
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.

The matlab help was much better!