www.pudn.com > trackingdemos.zip > plot_chi2.m
function fig = plot_chi2(track)
% chi2 region vs. time
[nx, ny] = size(track(1).NEES);
fig = figure;
subplot(2,2,1);
hold on;
for i=1: ny
index(i).ind = [];
for j=1:nx
if track(1).NEES(j,i)<13.3 % 99% uppper bound, 4df
if i>1
if ~isempty(find(~(index(i-1).ind-j)))
index(i).ind = [index(i).ind, j];
end
else
index(i).ind = [index(i).ind, j];
end
end
end
n(i) = length(index(i).ind);
lower = chi2inv(.025, n(i)*4)/n(i);
upper = chi2inv(.975, n(i)*4)/n(i);
plot(i, lower, 'r.');
plot(i, upper, 'r.');
plot(i, mean(track(1).NEES(index(i).ind, i)), 'k.-');
end
xlabel('scans');
ylabel('Test statistic (NEES) and the 95% \chi^2 region');
title('NEES, target 1, excluding lost tracks');
hold off;
subplot(2,2,2)
hold on;
for i=1:ny
index(i).ind = [];
for j=1:nx
if track(2).NEES(j,i)<13.3 % 99% uppper bound, 4df
if i>1
if ~isempty(find(~(index(i-1).ind-j)))
index(i).ind = [index(i).ind, j];
end
else
index(i).ind = [index(i).ind, j];
end
end
end
n(i) = length(index(i).ind);
lower = chi2inv(.025, n(i)*4)/n(i);
upper = chi2inv(.975, n(i)*4)/n(i);
plot(i, lower, 'r.');
plot(i, upper, 'r.');
plot(i, mean(track(2).NEES(index(i).ind, i)), 'k.-');
end
xlabel('scans');
ylabel('Test statistic (NEES) and the 95% \chi^2 region');
title('NEES, target 2, excluding lost tracks');
hold off;
lower = chi2inv(.025, nx*4)/nx;
upper = chi2inv(.975, nx*4)/nx;
tl = linspace(lower, lower, ny);
tu = linspace(upper, upper, ny);
subplot(2,2,3)
hold on;
plot(tl, 'r.');
plot(tu, 'r.');
plot(mean(track(1).NEES), 'k.-');
xlabel('scans');
ylabel('Test statistic (NEES) and the 95% \chi^2 region');
title('NEES, target 1, including lost tracks');
hold off;
subplot(2,2,4)
hold on;
plot(tl, 'r.');
plot(tu, 'r.');
plot(mean(track(2).NEES), 'k.-');
xlabel('scans');
ylabel('Test statistic (NEES) and the 95% \chi^2 region');
title('NEES, target 2, including lost tracks');
hold off;