示例#1
0
 def __init__(self, data, len_tag_key, scramble_bits=False):
     gr.top_block.__init__(self, "ofdm_tx")
     tx_data, tags = tagged_streams.packets_to_vectors((data,), len_tag_key)
     src = blocks.vector_source_b(data, False, 1, tags)
     self.tx = ofdm_tx(packet_length_tag_key=len_tag_key, debug_log=LOG_DEBUG_INFO, scramble_bits=scramble_bits)
     self.sink = blocks.vector_sink_c()
     self.connect(src, self.tx, self.sink)
 def test_004_ofdm_packets (self):
     """
     Send several bursts using ofdm_tx, see if the number of detects is correct.
     Burst lengths and content are random.
     """
     n_bursts = 42
     fft_len = 64
     cp_len = 16
     # Here, coarse freq offset is allowed
     max_freq_offset = 2*numpy.pi/fft_len * 4
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     tx_signal = []
     packets = []
     tagname = "packet_length"
     min_packet_length = 10
     max_packet_length = 50
     sync_sequence = [random.randint(0, 1)*2-1 for x in range(fft_len/2)]
     for i in xrange(n_bursts):
         packet_length = random.randint(min_packet_length,
                                        max_packet_length+1)
         packet = [random.randint(0, 255) for i in range(packet_length)]
         packets.append(packet)
     data, tags = tagged_streams.packets_to_vectors(packets, tagname, vlen=1)
     total_length = len(data)
     src = blocks.vector_source_b(data, False, 1, tags)
     mod = ofdm_tx(packet_length_tag_key=tagname)
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     sink_freq   = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     noise_level = 0.005
     channel = channels.channel_model(noise_level, freq_offset / 2 / numpy.pi)
     self.tb.connect(src, mod, channel, sync, sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     self.assertEqual(numpy.sum(sink_detect.data()), n_bursts)
示例#3
0
 def test_001_tx (self):
     """ Just make sure the Tx works in general """
     len_tag_key = 'frame_len'
     n_bytes = 52
     n_samples_expected = (numpy.ceil(1.0 * (n_bytes + 4) / 6) + 3) * 80
     test_data = [random.randint(0, 255) for x in range(n_bytes)]
     tx_data, tags = tagged_streams.packets_to_vectors((test_data,), len_tag_key)
     src = blocks.vector_source_b(test_data, False, 1, tags)
     tx = ofdm_tx(packet_length_tag_key=len_tag_key)
     tx_fg = ofdm_tx_fg(test_data, len_tag_key)
     tx_fg.run()
     self.assertEqual(len(tx_fg.get_tx_samples()), n_samples_expected)