Skip to content

Instantly share code, notes, and snippets.

@achutharanga
Last active September 16, 2019 15:04
Show Gist options
  • Save achutharanga/4e542c39bcbd28071d4f to your computer and use it in GitHub Desktop.
Save achutharanga/4e542c39bcbd28071d4f to your computer and use it in GitHub Desktop.
/**
* {@link Kalman} is an one dimensional implementation of KALMAN filter used to
* predict a noisy signal containing fluctuations due to measurement errors, noise etc.
*
* @author AchuthaRanga.Chenna
*
*/
public class SimpleKalman {
/** process noise COVARIANCE */
private double q = 1.48d;
/** measurement noise COVARIANCE */
private double r = 442.0d;
/** Measurement value */
private double x = 0d;
/** estimation error COVARIANCE */
private double p = 50d;
/** KALMAN gain */
private double k = 1d;
/**
* Init the filter with initial value of signal.
* @param initial_measurement
*/
public Kalman(double initial_measurement) {
this.x = initial_measurement;
}
/**
* Method to get the predicted value of the measured signal value.
*
* @param measurement
* value from real time data.
* @return predicted measurement.
*/
public double getPredicted_Value(double measurement) {
p = p + q;
k = p / (p + r);
x = x + k * (measurement - x);
p = (1 - k) * p;
return x;
}
}
@nurroy
Copy link

nurroy commented Sep 16, 2019

what's p? where's 50 come from? and what's measurement? is it different with x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment