comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: autocorrelation help
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: autocorrelation help [message #82898] Fri, 25 January 2013 15:03 Go to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
On Friday, January 25, 2013 10:52:50 PM UTC+1, Kat wrote:
> Hey guys,
>
> I'm trying to run an autocorrelation on a 2D plot and it is giving me way crazy/bad results. Seems simple enough, but it doesn't seem to be giving me what I should be expecting. I ran the following simple example below:
>
>
>
> a=indgen(100)*.2-2
>
> b=sin(a)
>
> lag=[-7,-6,-5,-4,-3,-2,-1, 1.0,2,3,4,5,6,7]
>
>
>
>
>
> Here are the values in column form for easy viewing:
>
>
>
> ENVI> print, transpose(lag)
>
> -7.00000
>
> -6.00000
>
> -5.00000
>
> -4.00000
>
> -3.00000
>
> -2.00000
>
> -1.00000
>
> 1.00000
>
> 2.00000
>
> 3.00000
>
> 4.00000
>
> 5.00000
>
> 6.00000
>
> 7.00000
>
>
>
> ENVI> print, transpose(autocorr)
>
> 0.777030
>
> 0.808242
>
> 0.839966
>
> 0.872025
>
> 0.904238
>
> 0.936422
>
> 0.968397
>
> 0.968397
>
> 0.936422
>
> 0.904238
>
> 0.872025
>
> 0.839966
>
> 0.808242
>
> 0.777030
>
>
>
> I may be mistaken, but in this instance I have three "sin" type curves which repeat roughly every 6 units. So for lag 6ish, the autocorrelation value should be going back up close to 1-ish. Yet this doesn't seem to be the case in my code.
>
> Can someone help explain to me why this is not working? And hopefully suggest some way to make it work?
>
> Thanks guys!

Several issues here.

First, I don't know what [a,b] is doing in that call. I assume you meant to calculate the autocorrelation of b:

autocorr=a_correlate(b, lag)

Second, sure a sine repeats after 2*!pi = 6 but your sampling is in steps of 0.2, so the sine repeats after 5*2*!pi = 31 array elements so your lag vector is too short for you to see the second peak.

Third, that second peak will be rather attenuated because 31 is a significant part of 100 (the number of elements in your array), so you may want to try this instead:

a=indgen(1000)*.2-2
b=sin(a)
lag=indgen(40)
autocorr=a_correlate(b, lag)
print,autocorr

The result is:
1.00000 0.979339 0.919713 0.823575 0.694829 0.538665
0.361360 0.170019 -0.0277101 -0.223938 -0.410852 -0.581026
-0.727717 -0.845127 -0.928641 -0.975000 -0.982433 -0.950722
-0.881211 -0.776744 -0.641553 -0.481085 -0.301784 -0.110828
0.0841515 0.275381 0.455253 0.616624 0.753107 0.859314
0.931081 0.965615 0.961622 0.919338 0.840526 0.728402
0.587498 0.423488 0.242950 0.0531106

And you can see the second peak at a lag of about 30 elements. Plot autocorr vs the 0.2 sampling and the peak will show up at 2*!pi as it should.
Re: autocorrelation help [message #82993 is a reply to message #82898] Fri, 25 January 2013 15:38 Go to previous message
Oana Coman is currently offline  Oana Coman
Messages: 27
Registered: December 2011
Junior Member
On Friday, January 25, 2013 5:03:54 PM UTC-6, Mats Löfdahl wrote:
> On Friday, January 25, 2013 10:52:50 PM UTC+1, Kat wrote:
>
>> Hey guys,
>
>>
>
>> I'm trying to run an autocorrelation on a 2D plot and it is giving me way crazy/bad results. Seems simple enough, but it doesn't seem to be giving me what I should be expecting. I ran the following simple example below:
>
>>
>
>>
>
>>
>
>> a=indgen(100)*.2-2
>
>>
>
>> b=sin(a)
>
>>
>
>> lag=[-7,-6,-5,-4,-3,-2,-1, 1.0,2,3,4,5,6,7]
>
>>
>
>>
>
>>
>
>>
>
>>
>
>> Here are the values in column form for easy viewing:
>
>>
>
>>
>
>>
>
>> ENVI> print, transpose(lag)
>
>>
>
>> -7.00000
>
>>
>
>> -6.00000
>
>>
>
>> -5.00000
>
>>
>
>> -4.00000
>
>>
>
>> -3.00000
>
>>
>
>> -2.00000
>
>>
>
>> -1.00000
>
>>
>
>> 1.00000
>
>>
>
>> 2.00000
>
>>
>
>> 3.00000
>
>>
>
>> 4.00000
>
>>
>
>> 5.00000
>
>>
>
>> 6.00000
>
>>
>
>> 7.00000
>
>>
>
>>
>
>>
>
>> ENVI> print, transpose(autocorr)
>
>>
>
>> 0.777030
>
>>
>
>> 0.808242
>
>>
>
>> 0.839966
>
>>
>
>> 0.872025
>
>>
>
>> 0.904238
>
>>
>
>> 0.936422
>
>>
>
>> 0.968397
>
>>
>
>> 0.968397
>
>>
>
>> 0.936422
>
>>
>
>> 0.904238
>
>>
>
>> 0.872025
>
>>
>
>> 0.839966
>
>>
>
>> 0.808242
>
>>
>
>> 0.777030
>
>>
>
>>
>
>>
>
>> I may be mistaken, but in this instance I have three "sin" type curves which repeat roughly every 6 units. So for lag 6ish, the autocorrelation value should be going back up close to 1-ish. Yet this doesn't seem to be the case in my code.
>
>>
>
>> Can someone help explain to me why this is not working? And hopefully suggest some way to make it work?
>
>>
>
>> Thanks guys!
>
>
>
> Several issues here.
>
>
>
> First, I don't know what [a,b] is doing in that call. I assume you meant to calculate the autocorrelation of b:
>
>
>
> autocorr=a_correlate(b, lag)
>
>
>
> Second, sure a sine repeats after 2*!pi = 6 but your sampling is in steps of 0.2, so the sine repeats after 5*2*!pi = 31 array elements so your lag vector is too short for you to see the second peak.
>
>
>
> Third, that second peak will be rather attenuated because 31 is a significant part of 100 (the number of elements in your array), so you may want to try this instead:
>
>
>
> a=indgen(1000)*.2-2
>
> b=sin(a)
>
> lag=indgen(40)
>
> autocorr=a_correlate(b, lag)
>
> print,autocorr
>
>
>
> The result is:
>
> 1.00000 0.979339 0.919713 0.823575 0.694829 0.538665
>
> 0.361360 0.170019 -0.0277101 -0.223938 -0.410852 -0.581026
>
> -0.727717 -0.845127 -0.928641 -0.975000 -0.982433 -0.950722
>
> -0.881211 -0.776744 -0.641553 -0.481085 -0.301784 -0.110828
>
> 0.0841515 0.275381 0.455253 0.616624 0.753107 0.859314
>
> 0.931081 0.965615 0.961622 0.919338 0.840526 0.728402
>
> 0.587498 0.423488 0.242950 0.0531106
>
>
>
> And you can see the second peak at a lag of about 30 elements. Plot autocorr vs the 0.2 sampling and the peak will show up at 2*!pi as it should.

Oh! I was confused about what lag actually was.
That makes more sense. Thanks!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: printing comma delimeted file from vectors
Next Topic: resizing array in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:42:59 PDT 2025

Total time taken to generate the page: 0.00671 seconds