卡尔曼滤波C语言实现
卡尔曼5条基本公式,参考 https://wenku.baidu.com/view/8523cb6eaf1ffc4ffe47ac24.html #include "stdio.h" #include "stdlib.h" #include "math.h" #define kal_Q 0.001 /*过程噪声协方差,Q增大,动态响应变快,收敛稳定性变坏*/ #define kal_R 0.542 /*观测噪声协方差,R增大,动态响应变慢,收敛稳定性变好*/ double frand() { return 2 * ((rand() / (double)RAND_MAX) - 0.5); /*随机噪声 */ } /*Measure 原始测量数据 op_flg 0 仅初始化参数 1 执行卡尔曼滤波 */ double Kalman(double measure,int op_flg) { double x_mid,kg,p_mid; static double x_last = 0,p_last = 0; double x_now,p_now; if(op_flg) /*非初始化*/ { x_mid = x_last; p_mid = p_last + kal_Q; kg = p_mid / (p_mid + kal_R); x_now = x_mid + kg * (measure -