PN_Phase_Trace.m
上传用户:shencti
上传日期:2016-08-16
资源大小:16k
文件大小:5k
- %
- % 本程序用于实现扩频系统信号跟踪中,码相位的跟踪
- % 输入信号为,载波锁定之后的多普勒频率和码相位
- % 目前实际多普勒频率1000,相位952
- function Catched = PN_Phase_Trace(fd_estimate, Correl_Peak_location_real)
- % 获取系统参数
- [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;
- %%%%产生接受中频信号伪码,抽头为1,8
- code_phase=[1,8];
- [inputcode]=code_gen(code_phase); % 1023大小的GOLD伪码
- %%%%本地伪码
- native_code=inputcode;
- inputcode_2=[native_code,native_code];
- EmulateIndex = 0;
- k = 0;
- half_dot_insert = dot_insert/2;
- ThisPN = zeros(1, N); % 本次即时码
- EarlyPN2 = zeros(1, N); % 超前码
- LagPN2 = zeros(1, N); % 滞后码
- const4 = fix(N/(4*1023)); % 超前、滞后1/4,需要移动的抽样点
- const8 = fix(N/(8*1023)); % 超前、滞后1/8,需要移动的抽样点,当采样为5808点时,无法采用
- Correl_Peak_location_real = Correl_Peak_location_real*5808/1023;
- while (1)
- % 模拟输入的中频信号
- EmulateIndex = EmulateIndex + 1;
- [signal,signal_noise]=SignalGenerator(EmulateIndex,inputcode,fs,Ts,fi,delay_time,fd,SNR,Bandwidth,code_cycle,sigma_n,f0,N);
- IF_signal(1:N)=signal(1:N);
- IF_signal_noise(1:N)=signal_noise(1:N);
- % % 绘制信号及噪声
- % figure(1);
- % plot(IF_signal, 'b'); % 绘制生成的信号(含噪声)
- % hold on;
- % plot(IF_signal_noise, 'r'); % 信号的噪声
- % hold off;
- % 当前的载波NCO ××× fd_estimate在不断调整
- [NCO_I_Quanti,NCO_Q_Quanti]=Nco_gen(Ts,fi,fd_estimate,N);
-
- % 下变频
- Rece_Signal_Quan_down_I = IF_signal(1:N).* NCO_I_Quanti;
- Rece_Signal_Quan_down_Q = IF_signal(1:N).* NCO_Q_Quanti;
- Rece_Signal_Quan_down_I_noise=IF_signal_noise.*NCO_I_Quanti;
- Rece_Signal_Quan_down_Q_noise=IF_signal_noise.*NCO_Q_Quanti;
- %%%%经过低通滤波器,截止频率为1.023MHz
- [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); %进过低通滤波器
-
- % % 绘制比较,低通滤波器的作用
- % figure(2);
- % plot(Rece_Signal_Quan_down_I, 'b'); % 原始
- % hold on
- % plot(signal_I, 'r'); %
- % hold off
- % 这次不再内插成4096个点,而是保持5808个抽样点,表示一个码字长度的值
- ThisPN = PN2Generator(inputcode,Correl_Peak_location_real,N);
- % 相关间隔1/2
- % 超前码1/4
- EarlyPN2 = [ThisPN((const4+1):N) ThisPN(1:const4)];
- % 滞后码
- LagPN2 = [ThisPN((N-const4):N) ThisPN(1:(N-const4-1))];
- % 相关间隔1/4
- % 超前码1/8
- EarlyPN4 = [ThisPN((const8+1):N) ThisPN(1:const8)];
- % 滞后码
- LagPN4 = [ThisPN((N-const8):N) ThisPN(1:(N-const8-1))];
-
- k = k+1;
- % 积分器,算出I.Q
- Ips(k) = sum(ThisPN.*Rece_Signal_Quan_down_I);
- Qps(k) = sum(ThisPN.*Rece_Signal_Quan_down_Q);
- Ies2(k) = sum(EarlyPN2.*Rece_Signal_Quan_down_I);
- Qes2(k) = sum(EarlyPN2.*Rece_Signal_Quan_down_Q);
- Ils2(k) = sum(LagPN2.*Rece_Signal_Quan_down_I);
- Qls2(k) = sum(LagPN2.*Rece_Signal_Quan_down_Q);
-
- % Ies4(k) = sum(EarlyPN4.*Rece_Signal_Quan_down_I);
- % Qes4(k) = sum(EarlyPN4.*Rece_Signal_Quan_down_Q);
- %
- % Ils4(k) = sum(LagPN4.*Rece_Signal_Quan_down_I);
- % Qls4(k) = sum(LagPN4.*Rece_Signal_Quan_down_Q);
- % 伪码相位误差
- % 归一化点积鉴项器-斜率2
- EC1(k) = ((Ies2(k)-Ils2(k))*Ips(k) + (Qes2(k)-Qls2(k))*Qps(k))/(Ips(k)*Ips(k) + Qps(k)*Qps(k));%
-
- % if(EC1(k) > 2)
- % EC1(k) = 2;
- % end;
- % if (EC1(k) < -2)
- % EC1(k) = -2;
- % end;
- % 归一化超前减滞后功率鉴项器-斜率4
- % 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));
-
- % 计算相位差
- diff1 = EC1(k)*5808/1023/2;
- DiffFilter(k) = EC1(k)*5808/1023/2;
- if(k > 128)
- DiffFilter(k) = sum(DiffFilter(k-127:k))/128;
- if(DiffFilter(k) < 1/24)
- Catched = 1;
- disp('码相位已经跟踪并锁定');
- Correl_Peak_location_real
- %break;
- end;
- end;
- % diff2 = EC2(k)/4;
-
- % 使用滤波
- if(abs(DiffFilter(k)) < 1)
- PhaseQueue(k) = Correl_Peak_location_real;
- else
- PhaseQueue(k) = Correl_Peak_location_real+round(DiffFilter(k));
- if(PhaseQueue(k) >= 5808)
- PhaseQueue(k) = mod(PhaseQueue(k),5808) + 1;%*1023
- end;
- end;
-
- % % 未加滤波
- % if(abs(diff1) < 1)
- % PhaseQueue(k) = Correl_Peak_location_real;
- % else
- % PhaseQueue(k) = Correl_Peak_location_real+round(diff1);
- % if(PhaseQueue(k) >= 5808)
- % PhaseQueue(k) = mod(PhaseQueue(k),5808) + 1;%*1023
- % end;
- % end;
-
- Correl_Peak_location_real = PhaseQueue(k);
- PhaseQueue(k) = fix(PhaseQueue(k)*1023/5808);
- %Correl_Peak_location_real = mod(Correl_Peak_location_real +1,1023) + 1;
- % if abs(diff1+diff2)/2 < 0.
- % end;
-
- if(mod(length(PhaseQueue),200)==0)
- % 绘制伪码相位跟踪的结果
- figure(91);
- plot(PhaseQueue);
- end;
-
- end