📄 ed_sim_mui.m
字号:
%the fine sync current_sample = sync_sample; state = CH_EST; sync_overlap = []; corr_overlap = []; coarse_sync_index = 0; fprintf('OK\n'); elseif(sync_ok) state = FINE_SYNC; %coarse sync ok, but fine sync not yet sync_overlap = []; corr_overlap = []; fprintf('OK\n'); else %update current_sample current_sample = current_sample + sync_block_size; fprintf('WAIT\n'); end case FINE_SYNC, fprintf('FINE_SYNC...'); %run the sync on the next block of data %get an rx signal block [pkts, rx_sig] = ... get_rx_signal(... current_sample + sync_block_size,... current_sample + sync_block_size + fine_sync_block_size - 1, ... pkts,total_len,users,ep,symbol_start,TC,... FS_CONT,channel_p,... DATA_LENGTH,RSCODE,L,PACKET_LENGTH,BURST_LENGTH,... SYMBOL_LENGTH,RX_BW,noise_var,samples,PLOT_DEBUG ... ); %pass it through the ed receiver [rx_down,samples_per_tint] = ed_receiver(rx_sig,T_INT,FS_CONT,N_INT,0); %run synchronization [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); fine_overlap = []; sync_sample = current_sample+sync_offset*samples_per_tint*N_INT; %the factor is because we only have this precision on %the fine sync current_sample = sync_sample; state = CH_EST; sync_overlap = []; %if we are in the begining corr_overlap = []; %what has to be remembered from the correlation in on step to next fine_overlap = []; coarse_sync_index = 0; fprintf('OK\n'); case CH_EST, fprintf('CH_EST...'); %check whether it makes sense to try if(sim_stop - current_sample < samples.packet) fprintf('OVER\n'); break; %it is over end fprintf(fidlog,'%20.0f:1 Sync OK\n',current_sample+start_samples-1); %get an rx signal block to run channel estimation on [pkts, rx_sig] = get_rx_signal(current_sample,... current_sample + ch_est_block_size - 1,pkts,total_len,users,ep,symbol_start,TC,... FS_CONT,channel_p,... DATA_LENGTH,RSCODE,L,PACKET_LENGTH,BURST_LENGTH,... SYMBOL_LENGTH,RX_BW,noise_var,samples,PLOT_DEBUG); %pass it through the ed receiver [rx_down,samples_per_tint] = ed_receiver(rx_sig,T_INT,FS_CONT,N_INT,0); %calculate thld for channel estimation chest_thld = noise_var * chi2inv(THLD_PROBA, (T_INT * 2* RX_BW) * ... N_INT * G_CHEST * non_zero_code_symbols); [channel_mask, est_sig_level] = channel_est(rx_down, 1, ... G_CHEST, abs(len31_preamble_code(users(1).code)), blocks_per_code_symbol, ... chest_thld, PLOT_DEBUG); %advance time current_sample = current_sample + ch_est_block_size; %go to sfd detection state = SFD; fprintf('OK\n'); case SFD, fprintf('SFD...'); fprintf(fidlog,'%20.0f:2 Channel Estimation done\n',current_sample+start_samples-1); %check whether it makes sense to try if(sim_stop - current_sample < samples.packet) fprintf('OVER\n'); fprintf(fidlog,'%20.0f:5 SFD MD, too late...\n',current_sample+start_samples-1); break; %it is over end %get an rx signal block to run channel estimation on [pkts, rx_sig] = get_rx_signal(current_sample,... current_sample + sfd_block_size - 1,pkts,total_len,users,ep,symbol_start,TC,... FS_CONT,channel_p,... DATA_LENGTH,RSCODE,L,PACKET_LENGTH,BURST_LENGTH,... SYMBOL_LENGTH,RX_BW,noise_var,samples,PLOT_DEBUG); %pass it through the ed receiver [rx_down,samples_per_tint] = ed_receiver(rx_sig,T_INT,FS_CONT,N_INT,0); %we are now ready to look for the sfd in the remaining part ch_taps = length(find(channel_mask>0));%no of taps that are non-zero fprintf(fidlog,'%20.0f:99 MaskLen=%i\n',current_sample+start_samples-1,ch_taps); est_noise_level = noise_var * (T_INT * 2* RX_BW) * N_INT * ... ch_taps * non_zero_code_symbols; sfd_thld = 2.5*(est_sig_level - est_noise_level); [sfd_index] = sfd_detection(rx_down,sfd_code,sfd_thld, ... 1-G_CHEST*code_len*blocks_per_code_symbol,channel_mask,G_CHEST,users(1).code,blocks_per_code_symbol,... PLOT_DEBUG); if(sfd_index) sfd_sync_sample = current_sample+(sfd_index-1)*samples_per_tint*N_INT; state = DATA; next_sample = sfd_sync_sample + NSFD * code_len*blocks_per_code_symbol*samples_per_tint*N_INT; sfd_overlap = rx_sig(next_sample-current_sample+1:end); current_sample = next_sample; fprintf('OK\n'); else state = SYNC; channel_mask = []; est_sig_level = 0; current_sample = current_sample + sfd_block_size; fprintf(fidlog,'%20.0f:6 SFD MD\n',current_sample+start_samples-1); fprintf(fidlog,'%20.0f:0 Sync Start\n',current_sample+start_samples-1); fprintf('FAILED\n'); end case DATA, fprintf('DATA...'); %add a decoding event %events.decoding = [events.decoding, current_sample+start_samples-1]; %check whether there is a data part of the UOI nearby. if %not it does not make sense to do the whole decoding stuff. [diff2closest, closest_idx] = min(abs(uoi_data_starts-current_sample)); %if the difference to the closest starting point of a data %sequence of the UOI is bigger than the length of the %channel mask, we will never be able to decode successfully if(diff2closest <= length(channel_mask)*N_INT*T_INT*FS_CONT) fprintf(fidlog,'%20.0f:3 SFD OK\n',current_sample+start_samples-1); sfd_overlap_len = length(sfd_overlap); %get an rx signal block [pkts, rx_sig] = get_rx_signal(current_sample+sfd_overlap_len,... current_sample + samples.packet - 1,pkts,total_len,users,ep,symbol_start,TC,... FS_CONT,channel_p,... DATA_LENGTH,RSCODE,L,PACKET_LENGTH,BURST_LENGTH,... SYMBOL_LENGTH,RX_BW,noise_var,samples,PLOT_DEBUG); rx_sig = [sfd_overlap rx_sig]; sfd_overlap = []; %pass it through the ed receiver demod_bit = ed_decoder(rx_sig, users(1).ths, ... symbol_start, ... 0,samples.burst,samples.symbol, ... channel_mask', T_INT*N_INT, ... 0, ... PACKET_LENGTH, FS_CONT, T_INT, N_INT); if RSCODE == 1 % RS decoding dec_bit = rs_decoder_154a(demod_bit,ep.interleaver_seed); else dec_bit = demod_bit; end %get the corresponding data bits data_bit = pkts(uoi_pkt_idx(closest_idx,1)).data_bits; % Compute the BER num_err = sum(abs(data_bit-dec_bit)); ber_sim = num_err/DATA_LENGTH; %do the bookkeeping %test to be sure if(uoi_pkt_errors(1,uoi_pkt_idx(closest_idx,2))~=-1) error('sth went wrong...'); end uoi_pkt_errors(1,uoi_pkt_idx(closest_idx,2))=num_err; uoi_pkt_errors(2,uoi_pkt_idx(closest_idx,2))=ber_sim; uoi_pkt_errors(3,uoi_pkt_idx(closest_idx,2))=diff2closest; fprintf('OK\n'); fprintf('errors: %d, ber: %.5f\n',num_err, ber_sim); else fprintf('TOO FAR (%20.0f), Decoding aborted\n',diff2closest); if(current_sample - uoi_data_starts(closest_idx) > 0)%we are too late fprintf(fidlog,'%20.0f:7 SFD FA LATE\n',current_sample+start_samples-1); else %we are too early fprintf(fidlog,'%20.0f:8 SFD FA EARLY\n',current_sample+start_samples-1); end end current_sample = current_sample + samples.packet; fprintf(fidlog,'%20.0f:4 Decoding done\n',current_sample+start_samples-1); fprintf(fidlog,'%20.0f:0 Sync Start\n',current_sample+start_samples-1); state = SYNC; otherwise error('undefined state of simulation'); end %state switch end %main while loop %tocend %sim chunksfprintf(fidlog,'%20.0f:9 Simulation Stop\n',current_sample+start_samples-1);fprintf(fidlog,'Packet Timings: \n');%write packet timings to same filefor i=1:size(timing.packets,1) fprintf(fidlog,'%20.0f:%i\n',timing.packets(i,1),timing.packets(i,2));endfprintf(fidlog,'Parameters: \n');fprintf(fidlog,'sync_len:%20.0f\n',sync_len);fprintf(fidlog,'sfd_len:%20.0f\n',sfd_len);fprintf(fidlog,'packet_len:%20.0f\n',samples.packet);%close log filefclose(fidlog);uoi_pkts_class = classify_packets(LOG_FILE);uoi_pkt_errors = [uoi_pkt_errors' uoi_pkts_class];%write stats to output filefid = fopen( OUT_FILE, 'w' );for i=1:size(uoi_pkt_errors,1) %errors, ber, syncoffset, ifsync, ifsfd, ifdata, howmissed, %pre_ifpreoverlap pre_ifdataoverlap data_ifpreoverlap, %data_ifdataoverlap, %FA: sync_ifpreoverlap sync_ifdataoverlap, chest ifpreo chesst ifdatao % sfd if preo sfd if data overlap, time2sync, time2sfd after synced, % mask_len fprintf(fid,'%i %.9f %i %i %i %i %i %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %i %i %i\n',... uoi_pkt_errors(i,1),uoi_pkt_errors(i,2),uoi_pkt_errors(i,3),uoi_pkt_errors(i,6),... uoi_pkt_errors(i,7),uoi_pkt_errors(i,8),uoi_pkt_errors(i,13),... uoi_pkt_errors(i,14),uoi_pkt_errors(i,15),uoi_pkt_errors(i,16),uoi_pkt_errors(i,17),... uoi_pkt_errors(i,18),uoi_pkt_errors(i,19),uoi_pkt_errors(i,20),... uoi_pkt_errors(i,21),uoi_pkt_errors(i,22),uoi_pkt_errors(i,23),... uoi_pkt_errors(i,24)/code_len/blocks_per_code_symbol/samples_per_tint/N_INT,... uoi_pkt_errors(i,25)/code_len/blocks_per_code_symbol/samples_per_tint/N_INT,... uoi_pkt_errors(i,26));endfclose(fid);%quit the matlab sessionif(CLUSTER) clear all; %quit;endreturn;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -