def __init__(self, constellation, f, N0=0.25, seed=-666L): """ constellation - a constellation object used for modulation. f - a finite state machine specification used for coding. N0 - noise level seed - random seed """ super(trellis_tb, self).__init__() # packet size in bits (make it multiple of 16 so it can be packed in a short) packet_size = 1024 * 16 # bits per FSM input symbol bitspersymbol = int(round(math.log(f.I()) / math.log(2))) # bits per FSM input symbol # packet size in trellis steps K = packet_size / bitspersymbol # TX src = gr.lfsr_32k_source_s() # packet size in shorts src_head = gr.head(gr.sizeof_short, packet_size / 16) # unpack shorts to symbols compatible with the FSM input cardinality s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST) # initial FSM state = 0 enc = trellis.encoder_ss(f, 0) mod = gr.chunks_to_symbols_sc(constellation.points(), 1) # CHANNEL add = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed) # RX # data preprocessing to generate metrics for Viterbi metrics = trellis.constellation_metrics_cf( constellation.base(), digital_swig.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_s(f, K, 0, -1) # pack FSM input symbols to shorts fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # check the output self.dst = gr.check_lfsr_32k_s() self.connect(src, src_head, s2fsmi, enc, mod) self.connect(mod, (add, 0)) self.connect(noise, (add, 1)) self.connect(add, metrics, va, fsmi2s, self.dst)
def __init__(self, constellation, f, N0=0.25, seed=-666L): """ constellation - a constellation object used for modulation. f - a finite state machine specification used for coding. N0 - noise level seed - random seed """ super(trellis_tb, self).__init__() # packet size in bits (make it multiple of 16 so it can be packed in a short) packet_size = 1024*16 # bits per FSM input symbol bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol # packet size in trellis steps K = packet_size/bitspersymbol # TX src = gr.lfsr_32k_source_s() # packet size in shorts src_head = gr.head (gr.sizeof_short, packet_size/16) # unpack shorts to symbols compatible with the FSM input cardinality s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST) # initial FSM state = 0 enc = trellis.encoder_ss(f, 0) mod = gr.chunks_to_symbols_sc(constellation.points(), 1) # CHANNEL add = gr.add_cc() noise = gr.noise_source_c(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed) # RX # data preprocessing to generate metrics for Viterbi metrics = trellis.constellation_metrics_cf(constellation.base(), digital_swig.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set. va = trellis.viterbi_s(f, K, 0, -1) # pack FSM input symbols to shorts fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST) # check the output self.dst = gr.check_lfsr_32k_s() self.connect (src, src_head, s2fsmi, enc, mod) self.connect (mod, (add, 0)) self.connect (noise, (add, 1)) self.connect (add, metrics, va, fsmi2s, self.dst)
def __init__(self, gui, options): gr.hier_block2.__init__(self, "bpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = options.sps self.amplitude = options.amplitude self.verbose = options.verbose self._excess_bw = _def_excess_bw self._gray_code = _def_gray_code if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: raise TypeError, ("sample per symbol must be an integer >= 2, is %d" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) # turn bytes into k-bit vectors self.packed_to_unpacked_bb = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: self.symbol_mapper = gr.map_bb(psk.binary_to_gray[arity]) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diff_encoder_bb = gr.diff_encoder_bb(arity) #This bloc allow to decode the stream #self.scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) #Transform symbols to chips self.symbols_to_chips = ieee.symbols_to_chips_bs() #self.chunks2symbols = gr.chunks_to_symbols_ic(psk.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_sc([-1+0j, 1+0j]) self.chunks2symbols_b = gr.chunks_to_symbols_bc([-1+0j, 1+0j]) # transform chips to symbols print "bits_per_symbol", self.bits_per_symbol() self.packed_to_unpacked_ss = \ gr.packed_to_unpacked_ss(self.bits_per_symbol(), gr.GR_MSB_FIRST) ntaps = 11 * self._samples_per_symbol # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol * self.amplitude, # gain (samples_per_symbol since we're # interpolating by samples_per_symbol) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) # Connect #self.connect(self, self.bytes2chunks, self.symbol_mapper,self.scrambler, self.chunks2symbols, self.rrc_filter, self) # self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c( # gui.GetWin(), # title="Constellation Plot", # sample_rate=self._samples_per_symbol, # frame_rate=5, # const_size=2048, # M=2, # theta=0, # alpha=0.005, # fmax=0.06, # mu=0.5, # gain_mu=0.005, # symbol_rate=self._samples_per_symbol/2, # omega_limit=0.005, # ) # gui.Add(self.wxgui_constellationsink2_0.win) #Modefied for IEEE 802.15.4 #self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.diff_encoder_bb, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self._scrambler, self.chunks2symbols_b, self.rrc_filter, self) #self.connect(self.rrc_filter, self.wxgui_constellationsink2_0) if self.verbose: self._print_verbage()
def __init__(self, principal_gui, options): gr.hier_block2.__init__(self, "bpsk_mod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._samples_per_symbol = options.sps self.amplitude = options.amplitude self.verbose = options.verbose self._excess_bw = _def_excess_bw self._gray_code = _def_gray_code if not isinstance(self._samples_per_symbol, int) or self._samples_per_symbol < 2: raise TypeError, ("sample per symbol must be an integer >= 2, is %d" % self._samples_per_symbol) arity = pow(2,self.bits_per_symbol()) #arity = pow (2, 2) # turn bytes into k-bit vectors self.packed_to_unpacked_bb = \ gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST) if self._gray_code: map_param = psk.binary_to_gray[arity] self.symbol_mapper = gr.map_bb(map_param) else: self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity]) self.diff_encoder_bb = gr.diff_encoder_bb(arity) #This bloc allow to decode the stream #self.scrambler = gr.scrambler_bb(0x8A, 0x7F, 7) #Transform symbols to chips self.symbols_to_chips = ieee.symbols_to_chips_bs() #self.chunks2symbols = gr.chunks_to_symbols_ic(psk.constellation[arity]) self.chunks2symbols = gr.chunks_to_symbols_sc([-1+0j, 1+0j]) self.chunks2symbols_b = gr.chunks_to_symbols_bc([-1+0j, 1+0j]) # transform chips to symbols print "bits_per_symbol", self.bits_per_symbol() self.packed_to_unpacked_ss = \ gr.packed_to_unpacked_ss(self.bits_per_symbol(), gr.GR_MSB_FIRST) ntaps = 11 * self._samples_per_symbol # pulse shaping filter self.rrc_taps = gr.firdes.root_raised_cosine( self._samples_per_symbol, # gain (samples_per_symbol since we're # interpolating by samples_per_symbol) self._samples_per_symbol, # sampling rate 1.0, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) self.rrc_filter = gr.interp_fir_filter_ccf(self._samples_per_symbol, self.rrc_taps) # Connect #self.connect(self, self.bytes2chunks, self.symbol_mapper,self.scrambler, self.chunks2symbols, self.rrc_filter, self) #Modefied for IEEE 802.15.4 #self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.diff_encoder_bb, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #For IEEE 802.15.4 915 868 MHz standard self.connect(self, self.packed_to_unpacked_bb, self.symbol_mapper, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.symbols_to_chips, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #self.connect(self, self.packed_to_unpacked_ss, self.chunks2symbols, self.rrc_filter, self) #case when we use a stream of bits #self.connect(self, self.chunks2symbols_b, self.rrc_filter, self) if self.verbose: self._print_verbage()