Exemple #1
0
	def test_003_t (self):
		# test cut frequency negative freq
		# set up fg
		test_len = 1000
		samp_rate = 2000
		freq1 = -200
		freq2 = -205
		ampl = 1
		packet_len = test_len
		threshold = -100
		samp_protect = 2
		
		src1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq1, ampl*0.2)
		src2 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq2, ampl)
		add = blocks.add_cc();
		head = blocks.head(8,test_len)
		s2ts = blocks.stream_to_tagged_stream(8,1,packet_len,"packet_len")
		fft = radar.ts_fft_cc(packet_len)
		peak = radar.find_max_peak_c(samp_rate, threshold, samp_protect, (-200,200), True)
		debug = blocks.message_debug()
		
		self.tb.connect((src1,0), (add,0))
		self.tb.connect((src2,0), (add,1))
		self.tb.connect(add,head,s2ts,fft,peak)
		self.tb.msg_connect(peak,"Msg out",debug,"store")
		#self.tb.msg_connect(peak,"Msg out",debug,"print")
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
		
		# check frequency in os_cfar message with given one
		msg = debug.get_message(0)
		self.assertAlmostEqual(freq1,pmt.f32vector_ref(pmt.nth(1,pmt.nth(1,msg)),0),8)
Exemple #2
0
    def test_001_t(self):
        # set up fg
        test_len = 1000
        packet_len = test_len
        pulse_send = (200, 300, 100)
        pulse_wait = (100, 100)
        amplitude = 0.5

        num_skip = 0  # skip samples with skiphead
        num_xcorr = 300  # num of xcorrs to determine delay samples

        src = radar.signal_generator_sync_pulse_c(packet_len, pulse_send,
                                                  pulse_wait, amplitude,
                                                  "packet_len")
        head = blocks.head(8, test_len)
        skiphead = blocks.skiphead(8, num_skip)
        est = radar.estimator_sync_pulse_c(num_xcorr, "packet_len")
        res = radar.print_results()
        debug = blocks.message_debug()

        self.tb.connect(src, skiphead, head)
        self.tb.connect((head, 0),
                        (est, 0))  # TX stream (undelayed but skiped)
        self.tb.connect((src, 0), (est, 1))  # RX stream (delayed but unskiped)
        self.tb.msg_connect(est, 'Msg out', res, 'Msg in')
        self.tb.msg_connect(est, 'Msg out', debug, 'store')
        self.tb.run()

        # check data
        msg = debug.get_message(0)
        num_skip_est = pmt.to_long(pmt.nth(1, pmt.nth(1, msg)))
        self.assertEqual(num_skip_est, num_skip)
	def test_001_t (self):
		# set up fg
		test_len = 1000
		packet_len = test_len
		pulse_send = (200,300,100)
		pulse_wait = (100,100)
		amplitude = 0.5
		
		num_skip = 5 # skip samples with skiphead
		num_xcorr = 300 # num of xcorrs to determine delay samples
		
		src = radar.signal_generator_sync_pulse_c(packet_len,pulse_send,pulse_wait,amplitude,"packet_len")
		head = blocks.head(8,test_len)
		skiphead = blocks.skiphead(8,num_skip)
		est = radar.estimator_sync_pulse_c(num_xcorr,"packet_len")
		res = radar.print_results()
		debug = blocks.message_debug()
		
		self.tb.connect(src,skiphead,head)
		self.tb.connect((head,0),(est,0)) # TX stream (undelayed but skiped)
		self.tb.connect((src,0),(est,1)) # RX stream (delayed but unskiped)
		self.tb.msg_connect(est,'Msg out',res,'Msg in')
		self.tb.msg_connect(est,'Msg out',debug,'store')
		self.tb.run ()
		
		# check data
		msg = debug.get_message(0)
		num_skip_est = pmt.to_long(pmt.nth(1,pmt.nth(1,msg)))
		self.assertEqual(num_skip_est,num_skip)
	def test_002_t (self):
		# set up fg
		test_len = 2**15
		samp_rate = 250000
		freq = -2000
		ampl = 1
		packet_len = test_len
		min_output_buffer = 2*packet_len
		compare_sample = 5
		protect_sample = 0
		rel_threshold = 0.78
		mult_threshold = 10
		
		src = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq, ampl)
		src.set_min_output_buffer(min_output_buffer)
		head = blocks.head(8,test_len)
		head.set_min_output_buffer(min_output_buffer)
		s2ts = blocks.stream_to_tagged_stream(8,1,packet_len,"packet_len")
		s2ts.set_min_output_buffer(min_output_buffer)
		fft = radar.ts_fft_cc(packet_len)
		fft.set_min_output_buffer(min_output_buffer)
		cfar = radar.os_cfar_c(samp_rate, compare_sample, protect_sample, rel_threshold, mult_threshold)
		debug = blocks.message_debug()
		
		self.tb.connect(src,head,s2ts,fft,cfar)
		self.tb.msg_connect(cfar,"Msg out",debug,"store")
		self.tb.msg_connect(cfar,"Msg out",debug,"print")
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
		
		# check frequency in os_cfar message with given one
		msg = debug.get_message(0)
		self.assertAlmostEqual(freq/pmt.f32vector_ref(pmt.nth(1,pmt.nth(1,msg)),0),1,2)
Exemple #5
0
    def test_001_t(self):
        data = [ord('a'), ord('b'), ord('c'), ord('d')]
        msg = pmt.list1(
            pmt.list2(pmt.string_to_symbol("msg_clear"),
                      pmt.init_u8vector(len(data), data)))
        filename_key = "secret.a"
        nacl.generate_key(filename_key)

        strobe = blocks.message_strobe(msg, 100)
        encrypt_secret = nacl.encrypt_secret(filename_key)
        decrypt_secret = nacl.decrypt_secret(filename_key)
        debug = blocks.message_debug()

        self.tb.msg_connect(strobe, "strobe", encrypt_secret, "Msg clear")
        self.tb.msg_connect(encrypt_secret, "Msg encrypted", decrypt_secret,
                            "Msg encrypted")
        self.tb.msg_connect(decrypt_secret, "Msg decrypted", debug, "store")

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

        # check results
        msg_out = debug.get_message(0)
        msg_symbol = pmt.symbol_to_string(pmt.nth(0, pmt.nth(0, msg_out)))
        msg_decrypted = pmt.u8vector_elements(pmt.nth(1, pmt.nth(0, msg_out)))
        print msg_symbol, msg_decrypted
        print "msg_clear", data

        for k in range(len(data)):
            self.assertEqual(data[k], msg_decrypted[k])
Exemple #6
0
    def msg_handler(self, p):

        length = pmt.length(p)

        for i in range(0,length):
           element = pmt.nth(i, p)

           key = pmt.nth(0, element)
           value = pmt.nth(1, element)

           if str(key) == "power":
               output = pmt.f32vector_elements(value)[0]


               output = 10 * math.log(output, 10)           
               output = pmt.make_f32vector(1, output)

               if i==0:
                   outpmt = pmt.list1(pmt.list2(pmt.string_to_symbol(str(key) + "_dB"), output))
               else:
                   outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol(str(key) + "_dB"), output))



           output = pmt.nth(1, element)

           if i==0:
               outpmt = pmt.list1(pmt.list2(key, output))
           else:
               outpmt = pmt.list_add(outpmt, pmt.list2(key, output))

       
        self.message_port_pub(pmt.string_to_symbol("out"), outpmt)
    def test_001_t(self):
        data = [ord("a"), ord("b"), ord("c"), ord("d")]
        msg = pmt.list1(pmt.list2(pmt.string_to_symbol("msg_clear"), pmt.init_u8vector(len(data), data)))
        filename_key = "secret.a"
        nacl.generate_key(filename_key)

        strobe = blocks.message_strobe(msg, 100)
        encrypt_secret = nacl.encrypt_secret(filename_key)
        decrypt_secret = nacl.decrypt_secret(filename_key)
        debug = blocks.message_debug()

        self.tb.msg_connect(strobe, "strobe", encrypt_secret, "Msg clear")
        self.tb.msg_connect(encrypt_secret, "Msg encrypted", decrypt_secret, "Msg encrypted")
        self.tb.msg_connect(decrypt_secret, "Msg decrypted", debug, "store")

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

        # check results
        msg_out = debug.get_message(0)
        msg_symbol = pmt.symbol_to_string(pmt.nth(0, pmt.nth(0, msg_out)))
        msg_decrypted = pmt.u8vector_elements(pmt.nth(1, pmt.nth(0, msg_out)))
        print msg_symbol, msg_decrypted
        print "msg_clear", data

        for k in range(len(data)):
            self.assertEqual(data[k], msg_decrypted[k])
Exemple #8
0
	def test_001_t (self):
		# test on positive frequencies
		# set up fg
		test_len = 1000
		samp_rate = 2000
		freq = 200
		ampl = 1
		packet_len = test_len
		threshold = -100
		samp_protect = 2
		
		src = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq, ampl)
		head = blocks.head(8,test_len)
		s2ts = blocks.stream_to_tagged_stream(8,1,packet_len,"packet_len")
		fft = radar.ts_fft_cc(packet_len)
		peak = radar.find_max_peak_c(samp_rate, threshold, samp_protect, (0,0), False)
		debug = blocks.message_debug()
		
		self.tb.connect(src,head,s2ts,fft,peak)
		self.tb.msg_connect(peak,"Msg out",debug,"store")
		#self.tb.msg_connect(peak,"Msg out",debug,"print")
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
		
		# check frequency in os_cfar message with given one
		msg = debug.get_message(0)
		self.assertAlmostEqual(freq,pmt.f32vector_ref(pmt.nth(1,pmt.nth(1,msg)),0),8)
Exemple #9
0
    def test_001_t(self):
        # set up fg
        test_len = 1024

        packet_len = test_len
        samp_rate = 2000

        center_freq = 1e9
        velocity = (5, 15, 20)

        src = radar.signal_generator_cw_c(packet_len, samp_rate, (0, 0), 1)
        head = blocks.head(8, test_len)
        sim = radar.static_target_simulator_cc(
            (10, 10, 10), velocity, (1e12, 1e12, 1e12), (0, 0, 0), (0, ),
            samp_rate, center_freq, 1, True, False)
        mult = blocks.multiply_cc()
        fft = radar.ts_fft_cc(packet_len)
        cfar = radar.os_cfar_c(samp_rate, 5, 0, 0.78, 10, True)
        est = radar.estimator_cw(center_freq)
        res1 = radar.print_results()
        res2 = radar.print_results()
        gate = radar.msg_gate(('velocity', 'bla'), (8, 8), (17, 17))
        debug1 = blocks.message_debug()
        debug2 = blocks.message_debug()

        self.tb.connect(src, head, (mult, 1))
        self.tb.connect(head, sim, (mult, 0))
        self.tb.connect(mult, fft, cfar)
        self.tb.msg_connect(cfar, 'Msg out', est, 'Msg in')
        self.tb.msg_connect(est, 'Msg out', res1, 'Msg in')
        self.tb.msg_connect(est, 'Msg out', debug1, 'store')
        self.tb.msg_connect(est, 'Msg out', gate, 'Msg in')
        self.tb.msg_connect(gate, 'Msg out', debug2, 'store')
        self.tb.msg_connect(gate, 'Msg out', res2, 'Msg in')

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

        # check data
        msg1 = debug1.get_message(0)  # msg without gate
        msg2 = debug2.get_message(0)  # msg with gate
        self.assertEqual(
            "velocity", pmt.symbol_to_string(pmt.nth(0, (pmt.nth(
                1, msg1)))))  # check velocity message part (symbol), 1
        self.assertEqual(
            "velocity", pmt.symbol_to_string(pmt.nth(0, (pmt.nth(
                1, msg2)))))  # check velocity message part (symbol), 2
        self.assertEqual(pmt.length(pmt.nth(1, pmt.nth(1, msg1))),
                         3)  # check number of targets without gate
        self.assertEqual(pmt.length(pmt.nth(1, pmt.nth(1, msg2))),
                         1)  # check nubmer of targets with gate
        self.assertAlmostEqual(
            1, velocity[1] / pmt.f32vector_ref(pmt.nth(1,
                                                       (pmt.nth(1, msg2))), 0),
            1)  # check velocity value
Exemple #10
0
    def test_001_t(self):
        # set up fg
        test_len = 1024

        packet_len = test_len
        samp_rate = 2000

        center_freq = 1e9
        velocity = (5, 15, 20)

        src = radar.signal_generator_cw_c(packet_len, samp_rate, (0, 0), 1)
        head = blocks.head(8, test_len)
        sim = radar.static_target_simulator_cc(
            (10, 10, 10), velocity, (1e12, 1e12, 1e12), (0, 0, 0), (0,), samp_rate, center_freq, 1, True, False
        )
        mult = blocks.multiply_cc()
        fft = radar.ts_fft_cc(packet_len)
        cfar = radar.os_cfar_c(samp_rate, 5, 0, 0.78, 10, True)
        est = radar.estimator_cw(center_freq)
        res1 = radar.print_results()
        res2 = radar.print_results()
        gate = radar.msg_gate(("velocity", "bla"), (8, 8), (17, 17))
        debug1 = blocks.message_debug()
        debug2 = blocks.message_debug()

        self.tb.connect(src, head, (mult, 1))
        self.tb.connect(head, sim, (mult, 0))
        self.tb.connect(mult, fft, cfar)
        self.tb.msg_connect(cfar, "Msg out", est, "Msg in")
        self.tb.msg_connect(est, "Msg out", res1, "Msg in")
        self.tb.msg_connect(est, "Msg out", debug1, "store")
        self.tb.msg_connect(est, "Msg out", gate, "Msg in")
        self.tb.msg_connect(gate, "Msg out", debug2, "store")
        self.tb.msg_connect(gate, "Msg out", res2, "Msg in")

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

        # check data
        msg1 = debug1.get_message(0)  # msg without gate
        msg2 = debug2.get_message(0)  # msg with gate
        self.assertEqual(
            "velocity", pmt.symbol_to_string(pmt.nth(0, (pmt.nth(1, msg1))))
        )  # check velocity message part (symbol), 1
        self.assertEqual(
            "velocity", pmt.symbol_to_string(pmt.nth(0, (pmt.nth(1, msg2))))
        )  # check velocity message part (symbol), 2
        self.assertEqual(pmt.length(pmt.nth(1, pmt.nth(1, msg1))), 3)  # check number of targets without gate
        self.assertEqual(pmt.length(pmt.nth(1, pmt.nth(1, msg2))), 1)  # check nubmer of targets with gate
        self.assertAlmostEqual(
            1, velocity[1] / pmt.f32vector_ref(pmt.nth(1, (pmt.nth(1, msg2))), 0), 1
        )  # check velocity value
    def test_001_t(self):
        # set up fg
        test_len = 1024

        packet_len = test_len
        samp_rate = 2000

        center_freq = 1e9
        velocity = 15

        src = radar.signal_generator_cw_c(packet_len, samp_rate, (0, 0), 1)
        head = blocks.head(8, test_len)
        sim = radar.static_target_simulator_cc(
            (10, 10), (velocity, velocity), (1e9, 1e9), (0, 0), (0, ),
            samp_rate, center_freq, 1, True, False)
        mult = blocks.multiply_cc()
        fft = radar.ts_fft_cc(packet_len)
        cfar = radar.os_cfar_c(samp_rate, 5, 0, 0.78, 10, True)
        est = radar.estimator_cw(center_freq)
        res = radar.print_results()
        debug = blocks.message_debug()

        self.tb.connect(src, head, (mult, 1))
        self.tb.connect(head, sim, (mult, 0))
        self.tb.connect(mult, fft, cfar)
        self.tb.msg_connect(cfar, 'Msg out', est, 'Msg in')
        self.tb.msg_connect(est, 'Msg out', res, 'Msg in')
        self.tb.msg_connect(est, 'Msg out', debug, 'store')
        #self.tb.msg_connect(est,'Msg out',debug,'print')

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

        # check data
        msg = debug.get_message(0)
        self.assertEqual("rx_time",
                         pmt.symbol_to_string(pmt.nth(0, (pmt.nth(
                             0, msg)))))  # check rx_time message part (symbol)
        self.assertEqual(0,
                         pmt.to_uint64(
                             pmt.tuple_ref(pmt.nth(1, (pmt.nth(0, msg))),
                                           0)))  # check rx_time value
        self.assertEqual(
            0.0, pmt.to_double(pmt.tuple_ref(pmt.nth(1, (pmt.nth(0, msg))),
                                             1)))
        self.assertEqual(
            "velocity", pmt.symbol_to_string(pmt.nth(
                0, (pmt.nth(1, msg)))))  # check velocity message part (symbol)
        self.assertAlmostEqual(
            1, velocity / pmt.f32vector_ref(pmt.nth(1, (pmt.nth(1, msg))), 0),
            2)  # check velocity value
Exemple #12
0
    def msg_handler(self, p):

        length = pmt.length(p)

        # iterate over all elements
        for i in range(0, length):
            element = pmt.nth(i, p)

            key = pmt.nth(0, element)
            value = pmt.nth(1, element)

            initial_phase = None

            # when we found the phase key
            if str(key) == "phase" and pmt.length(value) >= 1:
                # print "length of vector: ", pmt.length(value)
                value = pmt.f32vector_elements(value)[0]
                self.last_val = value

                # save that value
                initial_phase = value

                value = value - self.subtract
                while value < -numpy.pi:
                    value = value + numpy.pi
                while value > numpy.pi:
                    value = value - numpy.pi

                initial_phase = pmt.make_f32vector(1, initial_phase)
                initial_phase = pmt.list2(pmt.string_to_symbol("phase_initial"), initial_phase)

                outvalue = pmt.make_f32vector(1, value)
                output = pmt.list2(pmt.string_to_symbol(str(key)), outvalue)

            else:
                output = element

            if i == 0:
                outpmt = pmt.list1(output)
            else:
                outpmt = pmt.list_add(outpmt, output)

            if initial_phase != None:
                outpmt = pmt.list_add(outpmt, initial_phase)

        self.message_port_pub(pmt.string_to_symbol("out"), outpmt)
Exemple #13
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
Exemple #14
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)
Exemple #15
0
    def handle_msg(self, msg):
        d_size_msg = pmt.length(msg)
        # rx_time, frequency, power, phase

        time_tuple = pmt.nth(1, pmt.nth(0, msg))
        time_s = pmt.to_uint64(pmt.tuple_ref(time_tuple, 0))
        time_ms = pmt.to_double(pmt.tuple_ref(time_tuple, 1))
        timestamp = time_s + time_ms

        phase_val_vec = pmt.nth(1, pmt.nth(d_size_msg - 1, msg))
        phase_val = pmt.f32vector_elements(phase_val_vec)[0]

        #plt.scatter(timestamp, phase_val)
        #plt.pause(0.05)

        #power_val_vec = pmt.nth(1, pmt.nth(d_size_msg-2, msg))
        #power_val = pmt.f32vector_elements(power_val_vec)[0]

        self.phase = phase_val
        self.time = timestamp
Exemple #16
0
    def msg_handler(self, p):

        if self.filename != "":
            self.fdout = open(self.filename, "a")

        length = pmt.length(p)

        if self.key == "all":
            #if all keys are printed, they need however be printed once above
            if self.counter == 0:
                for i in range(0, length):
                    element = pmt.nth(i, p)
                    current_key = str(pmt.nth(0, element))
                    self.fdout.write(current_key + ",")
                self.fdout.write("\n")
                self.counter=1

            #print all
            for i in range(0, length):
                element = pmt.nth(i, p)
                current_key = str(pmt.nth(0, element))
                current_value = pmt.nth(1, element)

                if current_key=="rx_time":
                    number = pmt.to_uint64(pmt.tuple_ref(current_value,0)) + \
                             pmt.to_double(pmt.tuple_ref(current_value,1))
                    
                    self.fdout.write(str(number) + ",")
                else:
                    self.fdout.write(str(pmt.f32vector_elements(current_value)[0]) + ",")

        else:
            #print all values that correspond to keys
            for key in self.key:
                for i in range(0, length):
                    element = pmt.nth(i, p)
                    current_key = str(pmt.nth(0, element))
                    current_value = pmt.nth(1, element)

                    if current_key == key:
                        if key=="rx_time":
                            number = pmt.to_uint64(pmt.tuple_ref(current_value,0)) + \
                                     pmt.to_double(pmt.tuple_ref(current_value,1))
                            
                            self.fdout.write(str(number) + ",")
                        else:
                            self.fdout.write(str(pmt.f32vector_elements(current_value)[0]) + ",")

        self.fdout.write("\n")
        self.fdout.close()
    def test_001_t(self):
        data = [ord('t'), ord('e'), ord('s'), ord('t')]
        msg = pmt.list1(
            pmt.list2(pmt.string_to_symbol("msg_clear"),
                      pmt.init_u8vector(len(data), data)))
        filename_key = "secret.key"
        nacl.generate_key(filename_key)

        strobe = blocks.message_strobe(msg, 100)
        encrypt_secret = nacl.encrypt_secret(filename_key)
        debug = blocks.message_debug()

        self.tb.msg_connect(strobe, "strobe", encrypt_secret, "Msg clear")
        self.tb.msg_connect(encrypt_secret, "Msg encrypted", debug, "store")

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

        # check results
        msg_stored = debug.get_message(0)
        nonce = pmt.nth(0, msg_stored)
        msg_encrypted = pmt.nth(1, msg_stored)
        print pmt.symbol_to_string(pmt.nth(0, nonce)), pmt.u8vector_elements(
            pmt.nth(1, nonce))
        print pmt.symbol_to_string(pmt.nth(
            0,
            msg_encrypted)), pmt.u8vector_elements(pmt.nth(1, msg_encrypted))
	def test_001_t (self):
		# set up fg
		test_len = 1024

		packet_len = test_len
		samp_rate = 2000
		
		center_freq = 1e9
		velocity = 15

		src = radar.signal_generator_cw_c(packet_len,samp_rate,(0,0),1)
		head = blocks.head(8,test_len)
		sim = radar.static_target_simulator_cc((10,10),(velocity,velocity),(1e9,1e9),(0,0),(0,),samp_rate,center_freq,1,True,False)
		mult = blocks.multiply_cc()
		fft = radar.ts_fft_cc(packet_len)
		cfar = radar.os_cfar_c(samp_rate, 5, 0, 0.78, 10, True)
		est = radar.estimator_cw(center_freq)
		res = radar.print_results()
		debug = blocks.message_debug()

		self.tb.connect(src,head,(mult,1))
		self.tb.connect(head,sim,(mult,0))
		self.tb.connect(mult,fft,cfar)
		self.tb.msg_connect(cfar,'Msg out',est,'Msg in')
		self.tb.msg_connect(est,'Msg out',res,'Msg in')
		self.tb.msg_connect(est,'Msg out',debug,'store')
		#self.tb.msg_connect(est,'Msg out',debug,'print')

		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
		
		# check data
		msg = debug.get_message(0)
		self.assertEqual( "rx_time", pmt.symbol_to_string(pmt.nth(0,(pmt.nth(0,msg)))) ) # check rx_time message part (symbol)
		self.assertEqual( 0, pmt.to_uint64(pmt.tuple_ref(pmt.nth(1,(pmt.nth(0,msg))),0)) ) # check rx_time value
		self.assertEqual( 0.0, pmt.to_double(pmt.tuple_ref(pmt.nth(1,(pmt.nth(0,msg))),1)) )
		self.assertEqual( "velocity", pmt.symbol_to_string(pmt.nth(0,(pmt.nth(1,msg)))) ) # check velocity message part (symbol)
		self.assertAlmostEqual( 1, velocity/pmt.f32vector_ref(pmt.nth(1,(pmt.nth(1,msg))),0), 2 ) # check velocity value
Exemple #19
0
 def test_001_t (self):
     data = [ord('t'),ord('e'),ord('s'),ord('t')]
     msg = pmt.list1(pmt.list2(pmt.string_to_symbol("msg_clear"),pmt.init_u8vector(len(data),data)))
     filename_sk = "secret.key"
     filename_pk = "public.key"
     nacl.generate_keypair(filename_sk,filename_pk)
     
     strobe = blocks.message_strobe(msg, 100)
     encrypt_public = nacl.encrypt_public(filename_pk,filename_sk)
     debug = blocks.message_debug()
     
     self.tb.msg_connect(strobe,"strobe",encrypt_public,"Msg clear")
     self.tb.msg_connect(encrypt_public,"Msg encrypted",debug,"store")
     
     self.tb.start()
     sleep(0.15)
     self.tb.stop()
     self.tb.wait()
     
     # check results
     msg_stored = debug.get_message(0)
     nonce = pmt.nth(0,msg_stored)
     msg_encrypted = pmt.nth(1,msg_stored)
     print pmt.symbol_to_string(pmt.nth(0,nonce)), pmt.u8vector_elements(pmt.nth(1,nonce))
     print pmt.symbol_to_string(pmt.nth(0,msg_encrypted)), pmt.u8vector_elements(pmt.nth(1,msg_encrypted))
Exemple #20
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)
Exemple #21
0
    def check_file(self, fname, expected, has_header=False, data_type='uint8'):
        # instantiate objects
        debug = blocks.message_debug()
        reader = csv_reader(fname=fname,
                            has_header=has_header,
                            period=10,
                            repeat=False,
                            start_delay=0,
                            data_type=data_type)

        tb = gr.top_block()
        tb.msg_connect((reader, 'out'), (debug, 'store'))
        tb.start()
        time.sleep(.25)
        tb.stop()
        tb.wait()

        # collect results
        got = debug.get_message(0)
        got_car = pmt.car(got)

        print("got: {}".format(got))
        print("expected: {}".format(expected))

        # do a manual equal on elements because pmt equal is not the best
        expected_items = pmt.dict_items(pmt.car(expected))
        valid = True
        for i in range(pmt.length(expected_items)):
            key = pmt.car(pmt.nth(i, expected_items))
            value = pmt.cdr(pmt.nth(i, expected_items))
            got_value = pmt.dict_ref(got_car, key, pmt.PMT_NIL)
            if not pmt.equal(got_value, value):
                valid = False
                break

        return (valid and pmt.equal(pmt.cdr(got), pmt.cdr(expected)))
def parse_extra_dict(p, info, VERBOSE=False):
    if(pmt.is_dict(p) is False):
        sys.stderr.write("Extra header is not a PMT dictionary: invalid or corrupt data file.\n")
        sys.exit(1)

    items = pmt.dict_items(p)
    nitems = pmt.length(items)
    for i in xrange(nitems):
        item = pmt.nth(i, items)
        key = pmt.symbol_to_string(pmt.car(item))
        val = pmt.cdr(item)
        info[key] = val
        if(VERBOSE):
            print "{0}: {1}".format(key, val)

    return info
def parse_extra_dict(p, info, VERBOSE=False):
    if(pmt.is_dict(p) is False):
        sys.stderr.write("Extra header is not a PMT dictionary: invalid or corrupt data file.\n")
        sys.exit(1)

    items = pmt.dict_items(p)
    nitems = pmt.length(items)
    for i in range(nitems):
        item = pmt.nth(i, items)
        key = pmt.symbol_to_string(pmt.car(item))
        val = pmt.cdr(item)
        info[key] = val
        if(VERBOSE):
            print("{0}: {1}".format(key, val))

    return info
Exemple #24
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 test_001_t (self):
		# run full fsk setup on high sample rates
		test_len = 2**19

		packet_len = 2**19
		min_output_buffer = packet_len*2
		samp_rate = 5000000
		
		center_freq = 2.45e9
		
		Range = 50
		velocity = 5
				
		samp_per_freq = 1
		blocks_per_tag = packet_len/2
		freq_low = 0
		freq_high = 1250000
		amplitude = 1
		samp_discard = 0

		src = radar.signal_generator_fsk_c(samp_rate, samp_per_freq, blocks_per_tag, freq_low, freq_high, amplitude)
		src.set_min_output_buffer(min_output_buffer)
		
		head = blocks.head(8,test_len)
		head.set_min_output_buffer(min_output_buffer)
		
		sim = radar.static_target_simulator_cc((Range,),(velocity,),(1e20,),(0,),(0,),samp_rate,center_freq,1,False,False)
		sim.set_min_output_buffer(min_output_buffer)
		
		mult = blocks.multiply_conjugate_cc()
		mult.set_min_output_buffer(min_output_buffer)
		
		fft1 = radar.ts_fft_cc(packet_len/2)
		fft1.set_min_output_buffer(min_output_buffer)
		fft2 = radar.ts_fft_cc(packet_len/2)
		fft2.set_min_output_buffer(min_output_buffer)
		
		split = radar.split_fsk_cc(samp_per_freq,samp_discard)
		split.set_min_output_buffer(min_output_buffer)
		
		mult_conj = blocks.multiply_conjugate_cc()
		mult_conj.set_min_output_buffer(min_output_buffer)
		
		cfar = radar.find_max_peak_c(samp_rate/2,-120,0,(),False)
		cfar.set_min_output_buffer(min_output_buffer)
		
		est = radar.estimator_fsk(center_freq,freq_high-freq_low)
		res = radar.print_results()
		debug = blocks.message_debug()

		self.tb.connect(src,head,(mult,1))
		self.tb.connect(head,sim,(mult,0))
		self.tb.connect(mult,split)
		self.tb.connect((split,0),fft1)
		self.tb.connect((split,1),fft2)
		self.tb.connect(fft1,(mult_conj,0))
		self.tb.connect(fft2,(mult_conj,1))
		self.tb.connect(mult_conj,cfar)
		self.tb.msg_connect(cfar,'Msg out',est,'Msg in')
		self.tb.msg_connect(est,'Msg out',res,'Msg in')
		self.tb.msg_connect(est,'Msg out',debug,'store')

		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
		
		# check data
		msg = debug.get_message(0)
		#print "VELOCITY:", pmt.f32vector_ref(pmt.nth(1,(pmt.nth(1,msg))),0), velocity
		#print "RANGE:", pmt.f32vector_ref(pmt.nth(1,(pmt.nth(2,msg))),0), Range
		self.assertAlmostEqual( 1, velocity/pmt.f32vector_ref(pmt.nth(1,(pmt.nth(1,msg))),0), 1 ) # check velocity value
		self.assertAlmostEqual( 1, Range/pmt.f32vector_ref(pmt.nth(1,(pmt.nth(2,msg))),0), 1 ) # check range value
	def test_001_t (self):
		# set up variables
		xlen = 50
		ylen = 100
		test_len = xlen*ylen
		
		samp_compare = (5,10)
		samp_protect = (2,4)
		rel_threshold = 0.78
		mult_threshold = 4
		
		# setup input data
		in_data = [0]*test_len
		for k in range(test_len):
			in_data[k] = random.random()
		
		x0 = 10
		y0 = 10
		in_data[x0+xlen*y0] = 2
		
		x1 = 40
		y1 = 15
		in_data[x1+xlen*y1] = 3
		
		x2 = 41
		y2 = 13
		in_data[x2+xlen*y2] = 3
		
		# set up fg
		src = blocks.vector_source_c(in_data)
		s2v = blocks.stream_to_vector(8,xlen)
		s2ts = blocks.stream_to_tagged_stream(8,xlen,ylen,'packet_len')
		cfar = radar.os_cfar_2d_vc(xlen,samp_compare,samp_protect,rel_threshold,mult_threshold)
		debug = blocks.message_debug()
		
		self.tb.connect(src,s2v,s2ts,cfar)
		self.tb.msg_connect(cfar,"Msg out",debug,"store")
		self.tb.msg_connect(cfar,"Msg out",debug,"print")
		
		self.tb.run ()
		
		# check data
		msg = debug.get_message(0)
		cfar_x0 =  pmt.f32vector_ref(pmt.nth(1,pmt.nth(1,msg)),0)
		cfar_x1 =  pmt.f32vector_ref(pmt.nth(1,pmt.nth(1,msg)),1)
		cfar_x2 =  pmt.f32vector_ref(pmt.nth(1,pmt.nth(1,msg)),2)
		cfar_y0 =  pmt.f32vector_ref(pmt.nth(1,pmt.nth(2,msg)),0)
		cfar_y1 =  pmt.f32vector_ref(pmt.nth(1,pmt.nth(2,msg)),1)
		cfar_y2 =  pmt.f32vector_ref(pmt.nth(1,pmt.nth(2,msg)),2)
		
		self.assertAlmostEqual(x0,cfar_x0,4)
		self.assertAlmostEqual(x1,cfar_x1,4)
		self.assertAlmostEqual(x2,cfar_x2,4)
		
		self.assertAlmostEqual(y0,cfar_y0,4)
		self.assertAlmostEqual(y1,cfar_y1,4)
		self.assertAlmostEqual(y2,cfar_y2,4)
    def message_handler(self, msg):
        if not pmt.is_dict(msg):
            return

        try:
            # this will fail if message is a PDU with non-PMT_NIL arguments
            n = pmt.length(pmt.dict_items(msg))

            # a PDU with one element equal to PMT_NIL still looks like a
            # dictionary...grrrrr!
            if (n == 1) and (pmt.equal(pmt.car(msg), pmt.PMT_NIL)
                             or pmt.equal(pmt.cdr(msg), pmt.PMT_NIL)):
                # treat as a pdu
                car = pmt.car(msg)
                cdr = pmt.cdr(msg)
            else:
                car = msg
                cdr = pmt.init_u8vector(0, [])
        except:
            try:
                # message is a pdu
                pmt.length(pmt.dict_items(pmt.car(msg)))
                car = pmt.car(msg)
                cdr = pmt.cdr(msg)
            except:
                return

        if self.find_metadata:
            keys = pmt.dict_keys(car)
            self.header = [(pmt.nth(i, keys), pmt.symbol_to_string)
                           for i in range(pmt.length(keys))]

            header = ','.join([
                pmt.symbol_to_string(pmt.nth(i, keys))
                for i in range(pmt.length(keys))
            ])
            if self.fid:
                self.fid.write(header + '\n')

        # ensure we no longer search for metadata
        self.find_metadata = False

        if self.fid:
            # add metadata
            if self.add_metadata:
                self.print_metadata(car)

            # cdr must be a uniform vector type
            if not pmt.is_uniform_vector(cdr):
                self.fid.write('\n')
                return

            # add data
            values = self.data_type_mappings[self.data_type](cdr)
            if (self.precision > 0) and (self.data_type in [
                    'float', 'double', 'complex float', 'complex double'
            ]):
                self.fid.write(','.join(
                    ['{:.{n}f}'.format(i, n=self.precision) for i in values]))
            else:
                self.fid.write(','.join([str(i) for i in values]))
                self.fid.write('\n')
Exemple #28
0
    def msg_handler(self, p):

        verbose = False

        length = pmt.length(p)
        
        if verbose:
            print "PMT contrains " + str(length) + " key/value pairs"

        for i in range(0,length):
           element = pmt.nth(i, p)

           key = pmt.nth(0, element)
           value = pmt.nth(1, element)

           if verbose:
               print "Key of " + str(i) + "th element: " + str(key)
               print "Value of " + str(i) + "th element: " + str(value)
               print

           found = False
           for j in range(0, len(self.n)):
               if str(key) == self.kk[j]:
                   found = True

                   if verbose:
                       print "found the key " + str(key)

                   #rotate the values, the latest one disappears
                   self.prev_values[j] = numpy.roll(self.prev_values[j], -1)

                   #set the vector accordingly
                   self.prev_values[j][-1] = pmt.f32vector_elements(value)[0]
                   

                   output = sum(self.prev_values[j])/len(self.prev_values[j])
                   output = pmt.make_f32vector(1, output)

                   if i==0:
                       outpmt = pmt.list1(pmt.list2(pmt.string_to_symbol(str(key) + "_filtered"), output))
                   else:
                       outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol(str(key) + "_filtered"), output))



           output = pmt.nth(1, element)

           if i==0:
               outpmt = pmt.list1(pmt.list2(key, output))
           else:
               outpmt = pmt.list_add(outpmt, pmt.list2(key, output))

        if verbose:
            print


        #iterate over all keys
        for i in range(0, len(self.kk)):
            minimum = self.prev_values[i][0]
            maximum = self.prev_values[i][0]
            #iterate over all saved values
            for j in range(0, self.n[i]):
                if self.prev_values[i][j] < minimum:
                    minimum = self.prev_values[i][j]
                if self.prev_values[i][j] > maximum:
                    maximum = self.prev_values[i][j]
        
        #print out a min, diff, max for every key
        difference = maximum-minimum
        outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol("min"), pmt.make_f32vector(1, minimum)))
        outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol("max"), pmt.make_f32vector(1, maximum)))
        outpmt = pmt.list_add(outpmt, pmt.list2(pmt.string_to_symbol("diff"), pmt.make_f32vector(1, difference)))


        self.message_port_pub(pmt.string_to_symbol("out"), outpmt)
	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()
	def test_001_t (self):
		# set up fg
		samp_cw = 2**14
		samp_up = 2**14
		samp_down = samp_up
		packet_len = samp_cw+samp_up+samp_down
		min_output_buffer = packet_len*2
		test_len = 2*packet_len
		samp_rate = 10000000
		push_power = False
		
		center_freq = 5.7e9
		
		Range = 200
		velocity = 50
		
		freq_cw = 0
		freq_sweep = samp_rate/2
		amplitude = 1

		src = radar.signal_generator_fmcw_c(samp_rate, samp_up, samp_down, samp_cw, freq_cw, freq_sweep, amplitude)
		src.set_min_output_buffer(min_output_buffer)
		
		head = blocks.head(8,test_len)
		head.set_min_output_buffer(min_output_buffer)
		
		sim = radar.static_target_simulator_cc((Range,),(velocity,),(1e16,),(0,),(0,),samp_rate,center_freq,1,False,False)
		sim.set_min_output_buffer(min_output_buffer)
		
		mult = blocks.multiply_conjugate_cc()
		mult.set_min_output_buffer(min_output_buffer)
		
		decim_fac = 2**4
		
		resamp = filter.rational_resampler_ccc(1,decim_fac)
		resamp_tag = blocks.tagged_stream_multiply_length(8,'packet_len',1.0/float(decim_fac))
		resamp_tag.set_min_output_buffer(min_output_buffer/(decim_fac))
		
		packets = (samp_cw/(decim_fac), samp_up/(decim_fac), samp_down/(decim_fac))
		split_cw = radar.split_cc(0,packets)
		split_up = radar.split_cc(1,packets)
		split_down = radar.split_cc(2,packets)
		split_cw.set_min_output_buffer(min_output_buffer/(decim_fac))
		split_up.set_min_output_buffer(min_output_buffer/(decim_fac))
		split_down.set_min_output_buffer(min_output_buffer/(decim_fac))
		
		fft_cw = radar.ts_fft_cc(samp_cw/(decim_fac))
		fft_up = radar.ts_fft_cc(samp_up/(decim_fac))
		fft_down = radar.ts_fft_cc(samp_down/(decim_fac))
		fft_cw.set_min_output_buffer(min_output_buffer/(decim_fac))
		fft_up.set_min_output_buffer(min_output_buffer/(decim_fac))
		fft_down.set_min_output_buffer(min_output_buffer/(decim_fac))
		
		threshold = -300
		samp_protect = 0
		cfar_cw = radar.find_max_peak_c(samp_rate/(decim_fac), threshold, samp_protect, (0,0), False)
		cfar_up = radar.find_max_peak_c(samp_rate/(decim_fac), threshold, samp_protect, (0,0), False)
		cfar_down = radar.find_max_peak_c(samp_rate/(decim_fac), threshold, samp_protect, (0,0), False)
		
		est = radar.estimator_fmcw(samp_rate/(decim_fac), center_freq, freq_sweep, samp_up/(decim_fac), samp_down/(decim_fac), push_power)
		
		res = radar.print_results()
		debug = blocks.message_debug()
		
		self.tb.connect(src,head,(mult,0))
		self.tb.connect(head,sim,(mult,1))
		self.tb.connect(mult,resamp, resamp_tag)
		self.tb.connect(resamp_tag,split_cw, fft_cw, cfar_cw)
		self.tb.connect(resamp_tag,split_up, fft_up, cfar_up)
		self.tb.connect(resamp_tag,split_down, fft_down, cfar_down)
		
		self.tb.msg_connect(cfar_cw,'Msg out',est,'Msg in CW')
		self.tb.msg_connect(cfar_up,'Msg out',est,'Msg in UP')
		self.tb.msg_connect(cfar_down,'Msg out',est,'Msg in DOWN')
		self.tb.msg_connect(est,'Msg out',res,'Msg in')
		self.tb.msg_connect(est,'Msg out',debug,'store')
		
		# run fg
		self.tb.start()
		sleep(0.5)
		self.tb.stop()
		self.tb.wait()
		
		# check data
		msg = debug.get_message(0)
		self.assertGreater( velocity/pmt.f32vector_ref(pmt.nth(1,(pmt.nth(1,msg))),0), 0.8 ) # check velocity value
		self.assertGreater( Range/pmt.f32vector_ref(pmt.nth(1,(pmt.nth(2,msg))),0), 0.8 ) # check range value
Exemple #31
0
    def test_001_t(self):
        # set up fg
        samp_cw = 2**14
        samp_up = 2**14
        samp_down = samp_up
        packet_len = samp_cw + samp_up + samp_down
        min_output_buffer = packet_len * 2
        test_len = 2 * packet_len
        samp_rate = 10000000
        push_power = False

        center_freq = 5.7e9

        Range = 200
        velocity = 50

        freq_cw = 0
        freq_sweep = samp_rate / 2
        amplitude = 1

        src = radar.signal_generator_fmcw_c(samp_rate, samp_up, samp_down,
                                            samp_cw, freq_cw, freq_sweep,
                                            amplitude)
        src.set_min_output_buffer(min_output_buffer)

        head = blocks.head(8, test_len)
        head.set_min_output_buffer(min_output_buffer)

        sim = radar.static_target_simulator_cc(
            (Range, ), (velocity, ), (1e16, ), (0, ), (0, ), samp_rate,
            center_freq, 1, False, False)
        sim.set_min_output_buffer(min_output_buffer)

        mult = blocks.multiply_conjugate_cc()
        mult.set_min_output_buffer(min_output_buffer)

        decim_fac = 2**4

        resamp = filter.rational_resampler_ccc(1, decim_fac)
        resamp_tag = blocks.tagged_stream_multiply_length(
            8, 'packet_len', 1.0 / float(decim_fac))
        resamp_tag.set_min_output_buffer(min_output_buffer / (decim_fac))

        packets = (samp_cw / (decim_fac), samp_up / (decim_fac),
                   samp_down / (decim_fac))
        split_cw = radar.split_cc(0, packets)
        split_up = radar.split_cc(1, packets)
        split_down = radar.split_cc(2, packets)
        split_cw.set_min_output_buffer(min_output_buffer / (decim_fac))
        split_up.set_min_output_buffer(min_output_buffer / (decim_fac))
        split_down.set_min_output_buffer(min_output_buffer / (decim_fac))

        fft_cw = radar.ts_fft_cc(samp_cw / (decim_fac))
        fft_up = radar.ts_fft_cc(samp_up / (decim_fac))
        fft_down = radar.ts_fft_cc(samp_down / (decim_fac))
        fft_cw.set_min_output_buffer(min_output_buffer / (decim_fac))
        fft_up.set_min_output_buffer(min_output_buffer / (decim_fac))
        fft_down.set_min_output_buffer(min_output_buffer / (decim_fac))

        threshold = -300
        samp_protect = 0
        cfar_cw = radar.find_max_peak_c(samp_rate / (decim_fac), threshold,
                                        samp_protect, (0, 0), False)
        cfar_up = radar.find_max_peak_c(samp_rate / (decim_fac), threshold,
                                        samp_protect, (0, 0), False)
        cfar_down = radar.find_max_peak_c(samp_rate / (decim_fac), threshold,
                                          samp_protect, (0, 0), False)

        est = radar.estimator_fmcw(samp_rate / (decim_fac), center_freq,
                                   freq_sweep, samp_up / (decim_fac),
                                   samp_down / (decim_fac), push_power)

        res = radar.print_results()
        debug = blocks.message_debug()

        self.tb.connect(src, head, (mult, 0))
        self.tb.connect(head, sim, (mult, 1))
        self.tb.connect(mult, resamp, resamp_tag)
        self.tb.connect(resamp_tag, split_cw, fft_cw, cfar_cw)
        self.tb.connect(resamp_tag, split_up, fft_up, cfar_up)
        self.tb.connect(resamp_tag, split_down, fft_down, cfar_down)

        self.tb.msg_connect(cfar_cw, 'Msg out', est, 'Msg in CW')
        self.tb.msg_connect(cfar_up, 'Msg out', est, 'Msg in UP')
        self.tb.msg_connect(cfar_down, 'Msg out', est, 'Msg in DOWN')
        self.tb.msg_connect(est, 'Msg out', res, 'Msg in')
        self.tb.msg_connect(est, 'Msg out', debug, 'store')

        # run fg
        self.tb.start()
        sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # check data
        msg = debug.get_message(0)
        self.assertGreater(velocity /
                           pmt.f32vector_ref(pmt.nth(1, (pmt.nth(1, msg))), 0),
                           0.8)  # check velocity value
        self.assertGreater(Range /
                           pmt.f32vector_ref(pmt.nth(1, (pmt.nth(2, msg))), 0),
                           0.8)  # check range value
    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()
    def test_001_t(self):
        # set up variables
        xlen = 50
        ylen = 100
        test_len = xlen * ylen

        samp_compare = (5, 10)
        samp_protect = (2, 4)
        rel_threshold = 0.78
        mult_threshold = 4

        # setup input data
        in_data = [0] * test_len
        for k in range(test_len):
            in_data[k] = random.random()

        x0 = 10
        y0 = 10
        in_data[x0 + xlen * y0] = 2

        x1 = 40
        y1 = 15
        in_data[x1 + xlen * y1] = 3

        x2 = 41
        y2 = 13
        in_data[x2 + xlen * y2] = 3

        # set up fg
        src = blocks.vector_source_c(in_data)
        s2v = blocks.stream_to_vector(8, xlen)
        s2ts = blocks.stream_to_tagged_stream(8, xlen, ylen, 'packet_len')
        cfar = radar.os_cfar_2d_vc(xlen, samp_compare, samp_protect,
                                   rel_threshold, mult_threshold)
        debug = blocks.message_debug()

        self.tb.connect(src, s2v, s2ts, cfar)
        self.tb.msg_connect(cfar, "Msg out", debug, "store")
        self.tb.msg_connect(cfar, "Msg out", debug, "print")

        self.tb.run()

        # check data
        msg = debug.get_message(0)
        cfar_x0 = pmt.f32vector_ref(pmt.nth(1, pmt.nth(1, msg)), 0)
        cfar_x1 = pmt.f32vector_ref(pmt.nth(1, pmt.nth(1, msg)), 1)
        cfar_x2 = pmt.f32vector_ref(pmt.nth(1, pmt.nth(1, msg)), 2)
        cfar_y0 = pmt.f32vector_ref(pmt.nth(1, pmt.nth(2, msg)), 0)
        cfar_y1 = pmt.f32vector_ref(pmt.nth(1, pmt.nth(2, msg)), 1)
        cfar_y2 = pmt.f32vector_ref(pmt.nth(1, pmt.nth(2, msg)), 2)

        self.assertAlmostEqual(x0, cfar_x0, 4)
        self.assertAlmostEqual(x1, cfar_x1, 4)
        self.assertAlmostEqual(x2, cfar_x2, 4)

        self.assertAlmostEqual(y0, cfar_y0, 4)
        self.assertAlmostEqual(y1, cfar_y1, 4)
        self.assertAlmostEqual(y2, cfar_y2, 4)