-
Notifications
You must be signed in to change notification settings - Fork 6
/
Update.m
executable file
·45 lines (24 loc) · 1.22 KB
/
Update.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function [xkk,Pkk] = Update(xkk1,Pkk1,z, R)
%%%========================================================================
%%% Genrate a set of Cubature Points
%%%========================================================================
nx = 2; % state vector dimension
nPts = 2*nx; % No. of Cubature Points
CPtArray = sqrt(nPts/2)*[eye(nx) -eye(nx)];
%%%========================================================================
%%% find the square-root of Pkk1 using Singular Value Decomposition (SVD)
%%%========================================================================
Pkk1 = 0.5*(Pkk1+Pkk1'); % make Pkk1 to be symmetric (Property of a covariance matrix !)
[U, S, V] = svd(Pkk1);
Skk1 = 0.5*(U+V)*sqrt(S);
%%%========================================================================
Xi = repmat(xkk1,1,nPts) + Skk1*CPtArray;
Zi = MstEq(Xi);
zkk1 = sum(Zi,2)/nPts; % predicted Measurement
X = (Xi-repmat(xkk1,1,nPts))/sqrt(nPts);
Z = (Zi-repmat(zkk1,1,nPts))/sqrt(nPts);
Pzz = Z*Z'+ R; % Innovations Covariance
Pxz = X*Z'; % cross-covariance
G = Pxz*pinv(Pzz); % Cubature Kalman Gain
xkk = xkk1 + G*(z - zkk1);
Pkk = Pkk1 - G*Pzz*G';