容积卡尔曼滤波(ckf)MATLAB代码(一个ckf滤波器的子程序)

一个ckf滤波器的子程序,自己可以进行拓展,可以根据自己的实例进行套用,适用与多维实例的系统,代码注释全面,参数设置参考的文献均已注明,值得学习

%% ---------------------------------------------------------------
% Version: 20121120, one of the functions for Nonlinear Filtering.All
% Rights Reserved. Anyone can use it for your own simulations. Do not modify
% the following comments.
% 
% Implementation of the third-degree cubature Kalman filters. This script
% could be applied to multi-dimensional models.
% 
% Caution: For validating the third-degree cubture Kalman fiters only,
% the model employed is known as the bearing-only tracking (four-dimensional
% model), the values of parameters can be referred to the following
% references:
% [1] I. Arasaratnam, S. Haykin, "Cubature Kalman filters," IEEE Trans.
% Automat. Control, vol. 54, no. 6, 2009, pp. 1254-1269.
% [2] X. C. Zhang, C. J. Guo, "Square-root imbedded cubature Kalman
% filtering," Control Theory & Applications, to appear. (In Chinese).
% [3] X. C. Zhang, C. J. Guo, "Cubature Kalman filters: Derivation and
% extension," Chinese Physics B, accepted.
%
% 
%                                              - By Irvingzhang(UESTC)
%                                                    2012-11-20
%                                      Email Address: irving_zhang@163.com
%% ---------------------------------------------------------------
function [x, P] = CKF(xhat, Pplus, z)
global Q R fai gama kesi w m;
%% -----------------------------Time Update-----------------------
    % Evaluate the Cholesky factor
    Shat = sqrtm(Pplus);
    for cpoint = 1 : m
        % Evaluate the cubature points
        rjpoint(:, cpoint) = Shat * kesi(:, cpoint) + xhat;
        % Evaluate the propagated cubature points
        Xminus(:, cpoint) = fai * rjpoint(:, cpoint); 
    end


    % Estimate the predicted state
    xminus = w * sum(Xminus, 2);
    
    % Estimate the predicted error covariance
    Pminus = w * (Xminus * Xminus') - xminus * xminus' + gama * Q * gama';
%% ---------------------------------------------------------------


%% -------------------------Measurement Update--------------------
    % Evaluate the Cholesky factor
    Sminus = sqrtm(Pminus);
    for cpoint = 1 : m
        % Evaluate the cubature points
        rjpoint1(:, cpoint) = Sminus * kesi(:, cpoint) + xminus;
        % Evaluate the propagated cubature points
        Z(:, cpoint)=atan(rjpoint1(3, cpoint) / rjpoint1(1, cpoint));
    end    
    % Estimate the predicted measurement
    zhat = w * sum(Z, 2);
    
    % Estimate the innovation covariance matrix
    Pzminus = w * Z * Z'-zhat * zhat' + R;
    
    % Estimate the cross-covariance matrix
    Pxzminus = w * rjpoint1 * Z'- xminus * zhat';
    
    % Estimate the Kalman gain
    W = Pxzminus * inv(Pzminus);
    
    % Estimate the updated state
    x = xminus + W * (z - zhat);
    
    % Estimate the correspondong error covariance
    P = Pminus - W * Pzminus * W';


  • 4
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
容积卡尔曼滤波 (Cubature Kalman Filter, CKF) 是一种非线性滤波器,它通过在状态空间中取样来近似高维积分。下面是一个简单的CKFMatlab代码示例: ``` matlab function [x_est, P_est] = CKF(z, x_pred, P_pred, Q, R) n = length(x_pred); % 状态向量的维度 m = length(z); % 观测向量的维度 % 参数设置 num_samples = 2*n; % 采样点数量 w_m = 1 / (2*num_samples); % 权重系数 w_c = w_m; w_c0 = w_m; % 生成采样点 points = zeros(n, num_samples); for i = 1:n points(:,i) = x_pred + sqrt(n) * chol(P_pred)'(:,i); end % 预测 x_pred_points = zeros(n, num_samples); for i = 1:num_samples x_pred_points(:,i) = f(points(:,i)); % f为状态转移函数 end x_pred_est = sum(w_m * x_pred_points, 2); P_pred_est = zeros(n, n); for i = 1:num_samples P_pred_est = P_pred_est + w_c * (x_pred_points(:,i) - x_pred_est) * (x_pred_points(:,i) - x_pred_est)'; end P_pred_est = P_pred_est + Q; % Q为过程噪声的协方差矩阵 % 更新 z_pred_points = zeros(m, num_samples); for i = 1:num_samples z_pred_points(:,i) = h(x_pred_points(:,i)); % h为观测函数 end z_pred_est = sum(w_m * z_pred_points, 2); Pzz = zeros(m, m); Pxz = zeros(n, m); for i = 1:num_samples Pzz = Pzz + w_c * (z_pred_points(:,i) - z_pred_est) * (z_pred_points(:,i) - z_pred_est)'; Pxz = Pxz + w_c * (x_pred_points(:,i) - x_pred_est) * (z_pred_points(:,i) - z_pred_est)'; end Pzz = Pzz + R; % R为测量噪声的协方差矩阵 K = Pxz * inv(Pzz); % 卡尔曼增益 x_est = x_pred_est + K * (z - z_pred_est); % 估计的状态向量 P_est = P_pred_est - K * Pzz * K'; % 估计的状态协方差矩阵 end ``` 以上是一个简单的CKFMatlab代码示例,其中包含了预测和更新的步骤,通过在状态空间中取样来近似高维积分。需要注意的是,根据实际的问题场景和数据格式,需要对代码进行适当的修改和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值