简体   繁体   English

卡尔曼滤波器 2d 与 pykalman

[英]kalman filter 2d with pykalman

I'm trying to use the kalman filter on a dataset of GPS data for noise reduction.我正在尝试在 GPS 数据集上使用卡尔曼滤波器来降噪。 For this I checked if there already is an online implementation and found pykalman.为此,我检查了是否已经有在线实现并找到了 pykalman。 I'm trying to use it, but for some reason I'm not getting how i'm supposed to correctly assign the matrixes.我正在尝试使用它,但由于某种原因,我没有得到我应该如何正确分配矩阵。 When i try to run it, it tells me i have a dimension error.当我尝试运行它时,它告诉我我有尺寸错误。 So first things first, what I'm trying to do/get: I want the kalman filter to estimate the postion of the next time step with the old positon + velocity * t.所以首先,我想要做/得到什么:我希望卡尔曼滤波器用旧的位置 + 速度 * t 估计下一个时间步的位置。 The Velocity for the next step is simply the old velocity.下一步的速度就是旧的速度。 Each time step is excatly 1 second.每个时间步长是 1 秒。 I have measurments in x and y direction and with x_t,y_t,vx_t,vy_t the Transition matrix should look something like this (I think):我在 x 和 y 方向上进行了测量,对于 x_t,y_t,vx_t,vy_t,Transition 矩阵应该看起来像这样(我认为):

transition_matrix = np.array([[1, 0,1,0],
                              [0, 1,0,1],
                              [0,0,1,0],
                              [0,0,0,1]])
    

My measurements look like this:我的测量结果如下所示:

[[ 7.616984 47.53661 ]
 [ 7.616999 47.536629]
 [ 7.616997 47.536635]
 ...
 [ 7.617117 47.536999]
 [ 7.617117 47.536999]
 [ 7.617117 47.536999]]

What i tried so far: I have tried to piece together, how it works from variuos online sources and came up with this:到目前为止我尝试了什么:我试图拼凑起来,它是如何从各种在线资源中工作的,并想出了这个:

import numpy as np
import pykalman
import geopandas
measurments= np.asarray(gdf[["Longitude_deg", "Latitude_deg"]])
#gdf is a geopandas dataframe, but no i'm not currently using the geometry of it.
transition_matrix = np.array([[1, 0,1,0],
                              [0, 1,0,1],
                              [0,0,1,0],
                              [0,0,0,1]])
#the pykalman documentation says the model parameter can but don't have to be specified and it will simply use defaults for unspecified parameters:
kf = pykalman.KalmanFilter(
      transition_matrices =transition_matrix
)
        
(smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurments)
    

Trying to run the last part will give me the following error:尝试运行最后一部分会给我以下错误:

shapes (2,1) and (2,) not aligned: 1 (dim 1) != 2 (dim 0)形状 (2,1) 和 (2,) 未对齐:1 (dim 1) != 2 (dim 0)

Which I understand as far as the Matrices used don't have the correct sizes to be used with each other.据我所知,所使用的矩阵没有正确的尺寸可以相互使用。 In general my understanding of matrices is very limited.一般来说,我对矩阵的理解非常有限。 I hope someone can help me.我希望有一个人可以帮助我。

Based on your model your state vector is the following: [x, y, v_x, v_y] and you are observing (measuring) only [x, y] .根据您的 model 您的 state 向量如下: [x, y, v_x, v_y]并且您仅观察(测量) [x, y] So you need to properly define also measurement matrix H , which maps the true state space into the observed space: z=Hx + noise .因此,您还需要正确定义测量矩阵H ,它将真正的 state 空间映射到观察到的空间: z=Hx + noise So in your case, it is very simple:所以在你的情况下,这很简单:

observation_matrix = np.array(
    [[1, 0, 0, 0],
     [0, 1, 0, 0]]
)

This will work properly:这将正常工作:

kf = pykalman.KalmanFilter(
    transition_matrices=transition_matrix,
    observation_matrices=observation_matrix
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM