# Very simple Allan Standard Deviation implementation in julia

05 Jan 2017A short snippet to calculate the Allan Standard Deviation. It trims the data to have a length of an integer power of 2.

```
"""
astd(data, dt)
Compute the allan standard deviation of the vector data. dt is the time separation
of the samples.
The standard deviations are computed for averaging over number of samples equal
to integer powers of 2. The dataset is trimmed to have length equal to an integer
power of 2. The smallest averaging is over 2 samples, the largest is
over the length of dataset divided by 2. E.g. if length(data) = 100,
Returns:
t : array of the averaging time
s : the array of the corresponding standard deviations.
# Example
julia> astd(ones(100), 1)
([32,16,8,4,2],[0.0,0.0,0.0,0.0,0.0])
"""
function astd(data, dt)
log2len = Int64(floor(log2(length(data))))
truncd = data[1 : 2^log2len]
Ns = 2 .^ (1 : log2len-1)
asda = Float64[
sqrt( sum(diff(mean(reshape(truncd, length(truncd) ÷ N, N), 1)').^2) / 2(N - 1) )
for N in Ns ]
dt * (length(truncd) ÷ Ns), asda
end
```