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

📄 track_xor.m

📁 Faster GPS signal tracking using XOR method
💻 M
字号:
%function Ip = track(fid, fc, ph, num_sec, sat_id)
% The function
%   Ip = track(fid, fc, ph, num_sec, sat_id)
% returns the data output from the prompt I-channel
% of the code & carrier tracker.
clear all;
fid = fopen('d:\datafiles\data33.dat');% fid = file pointer to data
ph =5631; %codephase(samples)
%fseek(fid, ph, -1);
 fc =1424929; %carrier IF
 
num_sec =200e-3;%800*1e-3; %how many seconds of data to process
sat_id =4; %what satellite to receive

% SETUP
fs=5.714e6;
cit=1;
d1ms=cit*(fs/1000);
% # of samples between early -prompt and late prompt channel
chip_delay =3;
chip_delay1 =3; %shift for code loop alignment
scode1=5714;
% code chip rate
fcode = 1.023e6;
% # of samples in a code period
scode = d1ms+14;
% # of codeperiods to average over
num_ava = 1;
% Set file pointer to code phase 
%fseek(fid, ph, -1);
% Initialize variables
y(1) = 0;
pnco = 0.0;
t_end = 0;

% Filter coefficients
Bl =50;
damp = .7;
wn = 2*Bl/(damp+1/(4*damp));
dT =cit*1e-3;
K = 400*pi;
c1 = (8*damp*wn*dT)/(K*(4+4*damp*wn*dT+(wn*dT).^2));
c2 = 4*((wn*dT).^2)/(K*(4+4*damp*wn*dT+(wn*dT).^2));
count=0;
z=0;

% generate CA codes

prompt = xored_ca(sat_id, fcode, fs, scode1);
prompt = [prompt prompt(1:14)];
%prompt=[prompt1(scode+1-ph:scode) prompt1(1:scode-ph)];
%prompt=digitizg(scode,fs,0,sat_id);
%early = [prompt(scode+1-chip_delay:scode) prompt(1:scode-chip_delay)];
%late = [prompt(chip_delay+1:scode) prompt(1:chip_delay)];
%data1=(fscanf(fid, '%1d', ph))';
% Loop
for i = 1:round(num_sec*1000/(num_ava*cit))
   % Avaraging loop for code tracking
      for j = 1:num_ava
      % recalculate time vector
      t = t_end:(1/fs):(scode-1)/fs+t_end;
      t_end = t(scode)+1/fs;
      ss1 = fc*2*pi*t+pnco;
      ss2 = rem(ss1,2*pi);
      % generate I/Q (pnco = phase offset)
      Icomp_lo = sin(ss2);
      Qcomp_lo = cos(ss2);
    
      %Qcomp_lo = [Icomp_lo(1428:5714*cit) Icomp_lo(1:1427)]; %shifted version of sin for cos
      for m=1:length(Icomp_lo)
          if Icomp_lo(m)<0
              Icomp_lo(m)=0;
         else Icomp_lo(m)=1;
          end;
      end;
       for m=1:length(Icomp_lo)
         if Qcomp_lo(m)<0
             Qcomp_lo(m)=0;
         else Qcomp_lo(m)=1;
         end;
        end;
        ss2(1:10);
        Icomp_lo(1:10);
      % read data
      
       data=(fscanf(fid, '%1d', scode))';
       
       %data=(fscanf(fid, '%1d', scode));
         %convert i/p data into +1 and -1 form
        %for l=1:length(data)
         %  if data(l) == 0
          %    data(l) = -1;
          %end
          %end
%data =(fread(fid, scode, 'schar'))';
%fid =fopen('d:\datafiles\magic.txt.','w');
%fprintf(fid,'%d',Icomp_lo);
%fclose(fid);



      % Remove carrier( or code!!!!!!!)
      p1 = xor(data(1:1:5728),prompt(1:1:5728));
      
      
      % Calculate index for vectors
      inda = (i-1)*num_ava+j;
      %Despread with CA code
     
      
     
    %  pI=xor(p1(1:3:5714),Icomp_lo(1:3:5714));
       pI=xor(p1,Icomp_lo(1:1:5728));
      
      
   %   iQ=xor(p1(1:3:5714),Qcomp_lo(1:3:5714));
      iQ=xor(p1,Qcomp_lo(1:1:5728));
      
      % In-phase
      % 0.5 is being used beacsue instead of multiplication( 1 and -1) xor is used here 
      Ip(inda) = 0.5-mean(pI);
   %    Ip(inda) = mean(pI);
      % Quadrature
     
    Qp(inda) = 0.5-mean(iQ);%prompt
      % Qp(inda) = mean(iQ);
      %Envelops
      count=count+1;
      pp(inda)=(Ip(inda).^2 + Qp(inda).^2).^.5; %prompt
      envolope(count)=pp(inda);
      
  
      %costas loop for carrier tracking
      % Atan discriminator
      d2(inda) = atan(Qp(inda)./Ip(inda));
      %loop filter
        if inda<2
            y(inda)=0;
        else
            % filtered discriminator output
            y(inda)=y(inda-1)+(c1+c2)*d2(inda)-c1*d2(inda-1);
            %phase for carrier NCO
            pnco=rem(pnco+K*y(inda),2*pi);
        end
      
         %AVERAGING LOOP OF CODE TRACK END
    
   
   if count==1 
       % shift left by two bit 
       %disp('left shifted');
       temp=prompt(15:16);
       temp1=[prompt(5713:5714) prompt(1:2)];
       temp6=[prompt(13:16)];
       prompt=[prompt(3:scode) temp];
   end;
   if count==2
       %shift right by four bit 
       %disp('right shifted');
       
       prompt=[temp1 prompt(1:scode-4)];
   end;
   if count==3
       z=z+1;
       count;
       count=0;
       my_count=0;
       mid=(envolope(1));      
       left=(envolope(2));
       right=(envolope(3));
       max_vector=[ mid left right];
       [max_value max_col]=max(max_vector);
       %max_col
       if max_col==1                  
               % shift left by two bit
                temp=prompt(15:16);
             prompt=[prompt(3:scode) temp];
         end;
            if max_col==2 
             %shift left by four bit 
            
             prompt=[prompt(5:scode) temp6 ];
             end ;
       
       
             
             
             
             
   end;
       
   end;
   
   
end

plot(Ip);
figure(2);
plot(Qp);


%disp(Ip);
%for
%i
 %   if Ip(i) <-150 
  %      Ip(i)=-150;
   %  else if Ip(i)>150;
    %     Ip(i)=150;
 % end;
  %  end;
end; 
%hold
%plot(Ip,'r');
   
   
   
   
   
  

⌨️ 快捷键说明

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