How to add error bar to the plot while using the function allanvar ?
4 views (last 30 days)
Show older comments
ab represents speed and its a time series data. I can calculate allan variance for the time series. Now I want to calculate the errors in calculation using the function allanvar. How to do that ?
frate=66.45;
rowsToDelete = ab < -2 | ab > 2;
ab(rowsToDelete) = [];
a=(1:length(ab)).*(1./frate)
[avar,tau] = allanvar(ab,[1:length(ab)./2],(frate));
% figure
loglog(tau,avar)
hold on;
c=(1./tau)./(frate);
d=c.*(max(avar));
plot(tau,d)
1 Comment
Star Strider
on 14 Jul 2023
From the Wikipedia article on the Allan variance it would likely be best to calculate and plot the confidence intervals.
I leave that to you.
Answers (1)
Ruchika
on 10 Aug 2023
Hi, based on my understanding, you have computed the Allan variance for a time series data representing speed and you want to incorporate the corresponding calculation errors into the plot using the ‘allanvar’ function. To add error bars to the plot while using the allanvar function, you'll need to calculate the errors associated with each point on the Allan variance plot. The Allan variance itself is already an estimate of the variance, so you'll want to calculate the standard error of the mean for each data point on the plot. Here is how you can modify your code to achieve this :
frate = 66.45;
rowsToDelete = ab < -2 | ab > 2;
ab(rowsToDelete) = [];
a = (1:length(ab)) .* (1./frate);
[avar, tau] = allanvar(ab, [1:length(ab)./2], frate);
% Calculate standard error of the mean for each point
numSamples = numel(ab);
sem = sqrt(2 * avar.^2 / numSamples);
% Plot Allan variance with error bars
figure
loglog(tau, avar)
hold on;
errorbar(tau, avar, sem, 'r.') % Adding red error bars
c = (1./tau) ./ (frate);
d = c .* (max(avar));
plot(tau, d)
hold off;
xlabel('Tau')
ylabel('Allan Variance')
legend('Allan Variance', 'Error Bars', 'Linear Fit')
In this code, the ‘errorbar’ function is used to add error bars to the plot. The ‘sem’ variable holds the calculated standard error of the mean for each corresponding data point in ‘avar’. The error bars are plotted in red dots.
Kindly adjust the color, style, and size of the error bars and maximum expected value line according to your preference.
To learn more about the functions used above, please check out the MathWorks documentation links below:
0 Comments
See Also
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!