Allan Variance (allanvar) not working correctly
6 views (last 30 days)
Show older comments
I'm having an issue with using the allanvar function and I'm not sure if it is a bug or if I'm using the function incorrectly. The documentation states that if a matrix is supplied on input, then the Allan variance is evaluated over the columns.
In the following code, I compute the Allan variance two different ways for a matrix. In the first case, I'm using a loop over the columns. In the second case, I'm just sending the whole matrix in as input. I expect them to produce the same result, but they do not. When I send the whole matrix in, I'm finding that there are many zeros being returned, which does not happen when I evaluate the Allan variance in a loop. Any explanations?
% Test angle random walk
rng('default')
close all
clear
% Gyro angle random walk specification (deg / sqrt(sec))
angleRandomWalk = 0.001;
% Time step between gyro measurements (sec)
Fs = 100;
dt = 1 / Fs;
% Generate gyro random walk samples
nTime = 100000;
mMonteCarlo = 1000;
randomWalk = angleRandomWalk / sqrt(dt) * randn(nTime, mMonteCarlo);
% Time vector
t = [0:nTime-1]' / Fs;
% Integrate random walk rates over time to angle
angle = cumsum( randomWalk * dt );
% Allan Variance - the square root of the Allan Variance at t = 1 sec should
% equal the angleRandomWalk.
% Time points for evaluating Allan Variance
tm = [ 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 200 300 400 ]';
[~, m ] = intersect(t, tm);
aVar = zeros(length(m), mMonteCarlo);
for n = 1:mMonteCarlo
[aVar(:,n), tau] = allanvar(randomWalk(:,n), m, Fs);
end
[aVar2, tau2] = allanvar(randomWalk, m, Fs);
% Compute the mean of the square root of the Allan Variance at t = 1 second (should equal
% the angleRandomWalk).
rootAllanVar = mean( sqrt( aVar(10, :) ) );
rootAllanVar2 = mean( sqrt( aVar2(10, :) ) );
0 Comments
Accepted Answer
Shaunak
on 28 Mar 2025
Hey John,
It looks like the issue you are encountering with the "allanvar" function is recorded in the following MathWorks Documentation.
This happens when you input a matrix, as the function should evaluate the Allan variance over the columns. If you're getting zeros when passing the whole matrix, it might be due to an issue in earlier versions of MATLAB.
You can use the mentioned method of passing the input column-wise in a loop, which ensures each column is processed correctly.
Alternatively, you can also upgrade to MATLAB R2020b or later for the provided fix to the issue.
Hope this helps!
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!