How to add error bar to the plot while using the function allanvar ?

4 次查看(过去 30 天)
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 个)

Ruchika
Ruchika 2023-8-10
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:

类别

Help CenterFile Exchange 中查找有关 Errorbars 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by