classdef BaseObserverModel < handle
%BASEOBSERVERMODEL Abstract base class for observer models
% BaseObserverModel is a base class that encapsulates noisy process
% observation. It is abstract, and cannot be directly instantiated.
%
% BaseObserverModel methods:
% simulate - simulate a noisy measurement.
% observerData - given a Gaussian prediction for the state and an actual
% measurement, returns covariance data based on
% observation model.
%
properties
h % function handle for h(x,t) or h(x,t,v)
R % covariance of observation noise
isLinearNoise = true; % true if the noise is linear
J_x % function handle for Jacobian of h with respect to x
J_w % function handle for Jacobian of h with respect to w
% used only if isLinear == false
end
properties (Access = protected)
cholR;
end
methods
function obsModel = BaseObserverModel(h, R, varargin)
if nargin == 0
return;
end
if isa(h, 'BaseObserverModel')
assert(nargin == 1, 'Too many arguments');
obsModel.h = h.h;
obsModel.R = h.R;
obsModel.isLinearNoise = h.isLinearNoise;
obsModel.J_x = h.J_x;
obsModel.J_w = h.J_w;
obsModel.cholR = h.cholR;
else
obsModel.h = h;
obsModel.R = R;
obsModel.cholR = sdchol(obsModel.R);
if ~isempty(varargin)
% now parse option/value pairs
for k = 1:2:length(varargin)
obsModel.(varargin{k}) = varargin{k+1};
end
end
end
end
function observation = simulate(this, state, t)
%SIMULATE Simulate a measurement of the true state
%
if nargin == 2
t = 0;
end
v = (randn(1, size(this.cholR, 2)) * this.cholR)';
if this.isLinear
observation(k) = this.h(state, t) + v;
else
observation(k) = this.h(state, v, t);
end
end
end
methods (Abstract = true)
[C_zz C_xz innovation] = observerData(this, predMean, predCov, ...
meas, curTime);
%OBSERVERDATA
%
%
end
end