程序十分簡潔易懂,而且使用效果不錯,分享
#ifndef _KALMAN_H_
#define _KALMAN_H_
externEstimateCovariance;//估計協方差
externMeasureCovariance;//測量協方差
externEstimateValue;//估計值
extern void KalmanFilterInit(void);
extern KalmanFilter( Measure);
#endif
#include "config.h"
#include "math.h"
KalmanGain;//卡爾曼增益
EstimateCovariance;//估計協方差
MeasureCovariance;//測量協方差
EstimateValue;//估計值
void KalmanFilterInit(void);
extern floatKalmanFilter(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;
}
-
單片機
+關注
關注
6067文章
44961瀏覽量
648878 -
程序
+關注
關注
117文章
3825瀏覽量
82690 -
卡爾曼濾波
+關注
關注
3文章
166瀏覽量
25040
原文標題:在單片機上實現卡爾曼濾波
文章出處:【微信號:mcu168,微信公眾號:硬件攻城獅】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
教你在單片機上套公式實現卡爾曼濾波器
卡爾曼濾波程序
使用51單片機實現MPU6050的卡爾曼濾波算法代碼免費下載

MCS51單片機程序設計時堆棧的計算方法解析
什么是卡爾曼濾波?卡爾曼濾波的作用是什么

評論