コード例 #1
0
ファイル: qa_stretch.py プロジェクト: Gabotero/GNURadioNext
    def test_stretch_01(self):
        tb = self.tb

        data = 10*[1,]
        data0 = map(lambda x: x/20.0, data)
        data1 = map(lambda x: x/10.0, data)

        expected_result0 = 10*[0.05,]
        expected_result1 = 10*[0.1,]

        src0 = blocks.vector_source_f(data0, False)
        src1 = blocks.vector_source_f(data1, False)
        inter = blocks.streams_to_vector(gr.sizeof_float, 2)
        op = blocks.stretch_ff(0.1, 2)
        deinter = blocks.vector_to_streams(gr.sizeof_float, 2)
        dst0 = blocks.vector_sink_f()
        dst1 = blocks.vector_sink_f()
        
        tb.connect(src0, (inter,0))
        tb.connect(src1, (inter,1))
        tb.connect(inter, op)
        tb.connect(op, deinter)
        tb.connect((deinter,0), dst0)
        tb.connect((deinter,1), dst1)
        tb.run()

        dst0_data = dst0.data()
        dst1_data = dst1.data()

        self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4)
        self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4)
コード例 #2
0
ファイル: qa_vector_map.py プロジェクト: mfischer/gnuradio
 def test_interleaving(self):
     # Takes 3 streams (a, b and c)
     # Outputs 2 streams.
     # First (d) is interleaving of a and b.
     # Second (e) is interleaving of a and b and c.  c is taken in
     #     chunks of 2 which are reversed.
     A = (1, 2, 3, 4, 5)
     B = (11, 12, 13, 14, 15)
     C = (99, 98, 97, 96, 95, 94, 93, 92, 91, 90)
     expected_D = (1, 11, 2, 12, 3, 13, 4, 14, 5, 15)
     expected_E = (1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95,
                   4, 14, 92, 93, 5, 15, 90, 91)
     mapping = [[(0, 0), (1, 0)], # mapping to produce D
                [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E
                ]
     srcA = blocks.vector_source_f(A, False, 1)
     srcB = blocks.vector_source_f(B, False, 1)
     srcC = blocks.vector_source_f(C, False, 2)
     vmap =  blocks.vector_map(gr.sizeof_int, (1, 1, 2), mapping)
     dstD = blocks.vector_sink_f(2)
     dstE = blocks.vector_sink_f(4)
     self.tb.connect(srcA, (vmap, 0))
     self.tb.connect(srcB, (vmap, 1)) 
     self.tb.connect(srcC, (vmap, 2)) 
     self.tb.connect((vmap, 0), dstD)
     self.tb.connect((vmap, 1), dstE)
     self.tb.run()
     self.assertEqual(expected_D, dstD.data())
     self.assertEqual(expected_E, dstE.data())
コード例 #3
0
ファイル: qa_puncture.py プロジェクト: 0x7678/gnuradio-wg-grc
    def test_f_003(self):
        # Test scenariou where we have defined a puncture pattern with
        # more bits than the puncsize with a delay. The python code
        # doesn't account for this when creating self.expected, but
        # this should be equivalent to a puncpat of the correct size.

        self.puncsize = 4
        self.puncpat0 = 0x5555 # too many bits set
        self.puncpat1 = 0x55   # num bits = puncsize
        self.delay = 1

        src = blocks.vector_source_f(self.src_data)
	op0  = fec.puncture_ff(self.puncsize, self.puncpat0, self.delay)
	op1  = fec.puncture_ff(self.puncsize, self.puncpat1, self.delay)
	dst0 = blocks.vector_sink_f()
	dst1 = blocks.vector_sink_f()

	self.tb.connect(src, op0, dst0)
	self.tb.connect(src, op1, dst1)
	self.tb.run()

	dst_data0 = list(dst0.data())
	dst_data1 = list(dst1.data())

        self.assertEqual(dst_data1, dst_data0)
コード例 #4
0
    def test_deint_001 (self):
        lenx = 64
        src = blocks.vector_source_f (range (lenx))
        op = blocks.deinterleave (gr.sizeof_float)
        dst0 = blocks.vector_sink_f ()
        dst1 = blocks.vector_sink_f ()
        dst2 = blocks.vector_sink_f ()
        dst3 = blocks.vector_sink_f ()

        self.tb.connect (src, op)
        self.tb.connect ((op, 0), dst0)
        self.tb.connect ((op, 1), dst1)
        self.tb.connect ((op, 2), dst2)
        self.tb.connect ((op, 3), dst3)
        self.tb.run ()

        expected_result0 = tuple (range (0, lenx, 4))
        expected_result1 = tuple (range (1, lenx, 4))
        expected_result2 = tuple (range (2, lenx, 4))
        expected_result3 = tuple (range (3, lenx, 4))

        self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ())
        self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ())
        self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ())
        self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ())
コード例 #5
0
    def test_f_003(self):
        # Test scenariou where we have defined a puncture pattern with
        # more bits than the puncsize with a delay. The python code
        # doesn't account for this when creating self.expected, but
        # this should be equivalent to a puncpat of the correct size.

        self.puncsize = 4
        self.puncpat0 = 0x5555  # too many bits set
        self.puncpat1 = 0x55  # num bits = puncsize
        self.delay = 1

        src = blocks.vector_source_f(self.src_data)
        op0 = fec.puncture_ff(self.puncsize, self.puncpat0, self.delay)
        op1 = fec.puncture_ff(self.puncsize, self.puncpat1, self.delay)
        dst0 = blocks.vector_sink_f()
        dst1 = blocks.vector_sink_f()

        self.tb.connect(src, op0, dst0)
        self.tb.connect(src, op1, dst1)
        self.tb.run()

        dst_data0 = list(dst0.data())
        dst_data1 = list(dst1.data())

        self.assertEqual(dst_data1, dst_data0)
コード例 #6
0
 def test_010_run(self):
     expected = (1.0, 2.0, 3.0, 4.0)
     hblock = gr.top_block("test_block")
     src = blocks.vector_source_f(expected, False)
     sink1 = blocks.vector_sink_f()
     sink2 = blocks.vector_sink_f()
     hblock.connect(src, sink1)
     hblock.connect(src, sink2)
     hblock.run()
     actual1 = sink1.data()
     actual2 = sink2.data()
     self.assertEquals(expected, actual1)
     self.assertEquals(expected, actual2)
コード例 #7
0
 def test_010_run(self):
     expected = (1.0, 2.0, 3.0, 4.0)
     hblock = gr.top_block("test_block")
     src = blocks.vector_source_f(expected, False)
     sink1 = blocks.vector_sink_f()
     sink2 = blocks.vector_sink_f()
     hblock.connect(src, sink1)
     hblock.connect(src, sink2)
     hblock.run()
     actual1 = sink1.data()
     actual2 = sink2.data()
     self.assertEquals(expected, actual1)
     self.assertEquals(expected, actual2)
コード例 #8
0
 def test_complex_to_float_2(self):
     src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j)
     expected_data1 = (1.0, 3.0, 5.0, 7.0, 9.0)
     expected_data2 = (2.0, 4.0, 6.0, 8.0, 10.0)
     src = blocks.vector_source_c(src_data)
     op = blocks.complex_to_float()
     dst1 = blocks.vector_sink_f()
     dst2 = blocks.vector_sink_f()
     self.tb.connect(src, op)
     self.tb.connect((op, 0), dst1)
     self.tb.connect((op, 1), dst2)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data1, dst1.data())
     self.assertFloatTuplesAlmostEqual(expected_data2, dst2.data())
コード例 #9
0
 def test_complex_to_float_2(self):
     src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
     expected_data1 = (1.0, 3.0, 5.0, 7.0, 9.0)
     expected_data2 = (2.0, 4.0, 6.0, 8.0, 10.0)
     src = blocks.vector_source_c(src_data)
     op = blocks.complex_to_float()
     dst1 = blocks.vector_sink_f()
     dst2 = blocks.vector_sink_f()
     self.tb.connect(src, op)
     self.tb.connect((op, 0), dst1)
     self.tb.connect((op, 1), dst2)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data1, dst1.data())
     self.assertFloatTuplesAlmostEqual(expected_data2, dst2.data())
コード例 #10
0
 def test_001_detect (self):
     """ Send two bursts, with zeros in between, and check
     they are both detected at the correct position and no
     false alarms occur """
     n_zeros = 15
     fft_len = 32
     cp_len = 4
     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 = [0,] * n_zeros + \
                 sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     tx_signal = tx_signal * 2
     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()
     self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0))
     self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01), (add, 1))
     self.tb.connect(add, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     sig1_detect = sink_detect.data()[0:len(tx_signal)/2]
     sig2_detect = sink_detect.data()[len(tx_signal)/2:]
     self.assertTrue(abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertTrue(abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertEqual(numpy.sum(sig1_detect), 1)
     self.assertEqual(numpy.sum(sig2_detect), 1)
コード例 #11
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)
コード例 #12
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)
        )
コード例 #13
0
    def xtest_fff_004(self):
        random.seed(0)
        for i in xrange(25):
            sys.stderr.write("\n>>> Loop = %d\n" % (i, ))
            src_len = 4096
            src_data = make_random_float_tuple(src_len)
            ntaps = int(random.uniform(2, 1000))
            taps = make_random_float_tuple(ntaps)
            expected_result = reference_filter_fff(1, taps, src_data)

            src = blocks.vector_source_f(src_data)
            op = filter.fft_filter_fff(1, taps)
            dst = blocks.vector_sink_f()
            tb = gr.top_block()
            tb.connect(src, op, dst)
            tb.run()
            result_data = dst.data()

            #print "src_len =", src_len, " ntaps =", ntaps
            try:
                self.assert_fft_float_ok2(expected_result,
                                          result_data,
                                          abs_eps=1.0)
            except:
                expected = open('expected', 'w')
                for x in expected_result:
                    expected.write( ` x ` + '\n')
                actual = open('actual', 'w')
                for x in result_data:
                    actual.write( ` x ` + '\n')
                raise
コード例 #14
0
    def test_descriptor_001(self):
        src_data = range(1000)
        expected_result = range(1000)

        filename = "tmp.32f"
        fhandle0 = open(filename, "wb")
        fd0 = fhandle0.fileno()

        src = blocks.vector_source_f(src_data)
        snk = blocks.file_descriptor_sink(gr.sizeof_float, fd0)

        self.tb.connect(src, snk)
        self.tb.run()
        os.fsync(fd0)
        fhandle0.close()

        fhandle1 = open(filename, "rb")
        fd1 = fhandle1.fileno()
        src2 = blocks.file_descriptor_source(gr.sizeof_float, fd1, False)
        snk2 = blocks.vector_sink_f()

        self.tb.disconnect(src, snk)
        self.tb.connect(src2, snk2)
        self.tb.run()
        os.fsync(fd1)
        fhandle1.close()

        os.remove(filename)

        result_data = snk2.data()
        self.assertFloatTuplesAlmostEqual(expected_result, result_data)
コード例 #15
0
    def xtest_fff_004(self):
        random.seed(0)
        for i in xrange(25):
            sys.stderr.write("\n>>> Loop = %d\n" % (i,))
            src_len = 4096
            src_data = make_random_float_tuple(src_len)
            ntaps = int(random.uniform(2, 1000))
            taps = make_random_float_tuple(ntaps)
            expected_result = reference_filter_fff(1, taps, src_data)

            src = blocks.vector_source_f(src_data)
            op = filter.fft_filter_fff(1, taps)
            dst = blocks.vector_sink_f()
    	    tb = gr.top_block()
            tb.connect(src, op, dst)
            tb.run()
            result_data = dst.data()

            #print "src_len =", src_len, " ntaps =", ntaps
            try:
                self.assert_fft_float_ok2(expected_result, result_data, abs_eps=1.0)
            except:
                expected = open('expected', 'w')
                for x in expected_result:
                    expected.write(`x` + '\n')
                actual = open('actual', 'w')
                for x in result_data:
                    actual.write(`x` + '\n')
                raise
コード例 #16
0
    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 = blocks.vector_source_c(src_data)
        op = analog.quadrature_demod_cf(gain)
        dst = blocks.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)
コード例 #17
0
ファイル: qa_ber_bf.py プロジェクト: deactivated/gnuradio
    def test_003(self):
        # Cause a 8 bit errors out of 8*N bits
        # using test mode
        # Exit if BER < -2.0

        mode = True
        N = 1000
        data0 = numpy.random.randint(0, 256, N).tolist()
        data1 = copy.deepcopy(data0)
        data1[0] ^= 0xFF

        src0 = blocks.vector_source_b(data0)
        src1 = blocks.vector_source_b(data1)
        op = fec.ber_bf(mode, 10, -2.0)
        dst = blocks.vector_sink_f()

        self.tb.connect(src0, (op, 0))
        self.tb.connect(src1, (op, 1))
        self.tb.connect(op, dst)
        self.tb.run()

        data = dst.data()
        expected_result = [-2.0]

        print data
        print expected_result

        self.assertFloatTuplesAlmostEqual(expected_result, data, 5)
コード例 #18
0
 def test_001_detect(self):
     """ Send two bursts, with zeros in between, and check
     they are both detected at the correct position and no
     false alarms occur """
     n_zeros = 15
     fft_len = 32
     cp_len = 4
     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 = [0,] * n_zeros + \
                 sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     tx_signal = tx_signal * 2
     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()
     self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0))
     self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01),
                     (add, 1))
     self.tb.connect(add, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     sig1_detect = sink_detect.data()[0:len(tx_signal) / 2]
     sig2_detect = sink_detect.data()[len(tx_signal) / 2:]
     self.assertTrue(
         abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertTrue(
         abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertEqual(numpy.sum(sig1_detect), 1)
     self.assertEqual(numpy.sum(sig2_detect), 1)
コード例 #19
0
    def test_002(self):
        port = 65500

        n_data = 100
        src_data = [float(x) for x in range(n_data)]
        expected_result = tuple(src_data)
        src = blocks.vector_source_f(src_data, False)
        udp_snd = blocks.udp_sink(gr.sizeof_float, 'localhost', port)
        self.tb_snd.connect(src, udp_snd)

        udp_rcv = blocks.udp_source(gr.sizeof_float, 'localhost', port)
        dst = blocks.vector_sink_f()
        self.tb_rcv.connect(udp_rcv, dst)

        self.tb_rcv.start()
        self.tb_snd.run()
        udp_snd.disconnect()
        self.timeout = False
        q = Timer(2.0,self.stop_rcv)
        q.start()
        self.tb_rcv.wait()
        q.cancel()

        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        self.assert_(not self.timeout)
コード例 #20
0
    def test_005_(self):

        src_data = (1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)

        dwav = numpy.array(src_data)
        wvps = numpy.zeros(3)
        # wavelet power spectrum
        scl = 1.0 / sqr(dwav[0])
        k = 1
        for e in range(len(wvps)):
            wvps[e] = scl * sqr(dwav[k:k + (01 << e)]).sum()
            k += 01 << e

        src = blocks.vector_source_f(src_data, False, len(src_data))
        kon = wavelet_swig.wvps_ff(len(src_data))
        dst = blocks.vector_sink_f(int(math.ceil(math.log(len(src_data), 2))))

        self.tb.connect(src, kon)
        self.tb.connect(kon, dst)

        self.tb.run()
        snk_data = dst.data()

        sum = 0
        for (u, v) in zip(snk_data, wvps):
            w = u - v
            sum += w * w
        sum /= float(len(snk_data))
        assert sum < 1e-6
コード例 #21
0
    def test_fff_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        rrate = 1.123  # resampling rate

        nfilts = 32
        taps = filter.firdes.low_pass_2(
            nfilts,
            nfilts * fs,
            fs / 2,
            fs / 10,
            attenuation_dB=80,
            window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 100
        data = sig_source_f(fs, freq, 1, N)
        signal = blocks.vector_source_f(data)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps)
        snk = blocks.vector_sink_f()

        self.tb.connect(signal, pfb, snk)
        self.tb.run()

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

        phase = 0.53013
        expected_data = map(
            lambda x: math.sin(2. * math.pi * freq * x + phase), t)

        dst_data = snk.data()
        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:],
                                          dst_data[-Ntest:], 3)
コード例 #22
0
    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 = blocks.vector_source_c(src_data)
        op = analog.quadrature_demod_cf(gain)
        dst = blocks.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)
コード例 #23
0
    def xtest_005_interp_random_vals(self):
        MAX_TAPS = 9
        MAX_INTERP = 7
        INPUT_LEN = 9

        random.seed(0)  # we want reproducibility

        for ntaps in xrange(1, MAX_TAPS + 1):
            for interp in xrange(1, MAX_INTERP + 1):
                for ilen in xrange(ntaps, ntaps + INPUT_LEN):
                    src_data = random_floats(ilen)
                    taps = random_floats(ntaps)
                    expected_result = reference_interp_filter(src_data, interp, taps)

                    tb = gr.top_block()
                    src = blocks.vector_source_f(src_data)
                    op = filter.rational_resampler_base_fff(interp, 1, taps)
                    dst = blocks.vector_sink_f()
                    tb.connect(src, op, dst)
                    tb.run()
                    tb = None
                    result_data = dst.data()
                    L1 = len(result_data)
                    L2 = len(expected_result)
                    L = min(L1, L2)
                    # if True or abs(L1-L2) > 1:
                    if False:
                        sys.stderr.write(
                            "delta = %2d: ntaps = %d interp = %d ilen = %d\n" % (L2 - L1, ntaps, interp, ilen)
                        )
                        # sys.stderr.write('  len(result_data) = %d  len(expected_result) = %d\n' %
                        #                 (len(result_data), len(expected_result)))
                    # self.assertEqual(expected_result[0:L], result_data[0:L])
                    # FIXME check first ntaps+1 answers
                    self.assertEqual(expected_result[ntaps + 1 : L], result_data[ntaps + 1 : L])
コード例 #24
0
ファイル: qa_classify.py プロジェクト: Gabotero/GNURadioNext
    def test_005_(self):

        src_data = (1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)

        dwav = numpy.array(src_data)
        wvps = numpy.zeros(3)
        # wavelet power spectrum
        scl = 1.0/sqr(dwav[0])
        k = 1
        for e in range(len(wvps)):
            wvps[e] = scl*sqr(dwav[k:k+(01<<e)]).sum()
            k += 01<<e

        src = blocks.vector_source_f(src_data, False, len(src_data))
        kon = wavelet_swig.wvps_ff(len(src_data))
        dst = blocks.vector_sink_f(int(math.ceil(math.log(len(src_data), 2))))

        self.tb.connect(src, kon)
        self.tb.connect(kon, dst)

        self.tb.run()
        snk_data = dst.data()

        sum = 0
        for (u,v) in zip(snk_data, wvps):
            w = u - v
            sum += w * w
        sum /= float(len(snk_data))
        assert sum < 1e-6
コード例 #25
0
    def xtest_004_decim_random_vals(self):
        MAX_TAPS = 9
        MAX_DECIM = 7
        OUTPUT_LEN = 9

        random.seed(0)  # we want reproducibility

        for ntaps in xrange(1, MAX_TAPS + 1):
            for decim in xrange(1, MAX_DECIM + 1):
                for ilen in xrange(ntaps + decim, ntaps + OUTPUT_LEN * decim):
                    src_data = random_floats(ilen)
                    taps = random_floats(ntaps)
                    expected_result = reference_dec_filter(src_data, decim, taps)

                    tb = gr.top_block()
                    src = blocks.vector_source_f(src_data)
                    op = filter.rational_resampler_base_fff(1, decim, taps)
                    dst = blocks.vector_sink_f()
                    tb.connect(src, op, dst)
                    tb.run()
                    tb = None
                    result_data = dst.data()

                    L1 = len(result_data)
                    L2 = len(expected_result)
                    L = min(L1, L2)
                    if False:
                        sys.stderr.write(
                            "delta = %2d: ntaps = %d decim = %d ilen = %d\n" % (L2 - L1, ntaps, decim, ilen)
                        )
                        sys.stderr.write(
                            "  len(result_data) = %d  len(expected_result) = %d\n"
                            % (len(result_data), len(expected_result))
                        )
                    self.assertEqual(expected_result[0:L], result_data[0:L])
コード例 #26
0
    def xtest_004_decim_random_vals(self):
        MAX_TAPS = 9
        MAX_DECIM = 7
        OUTPUT_LEN = 9

        random.seed(0)  # we want reproducibility

        for ntaps in xrange(1, MAX_TAPS + 1):
            for decim in xrange(1, MAX_DECIM + 1):
                for ilen in xrange(ntaps + decim, ntaps + OUTPUT_LEN * decim):
                    src_data = random_floats(ilen)
                    taps = random_floats(ntaps)
                    expected_result = reference_dec_filter(
                        src_data, decim, taps)

                    tb = gr.top_block()
                    src = blocks.vector_source_f(src_data)
                    op = filter.rational_resampler_base_fff(1, decim, taps)
                    dst = blocks.vector_sink_f()
                    tb.connect(src, op, dst)
                    tb.run()
                    tb = None
                    result_data = dst.data()

                    L1 = len(result_data)
                    L2 = len(expected_result)
                    L = min(L1, L2)
                    if False:
                        sys.stderr.write(
                            'delta = %2d: ntaps = %d decim = %d ilen = %d\n' %
                            (L2 - L1, ntaps, decim, ilen))
                        sys.stderr.write(
                            '  len(result_data) = %d  len(expected_result) = %d\n'
                            % (len(result_data), len(expected_result)))
                    self.assertEqual(expected_result[0:L], result_data[0:L])
コード例 #27
0
    def test_003(self):
        udp_rcv = blocks.udp_source(gr.sizeof_float, '0.0.0.0', 0, eof=False)
        rcv_port = udp_rcv.get_port()

        udp_snd = blocks.udp_sink(gr.sizeof_float, '127.0.0.1', 65500)
        udp_snd.connect('localhost', rcv_port)

        n_data = 16
        src_data = [float(x) for x in range(n_data)]
        expected_result = tuple(src_data)
        src = blocks.vector_source_f(src_data)
        dst = blocks.vector_sink_f()

        self.tb_snd.connect(src, udp_snd)
        self.tb_rcv.connect(udp_rcv, dst)

        self.tb_rcv.start()
        self.tb_snd.run()
        udp_snd.disconnect()
        self.timeout = False
        q = Timer(2.0,self.stop_rcv)
        q.start()
        self.tb_rcv.wait()
        q.cancel()

        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        self.assert_(self.timeout)  # source ignores EOF?
コード例 #28
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))
コード例 #29
0
ファイル: qa_ber_bf.py プロジェクト: LUMERIIX/cs436-gnuradio
    def test_002(self):
        # Cause 8 bit errors out of 8*N bits
        # using test mode

        mode = True
        N = 1000
        data0 = numpy.random.randint(0, 256, N).tolist()
        data1 = copy.deepcopy(data0)
        data1[0] ^= 0xFF

        src0 = blocks.vector_source_b(data0)
        src1 = blocks.vector_source_b(data1)
        op = fec.ber_bf(mode, 1, -2.0)
        dst = blocks.vector_sink_f()

        self.tb.connect(src0, (op, 0))
        self.tb.connect(src1, (op, 1))
        self.tb.connect(op, dst)
        self.tb.run()

        data = dst.data()
        expected_result = [
            numpy.log10(8.0 / (8.0 * N)),
        ]

        self.assertFloatTuplesAlmostEqual(expected_result, data, 5)
コード例 #30
0
    def test_002(self):
        port = 65500

        n_data = 100
        src_data = [float(x) for x in range(n_data)]
        expected_result = tuple(src_data)
        src = blocks.vector_source_f(src_data, False)
        udp_snd = blocks.udp_sink(gr.sizeof_float, 'localhost', port)
        self.tb_snd.connect(src, udp_snd)

        udp_rcv = blocks.udp_source(gr.sizeof_float, 'localhost', port)
        dst = blocks.vector_sink_f()
        self.tb_rcv.connect(udp_rcv, dst)

        self.tb_rcv.start()
        self.tb_snd.run()
        udp_snd.disconnect()
        self.timeout = False
        q = Timer(2.0, self.stop_rcv)
        q.start()
        self.tb_rcv.wait()
        q.cancel()

        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        self.assert_(not self.timeout)
コード例 #31
0
    def test02(self):
        # Test float/float version
        omega = 2
        gain_omega = 0.01
        mu = 0.5
        gain_mu = 0.01
        omega_rel_lim = 0.001

        self.test = digital.clock_recovery_mm_ff(omega, gain_omega,
                                                 mu, gain_mu,
                                                 omega_rel_lim)
        
        data = 100*[1,]
        self.src = blocks.vector_source_f(data, False)
        self.snk = blocks.vector_sink_f()

        self.tb.connect(self.src, self.test, self.snk)
        self.tb.run()
        
        expected_result = 100*[0.99972, ] # doesn't quite get to 1.0
        dst_data = self.snk.data()

        # Only compare last Ncmp samples
        Ncmp = 30
        len_e = len(expected_result)
        len_d = len(dst_data)
        expected_result = expected_result[len_e - Ncmp:]
        dst_data = dst_data[len_d - Ncmp:]

        #print expected_result
        #print dst_data
        
        self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
コード例 #32
0
 def test_fir_filter_fff_001(self):
     src_data = 40*[1, 2, 3, 4]
     expected_data = (0.5, 1.5, 3.0, 5.0, 5.5, 6.5, 8.0, 10.0,
                      10.5, 11.5, 13.0, 15.0, 15.5, 16.5, 18.0,
                      20.0, 20.5, 21.5, 23.0, 25.0, 25.5, 26.5,
                      28.0, 30.0, 30.5, 31.5, 33.0, 35.0, 35.5,
                      36.5, 38.0, 40.0, 40.5, 41.5, 43.0, 45.0,
                      45.5, 46.5, 48.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0,
                      50.0, 50.0, 50.0, 50.0, 50.0)
     src = blocks.vector_source_f(src_data)
     op  = filter.fir_filter_fff(1, 20*[0.5, 0.5])
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertFloatTuplesAlmostEqual(expected_data, result_data, 5)
コード例 #33
0
    def test_003(self):
        udp_rcv = blocks.udp_source(gr.sizeof_float, '0.0.0.0', 0, eof=False)
        rcv_port = udp_rcv.get_port()

        udp_snd = blocks.udp_sink(gr.sizeof_float, '127.0.0.1', 65500)
        udp_snd.connect('localhost', rcv_port)

        n_data = 16
        src_data = [float(x) for x in range(n_data)]
        expected_result = tuple(src_data)
        src = blocks.vector_source_f(src_data)
        dst = blocks.vector_sink_f()

        self.tb_snd.connect(src, udp_snd)
        self.tb_rcv.connect(udp_rcv, dst)

        self.tb_rcv.start()
        self.tb_snd.run()
        udp_snd.disconnect()
        self.timeout = False
        q = Timer(2.0, self.stop_rcv)
        q.start()
        self.tb_rcv.wait()
        q.cancel()

        result_data = dst.data()
        self.assertEqual(expected_result, result_data)
        self.assert_(self.timeout)  # source ignores EOF?
コード例 #34
0
 def test_020_run(self):
     hblock = gr.top_block("test_block")
     data = (1.0, 2.0, 3.0, 4.0)
     src = blocks.vector_source_f(data, False)
     dst = blocks.vector_sink_f()
     hblock.connect(src, dst)
     hblock.run()
     self.assertEquals(data, dst.data())
コード例 #35
0
 def test_convolve(self):
     tb = gr.top_block()
     src = blocks.vector_source_f([1, 2, 3, 4, 5, 6, 7, 8], False)
     cv = convolve()
     sink = blocks.vector_sink_f()
     tb.connect(src, cv, sink)
     tb.run()
     self.assertEqual(sink.data(), (1, 2, 3, 4, 5, 6, 7, 8))
コード例 #36
0
 def test_decim2x(self):
     tb = gr.top_block()
     src = blocks.vector_source_f([1, 2, 3, 4, 5, 6, 7, 8], False)
     d2x = decim2x()
     sink = blocks.vector_sink_f()
     tb.connect(src, d2x, sink)
     tb.run()
     self.assertEqual(sink.data(), (1, 3, 5, 7))
コード例 #37
0
 def test_interp2x(self):
     tb = gr.top_block()
     src = blocks.vector_source_f([1, 3, 5, 7, 9], False)
     i2x = interp2x()
     sink = blocks.vector_sink_f()
     tb.connect(src, i2x, sink)
     tb.run()
     self.assertEqual(sink.data(), (1, 1, 3, 3, 5, 5, 7, 7, 9, 9))
コード例 #38
0
 def test_interp2x(self):
     tb = gr.top_block()
     src = blocks.vector_source_f([1, 3, 5, 7, 9], False)
     i2x = interp2x()
     sink = blocks.vector_sink_f()
     tb.connect(src, i2x, sink)
     tb.run()
     self.assertEqual(sink.data(), (1, 1, 3, 3, 5, 5, 7, 7, 9, 9))
コード例 #39
0
    def test_020_run(self):
	hblock = gr.top_block("test_block")
	data = (1.0, 2.0, 3.0, 4.0)
	src = blocks.vector_source_f(data, False)
	dst = blocks.vector_sink_f()
	hblock.connect(src, dst)
	hblock.run()
	self.assertEquals(data, dst.data())
コード例 #40
0
 def test_decim2x(self):
     tb = gr.top_block()
     src = blocks.vector_source_f([1, 2, 3, 4, 5, 6, 7, 8], False)
     d2x = decim2x()
     sink = blocks.vector_sink_f()
     tb.connect(src, d2x, sink)
     tb.run()
     self.assertEqual(sink.data(), (1, 3, 5, 7))
コード例 #41
0
 def test_convolve(self):
     tb = gr.top_block()
     src = blocks.vector_source_f([1, 2, 3, 4, 5, 6, 7, 8], False)
     cv = convolve()
     sink = blocks.vector_sink_f()
     tb.connect(src, cv, sink)
     tb.run()
     self.assertEqual(sink.data(), (1, 2, 3, 4, 5, 6, 7, 8))
コード例 #42
0
 def test_complex_to_real(self):
     src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
     expected_data = (1.0, 3.0, 5.0, 7.0, 9.0)
     src = blocks.vector_source_c(src_data)
     op = blocks.complex_to_real()
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #43
0
 def test_char_to_float_scale(self):
     src_data = (1, 2, 3, 4, 5)
     expected_data = (0.5, 1.0, 1.5, 2.0, 2.5)
     src = blocks.vector_source_b(src_data)
     op = blocks.char_to_float(scale=2.0)
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #44
0
 def test_char_to_float_identity(self):
     src_data = (1, 2, 3, 4, 5)
     expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     src = blocks.vector_source_b(src_data)
     op = blocks.char_to_float()
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #45
0
 def test_short_to_float_scale(self):
     src_data = (5, 10, 15, 20, 25)
     expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     src = blocks.vector_source_s(src_data)
     op = blocks.short_to_float(1, 5)
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
コード例 #46
0
 def test_int_to_float_scale(self):
     src_data = (1, 2, 3, 4, 5)
     expected_data = (0.2, 0.4, 0.6, 0.8, 1.0)
     src = blocks.vector_source_i(src_data)
     op = blocks.int_to_float(1, 5)
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #47
0
 def test_complex_to_real(self):
     src_data = (1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j, 9 + 10j)
     expected_data = (1.0, 3.0, 5.0, 7.0, 9.0)
     src = blocks.vector_source_c(src_data)
     op = blocks.complex_to_real()
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #48
0
 def test_complex_to_mag_squared(self):
     src_data = (1 + 2j, 3 - 4j, 5 + 6j, 7 - 8j, -9 + 10j)
     expected_data = (5.0, 25.0, 61.0, 113.0, 181.0)
     src = blocks.vector_source_c(src_data)
     op = blocks.complex_to_mag_squared()
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #49
0
 def test_int_to_float_scale(self):
     src_data = (1, 2, 3, 4, 5)
     expected_data = (0.2, 0.4, 0.6, 0.8, 1.0)
     src = blocks.vector_source_i(src_data)
     op = blocks.int_to_float(1, 5)
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #50
0
 def test_char_to_float_identity(self):
     src_data = (1, 2, 3, 4, 5)
     expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     src = blocks.vector_source_b(src_data)
     op = blocks.char_to_float()
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #51
0
 def test_char_to_float_scale(self):
     src_data = (1, 2, 3, 4, 5)
     expected_data = (0.5, 1.0, 1.5, 2.0, 2.5)
     src = blocks.vector_source_b(src_data)
     op = blocks.char_to_float(scale=2.0)
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
コード例 #52
0
 def test_complex_to_mag(self):
     src_data = (1 + 2j, 3 - 4j, 5 + 6j, 7 - 8j, -9 + 10j)
     expected_data = (sqrt(5), sqrt(25), sqrt(61), sqrt(113), sqrt(181))
     src = blocks.vector_source_c(src_data)
     op = blocks.complex_to_mag()
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 5)
コード例 #53
0
 def test_complex_to_arg(self):
     src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j)
     expected_data = (atan2(2, 1), atan2(-4,3), atan2(6, 5), atan2(-8, 7), atan2(10,-9))
     src = blocks.vector_source_c(src_data)
     op = blocks.complex_to_arg()
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 2)
コード例 #54
0
 def test_short_to_float_scale(self):
     src_data = (5, 10, 15, 20, 25)
     expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     src = blocks.vector_source_s(src_data)
     op = blocks.short_to_float(1, 5)
     dst = blocks.vector_sink_f()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
コード例 #55
0
 def help_ff(self, src_data, exp_data, op):
     for s in zip(range(len(src_data)), src_data):
         src = blocks.vector_source_f(s[1])
         self.tb.connect(src, (op, s[0]))
     dst = blocks.vector_sink_f()
     self.tb.connect(op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(exp_data, result_data)