1 function [xerr, P] = mctest2(type, N, M)
\r
4 % Toolbox for nonlinear filtering.
\r
5 % Copyright (C) 2005 Gustaf Hendeby, Jakob Rosén
\r
7 % This program is free software; you can redistribute it and/or
\r
8 % modify it under the terms of the GNU General Public License
\r
9 % as published by the Free Software Foundation; either version 2
\r
10 % of the License, or (at your option) any later version.
\r
12 % This program is distributed in the hope that it will be useful,
\r
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 % GNU General Public License for more details.
\r
17 % You should have received a copy of the GNU General Public License
\r
18 % along with this program; if not, write to the Free Software
\r
19 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
32 %h={'x1','x2','x4'};
\r
38 e_var=[0.25 0.2 0.1];
\r
40 %model=danl(f, gw, [], h, [], [0 0 0 0]',...
\r
41 % sqrt(w_var), sqrt(e_var), [], 1, {'x1','x2','x3','x4'});
\r
42 model=danl(f, gw, [], h, [], [0 0 0 0]',...
\r
43 w_var, e_var, [], 1, {'x1','x2','x3','x4'});
\r
45 %model=danl(f, gw, [], h, [], [0 0 0 0]',...
\r
46 % sqrt(w_var), sqrt(e_var), [1 1 1 1], 1, {'x1','x2','x3','x4'});
\r
49 xerr = zeros(4, N, M);
\r
50 P = zeros(4, 4, N, M);
\r
54 fprintf('MC run %g...\n', i);
\r
55 % Initialize new objects to get entirely new random data
\r
56 simobj=simulator(model);
\r
57 if strcmpi(type, 'EKF')
\r
58 filterobj = ekf(model);
\r
59 elseif strcmpi(type, 'SIR')
\r
60 filterobj = sir(model);
\r
62 simobj = simulate(simobj,N);
\r
63 filterobj = filter(filterobj, simobj);
\r
65 xerr(:,:, i) = get(filterobj, 'xhat') - get(simobj, 'x');
\r
66 % P(:,:, :, i) = reshape(cell2mat(get(filterobj, 'Phat')), 4, 4, N);
\r
67 P(:,:, :, i) = get(filterobj, 'Phat');
\r
74 %disp(P(:,:,end,1));
\r
75 %disp('Stationary P:');
\r
76 [Lbar Ppbar Pfbar]=dlqe(f, gw, h, diag(w_var), diag(e_var));
\r
80 MSE = mean(xerr.^2, 3);
\r
81 Pdiag = zeros(size(MSE));
\r
83 Pdiag(i,:) = squeeze(mean(P(i,i, :, :), 4))';
\r
89 subplot(2, 2, i); hold on;
\r
90 plot(MSE(i,:), 'b-');
\r
91 plot(Pdiag(i,:), 'r:');
\r
97 plot(sum(MSE, 1), 'b-');
\r
98 plot(sum(Pdiag, 1), 'r:');
\r