|
[Sponsors] |
October 1, 2020, 10:53 |
Reagrding autocorrelation
|
#1 | ||
Senior Member
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7 |
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:
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:
2. The τ = 0 to 10 Quote:
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. |
|||
October 1, 2020, 16:29 |
|
#2 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49 |
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. |
|
October 2, 2020, 05:36 |
|
#3 |
Member
EM
Join Date: Sep 2019
Posts: 59
Rep Power: 7 |
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.
-- |
|
October 2, 2020, 05:44 |
|
#4 | ||
Senior Member
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7 |
Quote:
Quote:
|
|||
October 2, 2020, 06:02 |
|
#5 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49 |
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.
|
|
October 2, 2020, 06:25 |
|
#6 | ||
Senior Member
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7 |
Quote:
Lets say Quote:
But I just plotted the thing in python just now both gave the same autocorr plot. |
|||
October 2, 2020, 06:31 |
|
#7 |
Member
EM
Join Date: Sep 2019
Posts: 59
Rep Power: 7 |
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. -- |
|
October 2, 2020, 06:33 |
|
#8 | |
Senior Member
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7 |
Quote:
|
||
October 2, 2020, 07:01 |
|
#9 | |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49 |
Quote:
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. |
||
October 2, 2020, 08:15 |
|
#10 | ||||
Senior Member
Arijit Saha
Join Date: Feb 2019
Location: Singapore
Posts: 132
Rep Power: 7 |
Quote:
This one is my original series : Quote:
This one is after deducting the mean value which is 10.445 Quote:
I m using both MATLAB and Python. When I plot both in Python I got the same result. For Python Quote:
Thanks again for your patience and eagerness. |
|||||
October 2, 2020, 08:32 |
|
#11 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49 |
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.
|
|
|
|
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 |