Math & Scientific
Calculate Allan Variance at a Stated Averaging Time
Compute non-overlapping Allan variance from ordered frequency averages, change the averaging time, and distinguish it from ordinary sample variance.
Identify the measured sequence and its timing
Allan variance describes changes between adjacent frequency averages at a specified averaging time. Start with an ordered sequence of fractional-frequency values sampled as contiguous averages over equal durations τ₀. Fractional frequency is the frequency offset divided by the nominal reference frequency. Record the sampling interval, any dead time and whether the file contains frequency or phase/time-error measurements. Sorting the observations destroys the temporal structure. An ordinary variance calculator ignores this ordering and therefore cannot substitute for Allan variance.
Define the non-overlapping estimator
For K consecutive non-overlapping average-frequency values at duration τ, use half the mean squared difference between neighbours: σ²y(τ)=Σ(ȳj+1−ȳj)²/[2(K−1)], where the sum includes K−1 adjacent differences. Allan deviation is the square root of that value. For averaging factor m, first average successive non-overlapping blocks of m original samples, giving τ=mτ₀. At least two complete block averages are needed. This guide uses that basic estimator, not the overlapping or modified variants.
Work the base-interval example
Take ordered frequency values 1, 2, 1, 2, 3, 2, each expressed in units of 10⁻⁶, with τ₀=1 second. The adjacent differences in those scaled units are 1, −1, 1, 1 and −1. Their squared sum is five. Dividing by 2×5 gives Allan variance 0.5 in squared scaled units, or 5×10⁻¹³ in fractional-frequency units. Allan deviation is √0.5×10⁻⁶≈7.071068×10⁻⁷ at an averaging time of one second.
Repeat at a longer averaging time
For m=2, average the non-overlapping pairs to obtain 1.5, 1.5 and 2.5 in the same scaled units. There are now three block averages and two adjacent differences, zero and one. The squared-difference sum is one, giving Allan variance 1/(2×2)=0.25 scaled units squared. In fractional-frequency units it is 2.5×10⁻¹³ and Allan deviation is 5×10⁻⁷ at τ=2 seconds. The small record yields few differences at this averaging time, so it illustrates arithmetic rather than a reliable stability characterization.
Compare with ordinary variance without confusing them
The original six scaled observations have mean 11/6. Their ordinary population variance is 17/36≈0.472222 and sample variance is 17/30≈0.566667. These are the two results the local form returns for 1, 2, 1, 2, 3, 2; neither is the Allan variance 0.5. Doubling the list to 2, 4, 2, 4, 6, 4 multiplies all variances by four, giving ordinary sample variance 2.266667 and base-interval Allan variance two in squared scaled units.
Use ordering as an independent diagnostic
Reordering the first list to 1, 1, 2, 2, 2, 3 leaves its mean and ordinary variances unchanged. Its adjacent differences become zero, one, zero, zero and one, so its base-interval Allan variance becomes 2/(2×5)=0.2 in squared scaled units. This deliberate reorder demonstrates why a routine that simply computes variance of the values is not implementing Allan variance. Actual measurement order must be retained; the rearranged list is an explanatory comparison, not a valid preprocessing step for a recorded time series.
Run a small explicit implementation
The code below requires a positive integer averaging factor and a record consisting of complete blocks. It rejects an incomplete trailing block rather than silently choosing a discard policy. It then computes non-overlapping block means and adjacent squared differences. Values are supplied in fractional-frequency units, so the output is already in the corresponding squared units. Real measurement analysis additionally needs uncertainty estimates, suitable handling of gaps and outliers, and a documented choice of estimator and averaging times.
from math import isfinite, sqrt
from statistics import mean
def nonoverlapping_allan(y, m=1):
if not isinstance(m, int) or isinstance(m, bool) or m < 1:
raise ValueError("m must be a positive integer")
if len(y) < 2*m or len(y) % m:
raise ValueError("provide at least two complete blocks")
if not all(isfinite(x) for x in y):
raise ValueError("all samples must be finite")
blocks = [mean(y[i:i+m]) for i in range(0, len(y), m)]
avar = sum((b-a)**2 for a, b in zip(blocks, blocks[1:]))
avar /= 2 * (len(blocks)-1)
return avar, sqrt(avar)
y = [x * 1e-6 for x in [1, 2, 1, 2, 3, 2]]
print(nonoverlapping_allan(y, 1)) # about (5e-13, 7.071068e-7)
print(nonoverlapping_allan(y, 2)) # about (2.5e-13, 5e-7)
Do not mix phase data or estimator variants
Phase/time-error measurements use a related second-difference formulation with different scaling by averaging time; they should not be pasted into the frequency formula unchanged. Overlapping Allan variance uses more adjacent overlapping averages, while modified Allan variance adds averaging structure and has different responses to noise types. Report the estimator name, τ, sample interval, units, record length and any preprocessing. A curve across averaging times contains more information than a single number, but interpreting its slopes requires enough data and the appropriate noise model.
Calculator for the supported step
The local form calculates ordinary sample and population variance only. It does not compute Allan variance, preserve a time-series model or accept averaging time. Use the separate worked formula and Python example for Allan variance; the linked form provides an ordinary-variance comparison.