def test_001_t (self): src = analog.sig_source_c(32000, analog.GR_COS_WAVE, 12500, 1) detector = inspector.signal_detector_cvf(32000, 1024, firdes.WIN_BLACKMAN_hARRIS, -80, 0.6, False, 0.5, 0.0001) dst1 = blocks.null_sink(gr.sizeof_float*1024) dst2 = blocks.null_sink(gr.sizeof_float*1024) msg_dst = blocks.message_debug() self.tb.connect(src, detector) self.tb.connect((detector, 0), dst1) self.tb.connect((detector, 1), dst2) self.tb.msg_connect((detector, 'map_out'), (msg_dst, 'store')) self.tb.start() time.sleep(0.5) self.tb.stop() self.tb.wait() msg = msg_dst.get_message(1) res_vector = numpy.empty([0, 2]) for i in range(pmt.length(msg)): row = pmt.vector_ref(msg, i) res_vector = numpy.vstack((res_vector, numpy.array( [pmt.f32vector_ref(row, 0), pmt.f32vector_ref(row, 1)] ))) self.assertAlmostEqual(12500.0, res_vector[0][0], delta=100) self.assertAlmostEqual(0.0, res_vector[0][1], delta=200)
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)
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)
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)
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 = (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
def test_001_t(self): src1 = analog.sig_source_c(32000, analog.GR_COS_WAVE, 12500, 3) src2 = analog.sig_source_c(32000, analog.GR_COS_WAVE, 9800, 3) add = blocks.add_cc() detector = inspector.signal_detector_cvf(32000, 4096, firdes.WIN_BLACKMAN_hARRIS, -80, 0.6, False, 0.5, 0.001) dst1 = blocks.null_sink(gr.sizeof_float * 4096) msg_dst = blocks.message_debug() # connections self.tb.connect(src1, (add, 0)) self.tb.connect(src2, (add, 1)) self.tb.connect(add, detector) self.tb.connect((detector, 0), dst1) self.tb.msg_connect((detector, 'map_out'), (msg_dst, 'store')) self.tb.start() time.sleep(0.5) self.tb.stop() self.tb.wait() # take most recent message msg = msg_dst.get_message(msg_dst.num_messages() - 1) res_vector = numpy.empty([0, 2]) for i in range(pmt.length(msg)): row = pmt.vector_ref(msg, i) res_vector = numpy.vstack( (res_vector, numpy.array( [pmt.f32vector_ref(row, 0), pmt.f32vector_ref(row, 1)]))) self.assertAlmostEqual(9800.0, res_vector[0][0], delta=50) self.assertAlmostEqual(0.0, res_vector[0][1], delta=100) self.assertAlmostEqual(12500.0, res_vector[1][0], delta=50) self.assertAlmostEqual(0.0, res_vector[1][1], delta=100)
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 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 test_001_t (self): src1 = analog.sig_source_c(32000, analog.GR_COS_WAVE, 12500, 3) src2 = analog.sig_source_c(32000, analog.GR_COS_WAVE, 9800, 3) add = blocks.add_cc() detector = inspector.signal_detector_cvf(32000, 4096, firdes.WIN_BLACKMAN_hARRIS, -80, 0.6, False, 0.5, 0.001) dst1 = blocks.null_sink(gr.sizeof_float*4096) msg_dst = blocks.message_debug() #connections self.tb.connect(src1, (add, 0)) self.tb.connect(src2, (add, 1)) self.tb.connect(add, detector) self.tb.connect((detector, 0), dst1) self.tb.msg_connect((detector, 'map_out'), (msg_dst, 'store')) self.tb.start() time.sleep(0.5) self.tb.stop() self.tb.wait() #take most recent message msg = msg_dst.get_message(msg_dst.num_messages()-1) res_vector = numpy.empty([0, 2]) for i in range(pmt.length(msg)): row = pmt.vector_ref(msg, i) res_vector = numpy.vstack((res_vector, numpy.array( [pmt.f32vector_ref(row, 0), pmt.f32vector_ref(row, 1)] ))) self.assertAlmostEqual(9800.0, res_vector[0][0], delta=50) self.assertAlmostEqual(0.0, res_vector[0][1], delta=100) self.assertAlmostEqual(12500.0, res_vector[1][0], delta=50) self.assertAlmostEqual(0.0, res_vector[1][1], delta=100)
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
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
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 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): # 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