def __init__(self, vlen_in=1, vlen_out=1, n_tailbits=1, denom_mother_code_rate=1, gen_poly=0, bits_per_symbol=1, map_tab=0, pp_0=0, interl_seq_0_2=(0,1), interl_seq_1_2=(0,1), pp_1_tail=0, pp_1=0, pp_0_tail=0, M_total=0, part_len_top=3, part_len_bot=3): gr.hier_block2.__init__( self, "MLC 16QAM", gr.io_signature(1, 1, gr.sizeof_char*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.vlen_in = vlen_in self.vlen_out = vlen_out self.n_tailbits = n_tailbits self.denom_mother_code_rate = denom_mother_code_rate self.gen_poly = gen_poly self.bits_per_symbol = bits_per_symbol self.map_tab = map_tab self.pp_0 = pp_0 self.interl_seq_0_2 = interl_seq_0_2 self.interl_seq_1_2 = interl_seq_1_2 self.pp_1_tail = pp_1_tail self.pp_1 = pp_1 self.pp_0_tail = pp_0_tail self.M_total = M_total self.part_len_top = part_len_top self.part_len_bot = part_len_bot ################################################## # Blocks ################################################## self.trellis_encoder_xx_top = trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0, 0) if False else trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0) self.trellis_encoder_xx_bot = trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0, 0) if False else trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0) self.drm_qam_map_bc_0 = drm.qam_map_bc(map_tab, bits_per_symbol, vlen_out, 2) self.drm_punct_bb_top = drm.punct_bb(pp_0, pp_0_tail, (part_len_top + n_tailbits) * denom_mother_code_rate, vlen_out * 2, n_tailbits * denom_mother_code_rate) self.drm_punct_bb_bot = drm.punct_bb(pp_1, pp_1_tail, (part_len_bot + n_tailbits) * denom_mother_code_rate, vlen_out * 2, n_tailbits * denom_mother_code_rate) self.drm_partitioning_16_bb_0 = drm.partitioning_bb(vlen_in, M_total) self.drm_interleaver_bb_top = drm.interleaver_bb((interl_seq_0_2)) self.drm_interleaver_bb_bot = drm.interleaver_bb((interl_seq_1_2)) self.drm_add_tailbits_bb_top = drm.add_tailbits_bb(part_len_top, n_tailbits) self.drm_add_tailbits_bb_bot = drm.add_tailbits_bb(part_len_bot, n_tailbits) self.blocks_unpack_k_bits_bb_top = blocks.unpack_k_bits_bb(denom_mother_code_rate) self.blocks_unpack_k_bits_bb_bot = blocks.unpack_k_bits_bb(denom_mother_code_rate) ################################################## # Connections ################################################## self.connect((self.blocks_unpack_k_bits_bb_bot, 0), (self.drm_punct_bb_bot, 0)) self.connect((self.blocks_unpack_k_bits_bb_top, 0), (self.drm_punct_bb_top, 0)) self.connect((self.drm_add_tailbits_bb_bot, 0), (self.trellis_encoder_xx_bot, 0)) self.connect((self.drm_add_tailbits_bb_top, 0), (self.trellis_encoder_xx_top, 0)) self.connect((self.drm_interleaver_bb_bot, 0), (self.drm_qam_map_bc_0, 1)) self.connect((self.drm_interleaver_bb_top, 0), (self.drm_qam_map_bc_0, 0)) self.connect((self.drm_partitioning_16_bb_0, 1), (self.drm_add_tailbits_bb_bot, 0)) self.connect((self.drm_partitioning_16_bb_0, 0), (self.drm_add_tailbits_bb_top, 0)) self.connect((self.drm_punct_bb_bot, 0), (self.drm_interleaver_bb_bot, 0)) self.connect((self.drm_punct_bb_top, 0), (self.drm_interleaver_bb_top, 0)) self.connect((self.drm_qam_map_bc_0, 0), (self, 0)) self.connect((self, 0), (self.drm_partitioning_16_bb_0, 0)) self.connect((self.trellis_encoder_xx_bot, 0), (self.blocks_unpack_k_bits_bb_bot, 0)) self.connect((self.trellis_encoder_xx_top, 0), (self.blocks_unpack_k_bits_bb_top, 0))
def test_001_t(self): """test_001_t: modulator check""" param = namedtuple('param', 'data_src bit_rate samp_rate') tb = self.tb param.bit_rate = 1000 param.samp_rate = 2000 param.data_src = (0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1) print_parameters(param) encoder_variable = fec.cc_encoder_make(1, 7, 2, ([79, -109]), 0, fec.CC_STREAMING, False) srcdir = os.environ['srcdir'] src = blocks.file_source( gr.sizeof_char * 1, os.path.join(srcdir, "test_files", "CADU_incl_ASM.bin"), False) src_expected = blocks.file_source( gr.sizeof_char * 1, os.path.join(srcdir, "test_files", "Convolutionally_encoded_CADU.bin"), False) pack1 = blocks.unpack_k_bits_bb(8) pack2 = blocks.unpack_k_bits_bb(8) dst = blocks.vector_sink_b() dst_expected = blocks.vector_sink_b() head = blocks.head(gr.sizeof_char, 2040) conv = fec.extended_encoder(encoder_obj_list=encoder_variable, threading='capillary', puncpat='11') # conv = fec.encoder(encoder_variable, gr.sizeof_char, gr.sizeof_char) tb.connect(src, pack1) tb.connect(pack1, conv) tb.connect(conv, dst) tb.connect(src_expected, pack2) tb.connect(pack2, dst_expected) self.tb.run() data_out = dst.data() expected_data = dst_expected.data() print(len(data_out)) self.assertFloatTuplesAlmostEqual(data_out, expected_data)
def test_003(self): #Tags on the incoming bytes src_data = [2, 3, 0, 1] src_tag_offsets = [0, 1, 1, 2, 3] #Ground Truth expected_data = [1, 0, 1, 1, 0, 0, 0, 1] expected_tag_offsets = [0, 2, 2, 4, 6] test_tags = list() tag_indexs = range(len(src_tag_offsets)) for src_tag in tag_indexs: test_tags.append( gr.tag_utils.python_to_tag( (src_tag_offsets[src_tag], pmt.intern('tag_byte'), pmt.from_long(src_tag), None))) src = blocks.vector_source_b(src_data, False, 1, test_tags) op = blocks.unpack_k_bits_bb(2) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() # Check the data self.assertEqual(expected_data, dst.data()) # Check the tag values self.assertEqual(list(tag_indexs), [pmt.to_python(x.value) for x in dst.tags()]) # Check the tag offsets self.assertEqual(expected_tag_offsets, [x.offset for x in dst.tags()])
def __init__(self): gr.top_block.__init__(self, "Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.delay = delay = 0 ################################################## # Blocks ################################################## self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate * 20,True) self.blocks_pack_k_bits_bb_1 = blocks.pack_k_bits_bb(8) self.blocks_head_1 = blocks.head(gr.sizeof_char*1, int(7 * 200e3 * 15/15)) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, '/home/rcampello/Main/FixedPath/OOT Gnuradio/gr-ITpp/examples/BPSK Ladams/27-06-2019 (BER Sem Diff)/Com C\xc3\xb3digo/output2.data', True) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, '/home/rcampello/Main/FixedPath/OOT Gnuradio/gr-ITpp/examples/BPSK Ladams/27-06-2019 (BER Sem Diff)/Com C\xc3\xb3digo/output3.data', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_0 = blocks.delay(gr.sizeof_char*1, int(delay)) self.ITpp_BCH_Decoder_0 = ITpp.BCH_Decoder(15, 2) ################################################## # Connections ################################################## self.connect((self.ITpp_BCH_Decoder_0, 0), (self.blocks_pack_k_bits_bb_1, 0)) self.connect((self.blocks_delay_0, 0), (self.ITpp_BCH_Decoder_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_head_1, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_pack_k_bits_bb_1, 0), (self.blocks_head_1, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_delay_0, 0))
def test_001_t (self): raw_data = (0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0); encoded = (28,28,28,228,228,28,28,228,28,228,228,28,28,228,28,28,28,228,228,28,28,228,28,28,28,228,228,228,228,28,228,228,28,228,28,228,228,228,228,28,228,228,28,28,228,28,28,28,228,28,28,28,228,28,28,28,228,228,228,28,228,228,28,28,228,28,28,28,228,28,28,228,28,228,228,28,28,228,28,28,28,28,28,228,228,28,28,228,28,28,28,28,28,28,28,28,28,228,228,28,28,228,28,228,228,228,228,28,228,228,28,28,228,228,228,28,228,228,28,28,228,28,28,28,228,28,28,228,28,228,228,228,228,228,28,228,28,28,28,228,228,228,228,228,28,28,228,228,228,228,28,28,228,228,228,228,28,228,28,28,28,228,228,228,228,228,28,28,228,228,228,28,228,28,228,228,28,28,228,228,228,228,28,28,228,28,28,28,228,228,228,228,28,28,228,228,228,228,28,28,228,28,28,28,228,28,28,228,28,228,228,228,228,228,28,28,228,228,228,228,28,228,28,228,228,228,228,28,228,228,28,228,28,28,28,28,28,28,28,28,28,228,228,28,28,228,28,228,228,28,28,228,28,228,228,28,28,228,28,228,228,28,28,28,228,28,28,28,228,28,28,228,28,28,28,228,228,28,28,28,228,28,28,28,228,28,28,228,28,28,28,228,228,28,28,28,228,28,28,28,228,28,28,228,28,28,28,228,228,28,28,228,28,28,28,228,228,228,228,228,28,28,228,228,228,228,28,228,28,28,28,228,228,228,228,28,228,228,28,228,28,228,228,28,28,28,228,228,228,28,228,28,228,228,28,28,228,28,28,228,28,228,228,228,228,28,228,28,228,28,228,28,228,28,228,228,28,228,28,228,228,228,228,28,228,228,28,28,228,228,228,28,228,228,28,228,28,228,228,28,28,28,228,28,28,228,28,28,28,28,28,28,28,28,28,28); sz = len(encoded) #print (sz) self.blocks_vector_source = blocks.vector_source_b(encoded, False, 1, tagged_streams.make_lengthtags((sz,), (0,), "packet_len")); self.decoder = ieee802_15_4a.viterbi (0, 100, 5, 4); self.blocks_unpacket_bits = blocks.unpack_k_bits_bb(8); self.sink = blocks.vector_sink_b(1) self.sink_outfile = blocks.file_sink (1, "output_out_viterbi.txt") self.tb.connect (self.blocks_vector_source, self.decoder) self.tb.connect (self.decoder, self.blocks_unpacket_bits) self.tb.connect (self.blocks_unpacket_bits, self.sink) #self.tb.connect (self.blocks_vector_source, self.blocks_unpacket_bits) #self.tb.connect (self.decoder, self.sink) self.tb.connect (self.blocks_unpacket_bits, self.sink_outfile) # set up fg self.tb.run () # check data decoded_data = self.sink.data() #print (len(raw_data)) #print (len(decoded_data)) # check data self.assertEqual(raw_data, decoded_data)
def __init__(self, constellation, differential, rotation): if constellation.arity() > 256: # If this becomes limiting some of the blocks should be generalised so # that they can work with shorts and ints as well as chars. raise ValueError("Constellation cannot contain more than 256 points.") gr.hier_block2.__init__( self, "mod_demod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_char), ) # Output signature arity = constellation.arity() # TX self.constellation = constellation self.differential = differential import weakref self.blocks = [weakref.proxy(self)] # We expect a stream of unpacked bits. # First step is to pack them. self.blocks.append(blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)) # Second step we unpack them such that we have k bits in each byte where # each constellation symbol hold k bits. self.blocks.append(blocks.packed_to_unpacked_bb(self.constellation.bits_per_symbol(), gr.GR_MSB_FIRST)) # Apply any pre-differential coding # Gray-coding is done here if we're also using differential coding. if self.constellation.apply_pre_diff_code(): self.blocks.append(digital.map_bb(self.constellation.pre_diff_code())) # Differential encoding. if self.differential: self.blocks.append(digital.diff_encoder_bb(arity)) # Convert to constellation symbols. self.blocks.append( digital.chunks_to_symbols_bc(self.constellation.points(), self.constellation.dimensionality()) ) # CHANNEL # Channel just consists of a rotation to check differential coding. if rotation is not None: self.blocks.append(blocks.multiply_const_cc(rotation)) # RX # Convert the constellation symbols back to binary values. self.blocks.append(digital.constellation_decoder_cb(self.constellation.base())) # Differential decoding. if self.differential: self.blocks.append(digital.diff_decoder_bb(arity)) # Decode any pre-differential coding. if self.constellation.apply_pre_diff_code(): self.blocks.append(digital.map_bb(mod_codes.invert_code(self.constellation.pre_diff_code()))) # unpack the k bit vector into a stream of bits self.blocks.append(blocks.unpack_k_bits_bb(self.constellation.bits_per_symbol())) # connect to block output check_index = len(self.blocks) self.blocks = self.blocks[:check_index] self.blocks.append(weakref.proxy(self)) self.connect(*self.blocks)
def __init__(self): gr.top_block.__init__(self, "Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.blocks_vector_source_x_0 = blocks.vector_source_b((225, 67, 255), True, 1, []) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char * 1) self.blocks_head_0 = blocks.head(gr.sizeof_char * 1, 1500000) ################################################## # Connections ################################################## self.connect((self.blocks_head_0, 0), (self.blocks_null_sink_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_throttle_0, 0))
def __init__(self, delay): gr.top_block.__init__(self, "Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.delay = delay = delay ################################################## # Blocks ################################################## self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate * 20,True) self.blocks_pack_k_bits_bb_1 = blocks.pack_k_bits_bb(8) self.blocks_head_1 = blocks.head(gr.sizeof_char*1, 393460) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, '/home/rcampello/Main/FixedPath/OOT Gnuradio/gr-ITpp/examples/Simula\xc3\xa7\xc3\xa3o BPSK/Transmiss\xc3\xa3o RedDot Usando ConstellationMod/output.data', True) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, '/home/rcampello/Main/FixedPath/OOT Gnuradio/gr-ITpp/examples/Simula\xc3\xa7\xc3\xa3o BPSK/Transmiss\xc3\xa3o RedDot Usando ConstellationMod/output2.data', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_0 = blocks.delay(gr.sizeof_char*1, int(delay)) self.ITpp_BCH_Decoder_0 = ITpp.BCH_Decoder(15, 2) ################################################## # Connections ################################################## self.connect((self.ITpp_BCH_Decoder_0, 0), (self.blocks_pack_k_bits_bb_1, 0)) self.connect((self.blocks_delay_0, 0), (self.ITpp_BCH_Decoder_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_head_1, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_pack_k_bits_bb_1, 0), (self.blocks_head_1, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_delay_0, 0))
def __init__(self, data_size, enc, dec, threading): gr.top_block.__init__(self, "_qa_helper") self.puncpat = puncpat = '11' self.enc = enc self.dec = dec self.data_size = data_size self.threading = threading self.ext_encoder = extended_encoder(enc, threading=self.threading, puncpat=self.puncpat) self.ext_decoder= extended_decoder(dec, threading=self.threading, ann=None, puncpat=self.puncpat, integration_period=10000) self.src = blocks.vector_source_b(data_size*[0, 1, 2, 3, 5, 7, 9, 13, 15, 25, 31, 45, 63, 95, 127], False) self.unpack = blocks.unpack_k_bits_bb(8) self.map = map_bb([-1, 1]) self.to_float = blocks.char_to_float(1) self.snk_input = blocks.vector_sink_b() self.snk_output = blocks.vector_sink_b() self.connect(self.src, self.unpack, self.ext_encoder) self.connect(self.ext_encoder, self.map, self.to_float) self.connect(self.to_float, self.ext_decoder) self.connect(self.unpack, self.snk_input) self.connect(self.ext_decoder, self.snk_output)
def __init__(self, n_bits=1000, bits_per_symbol=3): gr.hier_block2.__init__( self, "Custom Ber", gr.io_signaturev(2, 2, [gr.sizeof_char*1, gr.sizeof_char*1]), gr.io_signature(1, 1, gr.sizeof_float*1), ) ################################################## # Parameters ################################################## self.n_bits = n_bits self.bits_per_symbol = bits_per_symbol ################################################## # Variables ################################################## self.samp_rate = samp_rate = 8e6 ################################################## # Blocks ################################################## self.blocks_xor_xx_0 = blocks.xor_bb() self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_symbol) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_moving_average_xx_0 = blocks.moving_average_ff(n_bits, 1/float(n_bits), n_bits*4) ################################################## # Connections ################################################## self.connect((self.blocks_moving_average_xx_0, 0), (self, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_xor_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self, 1), (self.blocks_xor_xx_0, 1)) self.connect((self, 0), (self.blocks_xor_xx_0, 0))
def __init__(self, source_array): gr.top_block.__init__(self, "Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.source_tuple = source_array ################################################## # Blocks ################################################## self.blocks_vector_source_x_0 = blocks.vector_source_b( self.source_tuple, True, 1, []) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) # self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) # self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_head_0 = blocks.head(gr.sizeof_char * 1, 8 * 3) self.sink = blocks.vector_sink_b() ################################################## # Connections ################################################## self.connect((self.blocks_head_0, 0), (self.sink, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) # self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_throttle_0, 0))
def __init__(self, data_size, enc, dec, threading): gr.top_block.__init__(self, "_qa_helper") self.puncpat = puncpat = '11' self.enc = enc self.dec = dec self.data_size = data_size self.threading = threading self.ext_encoder = extended_encoder(enc, threading=self.threading, puncpat=self.puncpat) self.ext_decoder = extended_decoder(dec, threading=self.threading, ann=None, puncpat=self.puncpat, integration_period=10000) self.src = blocks.vector_source_b( data_size * [0, 1, 2, 3, 5, 7, 9, 13, 15, 25, 31, 45, 63, 95, 127], False) self.unpack = blocks.unpack_k_bits_bb(8) self.map = map_bb([-1, 1]) self.to_float = blocks.char_to_float(1) self.snk_input = blocks.vector_sink_b() self.snk_output = blocks.vector_sink_b() self.connect(self.src, self.unpack, self.ext_encoder) self.connect(self.ext_encoder, self.map, self.to_float) self.connect(self.to_float, self.ext_decoder) self.connect(self.unpack, self.snk_input) self.connect(self.ext_decoder, self.snk_output)
def test_003_asm_mask (self): # asm with errors asm = (0x1f, 0xcf, 0xf0, 0x1d) frame_len = 223 random_data = tuple(random.randint(0, 255) for _ in range(frame_len)) data_in = asm + random_data src = blocks.vector_source_b(data_in, repeat=True) unpack = blocks.unpack_k_bits_bb(8) mapper = digital.map_bb((1,0)) # mask to ignore errors corr = ccsds.correlator(0x1acffc1d, 0xf0fff0ff, 0, frame_len) dbg = blocks.message_debug() self.tb.connect(src, unpack, mapper, corr) self.tb.msg_connect((corr, 'out'), (dbg, 'store')) self.tb.start() while dbg.num_messages() < 1: time.sleep(0.001) self.tb.stop() self.tb.wait() msg = dbg.get_message(0) data_out = tuple(pmt.to_python(pmt.cdr(msg))) assert frame_len == len(data_out) assert random_data == data_out
def setup_bpsk0(self): self.tb = gr.top_block() # Build the constellation object arity = 2 bps = 1 pts, code = digital.psk_2_0x0() constellation = digital.constellation_psk(pts, code, 2) # Create BPSK data to pass to the demodulator src = blocks.vector_source_b(self.src_data_bpsk) p2u = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) mod = digital.generic_mod(constellation, True, self.sps, True, self.eb) snk = blocks.vector_sink_c() tb = gr.top_block() tb.connect(src, p2u, mod, snk) tb.run() self.src = blocks.vector_source_c(snk.data()) self.freq_recov = digital.fll_band_edge_cc(self.sps, self.eb, self.fll_ntaps, self.freq_bw) self.time_recov = digital.pfb_clock_sync_ccf(self.sps, self.timing_bw, self.taps, self.nfilts, self.nfilts//2, self.timing_max_dev) self.receiver = digital.constellation_receiver_cb( constellation.base(), self.phase_bw, self.fmin, self.fmax) self.diffdec = digital.diff_decoder_bb(arity) self.symbol_mapper = digital.map_bb( mod_codes.invert_code(constellation.pre_diff_code())) self.unpack = blocks.unpack_k_bits_bb(bps) self.snk = blocks.null_sink(gr.sizeof_char) self.tb.connect(self.src, self.freq_recov, self.time_recov, self.receiver) self.tb.connect(self.receiver, self.diffdec, self.symbol_mapper, self.unpack) self.tb.connect(self.unpack, self.snk)
def __init__(self, constellation, differential, rotation): if constellation.arity() > 256: # If this becomes limiting some of the blocks should be generalised so # that they can work with shorts and ints as well as chars. raise ValueError("Constellation cannot contain more than 256 points.") gr.hier_block2.__init__(self, "mod_demod", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature arity = constellation.arity() # TX self.constellation = constellation self.differential = differential import weakref self.blocks = [weakref.proxy(self)] # We expect a stream of unpacked bits. # First step is to pack them. self.blocks.append(blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)) # Second step we unpack them such that we have k bits in each byte where # each constellation symbol hold k bits. self.blocks.append( blocks.packed_to_unpacked_bb(self.constellation.bits_per_symbol(), gr.GR_MSB_FIRST)) # Apply any pre-differential coding # Gray-coding is done here if we're also using differential coding. if self.constellation.apply_pre_diff_code(): self.blocks.append(digital.map_bb(self.constellation.pre_diff_code())) # Differential encoding. if self.differential: self.blocks.append(digital.diff_encoder_bb(arity)) # Convert to constellation symbols. self.blocks.append(digital.chunks_to_symbols_bc(self.constellation.points(), self.constellation.dimensionality())) # CHANNEL # Channel just consists of a rotation to check differential coding. if rotation is not None: self.blocks.append(blocks.multiply_const_cc(rotation)) # RX # Convert the constellation symbols back to binary values. self.blocks.append(digital.constellation_decoder_cb(self.constellation.base())) # Differential decoding. if self.differential: self.blocks.append(digital.diff_decoder_bb(arity)) # Decode any pre-differential coding. if self.constellation.apply_pre_diff_code(): self.blocks.append(digital.map_bb( mod_codes.invert_code(self.constellation.pre_diff_code()))) # unpack the k bit vector into a stream of bits self.blocks.append(blocks.unpack_k_bits_bb( self.constellation.bits_per_symbol())) # connect to block output check_index = len(self.blocks) self.blocks = self.blocks[:check_index] self.blocks.append(weakref.proxy(self)) self.connect(*self.blocks)
def __init__(self): gr.hier_block2.__init__(self, "dvb_convolutional_encoder_bb", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature self.encoder = trellis.encoder_bb(trellis.fsm(dvb.k, dvb.n, G), dvb.dimensionality) self.unpack = blocks.unpack_k_bits_bb(dvb.dimensionality) self.connect(self, self.encoder, self.unpack, self)
def test_002(self): src_data = ( 2, 3, 0, 1) expected_results = (1,0,1,1,0,0,0,1) src = blocks.vector_source_b(src_data,False) op = blocks.unpack_k_bits_bb(2) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(expected_results, dst.data())
def add_mobile_station(self,station_id): """ Adds new receiver mobile station. Station ID must be unique. Initializes BER reference source. """ # Initialize id_src = self._control._id_source dmux = self._data_multiplexer port = self._data_multiplexer_nextport self._data_multiplexer_nextport += 1 # Setup ctrl_port = self._control.add_mobile_station(station_id) options = self._options if options.imgxfer: ref_src = ofdm.imgtransfer_src( options.img ) else: ref_src = ber_reference_source(self._options) if(options.coding): ## Encoder encoder = self._encoder = ofdm.encoder_bb(fo,0) unpack = self._unpack = blocks.unpack_k_bits_bb(2) ## Puncturing if not options.nopunct: puncturing = self._puncturing = puncture_bb(options.subcarriers) #sah = gr.sample_and_hold_bb() #sah_trigger = blocks.vector_source_b([1,0],True) #decim_sah=gr.keep_one_in_n(gr.sizeof_char,2) self.connect(self._bitmap_trigger_puncturing,(puncturing,2)) frametrigger_bitmap_filter = blocks.vector_source_b([1,0],True) bitmap_filter = self._puncturing_bitmap_src_filter = skip(gr.sizeof_char*options.subcarriers,2)# skip_known_symbols(frame_length,subcarriers) bitmap_filter.skip_call(0) #self.connect(self._bitmap_src_puncturing,bitmap_filter,(puncturing,1)) self.connect(self._map_src,bitmap_filter,(puncturing,1)) self.connect(frametrigger_bitmap_filter,(bitmap_filter,1)) #bmt = gr.char_to_float() #self.connect(bitmap_filter,blocks.vector_to_stream(gr.sizeof_char,options.subcarriers), bmt) #log_to_file(self, bmt, "data/bitmap_filter_tx.float") self.connect((self._control,ctrl_port),ref_src,encoder,unpack) if not options.nopunct: self.connect(unpack,puncturing,(dmux,port)) #self.connect(sah_trigger, (sah,1)) else: self.connect(unpack,(dmux,port)) else: self.connect((self._control,ctrl_port),ref_src,(dmux,port)) if options.log and options.coding: log_to_file(self, encoder, "data/encoder_out.char") log_to_file(self, ref_src, "data/reference_data_src.char") log_to_file(self, unpack, "data/encoder_unpacked_out.char") if not options.nopunct: log_to_file(self, puncturing, "data/puncturing_out.char")
def test_003(self): src_data = expected_results = map(lambda x: random.randint(0,3), range(10)); src = blocks.vector_source_b( src_data ); pack = blocks.pack_k_bits_bb(2); unpack = blocks.unpack_k_bits_bb(2); snk = blocks.vector_sink_b(); self.tb.connect(src,unpack,pack,snk); self.tb.run() self.assertEqual(list(expected_results), list(snk.data()));
def test_003(self): src_data = expected_results = [random.randint(0, 3) for x in range(10)] src = blocks.vector_source_b(src_data) pack = blocks.pack_k_bits_bb(2) unpack = blocks.unpack_k_bits_bb(2) snk = blocks.vector_sink_b() self.tb.connect(src, unpack, pack, snk) self.tb.run() self.assertEqual(list(expected_results), list(snk.data()))
def test_002(self): src_data = [2, 3, 0, 1] expected_results = [1, 0, 1, 1, 0, 0, 0, 1] src = blocks.vector_source_b(src_data, False) op = blocks.unpack_k_bits_bb(2) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(expected_results, dst.data())
def __init__(self, generic_encoder=0, generic_decoder=0, esno=0, samp_rate=3200000, threading="capillary", puncpat='11', seed=0): gr.hier_block2.__init__(self, "fec_test", gr.io_signature(1, 1, gr.sizeof_char * 1), gr.io_signature(2, 2, gr.sizeof_char * 1)) self.generic_encoder = generic_encoder self.generic_decoder = generic_decoder self.esno = esno self.samp_rate = samp_rate self.threading = threading self.puncpat = puncpat self.map_bb = digital.map_bb(([-1, 1])) self.b2f = blocks.char_to_float(1, 1) self.unpack8 = blocks.unpack_k_bits_bb(8) self.pack8 = blocks.pack_k_bits_bb(8) self.encoder = extended_encoder(encoder_obj_list=generic_encoder, threading=threading, puncpat=puncpat) self.decoder = extended_decoder(decoder_obj_list=generic_decoder, threading=threading, ann=None, puncpat=puncpat, integration_period=10000, rotator=None) noise = math.sqrt((10.0**(-esno / 10.0)) / 2.0) #self.fastnoise = analog.fastnoise_source_f(analog.GR_GAUSSIAN, noise, seed, 8192) self.fastnoise = analog.noise_source_f(analog.GR_GAUSSIAN, noise, seed) self.addnoise = blocks.add_ff(1) # Send packed input directly to the second output self.copy_packed = blocks.copy(gr.sizeof_char) self.connect(self, self.copy_packed) self.connect(self.copy_packed, (self, 1)) # Unpack inputl encode, convert to +/-1, add noise, decode, repack self.connect(self, self.unpack8) self.connect(self.unpack8, self.encoder) self.connect(self.encoder, self.map_bb) self.connect(self.map_bb, self.b2f) self.connect(self.b2f, (self.addnoise, 0)) self.connect(self.fastnoise, (self.addnoise, 1)) self.connect(self.addnoise, self.decoder) self.connect(self.decoder, self.pack8) self.connect(self.pack8, (self, 0))
def __init__(self): gr.hier_block2.__init__( self, "Bit Error Rate", gr.io_signaturev(2, 2, [gr.sizeof_char * 1, gr.sizeof_char * 1]), gr.io_signature(1, 1, gr.sizeof_float * 1), ) ################################################## # Variables ################################################## self._msgLength_config = ConfigParser.ConfigParser() self._msgLength_config.read("./configs/sdrConfig.txt") try: msgLength = self._msgLength_config.getint("main", "key") except: msgLength = 10000 self.msgLength = msgLength self._bits_per_byte_config = ConfigParser.ConfigParser() self._bits_per_byte_config.read("./configs/sdrConfig.txt") try: bits_per_byte = self._bits_per_byte_config.getint("main", "key") except: bits_per_byte = 8 self.bits_per_byte = bits_per_byte intdecim = 100000 if msgLength < intdecim: intdecim = msgLength ################################################## # Blocks ################################################## self.blocks_xor_xx_0 = blocks.xor_bb() self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_byte) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (1.0 / msgLength, )) self.blocks_integrate_xx_0 = blocks.integrate_ff(intdecim) ################################################## # Connections ################################################## self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 1), (self.blocks_xor_xx_0, 1)) self.connect((self, 0), (self.blocks_xor_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0)) self.connect((self.blocks_xor_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_integrate_xx_0, 0))
def __init__(self, bw_clock_sync=2*math.pi/100, bw_fll=math.pi/1600, bw_costas=2*math.pi/100, n_filts=32, len_sym_srrc=7, constellation=digital.constellation_calcdist([-1-1j, 1-1j, 1+1j, -1+1j], [], 4, 1).base(), samp_per_sym=3, alfa=0.35, bits_per_sym=2, alpha_probe=0.1, th_probe=0): gr.hier_block2.__init__( self, "Hier Rx", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_char*1), ) ################################################## # Parameters ################################################## self.bw_clock_sync = bw_clock_sync self.bw_fll = bw_fll self.bw_costas = bw_costas self.n_filts = n_filts self.len_sym_srrc = len_sym_srrc self.constellation = constellation self.samp_per_sym = samp_per_sym self.alfa = alfa self.bits_per_sym = bits_per_sym self.alpha_probe = alpha_probe self.th_probe = th_probe ################################################## # Variables ################################################## self.filtro_srrc = filtro_srrc = firdes.root_raised_cosine(n_filts,samp_per_sym*n_filts,1.0,alfa,samp_per_sym*len_sym_srrc*n_filts) ################################################## # Blocks ################################################## self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(samp_per_sym, bw_clock_sync, (filtro_srrc), n_filts, 16, 5, 1) self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc(samp_per_sym, alfa, len_sym_srrc*samp_per_sym, bw_fll) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2**bits_per_sym) self.digital_costas_loop_cc_0_0_0 = digital.costas_loop_cc(bw_costas, 2**bits_per_sym) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constellation) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_sym) self.analog_probe_avg_mag_sqrd_x_0 = analog.probe_avg_mag_sqrd_c(th_probe, alpha_probe) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.digital_fll_band_edge_cc_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0_0_0, 0)) self.connect((self, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.digital_costas_loop_cc_0_0_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self, 0)) self.connect((self, 0), (self.analog_probe_avg_mag_sqrd_x_0, 0))
def setup_test06(self): print "... benchmarking QPSK + 1/2 mapper" self.mode = 2 bitspermode = [0.5, 1, 1.5, 2, 3, 4, 4.5, 5, 6] self.nobits = (bitspermode[self.mode - 1]) self.data_subcarriers = 200 self.blks = self.N * (int(10 * self.nobits) + 1) self.tb = gr.top_block() self.encoder = self._encoder = trellis.encoder_bb(self.fo, 0) self.unpack = self._unpack = blocks.unpack_k_bits_bb(2) self.puncturing = puncture_bb(self.data_subcarriers) bmaptrig_stream_puncturing = [1] + [0] * (10 / 2 - 1) self.bitmap_trigger_puncturing = blocks.vector_source_b( bmaptrig_stream_puncturing, True) if self.interleave: int_object = trellis.interleaver(2000, 666) self.interlv = trellis.permutation(int_object.K(), int_object.INTER(), 1, gr.sizeof_char) #self.bitmap = [self.nobits]*self.data_subcarriers self.bitmap = [self.mode] * self.data_subcarriers + [ self.mode ] * self.data_subcarriers #self.bmaptrig_stream = [1, 1]+[0]*(11-2) self.bitdata = [ randint(0, 1) for i in range(self.blks * self.data_subcarriers) ] #self.data = numpy.array(self.bitdata)*(-2)+1 self.src = blocks.vector_source_b(self.bitdata) self.bitmap_src = blocks.vector_source_b(self.bitmap, True, self.data_subcarriers) #self.bitmap_trigger = blocks.vector_source_b(self.bmaptrig_stream, True) self.modulator = generic_mapper_bcv(self.data_subcarriers, self.coding, 10) self.snk = blocks.null_sink(gr.sizeof_gr_complex * self.data_subcarriers) #Connect blocks self.tb.connect(self.src, self.encoder, self.unpack, self.puncturing) #, self.modulator, self.snk) if self.interleave: self.tb.connect(self.puncturing, self.interlv, self.modulator, self.snk) else: self.tb.connect(self.puncturing, self.modulator, self.snk) self.tb.connect(self.bitmap_src, (self.modulator, 1)) self.tb.connect(self.bitmap_src, (self.puncturing, 1)) self.tb.connect(self.bitmap_trigger_puncturing, (self.puncturing, 2))
def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 10 self.baud_rate = baud_rate = 9600 self.samp_rate_tx = samp_rate_tx = 4003200 self.samp_rate = samp_rate = sps * baud_rate self.freq = freq = 435e6 ################################################## # Blocks ################################################## self.utat_endurosat_frame_sync_bb_0 = utat.endurosat_frame_sync_bb() self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char * 1) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_char * 1, "/home/ryan/Dev/ground-station/tests/rx_test/bin/tx_message.bin", False) ################################################## # Connections ################################################## self.connect((self.blocks_file_source_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.utat_endurosat_frame_sync_bb_0, 0)) self.connect((self.utat_endurosat_frame_sync_bb_0, 0), (self.blocks_null_sink_0, 0))
def __init__(self, bits_per_byte): gr.hier_block2.__init__(self, "BitErrors", gr.io_signature(2, 2, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_int)) # Bit comparison comp = blocks.xor_bb() intdump_decim = 100000 if N_BITS < intdump_decim: intdump_decim = int(N_BITS) self.connect(self, comp, blocks.unpack_k_bits_bb(bits_per_byte), blocks.uchar_to_float(), blocks.integrate_ff(intdump_decim), blocks.multiply_const_ff(1.0 / N_BITS), self) self.connect((self, 1), (comp, 1))
def __init__(self, generic_encoder=0, generic_decoder=0, esno=0, samp_rate=3200000, threading="capillary", puncpat='11', seed=0): gr.hier_block2.__init__(self, "fec_test", gr.io_signature(1, 1, gr.sizeof_char*1), gr.io_signature(2, 2, gr.sizeof_char*1)) self.generic_encoder = generic_encoder self.generic_decoder = generic_decoder self.esno = esno self.samp_rate = samp_rate self.threading = threading self.puncpat = puncpat self.map_bb = digital.map_bb(([-1, 1])) self.b2f = blocks.char_to_float(1, 1) self.unpack8 = blocks.unpack_k_bits_bb(8) self.pack8 = blocks.pack_k_bits_bb(8) self.encoder = extended_encoder(encoder_obj_list=generic_encoder, threading=threading, puncpat=puncpat) self.decoder = extended_decoder(decoder_obj_list=generic_decoder, threading=threading, ann=None, puncpat=puncpat, integration_period=10000, rotator=None) noise = math.sqrt((10.0**(-esno/10.0))/2.0) #self.fastnoise = analog.fastnoise_source_f(analog.GR_GAUSSIAN, noise, seed, 8192) self.fastnoise = analog.noise_source_f(analog.GR_GAUSSIAN, noise, seed) self.addnoise = blocks.add_ff(1) # Send packed input directly to the second output self.copy_packed = blocks.copy(gr.sizeof_char) self.connect(self, self.copy_packed) self.connect(self.copy_packed, (self, 1)) # Unpack inputl encode, convert to +/-1, add noise, decode, repack self.connect(self, self.unpack8) self.connect(self.unpack8, self.encoder) self.connect(self.encoder, self.map_bb) self.connect(self.map_bb, self.b2f) self.connect(self.b2f, (self.addnoise, 0)) self.connect(self.fastnoise, (self.addnoise,1)) self.connect(self.addnoise, self.decoder) self.connect(self.decoder, self.pack8) self.connect(self.pack8, (self, 0))
def __init__(self, parameter_0=0): gr.top_block.__init__(self, "gfsk_tx") ################################################## # Parameters ################################################## self.parameter_0 = parameter_0 ################################################## # Variables ################################################## self.transmission_rate = transmission_rate = 200e3 self.samp_rate = samp_rate = 4e6 ################################################## # Blocks ################################################## self.vlc_vlc_packet_source_b_0 = vlc.vlc_packet_source_b( 'vlc_gr_server') self.vlc_vlc_board_interface_b_0 = vlc.vlc_board_interface_b( '192.168.1.24', 7777, 6666, 256) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_repeat_0 = blocks.repeat( gr.sizeof_float * 1, int(samp_rate / transmission_rate * 32)) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(255) self.blocks_float_to_uchar_0 = blocks.float_to_uchar() self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) ################################################## # Connections ################################################## self.msg_connect( (self.vlc_vlc_board_interface_b_0, 'vlc_board_int_msg_out'), (self.vlc_vlc_packet_source_b_0, 'vlc_pkt_src_msg_in')) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_float_to_uchar_0, 0), (self.vlc_vlc_board_interface_b_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_float_to_uchar_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.vlc_vlc_packet_source_b_0, 0), (self.blocks_unpack_k_bits_bb_0, 0))
def __init__(self, pkt_len, nb_pkt, EbN0dB, fsm): gr.top_block.__init__(self, "Transmitter, channel and metrics computation") ################################################## # Variables ################################################## self.pkt_len = pkt_len Rc = 0.5 self.const = const = digital.constellation_bpsk().base() var_c = 1 Nb = 1 Eb = var_c / (2.0 * Nb * Rc) N0 = Eb * 10**(-EbN0dB / 10.0) noisevar = 2 * N0 ################################################## # Blocks ################################################## self.bits_src = blocks.vector_source_b( map(int, numpy.random.randint(0, 2, nb_pkt * pkt_len)), False) self.trellis_encoder = trellis.encoder_bb(trellis.fsm(fsm), 0, pkt_len) self.unpack = blocks.unpack_k_bits_bb(2) self.to_symbols = digital.chunks_to_symbols_bc((const.points()), 1) self.noise_src = analog.noise_source_c(analog.GR_GAUSSIAN, noisevar, 0) self.noise_adder = blocks.add_vcc(1) self.metrics_computer = trellis.metrics_c( 4, 2, ([-1, -1, -1, 1, 1, -1, 1, 1]), digital.TRELLIS_EUCLIDEAN) self.dst = blocks.vector_sink_f() ################################################## # Connections ################################################## self.connect((self.bits_src, 0), (self.trellis_encoder, 0)) self.connect((self.trellis_encoder, 0), (self.unpack, 0)) self.connect((self.unpack, 0), (self.to_symbols, 0)) self.connect((self.to_symbols, 0), (self.noise_adder, 0)) self.connect((self.noise_src, 0), (self.noise_adder, 1)) self.connect((self.noise_adder, 0), (self.metrics_computer, 0)) self.connect((self.metrics_computer, 0), (self.dst, 0))
def __init__(self): gr.hier_block2.__init__( self, "Bit Error Rate", gr.io_signaturev(2, 2, [gr.sizeof_char*1, gr.sizeof_char*1]), gr.io_signature(1, 1, gr.sizeof_float*1), ) ################################################## # Variables ################################################## self._msgLength_config = ConfigParser.ConfigParser() self._msgLength_config.read("./configs/sdrConfig.txt") try: msgLength = self._msgLength_config.getint("main", "key") except: msgLength = 10000 self.msgLength = msgLength self._bits_per_byte_config = ConfigParser.ConfigParser() self._bits_per_byte_config.read("./configs/sdrConfig.txt") try: bits_per_byte = self._bits_per_byte_config.getint("main", "key") except: bits_per_byte = 8 self.bits_per_byte = bits_per_byte intdecim = 100000 if msgLength < intdecim: intdecim = msgLength ################################################## # Blocks ################################################## self.blocks_xor_xx_0 = blocks.xor_bb() self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_byte) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((1.0/msgLength, )) self.blocks_integrate_xx_0 = blocks.integrate_ff(intdecim) ################################################## # Connections ################################################## self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 1), (self.blocks_xor_xx_0, 1)) self.connect((self, 0), (self.blocks_xor_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0)) self.connect((self.blocks_xor_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_integrate_xx_0, 0))
def sim ( self, arity, snr_db, N ): vlen = 1 N = int( N ) snr = 10.0**(snr_db/10.0) sigpow = 1.0 noise_pow = sigpow / snr demapper = ofdm.generic_demapper_vcb( vlen ) const = demapper.get_constellation( arity ) assert( len( const ) == 2**arity ) symsrc = ofdm.symbol_random_src( const, vlen ) noise_src = ofdm.complex_white_noise( 0.0, sqrt( noise_pow ) ) channel = blocks.add_cc() bitmap_src = blocks.vector_source_b( [arity] * vlen, True, vlen ) bm_trig_src = blocks.vector_source_b( [1], True ) ref_bitstream = blocks.unpack_k_bits_bb( arity ) bitstream_xor = blocks.xor_bb() bitstream_c2f = blocks.char_to_float() acc_biterr = ofdm.accumulator_ff() skiphead = blocks.skiphead( gr.sizeof_float, N-1 ) limit = blocks.head( gr.sizeof_float, 1 ) dst = blocks.vector_sink_f() tb = gr.top_block ( "test_block" ) tb.connect( (symsrc,0), (channel,0) ) tb.connect( noise_src, (channel,1) ) tb.connect( channel, (demapper,0), (bitstream_xor,0) ) tb.connect( bitmap_src, (demapper,1) ) tb.connect( bm_trig_src, (demapper,2) ) tb.connect( (symsrc,1), ref_bitstream, (bitstream_xor,1) ) tb.connect( bitstream_xor, bitstream_c2f, acc_biterr ) tb.connect( acc_biterr, skiphead, limit, dst ) tb.run() bit_errors = numpy.array( dst.data() ) assert( len( bit_errors ) == 1 ) bit_errors = bit_errors[0] return bit_errors / N
def setup_test06(self): print "... benchmarking QPSK + 1/2 mapper" self.mode = 2 bitspermode= [0.5,1,1.5,2,3,4,4.5,5,6] self.nobits = (bitspermode[self.mode-1]) self.data_subcarriers = 200 self.blks = self.N*(int(10*self.nobits) +1) self.tb = gr.top_block() self.encoder = self._encoder = trellis.encoder_bb(self.fo,0) self.unpack = self._unpack = blocks.unpack_k_bits_bb(2) self.puncturing = puncture_bb(self.data_subcarriers) bmaptrig_stream_puncturing = [1]+[0]*(10/2-1) self.bitmap_trigger_puncturing = blocks.vector_source_b(bmaptrig_stream_puncturing, True) if self.interleave: int_object=trellis.interleaver(2000,666) self.interlv = trellis.permutation(int_object.K(),int_object.INTER(),1,gr.sizeof_char) #self.bitmap = [self.nobits]*self.data_subcarriers self.bitmap = [self.mode]*self.data_subcarriers + [self.mode]*self.data_subcarriers #self.bmaptrig_stream = [1, 1]+[0]*(11-2) self.bitdata = [randint(0,1) for i in range(self.blks*self.data_subcarriers)] #self.data = numpy.array(self.bitdata)*(-2)+1 self.src = blocks.vector_source_b(self.bitdata) self.bitmap_src = blocks.vector_source_b(self.bitmap,True, self.data_subcarriers) #self.bitmap_trigger = blocks.vector_source_b(self.bmaptrig_stream, True) self.modulator = generic_mapper_bcv(self.data_subcarriers,self.coding,10) self.snk = blocks.null_sink(gr.sizeof_gr_complex*self.data_subcarriers) #Connect blocks self.tb.connect(self.src,self.encoder,self.unpack,self.puncturing)#, self.modulator, self.snk) if self.interleave: self.tb.connect(self.puncturing,self.interlv, self.modulator, self.snk) else: self.tb.connect(self.puncturing, self.modulator, self.snk) self.tb.connect(self.bitmap_src, (self.modulator,1)) self.tb.connect(self.bitmap_src, (self.puncturing,1)) self.tb.connect(self.bitmap_trigger_puncturing, (self.puncturing,2))
def __init__(self, vlen_in=1, vlen_out=1, n_tailbits=1, denom_mother_code_rate=1, map_tab=0, interl_seq=(0,1), bits_per_symbol=1, pp=0, pp_tail=0, gen_poly=0): gr.hier_block2.__init__( self, "MLC 4QAM", gr.io_signature(1, 1, gr.sizeof_char*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.vlen_in = vlen_in self.vlen_out = vlen_out self.n_tailbits = n_tailbits self.denom_mother_code_rate = denom_mother_code_rate self.map_tab = map_tab self.interl_seq = interl_seq self.bits_per_symbol = bits_per_symbol self.pp = pp self.pp_tail = pp_tail self.gen_poly = gen_poly ################################################## # Blocks ################################################## self.trellis_encoder_xx_0 = trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0, 0) if False else trellis.encoder_bb(trellis.fsm(1, denom_mother_code_rate, gen_poly), 0) self.drm_qam_map_bc_0 = drm.qam_map_bc(map_tab, bits_per_symbol, vlen_out, 1) self.drm_punct_bb_0 = drm.punct_bb(pp, pp_tail, (vlen_in + n_tailbits) * denom_mother_code_rate, vlen_out * 2, n_tailbits * denom_mother_code_rate) self.drm_interleaver_bb_0 = drm.interleaver_bb(((interl_seq))) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(denom_mother_code_rate) self.add_tailbits_bb_0 = drm.add_tailbits_bb(vlen_in, n_tailbits) ################################################## # Connections ################################################## self.connect((self.add_tailbits_bb_0, 0), (self.trellis_encoder_xx_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.drm_punct_bb_0, 0)) self.connect((self.drm_interleaver_bb_0, 0), (self.drm_qam_map_bc_0, 0)) self.connect((self.drm_punct_bb_0, 0), (self.drm_interleaver_bb_0, 0)) self.connect((self.drm_qam_map_bc_0, 0), (self, 0)) self.connect((self, 0), (self.add_tailbits_bb_0, 0)) self.connect((self.trellis_encoder_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0))
def __init__(self, bits_per_symbol=_def_bits_per_symbol, differential=_def_differential, mod_code=_def_mod_code, debug=False): #GNURadio constructor gr.hier_block2.__init__(self, "psk_constellation_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_char)) #Init internal attributes and basic building blocks self._bits_per_symbol = bits_per_symbol self._constellation_points = pow(2, bits_per_symbol) self._constellation = psk_constellation(self._constellation_points, mod_code, differential) self._constellation_decoder = digital_swig.constellation_decoder_cb( self._constellation.base()) self._differential = differential self._mod_code = mod_code self._pre_diff_code = self._constellation.apply_pre_diff_code() if self._differential: self._diffdec = digital_swig.diff_decoder_bb( self._constellation_points) if self._pre_diff_code: self._symbol_mapper = digital_swig.map_bb( mod_codes.invert_code(self._constellation.pre_diff_code())) # unpack the k bit vector into a stream of bits self.unpack = blocks.unpack_k_bits_bb(self.bits_per_symbol()) # Connect and Initialize base class self._blocks = [self, self._constellation_decoder] if self._differential: self._blocks.append(self._diffdec) if self._pre_diff_code: self._blocks.append(self._symbol_mapper) self._blocks += [self.unpack, self] if debug: self.debug_internal_state() self.connect(*self._blocks)
def test_modulator(self, param): """this function run the defined test, for easier understanding""" tb = self.tb src = blocks.file_source(gr.sizeof_char * 1, '../python/test_files/CADU.bin', False) pack = blocks.unpack_k_bits_bb(8) dst = blocks.vector_sink_b() head = blocks.head(gr.sizeof_char, len(param.data_src)) nrzl = ecss.nrzl_encoder(param.bit_rate, param.samp_rate) tb.connect(src, pack) tb.connect(pack, dst) self.tb.run() out = dst.data() return out
def __init__(self): gr.top_block.__init__(self, "Byte Construction") Qt.QWidget.__init__(self) self.setWindowTitle("Byte Construction") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "byte_construction") if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry(self.settings.value("geometry").toByteArray()) else: self.restoreGeometry( self.settings.value("geometry", type=QtCore.QByteArray)) ################################################## # Variables ################################################## self.sps = sps = 4 self.nfilts = nfilts = 32 self.timing_loop_bw = timing_loop_bw = 6.28 / 100.0 self.time_offset = time_offset = 1.00 self.taps = taps = [1.0, 0.25 - 0.25j, 0.50 + 0.10j, -0.3 + 0.2j] self.samp_rate = samp_rate = 32000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine( nfilts, nfilts, 1.0 / float(sps), 0.35, 11 * sps * nfilts) self.qpsk = qpsk = digital.constellation_rect(([ 0.707 + 0.707j, -0.707 + 0.707j, -0.707 - 0.707j, 0.707 - 0.707j ]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.phase_bw = phase_bw = 6.28 / 100.0 self.noise_volt = noise_volt = 0.0001 self.freq_offset = freq_offset = 0 self.excess_bw = excess_bw = 0.35 self.eq_gain = eq_gain = 0.01 self.delay = delay = 58 self.arity = arity = 4 ################################################## # Blocks ################################################## self.controls = Qt.QTabWidget() self.controls_widget_0 = Qt.QWidget() self.controls_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.controls_widget_0) self.controls_grid_layout_0 = Qt.QGridLayout() self.controls_layout_0.addLayout(self.controls_grid_layout_0) self.controls.addTab(self.controls_widget_0, 'Channel') self.controls_widget_1 = Qt.QWidget() self.controls_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.controls_widget_1) self.controls_grid_layout_1 = Qt.QGridLayout() self.controls_layout_1.addLayout(self.controls_grid_layout_1) self.controls.addTab(self.controls_widget_1, 'Receiver') self.top_grid_layout.addWidget(self.controls, 0, 0, 1, 2) [self.top_grid_layout.setRowStretch(r, 1) for r in range(0, 1)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 2)] self._timing_loop_bw_range = Range(0.0, 0.2, 0.01, 6.28 / 100.0, 200) self._timing_loop_bw_win = RangeWidget(self._timing_loop_bw_range, self.set_timing_loop_bw, 'Time: BW', "slider", float) self.controls_grid_layout_1.addWidget(self._timing_loop_bw_win, 0, 0, 1, 1) [self.controls_grid_layout_1.setRowStretch(r, 1) for r in range(0, 1)] [ self.controls_grid_layout_1.setColumnStretch(c, 1) for c in range(0, 1) ] self._time_offset_range = Range(0.999, 1.001, 0.0001, 1.00, 200) self._time_offset_win = RangeWidget(self._time_offset_range, self.set_time_offset, 'Timing Offset', "counter_slider", float) self.controls_grid_layout_0.addWidget(self._time_offset_win, 0, 2, 1, 1) [self.controls_grid_layout_0.setRowStretch(r, 1) for r in range(0, 1)] [ self.controls_grid_layout_0.setColumnStretch(c, 1) for c in range(2, 3) ] self.received = Qt.QTabWidget() self.received_widget_0 = Qt.QWidget() self.received_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.received_widget_0) self.received_grid_layout_0 = Qt.QGridLayout() self.received_layout_0.addLayout(self.received_grid_layout_0) self.received.addTab(self.received_widget_0, 'Constellation') self.received_widget_1 = Qt.QWidget() self.received_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.received_widget_1) self.received_grid_layout_1 = Qt.QGridLayout() self.received_layout_1.addLayout(self.received_grid_layout_1) self.received.addTab(self.received_widget_1, 'Symbols') self.top_grid_layout.addWidget(self.received, 2, 0, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 1)] self._phase_bw_range = Range(0.0, 1.0, 0.01, 6.28 / 100.0, 200) self._phase_bw_win = RangeWidget(self._phase_bw_range, self.set_phase_bw, 'Phase: Bandwidth', "slider", float) self.controls_grid_layout_1.addWidget(self._phase_bw_win, 0, 2, 1, 1) [self.controls_grid_layout_1.setRowStretch(r, 1) for r in range(0, 1)] [ self.controls_grid_layout_1.setColumnStretch(c, 1) for c in range(2, 3) ] self._noise_volt_range = Range(0, 1, 0.01, 0.0001, 200) self._noise_volt_win = RangeWidget(self._noise_volt_range, self.set_noise_volt, 'Noise Voltage', "counter_slider", float) self.controls_grid_layout_0.addWidget(self._noise_volt_win, 0, 0, 1, 1) [self.controls_grid_layout_0.setRowStretch(r, 1) for r in range(0, 1)] [ self.controls_grid_layout_0.setColumnStretch(c, 1) for c in range(0, 1) ] self._freq_offset_range = Range(-0.1, 0.1, 0.001, 0, 200) self._freq_offset_win = RangeWidget(self._freq_offset_range, self.set_freq_offset, 'Frequency Offset', "counter_slider", float) self.controls_grid_layout_0.addWidget(self._freq_offset_win, 0, 1, 1, 1) [self.controls_grid_layout_0.setRowStretch(r, 1) for r in range(0, 1)] [ self.controls_grid_layout_0.setColumnStretch(c, 1) for c in range(1, 2) ] self._eq_gain_range = Range(0.0, 0.1, 0.001, 0.01, 200) self._eq_gain_win = RangeWidget(self._eq_gain_range, self.set_eq_gain, 'Equalizer: rate', "slider", float) self.controls_grid_layout_1.addWidget(self._eq_gain_win, 0, 1, 1, 1) [self.controls_grid_layout_1.setRowStretch(r, 1) for r in range(0, 1)] [ self.controls_grid_layout_1.setColumnStretch(c, 1) for c in range(1, 2) ] self._delay_range = Range(0, 200, 1, 58, 200) self._delay_win = RangeWidget(self._delay_range, self.set_delay, 'Delay', "counter_slider", float) self.top_grid_layout.addWidget(self._delay_win, 1, 0, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(1, 2)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 1)] self.qtgui_time_sink_x_1 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "Input mins Output stream", #name 1 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.10) self.qtgui_time_sink_x_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1.enable_tags(-1, True) self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1.enable_autoscale(False) self.qtgui_time_sink_x_1.enable_grid(False) self.qtgui_time_sink_x_1.enable_axis_labels(True) self.qtgui_time_sink_x_1.enable_control_panel(False) self.qtgui_time_sink_x_1.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_1.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_win = sip.wrapinstance( self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_1_win) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate '', #name 2 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 2) self.qtgui_time_sink_x_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(False) self.qtgui_time_sink_x_0_0.enable_grid(False) self.qtgui_time_sink_x_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_0_0.enable_control_panel(False) self.qtgui_time_sink_x_0_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0_0.disable_legend() labels = ['Rx Bits', 'Tx Bits', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win, 2, 1, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(1, 2)] self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate '', #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 4) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ['Symbols', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.received_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_win, 0, 0, 1, 1) [self.received_grid_layout_1.setRowStretch(r, 1) for r in range(0, 1)] [ self.received_grid_layout_1.setColumnStretch(c, 1) for c in range(0, 1) ] self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0.enable_autoscale(False) self.qtgui_const_sink_x_0.enable_grid(False) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.received_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_win, 0, 0, 1, 1) [self.received_grid_layout_0.setRowStretch(r, 1) for r in range(0, 1)] [ self.received_grid_layout_0.setColumnStretch(c, 1) for c in range(0, 1) ] self.myblocks_qpsk_demod_v2_0 = myblocks.qpsk_demod_v2(0) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf( sps, timing_loop_bw, (rrc_taps), nfilts, nfilts / 2, 1.5, 2) self.digital_map_bb_0 = digital.map_bb(([0, 3, 2, 1])) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(4) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( phase_bw, arity, False) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=qpsk, differential=True, samples_per_symbol=sps, pre_diff_code=True, excess_bw=excess_bw, verbose=False, log=False, ) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc( 15, 1, eq_gain, 2) self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise_volt, frequency_offset=freq_offset, epsilon=time_offset, taps=(taps), noise_seed=0, block_tags=False) self.blocks_unpack_k_bits_bb_0_0 = blocks.unpack_k_bits_bb(8) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb( 2, 8, "", False, gr.GR_LSB_FIRST) self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, int(delay)) self.blocks_char_to_float_0_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, 256, 1000)), True) ################################################## # Connections ################################################## self.connect((self.analog_random_source_x_0, 0), (self.blocks_unpack_k_bits_bb_0_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_char_to_float_0_0_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_delay_0, 0), (self.qtgui_time_sink_x_0_0, 1)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.blocks_throttle_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0_0, 0), (self.blocks_char_to_float_0_0_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.myblocks_qpsk_demod_v2_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.digital_map_bb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_cma_equalizer_cc_0, 0)) self.connect((self.myblocks_qpsk_demod_v2_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.myblocks_qpsk_demod_v2_0, 0), (self.digital_map_bb_0, 0))
def __init__(self): gr.top_block.__init__(self, "Simulation for SDR TCC") Qt.QWidget.__init__(self) self.setWindowTitle("Simulation for SDR TCC") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "sdrSim2") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 4 self.nfilts = nfilts = 32 self.eb = eb = 0.35 self.timing_loop_bw = timing_loop_bw = 0.005 self.time_offset = time_offset = 1.00 self.taps = taps = [1.0, 0.25-0.25j, 0.50 + 0.10j, -0.3 + 0.2j] self.samp_rate = samp_rate = 32000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(sps), 0.35, 11*sps*nfilts) self.qpsk = qpsk = digital.constellation_rect(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.preamble = preamble = [1,-1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,-1] self.phase_bw = phase_bw = 6.28/100.0 self.payload_size = payload_size = 992 self.noise_volt = noise_volt = 0.0001 self.matched_filter = matched_filter = firdes.root_raised_cosine(nfilts, nfilts, 1, eb, int(11*sps*nfilts)) self.freq_offset = freq_offset = 0 self.freq_bw = freq_bw = 6.28/100.0 self.excess_bw = excess_bw = 0.35 self.eq_gain = eq_gain = 0.01 self.delay = delay = 0 self.arity = arity = 4 ################################################## # Blocks ################################################## self.controls = Qt.QTabWidget() self.controls_widget_0 = Qt.QWidget() self.controls_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.controls_widget_0) self.controls_grid_layout_0 = Qt.QGridLayout() self.controls_layout_0.addLayout(self.controls_grid_layout_0) self.controls.addTab(self.controls_widget_0, "Channel") self.controls_widget_1 = Qt.QWidget() self.controls_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.controls_widget_1) self.controls_grid_layout_1 = Qt.QGridLayout() self.controls_layout_1.addLayout(self.controls_grid_layout_1) self.controls.addTab(self.controls_widget_1, "Receiver") self.top_grid_layout.addWidget(self.controls, 0,0,1,2) self._timing_loop_bw_layout = Qt.QVBoxLayout() self._timing_loop_bw_label = Qt.QLabel("Time: BW") self._timing_loop_bw_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._timing_loop_bw_slider.setRange(0.0, 0.2, 0.005) self._timing_loop_bw_slider.setValue(self.timing_loop_bw) self._timing_loop_bw_slider.setMinimumWidth(200) self._timing_loop_bw_slider.valueChanged.connect(self.set_timing_loop_bw) self._timing_loop_bw_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter) self._timing_loop_bw_layout.addWidget(self._timing_loop_bw_label) self._timing_loop_bw_layout.addWidget(self._timing_loop_bw_slider) self.controls_grid_layout_1.addLayout(self._timing_loop_bw_layout, 0,0,1,1) self._time_offset_layout = Qt.QVBoxLayout() self._time_offset_tool_bar = Qt.QToolBar(self) self._time_offset_layout.addWidget(self._time_offset_tool_bar) self._time_offset_tool_bar.addWidget(Qt.QLabel("Timing Offset"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._time_offset_counter = qwt_counter_pyslot() self._time_offset_counter.setRange(0.999, 1.001, 0.0001) self._time_offset_counter.setNumButtons(2) self._time_offset_counter.setValue(self.time_offset) self._time_offset_tool_bar.addWidget(self._time_offset_counter) self._time_offset_counter.valueChanged.connect(self.set_time_offset) self._time_offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._time_offset_slider.setRange(0.999, 1.001, 0.0001) self._time_offset_slider.setValue(self.time_offset) self._time_offset_slider.setMinimumWidth(200) self._time_offset_slider.valueChanged.connect(self.set_time_offset) self._time_offset_layout.addWidget(self._time_offset_slider) self.controls_grid_layout_0.addLayout(self._time_offset_layout, 0,2,1,1) self.received = Qt.QTabWidget() self.received_widget_0 = Qt.QWidget() self.received_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.received_widget_0) self.received_grid_layout_0 = Qt.QGridLayout() self.received_layout_0.addLayout(self.received_grid_layout_0) self.received.addTab(self.received_widget_0, "Constellation") self.received_widget_1 = Qt.QWidget() self.received_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.received_widget_1) self.received_grid_layout_1 = Qt.QGridLayout() self.received_layout_1.addLayout(self.received_grid_layout_1) self.received.addTab(self.received_widget_1, "Symbols") self.top_grid_layout.addWidget(self.received, 2,0,1,1) self._phase_bw_layout = Qt.QVBoxLayout() self._phase_bw_label = Qt.QLabel("Phase: Bandwidth") self._phase_bw_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._phase_bw_slider.setRange(0.0, 1.0, 0.01) self._phase_bw_slider.setValue(self.phase_bw) self._phase_bw_slider.setMinimumWidth(200) self._phase_bw_slider.valueChanged.connect(self.set_phase_bw) self._phase_bw_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter) self._phase_bw_layout.addWidget(self._phase_bw_label) self._phase_bw_layout.addWidget(self._phase_bw_slider) self.controls_grid_layout_1.addLayout(self._phase_bw_layout, 0,2,1,1) self._noise_volt_layout = Qt.QVBoxLayout() self._noise_volt_tool_bar = Qt.QToolBar(self) self._noise_volt_layout.addWidget(self._noise_volt_tool_bar) self._noise_volt_tool_bar.addWidget(Qt.QLabel("Noise Voltage"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._noise_volt_counter = qwt_counter_pyslot() self._noise_volt_counter.setRange(0, 1, 0.01) self._noise_volt_counter.setNumButtons(2) self._noise_volt_counter.setValue(self.noise_volt) self._noise_volt_tool_bar.addWidget(self._noise_volt_counter) self._noise_volt_counter.valueChanged.connect(self.set_noise_volt) self._noise_volt_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._noise_volt_slider.setRange(0, 1, 0.01) self._noise_volt_slider.setValue(self.noise_volt) self._noise_volt_slider.setMinimumWidth(200) self._noise_volt_slider.valueChanged.connect(self.set_noise_volt) self._noise_volt_layout.addWidget(self._noise_volt_slider) self.controls_grid_layout_0.addLayout(self._noise_volt_layout, 0,0,1,1) self._freq_offset_layout = Qt.QVBoxLayout() self._freq_offset_tool_bar = Qt.QToolBar(self) self._freq_offset_layout.addWidget(self._freq_offset_tool_bar) self._freq_offset_tool_bar.addWidget(Qt.QLabel("Frequency Offset"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._freq_offset_counter = qwt_counter_pyslot() self._freq_offset_counter.setRange(-0.1, 0.1, 0.001) self._freq_offset_counter.setNumButtons(2) self._freq_offset_counter.setValue(self.freq_offset) self._freq_offset_tool_bar.addWidget(self._freq_offset_counter) self._freq_offset_counter.valueChanged.connect(self.set_freq_offset) self._freq_offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._freq_offset_slider.setRange(-0.1, 0.1, 0.001) self._freq_offset_slider.setValue(self.freq_offset) self._freq_offset_slider.setMinimumWidth(200) self._freq_offset_slider.valueChanged.connect(self.set_freq_offset) self._freq_offset_layout.addWidget(self._freq_offset_slider) self.controls_grid_layout_0.addLayout(self._freq_offset_layout, 0,1,1,1) self._eq_gain_layout = Qt.QVBoxLayout() self._eq_gain_label = Qt.QLabel("Equalizer: rate") self._eq_gain_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._eq_gain_slider.setRange(0.0, 0.1, 0.001) self._eq_gain_slider.setValue(self.eq_gain) self._eq_gain_slider.setMinimumWidth(200) self._eq_gain_slider.valueChanged.connect(self.set_eq_gain) self._eq_gain_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter) self._eq_gain_layout.addWidget(self._eq_gain_label) self._eq_gain_layout.addWidget(self._eq_gain_slider) self.controls_grid_layout_1.addLayout(self._eq_gain_layout, 0,1,1,1) self._delay_layout = Qt.QVBoxLayout() self._delay_tool_bar = Qt.QToolBar(self) self._delay_layout.addWidget(self._delay_tool_bar) self._delay_tool_bar.addWidget(Qt.QLabel("Delay"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._delay_counter = qwt_counter_pyslot() self._delay_counter.setRange(0, 200, 1) self._delay_counter.setNumButtons(2) self._delay_counter.setValue(self.delay) self._delay_tool_bar.addWidget(self._delay_counter) self._delay_counter.valueChanged.connect(self.set_delay) self._delay_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._delay_slider.setRange(0, 200, 1) self._delay_slider.setValue(self.delay) self._delay_slider.setMinimumWidth(200) self._delay_slider.valueChanged.connect(self.set_delay) self._delay_layout.addWidget(self._delay_slider) self.top_grid_layout.addLayout(self._delay_layout, 1,0,1,1) self.tutorial_my_qpsk_demod_cb_1 = tutorial.my_qpsk_demod_cb(True) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate "", #name 2 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 2) self.qtgui_time_sink_x_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win, 2,1,1,1) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 4) self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.received_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_win, 0,0,1,1) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0.enable_autoscale(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "red", "red", "red", "red", "red", "red", "red", "red"] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.received_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_win, 0,0,1,1) self._freq_bw_layout = Qt.QVBoxLayout() self._freq_bw_label = Qt.QLabel("Frequency Bandwidth") self._freq_bw_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._freq_bw_slider.setRange(0.0, 1.0, 0.01) self._freq_bw_slider.setValue(self.freq_bw) self._freq_bw_slider.setMinimumWidth(200) self._freq_bw_slider.valueChanged.connect(self.set_freq_bw) self._freq_bw_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter) self._freq_bw_layout.addWidget(self._freq_bw_label) self._freq_bw_layout.addWidget(self._freq_bw_slider) self.controls_grid_layout_1.addLayout(self._freq_bw_layout, 0,3,1,1) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, timing_loop_bw, (rrc_taps), nfilts, nfilts/2, 1.5, 2) self.digital_map_bb_0 = digital.map_bb(([0,1,3,2])) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(4) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(phase_bw, arity) self.digital_correlate_and_sync_cc_0 = digital.correlate_and_sync_cc((preamble), (matched_filter), sps) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=qpsk, differential=True, samples_per_symbol=sps, pre_diff_code=True, excess_bw=excess_bw, verbose=False, log=False, ) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(15, 1, eq_gain, 2) self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise_volt, frequency_offset=freq_offset, epsilon=time_offset, taps=(taps), noise_seed=0, block_tags=False ) self.blocks_vector_source_x_0_0 = blocks.vector_source_b(map(lambda x: (-x+1)/2, preamble), True, 1, []) self.blocks_unpack_k_bits_bb_0_0 = blocks.unpack_k_bits_bb(8) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(2) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_stream_mux_0_0_0 = blocks.stream_mux(gr.sizeof_char*1, (len(preamble)/8,payload_size)) self.blocks_pack_k_bits_bb_1 = blocks.pack_k_bits_bb(8) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/franchz/tcc/gnuradio/tx_teste.txt", True) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/home/franchz/tcc/gnuradio/rx_teste.txt", False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, int(delay)) self.blocks_char_to_float_0_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) ################################################## # Connections ################################################## self.connect((self.blocks_throttle_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_cma_equalizer_cc_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0_0, 0), (self.blocks_char_to_float_0_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.blocks_vector_source_x_0_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.blocks_stream_mux_0_0_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.digital_correlate_and_sync_cc_0, 0)) self.connect((self.digital_correlate_and_sync_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_correlate_and_sync_cc_0, 1), (self.blocks_null_sink_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_stream_mux_0_0_0, 1)) self.connect((self.blocks_file_source_0, 0), (self.blocks_unpack_k_bits_bb_0_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.qtgui_time_sink_x_0_0, 1)) self.connect((self.blocks_char_to_float_0_0_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_delay_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_pack_k_bits_bb_1, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_pack_k_bits_bb_1, 0)) self.connect((self.blocks_stream_mux_0_0_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.tutorial_my_qpsk_demod_cb_1, 0), (self.digital_map_bb_0, 0)) self.connect((self.digital_map_bb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.tutorial_my_qpsk_demod_cb_1, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0))
def __init__(self, options): gr.hier_block2.__init__( self, "fbmc_transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex) ) common_options.defaults(options) config = self.config = station_configuration() config.data_subcarriers = options.subcarriers config.cp_length = 0 config.frame_data_blocks = options.data_blocks config._verbose = options.verbose config.fft_length = options.fft_length config.dc_null = options.dc_null config.training_data = default_block_header(config.data_subcarriers, config.fft_length, config.dc_null, options) config.coding = options.coding config.fbmc = options.fbmc config.adaptive_fbmc = options.adaptive_fbmc config.frame_id_blocks = 1 # FIXME # digital rms amplitude sent to USRP rms_amp = options.rms_amplitude self._options = copy.copy(options) config.block_length = config.fft_length + config.cp_length config.frame_data_part = config.frame_data_blocks + config.frame_id_blocks config.frame_length = config.training_data.fbmc_no_preambles + 2 * config.frame_data_part config.subcarriers = config.data_subcarriers + config.training_data.pilot_subcarriers config.virtual_subcarriers = config.fft_length - config.subcarriers - config.dc_null # default values if parameters not set if rms_amp is None: rms_amp = math.sqrt(config.subcarriers) config.rms_amplitude = rms_amp # check some bounds if config.fft_length < config.subcarriers: raise SystemError, "Subcarrier number must be less than FFT length" if config.fft_length < config.cp_length: raise SystemError, "Cyclic prefix length must be less than FFT length" ## shortcuts blen = config.block_length flen = config.frame_length dsubc = config.data_subcarriers vsubc = config.virtual_subcarriers # Adaptive Transmitter Concept used_id_bits = config.used_id_bits = 8 # TODO: no constant in source code rep_id_bits = config.rep_id_bits = config.data_subcarriers / used_id_bits # BPSK if config.data_subcarriers % used_id_bits <> 0: raise SystemError, "Data subcarriers need to be multiple of %d" % (used_id_bits) ## Allocation Control self.allocation_src = allocation_src( config.data_subcarriers, config.frame_data_blocks, config.coding, "tcp://*:3333", "tcp://" + options.rx_hostname + ":3322", ) if options.static_allocation: # DEBUG # how many bits per subcarrier if options.coding: mode = 1 # Coding mode 1-9 bitspermode = [0.5, 1, 1.5, 2, 3, 4, 4.5, 5, 6] # Information bits per mode modulbitspermode = [1, 2, 2, 4, 4, 6, 6, 6, 8] # Coding bits per mode bitcount_vec = [(int)(config.data_subcarriers * config.frame_data_blocks * bitspermode[mode - 1])] modul_bitcount_vec = [config.data_subcarriers * config.frame_data_blocks * modulbitspermode[mode - 1]] bitcount_src = blocks.vector_source_i(bitcount_vec, True, 1) modul_bitcount_src = blocks.vector_source_i(modul_bitcount_vec, True, 1) bitloading = mode else: bitloading = 1 bitcount_vec = [config.data_subcarriers * config.frame_data_blocks * bitloading] bitcount_src = blocks.vector_source_i(bitcount_vec, True, 1) modul_bitcount_src = bitcount_src # id's for frames id_vec = range(0, 256) id_src = blocks.vector_source_s(id_vec, True, 1) # bitloading for ID symbol and then once for data symbols # bitloading_vec = [1]*dsubc+[0]*(dsubc/2)+[2]*(dsubc/2) test_allocation = ( [bitloading] * (int)(config.data_subcarriers / 8) + [0] * (int)(config.data_subcarriers / 4 * 3) + [bitloading] * (int)(config.data_subcarriers / 8) ) # bitloading_vec = [1]*dsubc+[bitloading]*dsubc bitloading_vec = [1] * dsubc + test_allocation bitloading_src = blocks.vector_source_b(bitloading_vec, True, dsubc) # bitcount for frames # bitcount_vec = [config.data_subcarriers*config.frame_data_blocks*bitloading] bitcount_vec = [config.frame_data_blocks * sum(test_allocation)] bitcount_src = blocks.vector_source_i(bitcount_vec, True, 1) # power loading, here same for all symbols power_vec = ( [1] * (int)(config.data_subcarriers / 8) + [0] * (int)(config.data_subcarriers / 4 * 3) + [1] * (int)(config.data_subcarriers / 8) ) power_src = blocks.vector_source_f(power_vec, True, dsubc) # mux control stream to mux id and data bits mux_vec = [0] * dsubc + [1] * bitcount_vec[0] mux_ctrl = blocks.vector_source_b(mux_vec, True, 1) else: id_src = (self.allocation_src, 0) bitcount_src = (self.allocation_src, 4) bitloading_src = (self.allocation_src, 2) power_src = (self.allocation_src, 1) if options.coding: modul_bitcount_src = (self.allocation_src, 5) else: modul_bitcount_src = bitcount_src mux_ctrl = ofdm.tx_mux_ctrl(dsubc) self.connect(modul_bitcount_src, mux_ctrl) # Initial allocation self.allocation_src.set_allocation([4] * config.data_subcarriers, [1] * config.data_subcarriers) if options.benchmarking: self.allocation_src.set_allocation([4] * config.data_subcarriers, [1] * config.data_subcarriers) if options.lab_special_case: self.allocation_src.set_allocation( [0] * (config.data_subcarriers / 4) + [2] * (config.data_subcarriers / 2) + [0] * (config.data_subcarriers / 4), [1] * config.data_subcarriers, ) if options.log: log_to_file(self, id_src, "data/id_src.short") log_to_file(self, bitcount_src, "data/bitcount_src.int") log_to_file(self, bitloading_src, "data/bitloading_src.char") log_to_file(self, power_src, "data/power_src.cmplx") ## GUI probe output zmq_probe_bitloading = zeromq.pub_sink(gr.sizeof_char, dsubc, "tcp://*:4445") # also skip ID symbol bitloading with keep_one_in_n (side effect) # factor 2 for bitloading because we have two vectors per frame, one for id symbol and one for all payload/data symbols # factor config.frame_data_part for power because there is one vector per ofdm symbol per frame self.connect(bitloading_src, blocks.keep_one_in_n(gr.sizeof_char * dsubc, 2 * 40), zmq_probe_bitloading) zmq_probe_power = zeromq.pub_sink(gr.sizeof_float, dsubc, "tcp://*:4444") # self.connect(power_src, blocks.keep_one_in_n(gr.sizeof_gr_complex*dsubc,40), blocks.complex_to_real(dsubc), zmq_probe_power) self.connect(power_src, blocks.keep_one_in_n(gr.sizeof_float * dsubc, 40), zmq_probe_power) ## Workaround to avoid periodic structure seed(1) whitener_pn = [randint(0, 1) for i in range(used_id_bits * rep_id_bits)] ## ID Encoder id_enc = self._id_encoder = repetition_encoder_sb(used_id_bits, rep_id_bits, whitener_pn) self.connect(id_src, id_enc) if options.log: id_enc_f = gr.char_to_float() self.connect(id_enc, id_enc_f) log_to_file(self, id_enc_f, "data/id_enc_out.float") ## Reference Data Source ber_ref_src = ber_reference_source(self._options) self.connect(id_src, (ber_ref_src, 0)) self.connect(bitcount_src, (ber_ref_src, 1)) if options.log: log_to_file(self, ber_ref_src, "data/ber_rec_src_tx.char") if options.log: log_to_file(self, btrig, "data/bitmap_trig.char") ## Frame Trigger ftrig_stream = [1] + [0] * (config.frame_data_part - 1) ftrig = self._frame_trigger = blocks.vector_source_b(ftrig_stream, True) ## Data Multiplexer # Input 0: control stream # Input 1: encoded ID stream # Inputs 2..n: data streams dmux = self._data_multiplexer = stream_controlled_mux_b() self.connect(mux_ctrl, (dmux, 0)) self.connect(id_enc, (dmux, 1)) if options.coding: fo = trellis.fsm(1, 2, [91, 121]) encoder = self._encoder = trellis.encoder_bb(fo, 0) unpack = self._unpack = blocks.unpack_k_bits_bb(2) self.connect(ber_ref_src, encoder, unpack) if options.interleave: int_object = trellis.interleaver(2000, 666) interlv = trellis.permutation(int_object.K(), int_object.INTER(), 1, gr.sizeof_char) if not options.nopunct: bmaptrig_stream_puncturing = [1] + [0] * (config.frame_data_blocks / 2 - 1) btrig_puncturing = self._bitmap_trigger_puncturing = blocks.vector_source_b( bmaptrig_stream_puncturing, True ) puncturing = self._puncturing = puncture_bb(config.data_subcarriers) self.connect(bitloading_src, (puncturing, 1)) self.connect(self._bitmap_trigger_puncturing, (puncturing, 2)) self.connect(unpack, puncturing) last_block = puncturing if options.interleave: self.connect(last_block, interlv) last_block = interlv if options.benchmarking: self.connect(last_block, blocks.head(gr.sizeof_char, options.N), (dmux, 2)) else: self.connect(last_block, (dmux, 2)) else: if options.benchmarking: self.connect(unpack, blocks.head(gr.sizeof_char, options.N), (dmux, 2)) else: self.connect(unpack, (dmux, 2)) else: if options.benchmarking: self.connect(ber_ref_src, blocks.head(gr.sizeof_char, options.N), (dmux, 2)) else: self.connect(ber_ref_src, (dmux, 2)) if options.log: dmux_f = gr.char_to_float() self.connect(dmux, dmux_f) log_to_file(self, dmux_f, "data/dmux_out.float") ## Modulator mod = self._modulator = generic_mapper_bcv(config.data_subcarriers, config.coding, config.frame_data_part) self.connect(dmux, (mod, 0)) self.connect(bitloading_src, (mod, 1)) if options.log: log_to_file(self, mod, "data/mod_out.compl") modi = blocks.complex_to_imag(config.data_subcarriers) modr = blocks.complex_to_real(config.data_subcarriers) self.connect(mod, modi) self.connect(mod, modr) log_to_file(self, modi, "data/mod_imag_out.float") log_to_file(self, modr, "data/mod_real_out.float") ## Power allocator pa = self._power_allocator = multiply_frame_fc(config.frame_data_part, config.data_subcarriers) self.connect(mod, (pa, 0)) self.connect(power_src, (pa, 1)) if options.log: log_to_file(self, pa, "data/pa_out.compl") if options.fbmc: psubc = pa else: psubc = self._pilot_subcarrier_inserter = pilot_subcarrier_inserter() self.connect(pa, psubc) if options.log: log_to_file(self, psubc, "data/psubc_out.compl") subcarriers = config.subcarriers # fbmc_pblocks_timing = self._fbmc_timing_pilot_block_inserter = fbmc_timing_pilot_block_inserter(5,False) oqam_prep = self._oqam_prep = fbmc_oqam_preprocessing_vcvc(config.subcarriers, 0, 0) self.connect(psubc, oqam_prep) fbmc_pblocks = self._fbmc_pilot_block_inserter = fbmc_pilot_block_inserter(5, False) self.connect(oqam_prep, fbmc_pblocks) # log_to_file(self, fbmc_pblocks, "data/fbmc_pblocks_out.compl") # fbmc_insert_pream = self._fbmc_insert_pream = fbmc_insert_preamble_vcvc(M, syms_per_frame, preamble) # log_to_file(self, oqam_prep, "data/oqam_prep.compl") # log_to_file(self, psubc, "data/psubc_out.compl") # fbmc_pblocks = fbmc_pblocks_timing # log_to_file(self, fbmc_pblocks, "data/fbmc_pblocks_out.compl") beta_mult = self._beta_mult = fbmc_beta_multiplier_vcvc(config.subcarriers, 4, 4 * config.fft_length - 1, 0) self.connect(fbmc_pblocks, beta_mult) log_to_file(self, beta_mult, "data/beta_mult.compl") ## Add virtual subcarriers if config.fft_length > subcarriers: vsubc = self._virtual_subcarrier_extender = vector_padding_dc_null( config.subcarriers, config.fft_length, config.dc_null ) self.connect(beta_mult, vsubc) else: vsubc = self._virtual_subcarrier_extender = beta_mult if options.log: log_to_file(self, vsubc, "data/vsubc_out.compl") ## IFFT, no window, block shift ifft = self._ifft = fft_blocks.fft_vcc(config.fft_length, False, [], True) self.connect(vsubc, ifft) if options.log: log_to_file(self, ifft, "data/ifft_out.compl") # FBMC separate stream + filterbanks separate_oqam = self._separate_oqam = fbmc_separate_vcvc(config.fft_length, 2) poly_netw_1 = self._poly_netw_1 = fbmc_polyphase_network_vcvc( config.fft_length, 4, 4 * config.fft_length - 1, False ) poly_netw_2 = self._poly_netw_2 = fbmc_polyphase_network_vcvc( config.fft_length, 4, 4 * config.fft_length - 1, False ) overlap_p2s = self._overlap_p2s = fbmc_overlapping_parallel_to_serial_vcc(config.fft_length) self.connect(ifft, (separate_oqam, 0), poly_netw_1) self.connect((separate_oqam, 1), poly_netw_2) self.connect(poly_netw_1, (overlap_p2s, 0)) self.connect(poly_netw_2, (overlap_p2s, 1)) ## Pilot blocks (preambles) # pblocks = self._pilot_block_inserter = pilot_block_inserter2(5,False) # self.connect( overlap_p2s, blocks.stream_to_vector(gr.sizeof_gr_complex,config.fft_length/2), pblocks ) # log_to_file(self, pblocks, "data/fbmc_pilot_block_ins_out.compl") if options.log: log_to_file(self, pblocks, "data/pilot_block_ins_out.compl") ## Cyclic Prefix # cp = self._cyclic_prefixer = cyclic_prefixer(config.fft_length, # config.block_length) # cp= blocks.vector_to_stream(gr.sizeof_gr_complex, config.fft_length/2) # self.connect(pblocks, cp ) # self.connect( overlap_p2s,blocks.stream_to_vector(gr.sizeof_gr_complex,config.fft_length/2), cp ) lastblock = overlap_p2s if options.log: log_to_file(self, overlap_p2s, "data/overlap_p2s_out.compl") # Digital Amplifier for resource allocation if config.adaptive_fbmc: rep = blocks.repeat(gr.sizeof_gr_complex, config.frame_length * config.block_length) amp = blocks.multiply_cc() self.connect(lastblock, (amp, 0)) self.connect((self.allocation_src, 3), rep, (amp, 1)) lastblock = amp else: self.connect((self.allocation_src, 3), blocks.null_sink(gr.sizeof_gr_complex)) ## Digital Amplifier # amp = self._amplifier = gr.multiply_const_cc(1) amp = self._amplifier = ofdm.multiply_const_ccf(1.0) self.connect(lastblock, amp) self.set_rms_amplitude(rms_amp) # log_to_file(self, amp, "data/amp_tx_out.compl") if options.log: log_to_file(self, amp, "data/amp_tx_out.compl") ## Tx parameters bandwidth = options.bandwidth or 2e6 bits = 8 * config.data_subcarriers * config.frame_data_blocks # max. QAM256 samples_per_frame = config.frame_length * config.block_length tb = samples_per_frame / bandwidth # set dummy carrier frequency if none available due to baseband mode if options.tx_freq is None: options.tx_freq = 0.0 self.tx_parameters = { "carrier_frequency": options.tx_freq / 1e9, "fft_size": config.fft_length, "cp_size": config.cp_length, "subcarrier_spacing": options.bandwidth / config.fft_length / 1e3, "data_subcarriers": config.data_subcarriers, "bandwidth": options.bandwidth / 1e6, "frame_length": config.frame_length, "symbol_time": (config.cp_length + config.fft_length) / options.bandwidth * 1e6, "max_data_rate": (bits / tb) / 1e6, } ## Setup Output self.connect(amp, self) # Display some information about the setup if config._verbose: self._print_verbage()
def __init__(self, filenames, dev_addrs, onebit, iq, noise, mix, gain, fs, fc, unint, sync_pps): gr.top_block.__init__(self) if mix: raise NotImplementedError("TODO: Hilbert remix mode not implemented.") uhd_sinks = [ uhd.usrp_sink(",".join( [addr, "send_frame_size=32768,num_send_frames=128"]), uhd.stream_args( cpu_format="fc32", otwformat="sc8", channels=[0])) for addr in dev_addrs] for sink in uhd_sinks: sink.set_clock_rate(fs*2, uhd.ALL_MBOARDS) sink.set_samp_rate(fs) sink.set_center_freq(fc, 0) sink.set_gain(gain, 0) # TODO Use offset tuning? if sync_pps: sink.set_clock_source("external") # 10 MHz sink.set_time_source("external") # PPS if unint: if noise or onebit or not iq: raise NotImplementedError("TODO: RX channel-interleaved mode only " "supported for noiseless 8-bit complex.") BLOCK_N=16*1024*1024 demux = blocks.vector_to_streams(2, len(uhd_sinks)) self.connect(blocks.file_source(2*len(uhd_sinks)*BLOCK_N, filenames[0], False), blocks.vector_to_stream(2*len(uhd_sinks), BLOCK_N), demux) for ix, sink in enumerate(uhd_sinks): self.connect((demux, ix), blocks.vector_to_stream(1, 2), blocks.interleaved_char_to_complex(), # [-128.0, +127.0] blocks.multiply_const_cc(1.0/1024), # [-0.125, 0.125) # blocks.vector_to_stream(8, 16*1024), sink) else: file_srcs = [blocks.file_source(gr.sizeof_char*1, f, False) for f in filenames] for src, sink in zip(file_srcs, uhd_sinks): if iq: node = blocks.multiply_const_cc(1.0/1024) if onebit: self.connect(src, blocks.unpack_k_bits_bb(8), blocks.char_to_short(), # [0, 1] -> [0, 256] blocks.add_const_ss(-128), # [-128, +128], blocks.interleaved_short_to_complex(), # [ -128.0, +128.0] node) # [-0.125, +0.125] else: self.connect(src, # [-128..127] blocks.interleaved_char_to_complex(), # [-128.0, +127.0] node) # [-0.125, +0.125) else: node = blocks.float_to_complex(1) if onebit: self.connect(src, blocks.unpack_k_bits_bb(8), # [0, 1] -> [-0.125, +0.125] blocks.char_to_float(vlen=1, scale=4), blocks.add_const_vff((-0.125, )), node) else: self.connect(src, # [-128..127] -> [-0.125, +0.125) blocks.char_to_float(vlen=1, scale=1024), node) if noise: combiner = blocks.add_vcc(1) self.connect(node, combiner, sink) self.connect(analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise, -222, 8192), (combiner, 1)) else: self.connect(node, sink) print "Setting clocks..." if sync_pps: time.sleep(1.1) # Ensure there's been an edge. TODO: necessary? last_pps_time = uhd_sinks[0].get_time_last_pps() while last_pps_time == uhd_sinks[0].get_time_last_pps(): time.sleep(0.1) print "Got edge" [sink.set_time_next_pps(uhd.time_spec(round(time.time())+1)) for sink in uhd_sinks] time.sleep(1.0) # Wait for edge to set the clocks else: # No external PPS/10 MHz. Just set each clock and accept some skew. t = time.time() [sink.set_time_now(uhd.time_spec(time.time())) for sink in uhd_sinks] if len(uhd_sinks) > 1: print "Uncabled; loosely synced only. Initial skew ~ %.1f ms" % ( (time.time()-t) * 1000) t_start = uhd.time_spec(time.time() + 1.5) [sink.set_start_time(t_start) for sink in uhd_sinks] print "ready"
def __init__(self): gr.top_block.__init__(self, "Demod") # the commented elements below did not work in testing so leave them alone! bitmappings = [ [0, 1, 2, 3], # [ 0, 1, 3, 2], [0, 2, 1, 3], # [ 0, 2, 3, 1], # [ 0, 3, 1, 2], [0, 3, 2, 1], [1, 0, 2, 3], [1, 0, 3, 2], # [ 1, 2, 0, 3], # [ 1, 2, 3, 0], # [ 1, 3, 0, 2], # [ 1, 3, 2, 0], # [ 2, 0, 1, 3], # [ 2, 0, 3, 1], [2, 1, 0, 3], # [ 2, 1, 3, 0], [2, 3, 0, 1], # [ 2, 3, 1, 0], # [ 3, 0, 1, 2], # [ 3, 0, 2, 1], # [ 3, 1, 0, 2], [3, 1, 2, 0], # [ 3, 2, 0, 1], [3, 2, 1, 0], ] constellation_map = random.choice(bitmappings) # override the above for now until figure out how to make the solver work dynamically constellation_map = [2, 3, 0, 1] # sys.stderr.write('{}'.format(constellation_map)) ################################################## # Variables ################################################## self.sps = sps = 8 self.nfilts = nfilts = 32 self.samp_rate = samp_rate = 32000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine( nfilts, nfilts, 1.0 / float(sps), 0.35, 11 * sps * nfilts) self.qpsk = qpsk = digital.constellation_rect(([ 0.707 + 0.707j, -0.707 + 0.707j, -0.707 - 0.707j, 0.707 - 0.707j ]), (constellation_map), 4, 2, 2, 1, 1).base() self.arity = arity = 4 ################################################## # Blocks ################################################## self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf( sps, 62.8e-3, (rrc_taps), nfilts, nfilts / 2, 1.5, 2) self.digital_map_bb_0 = digital.map_bb((constellation_map)) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(4) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( 62.8e-3, arity, False) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( qpsk) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc( 15, 1, 10e-3, 2) self.blocks_wavfile_source_0 = blocks.wavfile_source( sys.argv[1], False) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(2) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1, sys.argv[2], False) self.blocks_file_sink_0.set_unbuffered(False) self.analog_sig_source_x_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -8e3, 1, 0) ################################################## # Connections ################################################## self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_wavfile_source_0, 1), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_cma_equalizer_cc_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.digital_map_bb_0, 0)) self.connect((self.digital_map_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_file_sink_0, 0))
def __init__(self): gr.top_block.__init__(self, "Mpsk Stage6") ################################################## # Variables ################################################## self.sps = sps = 4 self.nfilts = nfilts = 32 self.variable_0 = variable_0 = 0 self.timing_loop_bw = timing_loop_bw = 6.28/100.0 self.time_offset = time_offset = 1.00 self.taps = taps = [1.0, 0.25-0.25j, 0.50 + 0.10j, -0.3 + 0.2j] # ntaps = 7 # taps = numpy.random.random(ntaps-1) + 1j*numpy.random.random(ntaps-1) # self.taps = taps = numpy.concatenate((numpy.ones(1), taps)) # self.taps = taps self.samp_rate = samp_rate = 32000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(sps), 0.35, 11*sps*nfilts) self.qpsk = qpsk = digital.constellation_rect(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.phase_bw = phase_bw = 6.28/100.0 self.noise_volt = noise_volt = 0 self.freq_offset = freq_offset = 0 self.excess_bw = excess_bw = 0.35 self.eq_gain = eq_gain = 0.01 self.delay = delay = 58 self.arity = arity = 4 ################################################## # Blocks ################################################## self.tutorial_my_qpsk_demod_cb_1 = tutorial.my_qpsk_demod_cb(True) self.iq_vector_sink = blocks.vector_sink_c(1) self.raw_vector_sink = blocks.vector_sink_f(1) self.decoded_vector_sink = blocks.vector_sink_f(1) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, timing_loop_bw, (rrc_taps), nfilts, nfilts/2, 1.5, 2) self.digital_map_bb_0 = digital.map_bb(([0,1,3,2])) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(phase_bw, arity, False) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=qpsk, differential=False, samples_per_symbol=sps, pre_diff_code=True, excess_bw=excess_bw, verbose=False, log=False, ) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(15, 1, eq_gain, 2) # snr = 18 # noise_amp = 10**(-snr/10.0) self.channels_channel_model_0 = channels.channel_model( noise_voltage=self.noise_volt, frequency_offset=freq_offset, epsilon=time_offset, taps=(taps), noise_seed=0, block_tags=False ) self.blocks_unpack_k_bits_bb_0_0 = blocks.unpack_k_bits_bb(8) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(2) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_file_sink_0_1 = blocks.file_sink(gr.sizeof_gr_complex*1, 'iq_qpsk.txt', False) self.blocks_file_sink_0_1.set_unbuffered(True) self.blocks_file_sink_0_0_0 = blocks.file_sink(gr.sizeof_float*1, 'decoded_qpsk.txt', False) self.blocks_file_sink_0_0_0.set_unbuffered(False) self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_float*1, 'ground_truth_qpsk.txt', False) self.blocks_file_sink_0_0.set_unbuffered(False) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float*1, 'ber_qpsk.txt', False) self.blocks_file_sink_0.set_unbuffered(True) self.blocks_delay_0_1 = blocks.delay(gr.sizeof_char*1, int(delay)) self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, int(delay)) self.blocks_char_to_float_0_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1) self.blks2_error_rate = grc_blks2.error_rate( type='BER', win_size=int(1e4), bits_per_symbol=1, ) self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 100000)), True) ################################################## # Connections ################################################## self.connect((self.analog_random_source_x_0, 0), (self.blocks_unpack_k_bits_bb_0_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.blks2_error_rate, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.blocks_file_sink_0_0_0, 0)) self.connect((self.blocks_char_to_float_0_0_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_file_sink_0_0, 0)) self.connect((self.blocks_delay_0_1, 0), (self.blks2_error_rate, 1)) self.connect((self.blocks_throttle_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blks2_error_rate, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0_0, 0), (self.blocks_char_to_float_0_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0_0, 0), (self.blocks_delay_0_1, 0)) self.connect((self.channels_channel_model_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.iq_vector_sink, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.decoded_vector_sink, 0)) self.connect((self.blocks_delay_0, 0), (self.raw_vector_sink, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.blocks_file_sink_0_1, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.tutorial_my_qpsk_demod_cb_1, 0)) self.connect((self.digital_map_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_cma_equalizer_cc_0, 0)) self.connect((self.tutorial_my_qpsk_demod_cb_1, 0), (self.digital_map_bb_0, 0))
def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 400000 self.preamble = preamble = [ -0.70711 + 0.70711j, 0.70711 - 0.70711j, -0.70711 + 0.70711j, 0.70711 + 0.70711j, 0.70711 - 0.70711j, 0.70711 - 0.70711j, -0.70711 + 0.70711j, -0.70711 + 0.70711j, -0.70711 - 0.70711j, -0.70711 - 0.70711j, 0.70711 - 0.70711j, 0.70711 + 0.70711j, -0.70711 + 0.70711j, 0.70711 - 0.70711j, 0.70711 - 0.70711j, -0.70711 + 0.70711j, -0.70711 + 0.70711j, 0.70711 + 0.70711j, 0.70711 + 0.70711j, 0.70711 + 0.70711j, -0.70711 - 0.70711j, -0.70711 + 0.70711j, -0.70711 + 0.70711j, -0.70711 - 0.70711j, -0.70711 - 0.70711j, 0.70711 - 0.70711j, 0.70711 + 0.70711j, -0.70711 - 0.70711j, -0.70711 - 0.70711j, 0.70711 - 0.70711j, 0.70711 + 0.70711j, -0.70711 - 0.70711j, 0.70711 + 0.70711j, 0.70711 + 0.70711j, 0.70711 - 0.70711j, -0.70711 + 0.70711j, 0.70711 + 0.70711j, -0.70711 - 0.70711j, 0.70711 - 0.70711j, 0.70711 + 0.70711j] self.audio_rate = audio_rate = 8000 self.audio_interp = audio_interp = 2 self.voice_gain = voice_gain = 0 self.tau = tau = 75e-6 self.rx_channel = rx_channel = 110 self.quadrature_rate = quadrature_rate = audio_rate*audio_interp self.qpsk_constellation = qpsk_constellation = digital.constellation_calcdist(([(sqrt(2)/2)+(sqrt(2)/2)*1j,-(sqrt(2)/2)+(sqrt(2)/2)*1j,(sqrt(2)/2)-(sqrt(2)/2)*1j,-(sqrt(2)/2)-(sqrt(2)/2)*1j]), (digital.psk_4()[1]), 4, 1).base() self.qpsk_constellation.gen_soft_dec_lut(8) self.preamble_size = preamble_size = len(preamble) self.poly_taps = poly_taps = firdes.low_pass(2.0, samp_rate, 20000, 1000, firdes.WIN_HAMMING, 6.76) self.payload_size = payload_size = 100 self.num_channels = num_channels = 4 self.max_deviation = max_deviation = 3500 self.guard_size = guard_size = 10 self.codec_rate = codec_rate = 64000 self.bpsk_rate = bpsk_rate = 400000 ################################################## # Blocks ################################################## self._voice_gain_range = Range(0, 2, 0.01, 0, 200) self._voice_gain_win = RangeWidget(self._voice_gain_range, self.set_voice_gain, "voice_gain", "counter_slider", float) self.top_layout.addWidget(self._voice_gain_win) self.tab2 = Qt.QTabWidget() self.tab2_widget_0 = Qt.QWidget() self.tab2_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab2_widget_0) self.tab2_grid_layout_0 = Qt.QGridLayout() self.tab2_layout_0.addLayout(self.tab2_grid_layout_0) self.tab2.addTab(self.tab2_widget_0, "Preamble Correlation") self.tab2_widget_1 = Qt.QWidget() self.tab2_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab2_widget_1) self.tab2_grid_layout_1 = Qt.QGridLayout() self.tab2_layout_1.addLayout(self.tab2_grid_layout_1) self.tab2.addTab(self.tab2_widget_1, "Received Analog Voice") self.top_grid_layout.addWidget(self.tab2, 1,1,1,1) self._rx_channel_options = (110, 110*2, 110*3, 0, ) self._rx_channel_labels = ("0", "1", "2", "3", ) self._rx_channel_group_box = Qt.QGroupBox("rx_channel") self._rx_channel_box = Qt.QHBoxLayout() class variable_chooser_button_group(Qt.QButtonGroup): def __init__(self, parent=None): Qt.QButtonGroup.__init__(self, parent) @pyqtSlot(int) def updateButtonChecked(self, button_id): self.button(button_id).setChecked(True) self._rx_channel_button_group = variable_chooser_button_group() self._rx_channel_group_box.setLayout(self._rx_channel_box) for i, label in enumerate(self._rx_channel_labels): radio_button = Qt.QRadioButton(label) self._rx_channel_box.addWidget(radio_button) self._rx_channel_button_group.addButton(radio_button, i) self._rx_channel_callback = lambda i: Qt.QMetaObject.invokeMethod(self._rx_channel_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._rx_channel_options.index(i))) self._rx_channel_callback(self.rx_channel) self._rx_channel_button_group.buttonClicked[int].connect( lambda i: self.set_rx_channel(self._rx_channel_options[i])) self.top_layout.addWidget(self._rx_channel_group_box) self.vocoder_ulaw_decode_bs_0 = vocoder.ulaw_decode_bs() self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("serial=309AF9C", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(433e6, 0) self.uhd_usrp_source_0.set_gain(5, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.root_raised_cosine_filter_1 = filter.fir_filter_ccf(2, firdes.root_raised_cosine( 1, bpsk_rate, bpsk_rate/2, 0.35, 101)) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 1024, #size bpsk_rate/2, #samp_rate "Preamble Correlation", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_0.enable_tags(-1, False) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(True) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_control_panel(False) if not False: self.qtgui_time_sink_x_0.disable_legend() labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2*1): if len(labels[i]) == 0: if(i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.tab2_layout_0.addWidget(self._qtgui_time_sink_x_0_win) self.qtgui_time_raster_sink_x_0_0 = qtgui.time_raster_sink_b( codec_rate, 100, (guard_size+payload_size)*num_channels, ([]), ([]), "Received TDM Frame", 1, ) self.qtgui_time_raster_sink_x_0_0.set_update_time(0.10) self.qtgui_time_raster_sink_x_0_0.set_intensity_range(-1, 1) self.qtgui_time_raster_sink_x_0_0.enable_grid(False) labels = ["", "", "", "", "", "", "", "", "", ""] colors = [2, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_raster_sink_x_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_raster_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_raster_sink_x_0_0.set_color_map(i, colors[i]) self.qtgui_time_raster_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_raster_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_raster_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_raster_sink_x_0_0_win, 1,2,1,1) self.qtgui_freq_sink_x_3 = qtgui.freq_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc audio_rate, #bw "Received Analog Voice", #name 1 #number of inputs ) self.qtgui_freq_sink_x_3.set_update_time(0.10) self.qtgui_freq_sink_x_3.set_y_axis(-140, 10) self.qtgui_freq_sink_x_3.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_3.enable_autoscale(False) self.qtgui_freq_sink_x_3.enable_grid(False) self.qtgui_freq_sink_x_3.set_fft_average(1.0) self.qtgui_freq_sink_x_3.enable_control_panel(False) if not False: self.qtgui_freq_sink_x_3.disable_legend() if float == type(float()): self.qtgui_freq_sink_x_3.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_3.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_3.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_3.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_3.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_3.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_3_win = sip.wrapinstance(self.qtgui_freq_sink_x_3.pyqwidget(), Qt.QWidget) self.tab2_layout_1.addWidget(self._qtgui_freq_sink_x_3_win) self.qtgui_freq_sink_x_1 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "Received Spectrum", #name 1 #number of inputs ) self.qtgui_freq_sink_x_1.set_update_time(0.10) self.qtgui_freq_sink_x_1.set_y_axis(-140, 10) self.qtgui_freq_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_1.enable_autoscale(False) self.qtgui_freq_sink_x_1.enable_grid(False) self.qtgui_freq_sink_x_1.set_fft_average(1.0) self.qtgui_freq_sink_x_1.enable_control_panel(False) if not False: self.qtgui_freq_sink_x_1.disable_legend() if complex == type(float()): self.qtgui_freq_sink_x_1.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_1.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_1.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_1.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_1.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_1_win = sip.wrapinstance(self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_1_win, 0,0,1,1) self.digital_map_bb_0_0 = digital.map_bb((digital.psk_4()[1])) self.digital_corr_est_cc_0 = digital.corr_est_cc((preamble), 1, 0, 0.15) self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb(qpsk_constellation) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(2) self.blocks_tagged_stream_align_0 = blocks.tagged_stream_align(gr.sizeof_gr_complex*1, "corr_start") self.blocks_short_to_float_0 = blocks.short_to_float(1, 2000) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((voice_gain, )) self.blocks_keep_m_in_n_1 = blocks.keep_m_in_n(gr.sizeof_char, payload_size, num_channels*(payload_size+guard_size), rx_channel) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, num_channels*(payload_size+guard_size)/2, num_channels*(payload_size+guard_size)/2 + preamble_size, preamble_size) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 2*(num_channels*(payload_size+guard_size)/2+preamble_size)-1) self.audio_sink_0 = audio.sink(8000, "", True) ################################################## # Connections ################################################## self.connect((self.blocks_delay_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.digital_constellation_decoder_cb_0_0, 0)) self.connect((self.blocks_keep_m_in_n_1, 0), (self.vocoder_ulaw_decode_bs_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.blocks_keep_m_in_n_1, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.qtgui_time_raster_sink_x_0_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.qtgui_freq_sink_x_3, 0)) self.connect((self.blocks_tagged_stream_align_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.digital_map_bb_0_0, 0)) self.connect((self.digital_corr_est_cc_0, 0), (self.blocks_tagged_stream_align_0, 0)) self.connect((self.digital_corr_est_cc_0, 1), (self.qtgui_time_sink_x_0, 0)) self.connect((self.digital_map_bb_0_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.root_raised_cosine_filter_1, 0), (self.digital_corr_est_cc_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_freq_sink_x_1, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.root_raised_cosine_filter_1, 0)) self.connect((self.vocoder_ulaw_decode_bs_0, 0), (self.blocks_short_to_float_0, 0))
def __init__(self, constellation, differential=_def_differential, samples_per_symbol=_def_samples_per_symbol, pre_diff_code=True, excess_bw=_def_excess_bw, freq_bw=_def_freq_bw, timing_bw=_def_timing_bw, phase_bw=_def_phase_bw, verbose=_def_verbose, log=_def_log): gr.hier_block2.__init__(self, "generic_demod", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature self._constellation = constellation self._samples_per_symbol = samples_per_symbol self._excess_bw = excess_bw self._phase_bw = phase_bw self._freq_bw = freq_bw self._timing_bw = timing_bw self._timing_max_dev= _def_timing_max_dev self._differential = differential if self._samples_per_symbol < 2: raise TypeError, ("sbp must be >= 2, is %d" % self._samples_per_symbol) # Only apply a predifferential coding if the constellation also supports it. self.pre_diff_code = pre_diff_code and self._constellation.apply_pre_diff_code() arity = pow(2,self.bits_per_symbol()) nfilts = 32 ntaps = 11 * int(self._samples_per_symbol*nfilts) # Automatic gain control self.agc = analog.agc2_cc(0.6e-1, 1e-3, 1, 1, 100) # Frequency correction fll_ntaps = 55 self.freq_recov = digital.fll_band_edge_cc(self._samples_per_symbol, self._excess_bw, fll_ntaps, self._freq_bw) # symbol timing recovery with RRC data filter taps = filter.firdes.root_raised_cosine(nfilts, nfilts*self._samples_per_symbol, 1.0, self._excess_bw, ntaps) self.time_recov = digital.pfb_clock_sync_ccf(self._samples_per_symbol, self._timing_bw, taps, nfilts, nfilts//2, self._timing_max_dev) fmin = -0.25 fmax = 0.25 self.receiver = digital.constellation_receiver_cb( self._constellation.base(), self._phase_bw, fmin, fmax) # Do differential decoding based on phase change of symbols if differential: self.diffdec = digital.diff_decoder_bb(arity) if self.pre_diff_code: self.symbol_mapper = digital.map_bb( mod_codes.invert_code(self._constellation.pre_diff_code())) # unpack the k bit vector into a stream of bits self.unpack = blocks.unpack_k_bits_bb(self.bits_per_symbol()) if verbose: self._print_verbage() if log: self._setup_logging() # Connect and Initialize base class self._blocks = [self, self.agc, self.freq_recov, self.time_recov, self.receiver] if differential: self._blocks.append(self.diffdec) if self.pre_diff_code: self._blocks.append(self.symbol_mapper) self._blocks += [self.unpack, self] self.connect(*self._blocks)
def __init__(self): gr.top_block.__init__(self, "Mpsk Stage3") Qt.QWidget.__init__(self) self.setWindowTitle("Mpsk Stage3") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "mpsk_stage3") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 8 self.payload = payload = range(256) self.nfilts = nfilts = 32 self.timing_loop_bw = timing_loop_bw = 6.28/100.0 self.taps = taps = [1.0 + 0.0j, ] self.samp_rate = samp_rate = 250e3 self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(sps), 0.35, 45*nfilts) self.qpsk_const = qpsk_const = digital.constellation_rect(([-1, +1]), ([0, 1]), 1, 2, 1, 1, 1).base() self.payload_str = payload_str = ''.join(map(lambda x: "{0:08b}".format(x), payload)) self.gain = gain = 50 self.freq = freq = 2.3e9 self.excess_bw = excess_bw = 0.35 self.delay = delay = 32 self.decim = decim = 1 self.arity = arity = 2 self.access_code_str = access_code_str = "1111100110101" self.access_code = access_code = [31, 53] ################################################## # Blocks ################################################## self._delay_layout = Qt.QVBoxLayout() self._delay_tool_bar = Qt.QToolBar(self) self._delay_layout.addWidget(self._delay_tool_bar) self._delay_tool_bar.addWidget(Qt.QLabel("delay"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._delay_counter = qwt_counter_pyslot() self._delay_counter.setRange(0, 100, 1) self._delay_counter.setNumButtons(2) self._delay_counter.setValue(self.delay) self._delay_tool_bar.addWidget(self._delay_counter) self._delay_counter.valueChanged.connect(self.set_delay) self._delay_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._delay_slider.setRange(0, 100, 1) self._delay_slider.setValue(self.delay) self._delay_slider.setMinimumWidth(200) self._delay_slider.valueChanged.connect(self.set_delay) self._delay_layout.addWidget(self._delay_slider) self.top_layout.addLayout(self._delay_layout) self.west_stream_trigged_pdu_0 = west.stream_trigged_pdu("start_payload", 2048) self.west_ber_pdu_0 = west.ber_pdu(payload_str) self._timing_loop_bw_layout = Qt.QVBoxLayout() self._timing_loop_bw_label = Qt.QLabel("Time: BW") self._timing_loop_bw_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._timing_loop_bw_slider.setRange(0.0, 0.2, 0.005) self._timing_loop_bw_slider.setValue(self.timing_loop_bw) self._timing_loop_bw_slider.setMinimumWidth(200) self._timing_loop_bw_slider.valueChanged.connect(self.set_timing_loop_bw) self._timing_loop_bw_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter) self._timing_loop_bw_layout.addWidget(self._timing_loop_bw_label) self._timing_loop_bw_layout.addWidget(self._timing_loop_bw_slider) self.top_grid_layout.addLayout(self._timing_loop_bw_layout, 3,1,1,1) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.qtgui_const_sink_x_1_0 = qtgui.const_sink_c( 1024, #size "Equalizer", #name 1 #number of inputs ) self.qtgui_const_sink_x_1_0.set_update_time(0.10) self.qtgui_const_sink_x_1_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_1_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_1_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_1_0.enable_autoscale(False) self.qtgui_const_sink_x_1_0.enable_grid(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "red", "red", "red", "red", "red", "red", "red", "red"] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_1_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_1_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_1_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_1_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_1_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_1_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_1_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_1_0_win = sip.wrapinstance(self.qtgui_const_sink_x_1_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_x_1_0_win) self.qtgui_const_sink_x_1 = qtgui.const_sink_c( 1024, #size "Clock Sync Output", #name 1 #number of inputs ) self.qtgui_const_sink_x_1.set_update_time(0.10) self.qtgui_const_sink_x_1.set_y_axis(-2, 2) self.qtgui_const_sink_x_1.set_x_axis(-2, 2) self.qtgui_const_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_1.enable_autoscale(False) self.qtgui_const_sink_x_1.enable_grid(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "red", "red", "red", "red", "red", "red", "red", "red"] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_1.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_1.set_line_label(i, labels[i]) self.qtgui_const_sink_x_1.set_line_width(i, widths[i]) self.qtgui_const_sink_x_1.set_line_color(i, colors[i]) self.qtgui_const_sink_x_1.set_line_style(i, styles[i]) self.qtgui_const_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_1_win = sip.wrapinstance(self.qtgui_const_sink_x_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_x_1_win) self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 2048, #size "Costas Loop Output", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0.enable_grid(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "red", "red", "red", "red", "red", "red", "red", "red"] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_0_win, 0,1,1,1) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf( 1, taps=(rrc_taps[:-1]), flt_size=32) self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) self._gain_layout = Qt.QVBoxLayout() self._gain_tool_bar = Qt.QToolBar(self) self._gain_layout.addWidget(self._gain_tool_bar) self._gain_tool_bar.addWidget(Qt.QLabel("RF gain"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._gain_counter = qwt_counter_pyslot() self._gain_counter.setRange(0, 90, 1) self._gain_counter.setNumButtons(2) self._gain_counter.setValue(self.gain) self._gain_tool_bar.addWidget(self._gain_counter) self._gain_counter.valueChanged.connect(self.set_gain) self._gain_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._gain_slider.setRange(0, 90, 1) self._gain_slider.setValue(self.gain) self._gain_slider.setMinimumWidth(200) self._gain_slider.valueChanged.connect(self.set_gain) self._gain_layout.addWidget(self._gain_slider) self.top_layout.addLayout(self._gain_layout) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(.015, 2) self.digital_correlate_access_code_bb_0 = digital.correlate_access_code_bb(access_code_str, 1) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=qpsk_const, differential=True, samples_per_symbol=sps, pre_diff_code=True, excess_bw=excess_bw, verbose=False, log=False, ) (self.digital_constellation_modulator_0).set_processor_affinity([2]) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(qpsk_const) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(16, 1, 0.15/100., 1) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(sps*(1+0.0), 0.25*0.175*0.175, 0.5, 0.175, 0.005) self.blocks_vector_source_x_0_0 = blocks.vector_source_b([135, 201]*5000 + access_code + payload*100000, False, 1, []) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((.0001, )) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_char*1, 1) self.blocks_delay_0 = blocks.delay(gr.sizeof_char*1, int(delay)) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.analog_fastnoise_source_x_0 = analog.fastnoise_source_c(analog.GR_GAUSSIAN, 0.3, 0, 8192) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-1, 1.0, 1) self.analog_agc2_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.analog_fastnoise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_vector_source_x_0_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_vector_source_x_0_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.qtgui_const_sink_x_1, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_cma_equalizer_cc_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.qtgui_const_sink_x_1_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.digital_correlate_access_code_bb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_correlate_access_code_bb_0, 0), (self.west_stream_trigged_pdu_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.digital_correlate_access_code_bb_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.digital_diff_decoder_bb_0, 0)) ################################################## # Asynch Message Connections ################################################## self.msg_connect(self.west_stream_trigged_pdu_0, "pdus", self.west_ber_pdu_0, "pdus")
def __init__(self, n_filts=32, bits_per_sym=2, alpha_probe=0.1, th_probe=0, constellation=digital.constellation_calcdist([-1-1j, 1-1j, 1+1j, -1+1j], [], 4, 1).base(), samp_per_sym=5, bw_costas=2*math.pi/100, bw_clock_sync=2*math.pi/100, bw_fll=2*math.pi/100, len_sym_srrc=11, alfa=0.45): grc_wxgui.top_block_gui.__init__(self, title="Test Hier Rx Usrp") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.n_filts = n_filts self.bits_per_sym = bits_per_sym self.alpha_probe = alpha_probe self.th_probe = th_probe self.constellation = constellation self.samp_per_sym = samp_per_sym self.bw_costas = bw_costas self.bw_clock_sync = bw_clock_sync self.bw_fll = bw_fll self.len_sym_srrc = len_sym_srrc self.alfa = alfa ################################################## # Variables ################################################## self.filtro_srrc = filtro_srrc = firdes.root_raised_cosine(n_filts,samp_per_sym*n_filts,1.0,alfa,samp_per_sym*len_sym_srrc*n_filts) ################################################## # Blocks ################################################## self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.GetWin(), title="Scope Plot", sample_rate=250000/samp_per_sym, v_scale=0.3, v_offset=0, t_scale=0.3, ac_couple=False, xy_mode=True, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(50000*samp_per_sym) self.uhd_usrp_source_0.set_center_freq(850000000, 0) self.uhd_usrp_source_0.set_gain(18, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(samp_per_sym, bw_clock_sync, (filtro_srrc), n_filts, 16, 5, 1) self.digital_mpsk_snr_est_cc_0 = digital.mpsk_snr_est_cc(2, 1000, 0.1) self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc(samp_per_sym, alfa, len_sym_srrc*samp_per_sym, bw_fll) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2**bits_per_sym) self.digital_costas_loop_cc_0_0_0 = digital.costas_loop_cc(bw_costas, 2**bits_per_sym) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constellation) self.blocks_vector_sink_x_0 = blocks.vector_sink_b(1) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_sym) self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_gr_complex*1, "/home/belza/pruebasUSRP/file_rx_sym", False) self.blocks_file_sink_0_0.set_unbuffered(True) self.analog_agc2_xx_0 = analog.agc2_cc(0.6e-1, 1e-3, 2, 15) self.analog_agc2_xx_0.set_max_gain(15) ################################################## # Connections ################################################## self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.digital_fll_band_edge_cc_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_vector_sink_x_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0_0_0, 0)) self.connect((self.digital_costas_loop_cc_0_0_0, 0), (self.blocks_file_sink_0_0, 0)) self.connect((self.digital_costas_loop_cc_0_0_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.digital_costas_loop_cc_0_0_0, 0), (self.digital_mpsk_snr_est_cc_0, 0)) self.connect((self.digital_mpsk_snr_est_cc_0, 0), (self.digital_constellation_decoder_cb_0, 0))
def __init__(self): gr.top_block.__init__(self, "FloripaSat-I Simulation Test") Qt.QWidget.__init__(self) self.setWindowTitle("FloripaSat-I Simulation Test") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "fsat_simulation_test") if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry(self.settings.value("geometry").toByteArray()) else: self.restoreGeometry( self.settings.value("geometry", type=QtCore.QByteArray)) ################################################## # Variables ################################################## self.symbol_rate = symbol_rate = 1.2e3 self.samples_per_symbol = samples_per_symbol = 40 self.sample_rate_tx = sample_rate_tx = symbol_rate * samples_per_symbol * 25 / 6 self.nfilts = nfilts = 32 self.sample_rate_rx = sample_rate_rx = sample_rate_tx * 6 / 5 self.sample_rate = sample_rate = symbol_rate * samples_per_symbol self.rrc_taps = rrc_taps = firdes.root_raised_cosine( nfilts, nfilts, 1.0 / float(40), 0.35, 45 * nfilts) self.pi = pi = numpy.pi self.phase_shift = phase_shift = 0 self.noise_amp = noise_amp = 1e-6 self.modulation_sensitivity = modulation_sensitivity = 4e3 self.freq_shift = freq_shift = 1e3 ################################################## # Blocks ################################################## self.tabs = Qt.QTabWidget() self.tabs_widget_0 = Qt.QWidget() self.tabs_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_0) self.tabs_grid_layout_0 = Qt.QGridLayout() self.tabs_layout_0.addLayout(self.tabs_grid_layout_0) self.tabs.addTab(self.tabs_widget_0, 'Spectrum') self.tabs_widget_1 = Qt.QWidget() self.tabs_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_1) self.tabs_grid_layout_1 = Qt.QGridLayout() self.tabs_layout_1.addLayout(self.tabs_grid_layout_1) self.tabs.addTab(self.tabs_widget_1, 'Time') self.top_layout.addWidget(self.tabs) self.qtgui_time_sink_x_0_0_0_0 = qtgui.time_sink_f( 11200, #size symbol_rate * samples_per_symbol, #samp_rate "Signal", #name 2 #number of inputs ) self.qtgui_time_sink_x_0_0_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0_0_0.set_y_axis(-1.2, 1.2) self.qtgui_time_sink_x_0_0_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0_0_0.set_trigger_mode( qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0_0_0.enable_autoscale(False) self.qtgui_time_sink_x_0_0_0_0.enable_grid(False) self.qtgui_time_sink_x_0_0_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_0_0_0_0.enable_control_panel(False) self.qtgui_time_sink_x_0_0_0_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0_0_0_0.disable_legend() labels = [ "Transmitted", "Received", "Transmitted", '', '', '', '', '', '', '' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_0_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_0_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0_0_0_0.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_0_0_0_win, 3, 0, 7, 1) [self.tabs_grid_layout_1.setRowStretch(r, 1) for r in range(3, 10)] [self.tabs_grid_layout_1.setColumnStretch(c, 1) for c in range(0, 1)] self.qtgui_time_sink_x_0_0_0 = qtgui.time_sink_f( 280, #size symbol_rate * samples_per_symbol, #samp_rate "Message", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0_0.set_y_axis(-1.2, 1.2) self.qtgui_time_sink_x_0_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0_0.enable_autoscale(False) self.qtgui_time_sink_x_0_0_0.enable_grid(False) self.qtgui_time_sink_x_0_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_0_0_0.enable_control_panel(False) self.qtgui_time_sink_x_0_0_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0_0_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [0, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0_0_0.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_0_0_win, 10, 0, 7, 1) [self.tabs_grid_layout_1.setRowStretch(r, 1) for r in range(10, 17)] [self.tabs_grid_layout_1.setColumnStretch(c, 1) for c in range(0, 1)] self.qtgui_freq_sink_x_0_0_0 = qtgui.freq_sink_c( 8192, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc sample_rate, #bw "Received Signal", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0_0_0.set_update_time(0.10) self.qtgui_freq_sink_x_0_0_0.set_y_axis(-180, 10) self.qtgui_freq_sink_x_0_0_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0_0_0.enable_autoscale(False) self.qtgui_freq_sink_x_0_0_0.enable_grid(False) self.qtgui_freq_sink_x_0_0_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0_0_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0_0_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0_0_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0_0_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0_0_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0_0_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0_0_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0_0_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_0_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0_0_0.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_0_0_win, 1, 0, 1, 1) [self.tabs_grid_layout_0.setRowStretch(r, 1) for r in range(1, 2)] [self.tabs_grid_layout_0.setColumnStretch(c, 1) for c in range(0, 1)] self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 8192, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc sample_rate, #bw "Transmitted Signal", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0_0.set_update_time(0.10) self.qtgui_freq_sink_x_0_0.set_y_axis(-180, 10) self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0_0.enable_autoscale(False) self.qtgui_freq_sink_x_0_0.enable_grid(False) self.qtgui_freq_sink_x_0_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_0_win, 0, 0, 1, 1) [self.tabs_grid_layout_0.setRowStretch(r, 1) for r in range(0, 1)] [self.tabs_grid_layout_0.setColumnStretch(c, 1) for c in range(0, 1)] self.qtgui_freq_sink_x_0 = qtgui.freq_sink_f( 8192, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc symbol_rate * samples_per_symbol, #bw "Demodulated Signal", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-180, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "float" == "float" or "float" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.tabs_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 2, 0, 1, 1) [self.tabs_grid_layout_0.setRowStretch(r, 1) for r in range(2, 3)] [self.tabs_grid_layout_0.setColumnStretch(c, 1) for c in range(0, 1)] self._phase_shift_range = Range(0, 2 * pi, 0.01, 0, 200) self._phase_shift_win = RangeWidget(self._phase_shift_range, self.set_phase_shift, "Channel Phase Shift", "counter_slider", float) self.tabs_grid_layout_1.addWidget(self._phase_shift_win, 1, 0, 1, 1) [self.tabs_grid_layout_1.setRowStretch(r, 1) for r in range(1, 2)] [self.tabs_grid_layout_1.setColumnStretch(c, 1) for c in range(0, 1)] self._noise_amp_range = Range(1e-6, 0.1, 1e-6, 1e-6, 200) self._noise_amp_win = RangeWidget(self._noise_amp_range, self.set_noise_amp, "Channel Noise Amplitude", "counter_slider", float) self.tabs_grid_layout_1.addWidget(self._noise_amp_win, 2, 0, 1, 1) [self.tabs_grid_layout_1.setRowStretch(r, 1) for r in range(2, 3)] [self.tabs_grid_layout_1.setColumnStretch(c, 1) for c in range(0, 1)] self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_fff( 1, (firdes.gaussian(1, samples_per_symbol / 2, 0.25, 100))) self.interp_fir_filter_xxx_0.declare_sample_delay(0) self._freq_shift_range = Range(0, 100e3, 1e3, 1e3, 200) self._freq_shift_win = RangeWidget(self._freq_shift_range, self.set_freq_shift, "Channel Frequency Shift", "counter_slider", float) self.tabs_grid_layout_1.addWidget(self._freq_shift_win, 0, 0, 1, 1) [self.tabs_grid_layout_1.setRowStretch(r, 1) for r in range(0, 1)] [self.tabs_grid_layout_1.setColumnStretch(c, 1) for c in range(0, 1)] self.fm_modulator_0 = fm_modulator( modulation_sensitivity=modulation_sensitivity, samp_rate=symbol_rate * samples_per_symbol, ) self.fm_demodulator_0 = fm_demodulator( modulation_sensitivity=modulation_sensitivity, samp_rate=sample_rate, ) self.custom_symbol_sync_early_late_fb_0 = custom.symbol_sync_early_late_fb( samples_per_symbol, 1 / sample_rate, 0.01 * sample_rate, 0.707, 3.22) self.custom_rect_encoder_bf_0 = custom.rect_encoder_bf( samples_per_symbol) self.custom_frame_sync_bb_0 = custom.frame_sync_bb(([ 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0 ]), 32, 3) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, sample_rate, True) self.blocks_file_source_0_0 = blocks.file_source( gr.sizeof_char * 1, '/home/rpa/code/FloripaSat-I-SDR-Receiver/Binary-Files/fsat-hello.bin', True) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) ################################################## # Connections ################################################## self.connect((self.blocks_char_to_float_0, 0), (self.qtgui_time_sink_x_0_0_0, 0)) self.connect((self.blocks_file_source_0_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.fm_demodulator_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.custom_rect_encoder_bf_0, 0)) self.connect((self.custom_frame_sync_bb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.custom_rect_encoder_bf_0, 0), (self.interp_fir_filter_xxx_0, 0)) self.connect((self.custom_symbol_sync_early_late_fb_0, 0), (self.custom_frame_sync_bb_0, 0)) self.connect((self.fm_demodulator_0, 0), (self.custom_symbol_sync_early_late_fb_0, 0)) self.connect((self.fm_demodulator_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.fm_demodulator_0, 0), (self.qtgui_time_sink_x_0_0_0_0, 1)) self.connect((self.fm_modulator_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.fm_modulator_0, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.qtgui_time_sink_x_0_0_0_0, 0))
def __init__(self, freq=0, gain=40, loopbw=100, loopbw_0=100, fllbw=0.002): gr.top_block.__init__(self, "Rx Gui") Qt.QWidget.__init__(self) self.setWindowTitle("Rx Gui") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "rx_gui") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.freq = freq self.gain = gain self.loopbw = loopbw self.loopbw_0 = loopbw_0 self.fllbw = fllbw ################################################## # Variables ################################################## self.sps = sps = 8 self.excess_bw = excess_bw = 0.25 self.target_samp_rate = target_samp_rate = sps*(200e3/(1 + excess_bw)) self.qpsk_const = qpsk_const = digital.constellation_qpsk().base() self.dsp_rate = dsp_rate = 100e6 self.const_choice = const_choice = "qpsk" self.bpsk_const = bpsk_const = digital.constellation_bpsk().base() self.barker_code_two_dim = barker_code_two_dim = [-1.0000 - 1.0000j, -1.0000 - 1.0000j, -1.0000 - 1.0000j, -1.0000 - 1.0000j, -1.0000 - 1.0000j, 1.0000 + 1.0000j, 1.0000 + 1.0000j, -1.0000 - 1.0000j, -1.0000 - 1.0000j, 1.0000 + 1.0000j, -1.0000 - 1.0000j, 1.0000 + 1.0000j, -1.0000 - 1.0000j] self.barker_code_one_dim = barker_code_one_dim = sqrt(2)*numpy.real([-1.0000 - 1.0000j, -1.0000 - 1.0000j, -1.0000 - 1.0000j, -1.0000 - 1.0000j, -1.0000 - 1.0000j, 1.0000 + 1.0000j, 1.0000 + 1.0000j, -1.0000 - 1.0000j, -1.0000 - 1.0000j, 1.0000 + 1.0000j, -1.0000 - 1.0000j, 1.0000 + 1.0000j, -1.0000 - 1.0000j]) self.rrc_delay = rrc_delay = int(round(-44*excess_bw + 33)) self.nfilts = nfilts = 32 self.n_barker_rep = n_barker_rep = 10 self.dec_factor = dec_factor = ceil(dsp_rate/target_samp_rate) self.constellation = constellation = qpsk_const if (const_choice=="qpsk") else bpsk_const self.barker_code = barker_code = barker_code_two_dim if (const_choice == "qpsk") else barker_code_one_dim self.preamble_syms = preamble_syms = numpy.matlib.repmat(barker_code, 1, n_barker_rep)[0] self.n_rrc_taps = n_rrc_taps = rrc_delay * int(sps*nfilts) self.n_codewords = n_codewords = 1 self.even_dec_factor = even_dec_factor = dec_factor if (dec_factor % 1 == 1) else (dec_factor+1) self.const_order = const_order = pow(2,constellation.bits_per_symbol()) self.codeword_len = codeword_len = 18444 self.usrp_rx_addr = usrp_rx_addr = "192.168.10.2" self.samp_rate = samp_rate = dsp_rate/even_dec_factor self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts*sps, 1.0, excess_bw, n_rrc_taps) self.rf_center_freq = rf_center_freq = 1428.4309e6 self.preamble_size = preamble_size = len(preamble_syms) self.pmf_peak_threshold = pmf_peak_threshold = 0.6 self.payload_size = payload_size = codeword_len*n_codewords/int(numpy.log2(const_order)) self.dataword_len = dataword_len = 6144 self.barker_len = barker_len = 13 ################################################## # Blocks ################################################## self.tabs = Qt.QTabWidget() self.tabs_widget_0 = Qt.QWidget() self.tabs_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_0) self.tabs_grid_layout_0 = Qt.QGridLayout() self.tabs_layout_0.addLayout(self.tabs_grid_layout_0) self.tabs.addTab(self.tabs_widget_0, 'PMF Out') self.tabs_widget_1 = Qt.QWidget() self.tabs_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_1) self.tabs_grid_layout_1 = Qt.QGridLayout() self.tabs_layout_1.addLayout(self.tabs_grid_layout_1) self.tabs.addTab(self.tabs_widget_1, 'Abs PMF Out') self.tabs_widget_2 = Qt.QWidget() self.tabs_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_2) self.tabs_grid_layout_2 = Qt.QGridLayout() self.tabs_layout_2.addLayout(self.tabs_grid_layout_2) self.tabs.addTab(self.tabs_widget_2, 'FLL In') self.tabs_widget_3 = Qt.QWidget() self.tabs_layout_3 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_3) self.tabs_grid_layout_3 = Qt.QGridLayout() self.tabs_layout_3.addLayout(self.tabs_grid_layout_3) self.tabs.addTab(self.tabs_widget_3, 'FLL Out') self.tabs_widget_4 = Qt.QWidget() self.tabs_layout_4 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_4) self.tabs_grid_layout_4 = Qt.QGridLayout() self.tabs_layout_4.addLayout(self.tabs_grid_layout_4) self.tabs.addTab(self.tabs_widget_4, 'FLL State') self.tabs_widget_5 = Qt.QWidget() self.tabs_layout_5 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_5) self.tabs_grid_layout_5 = Qt.QGridLayout() self.tabs_layout_5.addLayout(self.tabs_grid_layout_5) self.tabs.addTab(self.tabs_widget_5, 'PFB Sync Out') self.tabs_widget_6 = Qt.QWidget() self.tabs_layout_6 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_6) self.tabs_grid_layout_6 = Qt.QGridLayout() self.tabs_layout_6.addLayout(self.tabs_grid_layout_6) self.tabs.addTab(self.tabs_widget_6, 'Costas State') self.tabs_widget_7 = Qt.QWidget() self.tabs_layout_7 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_7) self.tabs_grid_layout_7 = Qt.QGridLayout() self.tabs_layout_7.addLayout(self.tabs_grid_layout_7) self.tabs.addTab(self.tabs_widget_7, 'Demod Bits') self.tabs_widget_8 = Qt.QWidget() self.tabs_layout_8 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_8) self.tabs_grid_layout_8 = Qt.QGridLayout() self.tabs_layout_8.addLayout(self.tabs_grid_layout_8) self.tabs.addTab(self.tabs_widget_8, 'Costas Sym Out') self.tabs_widget_9 = Qt.QWidget() self.tabs_layout_9 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tabs_widget_9) self.tabs_grid_layout_9 = Qt.QGridLayout() self.tabs_layout_9.addLayout(self.tabs_grid_layout_9) self.tabs.addTab(self.tabs_widget_9, 'Payload Symbols') self.top_layout.addWidget(self.tabs) self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' ) self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(freq, 0) self.rtlsdr_source_0.set_freq_corr(0, 0) self.rtlsdr_source_0.set_dc_offset_mode(0, 0) self.rtlsdr_source_0.set_iq_balance_mode(0, 0) self.rtlsdr_source_0.set_gain_mode(False, 0) self.rtlsdr_source_0.set_gain(gain, 0) self.rtlsdr_source_0.set_if_gain(20, 0) self.rtlsdr_source_0.set_bb_gain(20, 0) self.rtlsdr_source_0.set_antenna('', 0) self.rtlsdr_source_0.set_bandwidth(0, 0) self.qtgui_time_sink_x_2 = qtgui.time_sink_c( preamble_size + payload_size, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_2.set_update_time(0.10) self.qtgui_time_sink_x_2.set_y_axis(-1, 1) self.qtgui_time_sink_x_2.set_y_label('Amplitude', "") self.qtgui_time_sink_x_2.enable_tags(-1, True) self.qtgui_time_sink_x_2.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_2.enable_autoscale(True) self.qtgui_time_sink_x_2.enable_grid(False) self.qtgui_time_sink_x_2.enable_axis_labels(True) self.qtgui_time_sink_x_2.enable_control_panel(False) if not True: self.qtgui_time_sink_x_2.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2*1): if len(labels[i]) == 0: if(i % 2 == 0): self.qtgui_time_sink_x_2.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_2.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_2.set_line_label(i, labels[i]) self.qtgui_time_sink_x_2.set_line_width(i, widths[i]) self.qtgui_time_sink_x_2.set_line_color(i, colors[i]) self.qtgui_time_sink_x_2.set_line_style(i, styles[i]) self.qtgui_time_sink_x_2.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_2.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_2_win = sip.wrapinstance(self.qtgui_time_sink_x_2.pyqwidget(), Qt.QWidget) self.tabs_layout_0.addWidget(self._qtgui_time_sink_x_2_win) self.qtgui_time_sink_x_1_0_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_1_0_0.set_update_time(0.10) self.qtgui_time_sink_x_1_0_0.set_y_axis(-128, 128) self.qtgui_time_sink_x_1_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1_0_0.enable_tags(-1, False) self.qtgui_time_sink_x_1_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1_0_0.enable_autoscale(False) self.qtgui_time_sink_x_1_0_0.enable_grid(False) self.qtgui_time_sink_x_1_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_1_0_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_1_0_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_1_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_1_0_0.pyqwidget(), Qt.QWidget) self.tabs_layout_7.addWidget(self._qtgui_time_sink_x_1_0_0_win) self.qtgui_time_sink_x_1_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_1_0.set_update_time(0.10) self.qtgui_time_sink_x_1_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_1_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1_0.enable_tags(-1, True) self.qtgui_time_sink_x_1_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1_0.enable_autoscale(False) self.qtgui_time_sink_x_1_0.enable_grid(False) self.qtgui_time_sink_x_1_0.enable_axis_labels(True) self.qtgui_time_sink_x_1_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_1_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_1_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_0_win = sip.wrapinstance(self.qtgui_time_sink_x_1_0.pyqwidget(), Qt.QWidget) self.tabs_layout_7.addWidget(self._qtgui_time_sink_x_1_0_win) self.qtgui_time_sink_x_1 = qtgui.time_sink_f( 8192, #size samp_rate, #samp_rate "", #name 3 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.10) self.qtgui_time_sink_x_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1.enable_tags(-1, True) self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1.enable_autoscale(False) self.qtgui_time_sink_x_1.enable_grid(False) self.qtgui_time_sink_x_1.enable_axis_labels(True) self.qtgui_time_sink_x_1.enable_control_panel(False) if not True: self.qtgui_time_sink_x_1.disable_legend() labels = ['FLL Freq (PI Output)', 'FLL Phase Accum', 'FLL Error', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(3): if len(labels[i]) == 0: self.qtgui_time_sink_x_1.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_win = sip.wrapinstance(self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) self.tabs_layout_4.addWidget(self._qtgui_time_sink_x_1_win) self.qtgui_time_sink_x_0_3 = qtgui.time_sink_f( 1024*4, #size samp_rate, #samp_rate "Error", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_3.set_update_time(0.10) self.qtgui_time_sink_x_0_3.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_3.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_3.enable_tags(-1, True) self.qtgui_time_sink_x_0_3.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_3.enable_autoscale(False) self.qtgui_time_sink_x_0_3.enable_grid(False) self.qtgui_time_sink_x_0_3.enable_axis_labels(True) self.qtgui_time_sink_x_0_3.enable_control_panel(False) if not True: self.qtgui_time_sink_x_0_3.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_3.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_3.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_3.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_3.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_3.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_3.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_3.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_3_win = sip.wrapinstance(self.qtgui_time_sink_x_0_3.pyqwidget(), Qt.QWidget) self.tabs_layout_6.addWidget(self._qtgui_time_sink_x_0_3_win) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( preamble_size + payload_size, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(True) self.qtgui_time_sink_x_0_0.enable_grid(False) self.qtgui_time_sink_x_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_0_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_0_0.disable_legend() labels = ['Mag Sq', 'Mag', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.tabs_layout_1.addWidget(self._qtgui_time_sink_x_0_0_win) self.qtgui_sink_x_5 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name True, #plotfreq False, #plotwaterfall False, #plottime True, #plotconst ) self.qtgui_sink_x_5.set_update_time(1.0/10) self._qtgui_sink_x_5_win = sip.wrapinstance(self.qtgui_sink_x_5.pyqwidget(), Qt.QWidget) self.tabs_layout_3.addWidget(self._qtgui_sink_x_5_win) self.qtgui_sink_x_5.enable_rf_freq(False) self.qtgui_sink_x_1 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name True, #plotfreq False, #plotwaterfall False, #plottime True, #plotconst ) self.qtgui_sink_x_1.set_update_time(1.0/10) self._qtgui_sink_x_1_win = sip.wrapinstance(self.qtgui_sink_x_1.pyqwidget(), Qt.QWidget) self.tabs_layout_2.addWidget(self._qtgui_sink_x_1_win) self.qtgui_sink_x_1.enable_rf_freq(False) self.qtgui_sink_x_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name False, #plotfreq False, #plotwaterfall False, #plottime True, #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0/10) self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.tabs_layout_5.addWidget(self._qtgui_sink_x_0_win) self.qtgui_sink_x_0.enable_rf_freq(False) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.tabs_layout_2.addWidget(self._qtgui_freq_sink_x_0_win) self.qtgui_const_sink_x_1 = qtgui.const_sink_c( 1024, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_1.set_update_time(0.10) self.qtgui_const_sink_x_1.set_y_axis(-2, 2) self.qtgui_const_sink_x_1.set_x_axis(-2, 2) self.qtgui_const_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_1.enable_autoscale(False) self.qtgui_const_sink_x_1.enable_grid(False) self.qtgui_const_sink_x_1.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_1.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "red", "red", "red", "red", "red", "red", "red", "red"] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_1.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_1.set_line_label(i, labels[i]) self.qtgui_const_sink_x_1.set_line_width(i, widths[i]) self.qtgui_const_sink_x_1.set_line_color(i, colors[i]) self.qtgui_const_sink_x_1.set_line_style(i, styles[i]) self.qtgui_const_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_1_win = sip.wrapinstance(self.qtgui_const_sink_x_1.pyqwidget(), Qt.QWidget) self.tabs_layout_9.addWidget(self._qtgui_const_sink_x_1_win) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0.enable_autoscale(False) self.qtgui_const_sink_x_0.enable_grid(False) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "red", "red", "red", "red", "red", "red", "red", "red"] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.tabs_layout_8.addWidget(self._qtgui_const_sink_x_0_win) self.mods_turbo_decoder_0 = mods.turbo_decoder(codeword_len, dataword_len) self.mods_frame_sync_fast_0 = mods.frame_sync_fast(pmf_peak_threshold, preamble_size, payload_size, 0, 1, 1, int(const_order)) self.mods_fifo_async_sink_0 = mods.fifo_async_sink('/tmp/async_rx') self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_fff(1, ( numpy.ones(n_barker_rep*barker_len))) self.interp_fir_filter_xxx_0_0.declare_sample_delay(0) self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_ccc(1, ( numpy.flipud(numpy.conj(preamble_syms)))) self.interp_fir_filter_xxx_0.declare_sample_delay(0) self.framers_gr_hdlc_deframer_b_0 = framers.gr_hdlc_deframer_b(0) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, 2*pi/50, (rrc_taps), nfilts, nfilts/2, pi/8, 1) self.digital_map_bb_0_0_0 = digital.map_bb(([1,- 1])) self.digital_fll_band_edge_cc_1 = digital.fll_band_edge_cc(sps, excess_bw, rrc_delay * int(sps) + 1, fllbw) self.digital_descrambler_bb_0 = digital.descrambler_bb(0x21, 0x7F, 16) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(2*pi/loopbw, 2**constellation.bits_per_symbol(), False) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constellation.base()) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(constellation.bits_per_symbol()) self.blocks_rms_xx_1 = blocks.rms_cf(0.0001) self.blocks_pack_k_bits_bb_1 = blocks.pack_k_bits_bb(8) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_multiply_const_vxx_1_1 = blocks.multiply_const_vcc((1.0/sqrt(2), )) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((1.0/(preamble_size*sqrt(2)), )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_divide_xx_1 = blocks.divide_ff(1) self.blocks_divide_xx_0 = blocks.divide_cc(1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_mag_1 = blocks.complex_to_mag(1) self.blocks_char_to_float_0_1 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1) ################################################## # Connections ################################################## self.msg_connect((self.framers_gr_hdlc_deframer_b_0, 'pdu'), (self.mods_fifo_async_sink_0, 'async_pdu')) self.connect((self.blocks_char_to_float_0_0, 0), (self.qtgui_time_sink_x_1_0, 0)) self.connect((self.blocks_char_to_float_0_1, 0), (self.qtgui_time_sink_x_1_0_0, 0)) self.connect((self.blocks_complex_to_mag_1, 0), (self.blocks_divide_xx_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.interp_fir_filter_xxx_0_0, 0)) self.connect((self.blocks_divide_xx_0, 0), (self.digital_fll_band_edge_cc_1, 0)) self.connect((self.blocks_divide_xx_0, 0), (self.qtgui_sink_x_1, 0)) self.connect((self.blocks_divide_xx_1, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_divide_xx_1, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.mods_frame_sync_fast_0, 2)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.qtgui_time_sink_x_2, 0)) self.connect((self.blocks_multiply_const_vxx_1_1, 0), (self.blocks_complex_to_mag_1, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.mods_frame_sync_fast_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_pack_k_bits_bb_1, 0), (self.blocks_char_to_float_0_1, 0)) self.connect((self.blocks_rms_xx_1, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.digital_map_bb_0_0_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.interp_fir_filter_xxx_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.mods_frame_sync_fast_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.digital_costas_loop_cc_0, 1), (self.qtgui_time_sink_x_0_3, 0)) self.connect((self.digital_descrambler_bb_0, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.digital_descrambler_bb_0, 0), (self.blocks_pack_k_bits_bb_1, 0)) self.connect((self.digital_descrambler_bb_0, 0), (self.framers_gr_hdlc_deframer_b_0, 0)) self.connect((self.digital_fll_band_edge_cc_1, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_fll_band_edge_cc_1, 0), (self.qtgui_sink_x_5, 0)) self.connect((self.digital_fll_band_edge_cc_1, 3), (self.qtgui_time_sink_x_1, 2)) self.connect((self.digital_fll_band_edge_cc_1, 1), (self.qtgui_time_sink_x_1, 0)) self.connect((self.digital_fll_band_edge_cc_1, 2), (self.qtgui_time_sink_x_1, 1)) self.connect((self.digital_map_bb_0_0_0, 0), (self.mods_turbo_decoder_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.blocks_multiply_const_vxx_1_1, 0)) self.connect((self.interp_fir_filter_xxx_0_0, 0), (self.blocks_divide_xx_1, 1)) self.connect((self.mods_frame_sync_fast_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.mods_frame_sync_fast_0, 0), (self.qtgui_const_sink_x_1, 0)) self.connect((self.mods_turbo_decoder_0, 0), (self.digital_descrambler_bb_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.blocks_divide_xx_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.blocks_rms_xx_1, 0)) self.connect((self.rtlsdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0))
def __init__(self, hdr_format=digital.header_format_default( digital.packet_utils.default_access_code, 0)): grc_wxgui.top_block_gui.__init__(self, title="QPSK") ################################################## # Parameters ################################################## self.hdr_format = hdr_format ################################################## # Variables ################################################## self.sps = sps = 8 self.excess_bw = excess_bw = 0.35 self.samp_rate = samp_rate = 32000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine( 1, sps, 1, excess_bw, 45) self.qpsk1 = qpsk1 = digital.constellation_qpsk().base() self.our_txt = our_txt = 0 self.code1 = code1 = '010110011011101100010101011111101001001110001011010001101010001' ################################################## # Blocks ################################################## self.wxgui_scopesink2_2 = scopesink2.scope_sink_f( self.GetWin(), title='Scope Plot', sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label='Counts', ) self.Add(self.wxgui_scopesink2_2.win) self.wxgui_scopesink2_0_0 = scopesink2.scope_sink_c( self.GetWin(), title='Scope Plot', sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label='Counts', ) self.Add(self.wxgui_scopesink2_0_0.win) self.pluto_source_0 = iio.pluto_source('ip:pluto.local', int(800000000), int(2084000), int(20000000), 0x8000, True, True, True, "manual", 15, '', True) self.pluto_sink_2 = iio.pluto_sink('ip:pluto.local', int(800000000), int(2084000), int(20000000), 0x8000, False, 0, '', True) self._our_txt_text_box = forms.text_box( parent=self.GetWin(), value=self.our_txt, callback=self.set_our_txt, label='our_txt', converter=forms.str_converter(), ) self.Add(self._our_txt_text_box) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "tab1") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "tab2") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "tab3") self.Add(self.notebook_0) self.low_pass_filter_2 = filter.fir_filter_ccf( 1, firdes.low_pass(1, 2084000, 1000000, 500000, firdes.WIN_HAMMING, 6.76)) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf( sps, 0.0682, (rrc_taps), 64, 16, 1.5, sps) self.digital_map_bb_0 = digital.map_bb(([0, 1, 2, 3])) self.digital_lms_dd_equalizer_cc_0 = digital.lms_dd_equalizer_cc( 21, 0.050, sps, qpsk1) self.digital_diff_decoder_bb_1 = digital.diff_decoder_bb(4) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(0.0628, 4, True) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=qpsk1, differential=True, samples_per_symbol=sps, pre_diff_code=True, excess_bw=excess_bw, verbose=False, log=False, ) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( qpsk1) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(2) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_char * 1, '/Users/cake/Desktop/Projects/plutoSDR/2byte.txt', True) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.blocks_file_sink_1 = blocks.file_sink( gr.sizeof_char * 1, '/Users/cake/Desktop/Projects/plutoSDR/out.txt', False) self.blocks_file_sink_1.set_unbuffered(True) self.blocks_char_to_float_1 = blocks.char_to_float(1, 1) self.blks2_packet_encoder_0_0 = grc_blks2.packet_mod_b( grc_blks2.packet_encoder( samples_per_symbol=1, bits_per_symbol=1, preamble='', access_code=code1, pad_for_usrp=False, ), payload_length=8, ) self.blks2_packet_decoder_0_0 = grc_blks2.packet_demod_b( grc_blks2.packet_decoder( access_code=code1, threshold=-1, callback=lambda ok, payload: self.blks2_packet_decoder_0_0. recv_pkt(ok, payload), ), ) ################################################## # Connections ################################################## self.connect((self.blks2_packet_decoder_0_0, 0), (self.blocks_file_sink_1, 0)) self.connect((self.blks2_packet_encoder_0_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.blocks_char_to_float_1, 0), (self.wxgui_scopesink2_2, 0)) self.connect((self.blocks_file_source_0, 0), (self.blks2_packet_encoder_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blks2_packet_decoder_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_char_to_float_1, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_map_bb_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.pluto_sink_2, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.wxgui_scopesink2_0_0, 0)) self.connect((self.digital_diff_decoder_bb_1, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_lms_dd_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_map_bb_0, 0), (self.digital_diff_decoder_bb_1, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_lms_dd_equalizer_cc_0, 0)) self.connect((self.low_pass_filter_2, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.pluto_source_0, 0), (self.low_pass_filter_2, 0))
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 5 self.afc_gain = 1. self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 1 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## self.src = osmosdr.source( args=options.args ) self.src.set_sample_rate(srate_rx) self.src.set_center_freq(options.frequency, 0) self.src.set_freq_corr(options.ppm, 0) self.src.set_dc_offset_mode(0, 0) self.src.set_iq_balance_mode(0, 0) if options.gain is not None: self.src.set_gain_mode(False, 0) self.src.set_gain(36, 0) else: self.src.set_gain_mode(True, 0) out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, srate_rx) self.channelizer = pfb.channelizer_ccf( self.channels, (firdes.root_raised_cosine(1, srate_rx, 18000, 0.35, 1024)), 36./25., 100) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): squelch = analog.pwr_squelch_cc(0, 0.001, 0, True) mpsk = digital.mpsk_receiver_cc( 4, math.pi/4, math.pi/100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2./math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port)+ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) self.connect((self.channelizer, ch), (squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.squelch.append(squelch) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect( (self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) ################################################## # signal strenght identification ################################################## self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./self.srate_channel) self.pwr_probes.append(pwr_probe) self.connect((self.channelizer, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "Power level for squelch % 5.1f" % pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in self.squelch: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread(target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel/(2*math.pi)) samp_afc = self.srate_channel*self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1./samp_afc*self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_step: continue freq = self.freq_xlating.center_freq + err * self.afc_gain if self.debug: print "err: %f\tfreq: %f" % (err, freq, ) self.freq_xlating.set_center_freq(freq) self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): self.connect((self.channelizer, ch), (self.afc_selector, ch)) self.connect( (self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def main(args): nargs = len(args) if nargs == 1: infile = args[0] outfile = None elif nargs == 2: infile = args[0] outfile = args[1] else: sys.stderr.write("Usage: dvbs-blade.py input_file [output_file]\n") sys.exit(1) symbol_rate = 4500000 samp_rate = symbol_rate * 2 code_rate = dvbs.C1_2 rrc_taps = 20 center_freq = 435000000 txvga1_gain = -4 txvga2_gain = 1 bandwidth = 6000000 tb = gr.top_block() src = blocks.file_source(gr.sizeof_char, infile, True) dvbs_randomizer = dvbs.randomizer_bb() dvbs_reed_solomon_enc = dvbs.reed_solomon_enc_bb() dvbs_interleaver = dvbs.interleaver_bb() blocks_packed_to_unpacked = blocks.packed_to_unpacked_bb( 1, gr.GR_MSB_FIRST) trellis_encoder = trellis.encoder_bb(trellis.fsm(1, 2, (0171, 0133)), 0) blocks_unpack_k_bits = blocks.unpack_k_bits_bb(2) dvbs_puncture = dvbs.puncture_bb(code_rate) blocks_pack_k_bits = blocks.pack_k_bits_bb(2) digital_chunks_to_symbols = digital.chunks_to_symbols_bc(([ complex(0.70710678, 0.70710678), complex(0.70710678, -0.70710678), complex(-0.70710678, 0.70710678), complex(-0.70710678, -0.70710678) ]), 1) interp_fir_filter = filter.interp_fir_filter_ccc( 2, (firdes.root_raised_cosine(1.79, samp_rate, samp_rate / 2, 0.35, rrc_taps))) interp_fir_filter.declare_sample_delay(0) out = osmosdr.sink(args="bladerf=0,buffers=128,buflen=32768") out.set_sample_rate(samp_rate) out.set_center_freq(center_freq, 0) out.set_freq_corr(0, 0) out.set_gain(txvga2_gain, 0) out.set_bb_gain(txvga1_gain, 0) out.set_bandwidth(bandwidth, 0) tb.connect(src, dvbs_randomizer) tb.connect(dvbs_randomizer, dvbs_reed_solomon_enc) tb.connect(dvbs_reed_solomon_enc, dvbs_interleaver) tb.connect(dvbs_interleaver, blocks_packed_to_unpacked) tb.connect(blocks_packed_to_unpacked, trellis_encoder) tb.connect(trellis_encoder, blocks_unpack_k_bits) tb.connect(blocks_unpack_k_bits, dvbs_puncture) tb.connect(dvbs_puncture, blocks_pack_k_bits) tb.connect(blocks_pack_k_bits, digital_chunks_to_symbols) tb.connect(digital_chunks_to_symbols, interp_fir_filter) tb.connect(interp_fir_filter, out) if outfile: dst = blocks.file_sink(gr.sizeof_gr_complex, outfile) tb.connect(interp_fir_filter, dst) tb.run()
def __init__(self): gr.top_block.__init__(self, "Bpsk Sender1") ################################################## # Variables ################################################## self.sps = sps = 8 self.nfilts = nfilts = 32 self.transistion = transistion = 100 self.sideband_rx = sideband_rx = 500 self.sideband = sideband = 500 self.samp_rate = samp_rate = 48000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(sps), 0.35, 11*sps*nfilts) self.qpsk = qpsk = digital.constellation_rect(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.preamble = preamble = [1,-1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,-1] self.payload_size = payload_size = 10 self.interpolation = interpolation = 2000 self.gap = gap = 0 self.eb = eb = 0.35 self.delay = delay = 0 self.decimation = decimation = 1 self.constel = constel = digital.constellation_calcdist(([1,- 1]), ([0,1]), 2, 1).base() self.const_type = const_type = 1 self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.carrier = carrier = 10000 self.arity = arity = 2 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=interpolation, decimation=decimation, taps=None, fractional_bw=None, ) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(1, (firdes.band_pass (0.5,samp_rate,10000-sideband,10000+sideband,transistion)), -carrier, samp_rate) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=constel, differential=True, samples_per_symbol=sps, pre_diff_code=True, excess_bw=0.35, verbose=False, log=False, ) self.blocks_wavfile_sink_1 = blocks.wavfile_sink("BPSK_output.wav", 1, 48000, 16) self.blocks_unpack_k_bits_bb_0_0 = blocks.unpack_k_bits_bb(8) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((0.1, )) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "TestData2", False) self.blocks_file_sink_0_0_0 = blocks.file_sink(gr.sizeof_char*1, "inputBinary", False) self.blocks_file_sink_0_0_0.set_unbuffered(False) self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, "inputBinary2", False) self.blocks_file_sink_0_0.set_unbuffered(False) script, sdelay= argv self.blocks_delay_0_0 = blocks.delay(gr.sizeof_char*1, int(sdelay)) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_file_sink_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_file_sink_0_0_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_unpack_k_bits_bb_0_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_wavfile_sink_1, 0)) self.connect((self.blocks_unpack_k_bits_bb_0_0, 0), (self.blocks_delay_0_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Dvbs Tx") ################################################## # Variables ################################################## self.symbol_rate = symbol_rate = 4500000 self.samp_rate = samp_rate = symbol_rate * 2 self.rrc_taps = rrc_taps = 20 ################################################## # Blocks ################################################## self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=435000000, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=True, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.trellis_encoder_xx_0 = trellis.encoder_bb(trellis.fsm(1, 2, (0171, 0133)), 0) self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + "" ) self.osmosdr_sink_0.set_sample_rate(samp_rate) self.osmosdr_sink_0.set_center_freq(435e6, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(2, 0) self.osmosdr_sink_0.set_if_gain(0, 0) self.osmosdr_sink_0.set_bb_gain(-4, 0) self.osmosdr_sink_0.set_antenna("", 0) self.osmosdr_sink_0.set_bandwidth(6000000, 0) self.fft_filter_xxx_0 = filter.fft_filter_ccc(1, (firdes.root_raised_cosine(1.79, samp_rate, samp_rate/2, 0.35, rrc_taps)), 1) self.fft_filter_xxx_0.declare_sample_delay(0) self.dvbs_reed_solomon_enc_bb_0 = dvbs.reed_solomon_enc_bb() self.dvbs_randomizer_bb_0 = dvbs.randomizer_bb() self.dvbs_puncture_bb_0 = dvbs.puncture_bb(dvbs.C1_2) self.dvbs_modulator_bc_0 = dvbs.modulator_bc() self.dvbs_interleaver_bb_0 = dvbs.interleaver_bb() self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(2) self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(2) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/re/xfer/adv.ts", False) ################################################## # Connections ################################################## self.connect((self.blocks_file_source_0, 0), (self.dvbs_randomizer_bb_0, 0)) self.connect((self.dvbs_randomizer_bb_0, 0), (self.dvbs_reed_solomon_enc_bb_0, 0)) self.connect((self.dvbs_reed_solomon_enc_bb_0, 0), (self.dvbs_interleaver_bb_0, 0)) self.connect((self.dvbs_interleaver_bb_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.trellis_encoder_xx_0, 0)) self.connect((self.trellis_encoder_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.dvbs_puncture_bb_0, 0)) self.connect((self.dvbs_puncture_bb_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.dvbs_modulator_bc_0, 0), (self.fft_filter_xxx_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.dvbs_modulator_bc_0, 0)) self.connect((self.fft_filter_xxx_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.fft_filter_xxx_0, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self): gr.top_block.__init__(self, "Sync Test") Qt.QWidget.__init__(self) self.setWindowTitle("Sync Test") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "sync_test") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.pream_len = pream_len = 84 self.samp_rate = samp_rate = 32000 self.pream = pream = (mapper.preamble_generator(pream_len,511,1033)).get_preamble() self.SNR = SNR = 40 self.Rotation = Rotation = 0 self.Offset = Offset = 0 ################################################## # Blocks ################################################## self._SNR_tool_bar = Qt.QToolBar(self) self._SNR_tool_bar.addWidget(Qt.QLabel("SNR"+": ")) self._SNR_line_edit = Qt.QLineEdit(str(self.SNR)) self._SNR_tool_bar.addWidget(self._SNR_line_edit) self._SNR_line_edit.returnPressed.connect( lambda: self.set_SNR(eng_notation.str_to_num(self._SNR_line_edit.text().toAscii()))) self.top_layout.addWidget(self._SNR_tool_bar) self._Rotation_layout = Qt.QVBoxLayout() self._Rotation_label = Qt.QLabel("Rotation") self._Rotation_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._Rotation_slider.setRange(0, 2*pi, pi/100) self._Rotation_slider.setValue(self.Rotation) self._Rotation_slider.setMinimumWidth(200) self._Rotation_slider.valueChanged.connect(self.set_Rotation) self._Rotation_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter) self._Rotation_layout.addWidget(self._Rotation_label) self._Rotation_layout.addWidget(self._Rotation_slider) self.top_layout.addLayout(self._Rotation_layout) self._Offset_layout = Qt.QVBoxLayout() self._Offset_tool_bar = Qt.QToolBar(self) self._Offset_layout.addWidget(self._Offset_tool_bar) self._Offset_tool_bar.addWidget(Qt.QLabel("Offset"+": ")) self._Offset_counter = Qwt.QwtCounter() self._Offset_counter.setRange(-100, 100, 1) self._Offset_counter.setNumButtons(2) self._Offset_counter.setValue(self.Offset) self._Offset_tool_bar.addWidget(self._Offset_counter) self._Offset_counter.valueChanged.connect(self.set_Offset) self._Offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._Offset_slider.setRange(-100, 100, 1) self._Offset_slider.setValue(self.Offset) self._Offset_slider.setMinimumWidth(200) self._Offset_slider.valueChanged.connect(self.set_Offset) self._Offset_layout.addWidget(self._Offset_slider) self.top_layout.addLayout(self._Offset_layout) self.qtgui_const_sink_x_0_1 = qtgui.const_sink_c( 840-84, #size "QT GUI Plot", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_1.set_update_time(0.10) self.qtgui_const_sink_x_0_1.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_1.set_x_axis(-2, 2) self._qtgui_const_sink_x_0_1_win = sip.wrapinstance(self.qtgui_const_sink_x_0_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_x_0_1_win) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 840-84, #size "QT GUI Plot", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_x_0_win) self.mapper_preamble_sync_cc_0 = mapper.preamble_sync_cc(pream_len*10, (pream), mapper.PSK8, ([0,1,2,3,4,5,6,7]), .97, .90) self.mapper_preamble_insert_bb_0 = mapper.preamble_insert_bb(pream_len*10, (pream)) self.mapper_mapper_0 = mapper.mapper(mapper.PSK8, ([0,1,2,3,4,5,6,7])) self.mapper_demapper_0 = mapper.demapper(mapper.PSK8, ([0,1,2,3,4,5,6,7])) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(1.5*pi/100, 8) self.channels_channel_model_0 = channels.channel_model( noise_voltage=10**(-SNR/20.0), frequency_offset=Offset, epsilon=1.0, taps=(exp( (0 + 1j*Rotation) ), ), noise_seed=0, block_tags=False ) self.blocks_vector_sink_x_0_0 = blocks.vector_sink_b(1) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(3) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate) self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 7, 10000)), True) ################################################## # Connections ################################################## self.connect((self.mapper_preamble_insert_bb_0, 0), (self.mapper_mapper_0, 0)) self.connect((self.mapper_preamble_sync_cc_0, 0), (self.mapper_demapper_0, 0)) self.connect((self.mapper_mapper_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.mapper_preamble_sync_cc_0, 0)) self.connect((self.mapper_preamble_sync_cc_0, 0), (self.qtgui_const_sink_x_0_1, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.mapper_preamble_insert_bb_0, 0)) self.connect((self.mapper_demapper_0, 0), (self.blocks_vector_sink_x_0_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.qtgui_const_sink_x_0, 0))
def __init__(self, frame_size=100, puncpat='11'): gr.top_block.__init__(self, "Fecapi Ldpc Decoders") Qt.QWidget.__init__(self) self.setWindowTitle("Fecapi Ldpc Decoders") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "fecapi_ldpc_decoders") self.restoreGeometry(self.settings.value("geometry", type=QtCore.QByteArray)) ################################################## # Parameters ################################################## self.frame_size = frame_size self.puncpat = puncpat ################################################## # Variables ################################################## self.H = H = fec.ldpc_H_matrix(gr.prefix() + "/share/gnuradio/fec/ldpc/" + "n_0100_k_0042_gap_02.alist", 2) self.G = G = fec.ldpc_G_matrix(gr.prefix() + "/share/gnuradio/fec/ldpc/" + "n_0100_k_0058_gen_matrix.alist") self.samp_rate = samp_rate = 50000 self.ldpc_enc_H = ldpc_enc_H = fec.ldpc_par_mtrx_encoder_make_H(H) self.ldpc_enc_G = ldpc_enc_G = fec.ldpc_gen_mtrx_encoder_make(G) self.ldpc_enc = ldpc_enc = fec.ldpc_encoder_make(gr.prefix() + "/share/gnuradio/fec/ldpc/" + "n_0100_k_0042_gap_02.alist"); self.ldpc_dec_H = ldpc_dec_H = fec.ldpc_bit_flip_decoder.make(H.get_base_sptr(), 100) self.ldpc_dec_G = ldpc_dec_G = fec.ldpc_bit_flip_decoder.make(G.get_base_sptr(), 100) self.ldpc_dec = ldpc_dec = fec.ldpc_decoder.make(gr.prefix() + "/share/gnuradio/fec/ldpc/" + "n_0100_k_0042_gap_02.alist", 0.5, 50); ################################################## # Blocks ################################################## self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 2048, #size samp_rate, #samp_rate '', #name 4 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.01) self.qtgui_time_sink_x_0.set_y_axis(-0.5, 1.5) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = ['Input', 'LDPC (alist)', 'LDPC (H)', 'LDPC (G)', 'CCSDS', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 0.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(4): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win) self.fec_extended_encoder_1_0_0 = fec.extended_encoder(encoder_obj_list=ldpc_enc, threading= None, puncpat=puncpat) self.fec_extended_encoder_1_0 = fec.extended_encoder(encoder_obj_list=ldpc_enc_H, threading= None, puncpat=puncpat) self.fec_extended_encoder_1 = fec.extended_encoder(encoder_obj_list=ldpc_enc_G, threading= None, puncpat=puncpat) self.fec_extended_decoder_0_1_0 = fec.extended_decoder(decoder_obj_list=ldpc_dec, threading= None, ann=None, puncpat=puncpat, integration_period=10000) self.fec_extended_decoder_0_1 = fec.extended_decoder(decoder_obj_list=ldpc_dec_H, threading= None, ann=None, puncpat=puncpat, integration_period=10000) self.fec_extended_decoder_0 = fec.extended_decoder(decoder_obj_list=ldpc_dec_G, threading= None, ann=None, puncpat=puncpat, integration_period=10000) self.digital_map_bb_0_0_0_0 = digital.map_bb(([-1, 1])) self.digital_map_bb_0_0_0 = digital.map_bb(([-1, 1])) self.digital_map_bb_0_0 = digital.map_bb(([-1, 1])) self.blocks_vector_source_x_0_1_0 = blocks.vector_source_b((frame_size/15)*[0, 0, 1, 0, 3, 0, 7, 0, 15, 0, 31, 0, 63, 0, 127], True, 1, []) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate,True) self.blocks_char_to_float_0_2_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_2 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_1 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) ################################################## # Connections ################################################## self.connect((self.blocks_char_to_float_0, 0), (self.fec_extended_decoder_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.qtgui_time_sink_x_0, 3)) self.connect((self.blocks_char_to_float_0_0_0, 0), (self.qtgui_time_sink_x_0, 2)) self.connect((self.blocks_char_to_float_0_0_0_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.blocks_char_to_float_0_1, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_char_to_float_0_2, 0), (self.fec_extended_decoder_0_1, 0)) self.connect((self.blocks_char_to_float_0_2_0, 0), (self.fec_extended_decoder_0_1_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_char_to_float_0_1, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.fec_extended_encoder_1, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.fec_extended_encoder_1_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.fec_extended_encoder_1_0_0, 0)) self.connect((self.blocks_vector_source_x_0_1_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.digital_map_bb_0_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.digital_map_bb_0_0_0, 0), (self.blocks_char_to_float_0_2, 0)) self.connect((self.digital_map_bb_0_0_0_0, 0), (self.blocks_char_to_float_0_2_0, 0)) self.connect((self.fec_extended_decoder_0, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.fec_extended_decoder_0_1, 0), (self.blocks_char_to_float_0_0_0, 0)) self.connect((self.fec_extended_decoder_0_1_0, 0), (self.blocks_char_to_float_0_0_0_0, 0)) self.connect((self.fec_extended_encoder_1, 0), (self.digital_map_bb_0_0, 0)) self.connect((self.fec_extended_encoder_1_0, 0), (self.digital_map_bb_0_0_0, 0)) self.connect((self.fec_extended_encoder_1_0_0, 0), (self.digital_map_bb_0_0_0_0, 0))
def __init__(self): gr.hier_block2.__init__( self, "Hier Tx Ch Rx", gr.io_signature(1, 1, gr.sizeof_char*1), gr.io_signature(1, 1, gr.sizeof_char*1), ) ################################################## # Variables ################################################## self.samp_per_sym = samp_per_sym = 3 self.n_filts = n_filts = 32 self.len_sym_srrc = len_sym_srrc = 7 self.alfa = alfa = 0.35 self.pulso = pulso = firdes.root_raised_cosine(samp_per_sym,samp_per_sym,1.0,alfa,samp_per_sym*len_sym_srrc) self.gain = gain = 15 self.frec = frec = 850e3 self.filtro_srrc = filtro_srrc = firdes.root_raised_cosine(n_filts,samp_per_sym*n_filts,1.0,alfa,samp_per_sym*len_sym_srrc*n_filts) self.bits_per_sym = bits_per_sym = 2 ################################################## # Blocks ################################################## self.pfb_interpolator_ccf_0 = pfb.interpolator_ccf( samp_per_sym, (pulso), 100) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(samp_per_sym, 2*math.pi/100, (filtro_srrc), n_filts, 16, 5, 1) self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc(samp_per_sym, alfa, len_sym_srrc*samp_per_sym, math.pi/1600) self.digital_diff_encoder_bb_0 = digital.diff_encoder_bb(2**bits_per_sym) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2**bits_per_sym) self.digital_costas_loop_cc_0_0_0 = digital.costas_loop_cc(2*math.pi/100, 2**bits_per_sym) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( digital.constellation_calcdist([-1-1j, 1-1j, 1+1j, -1+1j], [], 4, 1).base()) self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc(([-1-1j,1-1j, 1+1j, -1+1j]), 1) self.channels_channel_model_0 = channels.channel_model( noise_voltage=0.0, frequency_offset=0.0, epsilon=1.00, taps=(1+0.5j, ), noise_seed=0, block_tags=False ) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_sym) self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(bits_per_sym, gr.GR_MSB_FIRST) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((0.4, )) self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b(grc_blks2.packet_encoder( samples_per_symbol=samp_per_sym, bits_per_symbol=bits_per_sym, preamble="", access_code="", pad_for_usrp=True, ), payload_length=1, ) self.blks2_packet_decoder_0 = grc_blks2.packet_demod_b(grc_blks2.packet_decoder( access_code="", threshold=-1, callback=lambda ok, payload: self.blks2_packet_decoder_0.recv_pkt(ok, payload), ), ) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.pfb_interpolator_ccf_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.digital_diff_encoder_bb_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0_0, 0), (self.pfb_interpolator_ccf_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.channels_channel_model_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_diff_encoder_bb_0, 0)) self.connect((self.blks2_packet_encoder_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blks2_packet_decoder_0, 0)) self.connect((self.blks2_packet_decoder_0, 0), (self, 0)) self.connect((self, 0), (self.blks2_packet_encoder_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.digital_costas_loop_cc_0_0_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.digital_fll_band_edge_cc_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0_0_0, 0))