-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJulierSigmaPoints.m
86 lines (62 loc) · 2.29 KB
/
JulierSigmaPoints.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
classdef JulierSigmaPoints
% Generates sigma points and weights according to Simon J. Julier and
% Jeffery K. Uhlmann's original paper[Julier, Simon J.; Uhlmann, Jeffrey
% "A New Extension of the Kalman Filter to Nonlinear Systems". Proc.
% SPIE 3068, Signal Processing, Sensor Fusion, and Target Recognition VI,
% 182 (July 28, 1997)]. It parametizes the sigma points using kappa.
% Properties
% n : Dimensionality of the state.
% kappa : Scaling factor that can reduce high order errors.
% Wm : Weight for each sigma point for the mean.
% Wc : Weight for each sigma point for the covariance.
properties
n
kappa
Wm
Wc
end
methods
function obj = JulierSigmaPoints(n, kappa)
% Class constructor
obj.n = n;
obj.kappa = kappa;
obj = compute_weights(obj);
end
function ns = num_sigmas(obj)
% Number of sigma points for each variable in the state x.
ns = 2*obj.n + 1;
end
function obj = compute_weights(obj)
% Computes the weights for the unscented Kalman filter.
n = obj.n;
k = obj.kappa;
Wm = ones(2*n+1);
Wm = Wm(1,:);
obj.Wm = Wm*(0.5/(n+k));
obj.Wm(1) = k/(n+k);
obj.Wc = obj.Wm;
end
function sigmas = sigma_points(obj, x, P)
if obj.n ~= size(x)
error('expected size(x) %d, but size is %d',obj.n, size(x));
end
n = obj.n;
n = length(x);
n = n(1);
if isscalar(P)
P = eye(n) * P;
end
sigmas = zeros(2*n+1, n);
% Returns lower triangular matrix.
U = chol((n + obj.kappa)*P);
% Gives you 5 sigma points, this amount is not mandatory, you
% can have 3 or 7 or more, first is always the middle point and
% the remaining must be an even number.
sigmas(1,:) = x(1,:);
for k = 1:n
sigmas(k+1,:) = minus(x(1,:),-U(k,:));
sigmas(n+k+1,:) = minus(x(1,:),U(k,:));
end
end
end
end