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

📄 sim_logic.m

📁 source Matlab traites the UWB
💻 M
📖 第 1 页 / 共 2 页
字号:
%create simulation logic%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Simulation parameters                                                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%close all;clear all;%%%%%%%%%%%%%%%%%%%%%%%% define parameters %%%%%%%%%%%%%%%%%%%%%%%%%TimingTC = 2e-9; %chip duration in sFS_CONT = 10e9; %sampling frequency in Hz to get cont time signal%PreambleL = 64; %spreading factorCODE_ID = 5; %which one of the 802.15.4a ternary codes to use for UOI%Channel ModelCH_MODEL = 1; %which channel model to chooseCH_ATT_THLD_DB = 15; %rays with bigger attenuation are considered 0CH_RNG_SEED  = sum(clock);%NoiseSNR_DB = 16; %Eb/N0%InterferenceNN = 3; %number of users, 1 is UOIIF_PWR_DB = [3 10]; %power levels of interferersIF_CODE_IDS = [6 6]; %interferer preamble code ids% DataLAMBDA = 200; %queue arrival rate (packets per second)BURST_LENGTH = 4; %pulses per burstSYMBOL_LENGTH = 512; %chips per symbolPACKET_LENGTH = 127*8; %max packet length, will be smaller if RSCODE = 1RSCODE = 0; %whether to use coding or not%ReceiverRX_BW = 2e9; %BW of the receiver determines Nyquist = 2*RX_BWT_INT = 1e-9; %integration lengthN_INT = 8; %how many blocks of length T_INT to sumG = 4; %how many repetitions of code in correlationTHLD_PROBA = 0.9999; %threshold for correlation peaksN = 6; %number of consecutive corr peaks neededG_CHEST = 8; %number of len 31 symbols we accumulate for channel mask%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%simulation specific values, runs, instances allowing parallelizationRUN = 9; %number of the run determines init of rngsPKTS_PER_RUN = 50; %number of UOI pkts per runPLOT_DEBUG = 0; %flag indicating whether to show plots%in/out filesCLUSTER = 0; %indicates whether we are running on cluster or notOUT_FILE = 'out_test.txt'; %output text file%determine packet length based on whether we do codingif RSCODE == 1  DATA_LENGTH = 870;  fullblock = floor(DATA_LENGTH/330);  PACKET_LENGTH = fullblock*378 + (DATA_LENGTH-fullblock*330) + 48;else  DATA_LENGTH = PACKET_LENGTH;end%add paths to includeaddpath ./rng;addpath ./util;addpath ./signal;addpath ./receiver;addpath ./preamble_signal;addpath ./data_signal;addpath ../src/channel;addpath ../src/scrambling_timehopping;addpath ./mui;addpath ./test;addpath ./reed_solomon;%for the time being we set noise level herenoise_var = 1 / 10^(SNR_DB/10) / 2; %EbN0%create UOIusers(1).pwr = 0;users(1).code = CODE_ID;%create interferersfor i=2:NN   users(i).pwr = IF_PWR_DB(i-1);   users(i).code = IF_CODE_IDS(i-1);end%get preamble values[uoi_pre sfd_code NSYNC NSFD] = generate_preamble(L,users(1).code);non_zero_code_symbols = sum(abs(len31_preamble_code(users(1).code)));code_len = length(len31_preamble_code(users(1).code));%create the packetsack_gap = (NSYNC + NSFD) * code_len * L * TC + 0 * SYMBOL_LENGTH * TC; %secondsWARMUP = 500; %number of warmup packets to pass transient phase%get the sim scenario[timing] = get_packet_timing(NN,PKTS_PER_RUN,LAMBDA,ack_gap,WARMUP,NSYNC,NSFD,...    TC,L,G,PACKET_LENGTH,SYMBOL_LENGTH,code_len,PLOT_DEBUG);%lengths in samplessamples = get_samples_values(TC,FS_CONT, ...    BURST_LENGTH, ...    SYMBOL_LENGTH, ...    PACKET_LENGTH);pre_len = (NSYNC+NSFD)*code_len*L*samples.chip; %length of preamble in samplestotal_len = pre_len + samples.packet; %length of total packet in samples%the different block sizes the simulator operates onsync_block_size = pre_len/4;% make sure the block size is divisible by % samples_per_tint * N_INT, so that we don't have to pad zeros in the ed receiversamples_per_tint = T_INT * FS_CONT;divider = samples_per_tint * N_INT;no_times = ceil(sync_block_size / divider);no_pad = no_times * divider - sync_block_size;sync_block_size = sync_block_size + no_pad;blocks_per_code_symbol = L * TC / (T_INT * N_INT);corr_tmpl_len = G*31*blocks_per_code_symbol;fine_sync_block_size = 3*blocks_per_code_symbol+corr_tmpl_len*samples_per_tint*N_INT;ch_est_block_size = G_CHEST*code_len*blocks_per_code_symbol*samples_per_tint*N_INT;sfd_block_size = (NSYNC+NSFD-G_CHEST)*code_len*blocks_per_code_symbol*samples_per_tint*N_INT;%best we can do is a precision of 1/FS_CONT -> convert cont. times to this%precisiontiming.startTimes = round(timing.startTimes*FS_CONT); timing.stopTimes = round(timing.stopTimes*FS_CONT); timing.packets(:,1) = round(timing.packets(:,1)*FS_CONT); %add some random samples at the beginning so that we are not always well%aligned with a chip -> effect of arbitrary sampling starttiming.startTimes = timing.startTimes - floor(samples.chip*rand(1,length(timing.startTimes)));%precompute some stuff[ep] = get_ep(PACKET_LENGTH, ...              SYMBOL_LENGTH, ...              BURST_LENGTH, ...              samples);symbol_start = get_symbol_start(PACKET_LENGTH,samples);% %just to make sure, recount quickly UOI packets% num_uoi_pkts = length(timing.packets(timing.packets(:,2)==1,2));% if(num_uoi_pkts ~= PKTS_PER_RUN)%     num_uoi_pkts%     PKTS_PER_RUN%     keyboard%     error('uoi pkts do not match...');% end%initialize stuff needed for bookkeepinguoi_pkt_errors = -1 * ones(3,PKTS_PER_RUN); %this is where we do the bookkeepingnum_uoi_pkts_seen = 0; %counter%now, let's start with the simulation. first of all we simulate by chunkstot_pkts = size(timing.packets,1)num_sim_chunks = length(timing.startTimes)for chunk=1:num_sim_chunks    tic    chunk    %get start/stop time    start_samples = timing.startTimes(chunk);    stop_samples = timing.stopTimes(chunk);    pkts = []; %all the packets relevant for this chunk    uoi_data_starts = []; %starting times of data parts of UOI    uoi_pkt_idx = []; %index into uoi_pkt_errors/pkts of the corresponding packet        %determine which of the packets belong to this chunk    num_pkts = 0; %number of packets in this chunk    for i=1:tot_pkts        is_part = false;        pkt_start = timing.packets(i,1);        pkt_user = timing.packets(i,2);        if(chunk==1 && pkt_start < start_samples)%the first chunk sometimes has             %packets preceeding it, if we had a forced stop when creating the timing            is_part = true;        elseif(pkt_start >= start_samples && pkt_start <= stop_samples)            %check whether it fall into the boundary            is_part = true;        end        if(is_part)            num_pkts = num_pkts + 1;            pkts(num_pkts).start = pkt_start-start_samples+1;            pkts(num_pkts).user = pkt_user;            pkts(num_pkts).channel = [];            pkts(num_pkts).ch_len = 0;            pkts(num_pkts).chip_span = 0.5;            pkts(num_pkts).tx_bits = [];            pkts(num_pkts).data_bits = [];            if(pkts(num_pkts).user == 1)                %don't consider packets that preceed chunk 1                if(~(chunk == 1 && pkt_start < start_samples))                    num_uoi_pkts_seen = num_uoi_pkts_seen + 1;                    uoi_data_starts = [uoi_data_starts pkts(num_pkts).start+pre_len];                    uoi_pkt_idx = [uoi_pkt_idx; num_pkts, num_uoi_pkts_seen];                end            end        end            end        %note we rescale so that the first sample of the chunk is sample number 1    sim_stop = stop_samples-start_samples;        %these are the states our simulater can be in, names are pretty    %self-explanatory    SYNC = 1;    FINE_SYNC = 2;    CH_EST = 3;    SFD = 4;    DATA = 5;

⌨️ 快捷键说明

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