@@ -0,0 +1,2454 @@
+package com.example.warner;%0A%0A/**%0A * Simple implementation of the Kalman Filter for 1D data.%0A * Originally written in JavaScript by Wouter Bulten%0A *%0A * Now rewritten into Java%0A * 2017%0A *%0A * @license MIT License%0A *%0A * @author Andreas Eppler%0A *%0A * @see https://github.com/wouterbulten/kalmanjs%0A *%0A */%0Apublic class KalmanFilter %7B%0A%0A    private double A = 1;%0A    private double B = 0;%0A    private double C = 1;%0A%0A    private double R;%0A    private double Q;%0A%0A    private double cov = Double.NaN;%0A    private double x = Double.NaN;%0A%0A    /**%0A     * Constructor%0A     *%0A     * @param R Process noise%0A     * @param Q Measurement noise%0A     * @param A State vector%0A     * @param B Control vector%0A     * @param C Measurement vector%0A     */%0A    %0A    public KalmanFilter(double R, double Q, double A, double B , double C)%7B%0A        this.R = R;%0A        this.Q = Q;%0A%0A        this.A = A;%0A        this.B = B;%0A        this.C = C;%0A%0A        this.cov = Double.NaN;%0A        this.x = Double.NaN; // estimated signal without noise%0A    %7D%0A%0A/*%0A    public KalmanFilter(double R, double Q)%7B%0A        this.R = R;%0A        this.Q = Q;%0A%0A    %7D%0A*/%0A%0A    /**%0A     * Filters a measurement%0A     *%0A     * @param measurement The measurement value to be filtered%0A     * @param u The controlled input value%0A     * @return The filtered value%0A     */%0A    public double filter(double measurement, double u)%7B%0A%0A        if (Double.isNaN(this.x)) %7B%0A            this.x = (1 / this.C) * measurement;%0A            this.cov = (1 / this.C) * this.Q * (1 / this.C);%0A        %7Delse %7B%0A            double predX = (this.A * this.x) + (this.B * u);%0A            double predCov = ((this.A * this.cov) * this.A) + this.R;%0A%0A            // Kalman gain%0A            double K = predCov * this.C * (1 / ((this.C * predCov * this.C) + this.Q));%0A%0A            // Correction%0A            this.x = predX + K * (measurement - (this.C * predX));%0A            this.cov = predCov - (K * this.C * predCov);%0A        %7D%0A        return this.x;%0A    %7D%0A%0A%0A    /**%0A     *%0A     * @return The last measurement fed into the filter%0A     */%0A    public double lastMeasurement()%7B%0A        return this.x;%0A    %7D%0A%0A    /**%0A     * Sets measurement noise%0A     *%0A     * @param noise The new measurement noise%0A     */%0A    public void setMeasurementNoise(double noise)%7B%0A        this.Q = noise;%0A    %7D%0A%0A    /**%0A     * Sets process noise%0A     *%0A     * @param noise The new process noise%0A     */%0A    public void setProcessNoise(double noise)%7B%0A        this.R = noise;%0A    %7D%0A%7D

Add a KalmanFilter for Java that takes input parameter