專(zhuān)注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

卡爾曼濾波在單片機(jī)上的使用

作者:佚名   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2012年11月29日   【字體:







#ifndef _KALMAN_H_
#define _KALMAN_H_

extern  KalmanGain;//  卡爾曼增益
extern  EstimateCovariance;//估計(jì)協(xié)方差
extern  MeasureCovariance;//測(cè)量協(xié)方差
extern  EstimateValue;//估計(jì)值
extern void KalmanFilterInit(void);
extern      KalmanFilter(   Measure);
#endif

 

#include "config.h"
#include "math.h"

  KalmanGain;//  卡爾曼增益
  EstimateCovariance;//估計(jì)協(xié)方差
  MeasureCovariance;//測(cè)量協(xié)方差
  EstimateValue;//估計(jì)值

void KalmanFilterInit(void);

extern    float  KalmanFilter(float   Measure);


void KalmanFilterInit(void)
{
EstimateValue=0;

EstimateCovariance=0.1;
 MeasureCovariance=0.02;


}
 
 KalmanFilter(   Measure)
{

//計(jì)算卡爾曼增益
KalmanGain=EstimateCovariance*sqrt(1/(EstimateCovariance*EstimateCovariance+MeasureCovariance*MeasureCovariance));

//計(jì)算本次濾波估計(jì)值
EstimateValue=EstimateValue+KalmanGain*(Measure-EstimateValue);
//更新估計(jì)協(xié)方差

EstimateCovariance=sqrt(1-KalmanGain)*EstimateCovariance;
//更新測(cè)量方差
MeasureCovariance=sqrt(1-KalmanGain)*MeasureCovariance;
//返回估計(jì)值
return EstimateValue;
}

 

關(guān)閉窗口

相關(guān)文章