如何在单片机上实现卡尔曼滤波详细计算方法和程序概述

电子说

1.2w人已加入

描述

程序

程序


      程序十分简洁易懂,而且使用效果不错,分享

#ifndef _KALMAN_H_

#define _KALMAN_H_

extern  KalmanGain;//  卡尔曼增益

extern  EstimateCovariance;//估计协方差

extern  MeasureCovariance;//测量协方差

extern  EstimateValue;//估计值

extern void KalmanFilterInit(void);

extern      KalmanFilter(   Measure);

#endif

#include "config.h"

#include "math.h"

KalmanGain;//  卡尔曼增益

EstimateCovariance;//估计协方差

MeasureCovariance;//测量协方差

EstimateValue;//估计值

void KalmanFilterInit(void);

extern    float  KalmanFilter(float   Measure);

void KalmanFilterInit(void)

{

EstimateValue=0;

EstimateCovariance=0.1;

MeasureCovariance=0.02;

}

KalmanFilter(   Measure)

{

//计算卡尔曼增益

KalmanGain=EstimateCovariance*sqrt(1/(EstimateCovariance*EstimateCovariance+MeasureCovariance*MeasureCovariance));

//计算本次滤波估计值

EstimateValue=EstimateValue+KalmanGain*(Measure-EstimateValue);

//更新估计协方差

EstimateCovariance=sqrt(1-KalmanGain)*EstimateCovariance;

//更新测量方差

MeasureCovariance=sqrt(1-KalmanGain)*MeasureCovariance;

//返回估计值

return EstimateValue;

}

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分