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

📄 fine_sync.m

📁 一个UWB仿真程序包
💻 M
字号:
function [fine_sync_index] = fine_sync(rx_down,corr_template,thld,...                blocks_per_code_symbol,code_len,coarse_sync_index,PLOT_DEBUG);        %calculate the correlation only in region we need it...    %temp_mat = zeros(blocks_per_code_symbol,length(corr_template));    %for i=1:blocks_per_code_symbol*31    %    temp_mat(i,:) = rx_down(coarse_sync_index+i-1:coarse_sync_index+length(corr_template)+i-2);    %end    %corr = temp_mat * corr_template';%     corr2 = conv(rx_down(coarse_sync_index:coarse_sync_index+code_len*blocks_per_code_symbol+length(corr_template)), fliplr(corr_template));%     corr = corr2(length(corr_template):length(corr_template)+blocks_per_code_symbol*code_len-1);%     % %  clear temp_mat; %free memory%     %determine max of corr -> strongest path%     [max_corr4, ind_corr4] = max(corr);%     %     %we now go backwards through the correlation until we find one sample%     %that is not above the threshold, the max number of steps we go back is%     %blocks_per_code_symbol/2%     current_index = ind_corr4;%     t0_index = ind_corr4;%     for i=1:floor(blocks_per_code_symbol/2)%         current_index = current_index - 1;%         %wrap around if it goes over the beginning%         if(current_index == 0)%             current_index = length(corr);%         end%         if(corr(current_index) >= thld)%             t0_index = t0_index - 1;%         else%             break;%         end%     end%     %     %fine_sync_index = coarse_sync_index + t0_index - 1;%     if(PLOT_DEBUG)%         %     figure%         %     plot(corr2)% %         figure%         plot(corr)%         hold on%         plot(thld*ones(1,length(corr)),'m')%         line([t0_index t0_index],[0 max(corr)],'Color','g')%         line([ind_corr4 ind_corr4],[0 max(corr)],'Color','y')%     end                        %from -block to + 2blocks    corr3 = conv(rx_down(coarse_sync_index-blocks_per_code_symbol:coarse_sync_index+3*blocks_per_code_symbol+length(corr_template)), fliplr(corr_template));    corr3 = corr3(length(corr_template):length(corr_template)+blocks_per_code_symbol*4);    %[max_corr4, ind_corr4] = max(corr3(blocks_per_code_symbol:2*blocks_per_code_symbol));    [max_corr4, ind_corr4] = max(corr3);    %ind_corr4 = ind_corr4 + blocks_per_code_symbol - 1;        %we now go backwards through the correlation until we find one sample    %that is not above the threshold, the max number of steps we go back is    %blocks_per_code_symbol/2    current_index = ind_corr4;    t0_index = ind_corr4;    for i=1:floor(blocks_per_code_symbol/2)    %for i=1:blocks_per_code_symbol-1        current_index = current_index - 1;        %wrap around if it goes over the beginning        if(current_index == 0)            break;        end        if(corr3(current_index) >= thld && corr3(current_index)>corr3(current_index+blocks_per_code_symbol))            t0_index = current_index;        end    end    fine_sync_index = coarse_sync_index - blocks_per_code_symbol + t0_index - 1;            if(PLOT_DEBUG)        %     figure        %     plot(corr2)        figure        plot(corr3)        hold on        plot(thld*ones(1,length(corr3)),'m')        line([t0_index t0_index],[0 max(corr3)],'Color','g')        line([ind_corr4 ind_corr4],[0 max(corr3)],'Color','y')    end%     coarse_template = reshape( ...%         repmat(abs(len31_preamble_code(5)),blocks_per_code_symbol, 1), ...%         1,31*blocks_per_code_symbol);%     %repeat correlation template G times%     coarse_template = repmat(coarse_template,1,4);%     corr4 = conv(rx_down(coarse_sync_index-blocks_per_code_symbol:coarse_sync_index+blocks_per_code_symbol+length(coarse_template)), fliplr(coarse_template));%     corr4 = corr4(length(coarse_template):length(coarse_template)+blocks_per_code_symbol*2-1);%     [max_corr4, ind_corr4] = max(corr4);%     if(PLOT_DEBUG)%         %     figure%         %     plot(corr2)% %         figure%         plot(corr4)%         hold on%         plot(thld*ones(1,length(corr4)),'m')%         %line([t0_index t0_index],[0 max(corr3)],'Color','g')%         line([ind_corr4 ind_corr4],[0 max(corr4)],'Color','y')%     end            %corr2 = conv(rx_down,fliplr(corr_template));%     vinc = corr(corr_coarse_sync_index-...%         blocks_per_code_symbol:corr_coarse_sync_index+blocks_per_code_symbol);%     [max_vinc ind_vinc] = max(vinc);%     %get the corresponding index in corr%     corr_fine_sync_index2 = corr_coarse_sync_index + ind_vinc - blocks_per_code_symbol - 1;%     %get the corresponding index in the received signal%     fine_sync_index2 = corr_fine_sync_index2 - (length(corr_template)-1)% % corr3 = conv(rx_down(coarse_sync_index:coarse_sync_index+blocks_per_code_symbol+length(corr_template2)), fliplr(corr_template2));% % thld3 = noise_var * chi2inv(THLD_PROBA, (T_INT * 2* RX_BW) * N_INT * G * 16)return;

⌨️ 快捷键说明

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