[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
autocorrelation
From: |
Francesco Potorti` |
Subject: |
autocorrelation |
Date: |
Mon, 18 Dec 2006 13:46:50 +0100 |
What is the reason why the autocorrelation (autocor.m) is computed with
a for loop rather than using fft?
This is a function that does it for a single column vector. For
matrices, one could iterate over the vectors. For long vectors (my ones
are 200 000 samples long each) this is hundreds time faster.
===File ~/math/octavelib/signal/autocorr.m==================
function A = autocorr(x)
# Given a vector X, computes a vector of the same shape, whose length
# is one less than the argument, representing the autocorrelation of X.
# The autocorrelation is simply the normalised autocovariance.
A = x - mean(x); # detrend
A = fftconv(A, rot90(A,2)); # fft
A = A(length(x) : 2*length(x)-1); # one-side fft
A /= length(x); # this is the autocovariance
A /= A(1); # this is the autocorrelation
endfunction
============================================================
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
Web: http://fly.isti.cnr.it/ Key: fly.isti.cnr.it/public.key
- autocorrelation,
Francesco Potorti` <=