From: Luna Moon on
I don't have the toolbox,

how to write my own "autocorr"?

Thanks a lot!
From: us on
On Jul 29, 1:58 pm, Luna Moon <lunamoonm...(a)gmail.com> wrote:
> I don't have the toolbox,
>
> how to write my own "autocorr"?
>
> Thanks a lot!

a hint:

http://en.wikipedia.org/wiki/Autocorrelation

us
From: Wayne King on
Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <ff4a396d-d548-4975-ba35-662180d14d78(a)g19g2000yqc.googlegroups.com>...
> I don't have the toolbox,
>
> how to write my own "autocorr"?
>
> Thanks a lot!

Hi Luna, you can do something like this:

% x is your signal
% numLags is the number of lags you want, e.g. 50,20 etc.
x = detrend(x,0);
xmagDFT = abs(fft(x)).^2;
autocorr = ifft(xmagDFT,'symmetric');
autocorr= autocorr(1:numLags);
% normalize the autocorrelation you may or may not want this
autocorr = autocorr./autocorr(1);

% Example with white noise-- create white noise input and estimate
% its autocorrelation sequence

reset(RandStream.getDefaultStream);
x = randn(512,1);
numLags = 50;
x = detrend(x,0);
xmagDFT = abs(fft(x)).^2;
autocorr = ifft(xmagDFT,'symmetric');
autocorr= autocorr(1:numLags);
% normalize the autocorrelation
autocorr = autocorr./autocorr(1);
stem(autocorr);

Hope that helps,
Wayne