allan 方差

%%matlab function

function [acc_sig,acc_wk] = allan_var(data,t0)
%ALLAN_VAR 此处显示有关此函数的摘要
%   此处显示详细说明
acc_data = data(:,1:3);
acc_sig = zeros(3,3);
acc_wk = zeros(3,3);

for i=1:3
    [adev,tau]=calc_var(acc_data(:,i),t0);
    slope = -0.5;
    b = search_by_slope(adev,tau,slope);
    % Determine the angle random walk coefficient from the line.
    logN = slope*log(1) + b;
    N = 10^logN;
    acc_sig(i,i) = N;
    
    %%walk noise
    slope = 0.5;
    [adev,tau]=calc_var(acc_data(:,i),t0);
    b = search_by_slope(adev,tau,slope);
    logK = slope*log10(3) + b;
    K = 10^logK;
    acc_wk(i,i)= K;
end

end

function b = search_by_slope(adev,tau,slope)

logtau = log10(tau);
logadev = log10(adev);
dlogadev = diff(logadev) ./ diff(logtau);
[~, i] = min(abs(dlogadev - slope));

% Find the y-intercept of the line.
b = logadev(i) - slope*logtau(i);
end


function [adev,tau]=calc_var(omega,t0)

    theta = cumsum(omega, 1)*t0;
    maxNumM = 100;
    L = size(theta, 1);
    maxM = 2.^floor(log2(L/2));
    m = logspace(log10(1), log10(maxM), maxNumM).';
    m = ceil(m); % m must be an integer.
    m = unique(m); % Remove duplicates.

    tau = m*t0;

    avar = zeros(numel(m), 1);
    for i = 1:numel(m)
        mi = m(i);
        avar(i,:) = sum((theta(1+2*mi:L) - 2*theta(1+mi:L-mi) + theta(1:L-2*mi)).^2, 1);
    end
    avar = avar ./ (2*tau.^2 .* (L - 2*m));

    adev = sqrt(avar);
end

%%-------------------------demo-------------------------------------

t0 = 0.005;
rawdata = load('D:\\project\\cpp\\imu_prei\\create_virtual_imu_data/imu_pose_noise.txt');
%rawdata = load('D:\\project\\cpp\\course2_hw_new\\vio_data_simulation\\build/imudata.txt');t0 = 1.0/200;
N_sample = size(rawdata,1);

data = rawdata(:,9:14);

[acc_noise,acc_walk]=allan_var(data(:,4:6),t0)
[gyr_noise,gyr_walk]=allan_var(data(:,1:3),t0)
disp('-----------------------------------------------')


return;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值