CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Reagrding autocorrelation

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By flotus1

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 1, 2020, 10:53
Default Reagrding autocorrelation
  #1
Senior Member
 
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7
ari003 is on a distinguished road
To have a proper understanding I started with a short dataframe where the 2nd column represensts velocity at different time-step collected from a probe (for example). And I m trying to plot the correlation function with time lag.
PHP Code:
time    U
1    10.22
2    10.54
3    10.15
4    10.87
5    10.24
6    10.35
7    10.45
8    10.75
9    10.58
10    10.4 

r(s)=⟨U(t)U(t+S)⟩/⟨⋃(t)^2 ⟩

And the above formula is my auto-correlation function where τ is my time lag.
Now as far my my knowledge it is calculated as follows (explaining with this example).
1. The denominator is just when τ =0. So
Quote:
<u(1)*u(1)+u(2)*u(2)…….u(10)*u(10)>
In this way we found the mean <u2>.

2. The τ = 0 to 10
Quote:
For r(0)= <u2>/<u2> =1
For r(1)= <u(1)u(2)+u(2)u(3)……+u(8)u(9)+u(9)u(10)>/ <u2>.
Similarly it will be on till 10 where finally r(10)=0

Now my questions are:-
1. Does this procedure really happen like this?
2. If so then I tried it in MATLAB and it gave results with negative( whereas my U are all positive). How is that possible?

I ve attached a word doc for better understanding of my doubt. Will be really helpful if someone helps.
Attached Files
File Type: docx Doubt.docx (33.5 KB, 8 views)
ari003 is offline   Reply With Quote

Old   October 1, 2020, 16:29
Default
  #2
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
Not sure which matlab function you used here. Or what the default behavior of matlab is with that function.
But there is some degree of ambiguity when it comes to evaluating autocorrelation. Just look at all the options gnu octave provides: https://octave.sourceforge.io/signal...ion/xcorr.html
On top of those, one could also remove the mean value before computing an autocorrelation. Maybe that's what your matlab call was doing, and why it gave negative values.
Among all those options (including your normalization with the value for tau=0), there is no definitive "right" or "wrong" way of computing an autocorrelation. Each of the options just highlights different properties of the signal. Which one is right for you mostly depends on what you want to do with the autocorrelation values.
flotus1 is offline   Reply With Quote

Old   October 2, 2020, 05:36
Default
  #3
Member
 
EM
Join Date: Sep 2019
Posts: 59
Rep Power: 7
gnwt4a is on a distinguished road
for calculating the correlation u need to subtract out the mean. so negative values are possible and sane. negative correlation means that for certain separation in time/space, the product of values above (or below) the average with those below (or above) the average are outsumming the other combination.
--
gnwt4a is offline   Reply With Quote

Old   October 2, 2020, 05:44
Default
  #4
Senior Member
 
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7
ari003 is on a distinguished road
Quote:
Originally Posted by gnwt4a View Post
for calculating the correlation u need to subtract out the mean. so negative values are possible and sane. negative correlation means that for certain separation in time/space, the product of values above (or below) the average with those below (or above) the average are outsumming the other combination.
--
Thank you for your response. Then the value of negetive makes sense if it is substracted out of mean but in the formula of turbulence autocorrelation where should I use that mean tern to substract?
Quote:
r(s)=⟨U(t)U(t+S)⟩/⟨⋃(t)^2 ⟩
I mean here in this equation. The mean is just divided not substracted.
ari003 is offline   Reply With Quote

Old   October 2, 2020, 06:02
Default
  #5
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
Not like that. You are dividing by the sum of squares. Removing the mean in this context: calculate the mean value of your signal, subtract that from each value of your signal, then go on to calculate autocorrelations with the result.
flotus1 is offline   Reply With Quote

Old   October 2, 2020, 06:25
Default
  #6
Senior Member
 
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7
ari003 is on a distinguished road
Quote:
Originally Posted by flotus1 View Post
Not like that. You are dividing by the sum of squares. Removing the mean in this context: calculate the mean value of your signal, subtract that from each value of your signal, then go on to calculate autocorrelations with the result.

Lets say
Quote:

U
0 10.22
1 10.54
2 10.15
3 10.87
4 10.24
5 10.35
6 10.45
7 10.75
8 10.58
9 10.4





U
0 -0.23499999999999943
1 0.08499999999999908
2 -0.3049999999999997
3 0.41499999999999915
4 -0.21499999999999986
5 -0.10500000000000043
6 -0.005000000000000782
7 0.29499999999999993
8 0.125
9 -0.054999999999999716
If the 2nd series represents U(t)-U(mean) then we should proceed with the autocorrelation with the 2nd series right?
But I just plotted the thing in python just now both gave the same autocorr plot.
ari003 is offline   Reply With Quote

Old   October 2, 2020, 06:31
Default
  #7
Member
 
EM
Join Date: Sep 2019
Posts: 59
Rep Power: 7
gnwt4a is on a distinguished road
that was fast.


1) find the mean of the u values.


2) from every u value subtract out the above mean. you will find negative values appearing.


3) calculate the autocorrelation which should be the same as the matlab one.



warning: i have not used matlab. it is very likely that matlab assumes periodicity in the data so that its calculation is 'wrapped' round.
--
gnwt4a is offline   Reply With Quote

Old   October 2, 2020, 06:33
Default
  #8
Senior Member
 
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7
ari003 is on a distinguished road
Quote:
Originally Posted by gnwt4a View Post
that was fast.


1) find the mean of the u values.


2) from every u value subtract out the above mean. you will find negative values appearing.


3) calculate the autocorrelation which should be the same as the matlab one.



warning: i have not used matlab. it is very likely that matlab assumes periodicity in the data so that its calculation is 'wrapped' round.
--
Yaa that s what I did and shared in my previous comment. Thanks a lot for your valuable time.
ari003 is offline   Reply With Quote

Old   October 2, 2020, 07:01
Default
  #9
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
Quote:
Originally Posted by ari003 View Post
But I just plotted the thing in python just now both gave the same autocorr plot.
Both... which ones are you referring to exactly?
If you plugged both your original series and the series with zero mean into your matlab call, then we have confirmation that whatever you used in matlab to get autocorrelations, does indeed remove mean values first. Maybe it's time to read the documentation now. Or share which call you used in matlab.
flotus1 is offline   Reply With Quote

Old   October 2, 2020, 08:15
Default
  #10
Senior Member
 
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7
ari003 is on a distinguished road
Quote:
Originally Posted by flotus1 View Post
Both... which ones are you referring to exactly?
If you plugged both your original series and the series with zero mean into your matlab call, then we have confirmation that whatever you used in matlab to get autocorrelations, does indeed remove mean values first. Maybe it's time to read the documentation now. Or share which call you used in matlab.

This one is my original series :
Quote:

U
0 10.22
1 10.54
2 10.15
3 10.87
4 10.24
5 10.35
6 10.45
7 10.75
8 10.58
9 10.4

This one is after deducting the mean value which is 10.445
Quote:

U
0 -0.24000
1 0.07999
2 -0.31000
3 0.40999
4 -0.22000
5 -0.11000
6 -0.01000
7 0.28999
8 0.11999
9 -0.06000

I m using both MATLAB and Python.
When I plot both in Python I got the same result.
For Python

Quote:
a=pd.DataFrame({'u':[10.22,10.54,10.15,10.87,10.24,10.35,10.45,10.75,10 .58,10.40]})
b=np.mean(a)
c=a-b.round(2)


z=plot_acf(c,lags=9)
pyplot.show()

Thanks again for your patience and eagerness.
ari003 is offline   Reply With Quote

Old   October 2, 2020, 08:32
Default
  #11
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
So mystery solved I guess? Your matlab call with default settings removes the mean values before calculating autocorrelations. That's why you get the same result with the original series, and the series where you manually removed the mean value before plugging it into the autocorrelation function.
ari003 likes this.
flotus1 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
autocorrelation in Matlab pappo1890 OpenFOAM 5 March 24, 2020 08:22
Energy Spectrum !!! stanking Main CFD Forum 107 October 21, 2016 11:48
Question about autocorrelation in turbulent flow pban92 Main CFD Forum 0 May 16, 2011 09:14
[OpenFOAM] Velocity autocorrelation and droplet counting coastal593 ParaView 0 March 12, 2008 01:27
tecplot: help reagrding ploting 2 diff data....... Kiran FLUENT 1 July 27, 2006 07:29


All times are GMT -4. The time now is 04:58.