Allan Variance:传感器随机误差实验代码(matlab)

clc;
clear all;
tic;
%data = csvread(‘G:\桌面文件\chuanganqi.csv’,2,5,[2 5 2000 5]);
%X = csvread(‘G:\桌面文件\chuanganqi.csv’,2,5,[2 5 2000 5]);
X = csvread(‘G:\桌面文件\chuanganqi.csv’,2,5);
%X = data(1:720000,1)*3600; %读取数据,以陀螺仪某一轴为例
%X = data(2:2000)*3600
Ts = 0.01; %采样时间
[N,M] = size(X);
N_max = floor(N/3);%(N/3)
T = zeros(N_max,10);
R = zeros(N_max,10);

for d = 1 %设置迭代的步长为d,当d=1时为传统的Allan方差
Allan = zeros(N_max,2);
Cluster_mean = zeros(N,1);
for n = 1:d:N_max %每一簇的簇长
K = floor(N/n);
for k = 1:K
Cluster_mean(k,1) = mean(X((n*(k-1)+1):(nk),1));
end
Cluster_diff = diff(Cluster_mean(1:K),1);
Allan(n,1) = n
Ts; %Time tau
Allan(n,2) = sum((Cluster_diff.^2))/(2*(K-1));
end
Allan(any(Allan,2)==0,:)=[]
TUP = ceil(N_max/d);
RUP = ceil(N_max/d);
T(1:TUP,d)=Allan(:,1);
R(1:RUP,d)=Allan(:,2);
end
x1 = T(:,1);
y1 = R(:,1);

a= [1 2 3 4 5];%函数拟合过程
a(1:5)=lsqcurvefit(@test,a,x1,y1);
f=a(1)*x1.(-2)+a(2)*x1.(-1)+a(3)*x1.(0)+a(4)*x1.(1)+a(5)*x1.^(2);

figure(1)=figure(‘color’,[1 1 1]);
loglog(T(:,1),R(:,1),‘color’,[255/255,215/255,0/255]);
hold on;
loglog(x1, f,‘r’,‘LineWidth’,1.3);
hold on;
xlabel(‘Cluster Time (sec)’);
ylabel(‘Allan Deviation (deg/h)’);
grid on;
legend(’ Step size=1’,’ Step size=2’,’ Step size=3’,’ Fitting Curve’)
toc;

test

function f=test(a,x)
f=a(1)*x.(-2)+a(2)*x.(-1)+a(3)*x.(0)+a(4)*x.(1)+a(5)*x.^(2);
end

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值