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

邮电通讯系统

开发平台:

Matlab

  1. %%检测程序
  2. function [snr,acq_flag,Correl_Peak_location]=Detection_Analysize_R_pd(Bandwidth,fd,f0,SNR,sigma_n,code_cycle,times_estimate,inputcode,T_interp,T,fd_estimate,Ts,fi,N,A1,B,M,fs,IntervalOfFreq,Code_native_fft_conj,dot_insert,delay_time,coef,coef_mod,EmulateIndex);
  3. acq_flag=0;
  4. for timeofestimate=1:times_estimate                                                  %搜索37个频点开始
  5.     fd_estimate=fd_estimate+(-1)^timeofestimate*(timeofestimate-1)*IntervalOfFreq;   %估计多普勒频率
  6.    fd_estimate = 1000;
  7.     %%%%唐检测参数复位
  8.     tong_k=B;
  9.     tong_k_last=0;
  10.     timeOfdetection=1;
  11.     
  12.     while(tong_k~=0&&tong_k~=A1)
  13.         for timesOfaccumu=1:M %加入M次非相干积累
  14.             EmulateIndex=EmulateIndex+1;
  15.             %%%%产生中频信号
  16.             [signal,signal_noise]=SignalGenerator(EmulateIndex,inputcode,fs,Ts,fi,delay_time,fd,SNR,Bandwidth,code_cycle,sigma_n,f0,N);
  17. %             figure(1)
  18. %             plot(abs(fft(signal)));
  19.             IF_signal(1:N)=signal(1:N);
  20.             IF_signal_noise(1:N)=signal_noise(1:N);
  21. %             figure(21);
  22. %             plot(IF_signal);
  23. %             figure(22);
  24. %             plot(IF_signal_noise);
  25.             %%%%进行下变频
  26.             [NCO_I_Quanti,NCO_Q_Quanti]=Nco_gen(Ts,fi,fd_estimate,N);                        %NCO产生        
  27.             Rece_Signal_Quan_down_I = IF_signal(1:N).* NCO_I_Quanti;
  28.             Rece_Signal_Quan_down_Q = IF_signal(1:N).* NCO_Q_Quanti;
  29.             Rece_Signal_Quan_down_I_noise=IF_signal_noise.*NCO_I_Quanti;
  30.             Rece_Signal_Quan_down_Q_noise=IF_signal_noise.*NCO_Q_Quanti;
  31.             
  32.          
  33.             %%%%经过低通滤波器,截止频率为1.023MHz
  34.             [signal_I,signal_Q,signal_I_noise,signal_Q_noise]=LP_filter(N,M,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);       %进过低通滤波器
  35. %             figure(2)
  36. %             plot(abs(fft(signal_I)));
  37. %             %%%%采用线性内插
  38.             for index_new=1:dot_insert
  39.                 index_previous=floor((index_new-1)*T_interp/Ts)+1;                                                 %产生内插抽取所需的原序列索引值
  40.                 Rece_Signal_down_I_1(index_new)=signal_I(index_previous)+round(((signal_I(index_previous+1)-signal_I(index_previous)))*mod(((index_new-1)*coef),coef_mod)/coef_mod);
  41.                 Rece_Signal_down_Q_1(index_new)=signal_Q(index_previous)+round(((signal_Q(index_previous+1)-signal_Q(index_previous)))*mod(((index_new-1)*coef),coef_mod)/coef_mod);
  42.                 Signal_Input(index_new)=Rece_Signal_down_I_1(index_new)-sqrt(-1)*Rece_Signal_down_Q_1(index_new);
  43.             end%%内插完成 
  44.             signal_fft=fft(Signal_Input,dot_insert);
  45.             %%%%与本地伪码进行相关
  46.             Z_spectrom=signal_fft.*Code_native_fft_conj;
  47.             Z_last=ifft(Z_spectrom);
  48.             Z_last_abs=abs(Z_last);
  49.             Z_last_square=Z_last_abs.^2;
  50.             Z_last_square_M(((timesOfaccumu-1)*dot_insert+1):(timesOfaccumu*dot_insert)) = Z_last_square;
  51.         end  %非相干积累完毕
  52.         Z= reshape(Z_last_square_M(1:M*dot_insert),dot_insert,M);   % 生成(4096*M)阶的矩阵  
  53.         Z_r = Z';                                                   % 将(4096*5)阶的矩阵转置为(M*4096)阶的矩阵  
  54.         Result_Sum(timeOfdetection,:) = sum(Z_r,1);                 % 进行M次非相参积累
  55.         Correl_Peak = max(Result_Sum(timeOfdetection,:));           %检测峰值
  56.         Correl_Peak_location(timeofestimate,timeOfdetection) = find(Result_Sum(timeOfdetection,:) == Correl_Peak,1,'first');     % 结果为(Detection_Times*1)维矩阵,查找第一个最大值 
  57.         snr(timeofestimate,timeOfdetection) =Correl_Peak/mean(Result_Sum(timeOfdetection,:));                                    %计算峰均比,作为门限判决   
  58.         %%%门限判决    
  59.             switch tong_k   
  60.                 case 1
  61.                     if(tong_k_last~=2)
  62.                         if (snr(timeofestimate,timeOfdetection)>4.5)            
  63.                             tong_k=tong_k+1;
  64.                         else
  65.                             tong_k=tong_k-1;
  66.                         end
  67.                     elseif (snr(timeofestimate,timeOfdetection) >4.5&&abs(Correl_Peak_location(timeofestimate,timeOfdetection)-Correl_Peak_location(timeofestimate,1))<=4)              % 门限范围4.5dB~6.5dB,每0.1dB步进
  68.                             tong_k_last=tong_k;
  69.                             tong_k=tong_k+1;
  70.                     else
  71.                             tong_k_last=tong_k;
  72.                             tong_k=tong_k-1;
  73.                     end
  74.                  otherwise
  75.                         tong_k_last=tong_k;
  76.                         if (snr(timeofestimate,timeOfdetection) >4.5&&abs(Correl_Peak_location(timeofestimate,timeOfdetection)-Correl_Peak_location(timeofestimate,1))<=4)              % 门限范围4.5dB~6.5dB,每0.1dB步进
  77.                             tong_k=tong_k+1;
  78.                         else
  79.                             tong_k=tong_k-1;
  80.                         end
  81.               end
  82.             if(tong_k==5)
  83.                 disp('信号存在')
  84.                 acq_flag=1;
  85.                 break;
  86.             else if(tong_k==0)
  87.                 disp('信号不存在')
  88.                 end;
  89.             end;
  90.             timeOfdetection=timeOfdetection+1;
  91.     end
  92. %         if acq_flag==1
  93. %             break;
  94. %         end;
  95. end  %搜索37个频点完毕