def test_002_dst_in_use (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) src2 = gr.null_source (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) fg.connect ((src1, 0), (dst1, 0)) self.assertRaises (ValueError, lambda : fg.connect ((src2, 0), (dst1, 0)))
def test_107 (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) src2 = gr.null_source (gr.sizeof_int) nop1 = gr.nop (gr.sizeof_int) nop2 = gr.nop (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) dst2 = gr.null_sink (gr.sizeof_int) fg.connect (src1, nop1) fg.connect (nop1, dst1) fg.connect (src2, nop2) fg.connect (nop2, dst2) fg.validate () ts = fg.topological_sort (fg.all_blocks ()) self.assertEqual ([src2, nop2, dst2, src1, nop1, dst1], ts)
def test_001_t (self): self.degree = 5 self.length = 2**self.degree - 1 expected_result = (self.length - 1)*[-1.0/self.length]+[1] # send a maximum length sequence with period 31 src_real = digital.glfsr_source_f(self.degree, True, 0, 1) src_imag = gr.null_source(gr.sizeof_float*1) f2c = gr.float_to_complex(1) mls_correlator = channelsounder_swig.mls_correlator(self.degree, mask = 0, seed = 1) # keep only the samples of the first two autocorrelation periods head = gr.head(gr.sizeof_gr_complex, 2*self.length) dest = gr.vector_sink_c(1) self.tb.connect( src_real, (f2c, 0)) self.tb.connect( src_imag, (f2c, 1)) self.tb.connect( f2c, mls_correlator ) self.tb.connect( mls_correlator, head, dest ) # set up fg self.tb.run () # check data result_data = dest.data() # discard the first period, since it is tainted by the zeros inserted # by set_history() result_data = result_data[self.length:] self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
def __init__(self, demodulator, rx_callback, options): gr.top_block.__init__(self) if(options.rx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = demodulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / demodulator(**args).bits_per_symbol() self.source = uhd_receiver(options.args, symbol_rate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.spec, options.antenna,1) #options.verbose) options.samples_per_symbol = self.source._sps elif(options.from_file is not None): sys.stderr.write(("Reading samples from '%s'.\n\n" % (options.from_file))) self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: sys.stderr.write("No source defined, pulling samples from null source.\n\n") self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(demodulator, rx_callback, options) self.connect(self.source, self.rxpath)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.scifile_flow_0 = scifile_flow.scifile_flow() self.scifile_flow_0.set_parameters("/home/rishabh/Downloads/test.sci", 1) self.plot_sink_0 = plot_sink.plot_sink_f( self.GetWin(), title="Scope Plot", vlen=1, decim=1, ) self.Add(self.plot_sink_0.win) self.gr_null_source_0 = gr.null_source(gr.sizeof_float * 1) ################################################## # Connections ################################################## self.connect((self.gr_null_source_0, 0), (self.scifile_flow_0, 0)) self.connect((self.scifile_flow_0, 0), (self.plot_sink_0, 0))
def __init__(self, demodulator, rx_callback, options): gr.top_block.__init__(self) if (options.rx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = demodulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / demodulator(**args).bits_per_symbol() self.source = osmo_receiver(options.args, symbol_rate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.antenna, options.bandwidth) options.samples_per_symbol = self.source._sps #elif (options.from_file is not None): # sys.stderr.write(("Reading samples from '%s'.\n\n" % (options.from_file))) # self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: sys.stderr.write("No source defined, pulling samples from null source.\n\n") self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the Osmocom sink) self.rxpath = receive_path(demodulator, rx_callback, options) self.connect(self.source, self.rxpath)
def __init__(self, item_size, num_inputs, num_outputs, input_index, output_index): """ Selector constructor. @param item_size the size of the gr data stream in bytes @param num_inputs the number of inputs (integer) @param num_outputs the number of outputs (integer) @param input_index the index for the source data @param output_index the index for the destination data """ gr.hier_block2.__init__( self, 'selector', gr.io_signature(num_inputs, num_inputs, item_size), gr.io_signature(num_outputs, num_outputs, item_size), ) #terminator blocks for unused inputs and outputs self.input_terminators = [gr.null_sink(item_size) for i in range(num_inputs)] self.output_terminators = [gr.head(item_size, 0) for i in range(num_outputs)] self.copy = gr.kludge_copy(item_size) #connections for i in range(num_inputs): self.connect((self, i), self.input_terminators[i]) for i in range(num_outputs): self.connect(gr.null_source(item_size), self.output_terminators[i], (self, i)) self.item_size = item_size self.input_index = input_index self.output_index = output_index self.num_inputs = num_inputs self.num_outputs = num_outputs self._connect_current()
def __init__(self, which=''): gr.top_block.__init__(self, "Filter Test") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex*1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc( interpolation=3, decimation=7, taps=None, fractional_bw=None, ) self.fir_filter_xxx_0 = filter.fir_filter_ccc(7, ([.7]*23)) if which == 'dfir': self.filter = self.fir_filter_xxx_0 if which == 'resamp': self.filter = self.blks2_rational_resampler_xxx_0 ################################################## # Connections ################################################## self.connect((self.filter, 0), (self.gr_null_sink_0, 0)) self.connect((self.gr_null_source_0, 0), (self.filter, 0))
def test_001_srcsink_ss (self): sys.stderr.write("Creating null source\n") src = gr.null_source(gr.sizeof_short) sys.stderr.write("Creating throttle\n") thr = gr.throttle(gr.sizeof_short,1000) sys.stderr.write("Creating fake SPI device\n") dummy = spi.srcsink_ss("/dev/null",1000000) sys.stderr.write("Creating null sink\n") sink = gr.null_sink(gr.sizeof_short) sys.stderr.write("Connecting source to throttle\n") self.fg.connect(src,thr) sys.stderr.write("Connecting throttle to SPI\n") self.fg.connect(thr,dummy) sys.stderr.write("Connecting SPI to sink\n") self.fg.connect(dummy,sink) sys.stderr.write("Starting flow graph\n") self.fg.start() time.sleep(0.1) sys.stderr.write("Stopping flow graph\n") self.fg.stop() sys.stderr.write("Deleting blocks\n") del src del thr del dummy del sink sys.stderr.write("All done!\n")
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.nyquist_block_nyquist_0 = nyquist.nyquist() self.nyquist_block_nyquist_0.set_parameters("0,1,2*0.9*10,100", "0,1,2*0.3*10.1,102.01", "0,1,2*0.1*15.1,228.01", "0,1,2*0.9*15,225") self.gr_null_source_0 = gr.null_source(gr.sizeof_float * 1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_float * 1) ################################################## # Connections ################################################## self.connect((self.gr_null_source_0, 0), (self.nyquist_block_nyquist_0, 0)) self.connect((self.nyquist_block_nyquist_0, 0), (self.gr_null_sink_0, 0))
def body_109 (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) fg.connect (src1, dst1) fg._setup_connections () self.assertEqual ((2,2,1,1), all_counts ())
def test_101_tsort_two (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) fg.connect ((src1, 0), (dst1, 0)) fg.validate () self.assertEqual ([src1, dst1], fg.topological_sort (fg.all_blocks ()))
def __init__(self, callback, options): gr.top_block.__init__(self) if (options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif (options.from_file is not None): self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) if (options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) self.source.set_sample_rate(1500000) #rx sample rate self.sink.set_sample_rate(640000) self.rxpath = receive_path(callback, options) self.txpath = transmit_path(options) self.connect(self.source, self.rxpath) self.connect(self.txpath, self.sink) self.source.set_antenna("RX2") global freq freq = options.tx_freq # - 12e6
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.sci_python_sci_py_0 = sci_py.sci_py() self.sci_python_sci_py_0.set_parameters("/home/rishabh/Downloads/test.sci",1,"y") self.plot_sink_0 = plot_sink.plot_sink_f( self.GetWin(), title="Scope Plot", vlen=1, decim=1, gsz=1000, ) self.Add(self.plot_sink_0.win) self.gr_null_source_0 = gr.null_source(gr.sizeof_float*1) ################################################## # Connections ################################################## self.connect((self.gr_null_source_0, 0), (self.sci_python_sci_py_0, 0)) self.connect((self.sci_python_sci_py_0, 0), (self.plot_sink_0, 0))
def test_001_t(self): self.degree = 5 self.length = 2**self.degree - 1 expected_result = (self.length - 1) * [-1.0 / self.length] + [1] # send a maximum length sequence with period 31 src_real = digital.glfsr_source_f(self.degree, True, 0, 1) src_imag = gr.null_source(gr.sizeof_float * 1) f2c = gr.float_to_complex(1) mls_correlator = channelsounder_swig.mls_correlator(self.degree, mask=0, seed=1) # keep only the samples of the first two autocorrelation periods head = gr.head(gr.sizeof_gr_complex, 2 * self.length) dest = gr.vector_sink_c(1) self.tb.connect(src_real, (f2c, 0)) self.tb.connect(src_imag, (f2c, 1)) self.tb.connect(f2c, mls_correlator) self.tb.connect(mls_correlator, head, dest) # set up fg self.tb.run() # check data result_data = dest.data() # discard the first period, since it is tainted by the zeros inserted # by set_history() result_data = result_data[self.length:] self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
def test_005_one_src_two_dst (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) dst2 = gr.null_sink (gr.sizeof_int) fg.connect ((src1, 0), (dst1, 0)) fg.connect ((src1, 0), (dst2, 0))
def test_004_no_such_dst_port (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) self.assertRaises (ValueError, lambda : fg.connect ((src1, 0), (dst1, 1)))
def test_006_check_item_sizes (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_char) self.assertRaises (ValueError, lambda : fg.connect ((src1, 0), (dst1, 0)))
def __init__(self, N, op, isizeof=gr.sizeof_gr_complex, osizeof=gr.sizeof_gr_complex, nsrcs=1, nsnks=1): gr.top_block.__init__(self, "helper") self.op = op self.srcs = [] self.snks = [] self.head = gr.head(isizeof, N) for n in xrange(nsrcs): self.srcs.append(gr.null_source(isizeof)) for n in xrange(nsnks): self.snks.append(gr.null_sink(osizeof)) self.connect(self.srcs[0], self.head, (self.op, 0)) for n in xrange(1, nsrcs): self.connect(self.srcs[n], (self.op, n)) for n in xrange(nsnks): self.connect((self.op, n), self.snks[n])
def __init__(self, demod_class, rx_callback, options): gr.top_block.__init__(self) self.rxpath = receive_path(demod_class, rx_callback, options) self.audio_tx = audio_tx(options.audio_output) if (options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bitrate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.antenna, options.verbose) options.samples_per_symbol = self.source._sps audio_rate = self.audio_tx.sample_rate usrp_rate = self.source.get_sample_rate() rrate = audio_rate / usrp_rate self.resampler = blks2.pfb_arb_resampler_ccf(rrate) self.connect(self.source, self.resampler, self.rxpath) elif (options.from_file is not None): self.thr = gr.throttle(gr.sizeof_gr_complex, options.bitrate) self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) self.connect(self.source, self.thr, self.rxpath) else: self.thr = gr.throttle(gr.sizeof_gr_complex, 1e6) self.source = gr.null_source(gr.sizeof_gr_complex) self.connect(self.source, self.thr, self.rxpath) self.connect(self.audio_tx)
def __init__(self, callback, options): gr.top_block.__init__(self) if (options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose, options.external) elif (options.from_file is not None): self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) self.connect(self.source, self.rxpath) if options.log: self.connect( self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx_benchmark.dat'))
def __init__(self): gr.top_block.__init__(self, "Affinity Set Test") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## vec_len = 1 self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*vec_len, samp_rate) self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex*vec_len) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*vec_len) self.gr_filt_0 = gr.fir_filter_ccc(1, 40000*[0.2+0.3j,]) self.gr_filt_1 = gr.fir_filter_ccc(1, 40000*[0.2+0.3j,]) self.gr_filt_0.set_processor_affinity([0,]) self.gr_filt_1.set_processor_affinity([0,1]) ################################################## # Connections ################################################## self.connect((self.gr_null_source_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_filt_0, 0)) self.connect((self.gr_filt_0, 0), (self.gr_filt_1, 0)) self.connect((self.gr_filt_1, 0), (self.gr_null_sink_0, 0))
def __init__(self, demod_class, rx_callback, options): gr.top_block.__init__(self) self.rxpath = receive_path(demod_class, rx_callback, options) self.audio_tx = audio_tx(options.audio_output) if(options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bitrate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.antenna, options.verbose) options.samples_per_symbol = self.source._sps audio_rate = self.audio_tx.sample_rate usrp_rate = self.source.get_sample_rate() rrate = audio_rate / usrp_rate self.resampler = blks2.pfb_arb_resampler_ccf(rrate) self.connect(self.source, self.resampler, self.rxpath) elif(options.from_file is not None): self.thr = gr.throttle(gr.sizeof_gr_complex, options.bitrate) self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) self.connect(self.source, self.thr, self.rxpath) else: self.thr = gr.throttle(gr.sizeof_gr_complex, 1e6) self.source = gr.null_source(gr.sizeof_gr_complex) self.connect(self.source, self.thr, self.rxpath) self.connect(self.audio_tx)
def test_014_connect_varargs (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) nop1 = gr.nop (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) fg.connect (src1, nop1, dst1) fg.validate ()
def __init__(self, callback, options): gr.top_block.__init__(self) ### Rx Side ### if(options.rx_freq is not None): self.source = uhd_receiver(options.args_rx, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif(options.from_file is not None): self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) ## Tx Side ### if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args_tx, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink) # self.txpath = gr.message_source(gr.sizeof_gr_complex, 3) # nco_sensitivity = 2.0/options.fft_length # correct for fine frequency # self.nco = ftw.pnc_frequency_modulator_fc(nco_sensitivity) # self.connect(self.txpath, self.sink) # self.nco, # if you use two USRPs and want to synchonized # need to change uhd_interface.py # self.source.config_mimo() # time.sleep(1) # to make sync stable if options.debug: self.connect(self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx.dat')) # Save reception signal else: self.connect(self.source, self.rxpath) #self.connect(self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx.dat')) if(options.verbose): self._print_verbage()
def test_007_validate (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) dst2 = gr.null_sink (gr.sizeof_int) fg.connect ((src1, 0), (dst1, 0)) fg.connect ((src1, 0), (dst2, 0)) fg.validate ()
def body_201 (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) src2 = gr.null_source (gr.sizeof_int) nop1 = gr.nop (gr.sizeof_int) nop2 = gr.nop (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) dst2 = gr.null_sink (gr.sizeof_int) fg.connect (nop2, dst2) fg.connect (src1, nop1) fg.connect (src2, nop2) fg.connect (nop1, dst1) fg.validate () p = fg.partition_graph (fg.all_blocks ()) self.assertEqual ([[src2, nop2, dst2], [src1, nop1, dst1]], p) self.assertEqual ((6,0,0,0), all_counts ())
def setUp (self): self.tb = gr.top_block () self.tp = drm.transm_params(1, 3, False, 0, False, 1, 0, 1, 1, 0, False, 24000, "station label", "this is a long sample text message!") self.audio_enc = drm.audio_encoder_svb(self.tp) self.src = gr.null_source(4) self.head = gr.head(4, 960*10*3) self.snk = gr.vector_sink_b(self.tp.msc().L_MUX()) self.tb.connect(self.src, self.head, self.audio_enc, self.snk)
def test_013_connect_varargs (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) nop1 = gr.nop (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) self.assertRaises (ValueError, lambda : fg.connect ()) self.assertRaises (ValueError, lambda : fg.connect (src1))
def test_103_tsort_three_b (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) nop1 = gr.nop (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) fg.connect (nop1, dst1) fg.connect (src1, nop1) fg.validate () self.assertEqual ([src1, nop1, dst1], fg.topological_sort (fg.all_blocks ()))
def __init__(self, callback, options): gr.top_block.__init__(self) ### Rx Side ### if (options.rx_freq is not None): self.source = uhd_receiver(options.args_rx, options.bandwidth, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) elif (options.from_file is not None): self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) ## Tx Side ### if (options.tx_freq is not None): self.sink = uhd_transmitter(options.args_tx, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(options) self.connect(self.txpath, self.sink) # self.txpath = gr.message_source(gr.sizeof_gr_complex, 3) # nco_sensitivity = 2.0/options.fft_length # correct for fine frequency # self.nco = ftw.pnc_frequency_modulator_fc(nco_sensitivity) # self.connect(self.txpath, self.sink) # self.nco, # if you use two USRPs and want to synchonized # need to change uhd_interface.py # self.source.config_mimo() # time.sleep(1) # to make sync stable if options.debug: self.connect(self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx.dat')) # Save reception signal else: self.connect(self.source, self.rxpath) #self.connect(self.source, gr.file_sink(gr.sizeof_gr_complex, 'rx.dat')) if (options.verbose): self._print_verbage()
def __init__(self): parser = OptionParser(option_class=eng_option, conflict_handler="resolve") expert_grp = parser.add_option_group("Expert") parser.add_option("-s", "--size", type="eng_float", default=400, help="set packet size [default=%default]") parser.add_option("-M", "--megabytes", type="eng_float", default=1.0, help="set megabytes to transmit [default=%default]") parser.add_option("","--discontinuous", action="store_true", default=False, help="enable discontinuous mode") (options, args) = parser.parse_args () gr.top_block.__init__(self) padded_preambles = list() known_symb = [-1, -1, 1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1] fft_length = 16 occupied_tones = 4 zeros_on_left= int(math.ceil((fft_length - occupied_tones)/2.0)) ksfreq = known_symb[0:occupied_tones] preambles = (ksfreq,) print zeros_on_left for pre in preambles: padded = fft_length*[0,] padded[zeros_on_left : zeros_on_left + occupied_tones] = pre padded_preambles.append(padded) self.preambles_2 = gr.ofdm_insert_preamble(fft_length, padded_preambles) data1 = 512*[complex(2,3)] #How to generate complex modulated values twos = 511*[1] twos_arr = array('B',twos) data2 = array('B',[1]) data2.extend(twos_arr) #print data self.data_src1 = gr.vector_source_c(data1,True,16) self.data_src2 = gr.vector_source_b(data2,True,1) self.data_src3 = gr.null_source(128) self.data_src4 = gr.null_source(1) self.sink_n = gr.vector_sink_c(16) self.sink_file = gr.file_sink(16*gr.sizeof_gr_complex,'pad') v2s = gr.vector_to_stream(128,1) self.connect(self.data_src1,(self.preambles_2,0)) self.connect(self.data_src2,(self.preambles_2,1)) self.connect((self.preambles_2,0),self.sink_n) self.connect((self.preambles_2,0),self.sink_file)
def __init__(self, controller, filename="", muted=True): # ------------------------------------------------------------------------ super(FileSourceAdapter, self).__init__() self.controller = controller self.samprate = controller.samprate if filename: self.source = gr.file_source(gr.sizeof_float, filename, True) else: self.source = gr.null_source(gr.sizeof_float) self.mute = gr.mute_ff(muted)
def setUp(self): self.tb = gr.top_block() self.tp = drm.transm_params( 1, 3, False, 0, False, 1, 0, 1, 1, 0, False, 24000, "station label", "this is a long sample text message!" ) self.audio_enc = drm.audio_encoder_svb(self.tp) self.src = gr.null_source(4) self.head = gr.head(4, 960 * 10 * 3) self.snk = gr.vector_sink_b(self.tp.msc().L_MUX()) self.tb.connect(self.src, self.head, self.audio_enc, self.snk)
def test_002_measure_processing_rate(self): src = gr.null_source(gr.sizeof_char) throttle = gr.throttle(gr.sizeof_char, 10000000) head = gr.head(gr.sizeof_char, 1000000) sink = dab_swig.measure_processing_rate(gr.sizeof_char,1000000) self.tb.connect(src, throttle, head, sink) self.tb.run() rate = sink.processing_rate() assert(rate > 8000000 and rate < 12000000)
def __init__(self): gr.top_block.__init__(self) default_nsamples = 10e6 parser = OptionParser(option_class=eng_option) parser.add_option( "-p", "--npipelines", type="intx", default=1, metavar="NPIPES", help="the number of pipelines to create (default=%default)") parser.add_option( "-s", "--nstages", type="intx", default=1, metavar="NSTAGES", help="the number of stages in each pipeline (default=%default)") parser.add_option( "-N", "--nsamples", type="eng_float", default=default_nsamples, help=( "the number of samples to run through the graph (default=%s)" % (eng_notation.num_to_str(default_nsamples)))) parser.add_option("-m", "--machine-readable", action="store_true", default=False, help="enable machine readable output") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 self.npipes = options.npipelines self.nstages = options.nstages self.nsamples = options.nsamples self.machine_readable = options.machine_readable ntaps = 256 # Something vaguely like floating point ops self.flop = 2 * ntaps * options.npipelines * options.nstages * options.nsamples src = gr.null_source(gr.sizeof_float) head = gr.head(gr.sizeof_float, int(options.nsamples)) self.connect(src, head) for n in range(options.npipelines): self.connect(head, pipeline(options.nstages, ntaps))
def test_001_srcsink_ss (self): src = gr.null_source(gr.sizeof_short) spi = gr_spi.spi_srcsink_ss() spi.open_spi("/dev/null",1000000) sink = gr.null_sink(gr.sizeof_short) self.fg.connect(src,0,spi,0) self.fg.connect(spi,sink) self.fg.start() time.sleep(0.5) self.fg.stop() spi.close_spi()
def test_010_validate (self): fg = self.fg src1 = gr.null_source (gr.sizeof_int) nop1 = gr.nop (gr.sizeof_int) dst1 = gr.null_sink (gr.sizeof_int) dst2 = gr.null_sink (gr.sizeof_int) fg.connect ((src1, 0), (nop1, 0)) fg.connect ((src1, 0), (nop1, 1)) fg.connect ((nop1, 0), (dst1, 0)) fg.connect ((nop1, 2), (dst2, 0)) self.assertRaises (ValueError, lambda : fg.validate ())
def ProcessCommand(self, command): # ------------------------------------------------------------------------ print "FileSourceAdapter.ProcessCommand", command if command[0] == "mute": self.mute.set_mute(command[1] == "true") return if command[0] == "filename": if command[1]: self.source = gr.file_source(gr.sizeof_float, command[1], True) else: self.source = gr.null_source(gr.sizeof_float) return print 'FileSourceAdapter.ProcessCommand: Unknown command "%s"' % (command[0])
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) parser = OptionParser (option_class=eng_option) (options, args) = parser.parse_args () sample_rate = 16e6 mpoints = 16 ampl = 1000 enable = mpoints/2 * [1, 0] enable[0] = 1 taps = gr.firdes.low_pass(1, # gain 1, # rate 1.0/mpoints * 0.4, # cutoff 1.0/mpoints * 0.1, # trans width gr.firdes.WIN_HANN) synth = blks2.synthesis_filterbank(mpoints, taps) null_source = gr.null_source(gr.sizeof_gr_complex) if 1: for i in range(mpoints): s = gr.sig_source_c(sample_rate/mpoints, gr.GR_SIN_WAVE, 300e3, ampl * enable[i], 0) self.connect(s, (synth, i)) else: for i in range(mpoints): if i == 1: #s = gr.sig_source_c(sample_rate/mpoints, gr.GR_SIN_WAVE, # 300e3, ampl * enable[i], 0) s = random_noise_c(ampl) self.connect(s, (synth, i)) else: self.connect(null_source, (synth, i)) # We add these throttle blocks so that this demo doesn't # suck down all the CPU available. Normally you wouldn't use these. thr = gr.throttle(gr.sizeof_gr_complex, sample_rate) fft = fftsink2.fft_sink_c(frame, fft_size=1024,sample_rate=sample_rate) vbox.Add(fft.win, 1, wx.EXPAND) self.connect(synth, thr, fft)
def __init__(self, rx_callback, options): gr.top_block.__init__(self) if (options.from_file is not None): sys.stderr.write( ("Reading samples from '%s'.\n\n" % (options.from_file))) self.source = gr.file_source(gr.sizeof_char, options.from_file, options.repeat_file) else: sys.stderr.write( "No source defined, pulling samples from null source.\n\n") self.source = gr.null_source(gr.sizeof_gr_byte) # Set up receive path self.rxpath = receive_path(rx_callback, options) self.unpacker_bb = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) self.connect(self.source, self.unpacker_bb) self.connect(self.unpacker_bb, (self.rxpath, 0)) self.connect(self.unpacker_bb, (self.rxpath, 1))
def __init__(self, app, samp_rate, at, filename, repeat, sine, lc): ''' in: - app = object of type RXApp - samp_rate = sample rate in Hertz - at = attenuation factor - filename = filename - repeat = if True them reads in a loop the file - sine - lc = large carrier ''' gr.hier_block2.__init__(self, "RXData", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) # instance variables self.app = app if sine: self.fileSrc = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, 1000, 1.0) self.addCte = None self.mulitplyCte = None print "i: signal = sine" else: if at == 0.0: self.fileSrc = gr.null_source(gr.sizeof_float*1) self.addCte = None self.mulitplyCte = None print "i: signal = null" else: self.fileSrc = gr.file_source(gr.sizeof_float*1, filename, repeat) self.addCte = gr.add_const_vff((lc, )) self.mulitplyCte = gr.multiply_const_vff((at, )) print "i: signal = " + filename # self.mulitplyCte = gr.multiply_const_vff((at, )) self.f2c = gr.float_to_complex(1) #EO instance variables self.__makeConnections()
def __init__(self, demod, options): gr.top_block.__init__(self, "rx_mpsk") self._demodulator_class = demod # Get demod_kwargs demod_kwargs = self._demodulator_class.extract_kwargs_from_options( options) # demodulator self._demodulator = self._demodulator_class(**demod_kwargs) if (options.rx_freq is not None): symbol_rate = options.bitrate / self._demodulator.bits_per_symbol() self._source = uhd_receiver(options.args, options.bitrate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self._source._sps elif (options.from_file is not None): self._source = gr.file_source(gr.sizeof_gr_complex, options.from_file) else: self._source = gr.null_source(gr.sizeof_gr_complex) # Create the BERT receiver self._receiver = bert_receiver(options.bitrate, self._demodulator._constellation, options.samples_per_symbol, options.differential, options.excess_bw, gray_coded=True, freq_bw=options.freq_bw, timing_bw=options.timing_bw, phase_bw=options.phase_bw, verbose=options.verbose, log=options.log) self.connect(self._source, self._receiver)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.plzr_plzr_0 = plzr.plzr() self.plzr_plzr_0.set_parameters("[1+s 2+3*s+4*s^2 5; 0 1-s s]","[1+3*s 5-s^3 s+1;1+s 1+s+s^2 3*s-1]") self.gr_null_source_0 = gr.null_source(gr.sizeof_float*1) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_float*1) ################################################## # Connections ################################################## self.connect((self.gr_null_source_0, 0), (self.plzr_plzr_0, 0)) self.connect((self.plzr_plzr_0, 0), (self.gr_null_sink_0, 0))
def test_001(self): src_data = [float(x) for x in range(16)] expected_result = tuple(src_data) period = 9177 offset = 0 src = gr.null_source(1) head = gr.head(1, 10000000) ins = blocks.vector_insert_b([1], period, offset) dst = blocks.vector_sink_b() self.tb.connect(src, head, ins, dst) self.tb.run() result_data = dst.data() for i in range(10000): if (i % period == offset): self.assertEqual(1, result_data[i]) else: self.assertEqual(0, result_data[i])
def __init__(self, item_size, num_inputs, num_outputs, input_index, output_index): """ Selector constructor. @param item_size the size of the gr data stream in bytes @param num_inputs the number of inputs (integer) @param num_outputs the number of outputs (integer) @param input_index the index for the source data @param output_index the index for the destination data """ gr.hier_block2.__init__( self, 'selector', gr.io_signature(num_inputs, num_inputs, item_size), gr.io_signature(num_outputs, num_outputs, item_size), ) #terminator blocks for unused inputs and outputs self.input_terminators = [ gr.null_sink(item_size) for i in range(num_inputs) ] self.output_terminators = [ gr.head(item_size, 0) for i in range(num_outputs) ] self.copy = gr.kludge_copy(item_size) #connections for i in range(num_inputs): self.connect((self, i), self.input_terminators[i]) for i in range(num_outputs): self.connect(gr.null_source(item_size), self.output_terminators[i], (self, i)) self.item_size = item_size self.input_index = input_index self.output_index = output_index self.num_inputs = num_inputs self.num_outputs = num_outputs self._connect_current()
import gnuradio from gnuradio import gr from gnuradio import blocks as grblocks import sys if __name__ == '__main__': duration = float(sys.argv[1]) tb = gr.top_block() src0 = gr.null_source(8) src1 = gr.null_source(8) addr01 = grblocks.add_cc() src2 = gr.null_source(8) src3 = gr.null_source(8) addr23 = grblocks.add_cc() mult03 = grblocks.multiply_cc() sink = gr.null_sink(8) tb.connect(src0, (addr01, 0)) tb.connect(src1, (addr01, 1)) tb.connect(src2, (addr23, 0)) tb.connect(src3, (addr23, 1)) tb.connect(addr01, (mult03, 0)) tb.connect(addr23, (mult03, 1)) tb.connect(mult03, sink) import time tb.start()
import gnuradio from gnuradio import gr from gnuradio import blocks as grblocks import sys if __name__ == '__main__': duration = float(sys.argv[1]) tb = gr.top_block() src = gr.null_source(8) b0 = gr.copy(8) b1 = grblocks.sub_cc() b2 = gr.copy(8) b3 = grblocks.divide_cc() b4 = gr.copy(8) sink = gr.null_sink(8) tb.connect(src, b0, b1, b2, b3, b4, sink) import time tb.start() time.sleep(duration) print '##RESULT##', sink.nitems_read(0) / duration import sys sys.stdout.flush() tb.stop() tb.wait()
# Set parameters for receiver, class found in uhd_interface.py self.source = uhd_receiver(options.args, symbol_rate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.source._sps # If transmission sources is a file elif(options.from_file is not None): sys.stderr.write(("Reading samples from '%s'.\n\n" % (options.from_file))) self.source = gr.file_source(gr.sizeof_gr_complex, options.from_file) # Transmission source else: sys.stderr.write("No source defined, pulling samples from null source.\n\n") self.source = gr.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(demodulator, rx_callback, options)# Pass self.connect(self.source, self.rxpath) # ///////////////////////////////////////////////////////////////////////////// # main # ///////////////////////////////////////////////////////////////////////////// global n_rcvd, n_right
def __init__(self, options, payload='', msgq_limit=2, pad_for_usrp=False): """ Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param options: pass modulation options from higher layers (fft length, occupied tones, etc.) @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples """ gr.hier_block2.__init__( self, "ofdm_mod", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._fft_length = 64 self._total_sub_carriers = 53 self._data_subcarriers = 48 self._cp_length = 16 self._regime = options.regime self._symbol_length = self._fft_length + self._cp_length self._role = options.role # assuming we have 100Ms/s going to the USRP2 and 80 samples per symbol # we can calculate the OFDM symboltime (in microseconds) # depending on the interpolation factor self._symbol_time = options.interp * (self._fft_length + self._cp_length) / 100 win = [] if (self._regime == "1" or self._regime == "2"): rotated_const = ofdm_packet_utils.bpsk(self) elif (self._regime == "3" or self._regime == "4"): rotated_const = ofdm_packet_utils.qpsk(self) elif (self._regime == "5" or self._regime == "6"): rotated_const = ofdm_packet_utils.qam16(self) elif (self._regime == "7" or self._regime == "8"): rotated_const = ofdm_packet_utils.qam64(self) # map groups of bits to complex symbols self._pkt_input = ftw.ofdm_mapper(rotated_const, msgq_limit, self._data_subcarriers, self._fft_length) # insert pilot symbols (use pnc block * by lzyou) if self._role == 'A': print " >>> [FPNC]: *A* Insert Pilot" self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 1) elif self._role == 'B': print " >>> [FPNC]: *B* Insert Pilot" self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 2) else: print " >>> [FTW ]: Insert Pilot" self.pilot = ftw.ofdm_pilot_cc(self._data_subcarriers) # just for test #self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 1) #self.pilot = ftw.pnc_ofdm_pilot_cc(self._data_subcarriers, 2) # move subcarriers to their designated place and insert DC self.cmap = ftw.ofdm_cmap_cc(self._fft_length, self._total_sub_carriers) # inverse fast fourier transform self.ifft = gr.fft_vcc(self._fft_length, False, win, False) # add cyclic prefix from gnuradio import digital self.cp_adder = digital.ofdm_cyclic_prefixer(self._fft_length, self._symbol_length) self.connect( gr.null_source(gr.sizeof_char), (self.cp_adder, 1)) # Note: dirty modification to accomdate the API change # scale accordingly self.scale = gr.multiply_const_cc(1.0 / math.sqrt(self._fft_length)) # we need to know the number of OFDM data symbols for preamble and zerogap info = ofdm_packet_utils.get_info(payload, options.regime, self._symbol_time) N_sym = info["N_sym"] # add training sequence (modify by lzyou) if self._role == 'A': print " >>> [FPNC]: *A* Insert Preamble" self.preamble = ofdm_packet_utils.insert_preamble( self._symbol_length, N_sym, 'A') elif self._role == 'B': print " >>> [FPNC]: *B* Insert Preamble" self.preamble = ofdm_packet_utils.insert_preamble( self._symbol_length, N_sym, 'B') else: print " >>> [FTW ]: Insert Preamble" self.preamble = ofdm_packet_utils.insert_preamble( self._symbol_length, N_sym) # append zero samples at the end (receiver needs that to decode) if self._role == None: print " >>> [FTW ]: Insert Zerogap" self.zerogap = ofdm_packet_utils.insert_zerogap( self._symbol_length, N_sym) else: print " >>> [FPNC]: Insert Zerogap" self.zerogap = ofdm_packet_utils.insert_zerogap( self._symbol_length, N_sym, 'FPNC') self.s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._symbol_length) self.v2s = gr.vector_to_stream(gr.sizeof_gr_complex, self._symbol_length) # swap real and immaginary component before sending (GNURadio/USRP2 bug!) if options.swapIQ == True: self.gr_complex_to_imag_0 = gr.complex_to_imag(1) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.connect((self.v2s, 0), (self.gr_complex_to_imag_0, 0)) self.connect((self.v2s, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_complex_to_imag_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self)) elif options.swapIQ == False: self.gr_complex_to_imag_0 = gr.complex_to_imag(1) self.gr_complex_to_real_0 = gr.complex_to_real(1) self.gr_float_to_complex_0 = gr.float_to_complex(1) self.connect((self.v2s, 0), (self.gr_complex_to_imag_0, 0)) self.connect((self.v2s, 0), (self.gr_complex_to_real_0, 0)) self.connect((self.gr_complex_to_imag_0, 0), (self.gr_float_to_complex_0, 1)) self.connect((self.gr_complex_to_real_0, 0), (self.gr_float_to_complex_0, 0)) self.connect((self.gr_float_to_complex_0, 0), (self)) # connect the blocks self.connect((self._pkt_input, 0), (self.pilot, 0)) self.connect((self._pkt_input, 1), (self.preamble, 1)) self.connect((self.preamble, 1), (self.zerogap, 1)) self.connect(self.pilot, self.cmap, self.ifft, self.cp_adder, self.scale, self.s2v, self.preamble, self.zerogap, self.v2s) if options.log: self.connect( (self._pkt_input), gr.file_sink(gr.sizeof_gr_complex * self._data_subcarriers, "ofdm_mapper.dat")) self.connect( self.pilot, gr.file_sink( gr.sizeof_gr_complex * (5 + self._data_subcarriers), "ofdm_pilot.dat")) self.connect( self.cmap, gr.file_sink(gr.sizeof_gr_complex * self._fft_length, "ofdm_cmap.dat")) self.connect( self.ifft, gr.file_sink(gr.sizeof_gr_complex * self._fft_length, "ofdm_ifft.dat")) self.connect( self.cp_adder, gr.file_sink(gr.sizeof_gr_complex, "ofdm_cp_adder.dat")) self.connect(self.scale, gr.file_sink(gr.sizeof_gr_complex, "ofdm_scale.dat")) self.connect( self.preamble, gr.file_sink(gr.sizeof_gr_complex * self._symbol_length, "ofdm_preamble.dat")) self.connect( self.zerogap, gr.file_sink(gr.sizeof_gr_complex * self._symbol_length, "ofdm_zerogap.dat"))
try: import gras import grextras except ImportError: pass import gnuradio from gnuradio import gr import sys if __name__ == '__main__': duration = float(sys.argv[1]) what = sys.argv[2] tb = gr.top_block() src0 = gr.null_source(8) sink = gr.null_sink(8) if what == 'extras_delay': delay_block = grextras.Delay(8) if what == 'core_delay': delay_block = gr.delay(8, 0) delay_block.set_delay(1000) tb.connect(src0, (delay_block, 0)) tb.connect(delay_block, sink) import time tb.start() time.sleep(duration) print '##RESULT##', sink.nitems_read(0) / duration import sys sys.stdout.flush()
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 _setup_dummy(self): self._u = gr.null_source(gr.sizeof_gr_complex)
def __init__(self, parent, ID, title): wxFrame.__init__(self, parent, ID, title, wxDefaultPosition) self.pga = 0 self.pgaMin = -20 self.pgaMax = 0 self.pgaStep = 0.25 # Parsing options parser = OptionParser(option_class=eng_option, usage="usage: %prog [options] filename1" \ " [-f frequency2 filename2 [...]]") parser.add_option("-a", "--agc", action="store_true", help="enable agc") parser.add_option("-c", "--clockrate", type="eng_float", default=128e6, help="set USRP clock rate (128e6)") parser.add_option("--copy", action="store_true", help="enable real to imag data copy when in real mode") parser.add_option("-e", "--encoding", type="choice", choices=["s", "f"], default="f", help="choose data encoding: [s]igned or [f]loat.") parser.add_option("-f", "--frequency", type="eng_float", action="callback", callback=appendFrequency, help="set output frequency (222.064e6)") parser.add_option("-g", "--gain", type="float", help="set output pga gain") parser.add_option("-l", "--list", action="callback", callback=listUsrp, help="list USRPs and daugtherboards") parser.add_option("-m", "--mode", type="eng_float", default=2, help="mode: 1: real, 2: complex (2)") parser.add_option("-o", "--osc", action="store_true", help="enable oscilloscope") parser.add_option("-r", "--samplingrate", type="eng_float", default=3.2e6, help="set input sampling rate (3200000)") parser.add_option("-s", "--spectrum", action="store_true", help="enable spectrum analyzer") # parser.add_option("-t", "--tx", type="choice", choices=["A", "B"], # default="A", help="choose USRP tx A|B output (A)") parser.add_option("-u", "--usrp", action="store_true", help="enable USRP output") (options, args) = parser.parse_args() if len(args) == 0 : options.filename = [ "/dev/stdin" ] else : options.filename = args # Setting default frequency if options.frequency is None : options.frequency = [ 222.064e6 ] if len(options.filename) != len(options.frequency) : parser.error("Nb input file != nb frequency!") # Status bar # self.CreateStatusBar(3, 0) # msg = "PGA: %.2f dB" % (self.pga * self.pgaStep) # self.SetStatusText(msg, 1) # msg = "Freq: %.3f mHz" % (options.frequency[0] / 1000000.0) # self.SetStatusText(msg, 2) # Menu bar menu = wxMenu() menu.Append(ID_ABOUT, "&About", "More information about this program") menu.AppendSeparator() menu.Append(ID_EXIT, "E&xit", "Terminate the program") menuBar = wxMenuBar() menuBar.Append(menu, "&File") self.SetMenuBar(menuBar) # Main windows mainSizer = wxFlexGridSizer(0, 1) sliderSizer = wxFlexGridSizer(0, 2) buttonSizer = wxBoxSizer(wxHORIZONTAL) if options.usrp : # TX d'board 0 gainLabel = wxStaticText(self, -1, "PGA 0") gainSlider = wxSlider(self, ID_GAIN_SLIDER0, self.pga, self.pgaMin / self.pgaStep, self.pgaMax / self.pgaStep, style = wxSL_HORIZONTAL | wxSL_AUTOTICKS) gainSlider.SetSize((400, -1)) sliderSizer.Add(gainLabel, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) sliderSizer.Add(gainSlider, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) freqLabel = wxStaticText(self, -1, "Frequency 0") freqSlider = wxSlider(self, ID_FREQ_SLIDER0, options.frequency[0] / 16000, 0, 20e3, style = wxSL_HORIZONTAL | wxSL_AUTOTICKS) freqSlider.SetSize((400, -1)) sliderSizer.Add(freqLabel, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) sliderSizer.Add(freqSlider, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) if len(options.frequency) > 1 : # TX d'board 1 gainLabel = wxStaticText(self, -1, "PGA 1") gainSlider = wxSlider(self, ID_GAIN_SLIDER1, self.pga, self.pgaMin / self.pgaStep, self.pgaMax / self.pgaStep, style = wxSL_HORIZONTAL | wxSL_AUTOTICKS) gainSlider.SetSize((400, -1)) sliderSizer.Add(gainLabel, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) sliderSizer.Add(gainSlider, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) freqLabel = wxStaticText(self, -1, "Frequency 1") freqSlider = wxSlider(self, ID_FREQ_SLIDER1, options.frequency[1] / 16000, 0, 20e3, style = wxSL_HORIZONTAL | wxSL_AUTOTICKS) freqSlider.SetSize((400, -1)) sliderSizer.Add(freqLabel, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) sliderSizer.Add(freqSlider, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0) mainSizer.Add(sliderSizer, 1, wxEXPAND, 0) start = wxButton(self, ID_START, "Start") stop = wxButton(self, ID_STOP, "Stop") buttonSizer.Add(start, 1, wxALIGN_CENTER, 0) buttonSizer.Add(stop, 1, wxALIGN_CENTER, 0) mainSizer.Add(buttonSizer, 1, wxEXPAND, 0) # GnuRadio self.fg = gr.flow_graph() if options.mode == 1 : print "Source: real" if (options.encoding == "s") : print "Source encoding: short" src = gr.file_source(gr.sizeof_short, options.filename[0], 1) if (options.copy) : print "Imag: copy" imag = src else : print "Imag: null" imag = gr.null_source(gr.sizeof_short) interleaver = gr.interleave(gr.sizeof_short) self.fg.connect(src, (interleaver, 0)) self.fg.connect(imag, (interleaver, 1)) tail = interleaver elif (options.encoding == "f") : print "Source encoding: float" src = gr.file_source(gr.sizeof_gr_complex, options.filename[0], 1) tail = src elif (options.mode == 2) : print "Source: complex" if len(options.frequency) == 1 : if (options.encoding == "s") : print "Source encoding: short" src = gr.file_source(gr.sizeof_short, options.filename[0], 1) elif (options.encoding == "f") : print "Source encoding: float" src = gr.file_source(gr.sizeof_gr_complex, options.filename[0], 1) else : parser.error("Invalid encoding type for complex data!") tail = src elif (len(options.frequency) == 2) : src0 = gr.file_source(gr.sizeof_gr_complex, options.filename[0], 1) src1 = gr.file_source(gr.sizeof_gr_complex, options.filename[1], 1) interleaver = gr.interleave(gr.sizeof_gr_complex) self.fg.connect(src0, (interleaver, 0)) self.fg.connect(src1, (interleaver, 1)) tail = interleaver else : parser.error( "Invalid number of source (> 2) with complex input!") else : parser.error("Invalid mode!") # Interpolation dac_freq = options.clockrate interp = int(dac_freq / options.samplingrate) if interp == 0 : parser.error("Invalid sampling rate!") if options.mode == 2 : print "Input sampling rate: %s complex samples/s" % \ num_to_str(options.samplingrate) else : print "Input sampling rate: %s samples/s" % \ num_to_str(options.samplingrate) print "Interpolation rate: int(%s / %s) = %sx" % \ (num_to_str(dac_freq), num_to_str(options.samplingrate), interp) if interp > 512 : factor = gcd(dac_freq / 512, options.samplingrate) num = int((dac_freq / 512) / factor) den = int(options.samplingrate / factor) print "Resampling by %i / %i" % (num, den) resampler = blks.rational_resampler_ccc(self.fg, num, den) self.fg.connect(tail, resampler) tail = resampler interp = 512 options.samplingrate = dac_freq / 512 # AGC if options.agc : agc = gr.agc_cc() self.fg.connect(tail, agc) tail = agc # USRP if options.usrp : nchan = len(options.frequency) if len(options.frequency) == 1 : if options.mode == 1 : mux = 0x00000098 elif options.mode == 2 : mux = 0x00000098 else : parser.error("Unsupported mode for USRP mux!") elif len(options.frequency) == 2 : if options.mode == 1 : mux = 0x0000ba98 elif options.mode == 2 : mux = 0x0000ba98 else : parser.error("Unsupported mode for USRP mux!") else : parser.error("Invalid number of frequency [0..2]!") # if options.tx == "A" : # mux = 0x00000098 # else : # mux = 0x00009800 print "Nb channels: ", nchan print "Mux: 0x%x" % mux if options.encoding == 's' : dst = usrp.sink_s(0, interp, nchan, mux) elif options.encoding == 'f' : dst = usrp.sink_c(0, interp, nchan, mux) else : parser.error("Unsupported data encoding for USRP!") dst.set_verbose(1) for i in range(len(options.frequency)) : if options.gain is None : print "Setting gain to %f" % dst.pga_max() dst.set_pga(i << 1, dst.pga_max()) else : print "Setting gain to %f" % options.gain dst.set_pga(i << 1, options.gain) tune = false for dboard in dst.db: if (dboard[0].dbid() != -1): device = dboard[0] print "Tuning TX d'board %s to %sHz" % \ (device.side_and_name(), num_to_str(options.frequency[i])) device.lo_offset = 38e6 (min, max, offset) = device.freq_range() print " Frequency" print " Min: %sHz" % num_to_str(min) print " Max: %sHz" % num_to_str(max) print " Offset: %sHz" % num_to_str(offset) #device.set_gain(device.gain_range()[1]) device.set_enable(True) tune = \ dst.tune(device._which, device, options.frequency[i] * 128e6 / dac_freq) if tune: print " Baseband frequency: %sHz" % \ num_to_str(tune.baseband_freq) print " DXC frequency: %sHz" % \ num_to_str(tune.dxc_freq) print " Residual Freqency: %sHz" % \ num_to_str(tune.residual_freq) print " Inverted: ", \ tune.inverted mux = usrp.determine_tx_mux_value(dst, (device._which, 0)) dst.set_mux(mux) break else: print " Failed!" if not tune: print " Failed!" raise SystemExit # int nunderruns () print "USRP" print " Rx halfband: ", dst.has_rx_halfband() print " Tx halfband: ", dst.has_tx_halfband() print " Nb DDC: ", dst.nddc() print " Nb DUC: ", dst.nduc() #dst._write_9862(0, 14, 224) print " DAC frequency: %s samples/s" % num_to_str(dst.dac_freq()) print " Fpga decimation rate: %s -> %s samples/s" % \ (num_to_str(dst.interp_rate()), num_to_str(dac_freq / dst.interp_rate())) print " Nb channels:", if hasattr(dst, "nchannels()") : print dst.nchannels() else: print "N/A" print " Mux:", if hasattr(dst, "mux()") : print "0x%x" % dst.mux() else : print "N/A" print " FPGA master clock frequency:", if hasattr(dst, "fpga_master_clock_freq()") : print "%sHz" % num_to_str(dst.fpga_master_clock_freq()) else : print "N/A" print " Converter rate:", if hasattr(dst, "converter_rate()") : print "%s" % num_to_str(dst.converter_rate()) else : print "N/A" print " DAC rate:", if hasattr(dst, "dac_rate()") : print "%s sample/s" % num_to_str(dst.dac_rate()) else : print "N/A" print " Interp rate: %sx" % num_to_str(dst.interp_rate()) print " DUC frequency 0: %sHz" % num_to_str(dst.tx_freq(0)) print " DUC frequency 1: %sHz" % num_to_str(dst.tx_freq(1)) print " Programmable Gain Amplifier 0: %s dB" % \ num_to_str(dst.pga(0)) print " Programmable Gain Amplifier 1: %s dB" % \ num_to_str(dst.pga(2)) else : dst = gr.null_sink(gr.sizeof_gr_complex) # AGC if options.agc : agc = gr.agc_cc() self.fg.connect(tail, agc) tail = agc self.fg.connect(tail, dst) # oscilloscope if options.osc : oscPanel = wxPanel(self, -1) if (options.encoding == "s") : converter = gr.interleaved_short_to_complex() self.fg.connect(tail, converter) signal = converter elif (options.encoding == "f") : signal = tail else : parser.error("Unsupported data encoding for oscilloscope!") #block = scope_sink_f(fg, parent, title=label, sample_rate=input_rate) #return (block, block.win) oscWin = scopesink.scope_sink_c(self.fg, oscPanel, "Signal", options.samplingrate) self.fg.connect(signal, oscWin) mainSizer.Add(oscPanel, 1, wxEXPAND) # spectrometer if options.spectrum : ymin = 0 ymax = 160 fftPanel = wxPanel(self, -1) if (options.encoding == "s") : converter = gr.interleaved_short_to_complex() self.fg.connect(tail, converter) signal = converter elif (options.encoding == "f") : signal = tail else : parser.error("Unsupported data encoding for oscilloscope!") fftWin = fftsink.fft_sink_c(self.fg, fftPanel, title="Spectrum", fft_size=2048, sample_rate=options.samplingrate, y_per_div=(ymax - ymin) / 8, ref_level=ymax, fft_rate=50, average=True ) self.fg.connect(signal, fftWin) mainSizer.Add(fftPanel, 1, wxEXPAND) # Events EVT_MENU(self, ID_ABOUT, self.OnAbout) EVT_MENU(self, ID_EXIT, self.TimeToQuit) EVT_SLIDER(self, ID_GAIN_SLIDER0, self.slideEvent) EVT_SLIDER(self, ID_FREQ_SLIDER0, self.slideEvent) EVT_SLIDER(self, ID_GAIN_SLIDER1, self.slideEvent) EVT_SLIDER(self, ID_FREQ_SLIDER1, self.slideEvent) EVT_BUTTON(self, ID_START, self.onClick) EVT_BUTTON(self, ID_STOP, self.onClick) #Layout sizers self.SetSizer(mainSizer) self.SetAutoLayout(1) mainSizer.Fit(self) self.fg.start()
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 __init__(self, freq_corr=0, avg_frames=1, decim=16, N_id_2=0, N_id_1=134): grc_wxgui.top_block_gui.__init__(self, title="Sss Corr5 Gui") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq_corr = freq_corr self.avg_frames = avg_frames self.decim = decim self.N_id_2 = N_id_2 self.N_id_1 = N_id_1 ################################################## # Variables ################################################## self.vec_half_frame = vec_half_frame = 30720 * 5 / decim self.symbol_start = symbol_start = 144 / decim self.slot_0_10 = slot_0_10 = 1 self.samp_rate = samp_rate = 30720e3 / decim self.rot = rot = 0 self.noise_level = noise_level = 0 self.fft_size = fft_size = 2048 / decim self.N_re = N_re = 62 ################################################## # Blocks ################################################## _rot_sizer = wx.BoxSizer(wx.VERTICAL) self._rot_text_box = forms.text_box( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, label='rot', converter=forms.float_converter(), proportion=0, ) self._rot_slider = forms.slider( parent=self.GetWin(), sizer=_rot_sizer, value=self.rot, callback=self.set_rot, minimum=0, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rot_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS ML") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS equ") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS in") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS equ") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS ch est") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "foo") self.Add(self.notebook_0) _noise_level_sizer = wx.BoxSizer(wx.VERTICAL) self._noise_level_text_box = forms.text_box( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, label='noise_level', converter=forms.float_converter(), proportion=0, ) self._noise_level_slider = forms.slider( parent=self.GetWin(), sizer=_noise_level_sizer, value=self.noise_level, callback=self.set_noise_level, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_noise_level_sizer) self.wxgui_scopesink2_0_1_0_1 = scopesink2.scope_sink_c( self.notebook_0.GetPage(3).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0_1_0_1.win) self.wxgui_scopesink2_0_1_0_0 = scopesink2.scope_sink_c( self.notebook_0.GetPage(2).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_0_1_0_0.win) self.wxgui_scopesink2_0_1_0 = scopesink2.scope_sink_c( self.notebook_0.GetPage(1).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0_1_0.win) self.wxgui_scopesink2_0_1 = scopesink2.scope_sink_f( self.notebook_0.GetPage(0).GetWin(), title="Scope Plot", sample_rate=100 / avg_frames, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.notebook_0.GetPage(0).Add(self.wxgui_scopesink2_0_1.win) _symbol_start_sizer = wx.BoxSizer(wx.VERTICAL) self._symbol_start_text_box = forms.text_box( parent=self.GetWin(), sizer=_symbol_start_sizer, value=self.symbol_start, callback=self.set_symbol_start, label='symbol_start', converter=forms.int_converter(), proportion=0, ) self._symbol_start_slider = forms.slider( parent=self.GetWin(), sizer=_symbol_start_sizer, value=self.symbol_start, callback=self.set_symbol_start, minimum=0, maximum=144 / decim, num_steps=144 / decim, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.Add(_symbol_start_sizer) self.sss_ml_fd_0 = sss_ml_fd( decim=decim, avg_frames=avg_frames, N_id_1=N_id_1, N_id_2=N_id_2, slot_0_10=slot_0_10, ) self.pss_chan_est2_0 = pss_chan_est2(N_id_2=N_id_2, ) self.gr_vector_to_stream_0_0_1_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0_1 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, N_re) self.gr_vector_to_stream_0 = gr.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.gr_vector_source_x_0_0_0 = gr.vector_source_c( (gen_pss_fd(N_id_2, N_re, False).get_data()), True, N_re) self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate) self.gr_stream_to_vector_0_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, N_re) self.gr_stream_to_vector_0 = gr.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.gr_stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex * 1, (N_re / 2, N_re / 2)) self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex * 1) self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0) self.gr_multiply_xx_1_0 = gr.multiply_vcc(N_re) self.gr_multiply_xx_1 = gr.multiply_vcc(N_re) self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc( (0.005 * exp(rot * 2 * numpy.pi * 1j), )) self.gr_keep_m_in_n_0_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re / 2, fft_size, (fft_size - N_re) / 2 - 1) self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re / 2, fft_size, (fft_size) / 2) self.gr_file_source_0 = gr.file_source( gr.sizeof_gr_complex * 1, "/home/user/git/gr-lte/gr-lte/test/octave/foo_sss_td_in.cfile", True) self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1) self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * N_re) self.gr_channel_model_0 = gr.channel_model( noise_voltage=0.005 * noise_level, frequency_offset=0.0, epsilon=1, taps=(0.005 * exp(rot * 2 * numpy.pi * 1j), ), noise_seed=0, ) self.gr_add_xx_0 = gr.add_vcc(1) self.blks2_selector_0_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex * 1, num_inputs=2, num_outputs=1, input_index=0, output_index=0, ) self.blks2_selector_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex * 1, num_inputs=3, num_outputs=2, input_index=0, output_index=0, ) ################################################## # Connections ################################################## self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.blks2_selector_0, 0), (self.gr_channel_model_0, 0)) self.connect((self.blks2_selector_0, 1), (self.gr_add_xx_0, 0)) self.connect((self.gr_channel_model_0, 0), (self.blks2_selector_0_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_selector_0_0, 1)) self.connect((self.gr_file_source_0, 0), (self.blks2_selector_0, 0)) self.connect((self.blks2_selector_0_0, 0), (self.gr_throttle_0, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_vector_to_stream_0_0_0, 0)) self.connect((self.gr_vector_to_stream_0_0_0, 0), (self.wxgui_scopesink2_0_1_0_0, 0)) self.connect((self.gr_vector_to_stream_0_0, 0), (self.wxgui_scopesink2_0_1_0, 0)) self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0, 0)) self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_deinterleave_0, 0)) self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0)) self.connect((self.gr_vector_to_stream_0_0_1, 0), (self.wxgui_scopesink2_0_1_0_1, 0)) self.connect((self.gr_vector_to_stream_0_0_1_0, 0), (self.wxgui_scopesink2_0_1_0_1, 1)) self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_0_1_0, 0)) self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.sss_ml_fd_0, 0)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_vector_to_stream_0_0, 0)) self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1_0, 0)) self.connect((self.gr_deinterleave_0, 1), (self.gr_multiply_xx_1_0, 1)) self.connect((self.gr_multiply_xx_1_0, 0), (self.gr_vector_to_stream_0_0_1, 0)) self.connect((self.gr_deinterleave_0, 1), (self.pss_chan_est2_0, 0)) self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0_0, 0)) self.connect((self.gr_keep_m_in_n_0_0, 0), (self.gr_stream_mux_0, 0)) self.connect((self.gr_keep_m_in_n_0, 0), (self.gr_stream_mux_0, 1)) self.connect((self.gr_stream_mux_0, 0), (self.gr_stream_to_vector_0_0, 0)) self.connect((self.gr_throttle_0, 0), (self.gr_stream_to_vector_0, 0)) self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 1)) self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 2)) self.connect((self.sss_ml_fd_0, 0), (self.wxgui_scopesink2_0_1, 0)) self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_1, 0))