⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot_2d_kf1.m

📁 一个目标跟踪系统的MATLAB 源程序包
💻 M
字号:
% plot_2d_kf1.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_kf1(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);
        k = 1;
        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
            % form the cost function for 2-D assignment
            cost(1,j) = 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) = lr_kalman(track(2).est(:,i), track(2).P(:,:,i), z(:,j), Qk, R(:,:,j), vm, wm, F, G, H, Ik, Pd, lambda);            
        end

        if isempty(cost) | max(max(cost)) < 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
            [q,omiga,assign] = auction_2D(cost);
            % update tracks
            ind1 = find(~(assign-1));
            if isempty(ind1) | cost(1, ind1) < 0
                [track(1).est(:,i+1), track(1).P(:,:,i+1)] = prekalman(track(1).est(:,i), track(1).P(:,:,i),vm,Qk,F,G);
            else
                [track(1).est(:,i+1), track(1).P(:,:,i+1)] = stdkalman(track(1).est(:,i), track(1).P(:,:,i),...
                z(:,ind1), Qk, R(:,:,ind1), vm, wm, F, G, H, Ik);
            end
            ind2 = find(~(assign-2));
            if isempty(ind2) | cost(2, ind2) < 0
                [track(2).est(:,i+1), track(2).P(:,:,i+1)] = prekalman(track(2).est(:,i), track(2).P(:,:,i),vm,Qk,F,G);
            else
                [track(2).est(:,i+1), track(2).P(:,:,i+1)] = stdkalman(track(2).est(:,i), track(2).P(:,:,i),...
                z(:,ind2), Qk, R(:,:,ind2), 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 hard assignment, sensor 1&2');
hold off;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -