Go to file
xiahouzuoxin 211d0c9b56 First commit 2014-09-25 11:46:47 +08:00
Makefile First commit 2014-09-25 11:46:47 +08:00
README.md First commit 2014-09-25 11:46:47 +08:00
fixed_test1.h First commit 2014-09-25 11:46:47 +08:00
fixed_test2.h First commit 2014-09-25 11:46:47 +08:00
free_test07.h First commit 2014-09-25 11:46:47 +08:00
kalman_filter.c First commit 2014-09-25 11:46:47 +08:00
kalman_filter.h First commit 2014-09-25 11:46:47 +08:00
plot_result.asv First commit 2014-09-25 11:46:47 +08:00
plot_result.m First commit 2014-09-25 11:46:47 +08:00
result.png First commit 2014-09-25 11:46:47 +08:00
result.txt First commit 2014-09-25 11:46:47 +08:00
test_kalman_filter.c First commit 2014-09-25 11:46:47 +08:00

README.md

Description

这是一个Kalman Filter的程序内含状态量为标量和二维矢量的C程序实现详见kalman_filter.ckalman_filter.h

程序使用的数据类型是float程序测试主要在PC上和TMS320C6000的嵌入式平台。当然因为是C程序移植到其它的平台那是特别的方便

fixed_test1.h``fixed_test2.h以及free_test07.h包含了测试用的数据。test_kalman_filter.c只是一个包含main函数测试程序。

Example

环境要求gcc的C编译环境当然最好有Matlab环境可以非常直观方便的看到滤波效果。

  1. test_kalman_filter.c中修改要使用Kalman滤波的数据只要修改include包含即可

    //#include "fixed_test1.h"
    #include "fixed_test2.h"
    //#include "free_test07.h"
    
  2. 推荐使用已经写好的Makefile文件进行编译执行在gcc环境中依次执行以下命令

    make       " gcc编译程序
    make run   " 运行程序
    

    之后数据和滤波结果会存储到当前目录的result.txt文件中第一列为原数据第二列为滤波结果

  3. 运行Matlab执行脚本plot_result.m,选择result.txt文件即可查看滤波效果,下面为使用标量滤波的效果,卡尔曼滤波器使突变的数据变得平滑。

    result

Usage

实际使用时只需要将kalman_filter.ckalman_filter.h拷贝到工程目录中即可,调用的步骤一律按照:

kalman_init(..., init_x, init_p)
kalman_filter(..., z_measure)

本程序未包含自适应调参,因此请根据实际应用环境仔细调整,很重要。关于调参有很多可研究的地方,主要需要设定的参数如下:

  1. init_x待测量的初始值如有中值一般设成中值如陀螺仪
  2. init_p后验状态估计值误差的方差的初始值
  3. q预测过程噪声方差
  4. r测量观测噪声方差。以陀螺仪为例测试方法是保持陀螺仪不动统计一段时间内的陀螺仪输出数据。数据会近似正态分布按3σ原则取正态分布的(3σ)^2作为r的初始化值。

其中q和r参数尤为重要一般得通过实验测试得到。

关于Kalman滤波的详细公式推导参见论文An Introduction to the Kalman Filter.

About me

Email: xiahouzuoxin@163.com

Copyright (C) MICL,USTB