|
|
Re: correlation function
Posted:
Nov 18, 2012 5:16 PM
|
|
> I get different results but have no idea why.
Hi. If I'm not mistaken, you are loosing data with the default settings of Fourier. As a personal technique, since I never remember these, I use these variables.
{ fftDefault={0,1}, fftData={-1,1}, fftSignal={1,-1} };
What you want to do is use Signal {1,-1}
SetOptions[{Fourier,InverseFourier},FourierParameters->fftSignal];
v=RandomInteger[{1,9},8] {6,2,7,7,9,4,5,4}
If we assume your Fourier equation is correct, then what you are doing is really Convolution:
InverseFourier[Fourier[v]^2] {259.,222.,250.,224.,242.,222.,267.,250.}
ListConvolve[v,v,{1,1}] {259,222,250,224,242,222,267,250}
%%==% True
If we assume your Correlation equation is correct, then one way might be:
ListCorrelate[v,v,{1,1}] {276,238,246,221,250,221,246,238}
InverseFourier[Fourier[v]*Fourier[v//Reverse]] //RotateRight {276.,238.,246.,221.,250.,221.,246.,238.}
%%==% True
= = = = = = = = = = HTH :>) Dana DeLouis Mac & Mathematica 8 = = = = = = = = = =
On Sunday, November 18, 2012 4:08:45 AM UTC-5, jure lapajne wrote: > Hello, > > I'm having hard time calculating correlation (autocorrelation) function of > > two lists (list). I'm trying two different ways of calculating it. One way > > is to use fourier transform and second way is to use Mathematica's function > > ListCorrelate. I get different results but have no idea why. Here's my code: > > > > korelacija1 = ListCorrelate[data, data, {1, 1}]; > > korelacija11 = Abs[InverseFourier[Abs[Fourier[data]]^2]]; > > > > All elements of "data" are real. I have two Abs in second line because for some reason InverseFourier returns small imaginary parts - I know it shouldn't. It's probably only numerical error. > > > > Thanks for help.
|
|