Code covered by the BSD License  

Highlights from
Kalman filtering framework

image thumbnail
from Kalman filtering framework by David Ogilvie
Object framework for filtering using Kalman filter, EKF, or UKF.

LinearObserverModel
classdef LinearObserverModel < BaseObserverModel
%LINEAROBSERVERMODEL  Linear observer model
%   sysModel = LinearObserverModel(H, R) creates a class
%   representing an observer measuring a state x by the formula
%      z = H*x + v
%   where v is gaussian noise with mean 0 and covariance R.

    properties
        H  % linear transformation which applied to state gives measurement
    end
    
    methods
        function obsModel = LinearObserverModel(H, R, varargin)
            if nargin > 0
                assert(isnumeric(H));
                assert(isnumeric(R));
                h = @(x,t) (H*x);
                superargs = {h, R, varargin{:}};
            else
                superargs = {};
            end

            obsModel = obsModel@BaseObserverModel(superargs{:});
            
            if nargin > 0
                obsModel.H = H;
                obsModel.J_x = @(x,t) (H);
                obsModel.J_w = @(x,t) (0);
            end
        end
        
        function observation = simulate(this, state, curTime)
        % simulate a true state observation
        
            temp = this.H * state;
            observation = temp + this.cholR' * randn(size(this.cholR, 1), 1);
        end        
        
        function [S C innovation] = observerData(this, predMean, ...
                                                 predCov, meas, curTime)
            S = (this.H * predCov * this.H') + this.R;
            S = (S + S')/2;

            C = predCov * this.H';
            innovation = meas - this.H * predMean;
        end

    end
end

Contact us at files@mathworks.com