2
$\begingroup$

I have a list with over 10.000 elements of data. Now I wanna calculate the Allan Variance of this Measurement. The Allan Variance is defined as following:

$$\sigma_y^2(\tau)=\frac1{2\tau^2}\langle(x_{n+2}-2x_{n+1}+x_n)^2\rangle$$

How do I do it?

Data Sample:

sample={4.59654*10^9, 4.59655*10^9, 4.59655*10^9, 4.59656*10^9, 4.59655*10^9,4.59655*10^9, 4.59658*10^9, 4.59656*10^9, 4.59657*10^9, 4.59654*10^9, 4.59656*10^9, 4.59657*10^9, 4.59655*10^9, 4.59656*10^9, 4.59656*10^9, 4.59655*10^9, 4.59656*10^9, 4.59654*10^9, 4.59656*10^9, 4.59656*10^9, 4.59655*10^9, 4.59657*10^9, 4.59655*10^9, 4.59655*10^9, 4.59654*10^9, 4.59656*10^9, 4.59656*10^9}

The whole measurement was made every 0.3s over a period of 1 hour.

$\endgroup$
5
  • $\begingroup$ You might be interested in Differences[]. $\endgroup$ Jan 22, 2021 at 15:45
  • $\begingroup$ Give us a sample of your data as well. Which of the estimators listed on the Wiki page is most appropriate in your application? $\endgroup$
    – MarcoB
    Jan 22, 2021 at 15:47
  • $\begingroup$ I would say fixed tau estimator. $\endgroup$
    – Luxamba
    Jan 22, 2021 at 16:22
  • $\begingroup$ A user-defined variable should start with a lower-case letter to avoid potential naming conflicts with built-in names. For example, List has a specific use in Mathematica. $\endgroup$
    – Bob Hanlon
    Jan 22, 2021 at 16:35
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Jan 22, 2021 at 17:15

1 Answer 1

4
$\begingroup$

I think this does what you need:

AVAR[list_List, tau_] /; Length[list] > 2 := Divide[
  Mean[
   Subtract[Drop[list, -2] + Drop[list, 2], 2*Take[list, {2, -2}]]^2
  ],
  2 * tau^2
];
AVAR[sample, 1]

3.78*10^8

Symbolic example:

AVAR[Array[x, 5], \[Tau]]

enter image description here

Edit

J.M.'s approach based on Differences (I honestly didn't know it had this functionality, but it's obvious in hindsight):

AVAR[list_List, tau_] /; Length[list] > 2 := Divide[
  Mean[Differences[list, 2]^2],
  2*tau^2
];
$\endgroup$
1
  • 4
    $\begingroup$ As I mentioned in the comments, Differences[] works nicely here: AVAR[list_List, tau_] /; Length[list] > 2 := Divide[Mean[Differences[list, 2]^2], 2 tau^2] $\endgroup$ Jan 22, 2021 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.