ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
KalmanFilter.tpp
Go to the documentation of this file.
1#pragma once
2
3template<typename T>
4KalmanFilter<T>::KalmanFilter(T processNoise, T sensorNoise, T errorCovariance) {
5 this->processNoise = processNoise;
6 this->sensorNoise = sensorNoise;
7 this->estimation = 0;
8 this->errorCovariance = errorCovariance;
9}
10
11template<typename T>
12T KalmanFilter<T>::Filter(T value) {
13 // Prediction
14 errorCovariance += processNoise;
15
16 // Update
17 T kalmanGain = errorCovariance / (errorCovariance + sensorNoise);
18 estimation += kalmanGain * (value - estimation);
19 errorCovariance *= T(1) - kalmanGain;
20
21 return estimation;
22}