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

📄 run_sync.m

📁 一个UWB仿真程序包
💻 M
字号:
function [sync_overlap, corr_overlap, fine_overlap, sync_ok, sync_offset, coarse_sync_index] = run_sync(rx_down, noise_var, sync_overlap, corr_overlap, fine_overlap, coarse_sync_index, users, L, TC, T_INT,...    N_INT,G,RX_BW,THLD_PROBA,N,PLOT_DEBUG)blocks_per_code_symbol = L * TC / (T_INT * N_INT );non_zero_code_symbols = sum(abs(len31_preamble_code(users(1).code)));code_len = length(len31_preamble_code(users(1).code));sync_overlap_len = length(sync_overlap);corr_tmpl_len = code_len * blocks_per_code_symbol * G;%used to cut out the extra overlap of one blocks_per_code_symbolstart_offset = max(0,sync_overlap_len-(corr_tmpl_len-1));if(isempty(fine_overlap))%we have to do coarse sync    %do coarse syncronization        %add overlap from last pass    rx_down = [sync_overlap rx_down];    %generate sequence to correlate with    corr_template = reshape( ...        repmat(abs(len31_preamble_code(users(1).code)),blocks_per_code_symbol, 1), ...        1,31*blocks_per_code_symbol);    %repeat correlation template G times    corr_template = repmat(corr_template,1,G);       %store overlap for next pass    sync_overlap = rx_down(max(1,end-corr_tmpl_len-blocks_per_code_symbol+2):end);        %analytical calculation of thld and noise floor, in a real system the noise    %comes from our components, so we know the noise_var and can thus always compute    %these thresholds    noise_floor = noise_var * T_INT * 2 * RX_BW * N_INT * G * ...        blocks_per_code_symbol * non_zero_code_symbols;    coarse_thld = noise_var * chi2inv(THLD_PROBA, (T_INT * 2* RX_BW) * N_INT * G * ...        blocks_per_code_symbol * non_zero_code_symbols);            [coarse_sync_index, corr_overlap] = coarse_sync_block(rx_down(1+start_offset:end),corr_overlap,corr_template,coarse_thld,...        blocks_per_code_symbol,N,PLOT_DEBUG);else    rx_down = [fine_overlap rx_down];endsync_offset = [];%check whether coarse sync succeededif(coarse_sync_index ~= 0)     coarse_sync_index = coarse_sync_index + start_offset;    %change the template wrt coarse_sync    corr_template = upsample(abs(len31_preamble_code(users(1).code)),blocks_per_code_symbol);    %repeat correlation template G times    corr_template = repmat(corr_template,1,G);        %calculate thld for new template    fine_thld = noise_var * chi2inv(THLD_PROBA, (T_INT * 2* RX_BW) * ...        N_INT * G * non_zero_code_symbols);    %run fine sync    %check whether we have enough samples to do fine sync    if(length(rx_down)>=coarse_sync_index+3*blocks_per_code_symbol+length(corr_template))        rx_down_fine = rx_down(coarse_sync_index-blocks_per_code_symbol:coarse_sync_index+3*blocks_per_code_symbol+length(corr_template));        [fine_sync_index] = fine_sync_block(rx_down_fine,corr_template,fine_thld,...            blocks_per_code_symbol,code_len,coarse_sync_index,PLOT_DEBUG);                %calculate sync offset wrt current_sample        sync_offset = fine_sync_index - sync_overlap_len - 1;                fine_overlap = [];    else        fine_overlap = rx_down;    endendsync_ok = coarse_sync_index > 0;% if(PLOT_DEBUG && sync_ok)%     figure%     plot(rx_down)%     hold on%     %plot(rx_t0_down,'x-r')%     line([coarse_sync_index coarse_sync_index],[0 max(rx_down)],'Color','y')%     %line([fine_sync_index fine_sync_index],[0 max(rx_down)],'Color','g')%     % line([fine_sync_index2 fine_sync_index2],[0 max(rx_down)],'Color','m')%     %%     %         figure%     %         plot(corr2)%     %         hold on%     %         plot(thld4*ones(1,length(corr2)),'g')%     %         line([corr_coarse_sync_index corr_coarse_sync_index],[0 max(corr2)],'Color','g')%     %         line([corr_fine_sync_index corr_fine_sync_index],[0 max(corr2)],'Color','y')%     %     end% endreturn;

⌨️ 快捷键说明

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