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 = gr.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), "", False, 4) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, eq, sink) self.tb.run () rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()] self.assertEqual(tx_data, rx_data)
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.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(n_syms) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1, ) * fft_len) src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag)) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, eq, sink) self.tb.run() # Check data self.assertEqual(tx_data, sink.data())
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)
def test_001_simple (self): """ Very simple functionality testing """ fft_len = 8 equalizer = digital.ofdm_equalizer_static(fft_len) n_syms = 3 len_tag_key = "frame_len" tx_data = (1,) * fft_len * n_syms len_tag = gr.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(n_syms) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1,) * fft_len) src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag)) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), len_tag_key) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, eq, sink) self.tb.run () # Check data self.assertEqual(tx_data, sink.data()) for tag in sink.tags(): self.assertEqual(pmt.pmt_symbol_to_string(tag.key), len_tag_key) self.assertEqual(pmt.pmt_to_long(tag.value), n_syms)
def test_002_simpledfe (self): """ Use the simple DFE equalizer. """ fft_len = 8 # 4 5 6 7 0 1 2 3 tx_data = [-1, -1, 1, 2, -1, 3, 0, -1, # 0 -1, -1, 0, 2, -1, 2, 0, -1, # 8 -1, -1, 3, 0, -1, 1, 0, -1, # 16 (Pilot symbols) -1, -1, 1, 1, -1, 0, 2, -1] # 24 cnst = digital.constellation_qpsk() tx_signal = [cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data] occupied_carriers = ((1, 2, 6, 7),) pilot_carriers = ((), (), (1, 2, 6, 7), ()) pilot_symbols = ( [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], [] ) equalizer = digital.ofdm_equalizer_simpledfe( fft_len, cnst.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 0.01 ) channel = [ 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, # These coefficients will be rotated slightly... 0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here! 0, 0, 1j, 1j, 0, 1j, 1j, 0 # ...and again here. ] for idx in range(fft_len, 2*fft_len): channel[idx] = channel[idx-fft_len] * numpy.exp(1j * .1 * numpy.pi * (numpy.random.rand()-.5)) idx2 = idx+2*fft_len channel[idx2] = channel[idx2] * numpy.exp(1j * 0 * numpy.pi * (numpy.random.rand()-.5)) len_tag_key = "frame_len" len_tag = gr.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(4) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.pmt_init_c32vector(fft_len, channel[:fft_len]) src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (len_tag, chan_tag)) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key, True) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, eq, sink) self.tb.run () rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()] self.assertEqual(tx_data, rx_data) for tag in sink.tags(): if pmt.pmt_symbol_to_string(tag.key) == len_tag_key: self.assertEqual(pmt.pmt_to_long(tag.value), 4) if pmt.pmt_symbol_to_string(tag.key) == "ofdm_sync_chan_taps": self.assertComplexTuplesAlmostEqual(list(pmt.pmt_c32vector_elements(tag.value)), channel[-fft_len:], places=1)
def test_002_simpledfe (self): """ Use the simple DFE equalizer. """ fft_len = 8 # 4 5 6 7 0 1 2 3 tx_data = [-1, -1, 1, 2, -1, 3, 0, -1, # 0 -1, -1, 0, 2, -1, 2, 0, -1, # 8 -1, -1, 3, 0, -1, 1, 0, -1, # 16 (Pilot symbols) -1, -1, 1, 1, -1, 0, 2, -1] # 24 cnst = digital.constellation_qpsk() tx_signal = [cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data] occupied_carriers = ((1, 2, 6, 7),) pilot_carriers = ((), (), (1, 2, 6, 7), ()) pilot_symbols = ( [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], [] ) equalizer = digital.ofdm_equalizer_simpledfe( fft_len, cnst.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 0.01 ) channel = [ 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, # These coefficients will be rotated slightly... 0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here! 0, 0, 1j, 1j, 0, 1j, 1j, 0 # ...and again here. ] for idx in range(fft_len, 2*fft_len): channel[idx] = channel[idx-fft_len] * numpy.exp(1j * .1 * numpy.pi * (numpy.random.rand()-.5)) idx2 = idx+2*fft_len channel[idx2] = channel[idx2] * numpy.exp(1j * 0 * numpy.pi * (numpy.random.rand()-.5)) len_tag_key = "frame_len" len_tag = gr.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)) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key, True) 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) for tag in sink.tags(): if pmt.symbol_to_string(tag.key) == len_tag_key: self.assertEqual(pmt.to_long(tag.value), 4) if pmt.symbol_to_string(tag.key) == "ofdm_sync_chan_taps": self.assertComplexTuplesAlmostEqual(list(pmt.c32vector_elements(tag.value)), channel[-fft_len:], places=1)
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 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 = gr.vector_sink_c(fft_len) self.tb.connect(src, eq, sink) self.tb.run () rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()] self.assertEqual(tx_data, rx_data) # 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_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.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(n_syms) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") # Note: this is shifted to the correct position! chan_tag.value = pmt.pmt_init_c32vector( fft_len, (0, 0, -1j, -1j, 0, -1j, -1j, 0)) offset_tag = gr.gr_tag_t() offset_tag.offset = 0 offset_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset") offset_tag.value = pmt.pmt_from_long(carr_offset) src = gr.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 = gr.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.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(n_syms) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1,) * fft_len) random_tag = gr.gr_tag_t() random_tag.offset = 1 random_tag.key = pmt.pmt_string_to_symbol("foo") random_tag.value = pmt.pmt_from_long(42) src = gr.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 = gr.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_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) len_tag_key = "frame_len" len_tag = gr.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(n_syms) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.pmt_init_c32vector(fft_len, (0, 0, 1, 1, 0, 1, 1, 0)) offset_tag = gr.gr_tag_t() offset_tag.offset = 0 offset_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset") offset_tag.value = pmt.pmt_from_long(carr_offset) src = gr.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 = gr.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_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) 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") 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, (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_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.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(n_syms) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1,) * fft_len) src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag)) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, eq, sink) self.tb.run () # Check data self.assertEqual(tx_data, sink.data())
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.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(n_syms) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") # Note: this is shifted to the correct position! chan_tag.value = pmt.pmt_init_c32vector(fft_len, (0, 0, -1j, -1j, 0, -1j, -1j, 0)) offset_tag = gr.gr_tag_t() offset_tag.offset = 0 offset_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset") offset_tag.value = pmt.pmt_from_long(carr_offset) src = gr.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 = gr.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 __init__(self, fft_len=_def_fft_len, cp_len=_def_cp_len, frame_length_tag_key=_def_frame_length_tag_key, packet_length_tag_key=_def_packet_length_tag_key, packet_num_tag_key=_def_packet_num_tag_key, occupied_carriers=_def_occupied_carriers, pilot_carriers=_def_pilot_carriers, pilot_symbols=_def_pilot_symbols, bps_header=1, bps_payload=1, sync_word1=None, sync_word2=None ): gr.hier_block2.__init__(self, "ofdm_rx", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_char)) self.fft_len = fft_len self.cp_len = cp_len self.frame_length_tag_key = frame_length_tag_key self.packet_length_tag_key = packet_length_tag_key self.occupied_carriers = occupied_carriers self.bps_header = bps_header self.bps_payload = bps_payload n_sync_words = 1 header_constellation = _get_constellation(bps_header) if sync_word1 is None: self.sync_word1 = _make_sync_word(fft_len, occupied_carriers, header_constellation) else: if len(sync_word1) != self.fft_len: raise ValueError("Length of sync sequence(s) must be FFT length.") self.sync_word1 = sync_word1 self.sync_word2 = () if sync_word2 is not None: if len(sync_word2) != fft_len: raise ValueError("Length of sync sequence(s) must be FFT length.") self.sync_word2 = sync_word2 n_sync_words = 2 else: sync_word2 = () # Receiver path sync_detect = digital.ofdm_sync_sc_cfb(fft_len, cp_len) oscillator = analog.frequency_modulator_fc(-2.0 / fft_len) delay = gr.delay(gr.sizeof_gr_complex, fft_len+cp_len) mixer = gr.multiply_cc() hpd = digital.header_payload_demux(n_sync_words, fft_len, cp_len, frame_length_tag_key, "", True) self.connect(self, sync_detect) self.connect((sync_detect, 0), oscillator, (mixer, 0)) self.connect(self, delay, (mixer, 1)) self.connect(mixer, (hpd, 0)) self.connect((sync_detect, 1), (hpd, 1)) # Header demodulation header_fft = fft.fft_vcc(self.fft_len, True, (), True) chanest = digital.ofdm_chanest_vcvc(self.sync_word1, self.sync_word2, 1) header_equalizer = digital.ofdm_equalizer_simpledfe( fft_len, header_constellation.base(), occupied_carriers, pilot_carriers, pilot_symbols ) header_eq = digital.ofdm_frame_equalizer_vcvc(header_equalizer.base(), frame_length_tag_key, True) header_serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers) header_constellation = _get_constellation(bps_header) header_demod = digital.constellation_decoder_cb(header_constellation.base()) header_formatter = digital.packet_header_ofdm( occupied_carriers, 1, packet_length_tag_key, frame_length_tag_key, packet_num_tag_key, bps_header ) header_parser = digital.packet_headerparser_b(header_formatter.formatter()) self.connect((hpd, 0), header_fft, chanest, header_eq, header_serializer, header_demod, header_parser) self.msg_connect(header_parser, "header_data", hpd, "header_data") # Payload demodulation payload_fft = fft.fft_vcc(self.fft_len, True, (), True) payload_equalizer = digital.ofdm_equalizer_simpledfe( fft_len, header_constellation.base(), occupied_carriers, pilot_carriers, pilot_symbols, 1 ) payload_eq = digital.ofdm_frame_equalizer_vcvc(payload_equalizer.base(), frame_length_tag_key) payload_serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers) payload_constellation = _get_constellation(bps_payload) payload_demod = digital.constellation_decoder_cb(payload_constellation.base()) bit_packer = blocks.repack_bits_bb(bps_payload, 8, packet_length_tag_key, True) self.connect((hpd, 1), payload_fft, payload_eq, payload_serializer, payload_demod, bit_packer, self)
def __init__(self, fft_len=_def_fft_len, cp_len=_def_cp_len, frame_length_tag_key=_def_frame_length_tag_key, packet_length_tag_key=_def_packet_length_tag_key, packet_num_tag_key=_def_packet_num_tag_key, occupied_carriers=_def_occupied_carriers, pilot_carriers=_def_pilot_carriers, pilot_symbols=_def_pilot_symbols, bps_header=1, bps_payload=1, sync_word1=None, sync_word2=None, debug_log=False, scramble_bits=False): gr.hier_block2.__init__(self, "ofdm_rx", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_char)) ### Param init / sanity check ######################################## self.fft_len = fft_len self.cp_len = cp_len self.frame_length_tag_key = frame_length_tag_key self.packet_length_tag_key = packet_length_tag_key self.occupied_carriers = occupied_carriers self.bps_header = bps_header self.bps_payload = bps_payload n_sync_words = 1 if sync_word1 is None: self.sync_word1 = _make_sync_word1(fft_len, occupied_carriers, pilot_carriers) else: if len(sync_word1) != self.fft_len: raise ValueError( "Length of sync sequence(s) must be FFT length.") self.sync_word1 = sync_word1 self.sync_word2 = () if sync_word2 is None: self.sync_word2 = _make_sync_word2(fft_len, occupied_carriers, pilot_carriers) n_sync_words = 2 elif len(sync_word2): if len(sync_word2) != fft_len: raise ValueError( "Length of sync sequence(s) must be FFT length.") self.sync_word2 = sync_word2 n_sync_words = 2 if scramble_bits: self.scramble_seed = 0x7f else: self.scramble_seed = 0x00 # We deactivate the scrambler by init'ing it with zeros ### Sync ############################################################ sync_detect = digital.ofdm_sync_sc_cfb(fft_len, cp_len) delay = blocks.delay(gr.sizeof_gr_complex, fft_len + cp_len) oscillator = analog.frequency_modulator_fc(-2.0 / fft_len) mixer = blocks.multiply_cc() hpd = digital.header_payload_demux( n_sync_words + 1, # Number of OFDM symbols before payload (sync + 1 sym header) fft_len, cp_len, # FFT length, guard interval frame_length_tag_key, # Frame length tag key "", # We're not using trigger tags True # One output item is one OFDM symbol (False would output complex scalars) ) self.connect(self, sync_detect) self.connect(self, delay, (mixer, 0), (hpd, 0)) self.connect((sync_detect, 0), oscillator, (mixer, 1)) self.connect((sync_detect, 1), (hpd, 1)) if debug_log: self.connect((sync_detect, 0), blocks.file_sink(gr.sizeof_float, 'freq-offset.dat')) self.connect((sync_detect, 1), blocks.file_sink(gr.sizeof_char, 'sync-detect.dat')) ### Header demodulation ############################################## header_fft = fft.fft_vcc(self.fft_len, True, (), True) chanest = digital.ofdm_chanest_vcvc(self.sync_word1, self.sync_word2, 1) header_constellation = _get_constellation(bps_header) header_equalizer = digital.ofdm_equalizer_simpledfe( fft_len, header_constellation.base(), occupied_carriers, pilot_carriers, pilot_symbols, symbols_skipped=0, ) header_eq = digital.ofdm_frame_equalizer_vcvc( header_equalizer.base(), cp_len, self.frame_length_tag_key, True, 1 # Header is 1 symbol long ) header_serializer = digital.ofdm_serializer_vcc( fft_len, occupied_carriers, self.frame_length_tag_key) header_demod = digital.constellation_decoder_cb( header_constellation.base()) header_formatter = digital.packet_header_ofdm( occupied_carriers, 1, packet_length_tag_key, frame_length_tag_key, packet_num_tag_key, bps_header, bps_payload, scramble_header=scramble_bits) header_parser = digital.packet_headerparser_b( header_formatter.formatter()) self.connect((hpd, 0), header_fft, chanest, header_eq, header_serializer, header_demod, header_parser) self.msg_connect(header_parser, "header_data", hpd, "header_data") if debug_log: self.connect((chanest, 1), blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'channel-estimate.dat')) self.connect((chanest, 0), blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'post-hdr-chanest.dat')) self.connect((chanest, 0), blocks.tag_debug(gr.sizeof_gr_complex * fft_len, 'post-hdr-chanest')) self.connect( header_eq, blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'post-hdr-eq.dat')) self.connect( header_serializer, blocks.file_sink(gr.sizeof_gr_complex, 'post-hdr-serializer.dat')) self.connect(header_descrambler, blocks.file_sink(1, 'post-hdr-demod.dat')) ### Payload demod #################################################### payload_fft = fft.fft_vcc(self.fft_len, True, (), True) payload_constellation = _get_constellation(bps_payload) payload_equalizer = digital.ofdm_equalizer_simpledfe( fft_len, payload_constellation.base(), occupied_carriers, pilot_carriers, pilot_symbols, symbols_skipped=1, # (that was already in the header) alpha=0.1) payload_eq = digital.ofdm_frame_equalizer_vcvc( payload_equalizer.base(), cp_len, self.frame_length_tag_key) payload_serializer = digital.ofdm_serializer_vcc( fft_len, occupied_carriers, self.frame_length_tag_key, self.packet_length_tag_key, 1 # Skip 1 symbol (that was already in the header) ) payload_demod = digital.constellation_decoder_cb( payload_constellation.base()) self.payload_descrambler = digital.additive_scrambler_bb( 0x8a, self.scramble_seed, 7, 0, # Don't reset after fixed length bits_per_byte=8, # This is after packing reset_tag_key=self.packet_length_tag_key) payload_pack = blocks.repack_bits_bb(bps_payload, 8, self.packet_length_tag_key, True) self.crc = digital.crc32_bb(True, self.packet_length_tag_key) self.connect((hpd, 1), payload_fft, payload_eq, payload_serializer, payload_demod, payload_pack, self.payload_descrambler, self.crc, self) if debug_log: self.connect((hpd, 1), blocks.tag_debug(gr.sizeof_gr_complex * fft_len, 'post-hpd')) self.connect( payload_fft, blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'post-payload-fft.dat')) self.connect( payload_eq, blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'post-payload-eq.dat')) self.connect( payload_serializer, blocks.file_sink(gr.sizeof_gr_complex, 'post-payload-serializer.dat')) self.connect(payload_demod, blocks.file_sink(1, 'post-payload-demod.dat')) self.connect(payload_pack, blocks.file_sink(1, 'post-payload-pack.dat')) self.connect(crc, blocks.file_sink(1, 'post-payload-crc.dat'))
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.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(4) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.pmt_init_c32vector(fft_len, channel[:fft_len]) src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (len_tag, chan_tag)) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key, True) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, eq, sink) self.tb.run() rx_data = [ cnst.decision_maker_v((x, )) if x != 0 else -1 for x in sink.data() ] # 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.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)
def __init__(self, fft_len=_def_fft_len, cp_len=_def_cp_len, frame_length_tag_key=_def_frame_length_tag_key, packet_length_tag_key=_def_packet_length_tag_key, packet_num_tag_key=_def_packet_num_tag_key, occupied_carriers=_def_occupied_carriers, pilot_carriers=_def_pilot_carriers, pilot_symbols=_def_pilot_symbols, bps_header=1, bps_payload=1, sync_word1=None, sync_word2=None, debug_log=False, scramble_bits=False ): gr.hier_block2.__init__(self, "ofdm_rx", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_char)) ### Param init / sanity check ######################################## self.fft_len = fft_len self.cp_len = cp_len self.frame_length_tag_key = frame_length_tag_key self.packet_length_tag_key = packet_length_tag_key self.occupied_carriers = occupied_carriers self.bps_header = bps_header self.bps_payload = bps_payload n_sync_words = 1 if sync_word1 is None: self.sync_word1 = _make_sync_word1(fft_len, occupied_carriers, pilot_carriers) else: if len(sync_word1) != self.fft_len: raise ValueError("Length of sync sequence(s) must be FFT length.") self.sync_word1 = sync_word1 self.sync_word2 = () if sync_word2 is None: self.sync_word2 = _make_sync_word2(fft_len, occupied_carriers, pilot_carriers) n_sync_words = 2 elif len(sync_word2): if len(sync_word2) != fft_len: raise ValueError("Length of sync sequence(s) must be FFT length.") self.sync_word2 = sync_word2 n_sync_words = 2 if scramble_bits: self.scramble_seed = 0x7f else: self.scramble_seed = 0x00 # We deactivate the scrambler by init'ing it with zeros ### Sync ############################################################ sync_detect = digital.ofdm_sync_sc_cfb(fft_len, cp_len) delay = blocks.delay(gr.sizeof_gr_complex, fft_len+cp_len) oscillator = analog.frequency_modulator_fc(-2.0 / fft_len) mixer = blocks.multiply_cc() hpd = digital.header_payload_demux( n_sync_words+1, # Number of OFDM symbols before payload (sync + 1 sym header) fft_len, cp_len, # FFT length, guard interval frame_length_tag_key, # Frame length tag key "", # We're not using trigger tags True # One output item is one OFDM symbol (False would output complex scalars) ) self.connect(self, sync_detect) self.connect(self, delay, (mixer, 0), (hpd, 0)) self.connect((sync_detect, 0), oscillator, (mixer, 1)) self.connect((sync_detect, 1), (hpd, 1)) if debug_log: self.connect((sync_detect, 0), blocks.file_sink(gr.sizeof_float, 'freq-offset.dat')) self.connect((sync_detect, 1), blocks.file_sink(gr.sizeof_char, 'sync-detect.dat')) ### Header demodulation ############################################## header_fft = fft.fft_vcc(self.fft_len, True, (), True) chanest = digital.ofdm_chanest_vcvc(self.sync_word1, self.sync_word2, 1) header_constellation = _get_constellation(bps_header) header_equalizer = digital.ofdm_equalizer_simpledfe( fft_len, header_constellation.base(), occupied_carriers, pilot_carriers, pilot_symbols, symbols_skipped=0, ) header_eq = digital.ofdm_frame_equalizer_vcvc( header_equalizer.base(), cp_len, self.frame_length_tag_key, True, 1 # Header is 1 symbol long ) header_serializer = digital.ofdm_serializer_vcc( fft_len, occupied_carriers, self.frame_length_tag_key ) header_demod = digital.constellation_decoder_cb(header_constellation.base()) header_formatter = digital.packet_header_ofdm( occupied_carriers, 1, packet_length_tag_key, frame_length_tag_key, packet_num_tag_key, bps_header, bps_payload, scramble_header=scramble_bits ) header_parser = digital.packet_headerparser_b(header_formatter.formatter()) self.connect( (hpd, 0), header_fft, chanest, header_eq, header_serializer, header_demod, header_parser ) self.msg_connect(header_parser, "header_data", hpd, "header_data") if debug_log: self.connect((chanest, 1), blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'channel-estimate.dat')) self.connect((chanest, 0), blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'post-hdr-chanest.dat')) self.connect((chanest, 0), blocks.tag_debug(gr.sizeof_gr_complex * fft_len, 'post-hdr-chanest')) self.connect(header_eq, blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'post-hdr-eq.dat')) self.connect(header_serializer, blocks.file_sink(gr.sizeof_gr_complex, 'post-hdr-serializer.dat')) self.connect(header_descrambler, blocks.file_sink(1, 'post-hdr-demod.dat')) ### Payload demod #################################################### payload_fft = fft.fft_vcc(self.fft_len, True, (), True) payload_constellation = _get_constellation(bps_payload) payload_equalizer = digital.ofdm_equalizer_simpledfe( fft_len, payload_constellation.base(), occupied_carriers, pilot_carriers, pilot_symbols, symbols_skipped=1, # (that was already in the header) alpha=0.1 ) payload_eq = digital.ofdm_frame_equalizer_vcvc( payload_equalizer.base(), cp_len, self.frame_length_tag_key ) payload_serializer = digital.ofdm_serializer_vcc( fft_len, occupied_carriers, self.frame_length_tag_key, self.packet_length_tag_key, 1 # Skip 1 symbol (that was already in the header) ) payload_demod = digital.constellation_decoder_cb(payload_constellation.base()) self.payload_descrambler = digital.additive_scrambler_bb( 0x8a, self.scramble_seed, 7, 0, # Don't reset after fixed length bits_per_byte=8, # This is after packing reset_tag_key=self.packet_length_tag_key ) payload_pack = blocks.repack_bits_bb(bps_payload, 8, self.packet_length_tag_key, True) self.crc = digital.crc32_bb(True, self.packet_length_tag_key) self.connect( (hpd, 1), payload_fft, payload_eq, payload_serializer, payload_demod, payload_pack, self.payload_descrambler, self.crc, self ) if debug_log: self.connect((hpd, 1), blocks.tag_debug(gr.sizeof_gr_complex*fft_len, 'post-hpd')) self.connect(payload_fft, blocks.file_sink(gr.sizeof_gr_complex*fft_len, 'post-payload-fft.dat')) self.connect(payload_eq, blocks.file_sink(gr.sizeof_gr_complex*fft_len, 'post-payload-eq.dat')) self.connect(payload_serializer, blocks.file_sink(gr.sizeof_gr_complex, 'post-payload-serializer.dat')) self.connect(payload_demod, blocks.file_sink(1, 'post-payload-demod.dat')) self.connect(payload_pack, blocks.file_sink(1, 'post-payload-pack.dat')) self.connect(crc, blocks.file_sink(1, 'post-payload-crc.dat'))
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.gr_tag_t() len_tag.offset = 0 len_tag.key = pmt.pmt_string_to_symbol(len_tag_key) len_tag.value = pmt.pmt_from_long(4) chan_tag = gr.gr_tag_t() chan_tag.offset = 0 chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps") chan_tag.value = pmt.pmt_init_c32vector(fft_len, channel[:fft_len]) src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (len_tag, chan_tag)) eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key, True) sink = gr.vector_sink_c(fft_len) self.tb.connect(src, eq, sink) self.tb.run () rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()] # 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.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)