#include "kalmanFilter.h"
/**
******************************************************************************
* @file kalmanFilter.c
* @brief 初始化卡尔曼滤波参数.
* @param kalmanFilter 卡尔曼参数结构体
* @param FirstMeaValue 测量值
* @param E_mea 固有测量误差
* @param FirstEstValue 卡尔曼参数结构体
* @param E_est 卡尔曼参数结构体
* @retval None
*****************************************************************************/
void Kalman_Init(KalmanFilter* kalmanFilter, float FirstMeaValue, float E_mea, float FirstEstValue, float E_est)
{
kalmanFilter->x_est = FirstEstValue;
kalmanFilter->x_mea = FirstMeaValue;
kalmanFilter->e_est = E_est;
kalmanFilter->e_mea = E_mea;
kalmanFilter->Kk = Kk_calc(kalmanFilter->e_est, kalmanFilter->e_mea);
}
/**
******************************************************************************
* @file kalmanFilter.c
* @brief 初始化卡尔曼滤波参数.
* @param kalmanFilter 卡尔曼参数结构体
* @param newMeaValue 新的测量值
* @retval None
*****************************************************************************/
void Kalman_Update(KalmanFilter* kalmanFilter, float newMeaValue) {
float temp = kalmanFilter->e_est;
kalmanFilter->x_est = kalmanFilter->x_est + kalmanFilter->Kk * (newMeaValue - kalmanFilter->x_est);
kalmanFilter->x_mea = newMeaValue;
kalmanFilter->Kk = Kk_calc(kalmanFilter->e_est, kalmanFilter->e_mea);
kalmanFilter->e_est = (1 - kalmanFilter->Kk) * temp;
}