kalman.m

来自「卡尔曼滤波 现代滤波器的实现,matlab源码」· M 代码 · 共 62 行

M
62
字号
% kalman filtering

load initial_track  s; % y:initial data,s:data with noise
T=0.1;

% yp denotes the sample value of position
% yv denotes the sample value of velocity
% Y=[yp(n);yv(n)];
% error deviation caused by the random acceleration 
% known data
Y=zeros(2,200);
Y0=[0;1];
Y(:,1)=Y0;
A=[1 T
    0 1];          
B=[1/2*(T)^2 T]';
H=[1 0];

C0=[0 0
    0 1];
C=[C0 zeros(2,2*199)];
Q=(0.25)^2; 
R=(0.25)^2; 


% kalman algorithm ieration
for n=1:200
    i=(n-1)*2+1;
    K=C(:,i:i+1)*H'*inv(H*C(:,i:i+1)*H'+R);
    Y(:,n)=Y(:,n)+K*(s(:,n)-H*Y(:,n));
    Y(:,n+1)=A*Y(:,n);
    C(:,i:i+1)=(eye(2,2)-K*H)*C(:,i:i+1);
    C(:,i+2:i+3)=A*C(:,i:i+1)*A'+B*Q*B';
end

% the diagram of position after filtering
figure(3) 
t=0:0.1:20;
yp=Y(1,:);A
plot(t,yp,'+');
axis([0 20 0 20]);
xlabel('time');
ylabel('yp position');
title('the track after kalman filtering');

% the diagram of velocity after filtering
figure(4) 
yv=Y(2,:);
plot(t,yv,'+');
xlabel('time');
ylabel('yv velocity');
title('the velocity caused by random acceleration');




    
    
    
   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?