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

📄 coarse_sync.m

📁 一个UWB仿真程序包
💻 M
字号:
function [coarse_sync_index] = coarse_sync(rx_down,corr_template,thld,...                                     blocks_per_code_symbol,N,PLOT_DEBUG)% %generate sequence to correlate with% blocks_per_code_symbol = L * TC / (T_INT * N_INT );% corr_template = reshape( ... %   repmat(abs(len31_preamble_code(CODE_ID)),blocks_per_code_symbol, 1), ...%   1,31*blocks_per_code_symbol);% % %repeat correlation template G times% corr_template = repmat(corr_template,1,G);%do the correlationcorr = conv(rx_down, fliplr(corr_template));%coarse synchronization% %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 * 16; %16 is due to the fact that out of the 31 code% %symbols 16 are non-zero% thld = noise_var * chi2inv(THLD_PROBA, (T_INT * 2* RX_BW) * N_INT * G * ...%   blocks_per_code_symbol * 16);%downsample correlation for coarse synccorr_sampled = downsample(corr,blocks_per_code_symbol);%pad the end with zeros so that we can do the reshapecorr_sampled = zero_pad_reshape(corr_sampled,31);corr_sampled_mat = reshape(corr_sampled,31,length(corr_sampled)/31);%check against threshold, set values lower than thld to zerocorr_sampled_mat(corr_sampled_mat < thld) = 0;[m max_slots] = max(corr_sampled_mat);clear corr_sampled_mat; %free memory%find N consecutive identical values (and make sure they don't correspond to a%slot that was below the thld i.e. that are zero)test_slot_no = -1; %this is to remember which of the 31 slots created the last maxno_consecutive = 0; %how many consecutive maxes do we have for this slotcorr_sampled_coarse_sync_index = 0;%index into corr_sampled of the sync pointfor i=1:length(max_slots)  current_slot_no = max_slots(i);  if(m(i)~= 0) %is not zero    if(test_slot_no == current_slot_no)        no_consecutive = no_consecutive + 1;    else        test_slot_no = current_slot_no;        no_consecutive = 1;    end    if(no_consecutive == N)        corr_sampled_coarse_sync_index = (i-1)*31 + test_slot_no;        break;    end  else    test_slot_no = -1;    no_consecutive = 0;  endend%coarse sync index is now 0 if not successful, otherwise equals number of %128ns block of starting point in corr_sampled%corr_sampled_coarse_sync_indexif(corr_sampled_coarse_sync_index ~= 0)    %find the corresponding index into corr (the one not sampled)    corr_coarse_sync_index = ...        (corr_sampled_coarse_sync_index-1)*blocks_per_code_symbol+1;        %find the corresponding index into the received signal    coarse_sync_index = corr_coarse_sync_index - (length(corr_template)-1);        if(PLOT_DEBUG)        figure        plot(corr)        hold on        %plot(noise_floor*ones(1,length(corr)),'r')        plot(thld*ones(1,length(corr)),'m')        line([corr_coarse_sync_index corr_coarse_sync_index],[0 max(corr)],'Color','y')    end    else    coarse_sync_index = 0;end    return;

⌨️ 快捷键说明

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