PN_Phase_Trace.m
上传用户:shencti
上传日期:2016-08-16
资源大小:16k
文件大小:5k
源码类别:

邮电通讯系统

开发平台:

Matlab

  1. %
  2. % 本程序用于实现扩频系统信号跟踪中,码相位的跟踪
  3. % 输入信号为,载波锁定之后的多普勒频率和码相位
  4. % 目前实际多普勒频率1000,相位952
  5. function Catched = PN_Phase_Trace(fd_estimate, Correl_Peak_location_real)
  6. % 获取系统参数
  7. [code_cycle,SNR,Ts,T,T_interp,fi,M,N,fd,f0,delay_time,fd_estimate_init,sigma_n,fs,Bandwidth,dot_insert,coef,coef_mod,B,A1]=set_parameter;
  8. %%%%产生接受中频信号伪码,抽头为1,8
  9. code_phase=[1,8];
  10. [inputcode]=code_gen(code_phase);   % 1023大小的GOLD伪码
  11. %%%%本地伪码
  12. native_code=inputcode;
  13. inputcode_2=[native_code,native_code];
  14. EmulateIndex = 0;
  15. k = 0;
  16. half_dot_insert = dot_insert/2;
  17. ThisPN = zeros(1, N);   % 本次即时码
  18. EarlyPN2 = zeros(1, N); % 超前码
  19. LagPN2 = zeros(1, N);   % 滞后码
  20. const4 = fix(N/(4*1023));      % 超前、滞后1/4,需要移动的抽样点
  21. const8 = fix(N/(8*1023));      % 超前、滞后1/8,需要移动的抽样点,当采样为5808点时,无法采用
  22. Correl_Peak_location_real = Correl_Peak_location_real*5808/1023;
  23. while (1)
  24.     % 模拟输入的中频信号
  25.     EmulateIndex = EmulateIndex + 1;
  26.     [signal,signal_noise]=SignalGenerator(EmulateIndex,inputcode,fs,Ts,fi,delay_time,fd,SNR,Bandwidth,code_cycle,sigma_n,f0,N);
  27.     IF_signal(1:N)=signal(1:N);
  28.     IF_signal_noise(1:N)=signal_noise(1:N);
  29. %     % 绘制信号及噪声
  30. %     figure(1);
  31. %     plot(IF_signal, 'b');  % 绘制生成的信号(含噪声)
  32. %     hold on;
  33. %     plot(IF_signal_noise, 'r');  % 信号的噪声
  34. %     hold off;
  35.     % 当前的载波NCO ××× fd_estimate在不断调整
  36.     [NCO_I_Quanti,NCO_Q_Quanti]=Nco_gen(Ts,fi,fd_estimate,N);
  37.     
  38.     % 下变频
  39. Rece_Signal_Quan_down_I = IF_signal(1:N).* NCO_I_Quanti;
  40. Rece_Signal_Quan_down_Q = IF_signal(1:N).* NCO_Q_Quanti;
  41. Rece_Signal_Quan_down_I_noise=IF_signal_noise.*NCO_I_Quanti;
  42. Rece_Signal_Quan_down_Q_noise=IF_signal_noise.*NCO_Q_Quanti;
  43.     %%%%经过低通滤波器,截止频率为1.023MHz
  44.     [signal_I,signal_Q,signal_I_noise,signal_Q_noise]=LP_filter(N,N+1,code_cycle,fs,Rece_Signal_Quan_down_I,Rece_Signal_Quan_down_Q,Rece_Signal_Quan_down_I_noise,Rece_Signal_Quan_down_Q_noise,EmulateIndex);       %进过低通滤波器
  45.     
  46. %     % 绘制比较,低通滤波器的作用
  47. %     figure(2);
  48. %     plot(Rece_Signal_Quan_down_I, 'b'); % 原始
  49. %     hold on
  50. %     plot(signal_I, 'r');    % 
  51. %     hold off
  52.     % 这次不再内插成4096个点,而是保持5808个抽样点,表示一个码字长度的值
  53.     ThisPN = PN2Generator(inputcode,Correl_Peak_location_real,N);
  54.     % 相关间隔1/2
  55.     % 超前码1/4
  56.     EarlyPN2 = [ThisPN((const4+1):N) ThisPN(1:const4)];
  57.     % 滞后码
  58.     LagPN2 = [ThisPN((N-const4):N) ThisPN(1:(N-const4-1))];
  59.     % 相关间隔1/4
  60.     % 超前码1/8
  61.     EarlyPN4 = [ThisPN((const8+1):N) ThisPN(1:const8)];
  62.     % 滞后码
  63.     LagPN4 = [ThisPN((N-const8):N) ThisPN(1:(N-const8-1))];
  64.     
  65.     k = k+1;
  66.     % 积分器,算出I.Q
  67.     Ips(k) = sum(ThisPN.*Rece_Signal_Quan_down_I);
  68.     Qps(k) = sum(ThisPN.*Rece_Signal_Quan_down_Q);
  69.     Ies2(k) = sum(EarlyPN2.*Rece_Signal_Quan_down_I);
  70.     Qes2(k) = sum(EarlyPN2.*Rece_Signal_Quan_down_Q);
  71.     Ils2(k) = sum(LagPN2.*Rece_Signal_Quan_down_I);
  72.     Qls2(k) = sum(LagPN2.*Rece_Signal_Quan_down_Q);
  73.     
  74. %     Ies4(k) = sum(EarlyPN4.*Rece_Signal_Quan_down_I);
  75. %     Qes4(k) = sum(EarlyPN4.*Rece_Signal_Quan_down_Q);
  76. %     Ils4(k) = sum(LagPN4.*Rece_Signal_Quan_down_I);
  77. %     Qls4(k) = sum(LagPN4.*Rece_Signal_Quan_down_Q);
  78.     % 伪码相位误差
  79.     % 归一化点积鉴项器-斜率2
  80.     EC1(k) = ((Ies2(k)-Ils2(k))*Ips(k) + (Qes2(k)-Qls2(k))*Qps(k))/(Ips(k)*Ips(k) + Qps(k)*Qps(k));%
  81.   
  82. %     if(EC1(k) > 2)
  83. %         EC1(k) = 2;
  84. %     end;
  85. %     if (EC1(k) < -2)
  86. %      EC1(k) = -2;
  87. %     end;
  88.     % 归一化超前减滞后功率鉴项器-斜率4
  89. %    EC2(k) = (Ies4(k)*Ies4(k)+Qes4(k)*Qes4(k)-Ils4(k)*Ils4(k)-Qls4(k)*Qls4(k))/(Ies4(k)*Ies4(k)+Qes4(k)*Qes4(k)+Ils4(k)*Ils4(k)+Qls4(k)*Qls4(k));
  90.     
  91.     % 计算相位差
  92.     diff1 = EC1(k)*5808/1023/2;
  93.     DiffFilter(k) = EC1(k)*5808/1023/2;
  94.     if(k > 128)
  95.         DiffFilter(k) = sum(DiffFilter(k-127:k))/128;
  96.         if(DiffFilter(k) < 1/24)
  97.             Catched = 1;
  98.             disp('码相位已经跟踪并锁定');
  99.             Correl_Peak_location_real
  100.             %break;
  101.         end;
  102.     end;
  103. %    diff2 = EC2(k)/4;
  104.     
  105. % 使用滤波
  106.     if(abs(DiffFilter(k)) < 1)
  107.         PhaseQueue(k) = Correl_Peak_location_real;
  108.     else
  109.         PhaseQueue(k) = Correl_Peak_location_real+round(DiffFilter(k));
  110.         if(PhaseQueue(k) >= 5808)
  111.             PhaseQueue(k) = mod(PhaseQueue(k),5808) + 1;%*1023
  112.         end;
  113.     end;
  114.     
  115. % % 未加滤波    
  116. %     if(abs(diff1) < 1)
  117. %         PhaseQueue(k) = Correl_Peak_location_real;
  118. %     else
  119. %         PhaseQueue(k) = Correl_Peak_location_real+round(diff1);
  120. %         if(PhaseQueue(k) >= 5808)
  121. %             PhaseQueue(k) = mod(PhaseQueue(k),5808) + 1;%*1023
  122. %         end;
  123. %     end;
  124.     
  125.     Correl_Peak_location_real = PhaseQueue(k);
  126.     PhaseQueue(k) = fix(PhaseQueue(k)*1023/5808);
  127. %Correl_Peak_location_real = mod(Correl_Peak_location_real +1,1023) + 1;
  128.     %    if abs(diff1+diff2)/2 < 0.
  129. %     end;
  130.     
  131.     if(mod(length(PhaseQueue),200)==0)
  132.         % 绘制伪码相位跟踪的结果
  133.         figure(91);
  134.         plot(PhaseQueue);
  135.     end;
  136.     
  137. end