I am trying to write my own Allan Deviation calculator in Mathematica using the definition, $$\sigma(\tau)^{2}=\frac{1}{2M-2}\sum_{i=1}^{N-1}(\bar{y}_{i+1} - \bar{y}_{i})^{2}\text{.}$$ Where the $\bar{y}$ are mean partitioned data for some multiple of measurement time $\tau$, and $M$ is the length of the number of $(\bar{y}_{i+1} - \bar{y}_{i})^{2}$ associated with each $\tau$. I made a toy model of partitioning the data that I am happy with, but I am struggling to extending it to the next step, which is simply summing the $(\bar{y}_{i+1} - \bar{y}_{i})^{2}$ for each $\tau$. The toy model is:
NumberPoints = 64;
IndexData = Range [NumberPoints];
Do[
Print["________________τ=", j];
Do[
Print[
"(MEAN", Partition[IndexData, j][[2 i]], "-", "MEAN",
Partition[IndexData, j][[2 i - 1]],
"\!\(\*SuperscriptBox[\()\), \(2\)]\)"
],
{i, 1, (NumberPoints/(j*2))}
],
{j, 1, NumberPoints/4}
];
If I try, for the next step:
Do[
Clear[BlockMeanDifferenceList];
BlockMeanDifferenceList = {};
Do[
BlockMeanDifferenceList = (
Mean[Partition[RandomData, τ][[2 i]]] -
Mean[Partition[RandomData, τ][[2 i - 1]]]
)^2;
AppendTo[σ, (1/(2 Length[BlockMeanDifference] - 2)*Total[BlockMeanDifference])^(1/2)];,
{i, 1, (NumberOfPoints/(τ*2))}
];,
{τ, 1, NumberOfPoints/4}
];
My sigma list is returned for zero in all elements...
Any thoughts?
σ
. Also, what's the difference betweenBlockMeanDifferenceList
andBlockMeanDifference
, andNumberOfPoints
vsNumberPoints
(I assume they're the same?)? Instead ofClear
inside a loop, consider usingModule
. And finally, your code seems to contradict your formula: One has differences of the form $y_2-y_1,y_3-y_2,...$ while the other one has $y_2-y_1,y_4-y_3$ (i.e. disjoint) $\endgroup$σ={}
should be included. andNumberOfPoints
andNumberPoints
is the same thing -- I was just sloppy. As for the disjoint, I don't see where that is as the indexing is the same for both the toy model showing the partitioning and for the real attempt? $\endgroup$