RECPO_LS.M
上传用户:sfyaiting
上传日期:2009-10-25
资源大小:320k
文件大小:3k
源码类别:

GPS编程

开发平台:

Matlab

  1. function [pos, El, GDOP, basic_obs] = recpo_ls(obs,sats,time,Eph)
  2. % RECPO_LS Computation of receiver position from pseudoranges
  3. %          using ordinary least-squares principle
  4. %Kai Borre 31-10-2001
  5. %Copyright (c) by Kai Borre
  6. %$Revision: 1.1 $  $Date: 2002/07/10  $
  7. v_light = 299792458;
  8. dtr = pi/180;
  9. m = size(obs,1);  % number of svs
  10. el = zeros(m,1);
  11. % identify ephemerides columns in Eph
  12. for t = 1:m
  13.     col_Eph(t) = find_eph(Eph,sats(t),time);
  14. end
  15. % preliminary guess for receiver position and receiver clock offset
  16. pos = zeros(4,1);
  17. no_iterations = 6; 
  18. ps_corr = [];
  19. sat_pos = [];
  20. for iter = 1:no_iterations
  21.     A = [];
  22.     omc = []; % observed minus computed observation
  23.     for i = 1:m        
  24.         k = col_Eph(i);
  25.         tx_RAW = time - obs(i)/v_light;
  26.         t0c = Eph(21,k);
  27.         dt = check_t(tx_RAW-t0c);
  28.         tcorr = (Eph(2,k)*dt + Eph(20,k))*dt + Eph(19,k);
  29.         tx_GPS = tx_RAW-tcorr;
  30.         dt = check_t(tx_GPS-t0c);
  31.         tcorr = (Eph(2,k)*dt + Eph(20,k))*dt + Eph(19,k);
  32.         tx_GPS = tx_RAW-tcorr;
  33.         X = satpos(tx_GPS, Eph(:,k));
  34.         if iter == 1
  35.             traveltime = 0.072;
  36.             Rot_X = X;
  37.             trop = 0;
  38.         else
  39.             rho2 = (X(1)-pos(1))^2+(X(2)-pos(2))^2+(X(3)-pos(3))^2;
  40.             traveltime = sqrt(rho2)/v_light;
  41.             Rot_X = e_r_corr(traveltime,X);
  42.             rho2 = (Rot_X(1)-pos(1))^2+(Rot_X(2)-pos(2))^2+(Rot_X(3)-pos(3))^2;          
  43.             [az,el,dist] = topocent(pos(1:3,:),Rot_X-pos(1:3,:));                                                            
  44.             if iter == no_iterations, El(i) = el; end
  45.             trop = tropo(sin(el*dtr),0.0,1013.0,293.0,50.0,...
  46.                 0.0,0.0,0.0);    
  47.         end
  48.         % subtraction of pos(4) corrects for receiver clock offset and
  49.         % v_light*tcorr is the satellite clock offset
  50.         if iter == no_iterations
  51.             ps_corr = [ps_corr; obs(i)+v_light*tcorr-trop];
  52.             sat_pos = [sat_pos; X'];
  53.         end
  54.         omc = [omc; obs(i)-norm(Rot_X-pos(1:3),'fro')-pos(4)+v_light*tcorr-trop];
  55.         A = [A; (-(Rot_X(1)-pos(1)))/obs(i)...
  56.                 (-(Rot_X(2)-pos(2)))/obs(i) ...
  57.                 (-(Rot_X(3)-pos(3)))/obs(i) 1];
  58.     end % i
  59.     x = Aomc;
  60.     pos = pos+x;
  61.     if iter == no_iterations, GDOP = sqrt(trace(inv(A'*A))); 
  62.         %% two lines that solve an exercise on computing tdop
  63.         % invm = inv(A'*A);
  64.         % tdop = sqrt(invm(4,4))
  65.     end
  66. end % iter
  67. basic_obs = [sat_pos ps_corr];
  68. %%%%%%%%%%%%%%%%%%%%%  recpo_ls.m  %%%%%%%%%%%%%%%%%%%%%