-
Notifications
You must be signed in to change notification settings - Fork 2
/
kalman_estimator.py
440 lines (354 loc) · 23.3 KB
/
kalman_estimator.py
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
import plotly.graph_objects as go
import numpy as np
from math import cos, sin
## For modelling the noise that gets added after each update step
def noise(mean_matrix, covariance_matrix):
return np.random.multivariate_normal(mean_matrix, covariance_matrix).reshape(-1, 1)
def action_upd(X_t, A_t, B_t, u_t, mean_epsilon, R):
return np.dot(A_t, X_t) + np.dot(B_t, u_t) + noise(mean_epsilon, R)
def obsv_upd(X_t, C_t, mean_delta, Q):
return np.dot(C_t, X_t) + noise(mean_delta, Q)
def actual_state_variables():
u_t = np.array([[0], [0], [0]]) ## Control Inputs are all 0
X_init = np.array([[0.0], [0.0], [0.0], [1.0], [1.0], [1.0]]) ## start from (0,0,0) with vel (1,1,1)
observed_vals = np.zeros((300, 3))
actual_vals = np.zeros((300, 3))
deltaT = 1.0
## Action Model Parameters
A_t = np.array([[1.0,0,0,deltaT,0,0],
[0,1.0,0,0,deltaT,0],
[0,0,1.0,0,0,deltaT],
[0,0,0,1.0,0,0],
[0,0,0,0,1.0,0],
[0,0,0,0,0,1.0]])
B_t = np.array([[0,0,0],
[0,0,0],
[0,0,0],
[1.0,0,0],
[0,1.0,0],
[0,0,1.0]])
sigma_ri = 1.0
sigma_ridot = 0.008
mean_epsilon = np.zeros(6)
R = np.diag(np.array([sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot]))
## Observation Model Parameters
C_t = np.array([[1.0,0,0,0,0,0],
[0,1.0,0,0,0,0],
[0,0,1.0,0,0,0]])
sigma_s = 8
Q = sigma_s*sigma_s*np.identity(3)
mean_delta = np.zeros(3)
for i in range(300):
X_init = action_upd(X_init, A_t, B_t, u_t, mean_epsilon, R)
z_t = obsv_upd(X_init, C_t, mean_delta, Q)
observed_vals[i] = z_t.squeeze()
actual_vals[i] = X_init[0:3].squeeze()
fig = go.Figure(data=[go.Scatter3d(x=observed_vals[:, 0],y=observed_vals[:, 1],z=observed_vals[:, 2],mode='lines', name='Observed Trajectory')])
fig.add_trace(go.Scatter3d(x=actual_vals[:, 0],y=actual_vals[:, 1],z=actual_vals[:, 2],mode='lines',name='Actual Trajectory'))
fig.update_layout(title='3D Line Plots of Actual Vs Observed Trajectories',scene=dict(aspectmode='data'))
fig.show()
return 0
## Kalman Filter Update Equations
def kalman_update(mu_tm1, sigma_tm1, u_t, z_t, A_t, B_t, C_t, Q_t, R_t):
n_shape = mu_tm1.shape[0]
C_t_transpose = np.transpose(C_t)
A_t_transpose = np.transpose(A_t)
mu_t_bar = np.dot(A_t, mu_tm1) + np.dot(B_t, u_t)
sigma_t_bar = np.dot(np.dot(A_t, sigma_tm1), A_t_transpose) + R_t
K_t = np.dot(np.dot(sigma_t_bar, C_t_transpose),np.linalg.inv(np.dot(np.dot(C_t, sigma_t_bar),C_t_transpose)+Q_t))
mu_t = mu_t_bar + np.dot(K_t, (z_t-np.dot(C_t, mu_t_bar)))
sigma_t = np.dot((np.identity(n_shape)-np.dot(K_t, C_t)), sigma_t_bar)
return mu_t, sigma_t
## Extract 100 points depaicting the uncertainity ellipses for a distribution
def uncer_ellipse_params(mu_t, sigma_t):
xy = mu_t[0:2].reshape(-1, 1)
xy_cov = sigma_t[:2, :2]
eigen_values, eigen_vectors = np.linalg.eig(xy_cov)
# Determine the major and minor axes lengths (standard deviations)
std_dev_major = np.sqrt(eigen_values[0])
std_dev_minor = np.sqrt(eigen_values[1])
rotation_angle = np.arctan2(eigen_vectors[1, 0], eigen_vectors[0, 0])
theta = np.linspace(0, 2 * np.pi, 100)
x_rotated = mu_t[0] + (std_dev_major * np.cos(theta)) * np.cos(rotation_angle) - (std_dev_minor * np.sin(theta)) * np.sin(rotation_angle)
y_rotated = mu_t[1] + (std_dev_major * np.cos(theta)) * np.sin(rotation_angle) + (std_dev_minor * np.sin(theta)) * np.cos(rotation_angle)
return x_rotated, y_rotated
## initialise parameters, estimate and plot
def simulate_and_estimate():
X_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
mu_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
sigma_init = (0.008)*(0.008)*np.identity(6)
observed_traj = np.zeros((300, 3))
actual_traj = np.zeros((300, 3))
estimated_traj = np.zeros((300, 3))
uncertainity_ellipse_values = np.zeros((300, 100, 2))
## Action Model Parameters
deltaT = 1.0
A_t = np.array([[1.0,0,0,deltaT,0,0],
[0,1.0,0,0,deltaT,0],
[0,0,1.0,0,0,deltaT],
[0,0,0,1.0,0,0],
[0,0,0,0,1.0,0],
[0,0,0,0,0,1.0]])
B_t = np.array([[0,0,0],
[0,0,0],
[0,0,0],
[1.0,0,0],
[0,1.0,0],
[0,0,1.0]])
sigma_ri = 1.0
sigma_ridot = 0.008
mean_epsilon = np.zeros(6)
R = np.diag(np.array([sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot]))
## Observation Model Parameters
C_t = np.array([[1.0,0,0,0,0,0],
[0,1.0,0,0,0,0],
[0,0,1.0,0,0,0]])
sigma_s = 8
Q = sigma_s*sigma_s*np.identity(3)
mean_delta = np.zeros(3)
for i in range(300):
tt_now = i * 1.0 ## Update this to a different timestamp if alternate readings reqd
u_t = np.array([[cos(tt_now)], [sin(tt_now)], [sin(tt_now)]]) ## Control Inputs are sinusoidal functions
X_init = action_upd(X_init, A_t, B_t, u_t, mean_epsilon, R)
z_t = obsv_upd(X_init, C_t, mean_delta, Q)
mu_init, sigma_init = kalman_update(mu_init, sigma_init, u_t, z_t, A_t, B_t, C_t, Q, R)
observed_traj[i] = z_t.squeeze()
actual_traj[i] = X_init[0:3].squeeze()
estimated_traj[i] = mu_init[0:3].squeeze()
x_uncert_points, y_uncert_points = uncer_ellipse_params(mu_init, sigma_init)
uncertainity_ellipse_values[i] = np.column_stack((x_uncert_points, y_uncert_points))
fig = go.Figure(data=[go.Scatter3d(x=observed_traj[:, 0],y=observed_traj[:, 1],z=observed_traj[:, 2],mode='lines',name='Noisy Observations')])
fig.add_trace(go.Scatter3d(x=actual_traj[:, 0],y=actual_traj[:, 1],z=actual_traj[:, 2],mode='lines',name='Actual Trajectory'))
fig.add_trace(go.Scatter3d(x=estimated_traj[:, 0],y=estimated_traj[:, 1],z=estimated_traj[:, 2],mode='lines',name='Kalman Estimation'))
fig.update_layout(title='3D Line Plots of Actual vs Estimated Trajectory, and Noisy Observations',scene=dict(aspectmode='data'))
fig2 = go.Figure(data=[go.Scatter(x=estimated_traj[:, 0],y=estimated_traj[:, 1],mode='lines',name='Trajectory Points',)])
for i in range(300):
fig2.add_trace(go.Scatter(x=uncertainity_ellipse_values[i][:,0],y=uncertainity_ellipse_values[i][:,1],mode='lines',line=dict(color='red', width=1),showlegend=False))
fig2.update_layout(title='Projection of Estimated Traj into X-Y plane',scene=dict(aspectmode='data'))
fig.show()
fig2.show()
fig.write_html("trajs.html")
fig2.write_html("ue.html")
return 0
## To analyse estimation accuracy of variables not monitored by the sensors
def check_velocity_estimation():
X_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
mu_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
sigma_init = (0.008)*(0.008)*np.identity(6)
actual_vel = np.zeros((300, 3))
estimated_vel = np.zeros((300, 3))
## Action Model Parameters
deltaT = 1.0
A_t = np.array([[1.0,0,0,deltaT,0,0],
[0,1.0,0,0,deltaT,0],
[0,0,1.0,0,0,deltaT],
[0,0,0,1.0,0,0],
[0,0,0,0,1.0,0],
[0,0,0,0,0,1.0]])
B_t = np.array([[0,0,0],
[0,0,0],
[0,0,0],
[1.0,0,0],
[0,1.0,0],
[0,0,1.0]])
sigma_ri = 1.0
sigma_ridot = 0.008
mean_epsilon = np.zeros(6)
R = np.diag(np.array([sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot]))
## Observation Model Parameters
C_t = np.array([[1.0,0,0,0,0,0],
[0,1.0,0,0,0,0],
[0,0,1.0,0,0,0]])
sigma_s = 8
Q = sigma_s*sigma_s*np.identity(3)
mean_delta = np.zeros(3)
for i in range(300):
tt_now = i
u_t = np.array([[cos(tt_now)], [sin(tt_now)], [sin(tt_now)]]) ## Control Inputs are sinusoidal functions
X_init = action_upd(X_init, A_t, B_t, u_t, mean_epsilon, R)
z_t = obsv_upd(X_init, C_t, mean_delta, Q)
mu_init, sigma_init = kalman_update(mu_init, sigma_init, u_t, z_t, A_t, B_t, C_t, Q, R)
actual_vel[i] = X_init[3:6].squeeze()
estimated_vel[i] = mu_init[3:6].squeeze()
fig = go.Figure(data=[go.Scatter3d(x=actual_vel[:, 0],y=actual_vel[:, 1],z=actual_vel[:, 2],mode='lines',name='Actual Velocity Values')])
fig.add_trace(go.Scatter3d(x=estimated_vel[:, 0],y=estimated_vel[:, 1],z=estimated_vel[:, 2],mode='lines',name='Estimated Velocity Velocity'))
# Update the layout if needed
fig.update_layout(title='3D Line Plots of Actual vs Estimated Velocity Points',scene=dict(aspectmode='data'))
fig.show()
fig.write_html("velPlot.html")
return 0
## Analyse effect of noise vairations on estimates and trajectories
def noise_variations_analysis():
observed_traj_normal = np.zeros((300, 3))
actual_traj_normal = np.zeros((300, 3))
estimated_traj_normal = np.zeros((300, 3))
observed_traj_pos_noise_enhanced = np.zeros((300, 3))
actual_traj_pos_noise_enhanced = np.zeros((300, 3))
estimated_traj_pos_noise_enhanced = np.zeros((300, 3))
observed_traj_vel_noise_enhanced = np.zeros((300, 3))
actual_traj_vel_noise_enhanced = np.zeros((300, 3))
estimated_traj_vel_noise_enhanced = np.zeros((300, 3))
observed_traj_sensor_noise_enhanced = np.zeros((300, 3))
actual_traj_sensor_noise_enhanced = np.zeros((300, 3))
estimated_traj_sensor_noise_enhanced = np.zeros((300, 3))
uncertainity_ellipse_values_normal = np.zeros((300, 100, 2))
uncertainity_ellipse_values_pos_noise_enhanced = np.zeros((300, 100, 2))
uncertainity_ellipse_values_vel_noise_enhanced = np.zeros((300, 100, 2))
uncertainity_ellipse_values_sensor_noise_enhanced = np.zeros((300, 100, 2))
## Action Model Parameters
deltaT = 1.0
A_t = np.array([[1.0,0,0,deltaT,0,0],
[0,1.0,0,0,deltaT,0],
[0,0,1.0,0,0,deltaT],
[0,0,0,1.0,0,0],
[0,0,0,0,1.0,0],
[0,0,0,0,0,1.0]])
B_t = np.array([[0,0,0],
[0,0,0],
[0,0,0],
[1.0,0,0],
[0,1.0,0],
[0,0,1.0]])
## Observation Model Parameters
C_t = np.array([[1.0,0,0,0,0,0],
[0,1.0,0,0,0,0],
[0,0,1.0,0,0,0]])
##### Normal case 1/4
X_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
mu_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
sigma_init = (0.008)*(0.008)*np.identity(6)
sigma_ri = 1.0
sigma_ridot = 0.008
mean_epsilon = np.zeros(6)
R = np.diag(np.array([sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot]))
sigma_s = 8
Q = sigma_s*sigma_s*np.identity(3)
mean_delta = np.zeros(3)
for i in range(300):
tt_now = i
u_t = np.array([[cos(tt_now)], [sin(tt_now)], [sin(tt_now)]]) ## Control Inputs are sinusoidal functions
X_init = action_upd(X_init, A_t, B_t, u_t, mean_epsilon, R)
z_t = obsv_upd(X_init, C_t, mean_delta, Q)
mu_init, sigma_init = kalman_update(mu_init, sigma_init, u_t, z_t, A_t, B_t, C_t, Q, R)
observed_traj_normal[i] = z_t.squeeze()
actual_traj_normal[i] = X_init[0:3].squeeze()
estimated_traj_normal[i] = mu_init[0:3].squeeze()
x_uncert_points, y_uncert_points = uncer_ellipse_params(mu_init, sigma_init)
uncertainity_ellipse_values_normal[i] = np.column_stack((x_uncert_points, y_uncert_points))
##### Position Noise Enhanced 2/4
X_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
mu_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
sigma_init = (0.008)*(0.008)*np.identity(6)
sigma_ri = 3.0
sigma_ridot = 0.008
mean_epsilon = np.zeros(6)
R = np.diag(np.array([sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot]))
sigma_s = 8
Q = sigma_s*sigma_s*np.identity(3)
mean_delta = np.zeros(3)
for i in range(300):
tt_now = i
u_t = np.array([[cos(tt_now)], [sin(tt_now)], [sin(tt_now)]]) ## Control Inputs are sinusoidal functions
X_init = action_upd(X_init, A_t, B_t, u_t, mean_epsilon, R)
z_t = obsv_upd(X_init, C_t, mean_delta, Q)
mu_init, sigma_init = kalman_update(mu_init, sigma_init, u_t, z_t, A_t, B_t, C_t, Q, R)
observed_traj_pos_noise_enhanced[i] = z_t.squeeze()
actual_traj_pos_noise_enhanced[i] = X_init[0:3].squeeze()
estimated_traj_pos_noise_enhanced[i] = mu_init[0:3].squeeze()
x_uncert_points, y_uncert_points = uncer_ellipse_params(mu_init, sigma_init)
uncertainity_ellipse_values_pos_noise_enhanced[i] = np.column_stack((x_uncert_points, y_uncert_points))
##### Velocity Noise Enhanced 3/4
sigma_ri = 1.0
sigma_ridot = 0.012
mean_epsilon = np.zeros(6)
R = np.diag(np.array([sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot]))
sigma_s = 8
Q = sigma_s*sigma_s*np.identity(3)
mean_delta = np.zeros(3)
X_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
mu_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
sigma_init = (0.008)*(0.008)*np.identity(6)
for i in range(300):
tt_now = i
u_t = np.array([[cos(tt_now)], [sin(tt_now)], [sin(tt_now)]]) ## Control Inputs are sinusoidal functions
X_init = action_upd(X_init, A_t, B_t, u_t, mean_epsilon, R)
# print("Upd shape =", X_init.shape)
z_t = obsv_upd(X_init, C_t, mean_delta, Q)
mu_init, sigma_init = kalman_update(mu_init, sigma_init, u_t, z_t, A_t, B_t, C_t, Q, R)
observed_traj_vel_noise_enhanced[i] = z_t.squeeze()
actual_traj_vel_noise_enhanced[i] = X_init[0:3].squeeze()
estimated_traj_vel_noise_enhanced[i] = mu_init[0:3].squeeze()
x_uncert_points, y_uncert_points = uncer_ellipse_params(mu_init, sigma_init)
uncertainity_ellipse_values_vel_noise_enhanced[i] = np.column_stack((x_uncert_points, y_uncert_points))
##### Sensor Noise enhanced 4/4
sigma_ri = 1.0
sigma_ridot = 0.008
mean_epsilon = np.zeros(6)
R = np.diag(np.array([sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ri*sigma_ri, sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot,sigma_ridot*sigma_ridot]))
sigma_s = 16
Q = sigma_s*sigma_s*np.identity(3)
mean_delta = np.zeros(3)
X_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
mu_init = np.array([[0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]) ## start from (0,0,0) with vel (0,0,0)
sigma_init = (0.008)*(0.008)*np.identity(6)
for i in range(300):
tt_now = i
u_t = np.array([[cos(tt_now)], [sin(tt_now)], [sin(tt_now)]]) ## Control Inputs are sinusoidal functions
X_init = action_upd(X_init, A_t, B_t, u_t, mean_epsilon, R)
z_t = obsv_upd(X_init, C_t, mean_delta, Q)
mu_init, sigma_init = kalman_update(mu_init, sigma_init, u_t, z_t, A_t, B_t, C_t, Q, R)
observed_traj_sensor_noise_enhanced[i] = z_t.squeeze()
actual_traj_sensor_noise_enhanced[i] = X_init[0:3].squeeze()
estimated_traj_sensor_noise_enhanced[i] = mu_init[0:3].squeeze()
x_uncert_points, y_uncert_points = uncer_ellipse_params(mu_init, sigma_init)
uncertainity_ellipse_values_sensor_noise_enhanced[i] = np.column_stack((x_uncert_points, y_uncert_points))
fig1 = go.Figure(data = [go.Scatter3d(x=observed_traj_normal[:, 0],y=observed_traj_normal[:, 1],z=observed_traj_normal[:, 2],mode='lines',name='Noisy Observations Normal')])
fig1.add_trace(go.Scatter3d(x=actual_traj_normal[:, 0],y=actual_traj_normal[:, 1],z=actual_traj_normal[:, 2],mode='lines',name='Actual Trajectory Normal'))
fig1.add_trace(go.Scatter3d(x=estimated_traj_normal[:, 0],y=estimated_traj_normal[:, 1],z=estimated_traj_normal[:, 2],mode='lines',name='Kalman Estimation Normal'))
fig1.add_trace(go.Scatter3d(x=observed_traj_pos_noise_enhanced[:, 0],y=observed_traj_pos_noise_enhanced[:, 1],z=observed_traj_pos_noise_enhanced[:, 2],mode='lines',name='Noisy Observations Position Noise Enhanced'))
fig1.add_trace(go.Scatter3d(x=actual_traj_pos_noise_enhanced[:, 0],y=actual_traj_pos_noise_enhanced[:, 1],z=actual_traj_pos_noise_enhanced[:, 2],mode='lines',name='Actual Trajectory Position Noise Enhanced'))
fig1.add_trace(go.Scatter3d(x=estimated_traj_pos_noise_enhanced[:, 0],y=estimated_traj_pos_noise_enhanced[:, 1],z=estimated_traj_pos_noise_enhanced[:, 2],mode='lines',name='Kalman Estimation Position Noise Enhanced'))
fig2 = go.Figure(data=[go.Scatter3d(x=observed_traj_normal[:, 0],y=observed_traj_normal[:, 1],z=observed_traj_normal[:, 2],mode='lines', name='Noisy Observations Normal')])
fig2.add_trace(go.Scatter3d(x=actual_traj_normal[:, 0],y=actual_traj_normal[:, 1],z=actual_traj_normal[:, 2],mode='lines',name='Actual Trajectory Normal'))
fig2.add_trace(go.Scatter3d(x=estimated_traj_normal[:, 0],y=estimated_traj_normal[:, 1],z=estimated_traj_normal[:, 2],mode='lines',name='Kalman Estimation Normal'))
fig2.add_trace(go.Scatter3d(x=observed_traj_vel_noise_enhanced[:, 0],y=observed_traj_vel_noise_enhanced[:, 1],z=observed_traj_vel_noise_enhanced[:, 2],mode='lines',name='Noisy Observations Velocity Noise Enhanced'))
fig2.add_trace(go.Scatter3d(x=actual_traj_vel_noise_enhanced[:, 0],y=actual_traj_vel_noise_enhanced[:, 1],z=actual_traj_vel_noise_enhanced[:, 2],mode='lines',name='Actual Trajectory Velocity Noise Enhanced'))
fig2.add_trace(go.Scatter3d(x=estimated_traj_vel_noise_enhanced[:, 0],y=estimated_traj_vel_noise_enhanced[:, 1],z=estimated_traj_vel_noise_enhanced[:, 2],mode='lines',name='Kalman Estimation Velocity Noise Enhanced'))
fig3 = go.Figure(data=[go.Scatter3d(x=observed_traj_normal[:, 0],y=observed_traj_normal[:, 1],z=observed_traj_normal[:, 2],mode='lines',name='Noisy Observations Normal')])
fig3.add_trace(go.Scatter3d(x=actual_traj_normal[:, 0],y=actual_traj_normal[:, 1],z=actual_traj_normal[:, 2],mode='lines',name='Actual Trajectory Normal'))
fig3.add_trace(go.Scatter3d(x=estimated_traj_normal[:, 0],y=estimated_traj_normal[:, 1],z=estimated_traj_normal[:, 2],mode='lines',name='Kalman Estimation Normal'))
fig3.add_trace(go.Scatter3d(x=observed_traj_sensor_noise_enhanced[:, 0],y=observed_traj_sensor_noise_enhanced[:, 1],z=observed_traj_sensor_noise_enhanced[:, 2],mode='lines',name='Noisy Observations Sensor Noise Enhanced'))
fig3.add_trace(go.Scatter3d(x=actual_traj_sensor_noise_enhanced[:, 0],y=actual_traj_sensor_noise_enhanced[:, 1],z=actual_traj_sensor_noise_enhanced[:, 2],mode='lines',name='Actual Trajectory Sensor Noise Enhanced'))
fig3.add_trace(go.Scatter3d(x=estimated_traj_sensor_noise_enhanced[:, 0],y=estimated_traj_sensor_noise_enhanced[:, 1],z=estimated_traj_sensor_noise_enhanced[:, 2], mode='lines',name='Kalman Estimation Sensor Noise Enhanced'))
fig4 = go.Figure(data=[go.Scatter(x=estimated_traj_normal[:, 0],y=estimated_traj_normal[:, 1],mode='lines',name='Trajectory Points Normal')])
fig4.add_trace(go.Scatter(x=estimated_traj_pos_noise_enhanced[:, 0],y=estimated_traj_pos_noise_enhanced[:, 1],mode='lines',name='Trajectory Points with Position Noise'))
fig4.add_trace(go.Scatter(x=estimated_traj_vel_noise_enhanced[:, 0],y=estimated_traj_vel_noise_enhanced[:, 1],mode='lines',name='Trajectory Points with Velocity Noise'))
fig4.add_trace(go.Scatter(x=estimated_traj_sensor_noise_enhanced[:, 0],y=estimated_traj_sensor_noise_enhanced[:, 1],mode='lines',name='Trajectory Points with Sensor Noise'))
for i in range(0, 300): # do range(0,300, 5) for selective ellipses
fig4.add_trace(go.Scatter(x=uncertainity_ellipse_values_normal[i][:,0],y=uncertainity_ellipse_values_normal[i][:,1],mode='lines', line=dict(color='red', width=1),showlegend=False))
fig4.add_trace(go.Scatter(x=uncertainity_ellipse_values_pos_noise_enhanced[i][:,0],y=uncertainity_ellipse_values_pos_noise_enhanced[i][:,1],mode='lines', line=dict(color='red', width=1),showlegend=False))
fig4.add_trace(go.Scatter(x=uncertainity_ellipse_values_vel_noise_enhanced[i][:,0],y=uncertainity_ellipse_values_vel_noise_enhanced[i][:,1],mode='lines', line=dict(color='red', width=1),showlegend=False))
fig4.add_trace(go.Scatter(x=uncertainity_ellipse_values_sensor_noise_enhanced[i][:,0],y=uncertainity_ellipse_values_sensor_noise_enhanced[i][:,1],mode='lines', line=dict(color='red', width=1),showlegend=False))
fig4.update_layout(
title='Uncertainity Ellipses and Projection',
scene=dict(aspectmode='data')
)
fig5 = go.Figure(data = [go.Scatter3d(x=actual_traj_normal[:, 0],y=actual_traj_normal[:, 1],z=actual_traj_normal[:, 2],mode='lines',name='Actual Trajectory Normal')])
fig5.add_trace(go.Scatter3d(x=actual_traj_pos_noise_enhanced[:, 0],y=actual_traj_pos_noise_enhanced[:, 1],z=actual_traj_pos_noise_enhanced[:, 2],mode='lines',name='Actual Trajectory Pos Noise'))
fig5.add_trace(go.Scatter3d(x=actual_traj_vel_noise_enhanced[:, 0],y=actual_traj_vel_noise_enhanced[:, 1],z=actual_traj_vel_noise_enhanced[:, 2],mode='lines',name='Actual Trajectory Vel Noise'))
fig5.add_trace(go.Scatter3d(x=actual_traj_sensor_noise_enhanced[:, 0],y=actual_traj_sensor_noise_enhanced[:, 1],z=actual_traj_sensor_noise_enhanced[:, 2],mode='lines',name='Actual Trajectory Sensor Noise'))
fig5.add_trace(go.Scatter3d(x=estimated_traj_normal[:, 0],y=estimated_traj_normal[:, 1],z=estimated_traj_normal[:, 2],mode='lines',name='Estimated Trajectory Normal'))
fig5.add_trace(go.Scatter3d(x=estimated_traj_pos_noise_enhanced[:, 0],y=estimated_traj_pos_noise_enhanced[:, 1],z=estimated_traj_pos_noise_enhanced[:, 2],mode='lines',name='Estimated Trajectory Pos Noise'))
fig5.add_trace(go.Scatter3d(x=estimated_traj_vel_noise_enhanced[:, 0],y=estimated_traj_vel_noise_enhanced[:, 1],z=estimated_traj_vel_noise_enhanced[:, 2],mode='lines',name='Estimated Trajectory Vel Noise'))
fig5.add_trace(go.Scatter3d(x=estimated_traj_sensor_noise_enhanced[:, 0],y=estimated_traj_sensor_noise_enhanced[:, 1],z=estimated_traj_sensor_noise_enhanced[:, 2],mode='lines',name='Estimated Trajectory Sensor Noise'))
fig1.show()
fig2.show()
fig3.show()
fig4.show()
fig5.show()
fig1.write_html("posNoiseComp.html")
fig2.write_html("velNoiseComp.html")
fig3.write_html("sensorNoiseComp.html")
fig4.write_html("ue_noiseVariations.html")
fig5.write_html("allTrajs_noisy.html")
return 0