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_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): # 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): # set up fg samp_rate = 20000 packet_len = 2048 freq = 0 ampl = 1 noise_ampl = 0.1 test_len = packet_len * 200 rng = (10, 10, 10) vlc = (5, -10, 0) rcs = (1e8, 1e8, 1e8) center_freq = 6e9 src = radar.signal_generator_cw_c(packet_len, samp_rate, freq, ampl) head = blocks.head(8, test_len) sim = radar.simulator_cc(rng, vlc, rcs, samp_rate, center_freq) noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_ampl, 0) add = blocks.add_cc() # estimator samp_compare = 10 samp_protect = 0 rel_threshold = 1 avg_mult = 6 dec_factor = 2 mult = blocks.multiply_cc() dec = radar.decimator_cc(dec_factor) fft = radar.tsfft_cc() cfar = radar.os_cfar_c(samp_rate / dec_factor, samp_compare, samp_protect, rel_threshold, avg_mult) est_v = radar.est_v_cw(center_freq) # end: estimator snk = blocks.vector_sink_c() # connect self.tb.connect(src, head, sim) self.tb.connect((sim, 0), (add, 0)) self.tb.connect((noise, 0), (add, 1)) self.tb.connect((head, 0), (mult, 0)) self.tb.connect((add, 0), (mult, 1)) self.tb.connect(mult, dec, fft, cfar) self.tb.msg_connect(cfar, 'cfar_out', est_v, 'cw_in') self.tb.connect(fft, snk) # run self.tb.start() sleep(0.5) self.tb.stop() self.tb.wait() # check data data = snk.data() y = [0] * packet_len for k in range(packet_len): y[k] = pow(abs(data[k + 0 * packet_len / 2]), 2) x = [0] * packet_len for k in range(packet_len / 2): x[k] = k * samp_rate / packet_len x[k + packet_len / 2] = -samp_rate / 2.0 + k * samp_rate / packet_len plt.plot(x, y) # frequency on x, shifted #plt.plot(y) # samples on x, nonshifted plt.yscale('log') plt.title("FFT spectrum")
def test_001_t (self): # set up fg samp_rate = 20000 packet_len = 2048 freq = 0 ampl = 1 noise_ampl = 0.1 test_len = packet_len*200 rng = (10,10, 10) vlc = (5,-10, 0) rcs = (1e8,1e8, 1e8) center_freq = 6e9; src = radar.signal_generator_cw_c(packet_len,samp_rate,freq,ampl) head = blocks.head(8,test_len) sim = radar.simulator_cc(rng,vlc,rcs,samp_rate,center_freq) noise = analog.noise_source_c(analog.GR_GAUSSIAN,noise_ampl,0) add = blocks.add_cc() # estimator samp_compare = 10 samp_protect = 0 rel_threshold = 1 avg_mult = 6 dec_factor = 2 mult = blocks.multiply_cc() dec = radar.decimator_cc(dec_factor) fft = radar.tsfft_cc() cfar = radar.os_cfar_c(samp_rate/dec_factor, samp_compare,samp_protect, rel_threshold, avg_mult) est_v = radar.est_v_cw(center_freq) # end: estimator snk = blocks.vector_sink_c() # connect self.tb.connect(src,head,sim) self.tb.connect((sim,0),(add,0)) self.tb.connect((noise,0),(add,1)) self.tb.connect((head,0),(mult,0)) self.tb.connect((add,0),(mult,1)) self.tb.connect(mult,dec,fft,cfar) self.tb.msg_connect(cfar,'cfar_out',est_v,'cw_in') self.tb.connect(fft,snk) # run self.tb.start() sleep(0.5) self.tb.stop() self.tb.wait() # check data data = snk.data() y = [0]*packet_len for k in range(packet_len): y[k] = pow(abs(data[k+0*packet_len/2]),2) x = [0]*packet_len for k in range(packet_len/2): x[k] = k*samp_rate/packet_len x[k+packet_len/2]=-samp_rate/2.0+k*samp_rate/packet_len plt.plot(x, y) # frequency on x, shifted #plt.plot(y) # samples on x, nonshifted plt.yscale('log') plt.title("FFT spectrum")