1

in the last days I was using pykalman to correct GPS coordinates with acceleration and velocity measurements, which is working fine. Now I would like to combine the resulting coordinates (1) with a second coordinate measurement (2) which is very precise but has a much lower logging rate. I masked all elements of the second measurement which have no value (== 0).

My problem is, that I don't know how the matrices have to look like. Maybe the Kalman Filter is not even suited for what I want to do.

Thank you very much in advance.

for i in range(len(lat1)):

    if i == 0:
        measurements = ma.asarray([(lat1[i], long1[i], lat2[i], long2[i])])
    else:
        measurements = ma.append(measurements, [[lat1[i], long1[i], lat2[i], long2[i]]], axis=0)


for i in range(len(measurements)):
    if measurements[i, 2] == 0:
        measurements[i, 2] = ma.masked
    if measurements[i, 3] == 0:
        measurements[i, 3] = ma.masked


initial_state_mean = ma.asarray([measurements[0, 0], measurements[0, 1], measurements[0, 2], measurements[0, 3]])

transition_matrix = [[0, 0, 1, 0],  
                     [0, 0, 0, 1],  
                     [0, 0, 0, 0],  
                     [0, 0, 0, 0]]  


observation_matrix = [[1, 0, 0, 0],
                      [0, 1, 0, 0],
                      [0, 0, 1, 0],
                      [0, 0, 0, 1]]


kf1 = KalmanFilter(transition_matrices=transition_matrix,
                   observation_matrices=observation_matrix,
                   initial_state_mean=initial_state_mean,
                   observation_covariance=[[0.1, 0, 0, 0],
                                           [0, 0.1, 0, 0],
                                           [0, 0, 1, 0],
                                           [0, 0, 0, 1]],

                   transition_covariance=[[0, 0, 1, 0],
                                          [0, 0, 0, 1],
                                          [0, 0, 0, 0],
                                          [0, 0, 0, 0]]
                   )


(smoothed_state_means, smoothed_state_covariances) = kf1.smooth(measurements)

lat_corr = smoothed_state_means[:, 0]
long_corr = smoothed_state_means[:, 1]
  • 1
    if you have several sensors, which measure the same physical value, you don't need to change your model, you just need to apply the update step of the Kalman Filter several times. Your filtering would look like: init(); update(sensor1); predict(); update(sensor1); update(sensor2); predict(); update(sensor2); and so on... So you proceed updates for the measurements which are available at a given time step. – Anton Oct 22 '19 at 12:06
  • 1
    Here is an example for pykalman: https://stackoverflow.com/questions/47599886/kalman-filter-with-varying-timesteps – Anton Oct 22 '19 at 12:16

0 Answers0