Function Repository Resource:

ModifiedAllanDeviation

Source Notebook

Measure the bandwidth-modified two-sample phase/frequency stability

Contributed by: Julien Kluge

ResourceFunction["ModifiedAllanDeviation"][data,r,taus]

calculates the bandwidth-modified two-sample deviation of data along sample times taus at rate r.

Details and Options

The modified Allan deviation is the square root of the bandwidth-modified two-sample variance, which is used to characterize the frequency/phase stability of an oscillator and can separate white from flicker noise.
The output usually comes in the format {τ,Around[σ,δσ]} where δσ denotes the statistical uncertainty related to the deviation σ.
The argument taus can be specified as:
{{n}}attempts to place n logarithmically-spaced samples
dplaces logarithmic spaced samplings with log base d
{τ1,τ2,}tries to use the specified sample times
Alluses all possible sample times
Automatictries to place a reasonable amount of samples along the whole possible time range
For a List of reals as a data argument, the resource function AllanDeviation will use a fast, compiled algorithm. Otherwise, valid inputs are exact expressions and/or Around.
The rate r must be a positive, numeric quantity.
Supported options are:
"Overlapping"Truewhether the Allan deviation is overlapping
"FrequencyData"Falsewhether data is a list of frequencies or False for phase data

Examples

Basic Examples (2) 

Calculate the overlapping modified Allan deviation of white noise at a rate of 0.1 for automatically chosen sampling points:

In[1]:=
data = RandomFunction[WhiteNoiseProcess[1], {100}]["Values"];
adev = ResourceFunction["ModifiedAllanDeviation"][data, 0.1, Automatic]
Out[2]=

Plot the results:

In[3]:=
ListLogLogPlot[adev]
Out[3]=

Display the overlapping modified Allan deviation of white noise at a rate of 0.1 for certain sampling points:

In[4]:=
data = RandomFunction[WhiteNoiseProcess[1], {100}]["Values"];
adev = ResourceFunction["ModifiedAllanDeviation"][data, 0.1, {20, 50, 100, 200}];
ListLogLogPlot[adev, GridLines -> Automatic]
Out[6]=

Scope (3) 

Sample at all possible times:

In[7]:=
data = RandomFunction[WhiteNoiseProcess[1], {100}]["Values"];
adev = ResourceFunction["ModifiedAllanDeviation"][data, 1, All];
ListLogLogPlot[adev]
Out[9]=

Try to sample at five different time values:

In[10]:=
data = RandomFunction[WhiteNoiseProcess[1], {500}]["Values"];
adev = ResourceFunction["ModifiedAllanDeviation"][data, 1, {{5}}];
ListLogLogPlot[adev]
Out[12]=

The function will try to use a fast evaluation method when the data array is fully real, and otherwise prints a warning:

In[13]:=
data = RandomFunction[WhiteNoiseProcess[1], {100}]["Values"];
adev = ResourceFunction["ModifiedAllanDeviation"][data~Join~{Pi}, 1, Automatic];
ListLogLogPlot[adev]
Out[15]=

Options (2) 

FrequencyData (1) 

"FrequencyData" accepts a Boolean as argument. True signals the use of frequency data as opposed to phase data:

In[16]:=
data = RandomFunction[WhiteNoiseProcess[1], {100}]["Values"];
adev = ResourceFunction["ModifiedAllanDeviation"][data, 1, All, "FrequencyData" -> True];
ListLogLogPlot[adev]
Out[18]=

Overlapping (1) 

"Overlapping" accepts a Boolean as argument. False signals the use of non-overlapping strides in the deviation sampling:

In[19]:=
data = RandomFunction[WhiteNoiseProcess[1], {100}]["Values"];
adev = ResourceFunction["ModifiedAllanDeviation"][data, 1, All, "Overlapping" -> False];
ListLogLogPlot[adev]
Out[21]=

Applications (2) 

Distinguish a random walk from white noise by their distinct slopes:

In[22]:=
datas = N[
     RandomFunction[#, {10000}]["Values"]] & /@ {WhiteNoiseProcess[], RandomWalkProcess[0.5]};
adevs = ResourceFunction["ModifiedAllanDeviation"][#, 1, Automatic] & /@ datas;
ListLogLogPlot[adevs]
Out[24]=

Detect a drift in frequency data by a rising slope in longer sample times:

In[25]:=
data = RandomFunction[WhiteNoiseProcess[], {10000}]["Values"] + Accumulate[ConstantArray[10^-4, 10001]];
adev = ResourceFunction["ModifiedAllanDeviation"][data, 1.0, Automatic, "FrequencyData" -> True];
ListLogLogPlot[adev]
Out[27]=

Properties and Relations (3) 

Using the fast algorithm is approximately two times faster:

In[28]:=
data = RandomFunction[WhiteNoiseProcess[], {1000000}]["Values"];
ResourceFunction["ModifiedAllanDeviation"][data~Join~{N@Pi}, 1.0, Automatic]; // Timing
Out[29]=
In[30]:=
ResourceFunction["ModifiedAllanDeviation"][data~Join~{Pi}, 1.0, Automatic]; // Timing
Out[30]=

The function can process Around objects as well as exact inputs directly:

In[31]:=
data = Table[
   Around[RandomVariate[NormalDistribution[0, 2]], 2], {i, 1, 1000}];
adev = ResourceFunction["ModifiedAllanDeviation"][data, 1, Automatic];
ListLogLogPlot[adev]
Out[33]=

Compare ModifiedAllanDeviation with the AllanDeviation resource function:

In[34]:=
data = RandomFunction[WhiteNoiseProcess[1], {100}]["Values"];
In[35]:=
ListLogLogPlot[{ResourceFunction["ModifiedAllanDeviation"][data, .1, Automatic], ResourceFunction["AllanDeviation"][data, 0.1, Automatic]}]
Out[35]=

Possible Issues (1) 

Requesting a certain amount of samples will not necessarily result in this amount of deviations:

In[36]:=
data = RandomFunction[WhiteNoiseProcess[1], {500}]["Values"];
ResourceFunction["ModifiedAllanDeviation"][data, 1.0, {{10}}] // Length
Out[37]=

Neat Examples (1) 

The function can distinguish between white phase noise and flicker noise (pink noise), as opposed to the plain Allan deviation:

In[38]:=
pink = Rescale[First@AudioData[AudioGenerator["Pink", 1.0]]];
white = Rescale[
   RandomFunction[WhiteNoiseProcess[1], {Length[pink] - 1}]["Values"]];

pinkmadev = ResourceFunction["ModifiedAllanDeviation"][pink, 1, Automatic];
whitemadev = ResourceFunction["ModifiedAllanDeviation"][white, 1, Automatic];

pinkadev = ResourceFunction["AllanDeviation"][pink, 1, Automatic];
whiteadev = ResourceFunction["AllanDeviation"][white, 1, Automatic];
ListLogLogPlot[{pinkmadev, whitemadev, pinkadev, whiteadev}, PlotLegends -> {"Modified Allan dev. pink", "Modified Allan dev. white", "Allan dev. pink", "Allan dev. white"}]
Out[44]=

Publisher

Julien Kluge

Version History

  • 1.0.0 – 09 July 2020

Source Metadata

Related Resources

License Information