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_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_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 xInit(self, signals, noises, sinks): # ------------------------------------------------------------------------ self.sources = {} self.mutes = {} self.amps = {} #sources for signal in signals: self.sources[signal] = gr.sig_source_f( self.samprate, gr.GR_SIN_WAVE, 440, 0.25, 0) self.mutes[signal] = gr.mute_ff(True) self.amps[signal] = gr.multiply_const_ff(0.25) for noise in noises: self.sources[noise] = analog.noise_source_f( analog.GR_LAPLACIAN, 1, 0) self.mutes[noise] = gr.mute_ff(True) self.amps[noise] = gr.multiply_const_ff(0.25) #mixer if len(self.sources) > 1: self.adder = self.add = gr.add_vff(1) else: self.adder = gr.multiply_const_vff((1, )) self.level = gr.multiply_const_ff(1) #sinks self.sinks = sinks self.audiomute = gr.mute_ff(True) self.audio = audio.sink(self.samprate, "", True) self.udp = gr.null_sink(gr.sizeof_float) self.rawfile = gr.null_sink(gr.sizeof_float) self.wavefile = gr.null_sink(gr.sizeof_float)
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 StopAllSinks(self): # ------------------------------------------------------------------------ self.audiomute.set_mute(True) self.Stop() self.udp = gr.null_sink(gr.sizeof_float) self.rawfile = gr.null_sink(gr.sizeof_float) self.wavefile = gr.null_sink(gr.sizeof_float) self.Start()
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 xSetEnable(self, sender, state): # ------------------------------------------------------------------------ if sender == "Audio Out": self.audiomute.set_mute(not state) if sender == "UDP Out": host = self.udpconfig["host"] port = self.udpconfig["port"] self.Stop() if state == False or not host or not port: self.udp = gr.null_sink(gr.sizeof_float) wx.GetApp().PostStatus( "SignalGenerator Info: Stopped UDP output to \"%s:%s\"" % ( host, port)) else: self.udp = gr.udp_sink(gr.sizeof_float, host, port, 1472, True) wx.GetApp().PostStatus( "SignalGenerator Info: Started UDP output to \"%s:%s\"" % ( host, port)) self.Start() if sender == "File Out": filename = self.fileconfig["filename"] self.Stop() if state == False or not filename: self.rawfile = gr.null_sink(gr.sizeof_float) wx.GetApp().PostStatus( "SignalGenerator Info: Stopped rawfile device \"%s\"" % ( filename,)) else: self.rawfile = gr.file_sink(gr.sizeof_float, filename) wx.GetApp().PostStatus( "SignalGenerator Info: Started rawfile device \"%s\"" % ( filename,)) self.Start() if sender == "Wave Out": filename = self.waveconfig["filename"] self.Stop() if state == False or not filename: self.wavefile = gr.null_sink(gr.sizeof_float) wx.GetApp().PostStatus( "SignalGenerator Info: Stopped wave device \"%s\"" % ( filename,)) else: self.wavefile = gr.wavfile_sink(filename, 1, self.samprate, 16) wx.GetApp().PostStatus( "SignalGenerator Info: Started wave device \"%s\"" % ( filename,)) self.Start()
def test01(self): sps = 4 rolloff = 0.35 bw = 2 * math.pi / 100.0 ntaps = 45 # Create pulse shape filter #rrc_taps = gr.firdes.root_raised_cosine( # sps, sps, 1.0, rolloff, ntaps) rrc_taps = taps # The frequency offset to correct foffset = 0.2 / (2.0 * math.pi) # Create a set of 1's and -1's, pulse shape and interpolate to sps random.seed(0) data = [2.0 * random.randint(0, 2) - 1.0 for i in xrange(200)] self.src = gr.vector_source_c(data, False) self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps) # Mix symbols with a complex sinusoid to spin them self.nco = gr.sig_source_c(1, gr.GR_SIN_WAVE, foffset, 1) self.mix = gr.multiply_cc() # FLL will despin the symbols to an arbitrary phase self.fll = digital_swig.fll_band_edge_cc(sps, rolloff, ntaps, bw) # Create sinks for all outputs of the FLL # we will only care about the freq and error outputs self.vsnk_frq = gr.vector_sink_f() self.nsnk_fll = gr.null_sink(gr.sizeof_gr_complex) self.nsnk_phs = gr.null_sink(gr.sizeof_float) self.nsnk_err = gr.null_sink(gr.sizeof_float) # Connect the blocks self.tb.connect(self.nco, (self.mix, 1)) self.tb.connect(self.src, self.rrc, (self.mix, 0)) self.tb.connect(self.mix, self.fll, self.nsnk_fll) self.tb.connect((self.fll, 1), self.vsnk_frq) self.tb.connect((self.fll, 2), self.nsnk_phs) self.tb.connect((self.fll, 3), self.nsnk_err) self.tb.run() N = 700 dst_data = self.vsnk_frq.data()[N:] expected_result = len(dst_data) * [ -0.20, ] self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 4)
def test01 (self): sps = 4 rolloff = 0.35 bw = 2*math.pi/100.0 ntaps = 45 # Create pulse shape filter #rrc_taps = gr.firdes.root_raised_cosine( # sps, sps, 1.0, rolloff, ntaps) rrc_taps = taps # The frequency offset to correct foffset = 0.2 / (2.0*math.pi) # Create a set of 1's and -1's, pulse shape and interpolate to sps random.seed(0) data = [2.0*random.randint(0, 2) - 1.0 for i in xrange(200)] self.src = gr.vector_source_c(data, False) self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps) # Mix symbols with a complex sinusoid to spin them self.nco = gr.sig_source_c(1, gr.GR_SIN_WAVE, foffset, 1) self.mix = gr.multiply_cc() # FLL will despin the symbols to an arbitrary phase self.fll = digital_swig.fll_band_edge_cc(sps, rolloff, ntaps, bw) # Create sinks for all outputs of the FLL # we will only care about the freq and error outputs self.vsnk_frq = gr.vector_sink_f() self.nsnk_fll = gr.null_sink(gr.sizeof_gr_complex) self.nsnk_phs = gr.null_sink(gr.sizeof_float) self.nsnk_err = gr.null_sink(gr.sizeof_float) # Connect the blocks self.tb.connect(self.nco, (self.mix,1)) self.tb.connect(self.src, self.rrc, (self.mix,0)) self.tb.connect(self.mix, self.fll, self.nsnk_fll) self.tb.connect((self.fll,1), self.vsnk_frq) self.tb.connect((self.fll,2), self.nsnk_phs) self.tb.connect((self.fll,3), self.nsnk_err) self.tb.run() N = 700 dst_data = self.vsnk_frq.data()[N:] expected_result = len(dst_data)* [-0.20,] self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4)
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 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_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, modulator_class, options): gr.top_block.__init__(self) self.txpath = transmit_path(modulator_class, options) self.audio_rx = audio_rx(options.audio_input) if options.tx_freq is not None: self.sink = uhd_transmitter( options.address, options.bitrate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.antenna, options.verbose, ) options.samples_per_symbol = self.sink._sps audio_rate = self.audio_rx.sample_rate usrp_rate = self.sink.get_sample_rate() rrate = usrp_rate / audio_rate elif options.to_file is not None: self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) rrate = 1 else: self.sink = gr.null_sink(gr.sizeof_gr_complex) rrate = 1 self.resampler = filter.pfb.arb_resampler_ccf(rrate) self.connect(self.audio_rx) self.connect(self.txpath, self.resampler, self.sink)
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, mod, options): gr.top_block.__init__(self, "tx_mpsk") self._modulator_class = mod # Get mod_kwargs mod_kwargs = self._modulator_class.extract_kwargs_from_options(options) # transmitter self._modulator = self._modulator_class(**mod_kwargs) if (options.tx_freq is not None): symbol_rate = options.bitrate / self._modulator.bits_per_symbol() self._sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self._sink._sps 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._transmitter = bert_transmit(self._modulator._constellation, options.samples_per_symbol, options.differential, options.excess_bw, gray_coded=True, verbose=options.verbose, log=options.log) self.amp = gr.multiply_const_cc(options.amplitude) self.connect(self._transmitter, self.amp, self._sink)
def __init__(self, modulator_class, options): gr.top_block.__init__(self) self.txpath = transmit_path(modulator_class, options) self.audio_rx = audio_rx(options.audio_input) if (options.tx_freq is not None): self.sink = uhd_transmitter(options.address, options.bitrate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.antenna, options.verbose) options.samples_per_symbol = self.sink._sps audio_rate = self.audio_rx.sample_rate usrp_rate = self.sink.get_sample_rate() rrate = usrp_rate / audio_rate elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) rrate = 1 else: self.sink = gr.null_sink(gr.sizeof_gr_complex) rrate = 1 self.resampler = blks2.pfb_arb_resampler_ccf(rrate) self.connect(self.audio_rx) self.connect(self.txpath, self.resampler, self.sink)
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 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 __init__(self, packet_sink=None): #we want outputs of different types # NOTE: The output signature depends on the number of the subcarriers signature_sizes = [self._item_size_out, gr.sizeof_gr_complex * packet_sink._occupied_tones] #initialize hier2 gr.hier_block2.__init__( self, "ofdm_demod", gr.io_signature(1, 1, packet_sink._hb.input_signature().sizeof_stream_item(0)), # Input signature gr.io_signaturev(2, 2, signature_sizes) # Output signature ) #create blocks msg_source = gr.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) self._msgq_out = msg_source.msgq() #connect self.connect(self, packet_sink) self.connect(msg_source, self) # For the vector analyzer connection self.connect((packet_sink, 1), (self, 1)) if packet_sink._hb.output_signature().sizeof_stream_item(0): self.connect(packet_sink, gr.null_sink(packet_sink._hb.output_signature().sizeof_stream_item(0)))
def test_100(self): vlen = 256 cp_len = 12 M = 10 N = int(3e6) uut = ofdm.frequency_shift_vcc( vlen, 1.0/vlen, cp_len ) trig = [0]*M trig[0] = 1 eps = [1.]*M src1 = gr.vector_source_c( [1.]*(M*vlen), True, vlen ) src2 = gr.vector_source_f( eps, True ) src3 = gr.vector_source_b( trig, True ) dst = gr.null_sink( gr.sizeof_gr_complex * vlen ) limit3 = gr.head( gr.sizeof_char, N ) self.fg.connect( src1, ( uut, 0 ) ) self.fg.connect( src2, ( uut, 1 ) ) self.fg.connect( src3, limit3, ( uut, 2 ) ) self.fg.connect( uut, dst ) r = time_it( self.fg ) print "Rate %s" % \ ( eng_notation.num_to_str( float( ( vlen + cp_len ) * N ) / r ) )
def test_101(self): vlen = 256 N = int(5e5) soff = 1.0 taps = [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j] freqoff = 0.0 norm_freq = freqoff / vlen rms_amplitude = 8000 snr_db = 10 snr = 10.0**(snr_db / 10.0) noise_sigma = sqrt(rms_amplitude**2 / snr) data = [1 + 1j] * vlen #data2 = [2] * vlen src = gr.vector_source_c(data, True, vlen) v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen) channel = gr.channel_model(noise_sigma, norm_freq, soff, taps) dst = gr.null_sink(gr.sizeof_gr_complex) limit = gr.head(gr.sizeof_gr_complex * vlen, N) self.tb.connect(src, limit, v2s, channel, dst) r = time_it(self.tb) print "Rate: %s Samples/second" \ % eng_notation.num_to_str( float(N) * vlen / r )
def test_002(self): vlen = 256 subc = 208 L = 8 cplen = 12 blocklen = vlen + cplen framelength = 11 bits_per_subc = [2] * vlen data_blocks = 10 N = int(1e9) # GI metric pre0, fd = morellimengali_designer.create(subc, vlen, L) ofdm_frames = \ ofdm_frame_src( vlen, data_blocks, pre0, cplen, framelength, bits_per_subc ) #uut = ofdm.autocorrelator0( vlen, cplen ) uut = autocorrelator(vlen, cplen) limit_stream = gr.head(gr.sizeof_float, N) self.tb.connect(ofdm_frames, uut, limit_stream, gr.null_sink(gr.sizeof_float)) # log_to_file( self.tb, limit_stream, "data/cyclicprefix_autocorr.float" ) r = time_it(self.tb) print "Expected throughput: %s Samples/s" % (eng_notation.num_to_str( float(N) / r))
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, Np=32, P=128, L=2, filename=None, sample_type='complex', verbose=True): gr.top_block.__init__(self) if filename is None: src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) if verbose: print "Using Gaussian noise source." else: if sample_type == 'complex': src = gr.file_source(gr.sizeof_gr_complex, filename, True) else: fsrc = gr.file_source(gr.sizeof_float, filename, True) src = gr.float_to_complex() self.connect(fsrc, src) if verbose: print "Reading data from %s" % filename if verbose: print "FAM configuration:" print "N' = %d" % Np print "P = %d" % P print "L = %d" % L #print "Δf = %f" % asfd sink = gr.null_sink(gr.sizeof_float * 2 * Np) self.cyclo_fam = specest.cyclo_fam(Np, P, L) self.connect(src, self.cyclo_fam, sink)
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 test_100(self): vlen = 256 cp_len = 12 M = 10 N = int(3e6) uut = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen, cp_len) trig = [0] * M trig[0] = 1 eps = [1.] * M src1 = gr.vector_source_c([1.] * (M * vlen), True, vlen) src2 = gr.vector_source_f(eps, True) src3 = gr.vector_source_b(trig, True) dst = gr.null_sink(gr.sizeof_gr_complex * vlen) limit3 = gr.head(gr.sizeof_char, N) self.fg.connect(src1, (uut, 0)) self.fg.connect(src2, (uut, 1)) self.fg.connect(src3, limit3, (uut, 2)) self.fg.connect(uut, dst) r = time_it(self.fg) print "Rate %s" % \ ( eng_notation.num_to_str( float( ( vlen + cp_len ) * N ) / r ) )
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 __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 __init__(self, tx, zc, reader, rx, matched_filter, reader_monitor_cmd_gate, cr, tag_monitor, amplitude): gr.top_block.__init__(self) # ASK/PSK demodulators to_mag_L = gr.complex_to_mag() to_mag_R = gr.complex_to_mag() # Others blocks for Buettner's reader samp_freq = (64 / dec_rate) * 1e6 num_taps = int(64000 / (dec_rate * up_link_freq * 4)) taps = [complex(1, 1)] * num_taps filt = gr.fir_filter_ccc(sw_dec, taps) # Matched filter amp = gr.multiply_const_cc(amplitude) c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR) # Null sink for terminating the Listener graph null_sink = gr.null_sink(gr.sizeof_float * 1) # Deinterleaver to separate FPGA channels di = gr.deinterleave(gr.sizeof_gr_complex) # Enable real-time scheduling r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" # Create flow-graph self.connect(rx, di) self.connect((di, 0), filt, to_mag_R, c_gate, zc, reader, amp, tx) self.connect((di, 1), matched_filter, to_mag_L, reader_monitor_cmd_gate, cr, tag_monitor, null_sink)
def test_101(self): vlen = 256 N = int( 5e5 ) soff=1.0 taps = [1.0,0.0,2e-1+0.1j,1e-4-0.04j] freqoff = 0.0 norm_freq = freqoff / vlen rms_amplitude = 8000 snr_db = 10 snr = 10.0**(snr_db/10.0) noise_sigma = sqrt( rms_amplitude**2 / snr) data = [1 + 1j] * vlen #data2 = [2] * vlen src = gr.vector_source_c( data, True, vlen ) v2s = gr.vector_to_stream(gr.sizeof_gr_complex,vlen) channel = gr.channel_model(noise_sigma,norm_freq,soff,taps) dst = gr.null_sink( gr.sizeof_gr_complex ) limit = gr.head( gr.sizeof_gr_complex * vlen, N ) self.tb.connect( src, limit, v2s, channel, dst ) r = time_it( self.tb ) print "Rate: %s Samples/second" \ % eng_notation.num_to_str( float(N) * vlen / r )
def __init__(self, rx, reader, tx): gr.top_block.__init__(self) samp_freq = (64 / dec_rate) * 1e6 amplitude = 33000 num_taps = int( 64000 / (dec_rate * up_link_freq * 2)) #Matched filter for 1/2 cycle taps = [complex(1, 1)] * num_taps print num_taps filt = gr.fir_filter_ccc(sw_dec, taps) to_mag = gr.complex_to_mag() amp = gr.multiply_const_cc(amplitude) c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR) zc = rfid.clock_recovery_zc_ff(samples_per_pulse, 2) dummy = gr.null_sink(gr.sizeof_float) to_complex = gr.float_to_complex() r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" self.connect(rx, filt, to_mag, c_gate, zc, reader, amp, tx)
def __init__(self, options): ''' See below for what options should hold ''' gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(1,1,gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_gr_complex)) options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose # turn verbose mode on/off self._tx_amplitude = options.tx_amplitude # digital amp sent to radio self.packet_tx = ofdm_mod(options, msgq_limit=4, pad_for_usrp=False) self.amp = gr.multiply_const_cc(1) self.set_tx_amplitude(self._tx_amplitude) self.null_sink = gr.null_sink(gr.sizeof_char) self.coding_block_length = options.block_length # Display some information about the setup if self._verbose: self._print_verbage() # Create and setup transmit path flow graph self.connect(self.packet_tx, self.amp, self) # connect hier block input to null when not using streaming inputs self.connect(self,self.null_sink)
def __init__(self, packet_sink=None): #initialize hier2 gr.hier_block2.__init__( self, "ofdm_mod", gr.io_signature( 1, 1, packet_sink._hb.input_signature().sizeof_stream_item( 0)), # Input signature gr.io_signature(1, 1, self._item_size_out) # Output signature ) #create blocks msg_source = gr.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) self._msgq_out = msg_source.msgq() #connect self.connect(self, packet_sink) self.connect(msg_source, self) if packet_sink._hb.output_signature().sizeof_stream_item(0): self.connect( packet_sink, gr.null_sink( packet_sink._hb.output_signature().sizeof_stream_item(0))) self.lasttime = [] self.chars = []
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 qa_linker(): import time from gnuradio import window from system import System from signal_psk31 import PSK31Signal def mag(c): """Magnitude of complex number.""" return (c*c.conjugate()).real src = gr.wavfile_source("../example.WAV", False) samp_rate = 44100 tb = gr.top_block() system = System(tb, src, samp_rate, throttle=False, src_is_float=True, center_freq=0) linker = Linker(1000, 80, samp_rate) snk = gr.null_sink(gr.sizeof_gr_complex) system.connect(system.out, linker, snk) system.refresh() system.start() time.sleep(5) system.stop() data = linker.probe.level() print(data[:10]) print(linker.samp_rate) plot_fft([mag(x) for x in data], linker.samp_rate)
def __init__(self, options, payload=''): gr.top_block.__init__(self) 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) options.interp = 100e6 / options.bandwidth # FTW-specific convertion # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) if (options.from_file is None): self.txpath = ftw_transmit_path(options, payload) else: self.txpath = gr.file_source(gr.sizeof_gr_complex, options.from_file) # options.tx_amplitude = 1 # static value to make sure we do not exceed +-1 for the floats being sent to the sink self._tx_amplitude = options.tx_amplitude self.amp = gr.multiply_const_cc(self._tx_amplitude) # self.txpath = ftw_pnc_transmit_path(options, payload) self.connect(self.txpath, self.amp, self.sink) if options.log: self.connect( self.txpath, gr.file_sink(gr.sizeof_gr_complex, 'ftw_benchmark.dat'))
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 __init__(self): gr.top_block.__init__(self, "Many Rate Changing") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.random_source_x_0 = gr.vector_source_b( map(int, numpy.random.randint(0, 256, 1000)), True) self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb( 2, gr.GR_LSB_FIRST) self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb( 2, gr.GR_MSB_FIRST) self.gr_null_sink_0_2 = gr.null_sink(gr.sizeof_char * 1) self.blocks_float_to_char_0 = blocks.float_to_char(1, 1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) ################################################## # Connections ################################################## self.connect((self.blocks_char_to_float_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.gr_packed_to_unpacked_xx_0, 0)) self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.random_source_x_0, 0), (self.gr_unpacked_to_packed_xx_0, 0)) self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.gr_null_sink_0_2, 0))
def __init__(self): #grc_wxgui.top_block_gui.__init__(self, title="Top Block") gr.top_block.__init__(self) print "abc" ################################################## # Variables ################################################## #self.samp_rate = samp_rate = 32000 self.osr = 4 self.key = '' self.configuration = '' self.clock_rate = 52e6 self.input_rate = self.clock_rate / 72 #TODO: what about usrp value? self.gsm_symb_rate = 1625000.0 / 6.0 self.sps = self.input_rate / self.gsm_symb_rate # configure channel filter filter_cutoff = 135e3 #135,417Hz is GSM bandwidth filter_t_width = 10e3 offset = 0.0 ################################################## # Blocks ################################################## self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1) print "Input files: ", downfile, " ", upfile self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, downfile, False) self.gr_file_source_1 = gr.file_source(gr.sizeof_gr_complex*1, upfile, False) filter_taps = gr.firdes.low_pass(1.0, self.input_rate, filter_cutoff, filter_t_width, gr.firdes.WIN_HAMMING) print len(filter_taps) self.filter0 = gr.freq_xlating_fir_filter_ccf(1, filter_taps, offset, self.input_rate) self.filter1 = gr.freq_xlating_fir_filter_ccf(1, filter_taps, offset, self.input_rate) self.interpolator_1 = gr.fractional_interpolator_cc(0, self.sps) self.tuner_callback = tuner(self) self.synchronizer_callback = synchronizer(self) #self.buffer = howto.buffer_cc() self.burst_cb = burst_callback(self) print ">>>>>Input rate: ", self.input_rate #self.burst = gsm.burst_cf(self.burst_cb,self.input_rate) self.receiver = gsm.receiver_cf(self.tuner_callback, self.synchronizer_callback, self.osr, self.key.replace(' ', '').lower(), self.configuration.upper()) ################################################## # Connections ################################################## #self.connect((self.gr_file_source_0, 0), (self.filter0, 0), (self.burst, 0)) self.connect((self.gr_file_source_1, 0), (self.filter1, 0), (self.interpolator_1, 0), (self.receiver, 0))
def __init__(self, modulator, options): gr.top_block.__init__(self) if (options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.sink._sps elif (options.to_file is not None): sys.stderr.write( ("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write( "No sink defined, dumping samples to null sink.\n\n") 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(modulator, options) self.connect(self.txpath, self.sink)
def __init__(self): gr.top_block.__init__(self, "Many Rate Changing") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## self.random_source_x_0 = gr.vector_source_b(map(int, numpy.random.randint(0, 256, 1000)), True) self.gr_unpacked_to_packed_xx_0 = gr.unpacked_to_packed_bb(2, gr.GR_LSB_FIRST) self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(2, gr.GR_MSB_FIRST) self.gr_null_sink_0_2 = gr.null_sink(gr.sizeof_char*1) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_float, 3, 20, 0) self.blocks_float_to_char_0 = blocks.float_to_char(1, 1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) ################################################## # Connections ################################################## self.connect((self.blocks_char_to_float_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.gr_packed_to_unpacked_xx_0, 0)) self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.random_source_x_0, 0), (self.gr_unpacked_to_packed_xx_0, 0)) self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.gr_null_sink_0_2, 0))
def __init__(self, options): ''' See below for what options should hold ''' gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(1, 1, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_gr_complex)) options = copy.copy( options) # make a copy so we can destructively modify self._verbose = options.verbose # turn verbose mode on/off self._tx_amplitude = options.tx_amplitude # digital amp sent to radio self.packet_tx = ofdm_mod(options, msgq_limit=4, pad_for_usrp=False) self.amp = gr.multiply_const_cc(1) self.set_tx_amplitude(self._tx_amplitude) self.null_sink = gr.null_sink(gr.sizeof_char) self.coding_block_length = options.block_length # Display some information about the setup if self._verbose: self._print_verbage() # Create and setup transmit path flow graph self.connect(self.packet_tx, self.amp, self) # connect hier block input to null when not using streaming inputs self.connect(self, self.null_sink)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2.4e6 ################################################## # Blocks ################################################## self.howto_spectrum_sensing_cf_0 = howto.spectrum_sensing_cf(samp_rate,2048,16,0.001,0.0001,1.9528,True,True,0,200000.0,False,3,4,1,6) self.gr_null_sink_0 = gr.null_sink(gr.sizeof_float*1) self.fft_vxx_0 = fft.fft_vcc(2048, True, (window.blackmanharris(1024)), False, 1) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, 2048) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0) ################################################## # Connections ################################################## self.connect((self.fft_vxx_0, 0), (self.howto_spectrum_sensing_cf_0, 0)) self.connect((self.howto_spectrum_sensing_cf_0, 0), (self.gr_null_sink_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_stream_to_vector_0, 0))
def build_block (tx_enable, rx_enable): max_usb_rate = 8e6 # 8 MS/sec dac_freq = 128e6 adc_freq = 64e6 tx_nchan = 2 tx_mux = 0x0000ba98 tx_interp = int (dac_freq / (max_usb_rate/2 * tx_nchan)) # 16 rx_nchan = 2 rx_mux = 0x00003210 rx_decim = int ((adc_freq * rx_nchan) / (max_usb_rate/2)) # 32 tb = gr.top_block () if tx_enable: tx_src0 = gr.sig_source_c (dac_freq/tx_interp, gr.GR_CONST_WAVE, 0, 16e3, 0) usrp_tx = usrp.sink_c (0, tx_interp, tx_nchan, tx_mux) usrp_tx.set_tx_freq (0, 10e6) usrp_tx.set_tx_freq (1, 9e6) tb.connect (tx_src0, usrp_tx) if rx_enable: usrp_rx = usrp.source_c (0, rx_decim, rx_nchan, rx_mux) usrp_rx.set_rx_freq (0, 5.5e6) usrp_rx.set_rx_freq (1, 6.5e6) rx_dst0 = gr.null_sink (gr.sizeof_gr_complex) tb.connect (usrp_rx, rx_dst0) return tb
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, modulator, options): gr.top_block.__init__(self) if(options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) options.samples_per_symbol = self.sink._sps elif(options.to_file is not None): sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") 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(modulator, options) self.connect(self.txpath, self.sink)
def __init__(self, rx, reader, tx): gr.top_block.__init__(self) samp_freq = (64 / dec_rate) * 1e6 amplitude = 33000 num_taps = int(64000 / (dec_rate * up_link_freq * 2)) #Matched filter for 1/2 cycle taps = [complex(1,1)] * num_taps print num_taps filt = gr.fir_filter_ccc(sw_dec, taps) to_mag = gr.complex_to_mag() amp = gr.multiply_const_cc(amplitude) c_gate = rfid.cmd_gate(dec_rate * sw_dec, reader.STATE_PTR) zc = rfid.clock_recovery_zc_ff(samples_per_pulse, 2); dummy = gr.null_sink(gr.sizeof_float) to_complex = gr.float_to_complex() r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" self.connect(rx, filt, to_mag, c_gate, zc, reader, amp, tx);
def __init__(self, options, payload=''): gr.top_block.__init__(self) 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) options.interp = 100e6/options.bandwidth # FTW-specific convertion # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) if(options.from_file is None): self.txpath = ftw_transmit_path(options, payload) else: self.txpath = gr.file_source(gr.sizeof_gr_complex, options.from_file); # options.tx_amplitude = 1 # static value to make sure we do not exceed +-1 for the floats being sent to the sink self._tx_amplitude = options.tx_amplitude self.amp = gr.multiply_const_cc(self._tx_amplitude) # self.txpath = ftw_pnc_transmit_path(options, payload) self.connect(self.txpath, self.amp, self.sink) if options.log: self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, 'ftw_benchmark.dat'))
def __build_graph(self, source, capture_rate): # tell the scope the source rate self.spectrum.set_sample_rate(capture_rate) # channel filter self.channel_offset = 0.0 channel_decim = capture_rate // self.channel_rate channel_rate = capture_rate // channel_decim trans_width = 12.5e3 / 2 trans_centre = trans_width + (trans_width / 2) # discriminator tap doesn't do freq. xlation, FM demodulation, etc. if not self.baseband_input: coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN) self.channel_filter = gr.freq_xlating_fir_filter_ccf( channel_decim, coeffs, 0.0, capture_rate) self.set_channel_offset(0.0, 0, self.spectrum.win._units) # power squelch squelch_db = 0 self.squelch = gr.pwr_squelch_cc(squelch_db, 1e-3, 0, True) self.set_squelch_threshold(squelch_db) # FM demodulator fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation) fm_demod = gr.quadrature_demod_cf(fm_demod_gain) # symbol filter symbol_decim = 1 #symbol_coeffs = gr.firdes.root_raised_cosine(1.0, channel_rate, self.symbol_rate, 0.2, 500) # boxcar coefficients for "integrate and dump" filter samples_per_symbol = channel_rate // self.symbol_rate symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs) # C4FM demodulator autotuneq = gr.msg_queue(2) demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, self.symbol_rate) # for now no audio output sink = gr.null_sink(gr.sizeof_float) # connect it all up if self.baseband_input: self.rescaler = gr.multiply_const_ff(1) sinkx = gr.file_sink(gr.sizeof_float, "rx.dat") self.__connect([[ source, self.rescaler, self.symbol_filter, demod_fsk4, self.slicer, self.p25_decoder, sink ], [self.symbol_filter, self.signal_scope], [demod_fsk4, sinkx], [demod_fsk4, self.symbol_scope]]) self.connect_data_scope(not self.datascope_raw_input) else: self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset) self.__connect([[ source, self.channel_filter, self.squelch, fm_demod, self.symbol_filter, demod_fsk4, self.slicer, self.p25_decoder, sink ], [source, self.spectrum], [self.symbol_filter, self.signal_scope], [demod_fsk4, self.symbol_scope]])
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 setup_flowgraph(self): options = self.options # Attempt to enable realtime scheduling if options.realtime: r = gr.enable_realtime_scheduling() if r == gr.RT_OK: options.realtime = True print >> sys.stderr, "Realtime scheduling ENABLED" else: options.realtime = False print >> sys.stderr, "Realtime scheduling FAILED" self.setup_timing() # Setup our input source if options.inputfile: self.using_usrp = False print >> sys.stderr, "Reading data from: " + options.inputfile self.source = gr.file_source(gr.sizeof_gr_complex, options.inputfile, options.fileloop) else: self.using_usrp = True self.setup_usrp() self.setup_filter() #create a tuner callback self.mean_offset = 0.0 #this is set by tuner callback self.burst_cb = burst_callback(self) # Setup flow based on decoder selection # if options.decoder.count("c"): self.setup_c_flowgraph() # elif options.decoder.count("f"): # self.setup_f_flowgraph() self.configure_burst_decoder() #Hookup a vector-stream converter if we want burst output if self.scopes.count("b") or options.outputfile: self.v2s = gr.vector_to_stream( gr.sizeof_float, 142) #burst output is 142 (USEFUL_BITS) self.connect(self.burst, self.v2s) else: self.burst_sink = gr.null_sink(gr.sizeof_float) self.v2s = gr.vector_to_stream( gr.sizeof_float, 142) #burst output is 142 (USEFUL_BITS) self.connect(self.burst, self.v2s) self.connect(self.v2s, self.burst_sink) #Output file if options.outputfile: self.filesink = gr.file_sink(gr.sizeof_float, options.outputfile) self.connect(self.v2s, self.filesink)
def __init__(self, N_id_2, decim=16, avg_halfframes=2 * 8, freq_corr=0, dump=None): gr.hier_block2.__init__( self, "PSS correlator", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_float), ) vec_half_frame = 30720 * 5 / decim self.taps = [] for i in range(0, 3): self.taps.append( gen_pss_td(i, N_re=2048 / decim, freq_corr=freq_corr).get_data_conj_rev()) self.corr = filter.fir_filter_ccc(1, self.taps[N_id_2]) self.mag = gr.complex_to_mag_squared() self.vec = gr.stream_to_vector(gr.sizeof_float * 1, vec_half_frame) self.deint = gr.deinterleave(gr.sizeof_float * vec_half_frame) self.add = gr.add_vff(vec_half_frame) self.argmax = gr.argmax_fs(vec_half_frame) self.null = gr.null_sink(gr.sizeof_short * 1) self.max = gr.max_ff(vec_half_frame) self.to_float = gr.short_to_float(1, 1. / decim) self.interleave = gr.interleave(gr.sizeof_float) #self.framestart = gr.add_const_ii(-160-144*5-2048*6+30720*5) self.connect(self, self.corr, self.mag, self.vec) self.connect((self.argmax, 1), self.null) #self.connect(self.argmax, self.to_float, self.to_int, self.framestart, self) self.connect(self.argmax, self.to_float, self.interleave, self) self.connect(self.max, (self.interleave, 1)) if avg_halfframes == 1: self.connect(self.vec, self.argmax) self.connect(self.vec, self.max) else: self.connect(self.vec, self.deint) self.connect(self.add, self.argmax) self.connect(self.add, self.max) for i in range(0, avg_halfframes): self.connect((self.deint, i), (self.add, i)) if dump != None: self.connect( self.mag, gr.file_sink(gr.sizeof_float, dump + "_pss_corr_f.cfile")) self.connect( self.add, gr.file_sink(gr.sizeof_float * vec_half_frame, dump + "_pss_corr_add_f.cfile"))
def __init__(self, mode, freq, gain, conf, subchid, record=None, usrp=True): gr.top_block.__init__(self) if usrp: # set up usrp source src = dabp_usrp.setup_usrp(freq, gain) else: # set up sample file source sinput = gr.file_source(gr.sizeof_short, samp.encode('ascii'), False) src = gr.interleaved_short_to_complex() self.connect(sinput, src) # channel configuration cc = dabp.channel_conf(conf) #sys.stderr.write("Playing Channel: "+cc.get_label(options.subchid)+"\n") start_addr = cc.get_start_addr(subchid) subchsz = cc.get_subchsz(subchid) optprot = cc.get_optprot(subchid) #print "start_addr=%d, subchsz=%d, optprot=%d" % (start_addr, subchsz, optprot) param = dabp.parameters(mode) # null symbol detector samples_per_null_sym=param.get_Nnull() #print "samples per null symbol : %d" % samples_per_null_sym nulldet = dabp.detect_null(samples_per_null_sym) # ofdm demod demod = dabp.ofdm_demod(mode) # FIC/MSC demultiplexer demux = dabp.fic_msc_demux(1, mode) cifsz = param.get_cifsz() scs = dabp.subchannel_selector(cifsz,start_addr,subchsz) intlv = dabp.time_deinterleaver(subchsz) punc = dabp.depuncturer(subchsz,optprot) I = punc.getI() vit = dabp.vitdec(I) scram = dabp.scrambler(I) len_logfrm=scram.get_nbytes() sync = dabp.super_frame_sync(len_logfrm) subchidx = sync.get_subchidx() rs = dabp.super_frame_rsdec(subchidx) if record == None: mplayer = subprocess.Popen(['mplayer', '-af', 'volume=20', '-ac', '+faad', '-rawaudio', 'format=0xff', '-demuxer', '+rawaudio','-'], stdin=subprocess.PIPE) dst = dabp.super_frame_sink(subchidx, mplayer.stdin.fileno()) else: dst = dabp.super_frame_sink(subchidx, record.encode('ascii')) nullsink = gr.null_sink(gr.sizeof_char) # connect everything self.connect(src, nulldet) self.connect(src, (demod,0)) self.connect(nulldet, (demod,1)) self.connect((demod,0), demux, scs, intlv, punc, vit, scram, sync, rs, dst) self.connect((demod,1), nullsink)
def build_graph(self, device, speed): self.src = gr.sig_source_s(2, gr.GR_CONST_WAVE, 1, 0, 1) self.sink = gr.null_sink(gr.sizeof_short) self.spi = gr_spi.gr_spi_srcsink_ss() sys.stdout.write("Blocks created\n") self.spi.open_spi(device, speed) sys.stdout.write("SPI device open\n") self.connect(self.src, self.spi) sys.stdout.write("Source connected\n") self.connect(self.spi, self.sink) sys.stdout.write("Sink connected\n")
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="My Second Msg Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 25e6 ################################################## # Blocks ################################################## self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.usrp_source = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.usrp_source.set_samp_rate(samp_rate) self.usrp_source.set_center_freq(105e6, 0) self.usrp_source.set_gain(15, 0) self.usrp_source.set_antenna("RX2", 0) self.my_second_msg_block_0 = dt.my_second_msg_block( "95e6,605e6,915e6,880e6,1986e6") self.heart_beat_0_0 = precog.heart_beat(5, "hello", "world") self.heart_beat_0 = precog.heart_beat(1, "hello", "world") self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char * 1) self.extras_pmt_rpc_0 = gr_extras.pmt_rpc(obj=self, result_msg=False) ################################################## # Connections ################################################## self.connect((self.heart_beat_0, 0), (self.my_second_msg_block_0, 0)) self.connect((self.heart_beat_0_0, 0), (self.my_second_msg_block_0, 1)) self.connect((self.my_second_msg_block_0, 1), (self.extras_pmt_rpc_0, 0)) self.connect((self.usrp_source, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.my_second_msg_block_0, 0), (self.gr_null_sink_0, 0))
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()