function value($value, $u = 0)
    {
        if (null === $this->x) {
            $this->x = (1 / $this->measurementVector) * $value;
            $this->cov = (1 / $this->measurementVector) * $this->measurementNoise * (1 / $this->measurementVector);
        } else {
            // Compute prediction
            $predX = ($this->stateVector * $this->x) + ($this->controlVector * $u);
            $predCov = (($this->stateVector * $this->cov) * $this->stateVector) + $this->processNoise;

            // Kalman gain
            $K = $predCov * $this->measurementVector *
                (1 / (($this->measurementVector * $predCov * $this->measurementVector) + $this->measurementNoise));

            // Correction
            $this->x = $predX + $K * ($value - ($this->measurementVector * $predX));
            $this->cov = $predCov - ($K * $this->measurementVector * $predCov);
        }

        return $this->x;
    }
function value($value, $u = 0)
    {
        if (null === $this->x) {
            $this->x = (1 / $this->measurementVector) * $value;
            $this->cov = (1 / $this->measurementVector) * $this->measurementNoise * (1 / $this->measurementVector);
        } else {
            // Compute prediction
            $predX = ($this->stateVector * $this->x) + ($this->controlVector * $u);
            $predCov = (($this->stateVector * $this->cov) * $this->stateVector) + $this->processNoise;

            // Kalman gain
            $K = $predCov * $this->measurementVector *
                (1 / (($this->measurementVector * $predCov * $this->measurementVector) + $this->measurementNoise));

            // Correction
            $this->x = $predX + $K * ($value - ($this->measurementVector * $predX));
            $this->cov = $predCov - ($K * $this->measurementVector * $predCov);
        }

        return $this->x;
    }
function value ( $ value , $ u = 0 ) { if ( null === $ this -> x ) { $ this -> x = ( 1 / $ this -> measurementVector ) * $ value ; $ this -> cov = ( 1 / $ this -> measurementVector ) * $ this -> measurementNoise * ( 1 / $ this -> measurementVector ) ; } else { // Compute prediction $ predX = ( $ this -> stateVector * $ this -> x ) + ( $ this -> controlVector * $ u ) ; $ predCov = ( ( $ this -> stateVector * $ this -> cov ) * $ this -> stateVector ) + $ this -> processNoise ; // Kalman gain $ K = $ predCov * $ this -> measurementVector * ( 1 / ( ( $ this -> measurementVector * $ predCov * $ this -> measurementVector ) + $ this -> measurementNoise ) ) ; // Correction $ this -> x = $ predX + $ K * ( $ value - ( $ this -> measurementVector * $ predX ) ) ; $ this -> cov = $ predCov - ( $ K * $ this -> measurementVector * $ predCov ) ; } return $ this -> x ; }
Filter a new value
@param  float $value Measurement
@param  float|int $u Control
@return float
Filter a new value