예제 #1
0
 def set_pilot_carriers(self, pilot_carriers):
     self.pilot_carriers = pilot_carriers
     self.set_header_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 0, True))
     self.set_payload_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 0, True))
예제 #2
0
 def set_fft_len(self, fft_len):
     self.fft_len = fft_len
     self.set_fft2(int(self.fft_len / 2))
     self.set_header_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 0, True))
     self.set_payload_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 0, True))
예제 #3
0
 def set_fft_len(self, fft_len):
     self.fft_len = fft_len
     self.set_header_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 0, True))
     self.set_payload_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 0, True))
     self.analog_frequency_modulator_fc_0.set_sensitivity(-2.0 /
                                                          self.fft_len)
     self.blocks_delay_0.set_dly(self.fft_len + self.fft_len // 4)
     self.blocks_keep_m_in_n_0.set_n(self.fft_len)
예제 #4
0
 def test_001b_simple_skip_nothing(self):
     """
     Same as before, but put a skip-header in there
     """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len, symbols_skipped=1)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1, ) * fft_len * n_syms
     len_tag = gr.tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.string_to_symbol(len_tag_key)
     len_tag.value = pmt.from_long(n_syms)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (1, ) * fft_len)
     src = blocks.vector_source_c(tx_data, False, fft_len,
                                  (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            len_tag_key)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run()
     # Check data
     self.assertEqual(tx_data, sink.data())
예제 #5
0
 def set_occupied_carriers(self, occupied_carriers):
     self.occupied_carriers = occupied_carriers
     self.set_bits_per_symbol_0(len(self.occupied_carriers[0]))
     self.set_hdr_format(
         digital.header_format_ofdm(
             self.occupied_carriers,
             1,
             self.length_tag_key,
         ))
     self.set_header_equalizer(
         digital.ofdm_equalizer_simpledfe(self.fft_len, header_mod.base(),
                                          self.occupied_carriers,
                                          self.pilot_carriers,
                                          self.pilot_symbols))
     self.set_header_formatter(
         digital.packet_header_ofdm(
             self.occupied_carriers,
             n_syms=1,
             len_tag_key=self.packet_length_tag_key,
             frame_len_tag_key=self.length_tag_key_0,
             bits_per_header_sym=header_mod.bits_per_symbol(),
             bits_per_payload_sym=8,
             scramble_header=False))
     self.set_payload_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 1))
     self.set_variable_0(len(self.occupied_carriers[0]))
 def test_001b_simple_skip_nothing(self):
     """
     Same as before, but put a skip-header in there
     """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len, symbols_skipped=1)
     n_syms = 3
     tx_data = [
         1,
     ] * fft_len * n_syms
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (1, ) * fft_len)
     src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag, ))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            self.tsb_key)
     sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len,
                                        n_syms, self.tsb_key), eq, sink)
     self.tb.run()
     # Check data
     self.assertEqual(tx_data, sink.data()[0])
 def test_002_static_wo_tags (self):
     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_static(fft_len, occupied_carriers, pilot_carriers, pilot_symbols)
     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))
     src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len)
     sink = blocks.vector_sink_c(fft_len)
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, "", False, 4)
     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)
예제 #8
0
파일: rx_ofdm.py 프로젝트: wes268/course
 def set_active_subcarriers(self, active_subcarriers):
     self.active_subcarriers = active_subcarriers
     self.set_payload_equalizer(
         digital.ofdm_equalizer_static(self.fft_len,
                                       self.active_subcarriers,
                                       self.pilot_carriers_0,
                                       self.pilot_symbols_0, 0, True))
예제 #9
0
 def set_occupied_carriers(self, occupied_carriers):
     self.occupied_carriers = occupied_carriers
     self.set_header_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 0, True))
     self.set_header_formatter(
         digital.packet_header_ofdm(
             self.occupied_carriers,
             n_syms=1,
             len_tag_key=self.packet_length_tag_key,
             frame_len_tag_key=self.length_tag_key,
             bits_per_header_sym=header_mod.bits_per_symbol(),
             bits_per_payload_sym=payload_mod.bits_per_symbol(),
             scramble_header=False))
     self.set_payload_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 0, True))
예제 #10
0
 def set_pilot_carriers(self, pilot_carriers):
     self.pilot_carriers = pilot_carriers
     self.set_header_equalizer(
         digital.ofdm_equalizer_simpledfe(self.fft_len, header_mod.base(),
                                          self.occupied_carriers,
                                          self.pilot_carriers,
                                          self.pilot_symbols))
     self.set_payload_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 1))
예제 #11
0
 def set_fft_len(self, fft_len):
     self.fft_len = fft_len
     self.set_header_equalizer(
         digital.ofdm_equalizer_simpledfe(self.fft_len, header_mod.base(),
                                          self.occupied_carriers,
                                          self.pilot_carriers,
                                          self.pilot_symbols))
     self.set_payload_equalizer(
         digital.ofdm_equalizer_static(self.fft_len, self.occupied_carriers,
                                       self.pilot_carriers,
                                       self.pilot_symbols, 1))
     self.analog_frequency_modulator_fc_0.set_sensitivity(-2.0 /
                                                          self.fft_len)
     self.blocks_delay_0.set_dly(self.fft_len + 0 * (self.fft_len // 4) +
                                 10)
 def test_002_static_wo_tags (self):
     """ Same as before, but the input stream has no tag.
     We specify the frame size in the constructor.
     We also specify a tag key, so the output stream *should* have
     a length tag.
     """
     fft_len = 8
     n_syms = 4
     #           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_static(fft_len, occupied_carriers, pilot_carriers, pilot_symbols)
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly (below)...
         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))
     src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len)
     # We do specify a length tag, it should then appear at the output
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, "frame_len", False, n_syms)
     sink = blocks.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)
     # Check len tag
     tags = sink.tags()
     len_tag = dict()
     for tag in tags:
         ptag = gr.tag_to_python(tag)
         if ptag.key == 'frame_len':
             len_tag[ptag.key] = ptag.value
     self.assertEqual(len_tag, {'frame_len': 4})
 def test_002_static_wo_tags (self):
     """ Same as before, but the input stream has no tag.
     We specify the frame size in the constructor.
     We also specify a tag key, so the output stream *should* have
     a TSB tag.
     """
     fft_len = 8
     n_syms = 4
     #           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_static(fft_len, occupied_carriers, pilot_carriers, pilot_symbols)
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly (below)...
         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))
     src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len)
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key, False, n_syms)
     sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key)
     self.tb.connect(
             src,
             blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key),
             eq,
             sink
     )
     self.tb.run ()
     rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()[0]]
     self.assertEqual(tx_data, rx_data)
     # Check TSB Functionality
     packets = sink.data()
     self.assertEqual(len(packets), 1)
     self.assertEqual(len(packets[0]), len(tx_data))
예제 #14
0
 def test_001c_carrier_offset_no_cp(self):
     """
     Same as before, but put a carrier offset in there
     """
     fft_len = 8
     cp_len = 0
     n_syms = 1
     carr_offset = 1
     occupied_carriers = ((-2, -1, 1, 2), )
     tx_data = (
         0,
         0,
         0,
         -1j,
         -1j,
         0,
         -1j,
         -1j,
     )
     # The rx'd signal is shifted
     rx_expected = (0, 0, 1, 1, 0, 1, 1, 0) * n_syms
     equalizer = digital.ofdm_equalizer_static(fft_len, occupied_carriers)
     len_tag_key = "frame_len"
     len_tag = gr.tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.string_to_symbol(len_tag_key)
     len_tag.value = pmt.from_long(n_syms)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     # Note: this is shifted to the correct position!
     chan_tag.value = pmt.init_c32vector(fft_len,
                                         (0, 0, -1j, -1j, 0, -1j, -1j, 0))
     offset_tag = gr.tag_t()
     offset_tag.offset = 0
     offset_tag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offset_tag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_data, False, fft_len,
                                  (len_tag, chan_tag, offset_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len,
                                            len_tag_key)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run()
     # Check data
     self.assertComplexTuplesAlmostEqual(rx_expected, sink.data(), places=4)
 def test_001_simple (self):
     """ Very simple functionality testing:
     - static equalizer
     - init channel state with all ones
     - transmit all ones
     - make sure we rx all ones
     - Tag check: put in frame length tag and one other random tag,
                  make sure they're propagated
     """
     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.tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.string_to_symbol(len_tag_key)
     len_tag.value = pmt.from_long(n_syms)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (1,) * fft_len)
     random_tag = gr.tag_t()
     random_tag.offset = 1
     random_tag.key = pmt.string_to_symbol("foo")
     random_tag.value = pmt.from_long(42)
     src = blocks.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag, random_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     # Check data
     self.assertEqual(tx_data, sink.data())
     # Check tags
     tag_dict = dict()
     for tag in sink.tags():
         ptag = gr.tag_to_python(tag)
         tag_dict[ptag.key] = ptag.value
     expected_dict = {
             'frame_len': n_syms,
             'foo': 42
     }
     self.assertEqual(tag_dict, expected_dict)
예제 #16
0
 def test_001_simple(self):
     """ Very simple functionality testing:
     - static equalizer
     - init channel state with all ones
     - transmit all ones
     - make sure we rx all ones
     - Tag check: put in frame length tag and one other random tag,
                  make sure they're propagated
     """
     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.tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.string_to_symbol(len_tag_key)
     len_tag.value = pmt.from_long(n_syms)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (1, ) * fft_len)
     random_tag = gr.tag_t()
     random_tag.offset = 1
     random_tag.key = pmt.string_to_symbol("foo")
     random_tag.value = pmt.from_long(42)
     src = blocks.vector_source_c(tx_data, False, fft_len,
                                  (len_tag, chan_tag, random_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            len_tag_key)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run()
     # Check data
     self.assertEqual(tx_data, sink.data())
     # Check tags
     tag_dict = dict()
     for tag in sink.tags():
         ptag = gr.tag_to_python(tag)
         tag_dict[ptag.key] = ptag.value
     expected_dict = {'frame_len': n_syms, 'foo': 42}
     self.assertEqual(tag_dict, expected_dict)
 def test_001c_carrier_offset_cp (self):
     """
     Same as before, but put a carrier offset in there and a CP
     """
     fft_len = 8
     cp_len = 2
     n_syms = 3
     # cp_len/fft_len == 1/4, therefore, the phase is rotated by
     # carr_offset * \pi/2 in every symbol
     occupied_carriers = ((-2, -1, 1, 2),)
     carr_offset = -1
     tx_data = (
             0,-1j,-1j, 0,-1j,-1j, 0, 0,
             0, -1, -1, 0, -1, -1, 0, 0,
             0, 1j, 1j, 0, 1j, 1j, 0, 0,
     )
     # Rx'd signal is corrected
     rx_expected = (0, 0, 1, 1, 0, 1, 1, 0) * n_syms
     equalizer = digital.ofdm_equalizer_static(fft_len, occupied_carriers)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (0, 0, 1, 1, 0, 1, 1, 0))
     offset_tag = gr.tag_t()
     offset_tag.offset = 0
     offset_tag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offset_tag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag, offset_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len, self.tsb_key)
     sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key),
         eq,
         sink
     )
     self.tb.run ()
     # Check data
     self.assertComplexTuplesAlmostEqual(rx_expected, sink.data()[0], places=4)
 def test_001b_simple_skip_nothing (self):
     """
     Same as before, but put a skip-header in there
     """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len, symbols_skipped=1)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1,) * fft_len * n_syms
     len_tag = gr.tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.string_to_symbol(len_tag_key)
     len_tag.value = pmt.from_long(n_syms)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (1,) * fft_len)
     src = blocks.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     # Check data
     self.assertEqual(tx_data, sink.data())
 def test_001c_carrier_offset_no_cp (self):
     """
     Same as before, but put a carrier offset in there
     """
     fft_len = 8
     cp_len = 0
     n_syms = 1
     carr_offset = 1
     occupied_carriers = ((-2, -1, 1, 2),)
     tx_data = (
             0, 0, 0,  -1j,  -1j, 0, -1j, -1j,
     )
     # The rx'd signal is shifted
     rx_expected = (0, 0, 1, 1, 0, 1, 1, 0) * n_syms
     equalizer = digital.ofdm_equalizer_static(fft_len, occupied_carriers)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     # Note: this is shifted to the correct position!
     chan_tag.value = pmt.init_c32vector(fft_len, (0, 0, -1j, -1j, 0, -1j, -1j, 0))
     offset_tag = gr.tag_t()
     offset_tag.offset = 0
     offset_tag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offset_tag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag, offset_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len, self.tsb_key)
     sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key),
         eq,
         sink
     )
     self.tb.run ()
     # Check data
     self.assertComplexTuplesAlmostEqual(rx_expected, sink.data()[0], places=4)
 def test_001b_simple_skip_nothing (self):
     """
     Same as before, but put a skip-header in there
     """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len, symbols_skipped=1)
     n_syms = 3
     tx_data = (1,) * fft_len * n_syms
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (1,) * fft_len)
     src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag,))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key)
     sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key),
         eq,
         sink
     )
     self.tb.run ()
     # Check data
     self.assertEqual(tx_data, sink.data()[0])
예제 #21
0
    def __init__(self):
        gr.top_block.__init__(self, "TX OFDM")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("TX OFDM")
        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", "tx_ofdm_papr")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.fft_len = fft_len = 256
        self.fft2 = fft2 = int(fft_len / 2)
        self.pilot_symbols = pilot_symbols = ((
            1,
            1,
            1,
            -1,
        ), )
        self.pilot_carriers = pilot_carriers = ((
            -21,
            -7,
            7,
            21,
        ), )
        self.payload_mod = payload_mod = digital.constellation_qpsk()
        self.packet_length_tag_key = packet_length_tag_key = "packet_len"
        self.occupied_carriers = occupied_carriers = (
            list(range(-fft2, 0)) + list(range(1, fft2 + 1)), )
        self.num_syms = num_syms = 16
        self.length_tag_key = length_tag_key = "frame_len"
        self.header_mod = header_mod = digital.constellation_bpsk()
        self.tx_amp = tx_amp = 1
        self.sync_word2 = sync_word2 = [
            0j, 0j, 0j, 0j, 0j, 0j, (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j),
            (1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j),
            (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (-1 + 0j), (1 + 0j), (-1 + 0j), 0j, (1 + 0j), (-1 + 0j),
            (1 + 0j), (1 + 0j), (1 + 0j), (-1 + 0j), (1 + 0j), (1 + 0j),
            (1 + 0j), (-1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j),
            0j, 0j, 0j, 0j, 0j
        ]
        self.sync_word1 = sync_word1 = [
            0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0.,
            1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0.,
            1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0.,
            -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            0., 0., 0., 0., 0.
        ]
        self.samp_rate = samp_rate = 1e6
        self.rx_gain = rx_gain = 30
        self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_static(
            fft_len, occupied_carriers, pilot_carriers, pilot_symbols, 0, True)
        self.packet_len = packet_len = int(96 / 8 * num_syms)
        self.offset = offset = 8
        self.header_formatter = header_formatter = digital.packet_header_ofdm(
            occupied_carriers,
            n_syms=1,
            len_tag_key=packet_length_tag_key,
            frame_len_tag_key=length_tag_key,
            bits_per_header_sym=header_mod.bits_per_symbol(),
            bits_per_payload_sym=payload_mod.bits_per_symbol(),
            scramble_header=False)
        self.header_equalizer = header_equalizer = digital.ofdm_equalizer_static(
            fft_len, occupied_carriers, pilot_carriers, pilot_symbols, 0, True)
        self.freqc = freqc = 900e6
        self.frame_len = frame_len = 4096

        ##################################################
        # Blocks
        ##################################################
        self._tx_amp_range = Range(0, 2, .001, 1, 200)
        self._tx_amp_win = RangeWidget(self._tx_amp_range, self.set_tx_amp,
                                       'TX Amplitude', "counter_slider", float)
        self.top_grid_layout.addWidget(self._tx_amp_win, 1, 0, 1, 8)
        for r in range(1, 2):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._rx_gain_range = Range(0, 64, 1, 30, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain,
                                        'RX Gain', "counter_slider", float)
        self.top_grid_layout.addWidget(self._rx_gain_win, 0, 0, 1, 8)
        for r in range(0, 1):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.wes_max_ff_0 = wes.max_ff(frame_len)
        self.qtgui_number_sink_0_1 = qtgui.number_sink(gr.sizeof_float, 0,
                                                       qtgui.NUM_GRAPH_HORIZ,
                                                       1)
        self.qtgui_number_sink_0_1.set_update_time(0.10)
        self.qtgui_number_sink_0_1.set_title('PAPR (dB)')

        labels = ['', '', '', '', '', '', '', '', '', '']
        units = ['', '', '', '', '', '', '', '', '', '']
        colors = [("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black")]
        factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

        for i in range(1):
            self.qtgui_number_sink_0_1.set_min(i, -1)
            self.qtgui_number_sink_0_1.set_max(i, 1)
            self.qtgui_number_sink_0_1.set_color(i, colors[i][0], colors[i][1])
            if len(labels[i]) == 0:
                self.qtgui_number_sink_0_1.set_label(i, "Data {0}".format(i))
            else:
                self.qtgui_number_sink_0_1.set_label(i, labels[i])
            self.qtgui_number_sink_0_1.set_unit(i, units[i])
            self.qtgui_number_sink_0_1.set_factor(i, factor[i])

        self.qtgui_number_sink_0_1.enable_autoscale(False)
        self._qtgui_number_sink_0_1_win = sip.wrapinstance(
            self.qtgui_number_sink_0_1.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_number_sink_0_1_win, 11, 4,
                                       1, 4)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(4, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 0,
                                                     qtgui.NUM_GRAPH_HORIZ, 1)
        self.qtgui_number_sink_0.set_update_time(0.10)
        self.qtgui_number_sink_0.set_title('PAPR')

        labels = ['', '', '', '', '', '', '', '', '', '']
        units = ['', '', '', '', '', '', '', '', '', '']
        colors = [("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black")]
        factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

        for i in range(1):
            self.qtgui_number_sink_0.set_min(i, -1)
            self.qtgui_number_sink_0.set_max(i, 1)
            self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1])
            if len(labels[i]) == 0:
                self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i))
            else:
                self.qtgui_number_sink_0.set_label(i, labels[i])
            self.qtgui_number_sink_0.set_unit(i, units[i])
            self.qtgui_number_sink_0.set_factor(i, factor[i])

        self.qtgui_number_sink_0.enable_autoscale(False)
        self._qtgui_number_sink_0_win = sip.wrapinstance(
            self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_number_sink_0_win, 11, 0, 1,
                                       4)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate * 2,  #bw
            "",  #name
            1)
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-120, -40)
        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(True)
        self.qtgui_freq_sink_x_0.set_fft_average(0.1)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(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 range(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.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 2, 0, 8,
                                       8)
        for r in range(2, 10):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.iio_pluto_source_0 = iio.pluto_source('usb:1.4.5', int(freqc),
                                                   int(samp_rate * 2),
                                                   20000000, 32768, True, True,
                                                   True, 'manual', rx_gain, '',
                                                   True)
        self.iio_pluto_sink_0 = iio.pluto_sink('usb:1.3.5', int(freqc),
                                               int(samp_rate), 20000000, 32768,
                                               False, 10.0, '', True)
        self.digital_ofdm_tx_0 = digital.ofdm_tx(
            fft_len=fft_len,
            cp_len=fft_len // 4,
            packet_length_tag_key=packet_length_tag_key,
            occupied_carriers=occupied_carriers,
            bps_header=2,
            bps_payload=2,
            rolloff=0,
            debug_log=False,
            scramble_bits=False)
        self.blocks_vector_source_x_0 = blocks.vector_source_b((1, 1, 1, 1),
                                                               True, 1, [])
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(
            gr.sizeof_char, 1, packet_len, packet_length_tag_key)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(tx_amp /
                                                                    30)
        self.blocks_moving_average_xx_0_0 = blocks.moving_average_ff(
            frame_len, 1 / frame_len, frame_len * 4, 1)
        self.blocks_moving_average_xx_0 = blocks.moving_average_ff(
            frame_len, 1 / frame_len, frame_len * 4, 1)
        self.blocks_divide_xx_0 = blocks.divide_ff(1)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_squared_0, 0),
                     (self.blocks_moving_average_xx_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0),
                     (self.wes_max_ff_0, 0))
        self.connect((self.blocks_divide_xx_0, 0),
                     (self.blocks_moving_average_xx_0_0, 0))
        self.connect((self.blocks_moving_average_xx_0, 0),
                     (self.blocks_divide_xx_0, 1))
        self.connect((self.blocks_moving_average_xx_0_0, 0),
                     (self.blocks_nlog10_ff_0, 0))
        self.connect((self.blocks_moving_average_xx_0_0, 0),
                     (self.qtgui_number_sink_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.iio_pluto_sink_0, 0))
        self.connect((self.blocks_nlog10_ff_0, 0),
                     (self.qtgui_number_sink_0_1, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0),
                     (self.digital_ofdm_tx_0, 0))
        self.connect((self.blocks_vector_source_x_0, 0),
                     (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.digital_ofdm_tx_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.iio_pluto_source_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.wes_max_ff_0, 0), (self.blocks_divide_xx_0, 0))
예제 #22
0
    def __init__(self, doc, ip="127.0.0.1"):
        gr.top_block.__init__(self, "RL Demod training")
        self.doc = doc
        self.plot_lst = []
        self.widget_lst = []

        ##################################################
        # Parameters
        ##################################################
        self.ip = ip

        ##################################################
        # Variables
        ##################################################
        self.pilot_symbols = pilot_symbols = ((
            1,
            1,
            1,
            -1,
        ), )
        self.pilot_carriers = pilot_carriers = ((
            -21,
            -7,
            7,
            21,
        ), )
        self.packet_length_tag_key = packet_length_tag_key = "packet_length"
        self.occupied_carriers = occupied_carriers = (
            list(range(-22, -21)) + list(range(-20, -7)) + list(range(-6, 0)) +
            list(range(1, 7)) + list(range(8, 21)) + list(range(22, 23)), )
        self.length_tag_key_0 = length_tag_key_0 = "frame_len"
        self.length_tag_key = length_tag_key = "packet_len"
        self.header_mod = header_mod = digital.constellation_bpsk()
        self.fft_len = fft_len = 64
        self.errors = errors = 0
        self.bits_per_symbol = bits_per_symbol = 4
        self.ber = ber = 0
        self.variable_qtgui_label_0_0_val = variable_qtgui_label_0_0 = ber
        self.variable_qtgui_label_0_val = variable_qtgui_label_0 = errors
        self.variable_0 = variable_0 = len(occupied_carriers[0])
        self.training_mod = training_mod = 1
        self.timestamp = timestamp = '1'
        self.t_state = t_state = 1
        self.sync_word2 = sync_word2 = [
            0, 0, 0, 0, 0, 0, -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, 0, 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, 0, 0, 0, 0, 0
        ]
        self.sync_word1 = sync_word1 = [
            0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0.,
            1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0.,
            1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0.,
            -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            0., 0., 0., 0., 0.
        ]
        self.snr_stop = snr_stop = 29
        self.snr_step = snr_step = 0.5
        self.snr_start = snr_start = 0
        self.samp_rate = samp_rate = 0.3e6
        self.rx_lr = rx_lr = -2
        self.rolloff = rolloff = 0
        self.puncpat = puncpat = '11'
        self.payload_mod = payload_mod = digital.qam_constellation(
            constellation_points=2**bits_per_symbol)
        self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_static(
            fft_len, occupied_carriers, pilot_carriers, pilot_symbols, 1)
        self.packet_len = packet_len = 400
        self.mag = mag = 10
        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 = ldpc_dec = fec.ldpc_decoder.make(
            gr.prefix() + "/share/gnuradio/fec/ldpc/" +
            "n_0100_k_0042_gap_02.alist", 0.5, 50)
        self.header_formatter = header_formatter = digital.packet_header_ofdm(
            occupied_carriers,
            n_syms=1,
            len_tag_key=packet_length_tag_key,
            frame_len_tag_key=length_tag_key_0,
            bits_per_header_sym=header_mod.bits_per_symbol(),
            bits_per_payload_sym=8,
            scramble_header=False)
        self.header_equalizer = header_equalizer = digital.ofdm_equalizer_simpledfe(
            fft_len, header_mod.base(), occupied_carriers, pilot_carriers,
            pilot_symbols)
        self.hdr_format = hdr_format = digital.header_format_ofdm(
            occupied_carriers,
            1,
            length_tag_key,
        )
        self.gain_rx = gain_rx = 5
        self.freq = freq = 900e6
        self.bits_per_symbol_0 = bits_per_symbol_0 = len(occupied_carriers[0])

        ##################################################
        # Blocks
        ##################################################
        self.training_mod_textbox = bokehgui.textbox(
            self.widget_lst, str(1), 'Alternate training every' + ": ")
        self.training_mod_textbox.add_callback(
            lambda attr, old, new: self.set_training_mod(int(new)))
        self._t_state_options = [
            1,
            0,
        ]
        self._t_state_labels = [
            'On',
            'Off',
        ]

        self.t_state_radiobutton = bokehgui.radiobutton(self.widget_lst,
                                                        None,
                                                        self._t_state_labels,
                                                        inline=True)
        self.t_state_radiobutton.add_callback(
            lambda new: self.set_t_state(int(self._t_state_options[new])))
        self.rx_lr_slider = bokehgui.slider(self.widget_lst,
                                            'RX Learning rate (log)' + ":", -5,
                                            0, 0.1, 1, -2)
        self.rx_lr_slider.add_callback(
            lambda attr, old, new: self.set_rx_lr(new))
        self.mag_slider = bokehgui.slider(self.widget_lst, 'Eb/N0' + ":", 0,
                                          40, 0.1, 1, 10)
        self.mag_slider.add_callback(lambda attr, old, new: self.set_mag(new))
        self.learning_ber_bf_0 = learning.ber_bf(False, 100, -7.0, 1)
        self.gain_rx_slider = bokehgui.slider(self.widget_lst,
                                              'Amplitude Rx' + ":", 0, 90, 0.5,
                                              1, 5)
        self.gain_rx_slider.add_callback(
            lambda attr, old, new: self.set_gain_rx(new))
        self.blocks_probe_signal_x_0 = blocks.probe_signal_f()
        self.zeromq_sub_msg_source_0_0 = zeromq.sub_msg_source(
            "tcp://" + ip + ":50001", 1000)
        self.zeromq_pub_msg_sink_0_0_0 = zeromq.pub_msg_sink(
            'tcp://*:50002', 1000)
        self.variable_qtgui_label_0_0 = bokehgui.label(
            self.widget_lst, str(variable_qtgui_label_0_0), 'BER' + ": ")
        self.variable_qtgui_label_0 = bokehgui.label(
            self.widget_lst, str(variable_qtgui_label_0), 'Error count' + ": ")
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                args='',
                channels=list(range(0, 1)),
            ),
        )

        self.uhd_usrp_source_0.set_samp_rate(samp_rate)

        self.uhd_usrp_source_0.set_time_now(uhd.time_spec(time.time()),
                                            uhd.ALL_MBOARDS)

        self.uhd_usrp_source_0.set_center_freq(freq, 0)

        self.uhd_usrp_source_0.set_antenna("TX/RX", 0)

        self.uhd_usrp_source_0.set_rx_agc(False, 0)
        self.uhd_usrp_source_0.set_gain(gain_rx, 0)
        self.timestamp_textbox = bokehgui.textbox(self.widget_lst, str('1'),
                                                  'Load timestamp' + ": ")
        self.timestamp_textbox.add_callback(
            lambda attr, old, new: self.set_timestamp(str(new)))
        self.learning_dl_demod_0 = learning.dl_demod(
            'packet_num', False, bits_per_symbol, packet_len, 20, training_mod,
            10**rx_lr, t_state,
            '/home/cyrille/Gnu-Radio/modules/gr-learning/examples/saved_models'
        )
        self.learning_align_0 = learning.align('packet_num', packet_len, 1, 48)
        self.fft_vxx_1 = fft.fft_vcc(fft_len, True, (), True, 1)
        self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (), True, 1)

        def _errors_probe():
            while True:

                val = self.learning_ber_bf_0.total_errors()
                try:
                    self.set_errors(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (0.5))

        _errors_thread = threading.Thread(target=_errors_probe)
        _errors_thread.daemon = True
        _errors_thread.start()

        self.digital_packet_headerparser_b_0 = digital.packet_headerparser_b(
            header_formatter.base())
        self.digital_ofdm_sync_sc_cfb_0 = digital.ofdm_sync_sc_cfb(
            fft_len, fft_len // 4, False, 0.9)
        self.digital_ofdm_serializer_vcc_payload = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key_0,
            packet_length_tag_key, 1, '', True)
        self.digital_ofdm_serializer_vcc_header = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key_0, '', 0, '', True)
        self.digital_ofdm_frame_equalizer_vcvc_1 = digital.ofdm_frame_equalizer_vcvc(
            payload_equalizer.base(), fft_len // 4, length_tag_key_0, True, 0)
        self.digital_ofdm_frame_equalizer_vcvc_0 = digital.ofdm_frame_equalizer_vcvc(
            header_equalizer.base(), fft_len // 4, length_tag_key_0, True, 1)
        self.digital_ofdm_chanest_vcvc_0 = digital.ofdm_chanest_vcvc(
            sync_word1, sync_word2, 1, 0, 3, False)
        self.digital_header_payload_demux_0 = digital.header_payload_demux(
            3, fft_len, fft_len // 4, length_tag_key_0, "", True,
            gr.sizeof_gr_complex, "rx_time", int(samp_rate), (), 0)
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(
            header_mod.base())
        self.bokehgui_time_sink_x_0 = bokehgui.time_sink_f_proc(
            1024, samp_rate, "Decoded minus label", 1)

        self.bokehgui_time_sink_x_0_plot = bokehgui.time_sink_f(
            self.doc,
            self.plot_lst,
            self.bokehgui_time_sink_x_0,
            is_message=False)

        labels = ['', '', '', '', '', '', '', '', '', '']
        legend_list = []
        for i in range(1):
            if len(labels[i]) == 0:
                legend_list.append("Data {0}".format(i))
            else:
                legend_list.append(labels[i])
        self.bokehgui_time_sink_x_0_plot.initialize(log_x=False,
                                                    log_y=False,
                                                    update_time=500,
                                                    legend_list=legend_list)

        self.bokehgui_time_sink_x_0_plot.set_y_axis([-10, 10])
        self.bokehgui_time_sink_x_0_plot.set_y_label('Difference' + '(' + "" +
                                                     ')')
        self.bokehgui_time_sink_x_0_plot.set_x_label('Symbol' + '(' + "" + ')')

        self.bokehgui_time_sink_x_0_plot.enable_tags(-1, True)
        self.bokehgui_time_sink_x_0_plot.set_trigger_mode(
            bokehgui.TRIG_MODE_FREE, bokehgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.bokehgui_time_sink_x_0_plot.enable_grid(False)
        self.bokehgui_time_sink_x_0_plot.enable_axis_labels(True)
        self.bokehgui_time_sink_x_0_plot.disable_legend(not True)
        self.bokehgui_time_sink_x_0_plot.set_layout(*((2, 0, 1, 3)))

        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "blue", "blue", "blue"
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        styles = [
            "solid", "solid", "solid", "solid", "solid", "solid", "solid",
            "solid", "solid", "solid"
        ]
        markers = [None, None, None, None, None, None, None, None, None, None]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in range(1):
            self.bokehgui_time_sink_x_0_plot.format_line(
                i, colors[i], widths[i], styles[i], markers[i], alphas[i])
        self.bokehgui_time_const_x_0 = bokehgui.time_sink_c_proc(
            1024, samp_rate, "Received noisy constellation", 1)

        self.bokehgui_time_const_x_0_plot = bokehgui.const_sink_c(
            self.doc,
            self.plot_lst,
            self.bokehgui_time_const_x_0,
            is_message=False)
        labels = ['', '', '', '', '', '', '', '', '', '']
        legend_list = []
        for i in range(1):
            if len(labels[i]) == 0:
                if (i % 2 == 0):
                    legend_list.append("Re{{Data {0}}}".format(i / 2))
                else:
                    legend_list.append("Im{{Data {0}}}".format(i / 2))
            else:
                legend_list.append(labels[i])

        self.bokehgui_time_const_x_0_plot.initialize(update_time=500,
                                                     legend_list=legend_list)

        self.bokehgui_time_const_x_0_plot.set_y_axis([-2, 2])
        self.bokehgui_time_const_x_0_plot.set_y_label('Q Channel' + '(' + "" +
                                                      ')')

        self.bokehgui_time_const_x_0_plot.set_x_label('I Channel' + '(' + "" +
                                                      ')')
        self.bokehgui_time_const_x_0_plot.enable_tags(-1, False)
        self.bokehgui_time_const_x_0_plot.set_trigger_mode(
            bokehgui.TRIG_MODE_FREE, bokehgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.bokehgui_time_const_x_0_plot.enable_grid(True)
        self.bokehgui_time_const_x_0_plot.enable_axis_labels(True)
        self.bokehgui_time_const_x_0_plot.disable_legend(not True)
        self.bokehgui_time_const_x_0_plot.set_layout(*((0, 1, 2, 2)))
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "blue", "blue", "blue"
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = ['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o']
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in range(1):
            self.bokehgui_time_const_x_0_plot.format_line(
                i, colors[i], widths[i], 'None', markers[i], alphas[i])
        self.bokehgui_frequency_sink_x_0 = bokehgui.freq_sink_c_proc(
            1024, firdes.WIN_BLACKMAN_hARRIS, freq, samp_rate, "Rx signal", 1)
        self.bokehgui_frequency_sink_x_0_plot = bokehgui.freq_sink_c(
            self.doc,
            self.plot_lst,
            self.bokehgui_frequency_sink_x_0,
            is_message=False)
        labels = ['', '', '', '', '', '', '', '', '', '']
        legend_list = []

        for i in range(1):
            if len(labels[i]) == 0:
                legend_list.append("Data {0}".format(i))
            else:
                legend_list.append(labels[i])

        self.bokehgui_frequency_sink_x_0_plot.initialize(
            update_time=100, legend_list=legend_list)

        self.bokehgui_frequency_sink_x_0_plot.set_y_axis([-140, 10])
        self.bokehgui_frequency_sink_x_0_plot.set_y_label('Relative Gain' +
                                                          '(' + 'dB' + ')')
        self.bokehgui_frequency_sink_x_0_plot.set_x_label('Frequency' + '(' +
                                                          "Hz" + ')')

        self.bokehgui_frequency_sink_x_0_plot.set_trigger_mode(
            bokehgui.TRIG_MODE_FREE, 0.0, 0, "")

        self.bokehgui_frequency_sink_x_0_plot.enable_grid(False)
        self.bokehgui_frequency_sink_x_0_plot.enable_axis_labels(True)
        self.bokehgui_frequency_sink_x_0_plot.disable_legend(not True)
        self.bokehgui_frequency_sink_x_0_plot.set_layout(*((3, 0, 1, 3)))
        self.bokehgui_frequency_sink_x_0_plot.enable_max_hold()
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "dark blue"
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        styles = [
            "solid", "solid", "solid", "solid", "solid", "solid", "solid",
            "solid", "solid", "solid"
        ]
        markers = [None, None, None, None, None, None, None, None, None, None]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for i in range(1):
            self.bokehgui_frequency_sink_x_0_plot.format_line(
                i, colors[i], widths[i], styles[i], markers[i], alphas[i])
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_repack_bits_bb_0_0_1_1 = blocks.repack_bits_bb(
            bits_per_symbol, 1, '', False, gr.GR_LSB_FIRST)
        self.blocks_repack_bits_bb_0_0_1 = blocks.repack_bits_bb(
            bits_per_symbol, 1, '', False, gr.GR_LSB_FIRST)
        self.blocks_pdu_to_tagged_stream_0_0 = blocks.pdu_to_tagged_stream(
            blocks.byte_t, 'packet_len')
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float *
                                                   bits_per_symbol)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                           fft_len + 0 * (fft_len // 4) + 10)
        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_add_xx_0 = blocks.add_vcc(1)

        def _ber_probe():
            while True:

                val = self.blocks_probe_signal_x_0.level()
                try:
                    self.set_ber(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (0.5))

        _ber_thread = threading.Thread(target=_ber_probe)
        _ber_thread.daemon = True
        _ber_thread.start()

        self.analog_noise_source_x_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN,
            np.sqrt(10**(np.log10(1 / bits_per_symbol) - (mag / 10.0))) * 1,
            -1)
        self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(
            -2.0 / fft_len)

        if self.widget_lst:
            input_t = bokehgui.bokeh_layout.widgetbox(self.widget_lst)
            widgetbox = bokehgui.bokeh_layout.WidgetLayout(input_t)
            widgetbox.set_layout(*((0, 0, 2, 1)))
            list_obj = [widgetbox] + self.plot_lst
        else:
            list_obj = self.plot_lst
        layout_t = bokehgui.bokeh_layout.create_layout(list_obj,
                                                       "stretch_both")
        self.doc.add_root(layout_t)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.digital_packet_headerparser_b_0, 'header_data'),
                         (self.digital_header_payload_demux_0, 'header_data'))
        self.msg_connect((self.learning_dl_demod_0, 'losses'),
                         (self.zeromq_pub_msg_sink_0_0_0, 'in'))
        self.msg_connect((self.zeromq_sub_msg_source_0_0, 'out'),
                         (self.blocks_pdu_to_tagged_stream_0_0, 'pdus'))
        self.connect((self.analog_frequency_modulator_fc_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.bokehgui_time_const_x_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.learning_align_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, 0),
                     (self.blocks_sub_xx_0, 1))
        self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.digital_header_payload_demux_0, 0))
        self.connect((self.blocks_pdu_to_tagged_stream_0_0, 0),
                     (self.learning_align_0, 1))
        self.connect((self.blocks_repack_bits_bb_0_0_1, 0),
                     (self.learning_ber_bf_0, 1))
        self.connect((self.blocks_repack_bits_bb_0_0_1_1, 0),
                     (self.learning_ber_bf_0, 0))
        self.connect((self.blocks_sub_xx_0, 0),
                     (self.bokehgui_time_sink_x_0, 0))
        self.connect((self.digital_constellation_decoder_cb_0, 0),
                     (self.digital_packet_headerparser_b_0, 0))
        self.connect((self.digital_header_payload_demux_0, 0),
                     (self.fft_vxx_0, 0))
        self.connect((self.digital_header_payload_demux_0, 1),
                     (self.fft_vxx_1, 0))
        self.connect((self.digital_ofdm_chanest_vcvc_0, 0),
                     (self.digital_ofdm_frame_equalizer_vcvc_0, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_0, 0),
                     (self.digital_ofdm_serializer_vcc_header, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_1, 0),
                     (self.digital_ofdm_serializer_vcc_payload, 0))
        self.connect((self.digital_ofdm_serializer_vcc_header, 0),
                     (self.digital_constellation_decoder_cb_0, 0))
        self.connect((self.digital_ofdm_serializer_vcc_payload, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 0),
                     (self.analog_frequency_modulator_fc_0, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 1),
                     (self.digital_header_payload_demux_0, 1))
        self.connect((self.fft_vxx_0, 0),
                     (self.digital_ofdm_chanest_vcvc_0, 0))
        self.connect((self.fft_vxx_1, 0),
                     (self.digital_ofdm_frame_equalizer_vcvc_1, 0))
        self.connect((self.learning_align_0, 1), (self.learning_dl_demod_0, 1))
        self.connect((self.learning_align_0, 0), (self.learning_dl_demod_0, 0))
        self.connect((self.learning_ber_bf_0, 0),
                     (self.blocks_probe_signal_x_0, 0))
        self.connect((self.learning_dl_demod_0, 1),
                     (self.blocks_char_to_float_0_0, 0))
        self.connect((self.learning_dl_demod_0, 2),
                     (self.blocks_char_to_float_0_0_0, 0))
        self.connect((self.learning_dl_demod_0, 0),
                     (self.blocks_null_sink_0, 0))
        self.connect((self.learning_dl_demod_0, 2),
                     (self.blocks_repack_bits_bb_0_0_1, 0))
        self.connect((self.learning_dl_demod_0, 1),
                     (self.blocks_repack_bits_bb_0_0_1_1, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.bokehgui_frequency_sink_x_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.digital_ofdm_sync_sc_cfb_0, 0))
예제 #23
0
 def test_002_static_wo_tags(self):
     """ Same as before, but the input stream has no tag.
     We specify the frame size in the constructor.
     We also specify a tag key, so the output stream *should* have
     a length tag.
     """
     fft_len = 8
     n_syms = 4
     #           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_static(fft_len, occupied_carriers,
                                               pilot_carriers,
                                               pilot_symbols)
     channel = [
         0,
         0,
         1,
         1,
         0,
         1,
         1,
         0,
         0,
         0,
         1,
         1,
         0,
         1,
         1,
         0,  # These coefficients will be rotated slightly (below)...
         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))
     src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False,
                              fft_len)
     # We do specify a length tag, it should then appear at the output
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            "frame_len", False, n_syms)
     sink = blocks.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)
     # Check len tag
     tags = sink.tags()
     len_tag = dict()
     for tag in tags:
         ptag = gr.tag_to_python(tag)
         if ptag.key == 'frame_len':
             len_tag[ptag.key] = ptag.value
     self.assertEqual(len_tag, {'frame_len': 4})
예제 #24
0
 def test_002_static(self):
     """
     - Add a simple channel
     - Make symbols QPSK
     """
     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_static(fft_len, occupied_carriers,
                                               pilot_carriers,
                                               pilot_symbols)
     channel = [
         0,
         0,
         1,
         1,
         0,
         1,
         1,
         0,
         0,
         0,
         1,
         1,
         0,
         1,
         1,
         0,  # These coefficients will be rotated slightly (but less than \pi/2)
         0,
         0,
         1j,
         1j,
         0,
         1j,
         1j,
         0,  # Go crazy here!
         0,
         0,
         1j,
         1j,
         0,
         1j,
         1j,
         0
     ]
     channel = [
         0,
         0,
         1,
         1,
         0,
         1,
         1,
         0,
         0,
         0,
         1,
         1,
         0,
         1,
         1,
         0,  # These coefficients will be rotated slightly (but less than \pi/2)
         0,
         0,
         1j,
         1j,
         0,
         1j,
         1j,
         0,  # Go crazy here!
         0,
         0,
         1j,
         1j,
         0,
         1j,
         1j,
         0
     ]
     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))
     len_tag_key = "frame_len"
     len_tag = gr.tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.string_to_symbol(len_tag_key)
     len_tag.value = pmt.from_long(4)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, channel[:fft_len])
     src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False,
                                  fft_len, (len_tag, chan_tag))
     sink = blocks.vector_sink_c(fft_len)
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            len_tag_key, True)
     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()
     ]
     # Check data
     self.assertEqual(tx_data, rx_data)
     # Check tags
     tag_dict = dict()
     for tag in sink.tags():
         ptag = gr.tag_to_python(tag)
         tag_dict[ptag.key] = ptag.value
         if ptag.key == 'ofdm_sync_chan_taps':
             tag_dict[ptag.key] = list(pmt.c32vector_elements(tag.value))
         else:
             tag_dict[ptag.key] = pmt.to_python(tag.value)
     expected_dict = {
         'frame_len': 4,
         'ofdm_sync_chan_taps': channel[-fft_len:]
     }
     self.assertEqual(tag_dict, expected_dict)
예제 #25
0
    def __init__(self):
        gr.top_block.__init__(self, "OFDM Transceiver")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("OFDM Transceiver")
        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", "rx_ofdm")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.pilot_symbols = pilot_symbols = ((
            1,
            1,
            1,
            -1,
        ), )
        self.pilot_carriers = pilot_carriers = ((
            -21,
            -7,
            7,
            21,
        ), )
        self.payload_mod = payload_mod = digital.constellation_qpsk()
        self.packet_length_tag_key = packet_length_tag_key = "packet_len"
        self.occupied_carriers = occupied_carriers = (
            list(range(-26, -21)) + list(range(-20, -7)) + list(range(-6, 0)) +
            list(range(1, 7)) + list(range(8, 21)) + list(range(22, 27)), )
        self.num_syms = num_syms = 1
        self.length_tag_key = length_tag_key = "frame_len"
        self.header_mod = header_mod = digital.constellation_bpsk()
        self.fft_len = fft_len = 64
        self.tx_amp = tx_amp = 0.034
        self.sync_word2 = sync_word2 = [
            0j, 0j, 0j, 0j, 0j, 0j, (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j),
            (1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j),
            (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (-1 + 0j), (1 + 0j), (-1 + 0j), 0j, (1 + 0j), (-1 + 0j),
            (1 + 0j), (1 + 0j), (1 + 0j), (-1 + 0j), (1 + 0j), (1 + 0j),
            (1 + 0j), (-1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j),
            0j, 0j, 0j, 0j, 0j
        ]
        self.sync_word1 = sync_word1 = [
            0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0.,
            1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0.,
            1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0.,
            -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            0., 0., 0., 0., 0.
        ]
        self.sc_select = sc_select = 0
        self.samp_rate = samp_rate = 1e6
        self.rx_gain = rx_gain = 30
        self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_static(
            fft_len, occupied_carriers, pilot_carriers, pilot_symbols, 0, True)
        self.packet_len = packet_len = int(96 / 8 * num_syms)
        self.offset = offset = 8
        self.mp_gain = mp_gain = 0
        self.mp_delay = mp_delay = 0
        self.header_formatter = header_formatter = digital.packet_header_ofdm(
            occupied_carriers,
            n_syms=1,
            len_tag_key=packet_length_tag_key,
            frame_len_tag_key=length_tag_key,
            bits_per_header_sym=header_mod.bits_per_symbol(),
            bits_per_payload_sym=payload_mod.bits_per_symbol(),
            scramble_header=False)
        self.header_equalizer = header_equalizer = digital.ofdm_equalizer_static(
            fft_len, occupied_carriers, pilot_carriers, pilot_symbols, 0, True)
        self.freqc = freqc = 900e6
        self.cp_delay = cp_delay = 0

        ##################################################
        # Blocks
        ##################################################
        self._tx_amp_range = Range(0.001, 0.1, .001, 0.034, 200)
        self._tx_amp_win = RangeWidget(self._tx_amp_range, self.set_tx_amp,
                                       'TX Amplitude', "counter_slider", float)
        self.top_grid_layout.addWidget(self._tx_amp_win, 1, 0, 1, 8)
        for r in range(1, 2):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.tab_const = Qt.QTabWidget()
        self.tab_const_widget_0 = Qt.QWidget()
        self.tab_const_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                                self.tab_const_widget_0)
        self.tab_const_grid_layout_0 = Qt.QGridLayout()
        self.tab_const_layout_0.addLayout(self.tab_const_grid_layout_0)
        self.tab_const.addTab(self.tab_const_widget_0,
                              'Pre-Equalization (Single-Subcarrier)')
        self.tab_const_widget_1 = Qt.QWidget()
        self.tab_const_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                                self.tab_const_widget_1)
        self.tab_const_grid_layout_1 = Qt.QGridLayout()
        self.tab_const_layout_1.addLayout(self.tab_const_grid_layout_1)
        self.tab_const.addTab(self.tab_const_widget_1,
                              'Pre-Equalization (All Subcarriers)')
        self.tab_const_widget_2 = Qt.QWidget()
        self.tab_const_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom,
                                                self.tab_const_widget_2)
        self.tab_const_grid_layout_2 = Qt.QGridLayout()
        self.tab_const_layout_2.addLayout(self.tab_const_grid_layout_2)
        self.tab_const.addTab(self.tab_const_widget_2,
                              'Post-Equalization (All Subcarriers)')
        self.top_grid_layout.addWidget(self.tab_const, 2, 0, 8, 4)
        for r in range(2, 10):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._sc_select_range = Range(0, fft_len - 1, 1, 0, 200)
        self._sc_select_win = RangeWidget(self._sc_select_range,
                                          self.set_sc_select,
                                          'Sub Carrier Select',
                                          "counter_slider", float)
        self.top_grid_layout.addWidget(self._sc_select_win, 12, 0, 1, 4)
        for r in range(12, 13):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._rx_gain_range = Range(0, 64, 1, 30, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain,
                                        'RX Gain', "counter_slider", float)
        self.top_grid_layout.addWidget(self._rx_gain_win, 0, 0, 1, 8)
        for r in range(0, 1):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._mp_gain_range = Range(0, 1, 0.001, 0, 200)
        self._mp_gain_win = RangeWidget(self._mp_gain_range, self.set_mp_gain,
                                        'Multipath Gain', "counter_slider",
                                        float)
        self.top_grid_layout.addWidget(self._mp_gain_win, 13, 0, 1, 4)
        for r in range(13, 14):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 4):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._mp_delay_range = Range(0, 32, 1, 0, 200)
        self._mp_delay_win = RangeWidget(self._mp_delay_range,
                                         self.set_mp_delay,
                                         'Multipath Delay (Samples)',
                                         "counter_slider", float)
        self.top_grid_layout.addWidget(self._mp_delay_win, 13, 4, 1, 4)
        for r in range(13, 14):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(4, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self._cp_delay_range = Range(0, 3, 1, 0, 200)
        self._cp_delay_win = RangeWidget(self._cp_delay_range,
                                         self.set_cp_delay,
                                         'CP Delay (samples)',
                                         "counter_slider", float)
        self.top_grid_layout.addWidget(self._cp_delay_win, 12, 4, 1, 4)
        for r in range(12, 13):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(4, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            fft_len,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "Channel Response",  #name
            1)
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-100, 0)
        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(True)
        self.qtgui_freq_sink_x_0.set_fft_average(0.1)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(True)

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [2, 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 range(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.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 2, 4, 8,
                                       4)
        for r in range(2, 10):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(4, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_const_sink_x_0_1 = qtgui.const_sink_c(
            1024,  #size
            "",  #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.5, 2.5)
        self.qtgui_const_sink_x_0_1.set_x_axis(-2.5, 2.5)
        self.qtgui_const_sink_x_0_1.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                     qtgui.TRIG_SLOPE_POS, 0.0,
                                                     0, "")
        self.qtgui_const_sink_x_0_1.enable_autoscale(False)
        self.qtgui_const_sink_x_0_1.enable_grid(True)
        self.qtgui_const_sink_x_0_1.enable_axis_labels(True)

        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 range(1):
            if len(labels[i]) == 0:
                self.qtgui_const_sink_x_0_1.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_const_sink_x_0_1.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_0_1.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_0_1.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_0_1.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_0_1.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_0_1.set_line_alpha(i, alphas[i])

        self._qtgui_const_sink_x_0_1_win = sip.wrapinstance(
            self.qtgui_const_sink_x_0_1.pyqwidget(), Qt.QWidget)
        self.tab_const_layout_1.addWidget(self._qtgui_const_sink_x_0_1_win)
        self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c(
            1024,  #size
            "",  #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.5, 2.5)
        self.qtgui_const_sink_x_0_0.set_x_axis(-2.5, 2.5)
        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(True)
        self.qtgui_const_sink_x_0_0.enable_axis_labels(True)

        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 range(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.tab_const_layout_0.addWidget(self._qtgui_const_sink_x_0_0_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.5, 2.5)
        self.qtgui_const_sink_x_0.set_x_axis(-2.5, 2.5)
        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(True)
        self.qtgui_const_sink_x_0.enable_axis_labels(True)

        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 range(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.tab_const_layout_2.addWidget(self._qtgui_const_sink_x_0_win)
        self._num_syms_range = Range(1, 20, 1, 1, 200)
        self._num_syms_win = RangeWidget(self._num_syms_range,
                                         self.set_num_syms,
                                         '# of Symbols per Pkt',
                                         "counter_slider", float)
        self.top_grid_layout.addWidget(self._num_syms_win, 11, 0, 1, 8)
        for r in range(11, 12):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 8):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.iio_pluto_source_0 = iio.pluto_source('usb:1.4.5', int(freqc),
                                                   int(samp_rate), 20000000,
                                                   32768, True, True, True,
                                                   'manual', rx_gain, '', True)
        self.iio_pluto_sink_0 = iio.pluto_sink('usb:1.3.5', int(freqc),
                                               int(samp_rate), 20000000, 32768,
                                               False, 10.0, '', True)
        self.fft_vxx_1 = fft.fft_vcc(fft_len, True, (), True, 1)
        self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (), True, 1)
        self.digital_packet_headerparser_b_0 = digital.packet_headerparser_b(
            header_formatter.base())
        self.digital_ofdm_tx_0 = digital.ofdm_tx(
            fft_len=fft_len,
            cp_len=fft_len // 4,
            packet_length_tag_key=packet_length_tag_key,
            occupied_carriers=occupied_carriers,
            pilot_carriers=pilot_carriers,
            pilot_symbols=pilot_symbols,
            sync_word1=sync_word1,
            sync_word2=sync_word2,
            bps_header=1,
            bps_payload=2,
            rolloff=0,
            debug_log=False,
            scramble_bits=False)
        self.digital_ofdm_sync_sc_cfb_0 = digital.ofdm_sync_sc_cfb(
            fft_len, fft_len // 4, False, 0.9)
        self.digital_ofdm_serializer_vcc_payload = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key, packet_length_tag_key,
            1, '', True)
        self.digital_ofdm_serializer_vcc_header = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key, '', 0, '', True)
        self.digital_ofdm_frame_equalizer_vcvc_1 = digital.ofdm_frame_equalizer_vcvc(
            payload_equalizer.base(), fft_len // 4, length_tag_key, True, 0)
        self.digital_ofdm_frame_equalizer_vcvc_0 = digital.ofdm_frame_equalizer_vcvc(
            header_equalizer.base(), fft_len // 4, length_tag_key, True, 1)
        self.digital_ofdm_chanest_vcvc_0 = digital.ofdm_chanest_vcvc(
            sync_word1, sync_word2, 1, 0, 3, False)
        self.digital_header_payload_demux_0 = digital.header_payload_demux(
            3, fft_len, fft_len // 4, length_tag_key, "", True,
            gr.sizeof_gr_complex, "rx_time", int(samp_rate), (), 0)
        self.digital_crc32_bb_0 = digital.crc32_bb(True, packet_length_tag_key,
                                                   True)
        self.digital_constellation_decoder_cb_1 = digital.constellation_decoder_cb(
            payload_mod.base())
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(
            header_mod.base())
        self.blocks_vector_to_stream_0_0_1 = blocks.vector_to_stream(
            gr.sizeof_gr_complex * 1, 64)
        self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream(
            gr.sizeof_gr_complex * 1, 64)
        self.blocks_tag_debug_1 = blocks.tag_debug(gr.sizeof_char * 1,
                                                   'Rx Bytes', "")
        self.blocks_tag_debug_1.set_display(False)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, 64)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(
            gr.sizeof_char, 1, packet_len, packet_length_tag_key)
        self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(
            payload_mod.bits_per_symbol(), 8, packet_length_tag_key, True,
            gr.GR_LSB_FIRST)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(mp_gain)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(tx_amp)
        self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, 1,
                                                       fft_len, sc_select)
        self.blocks_delay_2 = blocks.delay(gr.sizeof_gr_complex * 1, mp_delay)
        self.blocks_delay_1 = blocks.delay(gr.sizeof_gr_complex * 1, cp_delay)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                           fft_len + fft_len // 4)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_random_source_x_0 = blocks.vector_source_b(
            list(map(int, numpy.random.randint(0, 255, 1000))), True)
        self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(
            -2.0 / fft_len)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.digital_packet_headerparser_b_0, 'header_data'),
                         (self.digital_header_payload_demux_0, 'header_data'))
        self.connect((self.analog_frequency_modulator_fc_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.analog_random_source_x_0, 0),
                     (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.digital_ofdm_sync_sc_cfb_0, 0))
        self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_delay_1, 0),
                     (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_delay_2, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_keep_m_in_n_0, 0),
                     (self.qtgui_const_sink_x_0_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.iio_pluto_sink_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.digital_header_payload_demux_0, 0))
        self.connect((self.blocks_repack_bits_bb_0, 0),
                     (self.digital_crc32_bb_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0),
                     (self.digital_ofdm_tx_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_1, 0))
        self.connect((self.blocks_vector_to_stream_0_0, 0),
                     (self.blocks_delay_1, 0))
        self.connect((self.blocks_vector_to_stream_0_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.blocks_vector_to_stream_0_0_1, 0),
                     (self.blocks_keep_m_in_n_0, 0))
        self.connect((self.blocks_vector_to_stream_0_0_1, 0),
                     (self.qtgui_const_sink_x_0_1, 0))
        self.connect((self.digital_constellation_decoder_cb_0, 0),
                     (self.digital_packet_headerparser_b_0, 0))
        self.connect((self.digital_constellation_decoder_cb_1, 0),
                     (self.blocks_repack_bits_bb_0, 0))
        self.connect((self.digital_crc32_bb_0, 0),
                     (self.blocks_tag_debug_1, 0))
        self.connect((self.digital_header_payload_demux_0, 1),
                     (self.blocks_vector_to_stream_0_0, 0))
        self.connect((self.digital_header_payload_demux_0, 0),
                     (self.fft_vxx_0, 0))
        self.connect((self.digital_ofdm_chanest_vcvc_0, 0),
                     (self.digital_ofdm_frame_equalizer_vcvc_0, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_0, 0),
                     (self.digital_ofdm_serializer_vcc_header, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_1, 0),
                     (self.digital_ofdm_serializer_vcc_payload, 0))
        self.connect((self.digital_ofdm_serializer_vcc_header, 0),
                     (self.digital_constellation_decoder_cb_0, 0))
        self.connect((self.digital_ofdm_serializer_vcc_payload, 0),
                     (self.digital_constellation_decoder_cb_1, 0))
        self.connect((self.digital_ofdm_serializer_vcc_payload, 0),
                     (self.qtgui_const_sink_x_0, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 0),
                     (self.analog_frequency_modulator_fc_0, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 1),
                     (self.digital_header_payload_demux_0, 1))
        self.connect((self.digital_ofdm_tx_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.fft_vxx_0, 0),
                     (self.digital_ofdm_chanest_vcvc_0, 0))
        self.connect((self.fft_vxx_1, 0),
                     (self.blocks_vector_to_stream_0_0_1, 0))
        self.connect((self.fft_vxx_1, 0),
                     (self.digital_ofdm_frame_equalizer_vcvc_1, 0))
        self.connect((self.iio_pluto_source_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.iio_pluto_source_0, 0), (self.blocks_delay_2, 0))
 def test_002_static (self):
     """
     - Add a simple channel
     - Make symbols QPSK
     """
     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_static(fft_len, occupied_carriers, pilot_carriers, pilot_symbols)
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly (but less than \pi/2)
         0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here!
         0, 0, 1j, 1j, 0, 1j, 1j, 0
     ]
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly (but less than \pi/2)
         0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here!
         0, 0, 1j, 1j, 0, 1j, 1j, 0
     ]
     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))
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, channel[:fft_len])
     src = blocks.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (chan_tag,))
     sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key)
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key, True)
     self.tb.connect(
             src,
             blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, len(tx_data) // fft_len, self.tsb_key),
             eq,
             sink
     )
     self.tb.run ()
     rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()[0]]
     # Check data
     self.assertEqual(tx_data, rx_data)
     # Check tags
     tag_dict = dict()
     for tag in sink.tags():
         ptag = gr.tag_to_python(tag)
         tag_dict[ptag.key] = ptag.value
         if ptag.key == 'ofdm_sync_chan_taps':
             tag_dict[ptag.key] = list(pmt.c32vector_elements(tag.value))
         else:
             tag_dict[ptag.key] = pmt.to_python(tag.value)
     expected_dict = {
             'ofdm_sync_chan_taps': channel[-fft_len:]
     }
     self.assertEqual(tag_dict, expected_dict)
예제 #27
0
    def __init__(self, doc, ip="127.0.0.1"):
        gr.top_block.__init__(self, "RL Mod training")
        self.doc = doc
        self.plot_lst = []
        self.widget_lst = []

        ##################################################
        # Parameters
        ##################################################
        self.ip = ip

        ##################################################
        # Variables
        ##################################################
        self.pilot_symbols = pilot_symbols = ((1, 1, 1, -1,),)
        self.pilot_carriers = pilot_carriers = ((-21, -7, 7, 21,),)
        self.packet_length_tag_key = packet_length_tag_key = "packet_length"
        self.occupied_carriers = occupied_carriers = (list(range(-22, -21)) + list(range(-20, -7)) + list(range(-6, 0)) + list(range(1, 7)) + list(range(8, 21)) + list(range(22, 23)),)
        self.length_tag_key_0 = length_tag_key_0 = "frame_len"
        self.length_tag_key = length_tag_key = "packet_len"
        self.header_mod = header_mod = digital.constellation_bpsk()
        self.fft_len = fft_len = 64
        self.bits_per_symbol = bits_per_symbol = 4
        self.variable_0 = variable_0 = len(occupied_carriers[0])
        self.tx_lr = tx_lr = -3
        self.tx_explo = tx_explo = 0.15
        self.training_mod = training_mod = 1
        self.timestamp = timestamp = '1'
        self.t_state = t_state = 1
        self.sync_word2 = sync_word2 = [0, 0, 0, 0, 0, 0, -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, 0, 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, 0, 0, 0, 0, 0]
        self.sync_word1 = sync_word1 = [0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 0., 0., 0., 0., 0.]
        self.samp_rate = samp_rate = 0.3e6
        self.rolloff = rolloff = 0
        self.puncpat = puncpat = '11'
        self.payload_mod = payload_mod = digital.qam_constellation(constellation_points=2**bits_per_symbol)
        self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_static(fft_len,  occupied_carriers, pilot_carriers, pilot_symbols, 1)
        self.packet_len = packet_len = 400
        self.ldpc_enc = ldpc_enc = fec.ldpc_encoder_make(gr.prefix() + "/share/gnuradio/fec/ldpc/" + "n_0100_k_0042_gap_02.alist")
        self.header_formatter = header_formatter = digital.packet_header_ofdm(occupied_carriers, n_syms=1, len_tag_key=packet_length_tag_key, frame_len_tag_key=length_tag_key_0, bits_per_header_sym=header_mod.bits_per_symbol(), bits_per_payload_sym=8, scramble_header=False)
        self.header_equalizer = header_equalizer = digital.ofdm_equalizer_simpledfe(fft_len, header_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols)
        self.hdr_format = hdr_format = digital.header_format_ofdm(occupied_carriers, 1, length_tag_key,)
        self.gain = gain = 10
        self.freq = freq = 900e6
        self.bits_per_symbol_0 = bits_per_symbol_0 = len(occupied_carriers[0])

        ##################################################
        # Blocks
        ##################################################
        self.tx_lr_slider = bokehgui.slider(self.widget_lst, 'TX Learning rate (log)' +":", -5, 0, 0.1, 1, -3)
        self.tx_lr_slider.add_callback(lambda attr, old, new: self.set_tx_lr(new))
        self.tx_explo_slider = bokehgui.slider(self.widget_lst, 'TX Exploration noise' +":", 0.001, 0.5, 0.001, 1, 0.15)
        self.tx_explo_slider.add_callback(lambda attr, old, new: self.set_tx_explo(new))
        self.training_mod_textbox = bokehgui.textbox(self.widget_lst, str(1), 'Alternate training every' +": ")
        self.training_mod_textbox.add_callback(
          lambda attr, old, new: self.set_training_mod(int(new)))
        self._t_state_options = [    1,     0,   ]
        self._t_state_labels = [      'On',      'Off',  ]

        self.t_state_radiobutton = bokehgui.radiobutton(self.widget_lst, None, self._t_state_labels, inline = True)
        self.t_state_radiobutton.add_callback(
                  lambda new: self.set_t_state(int(self._t_state_options[new])))
        self.gain_slider = bokehgui.slider(self.widget_lst, 'Amplitude' +":", 0, 90, 0.5, 1, 10)
        self.gain_slider.add_callback(lambda attr, old, new: self.set_gain(new))
        self.zeromq_sub_msg_source_0_1 = zeromq.sub_msg_source("tcp://"+ip+":50002", 100)
        self.zeromq_pub_msg_sink_0_0 = zeromq.pub_msg_sink('tcp://*:50001', 100)
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                args='',
                channels=list(range(0,1)),
            ),
            length_tag_key,
        )


        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)

        self.uhd_usrp_sink_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS)

        self.uhd_usrp_sink_0.set_center_freq(freq, 0)

        self.uhd_usrp_sink_0.set_antenna('TX/RX', 0)

        self.uhd_usrp_sink_0.set_gain(gain, 0)
        self.timestamp_textbox = bokehgui.textbox(self.widget_lst, str('1'), 'Load timestamp' +": ")
        self.timestamp_textbox.add_callback(
          lambda attr, old, new: self.set_timestamp(str(new)))
        self.learning_tag_numerotation_0 = learning.tag_numerotation('packet_num', packet_len, 4096, "bb")
        self.learning_rl_mod_0 = learning.rl_mod('packet_num', bits_per_symbol, packet_len, 1, training_mod, 10**tx_lr , tx_explo, t_state , '/home/cyrille/Gnu-Radio/modules/gr-learning/examples/saved_models')
        self.fft_vxx_0_0 = fft.fft_vcc(fft_len, False, (), True, 1)
        self.fec_extended_encoder_1_0_0 = fec.extended_encoder(encoder_obj_list=ldpc_enc, threading= None, puncpat=puncpat)
        self.digital_protocol_formatter_bb_0 = digital.protocol_formatter_bb(hdr_format, length_tag_key)
        self.digital_ofdm_cyclic_prefixer_0 = digital.ofdm_cyclic_prefixer(
            fft_len,
            fft_len + fft_len//4,
            rolloff,
            length_tag_key)
        self.digital_ofdm_carrier_allocator_cvc_0 = digital.ofdm_carrier_allocator_cvc( fft_len, occupied_carriers, pilot_carriers, pilot_symbols, (sync_word1, sync_word2), length_tag_key, True)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc(header_mod.points(), 1)
        self.bokehgui_time_const_x_0 = bokehgui.time_sink_c_proc(1024, samp_rate, "Transmitted noiseless constellation",  1)

        self.bokehgui_time_const_x_0_plot = bokehgui.const_sink_c(self.doc, self.plot_lst, self.bokehgui_time_const_x_0, is_message = False)
        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        legend_list = []
        for i in range(  1 ):
          if len(labels[i]) == 0:
              if(i % 2 == 0):
                  legend_list.append("Re{{Data {0}}}".format(i/2))
              else:
                  legend_list.append("Im{{Data {0}}}".format(i/2))
          else:
              legend_list.append(labels[i])

        self.bokehgui_time_const_x_0_plot.initialize(update_time = 500,
                                    legend_list = legend_list)

        self.bokehgui_time_const_x_0_plot.set_y_axis([-2, 2])
        self.bokehgui_time_const_x_0_plot.set_y_label('Q Channel' + '(' +""+')')

        self.bokehgui_time_const_x_0_plot.set_x_label('I Channel' + '(' +""+')')
        self.bokehgui_time_const_x_0_plot.enable_tags(-1, False)
        self.bokehgui_time_const_x_0_plot.set_trigger_mode(bokehgui.TRIG_MODE_FREE, bokehgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.bokehgui_time_const_x_0_plot.enable_grid(False)
        self.bokehgui_time_const_x_0_plot.enable_axis_labels(True)
        self.bokehgui_time_const_x_0_plot.disable_legend(not True)
        self.bokehgui_time_const_x_0_plot.set_layout(*((0,1,2,2)))
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "blue", "blue", "blue"]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = ['o', 'o', 'o', 'o', 'o',
                   'o', 'o', 'o', 'o', 'o']
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in range(    1  ):
          self.bokehgui_time_const_x_0_plot.format_line(i, colors[i], widths[i], 'None', markers[i], alphas[i])
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate/6,True)
        self.blocks_tagged_stream_to_pdu_0_0_0 = blocks.tagged_stream_to_pdu(blocks.byte_t, 'packet_len')
        self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, length_tag_key, 0)
        self.blocks_stream_to_tagged_stream_0_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, length_tag_key)
        self.blocks_repack_bits_bb_0_0_0 = blocks.repack_bits_bb(8, 1, length_tag_key, False, gr.GR_LSB_FIRST)
        self.blocks_repack_bits_bb_0_0 = blocks.repack_bits_bb(1, bits_per_symbol, '', False, gr.GR_LSB_FIRST)
        self.blocks_multiply_const_xx_0 = blocks.multiply_const_cc(0.01, 1)
        self.analog_random_source_x_0_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 2, 1000))), True)

        if self.widget_lst:
            input_t = bokehgui.bokeh_layout.widgetbox(self.widget_lst)
            widgetbox = bokehgui.bokeh_layout.WidgetLayout(input_t)
            widgetbox.set_layout(*((0, 0, 2, 1)))
            list_obj = [widgetbox] + self.plot_lst
        else:
            list_obj = self.plot_lst
        layout_t = bokehgui.bokeh_layout.create_layout(list_obj, "fixed")
        self.doc.add_root(layout_t)


        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_tagged_stream_to_pdu_0_0_0, 'pdus'), (self.zeromq_pub_msg_sink_0_0, 'in'))
        self.msg_connect((self.zeromq_sub_msg_source_0_1, 'out'), (self.learning_rl_mod_0, 'losses'))
        self.connect((self.analog_random_source_x_0_0, 0), (self.fec_extended_encoder_1_0_0, 0))
        self.connect((self.blocks_multiply_const_xx_0, 0), (self.uhd_usrp_sink_0, 0))
        self.connect((self.blocks_repack_bits_bb_0_0, 0), (self.blocks_stream_to_tagged_stream_0_0, 0))
        self.connect((self.blocks_repack_bits_bb_0_0_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0_0, 0), (self.digital_protocol_formatter_bb_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0_0, 0), (self.learning_tag_numerotation_0, 0))
        self.connect((self.blocks_tagged_stream_mux_0, 0), (self.digital_ofdm_carrier_allocator_cvc_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_tagged_stream_to_pdu_0_0_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_tagged_stream_mux_0, 0))
        self.connect((self.digital_ofdm_carrier_allocator_cvc_0, 0), (self.fft_vxx_0_0, 0))
        self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.blocks_multiply_const_xx_0, 0))
        self.connect((self.digital_protocol_formatter_bb_0, 0), (self.blocks_repack_bits_bb_0_0_0, 0))
        self.connect((self.fec_extended_encoder_1_0_0, 0), (self.blocks_repack_bits_bb_0_0, 0))
        self.connect((self.fft_vxx_0_0, 0), (self.digital_ofdm_cyclic_prefixer_0, 0))
        self.connect((self.learning_rl_mod_0, 0), (self.blocks_tagged_stream_mux_0, 1))
        self.connect((self.learning_rl_mod_0, 1), (self.bokehgui_time_const_x_0, 0))
        self.connect((self.learning_tag_numerotation_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.learning_tag_numerotation_0, 0), (self.learning_rl_mod_0, 0))