annotate core/Kalman.cpp @ 151:e9c9404e3d1f ClockSync

Pff partially working. No PID. When setting the audio clock on the bbb to 44098 the master and slave clock keep diverging instead of converging ...
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 22 Sep 2015 04:10:07 +0100
parents 134bff10e561
children
rev   line source
giuliomoro@149 1 /*
giuliomoro@149 2 * Kalman.cpp
giuliomoro@149 3 *
giuliomoro@149 4 * Created on: 20 Sep 2015
giuliomoro@149 5 * Author: giulio
giuliomoro@149 6 */
giuliomoro@149 7 #include "Kalman.h"
giuliomoro@149 8 void KalmanOne::init(double newQ, double newR, double newX){
giuliomoro@149 9 A = 1;
giuliomoro@149 10 H = 1;
giuliomoro@149 11 Q = newQ; // covariance of the error on the prediction
giuliomoro@149 12 R = newR; // covariance of the measurement error
giuliomoro@149 13 x = newX; // 5805.09230769231; % predicted x
giuliomoro@149 14 P = 6; // predicted covariance
giuliomoro@149 15 return;
giuliomoro@149 16 }
giuliomoro@149 17 double KalmanOne:: process(double z){
giuliomoro@149 18 double xp = A*x; // I. Prediction of the estimate
giuliomoro@149 19 double Pp = A*P*A + Q; // Prediction of the error covariance
giuliomoro@149 20 double K = Pp*H/(H*Pp*H + R); // II. Computation of Kalman gain
giuliomoro@149 21 x = xp + K*(z - H*xp); // III. Computation of the estimate
giuliomoro@149 22 P = Pp - K*H*Pp; // IV. Computation of the error covariance
giuliomoro@149 23 return x;
giuliomoro@149 24 }