def test_001_t (self):
                # set up fg
                src_data = (0.1, 0.2, 0.3, 0.2, 0.1, 0, -0.2, -0.4, -0.6, -1, -0.6, -0.4, -0.2, 0)
                src = blocks.vector_source_f(src_data)
                sink = streamsink.streamsink(48000, 128, "SHOUTcast", "127.0.0.1", 8001, "-!1streamSDR9$_")
                self.tb.connect(src, sink)

                self.tb.run ()
                # check data


                if __name__ == '__main__':
                    gr_unittest.run(qa_streamsink, "qa_streamsink.xml")
Example #2
0
        src = blocks.vector_source_c(self.src_data)
        op = filter.freq_xlating_fft_filter_ccc(decim, self.taps, self.fc,
                                                self.fs)
        dst = blocks.vector_sink_c()
        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assert_fft_ok(expected_data, result_data)

    def test_fft_filter_ccc_002(self):
        self.generate_ccc_source()

        decim = 4
        lo = sig_source_c(self.fs, -self.fc, 1, len(self.src_data))
        despun = mix(lo, self.src_data)
        expected_data = fir_filter(despun, self.taps, decim)

        src = blocks.vector_source_c(self.src_data)
        op = filter.freq_xlating_fft_filter_ccc(decim, self.taps, self.fc,
                                                self.fs)
        dst = blocks.vector_sink_c()
        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assert_fft_ok(expected_data, result_data)


if __name__ == '__main__':
    gr_unittest.run(test_freq_xlating_filter)
        thr2 = 20

        op = analog.simple_squelch_cc(thr1, alpha)

        op.set_threshold(thr2)
        t = op.threshold()
        self.assertEqual(thr2, t)

    def test_simple_squelch_002(self):
        alpha = 0.0001
        thr = -25

        src_data = map(lambda x: float(x)/10.0, range(1, 40))
        src = blocks.vector_source_c(src_data)
        op = analog.simple_squelch_cc(thr, alpha)
        dst = blocks.vector_sink_c()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        expected_result = src_data
        expected_result[0:20] = 20*[0,]

        result_data = dst.data()
        self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4)

if __name__ == '__main__':
    gr_unittest.run(test_simple_squelch, "test_simple_squelch.xml")

# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import howto_swig as howto

class qa_ofdm_carrier_allocator_cvc (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_ofdm_carrier_allocator_cvc, "qa_ofdm_carrier_allocator_cvc.xml")
Example #5
0
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
import rscoding_bb_swig as rscoding_bb

class qa_decode_bb (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_decode_bb, "qa_decode_bb.xml")
Example #6
0
        num_frames = 5
        total_subcarriers = 8
        used_subcarriers = 4
        channel_map = ft.get_channel_map(used_subcarriers, total_subcarriers)
        payload_symbols = 8
        overlap = 4
        num_preamble_symbols = 4

        payload = ft.get_payload(payload_symbols, used_subcarriers)
        frame = ft.get_frame(payload, total_subcarriers, channel_map, payload_symbols, overlap)
        frame = np.tile(frame, num_frames).flatten()
        payload = np.tile(payload, num_frames).flatten()

        # set up fg
        src = blocks.vector_source_c(frame, repeat=False, vlen=total_subcarriers)
        deframer = fbmc.deframer_vcb(used_subcarriers, total_subcarriers, num_preamble_symbols, payload_symbols, overlap, channel_map)
        snk = blocks.vector_sink_b(1)
        self.tb.connect(src, deframer, snk)
        self.tb.run()

        # check data
        res = np.array(snk.data())
        print res
        print payload

        self.assertTupleEqual(tuple(payload), tuple(res))


if __name__ == '__main__':
    gr_unittest.run(qa_deframer_vcb, "qa_deframer_vcb.xml")
    def test_001_t (self): # very basic test
        self.cfg = fbmc.fbmc_config(num_used_subcarriers=8, num_payload_sym=18, num_overlap_sym=4, modulation="QPSK", preamble="IAM")
    	num_items = 3;
    	self.src = blocks.vector_source_c([complex(i,i) for i in range(1,self.cfg.num_total_subcarriers()+1)], vlen=self.cfg.num_total_subcarriers(), repeat=True)
    	self.head = blocks.head(gr.sizeof_gr_complex*self.cfg.num_total_subcarriers(),num_items)
    	self.ppfb = fbmc.polyphase_filterbank_vcvc(L=self.cfg.num_total_subcarriers(), prototype_taps=self.cfg.prototype_taps())
    	self.snk = blocks.vector_sink_c(vlen=self.cfg.num_total_subcarriers())
    	self.tb.connect(self.src, self.head, self.ppfb, self.snk)
        self.tb.run ()
        # check data
        data = self.snk.data()
        self.assertEqual(len(data), self.cfg.num_total_subcarriers()*num_items)
        
    def test_002_t (self): # again, just checking the length of the output
        self.cfg = fbmc.fbmc_config(num_used_subcarriers=64, num_payload_sym=18, num_overlap_sym=4, modulation="QPSK", preamble="IAM")
    	num_items = 10000
    	n = self.cfg.num_used_subcarriers()*num_items
    	input_data = range(n)
    	self.src = blocks.vector_source_c(input_data, vlen=self.cfg.num_total_subcarriers(), repeat=False)
    	self.ppfb = fbmc.polyphase_filterbank_vcvc(L=self.cfg.num_total_subcarriers(), prototype_taps=self.cfg.prototype_taps())
    	self.snk = blocks.vector_sink_c(vlen=self.cfg.num_total_subcarriers())
    	self.tb.connect(self.src, self.ppfb, self.snk)
        self.tb.run ()
        # check data
        data = self.snk.data()
        self.assertEqual(len(data), n)       

if __name__ == '__main__':
    gr_unittest.run(qa_polyphase_filterbank_vcvc)
# -*- coding: utf-8 -*-

from gnuradio import gr, gr_unittest
from gnuradio import blocks
from bit_source import bit_source

class qa_bit_source (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        src_data = range(50)
        expected_result = tuple(src_data)
        src = bit_source(src_data, repeat=False)
        snk = blocks.vector_sink_b()

        self.tb.connect(src,snk)
        self.tb.run ()

        # check data
        result_data = snk.data()
        self.assertEqual(expected_result, result_data)

if __name__ == '__main__':
    gr_unittest.run(qa_bit_source, "qa_bit_source.xml")
Example #9
0
        self.tb.msg_connect((self.emitter, 'msg'), (self.ctm2, 'cpdus'))
        self.tb.msg_connect((self.ctm2, 'fpdus'), (self.debug, 'store'))

        # gnuradio uses single-precision floats by default
        i_vec = pmt.init_c32vector(3, [3 + 4j, 1 + 0j, 0 + 1j])
        e_vec = pmt.init_f32vector(3, [25, 1, 1])

        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print "test ctm2:"
        print "pdu expected: " + repr(pmt.car(e_pdu))
        print "pdu got:      " + repr(pmt.car(self.debug.get_message(0)))
        print "data expected: " + repr(pmt.to_python(pmt.cdr(e_pdu)))
        print "data got:      " + repr(
            pmt.to_python(pmt.cdr(self.debug.get_message(0))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))


if __name__ == '__main__':
    gr_unittest.run(qa_pdu_complex_to_mag2, "qa_pdu_complex_to_mag2.xml")
            "0001011101101101011100001111001100010001000011011001101110011010000111011101001000011101010010111011100111000001011100100001111010100101111000100000",
            "0000001000100011000000000000110100000000010000001010100100001010000111011101001000011101000010010000000000001001000001011000000001010000000100010000",
            "0000100000110001000000000100000110001011100001001000000000001010000111011101001000011101001010010001010000000111010000000011000001000000000101010000"
        ]

        bursts_expected = [
            "0001000101000000001001111110000110010110110111110111101000001101001111101100010100111111001110001001110101110001010001000111011010010001011011000000",
            "0000010000000010000001001000011001010010000011000101000000001010000111011101001000011101010100100000000001001000001000000100100011000101001000111000",
            "0001100001000111111111100001011000000011010110111010110000111010000111011101001000011101100010111100100101110001101000110100110000001010101110011000",
            "0000110101000011011010110000110011010000000001001010110010001010000111011101001000011101010000011000111001101110000000110010100001101110101000100000"
        ]

        timeslot = 1
        src = grgsm.burst_source(framenumbers_input, timeslots_input,
                                 bursts_input)
        ts_filter = grgsm.burst_timeslot_filter(timeslot)
        sink = grgsm.burst_sink()

        self.tb.msg_connect(src, "out", ts_filter, "in")
        self.tb.msg_connect(ts_filter, "out", sink, "in")

        self.tb.run()

        bursts_result = list(sink.get_burst_data())

        self.assertEqual(bursts_expected, bursts_result)


if __name__ == '__main__':
    gr_unittest.run(qa_burst_timeslot_filter, "qa_burst_timeslot_filter.xml")
        src2_data =       [8,  2,  1 , 0x05000508,   0x11001105]
        expected_result = [9,  2,  3,  0x5500550C,   0x11001155]
        op = blocks.or_ii ()
        self.help_ii ((src1_data, src2_data),
                      expected_result, op)

    def test_not_ss (self):
        src1_data =       [1,      2,      3,       0x5004,   0x1150]
        expected_result = [~1,     ~2,      ~3,       ~0x5004,   ~0x1150]
        op = blocks.not_ss ()
        self.help_ss ((((src1_data),)),
                      expected_result, op)

    def test_not_bb (self):
        src1_data =       [1,     2,    2,     3,     0x04,   0x50]
        expected_result = [0xFE,  0xFD, 0xFD,  0xFC,  0xFB,   0xAF]
        op = blocks.not_bb ()
        self.help_bb (((src1_data), ),
                      expected_result, op)

    def test_not_ii (self):
        src1_data =       [1,    2,  3,  0x50005004,   0x11001150]
        expected_result = [~1 , ~2, ~3, ~0x50005004,  ~0x11001150]
        op = blocks.not_ii ()
        self.help_ii (((src1_data),),
                      expected_result, op)


if __name__ == '__main__':
    gr_unittest.run(test_boolean_operators, "test_boolean_operators.xml")
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import meu_swig as meu


class qa_qpsk_modulator_adapt_cb(gr_unittest.TestCase):
    def setUp(self):
        self.tb = gr.top_block()

    def tearDown(self):
        self.tb = None

    def test_001_t(self):
        # set up fg
        self.tb.run()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_qpsk_modulator_adapt_cb,
                    "qa_qpsk_modulator_adapt_cb.xml")
        result_tags = dst.tags()
        self.assertEqual(len(result_data), len(payload)*8)
        self.assertEqual(result_tags[0].offset, 0)
        self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8)
        self.assertEqual(result_data, expected)

    def test_002(self):
        payload = "test packet"     # payload length is 11 bytes
        header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped)
        packet = header + payload
        pad = (0,) * 64
        src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad
        src_floats = tuple(2*b-1 for b in src_data) # convert to binary antipodal symbols (-1,1)
        expected = src_floats[9+32:-len(pad)]
        src = blocks.vector_source_f(src_floats)
        op = digital.correlate_access_code_ff_ts("1011", 0, "sync")
        dst = blocks.vector_sink_f()
        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = dst.data()
        result_tags = dst.tags()
        self.assertEqual(len(result_data), len(payload)*8)
        self.assertEqual(result_tags[0].offset, 0)
        self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8)
        self.assertFloatTuplesAlmostEqual(result_data, expected, 5)


if __name__ == '__main__':
    gr_unittest.run(test_correlate_access_code_XX_ts, "test_correlate_access_code_XX_ts.xml")

Example #14
0
        self.dst = blocks.vector_sink_c()
        self.addbefafter = capture_tools.add_before_and_after_cc(10, 15, 0, 0)
        self.tb.connect(self.src, self.addbefafter, self.dst)
        self.tb.run()
        self.assertEqual(self.dst.data(),
                         (0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, (1 + 0j),
                          (2 + 0j), (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j),
                          (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j),
                          (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j),
                          (0 + 0j)))
        # check data

    def test_005_t(self):
        # set up fg
        self.src = blocks.vector_source_c([1])
        self.dst = blocks.vector_sink_c()
        self.addbefafter = capture_tools.add_before_and_after_cc(10, 15, 0, 0)
        self.tb.connect(self.src, self.addbefafter, self.dst)
        self.tb.run()
        self.assertEqual(self.dst.data(),
                         (0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, (1 + 0j),
                          (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j),
                          (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j),
                          (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j), (0 + 0j)))
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_add_before_and_after_cc,
                    "qa_add_before_and_after_cc.xml")
Example #15
0
                # 2 * -1
                2 * 4 + 0.00,
                # [-1, 0)
                # 1 * -1
                1 * 4 + 0.00,
                # [ 0, 1)
                # -1 * 0
                1 * 1 +
                # 1 * 0
                1 * 1 +
                # 2 * 0
                2 * 1 + 0.00,
                # [ 1, 2)
                # -1 * -1
                1 * 4 + 0.00,
                # [ 2, 3)
                # 1 * 2
                1 * 1 + 0.00,
                # [ 3, 4)
                0.00,
                # [ 4, 5)
                # 2 * 2
                2 * 1 + 0.00,
            ],
            unkhist,
            7)


if __name__ == '__main__':
    gr_unittest.run(qa_histogram_solve)
Example #16
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
from display_rate_file import display_rate_file

class qa_display_rate_file (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_display_rate_file, "qa_display_rate_file.xml")
Example #17
0
        self.tb.connect(trg, (op,1))
        self.tb.connect(op, snk)
        self.tb.run()

        # Tagged file sink gets 2 burst tags at index 2 and index 5.
        # Creates two new files, each with two integers in them from
        # src_data at these indexes (3,4) and (7,8).
        file0 = "file{0}_0_2.00000000.dat".format(snk.unique_id())
        file1 = "file{0}_1_6.00000000.dat".format(snk.unique_id())

        # Open the files and read in the data, then remove the files
        # to clean up the directory.
        outfile0 = file(file0, 'rb')
	outfile1 = file(file1, 'rb')
	data0 = outfile0.read(8)
	data1 = outfile1.read(8)
        outfile0.close()
        outfile1.close()
	os.remove(file0)
	os.remove(file1)

        # Convert the 8 bytes from the files into a tuple of 2 ints.
        idata0 = struct.unpack('ii', data0)
        idata1 = struct.unpack('ii', data1)

        self.assertEqual(idata0, (3, 4))
        self.assertEqual(idata1, (7, 8))

if __name__ == '__main__':
    gr_unittest.run(test_tag_file_sink, "test_tag_file_sink.xml")
Example #18
0
        freq = float(sum(freqs)) / len(freqs)
        freq /= 2 * math.pi
        return freq

    def get_expected_data(self, L):

        # Filter delay is the normal delay of each arm
        tpf = math.ceil(len(self.taps) / float(self.M))
        delay = -(tpf - 1.0) / 2.0
        delay = int(delay)

        # Create a time scale that's delayed to match the filter delay
        t = [float(x) / self.fs for x in range(delay, L + delay)]

        # Create known data as complex sinusoids at the different baseband freqs
        # the different channel numbering is due to channelizer output order.
        expected_data = [[math.cos(2. *
                                   math.pi *
                                   f *
                                   x) +
                          1j *
                          math.sin(2. *
                                   math.pi *
                                   f *
                                   x) for x in t] for f in self.freqs]
        return expected_data


if __name__ == '__main__':
    gr_unittest.run(test_pfb_channelizer)
Example #19
0
        dbg0 = blocks.message_debug()
        dbg1 = blocks.message_debug()
        dbg2 = blocks.message_debug()

        self.tb.connect(src, fir, sync)
        self.tb.msg_connect((sync, 'control'), (dbg0, 'store'))
        self.tb.msg_connect((sync, 'N_id_2'), (dbg1, 'store'))
        self.tb.msg_connect((sync, 'coarse_pos'), (dbg2, 'store'))
        # set up fg
        self.tb.run()
        # check data
        self.assertEqual(pmt.to_long(dbg1.get_message(0)), int(cell_id % 3))

        ctrl_res = pmt.to_bool(dbg0.get_message(0))
        assert ctrl_res

        offset = 10 + 5 * 9 + 6 * fftlen
        print(offset)

        # print()
        pos = pmt.to_long(dbg2.get_message(0))
        print(pos)
        print(pos * 2 - (len(taps) // 2))
        import matplotlib.pyplot as plt
        plt.plot(np.abs(samps))
        plt.show()


if __name__ == '__main__':
    gr_unittest.run(qa_mimo_pss_freq_sync)
Example #20
0
        op.set_amplitude(2)
        a = op.amplitude()
        self.assertEqual(2, a)

        freq = 2 * math.pi / 2.0
        f = op.freq()
        self.assertAlmostEqual(freq, f, 5)

        p = op.phase()
        self.assertEqual(0, p)

    def test_cpfsk_bc_002(self):
        src_data = 10 * [0, 1]
        expected_result = map(lambda x: complex(2 * x - 1, 0), src_data)

        src = gr.vector_source_b(src_data)
        op = analog.cpfsk_bc(2, 1, 2)
        dst = gr.vector_sink_c()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        result_data = dst.data()[0:len(expected_result)]
        self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4)


if __name__ == '__main__':
    gr_unittest.run(test_cpfsk_bc, "test_cpfsk_bc.xml")
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
from non_zero_file_sink import non_zero_file_sink

class qa_non_zero_file_sink (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_non_zero_file_sink, "qa_non_zero_file_sink.xml")
Example #22
0
        src_data = (2.0, )
        op = blocks.multiply_const_vff((3.0, ))
        exp_data = (6.0, )
        self.help_const_ff(src_data, exp_data, op)

    def test_multiply_const_vff_five(self):
        src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
        op = blocks.multiply_const_vff((6.0, 7.0, 8.0, 9.0, 10.0))
        exp_data = (6.0, 14.0, 24.0, 36.0, 50.0)
        self.help_const_ff(src_data, exp_data, op)

    def test_multiply_const_vcc_one(self):
        src_data = (1.0 + 2.0j, )
        op = blocks.multiply_const_vcc((2.0 + 3.0j, ))
        exp_data = (-4.0 + 7.0j, )
        self.help_const_cc(src_data, exp_data, op)

    def test_multiply_const_vcc_five(self):
        src_data = (1.0 + 2.0j, 3.0 + 4.0j, 5.0 + 6.0j, 7.0 + 8.0j,
                    9.0 + 10.0j)
        op = blocks.multiply_const_vcc(
            (11.0 + 12.0j, 13.0 + 14.0j, 15.0 + 16.0j, 17.0 + 18.0j,
             19.0 + 20.0j))
        exp_data = (-13.0 + 34.0j, -17.0 + 94.0j, -21.0 + 170.0j,
                    -25.0 + 262.0j, -29.0 + 370.0j)
        self.help_const_cc(src_data, exp_data, op)


if __name__ == '__main__':
    gr_unittest.run(test_add_mult_v, "test_add_mult_v.xml")
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import gfdm_swig as gfdm

class qa_cyclic_prefixer_cc (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_cyclic_prefixer_cc, "qa_cyclic_prefixer_cc.xml")
Example #24
0
        P1_dB = -12  #too high power leads to false detection
        P2_dB = -9

        tau = int(15 * R * N + STO * R)

        S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3
        S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3

        p1 = lora.gen_packet(SF, S1, R=R)
        p2 = lora.gen_packet(SF, S2, R=R)

        x1 = np.sqrt(10**(P1_dB / 10.0)) * np.concatenate(
            [np.zeros(0), p1, np.zeros(tau)])
        x2 = np.sqrt(10**(P2_dB / 10.0)) * np.concatenate(
            [np.zeros(tau), p2, np.zeros(0)])

        x2 = lora.add_cfo(SF, x2, CFO, R=R)

        x = np.concatenate([x1 + x2, np.zeros(20 * N * R)])

        S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
        self.assertEqual(S1, S1_out)
        self.assertEqual(S2, S2_out)


if __name__ == '__main__':
    #import os
    #print 'Blocked waiting for GDB attach (pid = %d)' % (os.getpid(),)
    #raw_input ('Press Enter to continue: ')
    gr_unittest.run(qa_mu_demod, "qa_mu_demod.xml")
Example #25
0
        self.src = drm.generate_fac_b(self.tp)
        self.head = blocks.head(1, self.tp.fac().L() * 3)
        self.snk = blocks.vector_sink_b()
        
        self.tb.connect(self.src, self.head, self.snk)

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data
        res = self.snk.data()
        # three consecutive FAC blocks
        ref =  (0,1,1,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, \
				0,0,1,0,0,0,1,1,0,1,0,0,0,1,0,1,0,0,0,0,1,1,1,0,0,0,0,1, \
				1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1, \
				0,0,1,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, \
				0,0,1,0,0,0,1,1,0,1,0,0,0,1,0,1,0,0,0,0,1,1,1,0,0,0,0,1, \
				1,0,0,0,0,0,0,0,1,1,0,1,1,0,1,1, \
				0,1,0,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, \
				0,0,1,0,0,0,1,1,0,1,0,0,0,1,0,1,0,0,0,0,1,1,1,0,0,0,0,1, \
				1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0)
        # check data
        self.assertTupleEqual(res, ref)


if __name__ == '__main__':
    gr_unittest.run(qa_generate_fac_b, "qa_generate_fac_b.xml")
Example #26
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import CyberRadio_swig as CyberRadio

class qa_ndr651_sink (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_ndr651_sink, "qa_ndr651_sink.xml")
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import ieee802_15_4_swig as ieee802_15_4

class qa_chips_to_bits_fb (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        chips_in = (3,2,-2,-3, 4,-3,3,-4, -2,2,-1,1.5, -1.5,-1.2,2,1)
        self.src = blocks.vector_source_f(chips_in)
        self.c2b = ieee802_15_4.chips_to_bits_fb([[1,1,0,0],[1,0,1,0],[0,1,0,1],[0,0,1,1]])
        self.snk = blocks.vector_sink_b(1)
        self.tb.connect(self.src, self.c2b, self.snk)
        self.tb.run ()
        # check data
        bits_out = self.snk.data()
        ref = (0,0,1,0,0,1,1,1)
        self.assertFloatTuplesAlmostEqual(bits_out, ref)

if __name__ == '__main__':
    gr_unittest.run(qa_chips_to_bits_fb, "qa_chips_to_bits_fb.xml")
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
from ra_integrate import ra_integrate

class qa_ra_integrate (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_ra_integrate, "qa_ra_integrate.xml")
        self.tb.run()
        self.assertEqual(expected_results, dst.data())

    def test_004(self):

        #Test vector_to_streams.

        n = 8
        src_len = n * 8
        src_data = tuple(range(src_len))
        expected_results = src_data

        src = gr.vector_source_i(src_data)
        op1 = gr.stream_to_vector(gr.sizeof_int, n)
        op2 = gr.vector_to_streams(gr.sizeof_int, n)
        op3 = gr.streams_to_stream(gr.sizeof_int, n)
        dst = gr.vector_sink_i()

        self.tb.connect(src, op1, op2)
        for i in range(n):
            self.tb.connect((op2, i), (op3, i))
        self.tb.connect(op3, dst)

        self.tb.run()
        self.assertEqual(expected_results, dst.data())


if __name__ == '__main__':
    gr_unittest.run(test_pipe_fittings, "test_pipe_fittings.xml")
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import dvbt2ll_swig as dvbt2ll

class qa_interleavermod_bc (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_interleavermod_bc, "qa_interleavermod_bc.xml")
Example #31
0
    def test_002_checkwavcopy(self):
	infile  = g_in_file
	outfile = "test_out.wav"

	wf_in  = blocks.wavfile_source(infile)
	wf_out = blocks.wavfile_sink(outfile,
                                     wf_in.channels(),
                                     wf_in.sample_rate(),
                                     wf_in.bits_per_sample())
	self.tb.connect(wf_in, wf_out)
	self.tb.run()
	wf_out.close()

	# we're loosing all extra header chunks
	self.assertEqual(getsize(infile) - g_extra_header_len, getsize(outfile))

	in_f  = file(infile,  'rb')
	out_f = file(outfile, 'rb')

	in_data  = in_f.read()
	out_data = out_f.read()
        out_f.close()
	os.remove(outfile)
	# cut extra header chunks input file
	self.assertEqual(in_data[:g_extra_header_offset] + \
	                 in_data[g_extra_header_offset + g_extra_header_len:], out_data)

if __name__ == '__main__':
    gr_unittest.run(test_wavefile, "test_wavefile.xml")
Example #32
0
        in_data = [99, 44]
        expected_data = [
            99,
        ] * 512 + [
            44,
        ] * 512
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_s32vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_s32vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.05)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
        self.assertTrue(pmt.equal(self.debug.get_message(1), expected_pdu))


if __name__ == '__main__':
    gr_unittest.run(qa_upsample)
Example #33
0
        self.help_ii ((src1_data,),
                      expected_result, op)

    def test_sub_ii_2 (self):
        src1_data = (1,  2, 3, 4, 5)
        src2_data = (8, -3, 4, 8, 2)
        expected_result = (-7, 5, -1, -4, 3)
        op = extras.subtract_s32_s32(2)
        self.help_ii ((src1_data, src2_data),
                      expected_result, op)

    def test_div_ff_1 (self):
        src1_data       = (1,  2,  4,    -8)
        expected_result = (1, 0.5, 0.25, -.125)
        op = extras.divide_f32_f32(1)
        self.help_ff ((src1_data,),
                      expected_result, op)

    def test_div_ff_2 (self):
        src1_data       = ( 5,  9, -15, 1024)
        src2_data       = (10,  3,  -5,   64)
        expected_result = (0.5, 3,   3,   16)
        op = extras.divide_f32_f32(2)
        self.help_ff ((src1_data, src2_data),
                      expected_result, op)



if __name__ == '__main__':
    gr_unittest.run(test_add_and_friends, "test_add_and_friends.xml")
Example #34
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import aistx_swig as aistx


class qa_Build_Frame_From_Input(gr_unittest.TestCase):
    def setUp(self):
        self.tb = gr.top_block()

    def tearDown(self):
        self.tb = None

    def test_001_t(self):
        # set up fg
        self.tb.run()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_Build_Frame_From_Input, "qa_Build_Frame_From_Input.xml")
Example #35
0
        src = blocks.message_source(gr.sizeof_char, msgq)
        dst = gr.vector_sink_b()
	tb = gr.top_block()
        tb.connect(src, dst)
        src.msgq().insert_tail(gr.message_from_string('01234'))
        src.msgq().insert_tail(gr.message_from_string('5'))
        src.msgq().insert_tail(gr.message_from_string(''))
        src.msgq().insert_tail(gr.message_from_string('6789'))
        src.msgq().insert_tail(gr.message(1))                  # send EOF
        tb.run()
        self.assertEquals(tuple(map(ord, '0123456789')), dst.data())

    def test_debug_401(self):
        msg = pmt.pmt_intern("TESTING")
        src = blocks.message_strobe(msg, 500)
        snk = blocks.message_debug()

	tb = gr.top_block()
        tb.msg_connect(src, "strobe", snk, "store")
        tb.start()
        time.sleep(1)
        tb.stop()
        tb.wait()

        rec_msg = snk.get_message(0)
        self.assertTrue(pmt.pmt_eqv(rec_msg, msg))
        

if __name__ == '__main__':
    gr_unittest.run(test_message, "test_message.xml")
Example #36
0
        dst = blocks.vector_sink_f()

        self.tb.connect (src, op, dst)
        self.tb.run()

        # only test samples around 2D-2
        result_data = dst.data()[60:65]
        self.assertFloatTuplesAlmostEqual (expected_result, result_data)

    def test_004(self):
        ''' Test impulse response - short form, ff '''
        src_data = [1,] + 100*[0,]
        expected_result = ((-0.029296875), (-0.0302734375),
                           (0.96875), (-0.0302734375),
                           (-0.029296875))

        src = blocks.vector_source_f(src_data)
        op = filter.dc_blocker_ff(32, False)
        dst = blocks.vector_sink_f()

        self.tb.connect (src, op, dst)
        self.tb.run()

        # only test samples around D-1
        result_data = dst.data()[29:34]
        self.assertFloatTuplesAlmostEqual (expected_result, result_data)

if __name__ == '__main__':
    gr_unittest.run(test_dc_blocker, "test_dc_blocker.xml")

        #print access_code
        src_data = code + (1, 0, 1, 1) + pad
        expected_result = pad + code + (3, 0, 1, 1)
        src = blocks.vector_source_b(src_data)
        op = digital.correlate_access_code_bb(access_code, 0)
        dst = blocks.vector_sink_b()
        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        
    def test_003(self):
        code = tuple(string_to_1_0_list(default_access_code))
        access_code = to_1_0_string(code)
        pad = (0,) * 64
        #print code
        #print access_code
        src_data = code + (1, 0, 1, 1) + pad
        expected_result = code + (1, 0, 1, 1) + pad
        src = blocks.vector_source_b(src_data)
        op = digital.correlate_access_code_tag_bb(access_code, 0, "test")
        dst = blocks.vector_sink_b()
        self.tb.connect(src, op, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(expected_result, result_data)

if __name__ == '__main__':
    gr_unittest.run(test_correlate_access_code, "test_correlate_access_code.xml")
        
Example #38
0
            src = blocks.vector_source_f(src_data, tags=tags)
            p = habets.packetize_burst('burst', 100)
            dbg = blocks.message_debug()
            self.tb.connect(src, p)
            self.tb.msg_connect(p, "pdus", dbg, "store")
            self.tb.start()
            while dbg.num_messages() < len(packets):
                time.sleep(0.1)
            self.tb.stop()
            self.tb.wait()

            for n, packet in enumerate(packets):
                r = pmt.to_python(pmt.cdr(dbg.get_message(n)))
                result_data = numpy.frombuffer(''.join([chr(x) for x in r]),
                                               dtype=numpy.float32)

                try:
                    self.assertFloatTuplesAlmostEqual(packet, result_data, 1)
                except AssertionError:
                    print "--"
                    print "Test name: ", name
                    print "Output packet index: ", n
                    print "Source: ", src_data
                    print "Want", packets
                    print "Got", result_data
                    raise


if __name__ == '__main__':
    gr_unittest.run(qa_packetize_burst, "qa_packetize_burst.xml")
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
import dvbt_swig as dvbt

class qa_energy_descramble (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_energy_descramble, "qa_energy_descramble.xml")
Example #40
0
        self.tb.connect(trg, (op,1))
        self.tb.connect(op, snk)
        self.tb.run()

        # Tagged file sink gets 2 burst tags at index 2 and index 5.
        # Creates two new files, each with two integers in them from
        # src_data at these indexes (3,4) and (7,8).
        file0 = "file{0}_0_2.00000000.dat".format(snk.unique_id())
        file1 = "file{0}_1_6.00000000.dat".format(snk.unique_id())

        # Open the files and read in the data, then remove the files
        # to clean up the directory.
        outfile0 = file(file0, 'rb')
	outfile1 = file(file1, 'rb')
	data0 = outfile0.read(8)
	data1 = outfile1.read(8)
        outfile0.close()
        outfile1.close()
	os.remove(file0)
	os.remove(file1)

        # Convert the 8 bytes from the files into a tuple of 2 ints.
        idata0 = struct.unpack('ii', data0)
        idata1 = struct.unpack('ii', data1)

        self.assertEqual(idata0, (3, 4))
        self.assertEqual(idata1, (7, 8))

if __name__ == '__main__':
    gr_unittest.run(test_tag_file_sink, "test_tag_file_sink.xml")
Example #41
0
        actual_result = self.mpsk_snr_est_setup(op)
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)

    def test_probe_mpsk_snr_est_m2m4(self):
	expected_result = [11.02, 6.20, 4.98, 5.16, 5.66]

        actual_result = []
        for i in xrange(1,6):
            src_data = [b+(i*n) for b,n in zip(self._bits, self._noise)]
            
            src = blocks.vector_source_c(src_data)

            N = 10000
            alpha = 0.001
            op = digital.probe_mpsk_snr_est_c(digital.SNR_EST_M2M4, N, alpha)

            tb = gr.top_block()
            tb.connect(src, op)
            tb.run()               # run the graph and wait for it to finish

            actual_result.append(op.snr())
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)

if __name__ == '__main__':
    # Test various SNR estimators; we're not using a Gaussian
    # noise source, so these estimates have no real meaning;
    # just a sanity check.
    gr_unittest.run(test_mpsk_snr_est, "test_mpsk_snr_est.xml")

Example #42
0
            -122, -130, -92, -126, -104, -90, -74, -118, -162, -154, -130,
            -133, -163, -18, -23, -155, -95, -145, -60, -63, 156, 864, 882,
            607, 449, 163, 204, 17, 47, 612, 447, 200, -59, -188, -175, -418,
            -192, 170, 14, -73, -258, -276, -267, -335, -117, 96, 34, -28,
            -152, -130, -124, -187, 42, 176, 131, 78, -52, -2, -57, -75, 104,
            130, 111, 29, -50, -46, -107, -64, 66, 36, 33, -39, -129, -91,
            -157, -39, 69, 1, -12, -84, -99, -52, -61, 86, 147, 58, 21, -63,
            -60, -100, -48, 68, 76, 6, -65, -79, -108, -159, -71, 89, 171, 183,
            216, 152, 26, -35, 0, 87, 126, 143, 182, 151, 95, 106, 115, 155,
            103, 86, 127, 12, -41, -91, -87, -32, -52, -41, -32, -123, -147,
            -154, -156, -61, -37, -8, -51, -127, -132, -127, -107, -54, 1, 26,
            -17, -100, -61, -9, 3, 57, 117, 102, 58, -47, 24, 67, 42, 116, 141,
            113, 39, -15, 63, 68, 41, 118, 80, 24, -46, -72, 12, 5, -17, 18,
            -43, -61, -110, -119, -42, -40, -16, 2, -11, -50)

        src = blocks.vector_source_s(data)
        enc = vocoder.codec2_encode_sp(codec2.MODE_2400)
        dec = vocoder.codec2_decode_ps(codec2.MODE_2400)
        snk = blocks.vector_sink_s()
        self.tb.connect(src, enc, dec, snk)
        self.tb.run()
        actual_result = snk.data()
        self.assertEqual(expected_data, actual_result)
        self.tb.disconnect(src, enc, dec, snk)


if __name__ == '__main__':
    # Note: The Vocoder is stateful, which means this test will produce failure when removing the xml option.
    # Perhaps this is not the best way to test such a vocoder.
    gr_unittest.run(test_codec2_vocoder, "test_codec2_vocoder.xml")
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import qitkat_swig as qitkat

class qa_ecc_golay2412_encode_bb(gr_unittest.TestCase):

  def setUp(self):
    self.tb = gr.top_block()

  def tearDown(self):
    self.tb = None

  def test_001(self):
    ''' 
        We got our Golay2412 encoding/decoding algorithm from a reputable source, so for now
        we can assume that it works correctly.
        
        TODO: Add our own tests for Golay2412
    '''
    self.tb.run()

if __name__ == '__main__':
  gr_unittest.run(qa_ecc_golay2412_encode_bb, "qa_ecc_golay2412_encode_bb.xml")
Example #44
0
        # 8PSK Convergence test with static rotation
        natfreq = 0.25
        order = 8
        self.test = digital.costas_loop_cc(natfreq, order)

        rot = cmath.exp(-cmath.pi/8.0j) # rotate to match Costas rotation
        const = psk.psk_constellation(order)
        data = [random.randint(0,7) for i in xrange(100)]
        data = [2*rot*const.points()[d] for d in data]

        N = 40 # settling time
        expected_result = data[N:]

        rot = cmath.exp(0.1j) # some small rotation
        data = [rot*d for d in data]

        self.src = blocks.vector_source_c(data, False)
        self.snk = blocks.vector_sink_c()

        self.tb.connect(self.src, self.test, self.snk)
        self.tb.run()

        dst_data = self.snk.data()[N:]

	# generously compare results; the loop will converge near to, but
        # not exactly on, the target data
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 2)

if __name__ == '__main__':
    gr_unittest.run(test_costas_loop_cc, "test_costas_loop_cc.xml")
Example #45
0
class test_binary_slicer_fb(gr_unittest.TestCase):

    def setUp(self):
        random.seed(0)
        self.tb = gr.top_block()

    def tearDown(self):
        self.tb = None

    def test_binary_slicer_fb(self):
        expected_result = ( 0, 1,  0,  0, 1, 1,  0,  0,  0, 1, 1, 1,  0, 1, 1, 1, 1)
        src_data =        (-1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1)
        src_data = [s + (1 - random.random()) for s in src_data] # add some noise
        src = blocks.vector_source_f(src_data)
        op = digital.binary_slicer_fb()
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()               # run the graph and wait for it to finish

        actual_result = dst.data()  # fetch the contents of the sink
        #print "actual result", actual_result
        #print "expected result", expected_result
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result)


if __name__ == '__main__':
    gr_unittest.run(test_binary_slicer_fb, "test_binary_slicer_fb.xml")
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import ofdm_swig as ofdm


class qa_vector_mask_dc_null(gr_unittest.TestCase):
    def setUp(self):
        self.tb = gr.top_block()

    def tearDown(self):
        self.tb = None

    def test_001_t(self):
        # set up fg
        self.tb.run()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_vector_mask_dc_null, "qa_vector_mask_dc_null.xml")
        tb = gr.top_block()
        src = gr.vector_source_f([1, 3, 5, 7, 9], False)
        i2x = interp2x()
        sink = gr.vector_sink_f()
        tb.connect(src, i2x, sink)
        tb.run()
        self.assertEqual(sink.data(), (1, 1, 3, 3, 5, 5, 7, 7, 9, 9))

    def test_tags(self):
        src = tag_source()
        sink = tag_sink()
        head = gr.head(gr.sizeof_float, 50000) #should be enough items to get a tag through
        tb = gr.top_block()
        tb.connect(src, head, sink)
        tb.run()
        self.assertEqual(sink.key, "example_key")

    def test_fc32_to_f32_2(self):
        tb = gr.top_block()
        src = gr.vector_source_c([1+2j, 3+4j, 5+6j, 7+8j, 9+10j], False)
        convert = fc32_to_f32_2()
        v2s = gr.vector_to_stream(gr.sizeof_float, 2)
        sink = gr.vector_sink_f()
        tb.connect(src, convert, v2s, sink)
        tb.run()
        self.assertEqual(sink.data(), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10))

if __name__ == '__main__':
    gr_unittest.run(test_block_gateway, "test_block_gateway.xml")

        fft_len = 16
        tx_symbols = range(1, 16);
        tx_symbols = (0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,  0,
                      0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0,
                      0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0,  0)
        expected_result = tuple(range(1, 16))
        occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
        n_syms = len(tx_symbols)/fft_len
        packet_len_tsb_key = "packet_len"
        tag2 = gr.tag_t()
        tag2.offset = 0
        tag2.key = pmt.string_to_symbol("packet_len")
        tag2.value = pmt.from_long(len(expected_result))
        src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag2,))
        serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, self.tsb_key, packet_len_tsb_key , 0, "", False)
        sink = blocks.tsb_vector_sink_c(tsb_key=packet_len_tsb_key)
        self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), serializer, sink)
        self.tb.run ()
        self.assertEqual(sink.data()[0], expected_result)

    def test_099 (self):
        """ Make sure it fails if it should """
        fft_len = 16
        occupied_carriers = ((1, 3, 4, 11, 12, 112),) # Something invalid
        self.assertRaises(RuntimeError, digital.ofdm_serializer_vcc, fft_len, occupied_carriers, self.tsb_key)


if __name__ == '__main__':
    gr_unittest.run(qa_ofdm_serializer_vcc, "qa_ofdm_serializer_vcc.xml")

            data = sig_source_c(ifs, f, 1, N)
            signals.append(blocks.vector_source_c(data))
            self.tb.connect(signals[i], (add,i))

        s2ss = blocks.stream_to_streams(gr.sizeof_gr_complex, M)
        pfb = filter.pfb_decimator_ccf(M, taps, channel)
        snk = blocks.vector_sink_c()

        self.tb.connect(add, s2ss)
        for i in xrange(M):
            self.tb.connect((s2ss,i), (pfb,i))
        self.tb.connect(pfb, snk)

        self.tb.run() 

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x)/fs, xrange(L))

        # Create known data as complex sinusoids for the baseband freq
        # of the extracted channel is due to decimator output order.
        phase = 6.1575
        expected_data = map(lambda x: math.cos(2.*math.pi*freqs[3]*x+phase) + \
                                1j*math.sin(2.*math.pi*freqs[3]*x+phase), t)
        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 4)

if __name__ == '__main__':
    gr_unittest.run(test_pfb_decimator, "test_pfb_decimator.xml")
        tag1 = gr.tag_t()
        tag1.offset = 0
        tag1.key = pmt.string_to_symbol(tagname)
        tag1.value = pmt.from_long(4)
        tag2 = gr.tag_t()
        tag2.offset = 4
        tag2.key = pmt.string_to_symbol(tagname)
        tag2.value = pmt.from_long(2)
        tag3 = gr.tag_t()
        tag3.offset = 6
        tag3.key = pmt.string_to_symbol(tagname)
        tag3.value = pmt.from_long(4)
        src = blocks.vector_source_b(data, False, 1, (tag1, tag2, tag3))
        formatter_object = digital.packet_header_ofdm(occupied_carriers, 1, tagname)
        self.assertEqual(formatter_object.header_len(), 6)
        self.assertEqual(pmt.symbol_to_string(formatter_object.len_tag_key()), tagname)
        header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname)
        sink = blocks.vector_sink_b()
        self.tb.connect(src, header, sink)
        self.tb.run()
        expected_data = (
            0, 0, 1, 0, 0, 0,
            0, 1, 0, 0, 0, 0,
            0, 0, 1, 0, 0, 0
        )
        self.assertEqual(sink.data(), expected_data)

if __name__ == '__main__':
    gr_unittest.run(qa_packet_headergenerator_bb, "qa_packet_headergenerator_bb.xml")

Example #51
0
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
import sdrportal_swig as sdrportal

class qa_ws_sink_c (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_ws_sink_c, "qa_ws_sink_c.xml")
Example #52
0
        self.tb.connect((self.lora_sdr_hamming_dec_0, 0),
                        (self.lora_sdr_header_decoder_0, 0))
        self.tb.connect((self.lora_sdr_header_decoder_0, 0),
                        (self.lora_sdr_dewhitening_0, 0))
        self.tb.connect((self.rational_resampler_xxx_0, 0),
                        (self.lora_sdr_frame_sync_0, 0))

        # run the flowgraph, since we use a message strobe we have to run and stop the flowgraph with some computation time inbetween
        self.tb.start()
        time.sleep(10)
        self.tb.stop()
        self.tb.wait()
        # try to get get the message from the store port of the message debug printer and convert to string from pmt message
        try:
            msg = pmt.symbol_to_string(
                self.blocks_message_debug_0.get_message(0))
        except:
            # if not possible set message to be None
            msg = None

        # check if message received is the same as the message decoded
        self.assertMultiLineEqual(
            src_data, msg, msg="Error decoded data {0} is not the same as input data {1}".format(msg, src_data))

        # self.assertMultiLineEqual(src_data, msg, msg="Error decoded data {0} is not the same as input data {1}.".format(
        #     msg, src_data


if __name__ == '__main__':
    gr_unittest.run(qa_tx_rx)
Example #53
0
# Boston, MA 02110-1301, USA.
#

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import howto_swig as howto


class qa_square_ff(gr_unittest.TestCase):
    def setUp(self):
        self.tb = gr.top_block()

    def tearDown(self):
        self.tb = None

    def test_001_square_ff(self):
        src_data = (-3, 4, -5.5, 2, 3)
        expected_result = (9, 16, 30.25, 4, 9)
        src = blocks.vector_source_f(src_data)
        sqr = howto.square_ff()
        dst = blocks.vector_sink_f()
        self.tb.connect(src, sqr)
        self.tb.connect(sqr, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)


if __name__ == "__main__":
    gr_unittest.run(qa_square_ff, "qa_square_ff.xml")
Example #54
0
        self.assertEqual(tuple(tx_fg.tx.sync_word1),
                         tuple(rx_fg.rx.sync_word1))
        self.assertEqual(tuple(tx_fg.tx.sync_word2),
                         tuple(rx_fg.rx.sync_word2))
        self.assertEqual(test_data, rx_data)

    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)


if __name__ == '__main__':
    gr_unittest.run(test_ofdm_txrx, "test_ofdm_txrx.xml")
Example #55
0
# Boston, MA 02110-1301, USA.
# 

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import drm_swig as drm

class qa_audio_encoder_sb (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()
        self.tp = drm.transm_params(1, 3, False, 0, 1, 0, 1, 1, 0, False, 24000, "station label", "this is a long sample text message!")
        self.audio_enc = drm.audio_encoder_sb(self.tp)
        self.src = blocks.null_source(4)
        self.head = blocks.head(4,  960*10*3)
        self.snk = blocks.vector_sink_b()
        
        self.tb.connect(self.src, self.head, self.audio_enc, self.snk)

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
        # set up fg
        self.tb.run ()
        # check data


if __name__ == '__main__':
    gr_unittest.run(qa_audio_encoder_sb, "qa_audio_encoder_sb.xml")
Example #56
0
        self.assertEqual(1 / period, f)

        d0 = 1.0 - 0.5*f;
        d1 = op.decision_threshold()
        self.assertAlmostEqual(d0, d1)

        p = op.phase()
        self.assertEqual(0, p)

    def test_dpll_bb_002(self):
        period = 4
        gain = 0.1

        src_data = 10*((period-1)*[0,] + [1,])
        expected_result = src_data

        src = blocks.vector_source_b(src_data)
        op = analog.dpll_bb(period, gain)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        result_data = dst.data()
        self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4)

if __name__ == '__main__':
    gr_unittest.run(test_dpll_bb, "test_dpll_bb.xml")

    def test_quad_demod_001(self):
        f = 1000.0
        fs = 8000.0

        src_data = []
        for i in xrange(200):
            ti = i/fs
            src_data.append(cmath.exp(2j*cmath.pi*f*ti))

        # f/fs is a quarter turn per sample.
        # Set the gain based on this to get 1 out.
        gain = 1.0/(cmath.pi/4)

        expected_result = [0,] + 199*[1.0]

        src = gr.vector_source_c(src_data)
        op = analog.quadrature_demod_cf(gain)
        dst = gr.vector_sink_f()
        
        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()
        
        result_data = dst.data()
        self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5)

if __name__ == '__main__':
    gr_unittest.run(test_quadrature_demod, "test_quadrature_demod.xml")

Example #58
0
        self.tb.msg_connect((self.emitter, 'msg'), (self.endi, 'pdu_in'))
        self.tb.msg_connect((self.endi, 'pdu_out'), (self.debug, 'store'))

        i_vec = pmt.init_u8vector(
            16, [1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0])
        e_vec = pmt.init_u8vector(
            16, [1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1])
        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print "test endian_swap8:"
        print "pdu expected: " + repr(pmt.car(e_pdu))
        print "pdu got:      " + repr(pmt.car(self.debug.get_message(0)))
        print "data expected: " + repr(pmt.u8vector_elements(pmt.cdr(e_pdu)))
        print "data got:      " + repr(
            pmt.u8vector_elements(pmt.cdr(self.debug.get_message(0))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))


if __name__ == '__main__':
    gr_unittest.run(qa_pdu_binary_tools, "qa_pdu_binary_tools.xml")
Example #59
0
        tb.connect(agc, dst1)

        tb.run()
        dst_data = dst1.data()
        M = 100
        result = [abs(x) for x in dst_data[N-M:]]
        self.assertFloatTuplesAlmostEqual(result, M*[ref,], 4)

    def test_100(self):
        ''' Test complex feedforward agc with constant input '''

        length = 8
        gain = 2

        input_data = 8*(0.0,) + 24*(1.0,) + 24*(0.0,)
        expected_result = (8+length-1)*(0.0,) + 24*(gain*1.0,) + (0,)

        src = blocks.vector_source_c(input_data)
        agc = analog.feedforward_agc_cc(8, 2.0)
        dst = blocks.vector_sink_c()
        self.tb.connect(src, agc, dst)

        self.tb.run()
        dst_data = dst.data()[0:len(expected_result)]

        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)


if __name__ == '__main__':
    gr_unittest.run(test_agc, "test_agc.xml")
Example #60
0
                    (-53.049201965332031-291.47097778320312j),
                    (-28.695289611816406-317.64553833007812j),
                    (57-300j),
                    (45.301143646240234-335.69509887695312j),
                    (91.936195373535156-373.32437133789062j),
                    (172.09465026855469-439.275146484375j),
                    (242.24473571777344-504.47515869140625j),
                    (387.81732177734375-666.6788330078125j),
                    (689.48553466796875-918.2142333984375j),
                    (1646.539306640625-1694.1956787109375j))

        src_data = tuple([x/fft_size for x in tmp_data])

        expected_result = tuple([complex(primes[2*i], primes[2*i+1]) for i in range(fft_size)])

        nthreads = 2

        src = gr.vector_source_c(src_data)
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        fft = gr.fft_vcc(fft_size, False, [], False, nthreads)
        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, fft_size)
        dst = gr.vector_sink_c()
        tb.connect(src, s2v, fft, v2s, dst)
        tb.run()
        result_data = dst.data()
        self.assert_fft_ok2(expected_result, result_data)

if __name__ == '__main__':
    gr_unittest.run(test_fft, "test_fft.xml")