Esempio n. 1
0
 def test_003_channel_no_carroffset(self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 0
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0,
                     0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol1 + sync_symbol2 + data_symbol
     channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     sink_chanest = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     tags = sink.tags()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset),
                      tuple(numpy.multiply(data_symbol, channel)))
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value),
                              channel)
     self.assertEqual(sink_chanest.data(), channel)
Esempio n. 2
0
 def test_006_channel_and_carroffset (self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 2
     # Index         0  1  2   3   4  5    6   7  8  9   10  11   12 13 14 15
     sync_symbol1 = (0, 0, 0,  1,  0, 1,  0,  -1, 0, 1,   0, -1,   0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0, 0)
     data_symbol  = (0, 0, 0,  1, -1, 1,  -1,  1, 0, 1,  -1, -1,  -1, 1, 0, 0)
     # Channel       0  1  2  3  4   5   6  7    8   9 10 11   12  13   14  15
     # Shifted      (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1)
     chanest_exp  = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     channel = range(fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     chan_est = None
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             chan_est = pmt.pmt_c32vector_elements(tag.value)
     self.assertEqual(chan_est, chanest_exp)
     self.assertEqual(sink.data(), tuple(numpy.multiply(shift_tuple(data_symbol, carr_offset), channel)))
Esempio n. 3
0
 def test_003_channel_no_carroffset (self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 0
     sync_symbol1 = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j,  1j, 0, 1, -1j, -1, -1j, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol1 + sync_symbol2 + data_symbol
     channel = (0, 0, 0, 2, -2, 2, 3j, 2, 0, 2, 2, 2, 2, 3, 0, 0)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     sink_chanest = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     tags = sink.tags()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), tuple(numpy.multiply(data_symbol, channel)))
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value), channel)
     self.assertEqual(sink_chanest.data(), channel)
Esempio n. 4
0
 def test_004_channel_no_carroffset_1sym (self):
     """ Add a channel, check if it's correctly estimated.
     Only uses 1 synchronisation symbol. """
     fft_len = 16
     carr_offset = 0
     sync_symbol = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol + data_symbol
     channel = (0, 0, 0, 2, 2, 2, 2, 3, 3, 2.5, 2.5, -3, -3, 1j, 1j, 0)
     #channel = (0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1)
     sink = blocks.vector_sink_c(fft_len)
     sink_chanest = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     self.assertEqual(sink_chanest.data(), channel)
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value), channel)
Esempio n. 5
0
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset/2, max_offset/2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len)]
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan= gr.multiply_const_vcc(channel)
     noise = gr.noise_source_c(gr.GR_GAUSSIAN, wgn_amplitude)
     add = gr.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = gr.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(noise, gr.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [0,] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(pmt.pmt_c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i], channel_est[i], places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
Esempio n. 6
0
 def test_006_channel_and_carroffset(self):
     """ Add a channel, check if it's correctly estimated """
     fft_len = 16
     carr_offset = 2
     # Index         0  1  2   3   4  5    6   7  8  9   10  11   12 13 14 15
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1, 0,
                     0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     # Channel       0  1  2  3  4   5   6  7    8   9 10 11   12  13   14  15
     # Shifted      (0, 0, 0, 0, 0, 1j, -1, 1, -1j, 1j, 0, 1, -1j, -1, -1j, 1)
     chanest_exp = (0, 0, 0, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     channel = range(fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.run()
     tags = sink.tags()
     chan_est = None
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             chan_est = pmt.pmt_c32vector_elements(tag.value)
     self.assertEqual(chan_est, chanest_exp)
     self.assertEqual(
         sink.data(),
         tuple(
             numpy.multiply(shift_tuple(data_symbol, carr_offset),
                            channel)))
Esempio n. 7
0
 def test_004_channel_no_carroffset_1sym(self):
     """ Add a channel, check if it's correctly estimated.
     Only uses 1 synchronisation symbol. """
     fft_len = 16
     carr_offset = 0
     sync_symbol = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = sync_symbol + data_symbol
     channel = (0, 0, 0, 2, 2, 2, 2, 3, 3, 2.5, 2.5, -3, -3, 1j, 1j, 0)
     #channel = (0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1)
     sink = blocks.vector_sink_c(fft_len)
     sink_chanest = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, chan, chanest, sink)
     self.tb.connect((chanest, 1), sink_chanest)
     self.tb.run()
     self.assertEqual(sink_chanest.data(), channel)
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             self.assertEqual(pmt.pmt_c32vector_elements(tag.value),
                              channel)
 def test_002_simpledfe (self):
     """ Use the simple DFE equalizer. """
     fft_len = 8
     #           4   5  6  7   0  1  2   3
     tx_data = [-1, -1, 1, 2, -1, 3, 0, -1, # 0
                -1, -1, 0, 2, -1, 2, 0, -1, # 8
                -1, -1, 3, 0, -1, 1, 0, -1, # 16 (Pilot symbols)
                -1, -1, 1, 1, -1, 0, 2, -1] # 24
     cnst = digital.constellation_qpsk()
     tx_signal = [cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data]
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((), (), (1, 2, 6, 7), ())
     pilot_symbols = (
             [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], []
     )
     equalizer = digital.ofdm_equalizer_simpledfe(
         fft_len, cnst.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 0.01
     )
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly...
         0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here!
         0, 0, 1j, 1j, 0, 1j, 1j, 0  # ...and again here.
     ]
     for idx in range(fft_len, 2*fft_len):
         channel[idx] = channel[idx-fft_len] * numpy.exp(1j * .1 * numpy.pi * (numpy.random.rand()-.5))
         idx2 = idx+2*fft_len
         channel[idx2] = channel[idx2] * numpy.exp(1j * 0 * numpy.pi * (numpy.random.rand()-.5))
     len_tag_key = "frame_len"
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(4)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, channel[:fft_len])
     src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key, True)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()]
     self.assertEqual(tx_data, rx_data)
     for tag in sink.tags():
         if pmt.pmt_symbol_to_string(tag.key) == len_tag_key:
             self.assertEqual(pmt.pmt_to_long(tag.value), 4)
         if pmt.pmt_symbol_to_string(tag.key) == "ofdm_sync_chan_taps":
             self.assertComplexTuplesAlmostEqual(list(pmt.pmt_c32vector_elements(tag.value)), channel[-fft_len:], places=1)
Esempio n. 9
0
    def work(self, input_items, output_items):
        num_input_items = len(input_items[0])

        #put code here to process the input items...

        #print all the tags received in this work call
        nread = self.nitems_read(0)
        tags = self.get_tags_in_range(0, nread, nread+num_input_items)
        for tag in tags:
            print tag.offset
            print pmt.pmt_symbol_to_string(tag.key)
            print pmt.pmt_symbol_to_string(tag.value)
            self.key = pmt.pmt_symbol_to_string(tag.key)

        return num_input_items
Esempio n. 10
0
 def test_001_simple (self):
     """ Standard test """
     fft_len = 16
     tx_symbols = range(1, 16);
     tx_symbols = (0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,  0,
                   0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0,
                   0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0,  0)
     expected_result = tuple(range(1, 16)) + (0, 0, 0)
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag,))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "", 0, False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(result_tag.value), n_syms * len(occupied_carriers[0]))
Esempio n. 11
0
 def test_002_with_offset (self):
     """ Standard test, carrier offset """
     fft_len = 16
     tx_symbols = range(1, 16);
     tx_symbols = (0, 0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,
                   0, 0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12,
                   0, 0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0)
     carr_offset = 1 # Compare this with tx_symbols from the previous test
     expected_result = tuple(range(1, 16)) + (0, 0, 0)
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, offsettag))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "", 0, False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 2)
     for tag in sink.tags():
         if pmt.pmt_symbol_to_string(tag.key) == tag_name:
             self.assertEqual(pmt.pmt_to_long(tag.value), n_syms * len(occupied_carriers[0]))
Esempio n. 12
0
 def test_001_simple(self):
     """ Standard test """
     fft_len = 16
     tx_symbols = (0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, 0, 7,
                   8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, 0, 13, 1j,
                   14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0, 0)
     expected_result = tuple(range(1, 16)) + (0, 0, 0)
     occupied_carriers = (
         (1, 3, 4, 11, 12, 14),
         (1, 2, 4, 11, 13, 14),
     )
     n_syms = len(tx_symbols) / fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, ))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers,
                                              tag_name, "", 0, "", False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(result_tag.value),
                      n_syms * len(occupied_carriers[0]))
 def test_004_8bits_formatter_ofdm(self):
     occupied_carriers = ((1, 2, 3, 5, 6, 7), )
     # 3 PDUs: |           |     |         |
     data = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tagname)
     tag1.value = pmt.pmt_from_long(4)
     tag2 = gr.gr_tag_t()
     tag2.offset = 4
     tag2.key = pmt.pmt_string_to_symbol(tagname)
     tag2.value = pmt.pmt_from_long(2)
     tag3 = gr.gr_tag_t()
     tag3.offset = 6
     tag3.key = pmt.pmt_string_to_symbol(tagname)
     tag3.value = pmt.pmt_from_long(4)
     src = gr.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     formatter_object = digital.packet_header_ofdm(occupied_carriers, 1,
                                                   tagname)
     self.assertEqual(formatter_object.header_len(), 6)
     self.assertEqual(
         pmt.pmt_symbol_to_string(formatter_object.len_tag_key()), tagname)
     header = digital.packet_headergenerator_bb(
         formatter_object.formatter(), tagname)
     sink = gr.vector_sink_b()
     self.tb.connect(src, header, sink)
     self.tb.run()
     expected_data = (0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0)
     self.assertEqual(sink.data(), expected_data)
Esempio n. 14
0
def vectors_to_packets(data, tags, lengthtagname, vlen=1):
    lengthtags = [
        t for t in tags if pmt.pmt_symbol_to_string(t.key) == lengthtagname
    ]
    lengths = {}
    for tag in lengthtags:
        if tag.offset in lengths:
            raise ValueError(
                "More than one tags with key {0} with the same offset={1}.".
                format(lengthtagname, tag.offset))
        lengths[tag.offset] = pmt.pmt_to_long(tag.value) * vlen
    if 0 not in lengths:
        raise ValueError(
            "There is no tag with key {0} and an offset of 0".format(
                lengthtagname))
    pos = 0
    packets = []
    while pos < len(data):
        if pos not in lengths:
            raise ValueError(
                "There is no tag with key {0} and an offset of {1}."
                "We were expecting one.".format(lengthtagname, pos))
        length = lengths[pos]
        if length == 0:
            raise ValueError("Packets cannot have zero length.")
        if pos + length > len(data):
            raise ValueError("The final packet is incomplete.")
        packets.append(data[pos:pos + length])
        pos += length
    return packets
 def test_004_8bits_formatter_ofdm (self):
     occupied_carriers = ((1, 2, 3, 5, 6, 7),)
     # 3 PDUs: |           |     |         |
     data   = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tagname)
     tag1.value = pmt.pmt_from_long(4)
     tag2 = gr.gr_tag_t()
     tag2.offset = 4
     tag2.key = pmt.pmt_string_to_symbol(tagname)
     tag2.value = pmt.pmt_from_long(2)
     tag3 = gr.gr_tag_t()
     tag3.offset = 6
     tag3.key = pmt.pmt_string_to_symbol(tagname)
     tag3.value = pmt.pmt_from_long(4)
     src = gr.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     formatter_object = digital.packet_header_ofdm(occupied_carriers, 1, tagname)
     self.assertEqual(formatter_object.header_len(), 6)
     self.assertEqual(pmt.pmt_symbol_to_string(formatter_object.len_tag_key()), tagname)
     header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname)
     sink = gr.vector_sink_b()
     self.tb.connect(src, header, sink)
     self.tb.run()
     expected_data = (
         0, 0, 1, 0, 0, 0,
         0, 1, 0, 0, 0, 0,
         0, 0, 1, 0, 0, 0
     )
     self.assertEqual(sink.data(), expected_data)
 def test_001_simple (self):
     """ Very simple functionality testing """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1,) * fft_len * n_syms
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1,) * fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     # Check data
     self.assertEqual(tx_data, sink.data())
     for tag in sink.tags():
         self.assertEqual(pmt.pmt_symbol_to_string(tag.key), len_tag_key)
         self.assertEqual(pmt.pmt_to_long(tag.value), n_syms)
Esempio n. 17
0
def count_bursts(data, tags, lengthtagname, vlen=1):
    lengthtags = [t for t in tags
                  if pmt.pmt_symbol_to_string(t.key) == lengthtagname]
    lengths = {}
    for tag in lengthtags:
        if tag.offset in lengths:
            raise ValueError(
                "More than one tags with key {0} with the same offset={1}."
                .format(lengthtagname, tag.offset))
        lengths[tag.offset] = pmt.pmt_to_long(tag.value)*vlen
    in_burst = False
    in_packet = False
    packet_length = None
    packet_pos = None
    burst_count = 0
    for pos in range(len(data)):
        if pos in lengths:
            if in_packet:
                print("Got tag at pos {0} current packet_pos is {1}".format(pos, packet_pos))
                raise StandardError("Received packet tag while in packet.")
            packet_pos = -1
            packet_length = lengths[pos]
            in_packet = True
            if not in_burst:
                burst_count += 1
            in_burst = True
        elif not in_packet:
            in_burst = False
        if in_packet:
            packet_pos += 1
            if packet_pos == packet_length-1:
                in_packet = False
                packet_pos = None
    return burst_count
 def test_001b_shifted (self):
     """ Same as before, but shifted, because that's the normal mode in OFDM Rx """
     fft_len = 16
     tx_symbols = (
         0, 0, 0, 0, 0,  0,  1,  2,    0,   3, 4,   5,  0, 0, 0, 0,
         0, 0, 0, 0, 6, 1j,  7,  8,    0,   9, 10, 1j, 11, 0, 0, 0,
         0, 0, 0, 0, 0, 12, 13, 14,    0,  15, 16, 17,  0, 0, 0, 0,
     )
     expected_result = tuple(range(18))
     occupied_carriers = ((13, 14, 15, 1, 2, 3), (-4, -2, -1, 1, 2, 4),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag,))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(result_tag.value), n_syms * len(occupied_carriers[0]))
Esempio n. 19
0
def vectors_to_packets(data, tags, lengthtagname, vlen=1):
    lengthtags = [t for t in tags
                  if pmt.pmt_symbol_to_string(t.key) == lengthtagname]
    lengths = {}
    for tag in lengthtags:
        if tag.offset in lengths:
            raise ValueError(
                "More than one tags with key {0} with the same offset={1}."
                .format(lengthtagname, tag.offset))
        lengths[tag.offset] = pmt.pmt_to_long(tag.value)*vlen
    if 0 not in lengths:
        raise ValueError("There is no tag with key {0} and an offset of 0"
                         .format(lengthtagname))
    pos = 0
    packets = []
    while pos < len(data):
        if pos not in lengths:
            raise ValueError("There is no tag with key {0} and an offset of {1}."
                             "We were expecting one."
                             .format(lengthtagname, pos))
        length = lengths[pos]
        if length == 0:
            raise ValueError("Packets cannot have zero length.")
        if pos+length > len(data):
            raise ValueError("The final packet is incomplete.")
        packets.append(data[pos: pos+length])
        pos += length
    return packets
Esempio n. 20
0
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset / 2, max_offset / 2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [
         rand_range(min_chan_ampl, max_chan_ampl) *
         numpy.exp(1j * rand_range(0, 2 * numpy.pi))
         for x in range(fft_len)
     ]
     src = gr.vector_source_c(tx_data, False, fft_len)
     chan = gr.multiply_const_vcc(channel)
     noise = gr.noise_source_c(gr.GR_GAUSSIAN, wgn_amplitude)
     add = gr.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = gr.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(
         noise, gr.stream_to_vector(gr.sizeof_gr_complex, fft_len),
         (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [
         0,
     ] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(
                 tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(
                 pmt.pmt_c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i],
                                    channel_est[i],
                                    places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est,
                                           -carr_offset_hat)))
Esempio n. 21
0
    def test_000(self):
        num_msgs = 10
        msg_interval = 1000
        msg_list = []
        for i in range(num_msgs):
            msg_list.append(pmt.pmt_from_long(i))

        # Create vector source with dummy data to trigger messages
        src_data = []
        for i in range(num_msgs * msg_interval):
            src_data.append(float(i))
        src = gr.vector_source_f(src_data, False)
        msg_gen = message_generator(msg_list, msg_interval)
        msg_cons = message_consumer()

        # Connect vector source to message gen
        self.tb.connect(src, msg_gen)

        # Connect message generator to message consumer
        self.tb.msg_connect(msg_gen, 'out_port', msg_cons, 'in_port')

        # Verify that the messgae port query functions work
        self.assertEqual(
            pmt.pmt_symbol_to_string(
                pmt.pmt_vector_ref(msg_gen.message_ports_out(), 0)),
            'out_port')
        self.assertEqual(
            pmt.pmt_symbol_to_string(
                pmt.pmt_vector_ref(msg_cons.message_ports_in(), 0)), 'in_port')

        # Run to verify message passing
        self.tb.start()

        # Wait for all messages to be sent
        while msg_gen.msg_ctr < num_msgs:
            time.sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # Verify that the message consumer got all the messages
        self.assertEqual(num_msgs, len(msg_cons.msg_list))
        for i in range(num_msgs):
            self.assertTrue(pmt.pmt_equal(msg_list[i], msg_cons.msg_list[i]))
Esempio n. 22
0
 def test_001_offset_2sym(self):
     """ Add a frequency offset, check if it's correctly detected.
     Also add some random tags and see if they come out at the correct
     position. """
     fft_len = 16
     carr_offset = -2
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol("test_tag_1")
     tag1.value = pmt.pmt_from_long(23)
     tag2 = gr.gr_tag_t()
     tag2.offset = 2
     tag2.key = pmt.pmt_string_to_symbol("test_tag_2")
     tag2.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(tx_data, False, fft_len, (tag1, tag2))
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     detected_tags = {
         'ofdm_sync_carr_offset': False,
         'test_tag_1': False,
         'test_tag_2': False
     }
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'test_tag_1':
             self.assertEqual(tag.offset, 0)
         if pmt.pmt_symbol_to_string(tag.key) == 'test_tag_2':
             self.assertEqual(tag.offset, 0)
         detected_tags[pmt.pmt_symbol_to_string(tag.key)] = True
     self.assertTrue(all(detected_tags.values()))
Esempio n. 23
0
 def test_001_offset_2sym (self):
     """ Add a frequency offset, check if it's correctly detected.
     Also add some random tags and see if they come out at the correct
     position. """
     fft_len = 16
     carr_offset = -2
     sync_symbol1 = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol("test_tag_1")
     tag1.value = pmt.pmt_from_long(23)
     tag2 = gr.gr_tag_t()
     tag2.offset = 2
     tag2.key = pmt.pmt_string_to_symbol("test_tag_2")
     tag2.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(tx_data, False, fft_len, (tag1, tag2))
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     detected_tags = {
             'ofdm_sync_carr_offset': False,
             'test_tag_1': False,
             'test_tag_2': False
     }
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'test_tag_1':
             self.assertEqual(tag.offset, 0)
         if pmt.pmt_symbol_to_string(tag.key) == 'test_tag_2':
             self.assertEqual(tag.offset, 0)
         detected_tags[pmt.pmt_symbol_to_string(tag.key)] = True
     self.assertTrue(all(detected_tags.values()))
    def test_000(self):
        num_msgs = 10
        msg_interval = 1000
        msg_list = []
        for i in range(num_msgs):
            msg_list.append(pmt.pmt_from_long(i))

        # Create vector source with dummy data to trigger messages
        src_data = []
        for i in range(num_msgs*msg_interval):
            src_data.append(float(i))
        src = gr.vector_source_f(src_data, False)
        msg_gen = message_generator(msg_list, msg_interval)
        msg_cons = message_consumer()
        
        # Connect vector source to message gen
        self.tb.connect(src, msg_gen)
        
        # Connect message generator to message consumer
        self.tb.msg_connect(msg_gen, 'out_port', msg_cons, 'in_port')

        # Verify that the messgae port query functions work
        self.assertEqual(pmt.pmt_symbol_to_string(pmt.pmt_vector_ref(
                    msg_gen.message_ports_out(), 0)), 'out_port')
        self.assertEqual(pmt.pmt_symbol_to_string(pmt.pmt_vector_ref(
                    msg_cons.message_ports_in(), 0)), 'in_port')
        
        # Run to verify message passing
        self.tb.start()

        # Wait for all messages to be sent
        while msg_gen.msg_ctr < num_msgs:
            time.sleep(0.5)
        self.tb.stop()
        self.tb.wait()               
        
        # Verify that the message consumer got all the messages
        self.assertEqual(num_msgs, len(msg_cons.msg_list))
        for i in range(num_msgs):
            self.assertTrue(pmt.pmt_equal(msg_list[i], msg_cons.msg_list[i]))
Esempio n. 25
0
def parse_extra_dict(p, info, VERBOSE=False):
    if(pmt.pmt_is_dict(p) is False):
        sys.stderr.write("Extra header is not a PMT dictionary: invalid or corrupt data file.\n")
        sys.exit(1)

    items = pmt.pmt_dict_items(p)
    nitems = pmt.pmt_length(items)
    for i in xrange(nitems):
        item = pmt.pmt_nth(i, items)
        key = pmt.pmt_symbol_to_string(pmt.pmt_car(item))
        val = pmt.pmt_cdr(item)
        info[key] = val
        if(VERBOSE):
            print "{0}: ".format(key)
            pmt.pmt_print(val)

    return info
Esempio n. 26
0
 def test_005_tag_propagation (self):
     """ Make sure tags on the CRC aren't lost. """
     data = (0, 1, 2, 3, 4, 5, 6, 7, 8, 230, 166, 39, 8)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(data))
     testtag = gr.gr_tag_t()
     testtag.offset = len(data)-1
     testtag.key = pmt.pmt_string_to_symbol('tag1')
     testtag.value = pmt.pmt_from_long(0)
     src = gr.vector_source_b(data, False, 1, (tag, testtag))
     crc_check = digital.crc32_bb(True, tag_name)
     sink = gr.vector_sink_b()
     self.tb.connect(src, crc_check, sink)
     self.tb.run()
     self.assertEqual([len(data)-5,], [tag.offset for tag in sink.tags() if pmt.pmt_symbol_to_string(tag.key) == 'tag1'])
Esempio n. 27
0
 def test_003_crc_correct_lentag (self):
     tag_name = "length"
     pack_len = 8
     packets = range(pack_len*2)
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tag_name)
     tag1.value = pmt.pmt_from_long(pack_len)
     tag2 = gr.gr_tag_t()
     tag2.offset = pack_len
     tag2.key = pmt.pmt_string_to_symbol(tag_name)
     tag2.value = pmt.pmt_from_long(pack_len)
     testtag1 = gr.gr_tag_t()
     testtag1.offset = 1
     testtag1.key = pmt.pmt_string_to_symbol("tag1")
     testtag1.value = pmt.pmt_from_long(0)
     testtag2 = gr.gr_tag_t()
     testtag2.offset = pack_len
     testtag2.key = pmt.pmt_string_to_symbol("tag2")
     testtag2.value = pmt.pmt_from_long(0)
     testtag3 = gr.gr_tag_t()
     testtag3.offset = len(packets)-1
     testtag3.key = pmt.pmt_string_to_symbol("tag3")
     testtag3.value = pmt.pmt_from_long(0)
     src = gr.vector_source_b(packets, False, 1, (tag1, tag2, testtag1, testtag2, testtag3))
     crc = digital.crc32_bb(False, tag_name)
     sink = gr.vector_sink_b()
     self.tb.connect(src, crc, sink)
     self.tb.run()
     self.assertEqual(len(sink.data()), 2*(pack_len+4))
     correct_offsets = {'tag1': 1, 'tag2': 12, 'tag3': 19}
     tags_found = {'tag1': False, 'tag2': False, 'tag3': False}
     for tag in sink.tags():
         key = pmt.pmt_symbol_to_string(tag.key)
         if key in correct_offsets.keys():
             tags_found[key] = True
             self.assertEqual(correct_offsets[key], tag.offset)
         if key == tag_name:
             self.assertTrue(tag.offset == 0 or tag.offset == pack_len+4)
     self.assertTrue(all(tags_found.values()))
Esempio n. 28
0
 def test_002_offset_1sym (self):
     """ Add a frequency offset, check if it's correctly detected.
     Difference to previous test is, it only uses one synchronisation symbol. """
     fft_len = 16
     carr_offset = -2
     # This will not correct for +2 because it thinks carrier 14 is used
     # (because of interpolation)
     sync_symbol = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     src = gr.vector_source_c(tx_data, False, fft_len)
     # 17 is out of bounds!
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1, 0, 17)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
Esempio n. 29
0
 def test_002_offset_1sym(self):
     """ Add a frequency offset, check if it's correctly detected.
     Difference to previous test is, it only uses one synchronisation symbol. """
     fft_len = 16
     carr_offset = -2
     # This will not correct for +2 because it thinks carrier 14 is used
     # (because of interpolation)
     sync_symbol = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     src = gr.vector_source_c(tx_data, False, fft_len)
     # 17 is out of bounds!
     chanest = digital.ofdm_chanest_vcvc(sync_symbol, (), 1, 0, 17)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
Esempio n. 30
0
 def test_002_with_offset(self):
     """ Standard test, carrier offset """
     fft_len = 16
     tx_symbols = range(1, 16)
     tx_symbols = (0, 0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, 0,
                   7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, 0, 13,
                   1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0)
     carr_offset = 1  # Compare this with tx_symbols from the previous test
     expected_result = tuple(range(1, 16)) + (0, 0, 0)
     occupied_carriers = (
         (1, 3, 4, 11, 12, 14),
         (1, 2, 4, 11, 13, 14),
     )
     n_syms = len(tx_symbols) / fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, offsettag))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers,
                                              tag_name, "", 0,
                                              "ofdm_sync_carr_offset",
                                              False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 2)
     for tag in sink.tags():
         if pmt.pmt_symbol_to_string(tag.key) == tag_name:
             self.assertEqual(pmt.pmt_to_long(tag.value),
                              n_syms * len(occupied_carriers[0]))
Esempio n. 31
0
    def work(self, input_items, output_items):
        self.state = SEARCH_EOB_IN

        in0 = input_items[0]
        out = output_items[0]

        out[:] = in0[:]

        nread = self.nitems_read(0) #number of items read on port 0
        ninput_items = len(input_items[0])

        #read all tags associated with port 0 for items in this work function
        tags = self.get_tags_in_range(0, nread, nread+ninput_items)

        num_items = min(len(input_items[0]), len(output_items[0]))

        if (len(input_items[0]) > len(output_items[0])):
            print "Burst Gate: Output items small. Might be bad."

        source = pmt.pmt_string_to_symbol("")

        for tag in tags:
            if pmt.pmt_symbol_to_string(tag.key) == "tx_eob":
                self.state = FOUND_EOB_IN
            else:
                self.add_item_tag(0, tag.offset, tag.key, tag.value, source)

        if self.state == FOUND_EOB_IN:
            item_index = num_items #which output item gets the tag?
            offset = self.nitems_written(0) + item_index
            key = pmt.pmt_string_to_symbol("tx_eob")

            value = pmt.pmt_string_to_symbol("")
            source = pmt.pmt_string_to_symbol("")
            self.add_item_tag(0, offset - 1, key, pmt.PMT_T, source)

        return len(out)
Esempio n. 32
0
    def work(self, input_items, output_items):
        self.state = SEARCH_EOB_IN

        in0 = input_items[0]
        out = output_items[0]

        out[:] = in0[:]

        nread = self.nitems_read(0)  #number of items read on port 0
        ninput_items = len(input_items[0])

        #read all tags associated with port 0 for items in this work function
        tags = self.get_tags_in_range(0, nread, nread + ninput_items)

        num_items = min(len(input_items[0]), len(output_items[0]))

        if (len(input_items[0]) > len(output_items[0])):
            print "Burst Gate: Output items small. Might be bad."

        source = pmt.pmt_string_to_symbol("")

        for tag in tags:
            if pmt.pmt_symbol_to_string(tag.key) == "tx_eob":
                self.state = FOUND_EOB_IN
            else:
                self.add_item_tag(0, tag.offset, tag.key, tag.value, source)

        if self.state == FOUND_EOB_IN:
            item_index = num_items  #which output item gets the tag?
            offset = self.nitems_written(0) + item_index
            key = pmt.pmt_string_to_symbol("tx_eob")

            value = pmt.pmt_string_to_symbol("")
            source = pmt.pmt_string_to_symbol("")
            self.add_item_tag(0, offset - 1, key, pmt.PMT_T, source)

        return len(out)
Esempio n. 33
0
def count_bursts(data, tags, lengthtagname, vlen=1):
    lengthtags = [
        t for t in tags if pmt.pmt_symbol_to_string(t.key) == lengthtagname
    ]
    lengths = {}
    for tag in lengthtags:
        if tag.offset in lengths:
            raise ValueError(
                "More than one tags with key {0} with the same offset={1}.".
                format(lengthtagname, tag.offset))
        lengths[tag.offset] = pmt.pmt_to_long(tag.value) * vlen
    in_burst = False
    in_packet = False
    packet_length = None
    packet_pos = None
    burst_count = 0
    for pos in range(len(data)):
        if pos in lengths:
            if in_packet:
                print("Got tag at pos {0} current packet_pos is {1}".format(
                    pos, packet_pos))
                raise StandardError("Received packet tag while in packet.")
            packet_pos = -1
            packet_length = lengths[pos]
            in_packet = True
            if not in_burst:
                burst_count += 1
            in_burst = True
        elif not in_packet:
            in_burst = False
        if in_packet:
            packet_pos += 1
            if packet_pos == packet_length - 1:
                in_packet = False
                packet_pos = None
    return burst_count
Esempio n. 34
0
 def test_005_three_with_tags_trailing (self):
     """ 3 -> 8, trailing bits """
     src_data = (0b101,) + (0b111,) * 4 + (0b001,)
     expected_data = (0b11111101, 0b11111111)
     k = 3
     l = 8
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(src_data))
     src = gr.vector_source_b(src_data, False, 1, (tag,))
     repack = blocks.repack_bits_bb(k, l, tag_name, True)
     sink = gr.vector_sink_b()
     self.tb.connect(src, repack, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_data)
     try:
         out_tag = sink.tags()[0]
     except:
         self.assertFail()
     self.assertEqual(out_tag.offset, 0)
     self.assertEqual(pmt.pmt_symbol_to_string(out_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(out_tag.value), len(expected_data))
 def test_003_t (self):
     """
     more advanced:
     - 6 symbols per carrier
     - 2 pilots per carrier
     - have enough data for nearly 3 OFDM symbols
     - send that twice
     - add some random tags
     """
     tx_symbols = range(1, 16); # 15 symbols
     pilot_symbols = ((1j, 2j), (3j, 4j))
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     pilot_carriers = ((2, 13), (3, 12))
     expected_result = (0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,  0,
                        0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0,
                        0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0,  0)
     fft_len = 16
     tag_name = "len"
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tag_name)
     tag1.value = pmt.pmt_from_long(len(tx_symbols))
     tag2 = gr.gr_tag_t()
     tag2.offset = len(tx_symbols)
     tag2.key = pmt.pmt_string_to_symbol(tag_name)
     tag2.value = pmt.pmt_from_long(len(tx_symbols))
     testtag1 = gr.gr_tag_t()
     testtag1.offset = 0
     testtag1.key = pmt.pmt_string_to_symbol('tag1')
     testtag1.value = pmt.pmt_from_long(0)
     testtag2 = gr.gr_tag_t()
     testtag2.offset = 7 # On the 2nd OFDM symbol
     testtag2.key = pmt.pmt_string_to_symbol('tag2')
     testtag2.value = pmt.pmt_from_long(0)
     testtag3 = gr.gr_tag_t()
     testtag3.offset = len(tx_symbols)+1 # First OFDM symbol of packet 2
     testtag3.key = pmt.pmt_string_to_symbol('tag3')
     testtag3.value = pmt.pmt_from_long(0)
     testtag4 = gr.gr_tag_t()
     testtag4.offset = 2*len(tx_symbols)-1 # Last OFDM symbol of packet 2
     testtag4.key = pmt.pmt_string_to_symbol('tag4')
     testtag4.value = pmt.pmt_from_long(0)
     src = gr.vector_source_c(tx_symbols * 2, False, 1, (tag1, tag2, testtag1, testtag2, testtag3, testtag4))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result * 2)
     tags_found = {'tag1': False, 'tag2': False, 'tag3': False, 'tag4': False}
     correct_offsets = {'tag1': 0, 'tag2': 1, 'tag3': 3, 'tag4': 5}
     for tag in sink.tags():
         key = pmt.pmt_symbol_to_string(tag.key)
         if key in tags_found.keys():
             tags_found[key] = True
             self.assertEqual(correct_offsets[key], tag.offset)
         if key == tag_name:
             self.assertTrue(tag.offset == 0 or tag.offset == 3)
             self.assertTrue(pmt.pmt_to_long(tag.value) == 3)
     self.assertTrue(all(tags_found.values()))
Esempio n. 36
0
 def work(self, input_items, output_items):
     while True:
         msg = self.pop_msg_queue()
         self._msgs.append(pmt.pmt_symbol_to_string(msg.value))
         if len(self._msgs) == self._num: return -1
Esempio n. 37
0
 def test_002_simpledfe(self):
     """ Use the simple DFE equalizer. """
     fft_len = 8
     #           4   5  6  7   0  1  2   3
     tx_data = [
         -1,
         -1,
         1,
         2,
         -1,
         3,
         0,
         -1,  # 0
         -1,
         -1,
         0,
         2,
         -1,
         2,
         0,
         -1,  # 8
         -1,
         -1,
         3,
         0,
         -1,
         1,
         0,
         -1,  # 16 (Pilot symbols)
         -1,
         -1,
         1,
         1,
         -1,
         0,
         2,
         -1
     ]  # 24
     cnst = digital.constellation_qpsk()
     tx_signal = [
         cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data
     ]
     occupied_carriers = ((1, 2, 6, 7), )
     pilot_carriers = ((), (), (1, 2, 6, 7), ())
     pilot_symbols = ([], [],
                      [cnst.map_to_points_v(x)[0]
                       for x in (1, 0, 3, 0)], [])
     equalizer = digital.ofdm_equalizer_simpledfe(fft_len, cnst.base(),
                                                  occupied_carriers,
                                                  pilot_carriers,
                                                  pilot_symbols, 0, 0.01)
     channel = [
         0,
         0,
         1,
         1,
         0,
         1,
         1,
         0,
         0,
         0,
         1,
         1,
         0,
         1,
         1,
         0,  # These coefficients will be rotated slightly...
         0,
         0,
         1j,
         1j,
         0,
         1j,
         1j,
         0,  # Go crazy here!
         0,
         0,
         1j,
         1j,
         0,
         1j,
         1j,
         0  # ...and again here.
     ]
     for idx in range(fft_len, 2 * fft_len):
         channel[idx] = channel[idx - fft_len] * numpy.exp(
             1j * .1 * numpy.pi * (numpy.random.rand() - .5))
         idx2 = idx + 2 * fft_len
         channel[idx2] = channel[idx2] * numpy.exp(
             1j * 0 * numpy.pi * (numpy.random.rand() - .5))
     len_tag_key = "frame_len"
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(4)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, channel[:fft_len])
     src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False,
                              fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            len_tag_key, True)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run()
     rx_data = [
         cnst.decision_maker_v((x, )) if x != 0 else -1
         for x in sink.data()
     ]
     self.assertEqual(tx_data, rx_data)
     for tag in sink.tags():
         if pmt.pmt_symbol_to_string(tag.key) == len_tag_key:
             self.assertEqual(pmt.pmt_to_long(tag.value), 4)
         if pmt.pmt_symbol_to_string(tag.key) == "ofdm_sync_chan_taps":
             self.assertComplexTuplesAlmostEqual(list(
                 pmt.pmt_c32vector_elements(tag.value)),
                                                 channel[-fft_len:],
                                                 places=1)
Esempio n. 38
0
 def work(self, input_items, output_items):
     while True:
         msg = self.pop_msg_queue()
         self._msgs.append(pmt.pmt_symbol_to_string(msg.value))
         if len(self._msgs) == self._num: return -1
Esempio n. 39
0
 def test_001b_shifted(self):
     """ Same as before, but shifted, because that's the normal mode in OFDM Rx """
     fft_len = 16
     tx_symbols = (
         0,
         0,
         0,
         0,
         0,
         0,
         1,
         2,
         0,
         3,
         4,
         5,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         6,
         1j,
         7,
         8,
         0,
         9,
         10,
         1j,
         11,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         12,
         13,
         14,
         0,
         15,
         16,
         17,
         0,
         0,
         0,
         0,
     )
     expected_result = tuple(range(18))
     occupied_carriers = (
         (13, 14, 15, 1, 2, 3),
         (-4, -2, -1, 1, 2, 4),
     )
     n_syms = len(tx_symbols) / fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, ))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers,
                                              tag_name)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(result_tag.value),
                      n_syms * len(occupied_carriers[0]))
 def test_003_t(self):
     """
     more advanced:
     - 6 symbols per carrier
     - 2 pilots per carrier
     - have enough data for nearly 3 OFDM symbols
     - send that twice
     - add some random tags
     """
     tx_symbols = range(1, 16)
     # 15 symbols
     pilot_symbols = ((1j, 2j), (3j, 4j))
     occupied_carriers = (
         (1, 3, 4, 11, 12, 14),
         (1, 2, 4, 11, 13, 14),
     )
     pilot_carriers = ((2, 13), (3, 12))
     expected_result = (0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, 0,
                        7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, 0,
                        13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0, 0)
     fft_len = 16
     tag_name = "len"
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tag_name)
     tag1.value = pmt.pmt_from_long(len(tx_symbols))
     tag2 = gr.gr_tag_t()
     tag2.offset = len(tx_symbols)
     tag2.key = pmt.pmt_string_to_symbol(tag_name)
     tag2.value = pmt.pmt_from_long(len(tx_symbols))
     testtag1 = gr.gr_tag_t()
     testtag1.offset = 0
     testtag1.key = pmt.pmt_string_to_symbol('tag1')
     testtag1.value = pmt.pmt_from_long(0)
     testtag2 = gr.gr_tag_t()
     testtag2.offset = 7  # On the 2nd OFDM symbol
     testtag2.key = pmt.pmt_string_to_symbol('tag2')
     testtag2.value = pmt.pmt_from_long(0)
     testtag3 = gr.gr_tag_t()
     testtag3.offset = len(tx_symbols) + 1  # First OFDM symbol of packet 2
     testtag3.key = pmt.pmt_string_to_symbol('tag3')
     testtag3.value = pmt.pmt_from_long(0)
     testtag4 = gr.gr_tag_t()
     testtag4.offset = 2 * len(
         tx_symbols) - 1  # Last OFDM symbol of packet 2
     testtag4.key = pmt.pmt_string_to_symbol('tag4')
     testtag4.value = pmt.pmt_from_long(0)
     src = gr.vector_source_c(
         tx_symbols * 2, False, 1,
         (tag1, tag2, testtag1, testtag2, testtag3, testtag4))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers,
                                                pilot_carriers,
                                                pilot_symbols, tag_name)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result * 2)
     tags_found = {
         'tag1': False,
         'tag2': False,
         'tag3': False,
         'tag4': False
     }
     correct_offsets = {'tag1': 0, 'tag2': 1, 'tag3': 3, 'tag4': 5}
     for tag in sink.tags():
         key = pmt.pmt_symbol_to_string(tag.key)
         if key in tags_found.keys():
             tags_found[key] = True
             self.assertEqual(correct_offsets[key], tag.offset)
         if key == tag_name:
             self.assertTrue(tag.offset == 0 or tag.offset == 3)
             self.assertTrue(pmt.pmt_to_long(tag.value) == 3)
     self.assertTrue(all(tags_found.values()))