def dec_wrap2(): """Declaration function. It initializes all the relevant parameters to the simulatiions """ # Broadcast parameters p = lib.SyncParams() p.zc_len = 31 # Length of the ZC sequence to use p.f_symb = 30.72e6 # "true" sampling rate p.f_samp = p.f_symb*4 # oversampling rate. SHould be an integer factor of p.f_samp. This factor is the oversampling factor p.repeat = 1 # Repeat the synchronization signal p.spacing_factor = 1 # Spacing between the raisedcosines. A factor of 1 uses the standard definition, where # one symbol is placed every p.power_weight = 2 # Exponent \gamma p.full_sim = True # Leave true p.bias_removal = False # Utilization of the bias removal algorithm p.ma_window = 1 # If bigger than 1, applies a moving average on the crosscorrelation R_yz p.train_type = 'chain' # 'single': only one ZC sequence makes up the synchronization systemm # 'chain' : pair of ZC sequence with opposite root parameter p.crosscorr_type = 'match_decimate' # don't touch p.match_decimate_fct = lib.downsample # lib.downsample corresponds to a standard idealized analog-digital sampler p.peak_detect = 'wavg' # 'wavg': Performs a weighted average on the crosscorrelation to determine the location of the # synchronization signal # 'argmax': Takes the max of the crosscorrelation instead of a weighted average p.pulse_type = 'rootraisedcosine' # Analog shaping pulse p.plen = 31 # Length of the raisedcosine pulseshape p.rolloff = 0.2 # Raisedcosine rolloff factor. A value of 0 corresponds to a normalized sinc p.central_padding = 0 # Pad zeros between the pair of ZC sequences. As a fraction of zpos length p.scfdma_precode = True # Apply SCFDMA? p.scfdma_L = 4 # SC-FDMA factor p.scfdma_sinc_len_factor = p.scfdma_L # Used for the demodulation of SC-FDMA in a decentralized setting #------------------------ # Simulation parameters ctrl = SimControls() ctrl.steps = 40 # Approximately how many T_0 synchronization steps will be executed ctrl.basephi = 40000 # How many oversamples per period T_0? T_0 = basephi*p.f_samp ctrl.nodecount = 35 # Number of nodes to simulate ctrl.display = True # Display stuff for a single simulation ctrl.static_nodes = 0 # Nodes that broadcast but do not synchronize ctrl.quiet_nodes = 0 # Nodes that synchronize but do not broadcast ctrl.quiet_selection = 'random' # How are quiet nodes assigned #ctrl.quiet_selection = 'kmeans' # Parameters specific to the contention method (sensing) ctrl.qc_threshold = 5 # As a factor of the outage threshold ctrl.qc_steps = 3 # Initialization parameters ctrl.CFO_step_wait = float('inf') # Use float('inf') to never correct for CFO. CFO CORRECTION DEPRECATED! ctrl.TO_step_wait = 4 # How many synchronization steps to wait before broadcasting. In factors of T_0 ctrl.max_start_delay = 7 # nodes are onlined between t \in [0, max_start_delay]. In factor of T_0 ctrl.use_ringarr = True # Use True unless you want to blow up your RAM ctrl.theta_bounds = [0,1] # bounds for the uniform distribution of \theta ctrl.deltaf_bound = 3e-2 # bounds for the uniform distribution of \delta f between the nodes. ctrl.rand_init = False # Randomly initiate values? ctrl.non_rand_seed = 1238819 # If rand_init = False, the 'random' values in the simulation will be initiated with this seed ctrl.epsilon_TO = 0.5 ctrl.noise_power = -101 + 9 # Reception thermal noise. -101 + 9 : thermal noise + receiver noise amplification. #ctrl.noise_power = float('-inf') # Use if you want a noiseless simulation # Multipath parameters ctrl.delay_params = lib.DelayParams(lib.delay_pdf_3gpp_exp) # corresponds to 3gpp specifications ctrl.delay_params.taps = 50 # How many multipath taps? # The next variable is badly named. it correponds to half the side of a square area # ctrl.max_dist_from_origin = 500 corresponds to an area of (1000m)^2 ctrl.max_dist_from_origin = 500 # (in meters) # Half-duplexing method. Use at your own risk ctrl.half_duplex = False ctrl.hd_slot0 = 0.3 # in terms of phi ctrl.hd_slot1 = 0.7 # in terms of phi ctrl.hd_block_during_emit = True ctrl.hd_block_extrawidth = 0 # as a factor of offset (see runsim to know what is offset) # Variable adjustement window size. Use at your own risk ctrl.var_winlen = False ctrl.vw_minsize = 5 # as a factor of len(p.analog_sig) ctrl.vw_lothreshold = 0.1 # winlen reduction threshold ctrl.vw_hithreshold = 0.1 # winlen increase threshold ctrl.vw_lofactor = 1.5 # winlen reduction factor ctrl.vw_hifactor = 2 # winlen increase factor # Outage detection. Only broadcast of "near" outage. E-mail [email protected] for more # explanation on how it works ctrl.outage_detect = False # thesis #ctrl.outage_detect = True # INTERD ctrl.outage_threshold_noisefactor = 1/(p.zc_len)*2 # COrrect propagation delay by applying some filter. # lib.highpass_avg(6) corresponds to a filter of length Q=6, as described in my thesis ctrl.prop_correction = True ctrl.pc_step_wait = 0 ctrl.pc_b, ctrl.pc_a = lib.hipass_avg(6) #THESIS ctrl.pc_avg_thresh = float('inf') # If std of N previous TOx samples is above this value, then ctrl.pc_std_thresh = float(80) # If std of N previous TOx samples is above this value, then # no PC is applied (but TOy is still calculated) # Save values to disk? ctrl.saveall = True #------------- # To run multiple simulations in bulk, a dictionary of modification to ctrl (cdict) and modifications to p # (pdict) can be used to iterate over multiple configurations # Note that any parameter to p or ctrl can be iterated this way # For example, this will iterate over 5 configurations, from right to left. Each iteration assigns # the value to the property and runs the simulations. See SimWrap for more details cdict = { 'prop_correction':[False, True , True , True , True ], } pdict = { 'scfdma_precode': [False, False, False, True , True ], 'bias_removal': [False, False, True , False, True] } #cdict = { # 'noise_power':[x for x in range(-120,-91,2)] # } #pdict = {} #cdict = { #} #pdict = {} return ctrl, p, cdict, pdict
def dec_regimes(): """Single ZC sequence with Decimation""" p = lib.SyncParams() p.zc_len = 73 p.plen = 61 p.rolloff = 0.2 #p.f_samp = 4e6 #p.f_symb = 1e6 p.f_symb = 30.72e6 p.f_samp = p.f_symb*4 p.repeat = 1 p.spacing_factor = 1 # CHANGE TO TWO! p.power_weight = 2 p.full_sim = True p.bias_removal = True p.ma_window = 1 # number of samples to average in the crosscorr i.e. after analog modulation p.train_type = 'chain' # Type of training sequence p.crosscorr_type = 'match_decimate' p.match_decimate_fct = lib.md_clkphase p.peak_detect = 'wavg' p.pulse_type = 'rootraisedcosine' p.central_padding = 0 # As a fraction of zpos length ctrl = SimControls() ctrl.steps = 40 # Approx number of emissions per node ctrl.basephi = 6000 # How many samples between emission ctrl.display = True # Show stuff in the console ctrl.keep_intermediate_values = False # Needed to draw graphs ctrl.nodecount = 20 # Number of nodes ctrl.static_nodes = 0 ctrl.CFO_step_wait = float('inf') # Use float('inf') to never correct for CFO ctrl.TO_step_wait = 3 ctrl.max_start_delay = 8 # In factor of basephi ctrl.theta_bounds = [0.2,0.8] # In units of phi #ctrl.theta_bounds = [0.48,0.52] # In units of phi #ctrl.theta_bounds = [0.5,0.5] # In units of phi #ctrl.theta_bounds = [0,1] # In units of phi ctrl.deltaf_bound = 3e-2 #ctrl.deltaf_bound = 0 ctrl.rand_init = False ctrl.epsilon_TO = 0.5 ctrl.non_rand_seed = 11231231 # Only used if rand_init is False ctrl.noise_power = float('-inf') #ctrl.noise_power = -101 + 9 # in dbm ctrl.delay_params = lib.DelayParams(lib.delay_pdf_3gpp_exp) ctrl.delay_params.taps = 5 ctrl.max_dist_from_origin = 250 # (in meters) ctrl.delay_params.max_dist_from_origin = 250 # (in meters) ctrl.delay_params.p_sigma = 500 # Paths sigma ctrl.half_duplex = False ctrl.hd_slot0 = 0.3 # in terms of phi ctrl.hd_slot1 = 0.7 # in terms of phi ctrl.hd_block_during_emit = True ctrl.hd_block_extrawidth = 0 # as a factor of offset (see runsim to know what is offset) ctrl.var_winlen = False ctrl.vw_minsize = 5 # as a factor of len(p.analog_sig) ctrl.vw_lothreshold = 0.1 # winlen reduction threshold ctrl.vw_hithreshold = 0.1 # winlen increase threshold ctrl.vw_lofactor = 1.5 # winlen reduction factor ctrl.vw_hifactor = 2 # winlen increase factor ctrl.prop_correction = False ctrl.pc_step_wait = 0 #ctrl.pc_b, ctrl.pc_a = lib.hipass_filter4(11, pi/1000, 0.5) #ctrl.pc_b, ctrl.pc_a = lib.hipass_semicirc_zeros(11, pi/4, 0.1) #ctrl.pc_b, ctrl.pc_a = lib.hipass_filter4(11, pi/4, 1) #ctrl.pc_b, ctrl.pc_a = lib.hipass_remez(20) #ctrl.pc_b, ctrl.pc_a = lib.hipass_butter(8) #ctrl.pc_b, ctrl.pc_a = lib.hipass_cheby(8) ctrl.pc_b, ctrl.pc_a = lib.hipass_avg(10) ctrl.pc_avg_thresh = float('inf') # If std of N previous TOx samples is above this value, then\ ctrl.pc_std_thresh = float(30) # If std of N previous TOx samples is above this value, then\ # no PC is applied (but TOy is still calculated) ctrl.saveall = True cdict = { 'nodecount':[x for x in range(10,61,1)] #'nodecou } pdict = {} #pdict = {'match_decimate_fct':[lib.md_clkphase, lib.md_energy]} return ctrl, p, cdict, pdict
def highlited_regimes(): """Highlights the converging vs the drift regime""" compare_fontsize = 15 compare_aspect=12 props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) fontsize_tmp = graphs.FONTSIZE def run_hair_graph(aspect='auto'): hair_kwargs = {'y_label':r'$\theta_i$ $(T_0)$', 'show_clusters':False, 'savename':''} hair_args = ( (ctrl.sample_inter , ctrl.theta_inter, ctrl), hair_kwargs, ) ax = graphs.hair(*hair_args[0], **hair_args[1]) ax.set_aspect(aspect) return ax # DRIFT REGIME graphs.change_fontsize(compare_fontsize) ctrl, p, cdict, pdict = dec_sample_theta() sim = SimWrap(ctrl, p, cdict, pdict) sim.conv_min_slope_samples = 15 sim.ctrl.keep_intermediate_values = True sim.simulate() ax = run_hair_graph(aspect=compare_aspect) ax.text(0.85, 0.9, 'No DC', transform=ax.transAxes, fontsize=compare_fontsize, verticalalignment='top', bbox=props) xmid = 12 xmax = ctrl.steps-13 xmin = 0 ymin, ymax = ax.get_ylim() ya = ymin-0.06 ax.set_xlim([xmin,xmax]) ax.set_ylim([ya,ymax]) fname = 'latex_figures/init_theta' graphs.save(fname) graphs.show() del ax graphs.change_fontsize(15) ax = run_hair_graph() # Draw biarrows ax.annotate('', xy=(xmid, ya), xycoords='data', xytext=(xmin, ya), textcoords='data', arrowprops=dict(arrowstyle="<->")) ax.annotate('', xy=(xmax, ya), xycoords='data', xytext=(xmid, ya), textcoords='data', arrowprops=dict(arrowstyle="<->")) ax.plot([xmid, xmid], [ya-1, ymax], 'k--') # text ax.text(xmid/2, ya, 'Transient', ha='center', va='bottom' ) ax.text((xmax-xmid)/2 +xmid, ya, 'Drifting', ha='center', va='bottom' ) ax.set_xlim([xmin,xmax]) ax.set_ylim([ya-0.03,ymax]) fname = 'latex_figures/highlighted_regimes' graphs.save(fname) graphs.show() # THETA EXAMPLE graphs.change_fontsize(compare_fontsize) ctrl, p, cdict, pdict = dec_sample_theta() ctrl.prop_correction = True sim = SimWrap(ctrl, p, cdict, pdict) sim.conv_min_slope_samples = 15 sim.ctrl.keep_intermediate_values = True sim.show_CFO = False sim.show_TO = False sim.make_cat = False sim.simulate() ax = run_hair_graph(aspect=compare_aspect) ax.text(0.85, 0.9, 'Q = 7', transform=ax.transAxes, fontsize=compare_fontsize, verticalalignment='top', bbox=props) ax.set_xlim([xmin,xmax]) ax.set_ylim([ya,ymax]) fname = 'latex_figures/example_theta' graphs.save(fname) graphs.show() # THETA EXAMPLE with Q=14 graphs.change_fontsize(compare_fontsize) ctrl, p, cdict, pdict = dec_sample_theta() ctrl.prop_correction = True ctrl.pc_b, ctrl.pc_a = lib.hipass_avg(14) sim = SimWrap(ctrl, p, cdict, pdict) sim.conv_min_slope_samples = 15 sim.ctrl.keep_intermediate_values = True sim.show_CFO = False sim.show_TO = False sim.make_cat = False sim.simulate() ax = run_hair_graph(aspect=compare_aspect) ax.text(0.85, 0.9, 'Q = 14', transform=ax.transAxes, fontsize=compare_fontsize, verticalalignment='top', bbox=props) ax.set_xlim([xmin,xmax]) ax.set_ylim([ya,ymax]) fname = 'latex_figures/example_theta_q14' graphs.save(fname) graphs.show() graphs.change_fontsize(fontsize_tmp)
def dec_r12(): """Single ZC sequence with Decimation""" p = lib.SyncParams() p.zc_len = 31 p.plen = 31 p.rolloff = 0.2 p.f_symb = 30.72e6 p.f_samp = p.f_symb*4 p.repeat = 1 p.spacing_factor = 1 p.power_weight = 2 p.full_sim = True p.bias_removal = False p.ma_window = 1 # number of samples to average in the crosscorr i.e. after analog modulation p.train_type = 'single' # Type of training sequence p.crosscorr_type = 'match_decimate' p.match_decimate_fct = lib.downsample p.peak_detect = 'argmax' p.pulse_type = 'rootraisedcosine' p.central_padding = 0 # As a fraction of zpos length p.scfdma_precode = False p.scfdma_L = 4 p.scfdma_sinc_len_factor = p.scfdma_L ctrl = SimControls() ctrl.steps = 20 ctrl.basephi = 6000 #Thesis #ctrl.basephi = 122880 #Interd ctrl.nodecount = 15 ctrl.display = True ctrl.static_nodes = 2 ctrl.quiet_nodes = 0 #ctrl.quiet_selection = 'kmeans' ctrl.quiet_selection = 'random' #ctrl.quiet_selection = 'contention' # Note this renders ctrl.quiet_nodes uiseless, and requires the use of outage detectection ctrl.qc_threshold = 5 # As a factor of the outage threshold ctrl.qc_steps = 3 ctrl.CFO_step_wait = float('inf') # Use float('inf') to never correct for CFO ctrl.TO_step_wait = ctrl.steps*2 ctrl.max_start_delay = 7 # In factor of basephi ctrl.use_ringarr = True ctrl.theta_bounds = [0,1] # In units of phi ctrl.deltaf_bound = 3e-2 #ctrl.deltaf_bound = 0 ctrl.rand_init = False ctrl.epsilon_TO = 1 #ctrl.non_rand_seed = 2810438 # Only used if rand_init is False ctrl.non_rand_seed = 12819 # Only used if rand_init is False #ctrl.noise_power = float('-inf') ctrl.noise_power = -101 + 9 # in dbm ctrl.delay_params = lib.DelayParams(lib.delay_pdf_3gpp_exp) ctrl.delay_params.taps = 5 #ctrl.delay_params.shadowing_fct = lambda : 0 ctrl.max_dist_from_origin = 500 # (in meters) #ctrl.max_dist_from_origin = 1000 # (in meters) #ctrl.max_dist_from_origin = 1000 # (in meters) #ctrl.max_dist_from_origin = 2000 # (in meters) ctrl.half_duplex = False ctrl.hd_slot0 = 0.3 # in terms of phi ctrl.hd_slot1 = 0.7 # in terms of phi ctrl.hd_block_during_emit = True ctrl.hd_block_extrawidth = 0 # as a factor of offset (see runsim to know what is offset) ctrl.var_winlen = False ctrl.vw_minsize = 5 # as a factor of len(p.analog_sig) ctrl.vw_lothreshold = 0.1 # winlen reduction threshold ctrl.vw_hithreshold = 0.1 # winlen increase threshold ctrl.vw_lofactor = 1.5 # winlen reduction factor ctrl.vw_hifactor = 2 # winlen increase factor #ctrl.outage_detect = False # thesis ctrl.outage_detect = True # INTERD ctrl.outage_threshold_noisefactor = 1/(p.zc_len)*2 ctrl.prop_correction = False ctrl.pc_step_wait = 0 ctrl.pc_b, ctrl.pc_a = lib.hipass_avg(6) #THESIS #ctrl.pc_b, ctrl.pc_a = lib.hipass_avg(10) #INTERD ctrl.pc_avg_thresh = float('inf') # If std of N previous TOx samples is above this value, then\ ctrl.pc_std_thresh = float(80) # If std of N previous TOx samples is above this value, then\ # no PC is applied (but TOy is still calculated) ctrl.saveall = True cdict = {} pdict = {} return ctrl, p, cdict, pdict
def dec_sample_theta(): p = lib.SyncParams() p.zc_len = 32 p.plen = 31 p.rolloff = 0.2 p.f_symb = 30.72e6 p.f_samp = p.f_symb*4 p.repeat = 1 p.spacing_factor = 1 p.power_weight = 2 p.full_sim = True p.bias_removal = False p.ma_window = 1 # number of samples to average in the crosscorr i.e. after analog modulation p.train_type = 'single' # Type of training sequence p.crosscorr_type = 'match_decimate' p.match_decimate_fct = lib.downsample p.peak_detect = 'wavg' p.pulse_type = 'rootraisedcosine' p.central_padding = 0 # As a fraction of zpos length p.scfdma_precode = True p.scfdma_L = 8 p.scfdma_M = p.zc_len*p.scfdma_L p.scfdma_sinc_len_factor = p.scfdma_L ctrl = SimControls() ctrl.steps = 40 # Approx number of emissions per node ctrl.basephi = 6000 # How many samples between emission ctrl.display = True # Show stuff in the console ctrl.keep_intermediate_values = False # Needed to draw graphs ctrl.nodecount = 15 # Number of nodes ctrl.static_nodes = 0 ctrl.CFO_step_wait = float('inf') # Use float('inf') to never correct for CFO ctrl.TO_step_wait = 5 ctrl.max_start_delay = 10 # In factor of basephi #ctrl.theta_bounds = [0.3,0.7] # In units of phi #ctrl.theta_bounds = [0.48,0.52] # In units of phi #ctrl.theta_bounds = [0.5,0.5] # In units of phi #ctrl.theta_bounds = [0,1] # In units of phi ctrl.theta_bounds = [0,0.6] # In units of phi ctrl.deltaf_bound = 3e-2 #ctrl.deltaf_bound = 0 ctrl.rand_init = False ctrl.epsilon_TO = 0.5 #seed = int(np.random.rand()*1e8); print(seed) seed = 2596829 ctrl.non_rand_seed = seed # Only used if rand_init is False #ctrl.non_rand_seed = 57276545 # Only used if rand_init is False #ctrl.noise_power = float('-inf') ctrl.noise_power = -101 + 9 # in dbm ctrl.delay_params = lib.DelayParams(lib.delay_pdf_3gpp_exp) ctrl.delay_params.taps = 5 ctrl.max_dist_from_origin = 250 # (in meters) ctrl.delay_params.max_dist_from_origin = 250 # (in meters) ctrl.half_duplex = False ctrl.hd_slot0 = 0.3 # in terms of phi ctrl.hd_slot1 = 0.7 # in terms of phi ctrl.hd_block_during_emit = True ctrl.hd_block_extrawidth = 0 # as a factor of offset (see runsim to know what is offset) ctrl.var_winlen = False ctrl.vw_minsize = 5 # as a factor of len(p.analog_sig) ctrl.vw_lothreshold = 0.1 # winlen reduction threshold ctrl.vw_hithreshold = 0.1 # winlen increase threshold ctrl.vw_lofactor = 1.5 # winlen reduction factor ctrl.vw_hifactor = 2 # winlen increase factor ctrl.prop_correction = False ctrl.pc_step_wait = 0 ctrl.pc_b, ctrl.pc_a = lib.hipass_avg(7) ctrl.pc_avg_thresh = float('inf') # If std of N previous TOx samples is above this value, then\ ctrl.pc_std_thresh = float(80) # If std of N previous TOx samples is above this value, then\ # no PC is applied (but TOy is still calculated) ctrl.saveall = True cdict = {'rand_init':[True]} #cdict = { # 'nodecount':[x for x in range(ncount_lo, ncount_hi,step)]*3 # } pdict = {} #pdict = {'match_decimate_fct':[lib.md_clkphase]*ntot+[lib.md_energy]*ntot+[lib.md_static]*ntot} return ctrl, p, cdict, pdict
def __init__(self): """Default values. See wrapper.dec_wrap2 for a description of the parameters""" self.use_ringarr = False self.steps = 30 self.nodecount = 7 self.basephi = 2000 self.chansize = self.basephi*self.steps self.trans_power = 23 # in dbm self.noise_power = -101 + 9 # in dbm self.phi_bounds = [1,1] self.theta_bounds = [0,1] self.max_start_delay = 0 # In factor of basephi self.min_back_adjust = 0.1 # In terms of phi self.self_emit = False # IF set to False, the self-emit will just be skipped. self.CFO_step_wait = 60 self.TO_step_wait = 1 self.rand_init = False self.display = True # Display progress of runsim self.keep_intermediate_values = True self.delay_fct = lib.delay_pdf_static self.deltaf_bound = 0.02 # in units of f_samp self.bmap_reach = 3e-1 self.bmap_scaling = 100 self.non_rand_seed = 1231231 self.f_carr = 2e9 # Carrier frequency in Hz # Node behaviours self.static_nodes = 0 # Static nodes do not adjust (but they emit) self.quiet_nodes = 0 # quiet nodes do not emit (but they adjust) self.quiet_selection = 'random' # Echo controls, initialized with no echoes self.delay_params = lib.DelayParams(lib.delay_pdf_exp) self.pdf_kwargs = dict() # Correction controls self.epsilon_TO = 0.5 self.epsilon_CFO = 0.25 self.max_CFO_correction = 0.02 # As a factor of f_symb self.CFO_processing_avgtype = 'mov_avg' # 'mov_avg' or 'reg' (non-mov avg) self.CFO_processing_avgwindow = 5 self.cfo_mapper_fct = lib.cfo_mapper_pass self.cfo_bias = 0 # in terms of f_samp self.CFO_step_wait = float('inf') # Half-duplex constraint - all options relevant only if half_duplex is True self.half_duplex = False self.hd_slot0 = 0.3 # in terms of phi self.hd_slot1 = 0.7 # in terms of phi self.hd_block_during_emit = True self.hd_block_extrawidth = 0 # as a factor of offset (see runsim to know what is offset) # Variable adjust window length - all options relevant only if half_duplex is True self.var_winlen = True self.vw_minsize = 2 # as a factor of len(p.analog_sig) self.vw_lothreshold = 0.1 # winlen reduction threshold self.vw_hithreshold = 0.1 # winlen increase threshold self.vw_lofactor = 1.5 # winlen reduction factor self.vw_hifactor = 2 # winlen increase factor # Propagation delay correction self.pc_step_wait = 20 self.pc_b, self.pc_a = lib.hipass_avg(5) self.pc_std_thresh = float('inf') self.pc_avg_thresh = float('inf') # Outage detection self.outage_detect = False self.outage_threshold_noisefactor = 0 # Factor of noise amplitude to threhsold outage # Other self.init_update = True self.saveall = False # This options also saves all fields in SyncParams to the control dict