def test_disconnect(self): msgs = ("this", "test", "should", "pass") tb = gr.top_block() #put the source in a hier block hb_src = gr.hier_block2("hb src", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, 1)) src = demo_msg_src(msgs) #put the sink in a hier block hb_sink = gr.hier_block2("hb sink", gr.io_signature(1, 1, 1), gr.io_signature(0, 0, 0)) sink = demo_msg_sink(len(msgs)) #connect hb_src.connect(src, hb_src) hb_sink.connect(hb_sink, sink) tb.connect(hb_src, hb_sink) #disconnect hb_src.disconnect(src, hb_src) hb_sink.disconnect(hb_sink, sink) tb.disconnect(hb_src, hb_sink) #reconnect hb_src.connect(src, hb_src) hb_sink.connect(hb_sink, sink) tb.connect(hb_src, hb_sink) tb.run() self.assertItemsEqual(sink.msgs(), msgs)
def test_030_nested_input(self): tb = gr.top_block() src = gr.vector_source_b([1]) hb1 = gr.hier_block2("hb1", gr.io_signature(1, 1, gr.sizeof_char), gr.io_signature(0, 0, 0)) hb2 = gr.hier_block2("hb2", gr.io_signature(1, 1, gr.sizeof_char), gr.io_signature(0, 0, 0)) dst = gr.vector_sink_b() tb.connect(src, hb1) hb1.connect(hb1, hb2) hb2.connect(hb2, gr.kludge_copy(gr.sizeof_char), dst) tb.run() self.assertEquals(dst.data(), (1,))
def test_006_connect_invalid_src_port_neg(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = gr.nop(gr.sizeof_int) self.assertRaises(ValueError, lambda: hblock.connect((hblock, -1), nop1))
def test_012_disconnect_input(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) hblock.disconnect(hblock, nop1)
def test_016_disconnect_output(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(nop1, hblock) hblock.disconnect(nop1, hblock)
def test_008_connect_invalid_dst_port_exceeds(self): hblock = gr.hier_block2( "test_block", gr.io_signature(1, 1, gr.sizeof_int), gr.io_signature(1, 1, gr.sizeof_int) ) nop1 = gr.null_sink(gr.sizeof_int) nop2 = gr.null_sink(gr.sizeof_int) self.assertRaises(ValueError, lambda: hblock.connect(nop1, (nop2, 1)))
def test_022_connect_single_with_ports(self): hblock = gr.top_block("test_block") blk = gr.hier_block2("block", gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) self.assertRaises(RuntimeError, lambda: hblock.connect(blk))
def test_024_disconnect_single(self): hblock = gr.top_block("test_block") blk = gr.hier_block2("block", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) hblock.connect(blk) hblock.disconnect(blk)
def test_025_disconnect_single_not_connected(self): hblock = gr.top_block("test_block") blk = gr.hier_block2("block", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) self.assertRaises(RuntimeError, lambda: hblock.disconnect(blk))
def test_019_disconnect_output_exceeds(self): hblock = gr.hier_block2( "test_block", gr.io_signature(1, 1, gr.sizeof_int), gr.io_signature(1, 1, gr.sizeof_int) ) nop1 = gr.nop(gr.sizeof_int) hblock.connect(nop1, hblock) self.assertRaises(ValueError, lambda: hblock.disconnect(nop1, (hblock, 1)))
def test_014_disconnect_input_neg(self): hblock = gr.hier_block2( "test_block", gr.io_signature(1, 1, gr.sizeof_int), gr.io_signature(1, 1, gr.sizeof_int) ) nop1 = gr.nop(gr.sizeof_int) hblock.connect(hblock, nop1) self.assertRaises(ValueError, lambda: hblock.disconnect((hblock, -1), nop1))
def test_005_connect_invalid_src_port_exceeds(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) self.assertRaises(RuntimeError, lambda: hblock.connect((hblock, 1), nop1))
def device_definition(options): """ Definition of the devices used in the program. @param options """ tb = OpERAFlow(name='US') the_source = blocks.file_source(gr.sizeof_gr_complex, "./%d_%d_%d_%d_noise.bin" % (options.fft_length, options.cp_length, options.ebn0, options.it), False) radio = RadioDevice(name="radio") det = Correlator() middle = gr.hier_block2( name='hier', input_signature = gr.io_signature(1, 1, gr.sizeof_gr_complex), output_signature = gr.io_signature(1, 1, gr.sizeof_float * 1024), ) middle.connect(middle, blocks.stream_to_vector(gr.sizeof_gr_complex, 1024), blocks.complex_to_mag(1024), middle) ed = EnergySSArch(1024, 1, EnergyDecision(th = options.threshold)) radio.add_arch(source = the_source, arch = middle, sink =(det,0), uhd_device=the_source, name='estimator') radio.add_arch(source = the_source, arch = ed, sink =(det,1), uhd_device=the_source, name = "ed") tb.add_radio(radio, "radio") return tb, radio, det
def test_005_connect_output_in_use(self): hblock = gr.hier_block2( "test_block", gr.io_signature(1, 1, gr.sizeof_int), gr.io_signature(1, 1, gr.sizeof_int) ) nop1 = gr.nop(gr.sizeof_int) nop2 = gr.nop(gr.sizeof_int) hblock.connect(nop1, hblock) self.assertRaises(ValueError, lambda: hblock.connect(nop2, hblock))
def test_027d_fully_unconnected_input(self): tb = gr.top_block() hb = gr.hier_block2("block", gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) hdst = gr.vector_source_b([1]) hb.connect(hdst, hb) # wire output internally dst = gr.vector_sink_b() tb.connect(hb, dst) # hb's input is not connected internally or externally self.assertRaises(RuntimeError, lambda: tb.run())
def test_007_connect_invalid_dst_port_neg(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) nop2 = blocks.nop(gr.sizeof_int) self.assertRaises(RuntimeError, lambda: hblock.connect(nop1, (nop2, -1)))
def test_018_disconnect_output_neg(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) self.assertRaises(RuntimeError, lambda: hblock.disconnect(nop1, (hblock, -1)))
def test_023_connect_single_twice(self): hblock = gr.top_block("test_block") blk = gr.hier_block2("block", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) hblock.connect(blk) self.assertRaises(RuntimeError, lambda: hblock.connect(blk))
def test_015_disconnect_input_exceeds(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) self.assertRaises(RuntimeError, lambda: hblock.disconnect((hblock, 1), nop1))
def test_001_make(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) self.assertEqual("test_block", hblock.name()) self.assertEqual(1, hblock.input_signature().max_streams()) self.assertEqual(1, hblock.output_signature().min_streams()) self.assertEqual(1, hblock.output_signature().max_streams()) self.assertEqual(gr.sizeof_int, hblock.output_signature().sizeof_stream_item(0))
def test_017_disconnect_output_not_connected(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) nop2 = blocks.nop(gr.sizeof_int) hblock.connect(nop1, hblock) self.assertRaises(RuntimeError, lambda: hblock.disconnect(nop2, hblock))
def test_013_disconnect_input_not_connected(self): hblock = gr.hier_block2("test_block", gr.io_signature(1,1,gr.sizeof_int), gr.io_signature(1,1,gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) nop2 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1) self.assertRaises(ValueError, lambda: hblock.disconnect(hblock, nop2))
def test_032_nested_multiple_internal_inputs(self): tb = gr.top_block() src = gr.vector_source_f([1.0]) hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) hb2 = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) m1 = gr.multiply_const_ff(1.0) m2 = gr.multiply_const_ff(2.0) add = gr.add_ff() hb2.connect(hb2, m1) # m1 is connected to hb2 external input #0 hb2.connect(hb2, m2) # m2 is also connected to hb2 external input #0 hb2.connect(m1, (add, 0)) hb2.connect(m2, (add, 1)) hb2.connect(add, hb2) # add is connected to hb2 external output #0 hb.connect(hb, hb2, hb) # hb as hb2 as nested internal block dst = gr.vector_sink_f() tb.connect(src, hb, dst) tb.run() self.assertEquals(dst.data(), (3.0,))
def test_026_run_single(self): expected_data = (1.0,) tb = gr.top_block("top_block") hb = gr.hier_block2("block", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) src = gr.vector_source_f(expected_data) dst = gr.vector_sink_f() hb.connect(src, dst) tb.connect(hb) tb.run() self.assertEquals(expected_data, dst.data())
def test_028_singleton_reconfigure(self): tb = gr.top_block() hb = gr.hier_block2("block", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) src = gr.vector_source_b([1]) dst = gr.vector_sink_b() hb.connect(src, dst) tb.connect(hb) # Singleton connect tb.lock() tb.disconnect_all() tb.connect(src, dst) tb.unlock()
def test_027c_fully_unconnected_output(self): tb = gr.top_block() hb = gr.hier_block2("block", gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) hsrc = blocks.vector_sink_b() hb.connect(hb, hsrc) # wire input internally src = blocks.vector_source_b([1, ]) dst = blocks.vector_sink_b() tb.connect(src, hb) # hb's output is not connected internally or externally self.assertRaises(RuntimeError, lambda: tb.run())
def __init__(self, squelch_rate, squelch_threshold=-100): alpha = 80.0 / squelch_rate self.__squelch = analog.simple_squelch_cc(squelch_threshold, alpha) self.__probe = analog.probe_avg_mag_sqrd_c(0, alpha=alpha) self.squelch_block = gr.hier_block2( defaultstr('SquelchMixin bundle'), gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.squelch_block.connect( self.squelch_block, self.__squelch, self.squelch_block) self.squelch_block.connect( self.squelch_block, self.__probe)
def test_031_multiple_internal_inputs(self): tb = gr.top_block() src = blocks.vector_source_f([1.0,]) hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) m1 = multiply_const_ff(1.0) m2 = multiply_const_ff(2.0) add = add_ff() hb.connect(hb, m1) # m1 is connected to hb external input #0 hb.connect(hb, m2) # m2 is also connected to hb external input #0 hb.connect(m1, (add, 0)) hb.connect(m2, (add, 1)) hb.connect(add, hb) # add is connected to hb external output #0 dst = blocks.vector_sink_f() tb.connect(src, hb, dst) tb.run() self.assertEqual(dst.data(), (3.0,))
def __init__(self, options): gr.top_block.__init__(self, "ofdm_benchmark") ##self._tx_freq = options.tx_freq # tranmitter's center frequency ##self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use ##self._fusb_block_size = options.fusb_block_size # usb info for USRP ##self._fusb_nblocks = options.fusb_nblocks # usb info for USRP ##self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose ##self._interface = options.interface ##self._mac_addr = options.mac_addr self._options = copy.copy(options) self._interpolation = 1 f1 = numpy.array([ -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0, 82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959, 0, -1271, 0, 445, 0, -107 ], numpy.float64) / 262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0 / self._interpolation tb = bw / 5 if self._interpolation > 1: self.tx_filter = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.tx_filter2 = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.tx_filter.connect(self.tx_filter, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.tx_filter) self.tx_filter2.connect(self.tx_filter2, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.tx_filter2) print "New" else: self.tx_filter = None self.tx_filter2 = None self.decimation = 1 if self.decimation > 1: bw = 0.5 / self.decimation * 1 tb = bw / 5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw + tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation, filt_coeff) self.rx_filter2 = gr.fir_filter_ccf(self.decimation, filt_coeff) else: self.rx_filter = None self.rx_filter2 = None ## if not options.from_file is None: ## # sent captured file to usrp ## self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file) ## self._setup_usrp_sink() ## if hasattr(self, "filter"): ## self.connect(self.src,self.filter,self.u) #,self.filter ## else: ## self.connect(self.src,self.u) ## ## return self._setup_tx_path(options) self._setup_rx_path(options) config = station_configuration() self.enable_info_tx("info_tx", "pa_user") # if not options.no_cheat: # self.txpath.enable_channel_cheating("channelcheat") self.txpath.enable_txpower_adjust("txpower") self.txpath.publish_txpower("txpower_info") if options.disable_equalization or options.ideal: #print "CHANGE set_k" self.rxpath.enable_estim_power_adjust("estim_power") #self.rxpath.publish_estim_power("txpower_info") #self.enable_txfreq_adjust("txfreq") if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() self.dst = (self.rxpath, 0) if options.force_rx_filter: print "Forcing rx filter usage" self.connect(self.rx_filter, self.dst) self.dst = self.rx_filter if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.connect(self.m, self.dst) self.dst = self.m if options.snr is not None: if options.berm is not False: noise_sigma = 380 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py #check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db / 10.0) noise_sigma = sqrt(config.rms_amplitude**2 / snr) print " Noise St. Dev. %d" % (noise_sigma) awgn_chan = blocks.add_cc() awgn_noise_src = ofdm.complex_white_noise(0.0, noise_sigma) self.connect(awgn_chan, self.dst) self.connect(awgn_noise_src, (awgn_chan, 1)) self.dst = awgn_chan if options.freqoff is not None: freq_shift = blocks.multiply_cc() norm_freq = options.freqoff / config.fft_length freq_off_src = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0) self.connect(freq_off_src, (freq_shift, 1)) dst = self.dst self.connect(freq_shift, dst) self.dst = freq_shift if options.multipath: if options.itu_channel: fad_chan = itpp.tdl_channel() #[0, -7, -20], [0, 2, 6] #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) fad_chan.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8) fad_chan.set_norm_doppler(1e-8) else: fad_chan = gr.fir_filter_ccc( 1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j]) self.connect(fad_chan, self.dst) self.dst = fad_chan if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000 + soff, 1000000) self.connect(interp, self.dst) self.dst = interp if options.record: log_to_file(self, interp, "data/interp_out.compl") tmm = blocks.throttle(gr.sizeof_gr_complex, self._bandwidth) tmm2 = blocks.throttle(gr.sizeof_gr_complex, self._bandwidth) tmm_add = blocks.add_cc() self.connect(tmm, tmm_add) self.connect(tmm2, (tmm_add, 1)) self.connect(tmm_add, self.dst) self.dst = tmm self.dst2 = tmm2 inter = blocks.interleave(gr.sizeof_gr_complex) deinter = blocks.deinterleave(gr.sizeof_gr_complex) self.connect(inter, deinter) self.connect((deinter, 0), self.dst) self.connect((deinter, 1), self.dst2) self.dst = inter self.dst2 = (inter, 1) if options.force_tx_filter: print "Forcing tx filter usage" self.connect(self.tx_filter, self.dst) self.connect(self.tx_filter2, self.dst2) self.dst = self.tx_filter self.dst2 = self.tx_filter2 if options.record: log_to_file(self, self.txpath, "data/txpath_out.compl") log_to_file(self, self.txpath2, "data/txpath2_out.compl") if options.nullsink: self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst) self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2) self.dst = gr.null_sink(gr.sizeof_gr_complex) self.dst2 = gr.null_sink(gr.sizeof_gr_complex) self.connect(self.txpath, self.dst) self.connect((self.txpath, 1), self.dst2) #log_to_file( self, self.txpath, "data/txpath_out.compl" ) #log_to_file( self, self.txpath,1), "data/txpath2_out.compl" ) if options.cheat: self.txpath.enable_channel_cheating("channelcheat") print "Hit Strg^C to terminate" if options.event_rxbaseband: self.publish_rx_baseband_measure() if options.with_old_gui: self.publish_spectrum(256) self.rxpath.publish_ctf("ctf_display") self.rxpath.publish_ber_measurement(["ber"]) self.rxpath.publish_average_snr(["totalsnr"]) if options.sinr_est: self.rxpath.publish_sinrsc("sinrsc_display") print "Hit Strg^C to terminate" # Display some information about the setup if self._verbose: self._print_verbage()
def test_022_connect_single_with_ports(self): hblock = gr.top_block("test_block") blk = gr.hier_block2("block", gr.io_signature(1, 1, 1), gr.io_signature(1, 1, 1)) self.assertRaises(ValueError, lambda: hblock.connect(blk))
def test_025_disconnect_single_not_connected(self): hblock = gr.top_block("test_block") blk = gr.hier_block2("block", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) self.assertRaises(ValueError, lambda: hblock.disconnect(blk))
def __init__ (self, options): gr.top_block.__init__(self, "ofdm_mrrc_benchmark") ##self._tx_freq = options.tx_freq # tranmitter's center frequency ##self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use ##self._fusb_block_size = options.fusb_block_size # usb info for USRP ##self._fusb_nblocks = options.fusb_nblocks # usb info for USRP ##self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose ##self._interface = options.interface ##self._mac_addr = options.mac_addr self._options = copy.copy( options ) self._interpolation = 1 f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953, 0,-24706,0,82359,262144/2,82359,0,-24706,0, 11953,0,-6107,0,2959,0,-1271,0,445,0,-107], numpy.float64)/262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0/self._interpolation tb = bw/5 if self._interpolation > 1: self.tx_filter = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter2 = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter ) self.tx_filter2.connect( self.tx_filter2, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter2 ) print "New" else: self.tx_filter = None self.tx_filter2 = None self.decimation = 1 if self.decimation > 1: bw = 0.5/self.decimation * 1 tb = bw/5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff) self.rx_filter2 = gr.fir_filter_ccf(self.decimation,filt_coeff) else: self.rx_filter = None self.rx_filter2 = None ## if not options.from_file is None: ## # sent captured file to usrp ## self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file) ## self._setup_usrp_sink() ## if hasattr(self, "filter"): ## self.connect(self.src,self.filter,self.u) #,self.filter ## else: ## self.connect(self.src,self.u) ## ## return self._setup_tx_path(options) self._setup_rx_path(options) self._setup_rpc_manager() config = self.config = station_configuration() #self.enable_txfreq_adjust("txfreq") if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() self.dst = (self.rxpath,0) self.dst2 = (self.rxpath,1) if options.force_rx_filter: print "Forcing rx filter usage" self.connect( self.rx_filter, self.dst ) self.connect( self.rx_filter2, self.dst2 ) self.dst = self.rx_filter self.dst2 = self.rx_filter2 if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.m2 = throughput_measure(gr.sizeof_gr_complex) self.connect( self.m, self.dst ) self.connect( self.m2, self.dst2 ) self.dst = self.m self.dst2 = self.m2 if options.snr is not None: if options.berm is not None: noise_sigma = 380/32767.0 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py print " Noise St. Dev. %f" % (noise_sigma)#check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( config.rms_amplitude**2 / snr ) print " Noise St. Dev. %f" % (noise_sigma) awgn_chan = blocks.add_cc() awgn_chan2 = blocks.add_cc() awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192) awgn_noise_src2 = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma*2, 0, 2192) self.connect( awgn_chan, self.dst ) self.connect( awgn_chan2, self.dst2 ) self.connect( awgn_noise_src, (awgn_chan,1) ) self.connect( awgn_noise_src2, (awgn_chan2,1) ) self.dst = awgn_chan self.dst2 = awgn_chan2 if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff ) freq_off2 = self.freq_off2 = channel.freq_offset(options.freqoff ) dst = self.dst dst2 = self.dst2 self.connect( freq_off, dst ) self.connect( freq_off2, dst2 ) self.dst = freq_off self.dst2 = freq_off2 self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff) self.rpc_mgr_tx.add_interface("set_freq_offset2",self.freq_off2.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) self.fad_chan2 = channel.itpp_channel(options.bandwidth) self.fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) self.fad_chan.set_norm_doppler( 1e-8 ) self.fad_chan2.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) self.fad_chan2.set_norm_doppler( 1e-8 ) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan2.set_channel_profile) else: fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) fad_chan2 = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect( self.fad_chan, self.dst ) self.connect( self.fad_chan2, self.dst2 ) self.dst = self.fad_chan self.dst2 = self.fad_chan2 if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000*(1.0+soff),1000000) interp2 = moms(1000000*(1.0+soff),1000000) self.connect( interp, self.dst ) self.connect( interp2, self.dst2 ) self.dst = interp self.dst2 = interp2 if options.record: log_to_file( self, interp, "data/interp_out.compl" ) log_to_file( self, interp2, "data/interp2_out.compl" ) tmm =blocks.throttle(gr.sizeof_gr_complex, 1e6) #tmm2 =blocks.throttle(gr.sizeof_gr_complex, 1e6) #self.connect( tmm, self.dst ) #self.connect( tmm2, self.dst2 ) #self.dst = tmm #self.dst2 = tmm2 #inter = blocks.interleave(gr.sizeof_gr_complex) #deinter = blocks.deinterleave(gr.sizeof_gr_complex) # Interleaving input/output streams ##self.connect(inter, deinter) #self.connect((deinter,0),self.dst) #self.connect((deinter,1),self.dst2) #self.dst = inter #self.dst2 = (inter,1) if options.force_tx_filter: print "Forcing tx filter usage" self.connect( self.tx_filter, self.dst ) self.connect( self.tx_filter2, self.dst2 ) self.dst = self.tx_filter self.dst2 = self.tx_filter2 if options.record: log_to_file( self, self.txpath, "data/txpath_out.compl" ) log_to_file( self, self.txpath2, "data/txpath2_out.compl" ) if options.nullsink: self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst) self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2) self.dst = gr.null_sink(gr.sizeof_gr_complex) self.dst2 = gr.null_sink(gr.sizeof_gr_complex) self.connect( self.txpath,tmm,self.dst ) self.connect( tmm,self.dst2 ) #self.connect( self.txpath,self.dst2 ) print "Hit Strg^C to terminate" if self._verbose: self._print_verbage()
def test_002_connect_input(self): hblock = gr.hier_block2("test_block", gr.io_signature(1, 1, gr.sizeof_int), gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(hblock, nop1)
def __init__ (self, options): gr.top_block.__init__(self, "ofdm_benchmark") self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose self._options = copy.copy( options ) self.ideal = options.ideal self.ideal2 = options.ideal2 rms_amp = options.rms_amplitude self._interpolation = 1 f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953, 0,-24706,0,82359,262144/2,82359,0,-24706,0, 11953,0,-6107,0,2959,0,-1271,0,445,0,-107], numpy.float64)/262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0/self._interpolation tb = bw/5 if self._interpolation > 1: self.tx_filter = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter ) print "New" else: self.tx_filter = None self.decimation = 1 if self.decimation > 1: bw = 0.5/self.decimation * 1 tb = bw/5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff) else: self.rx_filter = None self._setup_tx_path(options) self._setup_rx_path(options) self._setup_rpc_manager() config = self.config = station_configuration() if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() # capture transmitter's stream to disk #self.dst = gr.file_sink(gr.sizeof_gr_complex,options.to_file) self.dst= self.rxpath if options.force_rx_filter: print "Forcing rx filter usage" self.connect( self.rx_filter, self.dst ) self.dst = self.rx_filter if options.ideal or self.ideal2: self._amplifier = ofdm.multiply_const_ccf( 1.0 ) self.connect( self._amplifier, self.dst ) self.dst = self._amplifier self.set_rms_amplitude(rms_amp) if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.connect( self.m, self.dst ) self.dst = self.m if options.snr is not None: if options.berm is not None: # empirically determined to reach 30db SNR max in simulation mode noise_sigma = 0.0035 else: snr_db = options.snr snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( config.rms_amplitude**2 / snr ) print " Noise St. Dev. %f" % (noise_sigma) awgn_chan = blocks.add_cc() #awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma ) awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192) self.connect( awgn_noise_src, (awgn_chan,1) ) self.connect( awgn_chan, self.dst ) self.dst = awgn_chan if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff ) dst = self.dst self.connect(freq_off, dst) self.dst = freq_off self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile) self.rpc_mgr_tx.add_interface("set_norm_doppler",self.fad_chan.set_norm_doppler) else: #self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) # filter coefficients for the lab exercise self.fad_chan = filter.fir_filter_ccc(1,[0.3267,0.8868,0.3267]) #self.fad_chan = filter.fir_filter_ccc(1,[0,0,0.1,0.2,0.01,0.3])#0.3267,0.8868,0.3267]) #self.fad_chan = channels.selective_fading_model(5, 0.1, False, 1, -1, [0, 0, 0], [0.3267,0.8868,0.3267], 10 ) #self.fad_chan = channels.fading_model(6, 0.05, False); #self.fad_chan = channels.dynamic_channel_model(1000000, 0, 0, 0, 0, 3, 0.01, False, 0, [2e-6,4e-6,8e-6],[0.3267,0.8868,0.3267], 20, 0, 0) self.connect(self.fad_chan, self.dst) self.dst = self.fad_chan if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000*(1.0+soff),1000000) #interp = filter.fractional_resampler_cc(0,1000000*(1.0+soff)/1000000.0) self.connect( interp, self.dst ) self.dst = interp if options.record: log_to_file( self, interp, "data/interp_out.compl" ) tmm =blocks.throttle(gr.sizeof_gr_complex,options.bandwidth) self.connect( tmm, self.dst ) self.dst = tmm if options.force_tx_filter: print "Forcing tx filter usage" self.connect( self.tx_filter, self.dst ) self.dst = self.tx_filter if options.record: log_to_file( self, self.txpath, "data/txpath_out.compl" ) if options.scatterplot: print "Scatterplot enabled" self.connect( self.txpath,self.dst ) print "Hit Strg^C to terminate" print "Hit Strg^C to terminate" # Display some information about the setup if self._verbose: self._print_verbage()
def test_036_unconnected_lock(self): hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) hb.lock() hb.unlock()
def __init__(self, options): gr.top_block.__init__(self, "ofdm_tx") self._tx_freq = options.tx_freq # tranmitter's center frequency self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use self._fusb_block_size = options.fusb_block_size # usb info for USRP self._fusb_nblocks = options.fusb_nblocks # usb info for USRP self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._interface = options.interface self._mac_addr = options.mac_addr self._options = copy.copy(options) self._interpolation = 1 f1 = numpy.array([ -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0, 82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959, 0, -1271, 0, 445, 0, -107 ], numpy.float64) / 262144. print "Software interpolation: %d" % (self._interpolation) bw = 0.5 / self._interpolation tb = bw / 5 if self._interpolation > 1: self.filter = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.filter.connect(self.filter, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.filter) print "New" # # # self.filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.2, 60.0, 0) # self.filter = gr.interp_fir_filter_ccf(self._interpolation,self.filt_coeff) # print "Software interpolation filter length: %d" % (len(self.filt_coeff)) else: self.filter = None if not options.from_file is None: # sent captured file to usrp self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file) self._setup_usrp_sink() if hasattr(self, "filter"): self.connect(self.src, self.filter, self.u) #,self.filter else: self.connect(self.src, self.u) return self._setup_tx_path(options) config = station_configuration() self.enable_info_tx("info_tx", "pa_user") # if not options.no_cheat: # self.txpath.enable_channel_cheating("channelcheat") self.txpath.enable_txpower_adjust("txpower") self.txpath.publish_txpower("txpower_info") #self.enable_txfreq_adjust("txfreq") if options.nullsink: self.dst = gr.null_sink(gr.sizeof_gr_complex) else: if not options.to_file is None: # capture transmitter's stream to disk self.dst = gr.file_sink(gr.sizeof_gr_complex, options.to_file) tmp = gr.throttle(gr.sizeof_gr_complex, 1e5) self.connect(tmp, self.dst) self.dst = tmp if options.force_filter: print "Forcing filter usage" self.connect(self.filter, self.dst) self.dst = self.filter else: # connect transmitter to usrp self._setup_usrp_sink() if options.dyn_freq: self.enable_txfreq_adjust("txfreq") if self.filter is not None: self.connect(self.filter, self.dst) self.dst = self.filter if options.record: log_to_file(self, self.txpath, "data/txpath_out.compl") #self.publish_spectrum( 256 ) if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.connect(self.m, self.dst) self.dst = self.m if options.samplingoffset is not None: soff = options.samplingoffset interp = gr.fractional_interpolator_cc(0.0, soff) self.connect(interp, self.dst) self.dst = interp if options.snr is not None: # if options.berm is not None: # noise_sigma = 380 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py # #check for fading channel # else: snr_db = options.snr snr = 10.0**(snr_db / 10.0) noise_sigma = sqrt(config.rms_amplitude**2 / snr) print " Noise St. Dev. %d" % (noise_sigma) awgn_chan = gr.add_cc() awgn_noise_src = ofdm.complex_white_noise(0.0, noise_sigma) self.connect(awgn_noise_src, (awgn_chan, 1)) self.connect(awgn_chan, self.dst) self.dst = awgn_chan if options.berm is False: fad_chan = itpp.tdl_channel() #[0, -7, -20], [0, 2, 6] #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) fad_chan.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8) fad_chan.set_norm_doppler(1e-8) # fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect(fad_chan, self.dst) self.dst = fad_chan if options.freqoff is not None: freq_shift = gr.multiply_cc() norm_freq = options.freqoff / config.fft_length freq_off_src = gr.sig_source_c(1.0, gr.GR_SIN_WAVE, norm_freq, 1.0, 0.0) self.connect(freq_off_src, (freq_shift, 1)) dst = self.dst self.connect(freq_shift, dst) self.dst = freq_shift self.connect(self.txpath, self.dst) if options.cheat: self.txpath.enable_channel_cheating("channelcheat") print "Hit Strg^C to terminate"
def __init__ (self, options): gr.top_block.__init__(self, "ofdm_benchmark") ##self._tx_freq = options.tx_freq # tranmitter's center frequency ##self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use ##self._fusb_block_size = options.fusb_block_size # usb info for USRP ##self._fusb_nblocks = options.fusb_nblocks # usb info for USRP ##self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose ##self._interface = options.interface ##self._mac_addr = options.mac_addr self._options = copy.copy( options ) self._interpolation = 1 f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953, 0,-24706,0,82359,262144/2,82359,0,-24706,0, 11953,0,-6107,0,2959,0,-1271,0,445,0,-107], numpy.float64)/262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0/self._interpolation tb = bw/5 if self._interpolation > 1: self.tx_filter = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter2 = gr.hier_block2("filter", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter ) self.tx_filter2.connect( self.tx_filter2, gr.interp_fir_filter_ccf(2,f1), gr.interp_fir_filter_ccf(2,f1), self.tx_filter2 ) print "New" else: self.tx_filter = None self.tx_filter2 = None self.decimation = 1 if self.decimation > 1: bw = 0.5/self.decimation * 1 tb = bw/5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff) self.rx_filter2 = gr.fir_filter_ccf(self.decimation,filt_coeff) else: self.rx_filter = None self.rx_filter2 = None ## if not options.from_file is None: ## # sent captured file to usrp ## self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file) ## self._setup_usrp_sink() ## if hasattr(self, "filter"): ## self.connect(self.src,self.filter,self.u) #,self.filter ## else: ## self.connect(self.src,self.u) ## ## return self._setup_tx_path(options) self._setup_rx_path(options) config = station_configuration() self.enable_info_tx("info_tx", "pa_user") # if not options.no_cheat: # self.txpath.enable_channel_cheating("channelcheat") self.txpath.enable_txpower_adjust("txpower") self.txpath.publish_txpower("txpower_info") if options.disable_equalization or options.ideal: #print "CHANGE set_k" self.rxpath.enable_estim_power_adjust("estim_power") #self.rxpath.publish_estim_power("txpower_info") #self.enable_txfreq_adjust("txfreq") if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() self.dst = (self.rxpath,0) self.dst2 = (self.rxpath,1) if options.force_rx_filter: print "Forcing rx filter usage" self.connect( self.rx_filter, self.dst ) self.connect( self.rx_filter2, self.dst2 ) self.dst = self.rx_filter self.dst2 = self.rx_filter2 if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.m2 = throughput_measure(gr.sizeof_gr_complex) self.connect( self.m, self.dst ) self.connect( self.m2, self.dst2 ) self.dst = self.m self.dst2 = self.m2 if options.snr is not None: if options.berm is not False: noise_sigma = 380 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py #check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( config.rms_amplitude**2 / snr ) print " Noise St. Dev. %d" % (noise_sigma) awgn_chan = blocks.add_cc() awgn_chan2 = blocks.add_cc() awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma ) awgn_noise_src2 = ofdm.complex_white_noise( 0.0, noise_sigma ) self.connect( awgn_chan, self.dst ) self.connect( awgn_chan2, self.dst2 ) self.connect( awgn_noise_src, (awgn_chan,1) ) self.connect( awgn_noise_src2, (awgn_chan2,1) ) self.dst = awgn_chan self.dst2 = awgn_chan2 if options.freqoff is not None: freq_shift = blocks.multiply_cc() freq_shift2 = blocks.multiply_cc() norm_freq = options.freqoff / config.fft_length freq_off_src = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0 ) freq_off_src2 = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0 ) self.connect( freq_off_src, ( freq_shift, 1 ) ) self.connect( freq_off_src2, ( freq_shift2, 1 ) ) dst = self.dst dst2 = self.dst2 self.connect( freq_shift, dst ) self.connect( freq_shift2, dst2 ) self.dst = freq_shift self.dst2 = freq_shift2 if options.multipath: if options.itu_channel: fad_chan = itpp.tdl_channel( ) #[0, -7, -20], [0, 2, 6] #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) fad_chan2 = itpp.tdl_channel( ) fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) fad_chan.set_norm_doppler( 1e-8 ) fad_chan2.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 ) fad_chan2.set_norm_doppler( 1e-8 ) else: fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) fad_chan2 = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j]) self.connect( fad_chan, self.dst ) self.connect( fad_chan2, self.dst2 ) self.dst = fad_chan self.dst2 = fad_chan2 if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000+soff,1000000) interp2 = moms(1000000+soff,1000000) self.connect( interp, self.dst ) self.connect( interp2, self.dst2 ) self.dst = interp self.dst2 = interp2 if options.record: log_to_file( self, interp, "data/interp_out.compl" ) log_to_file( self, interp2, "data/interp2_out.compl" ) tmm =blocks.throttle(gr.sizeof_gr_complex,self._bandwidth) tmm2 =blocks.throttle(gr.sizeof_gr_complex,self._bandwidth) tmm_add = blocks.add_cc() tmm2_add = blocks.add_cc() self.connect( tmm, tmm_add ) self.connect( tmm2, (tmm_add,1) ) self.connect( tmm, tmm2_add ) self.connect( tmm2, (tmm2_add,1) ) self.connect( tmm_add, self.dst ) self.connect( tmm2_add, self.dst2 ) self.dst = tmm self.dst2 = tmm2 inter = blocks.interleave(gr.sizeof_gr_complex) deinter = blocks.deinterleave(gr.sizeof_gr_complex) self.connect(inter, deinter) self.connect((deinter,0),self.dst) self.connect((deinter,1),self.dst2) self.dst = inter self.dst2 = (inter,1) if options.force_tx_filter: print "Forcing tx filter usage" self.connect( self.tx_filter, self.dst ) self.connect( self.tx_filter2, self.dst2 ) self.dst = self.tx_filter self.dst2 = self.tx_filter2 if options.record: log_to_file( self, self.txpath, "data/txpath_out.compl" ) log_to_file( self, self.txpath2, "data/txpath2_out.compl" ) if options.nullsink: self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst) self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2) self.dst = gr.null_sink(gr.sizeof_gr_complex) self.dst2 = gr.null_sink(gr.sizeof_gr_complex) self.connect( self.txpath,self.dst ) self.connect( (self.txpath,1),self.dst2 ) if options.cheat: self.txpath.enable_channel_cheating("channelcheat") print "Hit Strg^C to terminate" if options.event_rxbaseband: self.publish_rx_baseband_measure() if options.with_old_gui: self.publish_spectrum(256) self.rxpath.publish_ctf("ctf_display") self.rxpath.publish_ber_measurement(["ber"]) self.rxpath.publish_average_snr(["totalsnr"]) if options.sinr_est: self.rxpath.publish_sinrsc("sinrsc_display") print "Hit Strg^C to terminate" # Display some information about the setup if self._verbose: self._print_verbage()
def test_005_connect_invalid_src_port_exceeds(self): hblock = gr.hier_block2("test_block", gr.io_signature(1, 1, gr.sizeof_int), gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) self.assertRaises(TypeError, lambda: hblock.connect((hblock, 1), nop1))
def test_004_connect_output(self): hblock = gr.hier_block2("test_block", gr.io_signature(1, 1, gr.sizeof_int), gr.io_signature(1, 1, gr.sizeof_int)) nop1 = blocks.nop(gr.sizeof_int) hblock.connect(nop1, hblock)
def __init__(self, options): gr.top_block.__init__(self, "ofdm_mrrc_benchmark") ##self._tx_freq = options.tx_freq # tranmitter's center frequency ##self._tx_subdev_spec = options.tx_subdev_spec # daughterboard to use ##self._fusb_block_size = options.fusb_block_size # usb info for USRP ##self._fusb_nblocks = options.fusb_nblocks # usb info for USRP ##self._which = options.which_usrp self._bandwidth = options.bandwidth self.servants = [] self._verbose = options.verbose ##self._interface = options.interface ##self._mac_addr = options.mac_addr self._options = copy.copy(options) self._interpolation = 1 f1 = numpy.array([ -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0, 82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959, 0, -1271, 0, 445, 0, -107 ], numpy.float64) / 262144. print "Software interpolation: %d" % (self._interpolation) bw = 1.0 / self._interpolation tb = bw / 5 if self._interpolation > 1: self.tx_filter = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.tx_filter2 = gr.hier_block2( "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.tx_filter.connect(self.tx_filter, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.tx_filter) self.tx_filter2.connect(self.tx_filter2, gr.interp_fir_filter_ccf(2, f1), gr.interp_fir_filter_ccf(2, f1), self.tx_filter2) print "New" else: self.tx_filter = None self.tx_filter2 = None self.decimation = 1 if self.decimation > 1: bw = 0.5 / self.decimation * 1 tb = bw / 5 # gain, sampling rate, passband cutoff, stopband cutoff # passband ripple in dB, stopband attenuation in dB # extra taps filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw + tb, 0.1, 60.0, 1) print "Software decimation filter length: %d" % (len(filt_coeff)) self.rx_filter = gr.fir_filter_ccf(self.decimation, filt_coeff) self.rx_filter2 = gr.fir_filter_ccf(self.decimation, filt_coeff) else: self.rx_filter = None self.rx_filter2 = None ## if not options.from_file is None: ## # sent captured file to usrp ## self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file) ## self._setup_usrp_sink() ## if hasattr(self, "filter"): ## self.connect(self.src,self.filter,self.u) #,self.filter ## else: ## self.connect(self.src,self.u) ## ## return self._setup_tx_path(options) self._setup_rx_path(options) self._setup_rpc_manager() config = self.config = station_configuration() #self.enable_txfreq_adjust("txfreq") if options.imgxfer: self.rxpath.setup_imgtransfer_sink() if not options.no_decoding: self.rxpath.publish_rx_performance_measure() self.dst = (self.rxpath, 0) self.dst2 = (self.rxpath, 1) if options.force_rx_filter: print "Forcing rx filter usage" self.connect(self.rx_filter, self.dst) self.connect(self.rx_filter2, self.dst2) self.dst = self.rx_filter self.dst2 = self.rx_filter2 if options.measure: self.m = throughput_measure(gr.sizeof_gr_complex) self.m2 = throughput_measure(gr.sizeof_gr_complex) self.connect(self.m, self.dst) self.connect(self.m2, self.dst2) self.dst = self.m self.dst2 = self.m2 if options.snr is not None: if options.berm is not None: noise_sigma = 380 / 32767.0 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py print " Noise St. Dev. %f" % (noise_sigma ) #check for fading channel else: snr_db = options.snr snr = 10.0**(snr_db / 10.0) noise_sigma = sqrt(config.rms_amplitude**2 / snr) print " Noise St. Dev. %f" % (noise_sigma) awgn_chan = blocks.add_cc() awgn_chan2 = blocks.add_cc() awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192) awgn_noise_src2 = analog.fastnoise_source_c( analog.GR_GAUSSIAN, noise_sigma * 2, 0, 2192) self.connect(awgn_chan, self.dst) self.connect(awgn_chan2, self.dst2) self.connect(awgn_noise_src, (awgn_chan, 1)) self.connect(awgn_noise_src2, (awgn_chan2, 1)) self.dst = awgn_chan self.dst2 = awgn_chan2 if options.freqoff is not None: freq_off = self.freq_off = channel.freq_offset(options.freqoff) freq_off2 = self.freq_off2 = channel.freq_offset(options.freqoff) dst = self.dst dst2 = self.dst2 self.connect(freq_off, dst) self.connect(freq_off2, dst2) self.dst = freq_off self.dst2 = freq_off2 self.rpc_mgr_tx.add_interface("set_freq_offset", self.freq_off.set_freqoff) self.rpc_mgr_tx.add_interface("set_freq_offset2", self.freq_off2.set_freqoff) if options.multipath: if options.itu_channel: self.fad_chan = channel.itpp_channel(options.bandwidth) #fad_chan.set_norm_doppler( 1e-9 ) #fad_chan.set_LOS( [500.,0,0] ) self.fad_chan2 = channel.itpp_channel(options.bandwidth) self.fad_chan.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8) self.fad_chan.set_norm_doppler(1e-8) self.fad_chan2.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8) self.fad_chan2.set_norm_doppler(1e-8) self.rpc_mgr_tx.add_interface( "set_channel_profile", self.fad_chan.set_channel_profile) self.rpc_mgr_tx.add_interface( "set_channel_profile", self.fad_chan2.set_channel_profile) else: fad_chan = filter.fir_filter_ccc( 1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j]) fad_chan2 = filter.fir_filter_ccc( 1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j]) self.connect(self.fad_chan, self.dst) self.connect(self.fad_chan2, self.dst2) self.dst = self.fad_chan self.dst2 = self.fad_chan2 if options.samplingoffset is not None: soff = options.samplingoffset interp = moms(1000000 * (1.0 + soff), 1000000) interp2 = moms(1000000 * (1.0 + soff), 1000000) self.connect(interp, self.dst) self.connect(interp2, self.dst2) self.dst = interp self.dst2 = interp2 if options.record: log_to_file(self, interp, "data/interp_out.compl") log_to_file(self, interp2, "data/interp2_out.compl") tmm = blocks.throttle(gr.sizeof_gr_complex, 1e6) #tmm2 =blocks.throttle(gr.sizeof_gr_complex, 1e6) #self.connect( tmm, self.dst ) #self.connect( tmm2, self.dst2 ) #self.dst = tmm #self.dst2 = tmm2 #inter = blocks.interleave(gr.sizeof_gr_complex) #deinter = blocks.deinterleave(gr.sizeof_gr_complex) # Interleaving input/output streams ##self.connect(inter, deinter) #self.connect((deinter,0),self.dst) #self.connect((deinter,1),self.dst2) #self.dst = inter #self.dst2 = (inter,1) if options.force_tx_filter: print "Forcing tx filter usage" self.connect(self.tx_filter, self.dst) self.connect(self.tx_filter2, self.dst2) self.dst = self.tx_filter self.dst2 = self.tx_filter2 if options.record: log_to_file(self, self.txpath, "data/txpath_out.compl") log_to_file(self, self.txpath2, "data/txpath2_out.compl") if options.nullsink: self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst) self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2) self.dst = gr.null_sink(gr.sizeof_gr_complex) self.dst2 = gr.null_sink(gr.sizeof_gr_complex) self.connect(self.txpath, tmm, self.dst) self.connect(tmm, self.dst2) #self.connect( self.txpath,self.dst2 ) print "Hit Strg^C to terminate" if self._verbose: self._print_verbage()
def test_023_connect_single_twice(self): hblock = gr.top_block("test_block") blk = gr.hier_block2("block", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) hblock.connect(blk) self.assertRaises(ValueError, lambda: hblock.connect(blk))