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

조회 수: 20 (최근 30일)
Sayanta Goswami
Sayanta Goswami 2023년 7월 14일
답변: Ruchika 2023년 8월 10일
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
Star Strider
Star Strider 2023년 7월 14일
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.

댓글을 달려면 로그인하십시오.

답변 (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