卡尔曼全名Rudolf Emil Kalman,匈牙利数学家,1930年出生于匈牙利首都布达佩斯。1953,1954年于麻省理工学院分别获得电机工程学士及硕士学位。1957年于哥伦比亚大学获得博士学位。我们现在要学习的卡尔曼滤波器,正是源于他的博士论文和1960年发表的论文《A New Approach to Linear Filtering and Prediction Problems》(线性滤波与预测问题的新方法)。
简单来说,卡尔曼滤波器是一个“optimal recursive data processing algorithm(最优化自回归数据处理算法)”。对于解决很大部分的问题,他是最优,效率最高甚至是最有用的。他的广泛应用已经超过30年,包括机器人导航,控制,传感器数据融合甚至在军事方面的雷达系统以及导弹追踪等等。近年来更被应用于计算机图像处理,例如头脸识别,图像分割,图像边缘检测等等。
clear all; close all; clc;
%% Initial condition
ts = 1; % Sampling time
t = [0:ts:100];
T = length(t);
%% Initial state
x = [0 40 0 20]';
x_hat = [0 0 0 0]';
%% Process noise covariance
q = 5
Q = q*eye(2);
%% Measurement noise covariance
r = 5
R = r*eye(2);
%% Process and measurement noise
w = sqrt(Q)*randn(2,T); % Process noise
v = sqrt(R)*randn(2,T); % Measurement noise
%% Estimate error covariance initialization
p = 5;
P(:,:,1) = p*eye(4);
%% Continuous-time state space model
%{
x_dot(t) = Ax(t)+Bu(t)
z(t) = Cx(t)+Dn(t)
%}
A = [0 1 0 0;
0 0 0 0;
0 0 0 1;
0 0 0 0];
B = [0 0;
1 0;
0 0;
0 1];
C = [1 0 0 0;
0 0 1 0];
D = [1 0;
0 1];
%% Discrete-time state space model
%{
x(k+1) = Fx(k)+Gw(k)
z(k) = Hx(k)+Iv(k)
Continuous to discrete form by zoh
%}
sysc = ss(A,B,C,D);
sysd = c2d(sysc, ts, 'zoh');
[F G H I] = ssdata(sysd);
%% Practice state of target
for i = 1:T-1
x(:,i+1) = F*x(:,i);
end
x = x+G*w; % State variable with noise
z = H*x+I*v; % Measurement value with noise