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_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_to_pam(self): self.emitter = pdu_utils.message_emitter() #self.flip = pdu_utils.pdu_binary_tools(pdu_utils.pdu_binary_tools.TO_PAM) self.flip = pdu_utils.pdu_binary_tools(1) 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_u8vector(6, [1, 0, 0, 1, 0, 1]) e_vec = pmt.init_f32vector(6, [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 to_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.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_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))
def test_001_t(self): self.emitter = pdu_utils.message_emitter() self.qd = pdu_utils.pdu_quadrature_demod_cf(1) self.debug = blocks.message_debug() self.tb.msg_connect((self.emitter, 'msg'), (self.qd, 'cpdus')) self.tb.msg_connect((self.qd, 'fpdus'), (self.debug, 'store')) in_data1 = [1., 1.j, -1., -1.j, 1.] in_data2 = [7. + 7.j, -7. + 7.j, -7. - 7.j, 7. - 7.j, 7. + 7.j] expected_data = [PI / 2, PI / 2, PI / 2, PI / 2] in_pdu1 = pmt.cons(pmt.make_dict(), pmt.init_c32vector(len(in_data1), in_data1)) in_pdu2 = pmt.cons(pmt.make_dict(), pmt.init_c32vector(len(in_data2), in_data2)) self.tb.start() time.sleep(.001) self.emitter.emit(in_pdu1) time.sleep(.01) self.emitter.emit(in_pdu2) time.sleep(.01) self.tb.stop() self.tb.wait() out_data = pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0))) self.assertFloatTuplesAlmostEqual(out_data, expected_data, 4) out_data = pmt.f32vector_elements(pmt.cdr(self.debug.get_message(1))) self.assertFloatTuplesAlmostEqual(out_data, expected_data, 4)
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_ao40_fec_deframer(self): """Loads symbols from an AO-73 packet and checks if ao40_fec_deframer produces the expected output and intermediate data (stored in a reference files)""" test_data = blocks.file_source(gr.sizeof_float, self.symbols_path) deframer = ao40_fec_deframer() dbg_sync = blocks.message_debug() dbg_deinterleave = blocks.message_debug() dbg_frame = blocks.message_debug() dbg_viterbi = blocks.message_debug() self.tb.connect(test_data, deframer) self.tb.msg_connect((deframer.deframer, 'out'), (dbg_sync, 'store')) self.tb.msg_connect((deframer.deinterleaver, 'out'), (dbg_deinterleave, 'store')) self.tb.msg_connect((deframer.viterbi_decoder, 'out'), (dbg_viterbi, 'store')) self.tb.msg_connect((deframer, 'out'), (dbg_frame, 'store')) self.tb.start() self.tb.wait() synced = pmt.f32vector_elements(pmt.cdr(dbg_sync.get_message(0))) synced_reference = np.fromfile(self.frame_path, dtype='float32') self.assertFloatTuplesAlmostEqual( synced, synced_reference, "synchronizer output doesn't match expected result") deinterleaved = pmt.f32vector_elements( pmt.cdr(dbg_deinterleave.get_message(0))) rows = 80 cols = 65 skip = 65 output_size = 5132 deinterleaved_reference = synced_reference.reshape( (cols, rows)).transpose().ravel()[skip:][:output_size] self.assertFloatTuplesAlmostEqual( deinterleaved, deinterleaved_reference, "deinterleaver output doesn't match expected result") post_viterbi = pmt.u8vector_elements( pmt.cdr(dbg_viterbi.get_message(0))) post_viterbi_reference = tuple( np.unpackbits(np.array(self.post_viterbi_reference, dtype='uint8'))) self.assertEqual( post_viterbi, post_viterbi_reference, "Viterbi decoder output doesn't match expected result") frame = pmt.u8vector_elements(pmt.cdr(dbg_frame.get_message(0))) self.assertEqual( frame, self.frame_reference, "ao40_fec_deframer() final output doesn't match expected frame")
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)))
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_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)
def parser(self, msg): # Get data from pdu cdr = pmt.cdr(msg) data = copy( numpy.array(pmt.f32vector_elements(cdr), dtype=numpy.float32)) # Calculate number of samples per half bit interpolation = 30 * self.samp_rate / 250000 self.threshold = .5 # Find first transition first_transition = numpy.argmax(data > self.threshold) burst_width = numpy.argmax(data[first_transition:] < self.threshold) while burst_width < 10: first_transition = numpy.argmax( data[first_transition + burst_width + 1:] > self.threshold) + first_transition + burst_width + 1 burst_width = numpy.argmax( data[first_transition:] < self.threshold) next_expected_transition = first_transition next_expected_transition += interpolation * 2 # The first transition is a zero bit bits = [0] while True: next_expected_transition = int(next_expected_transition) interp2 = int(interpolation * .5) # Grab a chunk of data around the next bit chunk = data[next_expected_transition - interp2:next_expected_transition + interp2] # If there wasn't enough data then exit if len(chunk) < interp2 * 1.5: break # Break into data before and after the transition chunk1 = chunk[:interp2] chunk2 = chunk[interp2:] # Calculate whether it is a falling or rising transition d = sum(chunk2) - sum(chunk1) if abs(d) < 10: break # If there is no transition then the packet is done if d > 0: bits.append(0) else: bits.append(1) ## Determine the next expected transition location dc = numpy.abs(numpy.diff(chunk)) amax = numpy.argmax(dc) drift = amax - (interp2 - 1) if abs(drift < 15): next_expected_transition += drift next_expected_transition += interpolation * 2 cdr = pmt.init_u8vector(len(bits), bits) msg = pmt.cons(pmt.PMT_NIL, cdr) self.message_port_pub(pmt.intern("data"), msg)
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)
def test_002_tags_plus_data(self): packet_len = 16 src_data = range(packet_len) tag1 = gr.tag_t() tag1.offset = 0 tag1.key = pmt.string_to_symbol('spam') tag1.value = pmt.from_long(23) tag2 = gr.tag_t() tag2.offset = 10 # Must be < packet_len tag2.key = pmt.string_to_symbol('eggs') tag2.value = pmt.from_long(42) src = blocks.vector_source_f(src_data, tags=(tag1, tag2)) s2ts = blocks.stream_to_tagged_stream(gr.sizeof_float, vlen=1, packet_len=packet_len, len_tag_key="packet_len") ts2pdu = blocks.tagged_stream_to_pdu(blocks.float_t, "packet_len") dbg = blocks.message_debug() self.tb.connect(src, s2ts, ts2pdu) self.tb.msg_connect(ts2pdu, "pdus", dbg, "store") self.tb.start() while dbg.num_messages() < 1: time.sleep(0.1) self.tb.stop() self.tb.wait() result_msg = dbg.get_message(0) metadata = pmt.to_python(pmt.car(result_msg)) vector = pmt.f32vector_elements(pmt.cdr(result_msg)) self.assertEqual(metadata, {'eggs': 42, 'spam': 23}) self.assertFloatTuplesAlmostEqual(tuple(vector), src_data)
def test_003_tags_plus_data(self): packet_len = 16 src_data = list(range(packet_len)) tag1 = gr.tag_t() tag1.offset = 0 tag1.key = pmt.string_to_symbol('spam') tag1.value = pmt.from_long(23) tag2 = gr.tag_t() tag2.offset = 10 # Must be < packet_len tag2.key = pmt.string_to_symbol('eggs') tag2.value = pmt.from_long(42) src = blocks.vector_source_f(src_data, tags=(tag1, tag2)) s2ts = blocks.stream_to_tagged_stream(gr.sizeof_float, vlen=1, packet_len=packet_len, len_tag_key="packet_len") ts2pdu = pdu.tagged_stream_to_pdu(gr.types.float_t, "packet_len") dbg = blocks.message_debug() self.tb.connect(src, s2ts, ts2pdu) self.tb.msg_connect(ts2pdu, "pdus", dbg, "store") self.tb.start() self.tb.wait() result_msg = dbg.get_message(0) metadata = pmt.to_python(pmt.car(result_msg)) vector = pmt.f32vector_elements(pmt.cdr(result_msg)) self.assertEqual(metadata, {'eggs': 42, 'spam': 23}) self.assertFloatTuplesAlmostEqual(tuple(vector), src_data)
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 handle_msg_fft_average(self, msg_pmt): # PMT TYPE CHECK AND UNPACKING if pmt.is_symbol(msg_pmt): msg_str = pmt.symbol_to_string(msg_pmt) if msg_str == "FFT_AVG_FINISH_ACK": self.top_block.rise_fft_avg_flag() elif pmt.is_f32vector(msg_pmt): data = pmt.f32vector_elements(msg_pmt) self.fft_data_buffer = data
def handle_msg_energy(self, msg_pmt): # PMT TYPE CHECK AND UNPACKING if pmt.is_symbol(msg_pmt): msg_str = pmt.symbol_to_string(msg_pmt) if msg_str == "E_FINISH_ACK": self.top_block.rise_energy_flag() elif pmt.is_f32vector(msg_pmt): data = pmt.f32vector_elements(msg_pmt) self.top_block.on_receive_pkt_data(data)
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 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 pls = np.array(pmt.f32vector_elements(msg)[:64], dtype='float32') correlations = np.sum(pls[:, np.newaxis] * scrambled_PLS_bipolar, axis=0) code = PLS_codes[np.argmax(correlations)] # It seems that there is a typo in the rev 1.04 document # PLS-code 0 is listed as corresponding to data length 223 # PLS-code 1 is listed as corresponding to data length 48 # However, according to the test IQ data it is the other way # around data_len = 48 if code == 0 else 223 payload_len = (data_len + 32) * 2 payload_out = pmt.f32vector_elements(msg)[64:][:8 * payload_len] payload_out = pmt.init_f32vector(len(payload_out), payload_out) msg_out = pmt.cons(pmt.car(msg_pmt), payload_out) self.message_port_pub(pmt.intern('out'), msg_out)
def test_to_pam(self): self.dut = pdu_utils.pdu_binary_tools(1) #TO_NRZ self.connectUp() i_vec = pmt.init_u8vector(6, [1, 0, 0, 1, 0, 1]) e_vec = pmt.init_f32vector(6, [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 to_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.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))
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))
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)
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)
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)
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)
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)
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
def fft_msg_handler(self, pdu): if not self.need_to_publish or self.fft_ready: # drop messages if we're not currently building an image return # if we are building an image, read the pdu f32 fft data try: meta = pmt.car(pdu) data = pmt.f32vector_elements(pmt.cdr(pdu)) except Exception as e: # should we reset the image data here? print(f"exception in burst_tag_debug, {e}") return # check that this vector is the same size as the rest if not len(data) == self.fft_size: print(f"different length vector received in burst_tag_debug block {len(data)}, resetting") self.image_data = [] self.row_idx = 0 return # save off the starting sample number of this image if self.starting_fft_sample is None: self.starting_fft_sample = pmt.to_uint64(pmt.dict_ref(meta, self.pmt_start_offset, pmt.PMT_NIL)) # looks good, add on the data to the image self.image_data.append(data) self.row_idx += 1 # publish an event followed by an image once it is complete if self.row_idx >= self.nrows: self.fft_ready = True # wait N more seconds for additional burst metadata to make it in N = 1.0 self.publish_timer = threading.Timer(N, self.publish_result) self.publish_timer.start()
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 __init__(self, fname='', add_metadata=False, metadata_format='', data_type='uint8', precision=0): gr.sync_block.__init__(self, name="csv_writer", in_sig=None, out_sig=None) self.fname = fname self.add_metadata = add_metadata self.metadata_format = metadata_format self.data_type = data_type self.precision = precision self.fid = None # setup logger logger_name = 'gr_log.' + self.to_basic_block().alias() if logger_name in gr.logger_get_names(): self.log = gr.logger(logger_name) else: self.log = gr.logger('log') # metadata field mappings self.metadata_mappings = { 'string': lambda x: pmt.symbol_to_string(x), 'bool': lambda x: pmt.to_bool(x), 'long': lambda x: pmt.to_long(x), 'uint64': lambda x: pmt.to_uint64(x), 'float': lambda x: pmt.to_float(x), 'double': lambda x: pmt.to_double(x), 'complex': lambda x: pmt.to_complex(x), 'time': lambda x: float(pmt.to_uint64(pmt.car(x))) + pmt.to_double( pmt.cdr(x)), 'time_tuple': lambda x: float(pmt.to_uint64(pmt.tuple_ref(x, 0))) + pmt. to_double(pmt.tuple_ref(x, 1)) } # data type parsers self.data_type_mappings = { 'uint8': lambda x: pmt.u8vector_elements(x), 'int8': lambda x: pmt.s8vector_elements(x), 'uint16': lambda x: pmt.u16vector_elements(x), 'int16': lambda x: pmt.s16vector_elements(x), 'uint32': lambda x: pmt.u32vector_elements(x), 'int32': lambda x: pmt.s32vector_elements(x), 'float': lambda x: pmt.f32vector_elements(x), 'complex float': lambda x: pmt.c32vector_elements(x), 'double': lambda x: pmt.f64vector_elements(x), 'complex double': lambda x: pmt.c64vector_elements(x) } # check data type if data_type not in self.data_type_mappings.keys(): raise ValueError('Invalid data type') self.find_metadata = False self.header = [] if self.add_metadata: if self.metadata_format == '': # set flag to load metadata on first message received self.find_metadata = True else: self.parse_header_format() # register message handler self.message_port_name = pmt.intern('in') self.message_port_register_in(self.message_port_name) self.set_msg_handler(self.message_port_name, self.message_handler)
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()