view core/Kalman.cpp @ 152:8f98b32d0e23 ClockSync

Last commit on this branch for a while. Overall not very succesful
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 05 Oct 2015 13:06:14 +0100
parents 134bff10e561
children
line wrap: on
line source
/*
 * Kalman.cpp
 *
 *  Created on: 20 Sep 2015
 *      Author: giulio
 */
#include "Kalman.h"
void KalmanOne::init(double newQ, double newR, double newX){
	A = 1;
	H = 1;
	Q = newQ;  // covariance of the error on the prediction
	R = newR; // covariance of the measurement error
	x = newX; // 5805.09230769231; % predicted x
	P = 6; // predicted covariance
	return;
}
double KalmanOne:: process(double z){
	double xp = A*x; // I. Prediction of the estimate
	double Pp = A*P*A + Q; // Prediction of the error covariance
	double K = Pp*H/(H*Pp*H + R); // II. Computation of Kalman gain
	x = xp + K*(z - H*xp); // III. Computation of the estimate
	P = Pp - K*H*Pp; // IV. Computation of the error covariance
	return x;
}