help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

autocorrelation


From: Francesco Potorti`
Subject: autocorrelation
Date: Thu, 27 Apr 1995 16:55 +0100 (MET)

I wrote:

    I need to compute the autocorrelation of vectors.  I started with the
    following experiment:
    
    kk=[2,3,4,5]
    kk =
    
      2  3  4  5
    
    fftconv(kk,kk)
    ans =
    
       4  12  25  44  46  40  25
    
    I would have expected 
    
       10  23  38  54  38  23  10
    
    instead.  What am I doing wrong?

Vinayak Dutt helped me find the answer, with this explanation:

   fft convolution is a periodic convolution which will give this aliasing
   problems if you try to compute linear convolution.

   if you want to compute linear convolution, pad the vectors to
   M+N-1 (where M and N are the lengths of the two vectors to
   convolve) with zeros and then use the fft method.

   for autocorrelation, just pad to twice the length with zeros.

Here are the two small function I wrote to compute the autocorrelation
and autocovariance of a sequence of data:

------------------------------autocov.oct----------------------------
function A = autoconv(x)
  A = [x, zeros(1, length(x))];
  A = fftconv(A, fliplr(A));
  A = A(2*length(x) : 3*length(x)-1);
endfunction

function A = autocov(x)
  A = [x, zeros(1, length(x))];
  A = fftconv(A, fliplr(A));
  A = A(2*length(x) : 3*length(x)-1) / sumsq(x);
endfunction
---------------------------------------------------------------------

Now:

autoconv([2,3,4,5])
ans =

  54  38  23  10

autocov([2,3,4,5])
ans =

  1.00000  0.70370  0.42593  0.18519


Cmments welcome and solicited.
--
            Francesco Potorti`  | address@hidden (Internet)
                                | 39369::pot (DECnet)
                                | +39-50-593203 (voice) 589354(fax)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]