示例#1
0
    def test_001_float(self):
        '''
        uint8_t input data, no decimation, no filter
        '''
        self.dut = pdu_utils.pdu_fir_filter(1, [1.0])
        self.connectUp()

        i_data = [1, 0, 0, 0] * 5
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_float(1000.0))
        in_pdu = pmt.cons(i_meta, pmt.init_f32vector(len(i_data), i_data))

        e_data = [1, 0, 0, 0] * 5
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_float(1000.0))
        e_pdu = pmt.cons(e_meta, pmt.init_f32vector(len(e_data), e_data))

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

        #print("test_001:")
        #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))
    def test_float(self):
        self.down = pdu_utils.pdu_downsample(3, 0)
        self.connectUp()

        i_vec = pmt.init_f32vector(9, [0, 1, 2, 3.3, 4, 5, 6, 7, 8])
        e_vec = pmt.init_f32vector(3, [0, 3.3, 6])
        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 float:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.f32vector_elements(pmt.cdr(e_pdu))))
        print("data got:      " +
              repr(pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
示例#3
0
    def test_005_fff_down(self):
        self.dut = pdu_utils.pdu_pfb_resamp_fff([1], 1, 0.5)
        self.connectUp()

        in_data = [1, 1, 0, 0] * 4
        in_pdu = pmt.cons(pmt.make_dict(), pmt.init_f32vector(len(in_data), in_data))

        expected_data = [1, 0] * 4
        expected_pdu = pmt.cons(pmt.make_dict(), pmt.init_f32vector(len(expected_data), expected_data))

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

        self.assertEqual(1, self.debug.num_messages())

        print("test_005_fff_down:")
        print("pdu expected: " + repr(pmt.car(expected_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.to_python(pmt.cdr(expected_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), expected_pdu))
    def test_sf_tag(self):
        constA = [-3.0, -1.0, 1.0, 3]
        constB = [12.0, -12.0, 6.0, -6]
        src_data = (0, 1, 2, 3, 3, 2, 1, 0)
        expected_result = [-3, -1, 1, 3, -6, 6, -12, 12]
        first_tag = gr.tag_t()
        first_tag.key = pmt.intern("set_symbol_table")
        first_tag.value = pmt.init_f32vector(len(constA), constA)
        first_tag.offset = 0
        second_tag = gr.tag_t()
        second_tag.key = pmt.intern("set_symbol_table")
        second_tag.value = pmt.init_f32vector(len(constB), constB)
        second_tag.offset = 4

        src = blocks.vector_source_s(src_data, False, 1,
                                     [first_tag, second_tag])
        op = digital.chunks_to_symbols_sf(constB)

        dst = blocks.vector_sink_f()
        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        actual_result = dst.data()
        self.assertEqual(expected_result, actual_result)
示例#5
0
    def test_float(self):
        self.emitter = pdu_utils.message_emitter()
        self.down = pdu_utils.pdu_downsample(3, 0)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.down, 'pdu_in'))
        self.tb.msg_connect((self.down, 'pdu_out'), (self.debug, 'store'))

        i_vec = pmt.init_f32vector(9, [0, 1, 2, 3.3, 4, 5, 6, 7, 8])
        e_vec = pmt.init_f32vector(3, [0, 3.3, 6])
        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 float:"
        print "pdu expected: " + repr(pmt.car(e_pdu))
        print "pdu got:      " + repr(pmt.car(self.debug.get_message(0)))
        print "data expected: " + repr(pmt.f32vector_elements(pmt.cdr(e_pdu)))
        print "data got:      " + repr(
            pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
    def test_sf_tag(self):
        constA = [-3.0, -1.0, 1.0, 3]
        constB = [12.0, -12.0, 6.0, -6]
        src_data = (0, 1, 2, 3, 3, 2, 1, 0)
        expected_result = (-3, -1, 1, 3,
                            -6, 6, -12, 12)
        first_tag = gr.tag_t()
        first_tag.key = pmt.intern("set_symbol_table")
        first_tag.value = pmt.init_f32vector(len(constA), constA)
        first_tag.offset = 0
        second_tag = gr.tag_t()
        second_tag.key = pmt.intern("set_symbol_table")
        second_tag.value = pmt.init_f32vector(len(constB), constB)
        second_tag.offset = 4

        src = blocks.vector_source_s(src_data, False, 1, [first_tag, second_tag])
        op = digital.chunks_to_symbols_sf(constB)

        dst = blocks.vector_sink_f()
        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        actual_result = dst.data()
        self.assertEqual(expected_result, actual_result)
示例#7
0
    def test_006_precision(self):
        emitter = pdu_utils.message_emitter()
        writer = csv_writer('/tmp/file.csv', False, '', 'float', precision=4)

        # generate pdu
        metadata = pmt.PMT_NIL
        data = pmt.init_f32vector(2, [1.111111] * 2)
        sent = pmt.cons(metadata, data)
        expected = pmt.cons(pmt.PMT_NIL, pmt.init_f32vector(2, [1.1111] * 2))

        # run
        tb = gr.top_block()
        tb.msg_connect((emitter, 'msg'), (writer, 'in'))
        tb.start()
        emitter.emit(expected)
        time.sleep(.5)
        tb.stop()
        tb.wait()

        # read in csv
        self.assertTrue(
            self.check_file('/tmp/file.csv',
                            expected,
                            data_type='float',
                            has_header=False))
示例#8
0
    def test_006_f32(self):
        '''
        float input data, complicated input, decimation, and filtering
        '''
        taps = [
            -0.1, -0.2, -0.3, 0., 0.8, 1.4, 0.7, -1.9, -4.5, -3.8, 2.9, 14.4,
            25.5, 30.1, 30.1, 25.5, 14.4, 2.9, -3.8, -4.5, -1.9, 0.7, 1.4, 0.8,
            0., -0.3, -0.2, -0.1
        ]
        print(len(taps))
        self.dut = pdu_utils.pdu_fir_filter(4, taps)
        self.connectUp()

        i_data = [
            0., 0.25, 0.48, 0.68, 0.84, 0.95, 1., 0.98, 0.91, 0.78, 0.6, 0.38,
            0.14, -0.11, -0.35, -0.57, -0.76, -0.89, -0.98, -1., -0.96, -0.86,
            -0.71, -0.51, -0.28, -0.03, 0.22, 0.45, 0.66, 0.82, 0.94, 0.99,
            0.99, 0.92, 0.8, 0.62, 0.41, 0.17, -0.08, -0.32, -0.54, -0.73,
            -0.88, -0.97, -1., -0.97, -0.88, -0.73, -0.54, -0.31, -0.07, 0.18,
            0.42, 0.63, 0.8, 0.93, 0.99, 0.99, 0.93, 0.82, 0.65, 0.44, 0.21,
            -0.04, -0.29, -0.52, -0.71, -0.86, -0.96, -1., -0.98, -0.89
        ]
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(40e3))
        i_meta = pmt.dict_add(i_meta, pmt.intern("start_time"),
                              pmt.from_double(65.4321))
        in_pdu = pmt.cons(i_meta, pmt.init_f32vector(len(i_data), i_data))

        e_data = [
            8.344998, 95.737, 121.949005, 33.454994, -85.351006, -126.05898,
            -50.684998, 71.381004, 127.386, 66.26399, -55.451004, -126.658005,
            -81.652, 38.550003, 123.046005, 94.08399, -19.649996, -123.254005
        ]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(10e3))
        e_meta = pmt.dict_add(e_meta, pmt.intern("start_time"),
                              pmt.from_double(65.432050))
        e_pdu = pmt.cons(e_meta, pmt.init_f32vector(len(e_data), e_data))

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

        #print("test_005:")
        #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(pmt.car(self.debug.get_message(0)), e_meta))
        v_diff = np.abs(
            pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0))) -
            np.array(e_data)) / e_data
        print("Maximum error is", np.max(v_diff))
        self.assertTrue(np.max(v_diff) < 0.0001)
    def occ_handler_method(self, msg):
        occvec = []

        for i in range(0, self.num_split):
            occvec.append(pmt.to_double(pmt.vector_ref(msg, i)))

        pmt_to_send = pmt.make_dict()

        curtime = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        attributes = pmt.make_dict()
        attributes = pmt.dict_add(attributes,
                                  pmt.string_to_symbol("center_freq"),
                                  pmt.from_double(self.center_freq))
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("occ"),
                                  pmt.init_f32vector(self.num_split, occvec))
        attributes = pmt.dict_add(attributes,
                                  pmt.string_to_symbol("bandwidth"),
                                  pmt.from_double(self.bw))
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("timetag"),
                                  pmt.intern(curtime))
        attributes = pmt.dict_add(
            attributes, pmt.string_to_symbol("noise_floor"),
            pmt.init_f32vector(self.num_split, self.noise_floor))
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("nodeid"),
                                  pmt.from_long(self.nodeid))
        attributes = pmt.dict_add(attributes, pmt.string_to_symbol("latitude"),
                                  pmt.from_double(self.latitude))
        attributes = pmt.dict_add(attributes,
                                  pmt.string_to_symbol("longitude"),
                                  pmt.from_double(self.longitude))

        command = pmt.make_dict()
        command = pmt.dict_add(command, pmt.string_to_symbol("table"),
                               pmt.string_to_symbol("spectruminfo"))
        command = pmt.dict_add(command, pmt.string_to_symbol("attributes"),
                               attributes)

        pmt_to_send = pmt.dict_add(pmt_to_send, pmt.string_to_symbol("INSERT"),
                                   command)

        serialized_pmt = pmt.serialize_str(pmt_to_send)

        #print pmt_to_send

        UDP_IP = self.host
        UDP_PORT = self.port

        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.sendto(serialized_pmt, (UDP_IP, UDP_PORT))
示例#10
0
    def test_005_f32(self):
        '''
        float input data, no decimation, even number of taps
        '''
        self.dut = pdu_utils.pdu_fir_filter(1, [.2] * 6)
        self.connectUp()

        i_data = [
            1,
        ] * 10
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(100.0))
        i_meta = pmt.dict_add(i_meta, pmt.intern("start_time"),
                              pmt.from_double(9.9))
        in_pdu = pmt.cons(i_meta, pmt.init_f32vector(len(i_data), i_data))

        e_data = [
            .6,
            .8,
            1,
        ] + [
            1.2,
        ] * 5 + [1, .8, .6]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(100.0))
        e_meta = pmt.dict_add(e_meta, pmt.intern("start_time"),
                              pmt.from_double(9.895))
        e_pdu = pmt.cons(e_meta, pmt.init_f32vector(len(e_data), e_data))

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

        #print("test_005:")
        #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(pmt.car(self.debug.get_message(0)), e_meta))
        v_diff = np.abs(
            pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0))) -
            np.array(e_data)) / e_data
        print("Maximum error is", np.max(v_diff))
        self.assertTrue(np.max(v_diff) < 0.0001)
示例#11
0
	def test_001_t (self):
		# set up pmt
		in_2 = (-1,2,-3,4,5,0)
		in_3 = (1,2,3,4,5,0)
		in_4 = (1,-2.1,3,-4.2,5.9,0)
		
		pmt_1 = pmt.list2(pmt.string_to_symbol("rx_time"),pmt.from_long(0))
		pmt_2 = pmt.list2(pmt.string_to_symbol("test"),pmt.init_f32vector(6,in_2))
		pmt_3 = pmt.list2(pmt.string_to_symbol("velocity"),pmt.init_f32vector(6,in_3))
		pmt_4 = pmt.list2(pmt.string_to_symbol("test2"),pmt.init_f32vector(6,in_4))
		pmt_in = pmt.list4(pmt_1,pmt_2,pmt_3,pmt_4)
		
		# set up fg
		symbols = ("test", "test2")
		const_add = (1, -2)
		const_mult = (-5, 1)
		
		strobe = blocks.message_strobe(pmt_in,400);
		test = radar.msg_manipulator(symbols,const_add,const_mult)
		debug = blocks.message_debug()
		
		self.tb.msg_connect(strobe, "strobe", test, "Msg in")
		self.tb.msg_connect(test, "Msg out", debug, "store")
		self.tb.msg_connect(test, "Msg out", debug, "print")
		
		# run fg
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
		
		# check data
		msg = debug.get_message(0)
		out_2 = pmt.f32vector_elements(pmt.nth(1,pmt.nth(1,msg)))
		out_3 = pmt.f32vector_elements(pmt.nth(1,pmt.nth(2,msg)))
		out_4 = pmt.f32vector_elements(pmt.nth(1,pmt.nth(3,msg)))
		
		ref_2 = [0]*6
		ref_3 = [0]*6
		ref_4 = [0]*6
		for k in range(6):
			ref_2[k] = (in_2[k]+const_add[0])*const_mult[0]
			ref_3[k] = in_3[k]
			ref_4[k] = (in_4[k]+const_add[1])*const_mult[1]
			
		for k in range(6): # do asserts
			self.assertAlmostEqual(ref_2[k],out_2[k],3)
			self.assertAlmostEqual(ref_3[k],out_3[k],3)
			self.assertAlmostEqual(ref_4[k],out_4[k],3)
 def handle_msg(self, msg_pmt):
     msg = pmt.cdr(msg_pmt)
     if not pmt.is_f32vector(msg):
         print("[ERROR] Received invalid message type. Expected f32vector")
         return
     packet_short = pmt.f32vector_elements(msg)[8:8 + 1020]
     packet_long = pmt.f32vector_elements(msg)[8:8 + 1996]
     self.message_port_pub(
         pmt.intern('short'),
         pmt.cons(pmt.PMT_NIL,
                  pmt.init_f32vector(len(packet_short), packet_short)))
     self.message_port_pub(
         pmt.intern('long'),
         pmt.cons(pmt.PMT_NIL,
                  pmt.init_f32vector(len(packet_long), packet_long)))
示例#13
0
    def test_001_basic_nrz_test(self):
        emitter = pdu_utils.message_emitter()
        preamble = pdu_utils.pdu_preamble([0, 1, 0, 1], [], 2, 3, True)
        debug = blocks.message_debug()
        self.tb.msg_connect((emitter, 'msg'), (preamble, 'pdu_in'))
        self.tb.msg_connect((preamble, 'pdu_out'), (debug, 'store'))

        input_data = pmt.init_u8vector(8, [1, 0, 1, 1, 0, 0, 1, 0])
        input_dict = pmt.dict_add(pmt.make_dict(), pmt.intern("KEY"),
                                  pmt.intern("VALUE"))
        expected_data = pmt.init_f32vector((8 + 4 + 0) * 2 + 3 * 2, [
            0, 0, 0, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1,
            -1, -1, -1, 1, 1, -1, -1, 0, 0, 0
        ])
        self.tb.start()
        time.sleep(.001)
        emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        emitter.emit(pmt.cons(input_dict, input_data))
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()
        output_data = pmt.cdr(debug.get_message(0))

        self.assertEquals(1, debug.num_messages())
        self.assertTrue((pmt.f32vector_elements(expected_data) ==
                         pmt.f32vector_elements(output_data)))
    def test_003_f32noise(self):
        self.add.set_scale(4)
        self.add.set_offset(3)
        self.add.set_noise_level(0.1)

        in_data = range(8)
        expected_data = [
            2.7966434955596924, 7.237407207489014, 11.077142715454102,
            14.856366157531738, 18.887033462524414, 22.75377082824707,
            26.903127670288086, 30.93477439880371
        ]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_f32vector(len(in_data), in_data))

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

        out_data = pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))

        self.assertComplexTuplesAlmostEqual(out_data, expected_data)
示例#15
0
    def test_003_f32noise(self):
        self.add.set_scale(4)
        self.add.set_offset(3)
        self.add.set_noise_level(0.1)
        self.add.set_seed(123)

        in_data = range(8)
        expected_data = [
            3.1571753, 7.1703644, 10.828911, 14.942777, 18.78148, 23.152708,
            27.041052, 31.17532
        ]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_f32vector(len(in_data), in_data))

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

        out_data = pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))

        self.assertComplexTuplesAlmostEqual(out_data, expected_data, 3)
示例#16
0
    def test_001_simplelog(self):
        in_data_c32 = [4.1 - 2.4j, 0. - 0.j, 1. + 1.j, 1e-9 - 1e-9j]
        in_pdu_c32 = pmt.cons(
            pmt.make_dict(), pmt.init_c32vector(len(in_data_c32), in_data_c32))
        in_data_f32 = [4.1, -2.4, 0., -0., 1., 1., 1e-9, -1e-9]
        in_pdu_f32 = pmt.cons(
            pmt.make_dict(), pmt.init_f32vector(len(in_data_f32), in_data_f32))
        in_data_u8 = [1, 2, 3, 4, 5, 6, 7, 8]
        in_pdu_u8 = pmt.cons(pmt.make_dict(),
                             pmt.init_u8vector(len(in_data_u8), in_data_u8))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu_c32)
        time.sleep(.001)
        self.emitter.emit(in_pdu_f32)
        time.sleep(.001)
        self.emitter.emit(in_pdu_u8)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        #TODO check contents of PDUs
        os.remove(QA_LOG_DIR + 'raw-c32_0000.fc32')
        os.remove(QA_LOG_DIR + 'raw-f32_0001.f32')
        os.remove(QA_LOG_DIR + 'raw-u8_0002.u8')
    def test_simple(self):
        self.emitter = pdu_utils.message_emitter()
        self.ctm2 = pdu_utils.pdu_complex_to_mag2()
        self.debug = blocks.message_debug()
        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))
示例#18
0
    def test_006_basic_nrz(self):

        self.dut = pdu_utils.pdu_preamble([], [], 1, 0, True)
        self.connectUp()

        input_data = pmt.init_u8vector(8, [1, 0, 1, 1, 0, 0, 1, 0])
        input_dict = pmt.dict_add(pmt.make_dict(), pmt.intern("KEY"),
                                  pmt.intern("VALUE"))
        input_pdu = pmt.cons(input_dict, input_data)

        expected_data = [1, -1, 1, 1, -1, -1, 1, -1]
        expected_dict = pmt.dict_add(pmt.make_dict(), pmt.intern("KEY"),
                                     pmt.intern("VALUE"))
        expected_pdu = pmt.cons(
            expected_dict, pmt.init_f32vector(len(expected_data),
                                              expected_data))

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

        self.assertEqual(1, self.debug.num_messages())

        print("test_006_basic_nrz:")
        print("pdu expected: " + repr(pmt.car(expected_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.to_python(pmt.cdr(expected_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), expected_pdu))
示例#19
0
    def test_from_pam(self):
        self.emitter = pdu_utils.message_emitter()
        #self.flip = pdu_utils.pdu_binary_tools(pdu_utils.pdu_binary_tools.FROM_PAM)
        self.flip = pdu_utils.pdu_binary_tools(2)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.flip, 'pdu_in'))
        self.tb.msg_connect((self.flip, 'pdu_out'), (self.debug, 'store'))

        i_vec = pmt.init_f32vector(6, [1, -1, -1, 1, -1, 1])
        e_vec = pmt.init_u8vector(6, [1, 0, 0, 1, 0, 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 from_pam:")
        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))
    def test_004_unpack_LSB(self):
        self.pack.set_mode(pdu_utils.MODE_UNPACK_BYTE)
        self.pack.set_bit_order(pdu_utils.BIT_ORDER_LSB_FIRST)

        in_data = [123, 209, 17, 35]
        expected_data = [
            1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0,
            0, 0, 1, 1, 0, 0, 0, 1, 0, 0
        ]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(
            pmt.cons(pmt.intern("NON U8 PDU"), pmt.init_f32vector(2,
                                                                  [1.9, 2])))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
示例#21
0
    def test_monte_carlo(self):
        emitter = pdu_utils.message_emitter()
        clock_rec = pdu_utils.pdu_clock_recovery(True)
        msg_debug = blocks.message_debug()

        # make connections
        self.tb.msg_connect((emitter, 'msg'), (clock_rec, 'pdu_in'))
        self.tb.msg_connect((clock_rec, 'pdu_out'), (msg_debug, 'store'))

        # run
        self.tb.start()
        time.sleep(.05)

        # generate and emit
        for i in range(100):
            n_symbols = 100
            sps = 8
            noise_power = 0.02 * i
            original_bits = np.random.randint(0, 2, n_symbols)
            original_samples = original_bits * 2 - 1
            sample_rate = 1e6
            symbol_rate = sample_rate / sps
            data = np.repeat(original_samples, sps) + (
                np.random.rand(n_symbols * sps) * np.sqrt(noise_power))

            meta = pmt.make_dict()
            meta = pmt.dict_add(meta, self.pmt_sample_rate,
                                pmt.from_double(1e6))
            vector = pmt.init_f32vector(len(data), data)

            emitter.emit(pmt.cons(meta, vector))

            time.sleep(.05)

            result = msg_debug.get_message(i)
            result_meta = pmt.car(result)
            result_vector = pmt.to_python(pmt.cdr(result))
            n_errors = sum(original_bits[:len(result_vector)]
                           ^ result_vector[:len(original_bits)])
            result_rate = pmt.to_double(
                pmt.dict_ref(result_meta, self.pmt_symbol_rate, pmt.PMT_NIL))

            #print("result is ", result_rate)
            #print("we expected ", symbol_rate)
            #print("result vector is", result_vector)
            #print("we expected ", original_bits)
            #print("num errors", n_errors)

            # assert some stuff
            if n_errors != 0:
                print("got bad data", i)
            if (result_rate - symbol_rate) > 100:
                print("got bad rate", i)

        # shut down
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(True)
示例#22
0
    def test_003_change_f32(self):
        self.upsample.set_n(1)
        self.upsample.set_repeat(True)

        in_data = [0, 1, 2, 4, 8, 16, 32]
        expected_data2 = [0, 0, 1, 1, 2, 2, 4, 4, 8, 8, 16, 16, 32, 32]
        expected_data3 = [
            0, 0, 0, 1, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32
        ]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_f32vector(len(in_data), in_data))
        expected_pdu1 = pmt.cons(pmt.make_dict(),
                                 pmt.init_f32vector(len(in_data), in_data))
        expected_pdu2 = pmt.cons(
            pmt.make_dict(),
            pmt.init_f32vector(len(expected_data2), expected_data2))
        expected_pdu3 = pmt.cons(
            pmt.make_dict(),
            pmt.init_f32vector(len(expected_data3), expected_data3))
        expected_pdu4 = pmt.cons(
            pmt.make_dict(),
            pmt.init_f32vector(len(expected_data3), expected_data3))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.001)
        self.upsample.set_n(2)
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.001)
        self.upsample.set_n(3)
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.001)
        self.upsample.set_n(0)
        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_pdu1))
        self.assertTrue(pmt.equal(self.debug.get_message(1), expected_pdu2))
        self.assertTrue(pmt.equal(self.debug.get_message(2), expected_pdu3))
        self.assertTrue(pmt.equal(self.debug.get_message(3), expected_pdu4))
示例#23
0
	def test_001_t (self):
		# set up fg
		num_mean = 1
		center_freq = 1
		antenna_gain_tx = 1
		antenna_gain_rx = 1
		usrp_gain_rx = 1
		amplitude = 1
		corr_factor = 1
		exponent = 1

		Range = (10, 20, 30)
		power = (15, 30, 45)

		pmt_range = pmt.list2(pmt.string_to_symbol('range'),pmt.init_f32vector(len(Range),Range))
		pmt_power = pmt.list2(pmt.string_to_symbol('power'),pmt.init_f32vector(len(power),power))
		pmt_misc = pmt.list2(pmt.string_to_symbol('misc'),pmt.init_f32vector(3,(1,2,3)))
		pmt_in = pmt.list3(pmt_misc,pmt_range,pmt_power)

		src = blocks.message_strobe(pmt_in, 300)
		est = radar.estimator_rcs(num_mean, center_freq, antenna_gain_tx, antenna_gain_rx, usrp_gain_rx, amplitude, corr_factor, exponent)
		snk = blocks.message_debug()
		self.tb.msg_connect(src,"strobe",est,"Msg in")
		self.tb.msg_connect(est,"Msg out",snk,"store")
		self.tb.msg_connect(est,"Msg out",snk,"print")
		
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()

		# check data

		msg = snk.get_message(0)

		wavel = 3e8/center_freq
		d_antenna_gain_abs_rx = 10**(antenna_gain_rx/10)
		d_antenna_gain_abs_tx = 10**(antenna_gain_tx/10)
		power_rx = power[0]**exponent / 10**(usrp_gain_rx/10);
		power_tx = amplitude

		rcs_ref = (4*math.pi)**(3)/(d_antenna_gain_abs_rx*d_antenna_gain_abs_tx*wavel**2)*Range[0]**4*power_rx/power_tx*corr_factor

		self.assertAlmostEqual( rcs_ref, pmt.f32vector_ref(pmt.nth(1,(pmt.nth(0,msg))),0), 4 ) # check rcs value
示例#24
0
    def test_001_t(self):
        # set up fg
        Range = (2, 4, 22, 23)
        velocity = (3, 12, 19, 19)
        power = (10, 10, 10, 1)  # last value is thrown away with merging peaks
        pmt_time = pmt.list2(
            pmt.string_to_symbol('rx_time'),
            pmt.make_tuple(pmt.from_long(-1), pmt.from_double(0)))
        pmt_axisx = pmt.list2(pmt.string_to_symbol('axis_x'),
                              pmt.init_f32vector(len(Range), Range))
        pmt_axisy = pmt.list2(pmt.string_to_symbol('axis_y'),
                              pmt.init_f32vector(len(velocity), velocity))
        pmt_power = pmt.list2(pmt.string_to_symbol('power'),
                              pmt.init_f32vector(len(power), power))
        pmt_in = pmt.list4(pmt_time, pmt_axisx, pmt_axisy, pmt_power)

        src = blocks.message_strobe(pmt_in, 300)
        est = radar.estimator_ofdm('range', 30, (0, 40, -40, 10), 'velocity',
                                   20, (-5, 5))
        snk = blocks.message_debug()
        self.tb.msg_connect(src, "strobe", est, "Msg in")
        self.tb.msg_connect(est, "Msg out", snk, "store")
        self.tb.msg_connect(est, "Msg out", snk, "print")

        self.tb.start()
        sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # get ref data
        ref_range = (0 + 40 * 2 / 15.0, 0 + 40 * 4 / 15.0,
                     -40 + 50 * (22 - 15) / 15.0)
        ref_velocity = (-5 + 10 * 3 / 20.0, -5 + 10 * 12 / 20.0,
                        -5 + 10 * 19 / 20.0)

        # check data
        msg = snk.get_message(0)
        val_range = pmt.f32vector_elements(pmt.nth(1, pmt.nth(1, msg)))
        val_velocity = pmt.f32vector_elements(pmt.nth(1, pmt.nth(2, msg)))
        print val_range
        self.assertFloatTuplesAlmostEqual(val_velocity, ref_velocity, 4)
        self.assertFloatTuplesAlmostEqual(val_range, ref_range, 4)
	def test_001_t (self):
		# set up fg
		Range = (10, 20, 30)
		power = (15, 30, 45)
		block_time = 100

		pmt_range = pmt.list2(pmt.string_to_symbol('range'),pmt.init_f32vector(len(Range),Range))
		pmt_power = pmt.list2(pmt.string_to_symbol('power'),pmt.init_f32vector(len(power),power))
		pmt_misc = pmt.list2(pmt.string_to_symbol('misc'),pmt.init_f32vector(3,(1,2,3)))
		pmt_in = pmt.list3(pmt_misc,pmt_range,pmt_power)

		src = blocks.message_strobe(pmt_in, 100)
		test = radar.trigger_command("echo test_command",("Range","power"),(5, 10),(35, 50), block_time)
		
		self.tb.msg_connect(src,"strobe",test,"Msg in")
		
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
    def verify_vector_snr(self, constellation_order, nbits):
        constellation, bits_rep = generate_gray_constellation(
            constellation_order)
        data = np.random.randint(0, 2,
                                 constellation_order * nbits).astype(np.uint8)
        symbols = map_to_constellation(data, constellation)

        snr = np.arange(35, dtype=np.float) + 1.
        snr_step = 2.5
        tags = []
        offsets = (0, 50, 400, 450, 800)
        last_offset = 0
        ref = np.array([], dtype=np.float32)
        for offset in offsets:
            valuevector = pmt.init_f32vector(snr.size, snr.tolist())
            t = gr.tag_utils.python_to_tag(
                (offset, pmt.string_to_symbol("snr"), valuevector))
            tags.append(t)

            syms = symbols[last_offset:offset]
            # print(syms.size)
            ref_ln_probs = calculate_symbol_log_probabilities(
                syms, constellation, snr - snr_step)
            refs = calculate_llrs(ref_ln_probs)
            ref = np.concatenate((ref, refs))
            last_offset = offset
            snr += snr_step

        syms = symbols[last_offset:]
        ref_ln_probs = calculate_symbol_log_probabilities(
            syms, constellation, snr - snr_step)
        refs = calculate_llrs(ref_ln_probs)
        ref = np.concatenate((ref, refs))
        ref *= .5

        # print(f'test: Order={constellation_order}, bits={nbits}/{data.size}, packed={is_packed}')

        mapper = symbolmapping.symbol_demapper_cf(constellation_order, "GRAY",
                                                  "snr")
        src = blocks.vector_source_c(symbols, False, 1, tags)
        snk = blocks.vector_sink_f()

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

        res = np.array(snk.data())
        if constellation_order > 3:
            self.assertFloatTuplesAlmostEqual(tuple(np.sign(res)),
                                              tuple(np.sign(ref)))
        else:
            # for i in range(ref.size - 10):
            #     if not np.abs(ref[i + 10] - res[i + 10]) < 1e-5:
            #         print(i, ref[i], res[i], np.abs(ref[i] - res[i]) < 1e-5)
            self.assertFloatTuplesAlmostEqual(tuple(res), tuple(ref), 5)
示例#27
0
    def test_001_f_32 (self):
        self.source = blocks.vector_source_f(range(0,32*3), False, 1, [])
        self.ts_pdu = pdu_utils.take_skip_to_pdu_f(32, 32)
        self.debug = blocks.message_debug()
        self.tb.connect((self.source, 0), (self.ts_pdu, 0))
        self.tb.msg_connect((self.ts_pdu, 'pdu_out'), (self.debug, 'store'))

        dic = pmt.dict_add(pmt.make_dict(), pmt.intern("pdu_num"), pmt.from_uint64(0))
        vec = pmt.init_f32vector(32, range(0,32))
        expected = pmt.cons(dic,vec)
        self.tb.run ()
        actual = self.debug.get_message(0)
        self.assertEqualPDU(actual, expected)
示例#28
0
    def test_004_f32(self):
        '''
        float input data, no decimation, odd number of taps
        '''
        self.dut = pdu_utils.pdu_fir_filter(1, [.2] * 5)
        self.connectUp()

        i_data = [
            1,
        ] * 10
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(1000.0))
        in_pdu = pmt.cons(i_meta, pmt.init_f32vector(len(i_data), i_data))

        e_data = [
            .6,
            .8,
        ] + [
            1,
        ] * 6 + [.8, .6]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(1000.0))
        e_pdu = pmt.cons(e_meta, pmt.init_f32vector(len(e_data), e_data))

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

        #print("test_004:")
        #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))
    def test_manchester_decode_nrz(self):
        self.dut = pdu_utils.pdu_binary_tools(6) #MANCHESTER_DECODE
        self.connectUp()

        i_vec = pmt.init_f32vector(16, [1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1])
        e_vec = pmt.init_f32vector(8, [1, 1, -1, -1, 1, -1, 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 manchester decode nrz:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.f32vector_elements(pmt.cdr(e_pdu))))
        print("data got:      " + repr(pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))))

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
示例#30
0
    def test23_absolute_serialization_float_uvecs(self):
        # f32_vector SERDES
        in_vec = [0x01020304, 2.1, 3.1415, 1e-9]
        # old serialization (f32 serialized as f64):
        # in_str = b'\n\x08\x00\x00\x00\x04\x01\x00Ap 0@\x00\x00\x00@\x00\xcc\xcc\xc0\x00\x00\x00@\t!\xca\xc0\x00\x00\x00>\x11.\x0b\xe0\x00\x00\x00'
        in_str = b'\n\x08\x00\x00\x00\x04\x01\x00K\x81\x01\x82@\x06ff@I\x0eV0\x89p_'
        out_str = pmt.serialize_str(pmt.init_f32vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        # old serialization (f32 serialized as f64):
        # in_str = b'\n\x08\x00\x00\x00\x04\x01\x00?\xf0\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\xbf\xc0\x00\x00\x00\x00\x00\x00@\xfe$\x00\x00\x00\x00\x00'
        in_str = b'\n\x08\x00\x00\x00\x04\x01\x00?\x80\x00\x00@\x00\x00\x00\xbe\x00\x00\x00G\xf1 \x00'
        in_vec = [1., 2., -0.125, 123456.0]
        out_vec = pmt.f32vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # f64_vector SERDES
        in_vec = [0x010203040506, 2.1, 1e-9]
        in_str = b'\n\t\x00\x00\x00\x03\x01\x00Bp 0@P`\x00@\x00\xcc\xcc\xcc\xcc\xcc\xcd>\x11.\x0b\xe8&\xd6\x95'
        out_str = pmt.serialize_str(pmt.init_f64vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\t\x00\x00\x00\x04\x01\x00?\xf0\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\xbf\xc0\x00\x00\x00\x00\x00\x00A\x9do4T\x00\x00\x00'
        in_vec = [1., 2., -0.125, 123456789.0]
        out_vec = pmt.f64vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # c32_vector SERDES
        in_vec = [0x01020304 - 1j, 3.1415 + 99.99j]
        # old serialization (c32 serialized as c64):
        # in_str = b'\n\n\x00\x00\x00\x02\x01\x00Ap 0@\x00\x00\x00\xbf\xf0\x00\x00\x00\x00\x00\x00@\t!\xca\xc0\x00\x00\x00@X\xff\\ \x00\x00\x00'
        in_str = b'\n\n\x00\x00\x00\x02\x01\x00\xbf\x80\x00\x00K\x81\x01\x82B\xc7\xfa\xe1@I\x0eV'
        out_str = pmt.serialize_str(pmt.init_c32vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        # old serialization (c32 serialized as c64):
        # in_str = b'\n\n\x00\x00\x00\x02\x01\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xc0\x00\x00\x00\x00\x00\x00\xc1c\x12\xcf\xe0\x00\x00\x00'
        in_str = b'\n\n\x00\x00\x00\x02\x01\x00?\x80\x00\x00?\x80\x00\x00\xcb\x18\x96\x7f>\x00\x00\x00'
        in_vec = [1 + 1j, .125 - 9999999j]
        out_vec = pmt.c32vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)

        # c64_vector SERDES
        in_vec = [0xffffffff, .9j]
        in_str = b'\n\x0b\x00\x00\x00\x02\x01\x00A\xef\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xec\xcc\xcc\xcc\xcc\xcc\xcd'
        out_str = pmt.serialize_str(pmt.init_c64vector(len(in_vec), in_vec))
        self.assertEqual(out_str, in_str)
        in_str = b'\n\x0b\x00\x00\x00\x02\x01\x00?\xf0\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00?\xc0\x00\x00\x00\x00\x00\x00\xc1c\x12\xcf\xe0\x00\x00\x00'
        in_vec = [1 + 1j, .125 - 9999999j]
        out_vec = pmt.c64vector_elements(pmt.deserialize_str(in_str))
        self.assertEqual(out_vec, in_vec)
示例#31
0
    def test_003_pdu (self):
        self.emd.set_key(pmt.intern("key2"))
        self.emd.set_scale(3.333)
        self.emd.set_offset(2)

        in_msg = pmt.cons(self.base_dict, pmt.init_f32vector(3,[1.1,2.2,3.3]))
        expected_msg = pmt.cons(pmt.intern("key2"), pmt.intern("value2"))

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

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_msg))
示例#32
0
文件: qa_pdu.py 项目: danbar/gnuradio
    def test_001(self):
        #Test the overflow buffer in pdu_to_tagged_stream
        src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
        src = blocks.pdu_to_tagged_stream(blocks.float_t)
        snk = blocks.vector_sink_f()

        self.tb.connect(src, snk)
        port = pmt.intern("pdus")

        msg = pmt.cons( pmt.PMT_NIL, pmt.init_f32vector(10, src_data))
        src.to_basic_block()._post(port, msg)
        src.to_basic_block()._post(pmt.intern("system"),
                pmt.cons(pmt.intern("done"), pmt.from_long(1)))

        self.tb.start()
        self.tb.wait()

        self.assertEqual(src_data, list(snk.data()) )
示例#33
0
    def test_001(self):
        #Test the overflow buffer in pdu_to_tagged_stream
        src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
        src = blocks.pdu_to_tagged_stream(blocks.float_t)
        snk = blocks.vector_sink_f()

        self.tb.connect(src, snk)
        port = pmt.intern("pdus")

        msg = pmt.cons( pmt.PMT_NIL, pmt.init_f32vector(10, src_data))
        src.to_basic_block()._post(port, msg)

        self.tb.start()
        #ideally, would wait until we get ten samples
        time.sleep(0.2)
        self.tb.stop()

        self.assertEqual(src_data, list(snk.data()) )
示例#34
0
    def handler(self, msg):
        meta = pmt.car(msg)
        data_i = pmt.cdr(msg)

        # convert pmt -> int list (of bits) -- chop off front and back
        # data = array.array('B', pmt.u8vector_elements(data_i))
        data = array.array("f", pmt.f32vector_elements(data_i))
        data = data[self.skip : -1]
        nblocks = math.floor(len(data) / self.blocksize)
        data = data[0 : int(nblocks * self.blocksize)]

        # print "framealign: %d in, %d blocks, %d blocksize, %d out"%(len(pmt.f32vector_elements(data_i)), nblocks, self.blocksize, len(data));

        # send output
        # fout = pmt.init_u8vector(len(data), data.tolist());
        fout = pmt.init_f32vector(len(data), data.tolist())
        pdu = pmt.cons(meta, fout)
        self.message_port_pub(pmt.intern("fpdus"), pdu)
示例#35
0
    def msg_handler(self, p):
        self.counter = self.counter + 1
        if self.counter == self.d_period:
            self.counter = 0
            #print "turning ", self.d_degrees_per_trigger, " degrees"
            self.angle += self.d_degrees_per_trigger

            if self.d_serial_port != "":
                self.ttctrl.move_to(self.angle)

            if self.angle > self.d_stop:
                print "Stopping execution now"
                #sys.exit(0)

        ang_key = pmt.string_to_symbol("angle")
        ang_value = pmt.init_f32vector(1, [self.angle])
        ang_pack = pmt.list2(ang_key, ang_value)

        #m = pmt.list1(ang_pack)
        m = pmt.list4(pmt.nth(0, p), pmt.nth(1, p), pmt.nth(2, p), ang_pack)

        #pmt.list_add(m, p)
        self.message_port_pub(pmt.string_to_symbol("out"), m)
示例#36
0
    def handler(self, msg):
        # get input
        meta = pmt.car(msg);
        samples = pmt.cdr(msg);
        x = numpy.array(pmt.c32vector_elements(samples), dtype=numpy.complex64)
 
        # upsample and normalize power
        xi = signal.resample(x, len(x)* (self.N / self.T));
        # compute the symbol timing
        xt = numpy.real(xi*xi.conjugate()) * numpy.exp( (-1j*2.0*numpy.pi/self.N) * numpy.linspace(1,len(xi),len(xi)) );
        s = numpy.sum(x);    
        tau = (-self.T/(2*numpy.pi)) * numpy.arctan2(numpy.imag(s), numpy.real(s));
        
        # publish timing metric for debugging
        tm = pmt.init_c32vector(xt.size, map(lambda i: complex(i), xt))
        tm_cpdu = pmt.cons(meta,tm)
        self.message_port_pub(pmt.intern("timing_metric"), tm_cpdu);

        # extract symbols
        offset = round(self.N*tau/self.T);
        fo = (offset + self.N)%self.N;
        sym = xi[fo:-1:self.N];
        
        # normalize power to 1
        sym = sym / numpy.mean(numpy.real(sym * sym.conjugate()));

        # publish timing correct symbols (with frequency offset)
        sm = pmt.init_c32vector(sym.size, map(lambda i: complex(i), sym))
        sm_cpdu = pmt.cons(meta,sm)
        self.message_port_pub(pmt.intern("sym_timed"), sm_cpdu);

        # compute symbol frequency offset (linear phase offset within block)
        x_n = numpy.power(sym[200:1000], self.O);
        phase_ramp = numpy.unwrap(numpy.angle( x_n ));
        f_off_O = numpy.mean(numpy.diff(phase_ramp));
        goodstat = numpy.std(numpy.diff(phase_ramp));
        f_off = f_off_O / self.O;

        # check percentages
        self.nburst = self.nburst + 1;
        if(goodstat < 1.0):
            self.nburst_ok = self.nburst_ok + 1;
        else:
            print "WARNING: feedforward synchronizer discarding burst, goodness metric %f < 1.0 (likely poor timing recovery occurred, the CFO phase ramp looks like garbage)"%(goodstat)
            return
        print "sync: "+str((goodstat, self.nburst, self.nburst_ok, self.nburst_ok*100.0 / self.nburst));       

        # export phase ramp
        pr = pmt.init_f32vector(phase_ramp.size, map(lambda i: float(i), phase_ramp))
        pr_fpdu = pmt.cons(meta,pr)
        self.message_port_pub(pmt.intern("phase_ramp"), pr_fpdu);

        # apply frequency offset correction
        xc = numpy.multiply(sym, numpy.exp(-1j * f_off * numpy.linspace(1,sym.size,sym.size)));
        
        # compute and correct static symbol phase offset
        xcp = numpy.power(xc[400:1000], self.O);

# linear mean
        theta = numpy.mean( numpy.angle( xcp ) ) / self.O + numpy.pi/4;
# weighted mean
#        theta = numpy.sum(numpy.angle(xcp) * numpy.abs(xcp)) / numpy.sum(numpy.abs(xcp));
#        theta = theta / self.O + numpy.pi/4;

        xc = xc * numpy.exp(-1j*theta);

        # show time, frequency and phase estimates
        #print "tau = %f, f_off = %f, theta = %f"%(tau, f_off, theta);

        # add our estimates to the metadata dictionary
        meta = pmt.dict_add(meta, pmt.intern("tau"), pmt.from_double(tau));
        meta = pmt.dict_add(meta, pmt.intern("f_off"), pmt.from_double(f_off));
        meta = pmt.dict_add(meta, pmt.intern("theta"), pmt.from_double(theta));

        # publish freq corrected symbols
        xcm = pmt.init_c32vector(xc.size, map(lambda i: complex(i), xc))
        xcm_cpdu = pmt.cons(meta,xcm)
        self.message_port_pub(pmt.intern("cpdus"), xcm_cpdu);
示例#37
0
文件: qa_pmt.py 项目: dl1ksv/gnuradio
 def test03(self):
     v = pmt.init_f32vector(3, [11, -22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
     self.assertEqual(pmt.uniform_vector_itemsize(v), 4)
	def test_001_t (self):
		# create input data
		steps = 200
		vec_time = np.linspace(0,20,steps);
		vec_velocity = np.linspace(5,5,steps)
		vec_range = np.linspace(100,1,steps)
		vec_velocity_real = [0]*steps
		vec_range_real = [0]*steps
		for k in range(steps):
			vec_velocity_real[k] = vec_velocity[k]
			vec_range_real[k] = vec_range[k]
		
		# random data on trajectory
		mu = 0
		sigma_vel = 0.5
		sigma_rge = 7
		for k in range(len(vec_velocity)):
			vec_velocity[k] = vec_velocity[k] + random.gauss(mu,sigma_vel)
			vec_range[k] = vec_range[k] + random.gauss(mu,sigma_rge)
		
		# set up pmts with zero points
		target_pmts = [0]*len(vec_velocity)
		#zero_points = (5,12,17)
		zero_points = ()
		for k in range(len(vec_velocity)):
			pmt_time = pmt.list2(pmt.string_to_symbol("rx_time"),pmt.make_tuple(pmt.from_long(int(vec_time[k])),pmt.from_double(vec_time[k]-int(vec_time[k]))))
			if k in zero_points:
				vec = [0]
				pmt_velocity = pmt.list2(pmt.string_to_symbol("velocity"),pmt.init_f32vector(1,vec))
				pmt_range = pmt.list2(pmt.string_to_symbol("range"),pmt.init_f32vector(1,vec))
			else:
				pmt_velocity = pmt.list2(pmt.string_to_symbol("velocity"),pmt.init_f32vector(1,(vec_velocity[k],)))
				pmt_range = pmt.list2(pmt.string_to_symbol("range"),pmt.init_f32vector(1,(vec_range[k],)))
			target_pmts[k] = pmt.list3(pmt_time,pmt_velocity,pmt_range)
		
		# set up fg
		test_duration = 1000 # ms, do not change!
		
		num_particle = 300
		std_range_meas = sigma_rge
		std_velocity_meas = sigma_vel
		std_accel_sys = 0.1
		threshold_track = 0.001
		threshold_lost = 4
		tracking_filter = "particle"
		#tracking_filter = "kalman"
		
		# connect multiple strobes for different msgs
		src = [0]*len(target_pmts)
		for k in range(len(target_pmts)):
			src[k] = blocks.message_strobe(target_pmts[k], test_duration-400+400/len(target_pmts)*k)
		tracking = radar.tracking_singletarget(num_particle, std_range_meas, std_velocity_meas, std_accel_sys, threshold_track, threshold_lost, tracking_filter)
		snk = blocks.message_debug()
		
		for k in range(len(target_pmts)):
			self.tb.msg_connect(src[k],"strobe",tracking,"Msg in")
		self.tb.msg_connect(tracking,"Msg out",snk,"store")
		
		self.tb.start()
		sleep(test_duration/1000.0)
		self.tb.stop()
		self.tb.wait
		()
		# check data
#		show_data = False # Toggle visibility of single messages # broken
		msg_num = snk.num_messages()
		vec_out_range = []
		vec_out_velocity = []
		for k in range(msg_num):
			msg_part = snk.get_message(k)
			tme = pmt.nth(0,msg_part) # not used
			vel = pmt.nth(1,msg_part)
			rgn = pmt.nth(2,msg_part)
			vec_out_range.append(pmt.f32vector_elements(pmt.nth(1,rgn))[0])
			vec_out_velocity.append(pmt.f32vector_elements(pmt.nth(1,vel))[0])
#			if show_data:
#				print "msg:", k
#				print pmt.symbol_to_string(pmt.nth(0,vel)), pmt.f32vector_elements(pmt.nth(1,vel))[0]
#				print pmt.symbol_to_string(pmt.nth(0,rgn)), pmt.f32vector_elements(pmt.nth(1,rgn))[0]
#				print 
#		print "RANGE:"
#		print vec_out_range
#		print "VELOCITY:"
#		print vec_out_velocity
		
		# make plots
		show_plots = False # Toggle visibility of plots
		if show_plots:
			time = range(len(vec_range))
			time_out = range(len(vec_out_range))
			plt.figure(1)
			
			plt.subplot(211)
			marker = '-o'
			p1 = plt.plot(time,vec_velocity_real,marker,time,vec_velocity,marker,time_out,vec_out_velocity,marker)
			plt.legend(p1,["IN velocity real", "IN velocity", "OUT velocity"])
			plt.title("VELOCITY")
			plt.xlabel('time')
			
			plt.subplot(212)
			marker = '-o'
			p1 = plt.plot(time,vec_range_real,marker,time,vec_range,marker,time_out,vec_out_range,marker)
			plt.legend(p1,["IN range real","IN range","OUT range"])
			plt.title("RANGE")
			plt.xlabel('time')
			
			plt.show()
示例#39
0
文件: qa_pmt.py 项目: 232675/gnuradio
 def test03(self):
     v = pmt.init_f32vector(3, [11, -22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))