📄 effective_rate_calculator.m
字号:
%Wrapper file for sim, define sim params here and launch this script to start sim.%please refere to this file for a description of the possible params.%clean upclose allclear all%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Simulation parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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 0%NoiseSNR_DB = 16; %Eb/N0%InterferenceNN = 2; %number of users, 1 is UOIIF_PWR_DB = 0; %power levels of interferersIF_CODE_IDS = 5; %interferer preamble code ids% DataLAMBDA = 400; %[300 10]; %queue arrival rate (packets per second) [src ifs]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 notRAND_THS = 0; %whether to use random ths instead of 802.15.4a%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 = 11; %number of the run determines init of rngsPKTS_PER_RUN = 1000; %number of UOI pkts per runPLOT_DEBUG = 0; %flag indicating whether to show plots%in/out files% %set this to run, the actual channels are further dependend on rand...% RNG_SEED = RUN;% %set the random number generator to another state each time% rand('state',RNG_SEED); %same for same run% randn('state',RNG_SEED); %same for same run% CH_RNG_SEED = RNG_SEED;%determine packet length based on whether we do codingif RSCODE == 1 DATA_LENGTH = 1014;%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 ../signal;addpath ../receiver;addpath ../preamble_signal;addpath ../data_signal;addpath ../mui;addpath ../reed_solomon;%lengths in samplessamples = get_samples_values(TC,FS_CONT, ... BURST_LENGTH, ... SYMBOL_LENGTH, ... PACKET_LENGTH);%create UOIusers(1).pwr = 0;users(1).code = CODE_ID;%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 phaseNRUN = 100;eff_rates = zeros(1,NRUN);eff_pkts = zeros(1,NRUN);for i = 1:NRUN i%get the sim scenario[stat] = get_packet_timing(NN,PKTS_PER_RUN,LAMBDA,ack_gap,WARMUP,NSYNC,NSFD,... TC,L,G,PACKET_LENGTH,SYMBOL_LENGTH,code_len,PLOT_DEBUG);%effective packets per secondssim_time = stat.stopTimes(end)-stat.startTimes(1);% packets_after_start = find(stat.packets(:,1)>=stat.startTimes(1))% num_if_packets = length(find(stat.packets(packets_after_start,2)==2))% eff_if_pkts_per_second = num_if_packets/sim_time% eff_if_rate_Mbps = eff_if_pkts_per_second*PACKET_LENGTH/1e06eff_pkts_per_second = PKTS_PER_RUN/sim_time;theoretical_rate_Mbps = LAMBDA(1)*PACKET_LENGTH/1e06;eff_rate_Mbps = PKTS_PER_RUN*PACKET_LENGTH/sim_time/1e06;fprintf('Duration of the simulation = %.4f [s]\n',sim_time);fprintf('Packets/sec = %.2f, theo. rate = %.2f [Mbps]\n', ... eff_pkts_per_second,theoretical_rate_Mbps);fprintf('Eff. rate = %.4f [Mbps]\n',eff_rate_Mbps);eff_rates(i) = eff_rate_Mbps;eff_pkts(i) = eff_pkts_per_second;end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -