www.pudn.com > trackingdemos.zip > plot_2d_pda1.m


% plot_2d_pda1.m 
% 
% Kalman filter with 2-D assignment for tracking multiple targets with possibly unresolved measurements, 
% assuming the resolvability indicator is known. 
 
 
% See also: gene_2d_scn.m, gene_2d_meas.m 
function fig = plot_2d_pda1(target, measurement) 
 
fig = figure; 
hold on; 
plot(target(1).state(1,:), target(1).state(3,:), '.'); 
plot(target(2).state(1,:), target(2).state(3,:), '.'); 
axis([100e3,130e3,147e3,151e3]); 
% define SNR 
SNRdb = 10; 
SNR = 10^(SNRdb/10); 
% detection threshold 
threshold = 2.55; 
% calc. the probability of detection and false alarm per cell  
% according to certain model (currently Swerling-I) 
Pfa = exp(-threshold*threshold/2); 
Pd = exp(-threshold*threshold/2/(1+SNR)); 
% measurement std, cell size 
C_r = 50; 
C_b = 2e-3; 
 
% track initiation 
track(1).time(1) = 1; 
track(2).time(1) = 1; 
track(1).est(:,1) = target(1).state(:,1);  
track(2).est(:,1) = target(2).state(:,1); 
track(1).P(:,:,1) = 1e4.* [9, 0, -6, 0; 
                            0, .2, 0, 0; 
                           -6 0,  5, 0; 
                           0, 0, 0, .2]; 
track(2).P(:,:,1) = 1e4.* [9, 0, -6, 0; 
                            0, .2, 0, 0; 
                           -6 0,  5, 0; 
                           0, 0, 0, .2]; 
q = .05; % process noise 
H = [1, 0, 0, 0; 0, 0, 1, 0]; 
vm = zeros(2,1); 
wm = zeros(2,1); 
Ik = eye(2); 
Qk = q.*Ik; 
lambda = 1e-7; 
numScan = length(target(1).time); 
 
    for i=1:numScan 
        T = measurement(i).time - track(1).time(i); 
        F = [1, T, 0, 0; 
            0, 1, 0, 0; 
            0, 0, 1, T; 
            0, 0, 0, 1]; 
        G = [T*T/2, 0; 
            T, 0; 
            0, T*T/2; 
            0, T]; 
        z = []; 
        R = []; 
        cost = []; 
        assign = []; 
        ind = length(measurement(i).flag); 
        if ind == 0 
            [track(1).est(:,i+1), track(1).P(:,:,i+1)] = prekalman(track(1).est(:,i), track(1).P(:,:,i),vm,Qk,F,G); 
            [track(2).est(:,i+1), track(2).P(:,:,i+1)] = prekalman(track(2).est(:,i), track(2).P(:,:,i),vm,Qk,F,G); 
        else 
            k = 1; 
            cost(1,1) = 0; 
            cost(2,1) = 0; 
            for j=1:ind 
                if measurement(i).flag(j) == 0 
                    [z(1,k), z(2,k), R(:,:,k)] = CalcMeasCov2(measurement(i).range(j), measurement(i).bearing(j), measurement(i).pos(1), measurement(i).pos(2), C_r, C_b); 
                    plot(z(1,k), z(2,k), 'k*'); 
                    k = k + 1; 
                    [z(1,k), z(2,k), R(:,:,k)] = CalcMeasCov2(measurement(i).range(j), measurement(i).bearing(j), measurement(i).pos(1), measurement(i).pos(2), C_r, C_b); 
                    k = k + 1; 
                else 
                    [z(1,k), z(2,k), R(:,:,k)] = CalcMeasCov2(measurement(i).range(j), measurement(i).bearing(j), measurement(i).pos(1), measurement(i).pos(2), C_r/sqrt(12), C_b/sqrt(12)); 
                    plot(z(1,k), z(2,k), 'c*');  
                    k = k + 1; 
                end 
            end 
            for j=1:k-1 
                cost(1,j+1) = lr_kalman(track(1).est(:,i), track(1).P(:,:,i), z(:,j), Qk, R(:,:,j), vm, wm, F, G, H, Ik, Pd, lambda); 
                cost(2,j+1) = lr_kalman(track(2).est(:,i), track(2).P(:,:,i), z(:,j), Qk, R(:,:,j), vm, wm, F, G, H, Ik, Pd, lambda);             
            end 
            % LP solution of the 2-D assignment problem 
            associate_prob = myLinProg(-cost); 
            if isempty(associate_prob) 
                [track(1).est(:,i+1), track(1).P(:,:,i+1)] = prekalman(track(1).est(:,i), track(1).P(:,:,i),vm,Qk,F,G); 
                [track(2).est(:,i+1), track(2).P(:,:,i+1)] = prekalman(track(2).est(:,i), track(2).P(:,:,i),vm,Qk,F,G); 
            else 
                % update tracks 
                [track(1).est(:,i+1), track(1).P(:,:,i+1)] = pdakalman(track(1).est(:,i), track(1).P(:,:,i),... 
                z, R, associate_prob(1,:), Qk, vm, wm, F, G, H, Ik); 
                [track(2).est(:,i+1), track(2).P(:,:,i+1)] = pdakalman(track(2).est(:,i), track(2).P(:,:,i),... 
                z, R, associate_prob(2,:), Qk, vm, wm, F, G, H, Ik); 
            end 
        end 
 
        plot(track(1).est(1, i+1), track(1).est(3, i+1), 'g.'); 
        plot(track(2).est(1, i+1), track(2).est(3, i+1), 'g.'); 
        center1 = [track(1).est(1,i+1), track(1).est(3, i+1)]; 
        covariance1 = [track(1).P(1,1,i+1), track(1).P(1,3,i+1); track(1).P(3,1,i+1), track(1).P(3,3,i+1)]; 
        [X1, Y1] = get_ellipsoid_gate(center1, covariance1, 1.96); 
        plot(X1, Y1, 'm'); 
        center2 = [track(2).est(1,i+1), track(2).est(3, i+1)]; 
        covariance2 = [track(2).P(1,1,i+1), track(2).P(1,3,i+1); track(2).P(3,1,i+1), track(2).P(3,3,i+1)]; 
        [X2, Y2] = get_ellipsoid_gate(center2, covariance2, 1.96); 
        plot(X2, Y2, 'm'); 
        axis([100e3,130e3,147e3,151e3]); 
        pause(.5); 
        track(1).time(i+1) = measurement(i).time; 
        track(2).time(i+1) = measurement(i).time; 
    end 
     
xlabel('x position (m)'); 
ylabel('y position (m)'); 
title('2-D soft assignment, sensor 1&2'); 
hold off;