Sensor fusion combines data from multiple sensors to achieve more accurate and reliable measurements than would be possible using a single sensor.
// Kalman filter implementation
class KalmanFilter {
private:
float Q = 0.1; // Process noise
float R = 0.1; // Measurement noise
float P = 1.0; // Estimation error
float K = 0.0; // Kalman gain
float X = 0.0; // State estimate
public:
float update(float measurement) {
// Prediction
P = P + Q;
// Update
K = P / (P + R);
X = X + K * (measurement - X);
P = (1 - K) * P;
return X;
}
};