Esempio n. 1
0
    def test_003_multiburst(self):
        """ Send several bursts, see if the number of detects is correct.
        Burst lengths and content are random.
        """
        n_bursts = 42
        fft_len = 32
        cp_len = 4
        tx_signal = []
        for i in xrange(n_bursts):
            sync_symbol = [(random.randint(0, 1) * 2) - 1
                           for x in range(fft_len / 2)] * 2
            tx_signal += [0,] * random.randint(0, 2*fft_len) + \
                         sync_symbol[-cp_len:] + \
                         sync_symbol + \
                         [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))]
        add = blocks.add_cc()
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq = blocks.vector_sink_f()
        sink_detect = blocks.vector_sink_b()
        channel = channels.channel_model(0.005)
        self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
        self.tb.connect((sync, 0), sink_freq)
        self.tb.connect((sync, 1), sink_detect)
        self.tb.run()
        n_bursts_detected = numpy.sum(sink_detect.data())
        # We allow for one false alarm or missed burst
        self.assertTrue(
            abs(n_bursts_detected - n_bursts) <= 1,
            msg="""Because of statistics, it is possible (though unlikely)
that the number of detected bursts differs slightly. If the number of detects is
off by one or two, run the test again and see what happen.
Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts))
 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)
    def test_003_multiburst (self):
        """ Send several bursts, see if the number of detects is correct.
        Burst lengths and content are random.
        """
        n_bursts = 42
        fft_len = 32
        cp_len = 4
        tx_signal = []
        for i in xrange(n_bursts):
            sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
            tx_signal += [0,] * random.randint(0, 2*fft_len) + \
                         sync_symbol[-cp_len:] + \
                         sync_symbol + \
                         [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))]
        add = blocks.add_cc()
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq   = blocks.vector_sink_f()
        sink_detect = blocks.vector_sink_b()
        channel = channels.channel_model(0.005)
        self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
        self.tb.connect((sync, 0), sink_freq)
        self.tb.connect((sync, 1), sink_detect)
        self.tb.run()
        n_bursts_detected = numpy.sum(sink_detect.data())
        # We allow for one false alarm or missed burst
        self.assertTrue(abs(n_bursts_detected - n_bursts) <= 1,
                msg="""Because of statistics, it is possible (though unlikely)
that the number of detected bursts differs slightly. If the number of detects is
off by one or two, run the test again and see what happen.
Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts)
        )
Esempio n. 4
0
    def test_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        freq = 100

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = channels.channel_model(0.0, 0.0, 1.0, [
            1,
        ], 0)
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        op.set_noise_voltage(0.0)
        op.set_frequency_offset(0.0)
        op.set_taps([
            1,
        ])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, snk)
        self.tb.connect(op, snk1)
        self.tb.run()

        dst_data = snk.data()
        exp_data = snk1.data()
        self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
Esempio n. 5
0
 def test_002_rx_only_noise(self):
     """ Run the RX with only noise, check it doesn't crash
     or return a burst. """
     len_tag_key = 'frame_len'
     samples = (0,) * 1000
     channel = channels.channel_model(0.1)
     rx_fg = ofdm_rx_fg(samples, len_tag_key, channel)
     rx_fg.run()
     self.assertEqual(len(rx_fg.get_rx_bytes()), 0)
Esempio n. 6
0
 def test_004_tx1packet_large_fO(self):
     """ Transmit one packet, with slight AWGN and large frequency offset.
     Check packet is received and no bit errors have occurred. """
     fft_len = 64
     len_tag_key = 'frame_len'
     n_bytes = 21
     test_data = tuple([random.randint(0, 255) for x in range(n_bytes)])
     #test_data = tuple([255 for x in range(n_bytes)])
     # 1.0/fft_len is one sub-carrier
     frequency_offset = 1.0 / fft_len * 2.5
     channel = channels.channel_model(0.00001, frequency_offset)
     # Tx
     tx_fg = ofdm_tx_fg(test_data, len_tag_key)
     tx_fg.run()
     tx_samples = tx_fg.get_tx_samples()
     # Rx
     rx_fg = ofdm_rx_fg(tx_samples, len_tag_key, channel, prepend_zeros=100)
     rx_fg.run()
     rx_data = rx_fg.get_rx_bytes()
     self.assertEqual(test_data, rx_data)
Esempio n. 7
0
 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)
 def test_002_freq (self):
     """ Add a fine frequency offset and see if that get's detected properly """
     fft_len = 32
     cp_len = 4
     # This frequency offset is normalized to rads, i.e. \pi == f_s/2
     max_freq_offset = 2*numpy.pi/fft_len # Otherwise, it's coarse
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     sig_len = (fft_len + cp_len) * 10
     sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
     tx_signal = sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len, True)
     sink_freq   = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     channel = channels.channel_model(0.005, freq_offset / 2.0 / numpy.pi)
     self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     phi_hat = sink_freq.data()[sink_detect.data().index(1)]
     est_freq_offset = 2 * phi_hat / fft_len
     self.assertAlmostEqual(est_freq_offset, freq_offset, places=2)
Esempio n. 9
0
    def test_000(self):
        N = 1000         # number of samples to use
        fs = 1000        # baseband sampling rate
        freq = 100

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = channels.channel_model(0.0, 0.0, 1.0, [1,], 0)
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        op.set_noise_voltage(0.0)
        op.set_frequency_offset(0.0)
        op.set_taps([1,])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, snk)
        self.tb.connect(op, snk1)
        self.tb.run() 
        
        dst_data = snk.data()
        exp_data = snk1.data()
        self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
Esempio n. 10
0
 def test_002_freq(self):
     """ Add a fine frequency offset and see if that get's detected properly """
     fft_len = 32
     cp_len = 4
     # This frequency offset is normalized to rads, i.e. \pi == f_s/2
     max_freq_offset = 2 * numpy.pi / fft_len  # Otherwise, it's coarse
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     sig_len = (fft_len + cp_len) * 10
     sync_symbol = [(random.randint(0, 1) * 2) - 1
                    for x in range(fft_len / 2)] * 2
     tx_signal = sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len, True)
     sink_freq = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     channel = channels.channel_model(0.005, freq_offset / 2.0 / numpy.pi)
     self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     phi_hat = sink_freq.data()[sink_detect.data().index(1)]
     est_freq_offset = 2 * phi_hat / fft_len
     self.assertAlmostEqual(est_freq_offset, freq_offset, places=2)