forked from korken89/Comparison-of-UKF-CKF-EKF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_time.m
186 lines (145 loc) · 4.74 KB
/
test_time.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Compare execution time of the SR-EKF, SR-UKF and SR-CKF
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear; clc;
fprintf('\n')
fprintf('---------------------------------------------------------------')
fprintf('\n')
fprintf('- Compare execution time of the SR-UKF, SR-CKF and SR-EKF -')
fprintf('\n')
fprintf('- By Emil Fresk, Lulea University of Technology -')
fprintf('\n')
fprintf('---------------------------------------------------------------')
fprintf('\n\n')
% Number of iterations
iter = 100000;
% State size
state_s = 15;
% Measuremenat size
meas_s_best = 6;
meas_s_worst = 9;
% % % % % % % % % % % % % % % % % % % % % %
% Initialize matricies
% % % % % % % % % % % % % % % % % % % % % %
x = zeros(state_s, 1);
u = 0;
z = zeros(meas_s_best, 1);
Sp = eye(state_s);
Sq = eye(state_s);
Sr = eye(meas_s_best);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Run SR-UKF test
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('Running SR-UKF best case test...')
tic
for i=1:iter
[ x, Sp ] = srukf_innovate( x, u, z, Sp, Sq, Sr, @f_test, @h_best_test);
end
ukf_time_best = toc;
fprintf(' Done!\n')
% % % % % % % % % % % % % % % % % % % % % %
% Initialize matricies
% % % % % % % % % % % % % % % % % % % % % %
x = zeros(state_s, 1);
u = 0;
z = zeros(meas_s_worst, 1);
Sp = eye(state_s);
Sq = eye(state_s);
Sr = eye(meas_s_worst);
fprintf('Running SR-UKF worst case test...')
tic
for i=1:iter
[ x, Sp ] = srukf_innovate( x, u, z, Sp, Sq, Sr, @f_test, @h_worst_test);
end
ukf_time_worst = toc;
fprintf(' Done!\n')
% % % % % % % % % % % % % % % % % % % % % %
% Initialize matricies
% % % % % % % % % % % % % % % % % % % % % %
x = zeros(state_s, 1);
u = 0;
z = zeros(meas_s_best, 1);
Sp = eye(state_s);
Sq = eye(state_s);
Sr = eye(meas_s_best);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Run SR-UKF test
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('Running SR-CKF best case test...')
tic
for i=1:iter
[ x, Sp ] = srckf_innovate( x, u, z, Sp, Sq, Sr, @f_test, @h_best_test);
end
ckf_time_best = toc;
fprintf(' Done!\n')
% % % % % % % % % % % % % % % % % % % % % %
% Initialize matricies
% % % % % % % % % % % % % % % % % % % % % %
x = zeros(state_s, 1);
u = 0;
z = zeros(meas_s_worst, 1);
Sp = eye(state_s);
Sq = eye(state_s);
Sr = eye(meas_s_worst);
fprintf('Running SR-CKF worst case test...')
tic
for i=1:iter
[ x, Sp ] = srckf_innovate( x, u, z, Sp, Sq, Sr, @f_test, @h_worst_test);
end
ckf_time_worst = toc;
fprintf(' Done!\n')
% % % % % % % % % % % % % % % % % % % % % %
% Initialize matricies
% % % % % % % % % % % % % % % % % % % % % %
x = zeros(state_s, 1);
u = 0;
z = zeros(meas_s_best, 1);
Sp = eye(state_s);
Sq = eye(state_s);
Sr = eye(meas_s_best);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Run SR-UKF test
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('Running SR-EKF best case test...')
tic
for i=1:iter
[ x, Sp ] = srekf_innovate_best( x, u, z, Sp, Sq, Sr, @f_test, @h_best_test);
end
ekf_time_best = toc;
fprintf(' Done!\n')
% % % % % % % % % % % % % % % % % % % % % %
% Initialize matricies
% % % % % % % % % % % % % % % % % % % % % %
x = zeros(state_s, 1);
u = 0;
z = zeros(meas_s_worst, 1);
Sp = eye(state_s);
Sq = eye(state_s);
Sr = eye(meas_s_worst);
fprintf('Running SR-EKF worst case test...')
tic
for i=1:iter
[ x, Sp ] = srekf_innovate_worst( x, u, z, Sp, Sq, Sr, @f_test, @h_worst_test);
end
ekf_time_worst = toc;
fprintf(' Done!\n\n')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot results
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf(['Iterations: ', num2str(iter)])
fprintf('\n\n')
fprintf(' Best (s)\t\tWorst (s)\t\tRelative best\t\tRelative worst')
fprintf('\n')
fprintf(' --------\t\t---------\t\t-------------\t\t--------------')
fprintf('\n')
fprintf(['SR-UKF: ', num2str(ukf_time_best, 3), ' \t\t', num2str(ukf_time_worst, 3)])
fprintf([' \t\t\t', num2str(ukf_time_best/ekf_time_best, 3), '\t\t\t\t', num2str(ukf_time_worst/ekf_time_worst, 3)])
fprintf('\n')
fprintf(['SR-CKF: ', num2str(ckf_time_best, 3), ' \t\t', num2str(ckf_time_worst, 3)])
fprintf([' \t\t\t', num2str(ckf_time_best/ekf_time_best, 3), '\t\t\t\t', num2str(ckf_time_worst/ekf_time_worst, 3)])
fprintf('\n')
fprintf(['SR-EKF: ', num2str(ekf_time_best, 3), ' \t\t', num2str(ekf_time_worst, 3)])
fprintf([' \t\t\t', num2str(ekf_time_best/ekf_time_best, 3), ' \t\t\t\t', num2str(ekf_time_worst/ekf_time_worst, 3)])
fprintf('\n\n')