Simple Kalman Filter in C
This code snippet covers simple Kalman filters in C.
Join the DZone community and get the full member experience.
Join For Free/** A simple kalman filter example by Adrian Boeing
www.adrianboeing.com
*/
โ
โ
double frand() {
return 2*((rand()/(double)RAND_MAX) - 0.5);
}
โ
int main() {
โ
//initial values for the kalman filter
float x_est_last = 0;
float P_last = 0;
//the noise in the system
float Q = 0.022;
float R = 0.617;
โ
float K;
float P;
float P_temp;
float x_temp_est;
float x_est;
float z_measured; //the 'noisy' value we measured
float z_real = 0.5; //the ideal value we wish to measure
โ
srand(0);
โ
//initialize with a measurement
x_est_last = z_real + frand()*0.09;
โ
float sum_error_kalman = 0;
float sum_error_measure = 0;
โ
for (int i=0;i
Opinions expressed by DZone contributors are their own.
Comments