JPDA.txt
上传用户:teng_da99
上传日期:2014-12-25
资源大小:3k
文件大小:13k
源码类别:

并行计算

开发平台:

MultiPlatform

  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %多目标跟踪    
  3. %概率数据关联滤波器   standard_jpdaf      
  4. %两个目标两个目标交叉运动场景  Kalman滤波进行状态估计
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. m=2;
  7. Pd=1;
  8. Pg=0.99;
  9. g_sigma=9.21;                                             %门限
  10. gamma=1;                                                  %杂波个数
  11. Target_measurement=zeros(c,2,n);                          %目标观测互联存储矩阵
  12. target_delta=[0.150 0.150];                               %目标对应的观测标准差   
  13. data_measurement=zeros(c,n);                              %观测存储矩阵,n采样次数    行---代表目标 列---代表传感器                   
  14. P=zeros(4,4,c);                                           %滤波时协方差更新
  15. P1=[target_delta(1)^2 0 0 0;0 0.01 0 0;0 0 target_delta(1)^2 0;0 0 0 0.01];
  16. P(:,:,1)=P1;
  17. P(:,:,2)=P1;
  18. x_filter=zeros(4,c,n);                                    %存储所有六个目标的各时刻的滤波值
  19. A = [1 T 0 0;0 1 0 0;0 0 1 T;0 0 0 1];                    %状态转移矩阵
  20. C = [1 0 0 0;0 0 1 0]; 
  21. G=[T^2/2 0;T 0;0 T^2/2;0 T];        
  22. x_filter1=zeros(4,c,n,MC_number);
  23. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24. %主程序
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
  26. tic
  27. for M=1:MC_number
  28. %产生路径
  29. Noise=[];
  30. for i=1:n
  31.     for j=1:c
  32.             data_measurement(j,1,i)=data_measurement1(j,1,i)+randn(1)*target_delta(j);
  33.             data_measurement(j,2,i)=data_measurement1(j,2,i)+randn(1)*target_delta(j);                %各传感器观测的位置
  34.     end
  35. end
  36. % for i=1:c
  37. %     a=zeros(1,n);
  38. %     b=zeros(1,n);
  39. %     for j=1:n
  40. %         a(j)=data_measurement1(i,1,j);b(j)=data_measurement1(i,2,j);
  41. %     end
  42. %     plot(a(:),b(:),'o'),hold on
  43. % end
  44. % for i=1:c
  45. %     a=zeros(1,n);
  46. %     b=zeros(1,n);
  47. %     for j=1:n
  48. %         a(j)=data_measurement(i,1,j);b(j)=data_measurement(i,2,j);
  49. %     end
  50. %     plot(a(:),b(:),'*'),hold on
  51. % end
  52. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  53. %产生杂波,并确定有效观测
  54. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  55. S=zeros(2,2,c);
  56. Z_predic=zeros(2,2);                                                     %存储两个目标的观测预测值
  57. x_predic=zeros(4,2);                                                     %存储两个目标的状态预测值 
  58. ellipse_Volume=zeros(1,2);
  59. for t=1:n
  60.     y1=[];
  61.     y=[];
  62.     NOISE=[];
  63.     for i=1:c                                                              %产生在每个椭圆域中的杂波数
  64.         Noise=[];
  65.     if t~=1
  66.         x_predic(:,i) = A*x_filter(:,i,t-1);                               %用前一时刻的滤波值来预测当前的值 
  67.     else
  68.         x_predic(:,i)=target_position(:,i);                                %第一次采样我们用真实位置当预测值 
  69.     end
  70.     P_predic = A*P(:,:,i)*A'+G*Q*G';                                    
  71.     Z_predic(:,i) = C*x_predic(:,i);
  72.     R=[target_delta(i)^2  0;0  target_delta(i)^2];
  73.     S(:,:,i)= C*P_predic*C'+ R;
  74.     %============??????????????????????????????????????/
  75.     ellipse_Volume(i)=pi*g_sigma*sqrt(det(S(:,:,i)));                     %计算椭球体积,这里算的是面积   
  76.     number_returns=floor(10*ellipse_Volume(i)*gamma+1);                   %错误回波数
  77.     side=sqrt((10*ellipse_Volume(i)*gamma+1)/gamma)/2;                    %求出正方行边长的二分之一
  78.     Noise_x=x_predic(1,i)+side-2*rand(1,number_returns)*side;               %在预测值周围产生多余回波
  79.     Noise_y=x_predic(3,i)+side-2*rand(1,number_returns)*side;    
  80.     Noise=[Noise_x ;Noise_y];
  81.     NOISE=[NOISE Noise];
  82.     %==============????????????????????????????????????=
  83.     end    
  84.     b=zeros(1,2);
  85.     b(1)=data_measurement(1,1,t);
  86.     b(2)=data_measurement(1,2,t);
  87.     y1=[NOISE b'];                                                      %将接收到的所有的回波存在y1中%杂波、观测都放在y中
  88.     b(1)=data_measurement(2,1,t);
  89.     b(2)=data_measurement(2,2,t);
  90.     y1=[y1 b'];        %当有一个杂波回波时,y1[2*282]282=(2+2(2个回波)+2+2(2个杂波))*35+2
  91. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  92. %产生观测确认矩阵Q2
  93. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  94.     m1=0;                                                                 %记录有效观测个数
  95.     [n1,n2]=size(y1);
  96.     Q1=zeros(100,3);
  97.     for j=1:n2 
  98.         flag=0;
  99.         for i=1:c
  100.             d=y1(:,j)-Z_predic(:,i);
  101.             D=d'*inv(S(:,:,i))*d;                       
  102.             if D<=g_sigma                                                    
  103.                flag=1;
  104.                Q1(m1+1,1)=1;Q1(m1+1,i+1)=1;
  105.             end
  106.         end
  107.             if flag==1   
  108.                y=[y y1(:,j)];                                              %把落入跟踪门中的所有回波放入y中
  109.                m1=m1+1;                                                    %记录有效观测个数
  110.             end
  111.     end
  112.     Q2=Q1(1:m1,1:3);
  113. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  114. %产生互联矩阵A_matrix   num表示可行联合事件个数                  
  115. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  116. A_matrix=zeros(m1,3,10000);
  117. A_matrix(:,1,1:10000)=1;
  118. if m1~=0
  119.     num=1;                                  %num=1表示两个目标都没有观测时
  120. %当目标1有有效观测
  121.     for i=1:m1
  122.         if Q2(i,2)==1
  123.             A_matrix(i,2,num)=1;A_matrix(i,1,num)=0;
  124.             num=num+1;
  125.             for j=1:m1
  126.                 if (i~=j)&(Q2(j,3)==1)
  127.                     A_matrix(i,2,num)=1;A_matrix(i,1,num)=0;
  128.                     A_matrix(j,3,num)=1;A_matrix(j,1,num)=0;
  129.                     num=num+1;
  130.                 end
  131.             end
  132.         end
  133.     end                                   
  134. %当目标2无观测时
  135.     for i=1:m1
  136.         if Q2(i,3)==1
  137.             A_matrix(i,3,num)=1;A_matrix(i,1,num)=0;
  138.             num=num+1;
  139.         end
  140.     end
  141. else
  142.     flag=1;
  143. end
  144. A_matrix=A_matrix(:,:,1:num);
  145. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  146. % 计算后验概率Pr,  False_num表示假量测,mea_indicator表示观测指示器,target_indicator表示目标指示器
  147. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  148. Pr=zeros(1,num);
  149. for i=1:num
  150.     False_num=m1;
  151.     N=1;
  152.     for j=1:m1
  153.         mea_indicator=sum(A_matrix(j,2:3,i));
  154.         if mea_indicator==1
  155.             False_num=False_num-1;
  156.             if A_matrix(j,2,i)==1
  157.                 b=(y(:,j)-Z_predic(:,1))'*inv(S(:,:,1))*(y(:,j)-Z_predic(:,1));
  158.                 N=N/sqrt(det(2*pi*S(:,:,1)))*exp(-1/2*b);                  %如果观测与目标1关联
  159.             else
  160.                 b=(y(:,j)-Z_predic(:,2))'*inv(S(:,:,2))*(y(:,j)-Z_predic(:,2));
  161.                 N=N/sqrt(det(2*pi*S(:,:,2)))*exp(-1/2*b);                  %如果观测与目标2关联
  162.             end                                                          %计算正态分布函数    
  163.         end
  164.     end
  165.     if Pd==1
  166.         a=1;
  167.     else
  168.         a=1;
  169.         for j=1:c
  170.             target_indicator=sum(A_matrix(:,j+1,i));
  171.             a=a*Pd^target_indicator*(1-Pd)^(1-target_indicator);
  172.         end
  173.     end                                                                 %计算检测概率
  174.     V=ellipse_Volume(1)+ellipse_Volume(2);                            %表示整个空域的体积
  175.     a1=1;
  176.     for j=1:False_num
  177.         a1=a1*j;
  178.     end
  179.     Pr(i)=N*a*a1/(V^False_num);
  180. end
  181. Pr=Pr/sum(Pr);
  182. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  183. %计算关联概率U
  184. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  185. U=zeros(m1+1,c);
  186. for i=1:c
  187.     for j=1:m1
  188.         for k=1:num
  189.             U(j,i)=U(j,i)+Pr(k)*A_matrix(j,i+1,k);
  190.         end
  191.     end
  192. end
  193. U(m1+1,:)=1-sum(U(1:m1,1:c));                          %无量测与目标T互联的关联概率存入U(m1+1,:),规一化
  194. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  195. %滤波开始  
  196. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  197. for i=1:c                                                                            % 更新协方差矩阵
  198.     P_predic = A*P(:,:,i)*A'+G*Q*G';
  199.     K (:,:,i)= P_predic*C'*inv(S(:,:,i));
  200.     P(:,:,i)= P_predic-(1-U(m1+1,i))*K(:,:,i)*S(:,:,i)*K(:,:,i)';
  201. end
  202. for i=1:c
  203.     a=0;         
  204.     b=0;
  205.     x_filter2=0;%随便设置的中间参数
  206.     for j=1:m1
  207.         x_filter2=x_filter2+U(j,i)*(x_predic(:,i)+ K (:,:,i)*(y(:,j)- Z_predic(:,i)));
  208.     end
  209.     x_filter2=U(j+1,i)*x_predic(:,i)+x_filter2;
  210.     x_filter(:,i,t)=x_filter2;
  211.     for j=1:m1+1
  212.         if j==m1+1
  213.             a=x_predic(:,i);
  214.         else
  215.            a=x_predic(:,i)+ K (:,:,i)*(y(:,j)- Z_predic(:,i));
  216.         end
  217.         b=b+U(j,i)*(a*a'-x_filter2*x_filter2');
  218.     end
  219.     P(:,:,i)=P(:,:,i)+b; 
  220.     x_filter1(:,i,t,M)=x_filter(:,i,t);   
  221. end
  222. end
  223. end
  224. toc
  225. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  226. %画图
  227. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  228. x_filter=sum(x_filter1,4)/MC_number;                                %滤波值作平均
  229. a=zeros(1,n);
  230. b=zeros(1,n);
  231. figure(1)
  232. for i=1:c
  233.     a=zeros(1,n);
  234.     b=zeros(1,n);
  235.     for j=1:n
  236.         a(j)=data_measurement1(i,1,j);b(j)=data_measurement1(i,2,j);
  237.     end
  238.     plot(a(:),b(:)),hold on
  239. end
  240. % axis([5900 8500 5900 6200 ])
  241. for i=1:c
  242.     a=zeros(1,n);
  243.     b=zeros(1,n);
  244.     for j=1:n
  245.         a(j)=x_filter(1,i,j);b(j)=x_filter(3,i,j);
  246.     end
  247. if i==1
  248.     plot(a(:),b(:),'m+')
  249. else 
  250.     plot(a(:),b(:),'+')
  251. end
  252. end
  253. xlabel('x/km'),ylabel('y/km');
  254. %估计误差
  255. % a=zeros(c,n);b=zeros(c,n);c1=zeros(1,n);MEASURE=zeros(2,c,n);
  256. % for j=1:n
  257. %     a(1,j)=sqrt((x_filter(1,1,j)-data_measurement1(1,1,j))^2+(x_filter(3,1,j)-data_measurement1(1,2,j))^2);%最小均方误差
  258. %     c1(1,j)=c1(1,j)+a(1,j);
  259. % end
  260. % figure(3)
  261. % plot(1:n,c1(1,:),'r:') 
  262. % hold on
  263. % c1=zeros(1,n);
  264. % for j=1:n
  265. %         a(1,j)=sqrt((x_filter(1,2,j)-data_measurement1(2,1,j))^2+(x_filter(3,2,j)-data_measurement1(2,2,j))^2);%最小均方误差
  266. %         c1(1,j)=c1(1,j)+a(1,j);
  267. % end
  268. % plot(1:n,c1(1,:),'r-') 
  269. % % axis([0 20 0 11 ])
  270. % xlabel('times'),ylabel('Mean Estimated Errors/km');
  271. % legend('target1','target2')
  272. a=0;b=zeros(c,n);c1=zeros(c,n);
  273. for j=1:n
  274.     for i=1:MC_number
  275.         a=(x_filter1(1,1,j,i)-data_measurement1(1,1,j))^2+(x_filter1(3,1,j,i)-data_measurement1(1,2,j))^2;%最小均方误差
  276.         c1(1,j)=c1(1,j)+a;
  277.     end
  278.         c1(1,j)=sqrt(c1(1,j)/MC_number);
  279. end
  280. figure(3)
  281. plot(1:n,c1(1,:),'r:') 
  282. hold on
  283. for j=1:n
  284.     for i=1:MC_number
  285.         a=(x_filter1(1,2,j,i)-data_measurement1(2,1,j))^2+(x_filter1(3,2,j,i)-data_measurement1(2,2,j))^2;%最小均方误差
  286.         c1(2,j)=c1(2,j)+a;
  287.     end
  288.         c1(2,j)=sqrt(c1(2,j)/MC_number);
  289. end
  290. plot(1:n,c1(2,:),'r-') 
  291. % axis([0 20 0 11 ])
  292. xlabel('times'),ylabel('RMS Position  Errors /km');
  293. legend('Target1','Target2')
  294.  %单独画出每个目标的曲线
  295. figure(4)
  296. c1=zeros(c,n);
  297. for j=1:n
  298.     for i=1:MC_number
  299.         a=(x_filter1(1,1,j,i)-data_measurement1(1,1,j))^2+(x_filter1(3,1,j,i)-data_measurement1(1,2,j))^2;%最小均方误差
  300.         c1(1,j)=c1(1,j)+a;                                                                              %目标一
  301.     end
  302.         c1(1,j)=sqrt(c1(1,j)/MC_number);
  303. end
  304. plot(1:n,c1(1,:),'r:')
  305. xlabel('times'),ylabel('RMS Position  Errors /km');
  306. legend('Target1')
  307. figure(5)
  308. for j=1:n
  309.     for i=1:MC_number
  310.         a=(x_filter1(1,2,j,i)-data_measurement1(2,1,j))^2+(x_filter1(3,2,j,i)-data_measurement1(2,2,j))^2;%最小均方误差
  311.         c1(2,j)=c1(2,j)+a;
  312.     end                                                                                        % 目标2
  313.         c1(2,j)=sqrt(c1(2,j)/MC_number);
  314. end
  315. plot(1:n,c1(2,:),'r-') 
  316. % axis([0 20 0 11 ])
  317. xlabel('times'),ylabel('RMS Position  Errors /km');
  318. legend('Target2')
  319. %
  320. % c1=zeros(1,n);
  321. % for j=1:n
  322. %     a(1,j)=sqrt((x_filter(2,1,j)-target_position(2,1))^2+(x_filter(4,1,j)-target_position(4,1))^2);%最小均方误差
  323. %     c1(1,j)=c1(1,j)+a(1,j);
  324. % end
  325. % figure(4)
  326. % plot(1:n,c1(1,:),'r:') 
  327. % hold on
  328. % c1=zeros(1,n);
  329. % for j=1:n
  330. %     a(1,j)=sqrt((x_filter(2,2,j)-target_position(2,2))^2+(x_filter(4,2,j)-target_position(4,2))^2);%最小均方误差
  331. %     c1(1,j)=c1(1,j)+a(1,j);
  332. % end
  333. % plot(1:n,c1(1,:),'r-') 
  334. % xlabel('times'),ylabel('Mean Estimated Errors km/s');
  335. %给出速度的RMS曲线]
  336. a=0;b=zeros(c,n);c1=zeros(c,n);
  337. for j=1:n
  338.     for i=1:MC_number
  339.         a=(x_filter1(2,1,j,i)-target_position(2,1))^2+(x_filter1(4,1,j,i)-target_position(4,1))^2;%最小均方误差
  340.         c1(1,j)=c1(1,j)+a;
  341.     end
  342.         c1(1,j)=sqrt(c1(1,j)/MC_number);
  343. end
  344. figure(6)
  345. plot(1:n,c1(1,:),'r:') 
  346. hold on
  347. for j=1:n
  348.     for i=1:MC_number
  349.         a=(x_filter1(2,2,j,i)-target_position(2,2))^2+(x_filter1(4,2,j,i)-target_position(4,2))^2;%最小均方误差
  350.         c1(2,j)=c1(2,j)+a;
  351.     end
  352.         c1(2,j)=sqrt(c1(2,j)/MC_number);
  353. end
  354. plot(1:n,c1(2,:),'r-') 
  355. % axis([0 20 0 11 ])
  356. xlabel('times'),ylabel('RMS Position  Errors /km');
  357. legend('Target1','Target2')
  358. % legend('target1','target2')