MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: correlation function

>    ListConvolve and ListCorrelate should give same results when given right parameters.

Hi.  They are very similar, but they do work differently.
It would help if you gave a 'small' example of what you are really trying to do.

Some thoughts on why you are not getting results you expect could be:
-Your FourierParameter is not set correctly.
-You are cutting off your data too much with {1,1}
-You are rotating the second vector, when you don't mean to.

With you large data (ie 309 data points), I get the same results.

v = << Your Data as posted >>


SetOptions[{Fourier,InverseFourier},FourierParameters->{1,-1}] ;





With either way, the above are always equal.  Again, it depends on what you are doing.

>>   ListConvolve and ListCorrelate should give same results

They operate slightly differently.

Here, we don't rotate v2, by using 0, to make it easier to see.


// Here, we keep v2 as is, and shift it right to left

{a^2+b^2+c^2,a b+b c,a c}

// Here, we reverse v2, but shift it left to right
{a^2,2 a b,b^2+2 a c}

// So, they will always be slightly different.  By reversing v2, it's the same as ListConvolve, except we are going left to right.
// This is just the opposite of right to left.    Add 'Reverse to make this equal to ListConvolve.

{a c,a b+b c,a^2+b^2+c^2}

This is the same as ListCorrelate, only backwards.

As a fun side note,  when I've done InverseFourier[Fourier[v]^2 ] in other languages, it was to square a very large number.

For example, to do slow school-method multiplication, one would not chop the data off with {1,1}, but use {1,-1}.

Here's an example of 123 * 123


// Don't rotate  (use 0), and have the last digit of v2 (ie 9), end when it gets to the last digit of v1 (use -1)


//  This is the correct answer in Base 10.  To adjust, for the 12, we keep the 2, and carry the 1.   10+1 == 1, carry the 1,  etc.
//  The function FromDigits with default base 10 does all this for us:


// Same Answer:

Here's a technique to try to see what's going on.  Experiment with ListCorrelate as well.

// Here is what you have
ListConvolve[{a,b,c},{d,e,f},{1,1}] //MatrixForm

// This is what you are really doing.  You're rotating {d,e,f} around.
ListConvolve[{a,b,c},{d,e,f},{1,1},{d,e,f},Times,Plus]  //MatrixForm

// Same, but not adding.
ListConvolve[{a,b,c},{d,e,f},{1,1},{d,e,f},Times,List]  //MatrixForm

// Different Start / End
ListConvolve[{a,b,c},{d,e,f},{1,1},0,Times,List]  //MatrixForm

ListConvolve[{a,b,c},{d,e,f},{1,-1},0,Times,List]  //MatrixForm

Now that I've seen the above, I may have said things backwards with regards to v1,v2.   However, the results are the same.

Good Luck.
= = = = = = = = = =
HTH  :>)
Dana DeLouis
Mac & Mathematica 8
= = = = = = = = = =

On Friday, November 23, 2012 3:38:21 AM UTC-5, jure lapajne wrote:
> Professor (physicist) said this function is called correlation =
function. Than I talked to someone from mathematics department and he =
said it's some sort of discrete convolution, so it really depends on =
person, how he/she calls it. ListConvolve and ListCorrelate should give =
same results when given right parameters. I think there is something =
strange about my data (linked in previous post), because I also have =
some other data and when I use them I get correct (same) results. I =
tried all the code in above answers and with given data nothing works. I =
think I'll just use fourier transform method because it returns =
symmetric data (which is correct) in contrast to ListCorrelate and =
ListConvolve which return asymmetric data.
> Thank you all.

  • Prev by Date: Re: Integer Length Count
  • Next by Date: How to calculate derivative of a vector function
  • Previous by thread: Re: correlation function
  • Next by thread: Re: correlation function