constrained_weighted_NLOS.asv
上传用户:doryuen
上传日期:2013-10-30
资源大小:23k
文件大小:3k
源码类别:

通讯/手机编程

开发平台:

Matlab

  1.     clc;
  2.     clear;
  3.     
  4.     n=4;      % the number of base stations
  5.     m=1;    % the number of measurements
  6.     
  7.     delta=60;    % variance of measurement noise
  8.     
  9. %     bx(1:n)=0; by(1:5)=0;   % the coordinate of base staions
  10.     
  11.     radius=1000;
  12.     bx=[   1.5*radius         0               -1.5*radius        -1.5*radius          0               1.5*radius];
  13.     by=[   sqrt(3)*radius/2   sqrt(3)*radius   sqrt(3)*radius/2   -sqrt(3)*radius/2  -sqrt(3)*radius  -sqrt(3)*radius/2];
  14.     
  15.     p=[1 0 0;
  16.         0 1 0;
  17.         0 0 0];
  18.     q=[0 0 -1]';
  19.     
  20.     A=[]; b=[];
  21.     for an=1:n
  22.         A(an,:)=[bx(an) by(an) -0.5];
  23.     end
  24.     
  25.      for loop=1:m;
  26.         
  27.         txr=1*rand*radius;    tx_angle=rand*2*pi;
  28.         tx(loop)=txr*cos(tx_angle);  ty(loop)=txr*sin(tx_angle);
  29. %         tx(loop)=500;  ty(loop)=800;
  30.         for k=1:n
  31.             dt(loop,k)=sqrt((tx(loop)-bx(k))^2+(ty(loop)-by(k))^2);
  32. %             d(loop,k)=0.95*dt(loop,k)-0*delta*rand+00;         % distance measurement
  33. %             d(loop,k)=dt(loop,k)+exprnd(1,1,1)*100;         % distance measurement
  34.             d(loop,k)=dt(loop,k)+(0.5+0.5*rand)*100;
  35. %             d(loop,k)=dt(loop,k)+noise(loop,k);         % distance measurement
  36.         end
  37.         clear k
  38.         true_w=dt(loop,:)./d(loop,:);
  39.         
  40.         weights=weights_cal(bx(1:n),by(1:n),d);
  41.         
  42.         step=0.02; wn=0; w=[]; cost=[];
  43.         theta=[];
  44.         
  45. %         for w1=weights(1):step:1
  46. %             for w2=weights(2):step:1
  47. %                 for w3=weights(3):step:1
  48. %                     for w4=weights(4):step:1
  49.                 for k=1:1e4;
  50.                         wn=wn+1;
  51. %                         w(wn,:)=[w1 w2 w3 w4];
  52.                         w(wn,:)=[weights(1)+rand*(1-weights(1)) weights(2)+rand*(1-weights(2)) weights(3)+rand*(1-weights(3)) weights(4)+rand*(1-weights(4))];
  53.                         
  54. %                         for bn=1:n
  55. %                             b(bn,:)=0.5*[bx(bn)^2+by(bn)^2-(w(wn,bn)*d(bn))^2];
  56. % %                             b(bn,:)=0.5*[bx(bn)^2+by(bn)^2-(true_w(bn)*d(bn))^2];
  57. %                         end
  58. %                         
  59. %                         [t_cost t_theta]=cost_est(A,b,p,q);
  60. %                         cost(wn)=t_cost;
  61. %                         theta(wn,:)=t_theta';
  62.                         
  63.                         [tex,tey,tcost]=TOA_LS(radius,bx(1:n),by(1:n),w(wn,:).*d(1:n));
  64.                         
  65.                         theta(wn,:)=[tex tey];
  66.                         cost(wn)=tcost;
  67.                         
  68.                         
  69.                         wn
  70.                  end
  71. %                     end % w1
  72. %                 end % w2
  73. %             end % w3
  74. %         end % w4
  75.         
  76.         [m,mi]=min(cost);
  77.         ex=theta(mi,1)
  78.         ey=theta(mi,2)
  79.         [tx(loop) ty(loop)]
  80.         err=sqrt((ex-tx(loop))^2+(ey-ty(loop))^2)
  81.         
  82.         w(mi,:)
  83.         true_w
  84.         
  85.         loop
  86.         
  87.     end % loop
  88.