Esempio n. 1
0
    def __init__(self):
        gr.top_block.__init__(self)
        #build graph now

        #usrp_source
        self.usrp = usrp.source_c()
        adc_rate = self.usrp.adc_rate()  #64MHz
        hw_decim = 16  #so Sample rate into host is 4MHz
        self.usrp.set_decim_rate(hw_decim)
        self.subdev = usrp.selected_subdev(self.usrp,
                                           usrp.pick_rx_subdevice(self.usrp))
        self.usrp.set_mux(
            usrp.determine_rx_mux_value(self.usrp,
                                        usrp.pick_rx_subdevice(self.usrp)))
        print "Using RX d'board %s" % (self.subdev.side_and_name(), )
        self.subdev.set_gain(30)
        rf_freq = 106800000  # 106.8MHz
        self.set_freq(rf_freq)
        print "Freq: ", rf_freq
        self.subdev.select_rx_antenna("TX/RX")

        #low pass filter
        self.sample_rate = adc_rate / hw_decim
        self.lpf_decim = 20  # so after channel filter, the sample rate is 200KHz
        self.lp_filter = gr.fir_filter_ccf(
            self.lpf_decim,
            gr.firdes.low_pass(
                1,
                self.sample_rate,
                100e3,  # cut off freq
                10e3,  # transition band
                gr.firdes.WIN_BLACKMAN,  # Window function
                6.76  # not used
            ))
        # WBFM receiver
        quad_rate = self.sample_rate  #input rate of demodulator
        max_dev = 75e3  #max deviation of FM Broadcast
        fm_demod_gain = quad_rate / (2 * math.pi * max_dev)
        self.fm_decoder = gr.quadrature_demod_cf(fm_demod_gain)

        # Rational Resampler
        self.audio_sample_rate = 96000
        self.rational_resampler = blks2.rational_resampler_fff(
            interpolation=int(self.audio_sample_rate / 1000),
            decimation=int(self.sample_rate / self.lpf_decim / 1000),
            taps=None,
            fractional_bw=None,
        )
        self.audio_sink = audio.sink(int(self.audio_sample_rate), "", True)

        #connections
        self.connect(self.usrp, self.lp_filter, self.fm_decoder,
                     self.rational_resampler, self.audio_sink)
Esempio n. 2
0
 def __set_rx_from_usrp(self, subdev_spec, decimation_rate, gain, frequency, preserve):
     from gnuradio import usrp
     # setup USRP
     self.usrp.set_decim_rate(decimation_rate)
     if subdev_spec is None:
         subdev_spec = usrp.pick_rx_subdevice(self.usrp)
     self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, subdev_spec))
     subdev = usrp.selected_subdev(self.usrp, subdev_spec)
     capture_rate = self.usrp.adc_freq() / self.usrp.decim_rate()
     self.info["capture-rate"] = capture_rate
     if gain is None:
         g = subdev.gain_range()
         gain = float(g[0]+g[1])/2
     subdev.set_gain(gain)
     r = self.usrp.tune(0, subdev, frequency)
     if not r:
         raise RuntimeError("failed to set USRP frequency")
     # capture file
     if preserve:
         try:
             self.capture_filename = os.tmpnam()
         except RuntimeWarning:
             ignore = True
         capture_file = gr.file_sink(gr.sizeof_gr_complex, self.capture_filename)
         self.__connect([[self.usrp, capture_file]])
     else:
         self.capture_filename = None
     # everything else
     self.__build_graph(self.usrp, capture_rate)
    def __init__(self, N, fs):
        gr.hier_block2.__init__(self,
                "usrp_source",
                gr.io_signature(0,0,0),
                gr.io_signature(1,1, gr.sizeof_gr_complex))

        # Parameters.
        frequency = 1575.6e6
        decim_rate = int(64e6/fs)
        fpga_filename = "std_4rx_0tx.rbf"

        # Sources.
        usrp = usrp.source_c( decim_rate=decim_rate, fpga_filename=fpga_filename )
        head = gr.head( gr.sizeof_gr_complex, N*fs*1e-3 )
        self.connect( usrp, head, self )

        # USRP settings.
        rx_subdev_spec = usrp.pick_rx_subdevice(usrp)
        usrp.set_mux(usrp.determine_rx_mux_value(usrp, rx_subdev_spec))
        subdev = usrp.selected_subdev( usrp, rx_subdev_spec )
        print "Subdev gain range: "
        print subdev.gain_range()

        subdev.set_gain(70)
        r = usrp.tune( 0,_subdev, frequency )
        if not r:
            sys.exit('Failed to set frequency')
Esempio n. 4
0
def setup_usrp(freq, gain):
    ######## set up usrp
    u = usrp.source_c(decim_rate=32) # 2M sampling freq
    rx_subdev_spec = usrp.pick_rx_subdevice(u)
    #print "u.db(0,0).dbid() = ", self.u.db(0,0).dbid()
    #print "u.db(1,0).dbid() = ", self.u.db(1,0).dbid()
    #print "rx_subdev_spec = ", options.rx_subdev_spec
    
    mux=usrp.determine_rx_mux_value(u, rx_subdev_spec)
    #print "mux = ", mux
    u.set_mux(mux)

    # determine the daughterboard subdevice we're using
    subdev = usrp.selected_subdev(u, rx_subdev_spec)
    #print "Using RX d'board %s" % (self.subdev.side_and_name(),)
    input_rate = u.adc_freq() / u.decim_rate()
    #print "ADC sampling @ ", eng_notation.num_to_str(self.u.adc_freq())
    #print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

    subdev.set_gain(gain)
    r = u.tune(0, subdev, freq)
    
    #print "freq range = [%s, %s]" % (eng_notation.num_to_str(self.subdev.freq_min()), eng_notation.num_to_str(self.subdev.freq_max()))
    if not r:
        sys.stderr.write('Failed to set frequency\n')
        raise SystemExit, 1
    return u
    
Esempio n. 5
0
def setup_usrp(freq, gain):
    ######## set up usrp
    u = usrp.source_c(decim_rate=32)  # 2M sampling freq
    rx_subdev_spec = usrp.pick_rx_subdevice(u)
    #print "u.db(0,0).dbid() = ", self.u.db(0,0).dbid()
    #print "u.db(1,0).dbid() = ", self.u.db(1,0).dbid()
    #print "rx_subdev_spec = ", options.rx_subdev_spec

    mux = usrp.determine_rx_mux_value(u, rx_subdev_spec)
    #print "mux = ", mux
    u.set_mux(mux)

    # determine the daughterboard subdevice we're using
    subdev = usrp.selected_subdev(u, rx_subdev_spec)
    #print "Using RX d'board %s" % (self.subdev.side_and_name(),)
    input_rate = u.adc_freq() / u.decim_rate()
    #print "ADC sampling @ ", eng_notation.num_to_str(self.u.adc_freq())
    #print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

    subdev.set_gain(gain)
    r = u.tune(0, subdev, freq)

    #print "freq range = [%s, %s]" % (eng_notation.num_to_str(self.subdev.freq_min()), eng_notation.num_to_str(self.subdev.freq_max()))
    if not r:
        sys.stderr.write('Failed to set frequency\n')
        raise SystemExit, 1
    return u
Esempio n. 6
0
    def _setup_usrp_source(self):
        self.rx_u = usrp.source_c (fusb_block_size=self._fusb_block_size,
                                fusb_nblocks=self._fusb_nblocks)
        adc_rate = self.rx_u.adc_rate()

        self.rx_u.set_decim_rate(self._decim)

        # determine the daughterboard subdevice we're using
        if self._rx_subdev_spec is None:
            print 'not set rx subdev'
            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.rx_u)
        print self._rx_subdev_spec
        self.rx_subdev = usrp.selected_subdev(self.rx_u, self._rx_subdev_spec)

        gains = self.rx_subdev.gain_range()
        self.rx_subdev.set_gain((gains[0]+gains[1])/2)

        self.rx_u.set_mux(usrp.determine_rx_mux_value(self.rx_u, self._rx_subdev_spec))
        print 'subdev size %d' % self.rx_subdev.which()
        ok = self.rx_u.tune(0, self.rx_subdev, self._rx_freq)
        if not ok:
            print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(self._rx_freq),)
            raise ValueError

        self.rx_subdev.set_auto_tr(True)
Esempio n. 7
0
 def __set_rx_from_usrp(self, subdev_spec, decimation_rate, gain, frequency,
                        preserve):
     from gnuradio import usrp
     # setup USRP
     self.usrp.set_decim_rate(decimation_rate)
     if subdev_spec is None:
         subdev_spec = usrp.pick_rx_subdevice(self.usrp)
     self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, subdev_spec))
     subdev = usrp.selected_subdev(self.usrp, subdev_spec)
     capture_rate = self.usrp.adc_freq() / self.usrp.decim_rate()
     self.info["capture-rate"] = capture_rate
     if gain is None:
         g = subdev.gain_range()
         gain = float(g[0] + g[1]) / 2
     subdev.set_gain(gain)
     r = self.usrp.tune(0, subdev, frequency)
     if not r:
         raise RuntimeError("failed to set USRP frequency")
     # capture file
     if preserve:
         try:
             self.capture_filename = os.tmpnam()
         except RuntimeWarning:
             ignore = True
         capture_file = gr.file_sink(gr.sizeof_gr_complex,
                                     self.capture_filename)
         self.__connect([[self.usrp, capture_file]])
     else:
         self.capture_filename = None
     # everything else
     self.__build_graph(self.usrp, capture_rate)
Esempio n. 8
0
    def _setup_usrp_source(self):
        self.rx_u = usrp.source_c(fusb_block_size=self._fusb_block_size,
                                  fusb_nblocks=self._fusb_nblocks)
        adc_rate = self.rx_u.adc_rate()

        self.rx_u.set_decim_rate(self._decim)

        # determine the daughterboard subdevice we're using
        if self._rx_subdev_spec is None:
            print 'not set rx subdev'
            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.rx_u)
        print self._rx_subdev_spec
        self.rx_subdev = usrp.selected_subdev(self.rx_u, self._rx_subdev_spec)

        gains = self.rx_subdev.gain_range()
        self.rx_subdev.set_gain((gains[0] + gains[1]) / 2)

        self.rx_u.set_mux(
            usrp.determine_rx_mux_value(self.rx_u, self._rx_subdev_spec))
        print 'subdev size %d' % self.rx_subdev.which()
        ok = self.rx_u.tune(0, self.rx_subdev, self._rx_freq)
        if not ok:
            print "Failed to set Rx frequency to %s" % (
                eng_notation.num_to_str(self._rx_freq), )
            raise ValueError

        self.rx_subdev.set_auto_tr(True)
    def _set_source(self):
        options = self.options
        fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
        fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
        self.usrp = usrp.source_c(decim_rate=options.decim, fusb_block_size=fusb_block_size, fusb_nblocks=fusb_nblocks)
        
        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_rx_subdevice(self.usrp)
        
        self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, options.rx_subdev_spec))
        # determine the daughterboard subdevice
        self.subdev = usrp.selected_subdev(self.usrp, options.rx_subdev_spec)
	print "Using Rx d'board %s" % (self.subdev.side_and_name(),)
        input_rate = self.usrp.adc_freq() / self.usrp.decim_rate()
	print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        # set initial values
        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0]+g[1])/2

        r = self.usrp.tune(0, self.subdev, options.freq)
        self.subdev.set_gain(options.gain)
        return self.usrp
Esempio n. 10
0
    def __init__(self, N, fs):
        gr.hier_block2.__init__(self, "usrp_source", gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        # Parameters.
        frequency = 1575.6e6
        decim_rate = int(64e6 / fs)
        fpga_filename = "std_4rx_0tx.rbf"

        # Sources.
        usrp = usrp.source_c(decim_rate=decim_rate,
                             fpga_filename=fpga_filename)
        head = gr.head(gr.sizeof_gr_complex, N * fs * 1e-3)
        self.connect(usrp, head, self)

        # USRP settings.
        rx_subdev_spec = usrp.pick_rx_subdevice(usrp)
        usrp.set_mux(usrp.determine_rx_mux_value(usrp, rx_subdev_spec))
        subdev = usrp.selected_subdev(usrp, rx_subdev_spec)
        print "Subdev gain range: "
        print subdev.gain_range()

        subdev.set_gain(70)
        r = usrp.tune(0, _subdev, frequency)
        if not r:
            sys.exit('Failed to set frequency')
 def _setup_usrp_source(self, options):
     #create USRP
     self._usrp = usrp.source_c(which= options.which, decim_rate = options.decim_rate)
     if options.rx_subdev_spec is None:
        options.rx_subdev_spec = usrp.pick_rx_subdevice(self._usrp)
            
     self._subdev = usrp.selected_subdev(self._usrp, options.rx_subdev_spec)
     
     adc_rate = self._usrp.adc_rate()
     
     mux = usrp.determine_rx_mux_value(self._usrp, options.rx_subdev_spec)
     self._usrp.set_mux(mux)
     tr = self._usrp.tune(0, self._subdev, options.freq)
     if not (tr):
         print "Failed to tune to center frequency!"
     else:
         print "Center frequency:", n2s(options.freq)
     if options.gain is None:
         g = self._subdev.gain_range();
         options.gain = float(g[0]+g[1])/2.0
     self._subdev.set_gain(options.gain)
     
     #the bitrate option is initialised to value
     self.rs_rate = options.rate
     
     #Hard initialisation of bits per symbol
     self.bits_per_symbol = 1
     
     
     if options.verbose:
         print "USRP source:", self._usrp
         print "Decimation:", options.decim_rate
Esempio n. 12
0
    def _set_source(self):
        options = self.options
        fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
        fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16)
        self.usrp = usrp.source_c(decim_rate=options.decim,
                                  fusb_block_size=fusb_block_size,
                                  fusb_nblocks=fusb_nblocks)

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_rx_subdevice(self.usrp)

        self.usrp.set_mux(
            usrp.determine_rx_mux_value(self.usrp, options.rx_subdev_spec))
        # determine the daughterboard subdevice
        self.subdev = usrp.selected_subdev(self.usrp, options.rx_subdev_spec)
        print "Using Rx d'board %s" % (self.subdev.side_and_name(), )
        input_rate = self.usrp.adc_freq() / self.usrp.decim_rate()
        print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        # set initial values
        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        r = self.usrp.tune(0, self.subdev, options.freq)
        self.subdev.set_gain(options.gain)
        return self.usrp
Esempio n. 13
0
def main():
	tb = gr.top_block()
	ofdm_rx = howto.ofdm_rx();
        #rs = gr.vector_source_c()
	#rs = gr.file_source(gr.sizeof_gr_complex,'out.dat')
	src = usrp.source_c(0)
	#nchannel
	src.set_nchannels(1)
	sample_rate = 1e6

	ulist = [src]
	print "ulist"
	print ulist
	
	for u in ulist:
		rdecim = int(u.adc_rate() / sample_rate)
		u.set_decim_rate(rdecim)
	sys.stderr.write("the decimate = %d\n"%(rdecim))


	srx1 = usrp.pick_rx_subdevice(src)
	print "srx1="
	print srx1

	subdev = ()
	"""configure USRP mux and set rx/tx subdev """
	ulist = [src]
	assert len(ulist) == 1
	src = ulist[0]
	src.set_mux( usrp.determine_rx_mux_value(src, srx1))
	subdev += (usrp.selected_subdev(src, srx1), )
	for s in subdev: exec("if not hasattr(s, '_u'): s._u = src")
	for s in subdev: s.set_auto_tr(True)
	
	print "subdev"
	print subdev

	freq = 2400000000.0
	for s in subdev:
		r = usrp.tune(s._u, s.which(), s, freq)
		if r:
			sys.stderr.write("setting frequency of %s :\n"%(str(s)))
			sys.stderr.write(" baseband frequency = %s \n" %(eng_notation.num_to_str(r.baseband_freq)))
			sys.stderr.write(" DUC/DDC offset = %s\n" %(eng_notation.num_to_str(r.dxc_freq)))
		elif not r:
			sys.stderr.write("Unable to set frequency of %s to %g MHz \n"%(str(s), freq/ 1.0e6))

	#g = 40.0
	for s in subdev:
		gain_range = s.gain_range()
		#rx_gain = max(min(g, gain_range[1]), gain_range[0])
		rx_gain = 0.3 * gain_range[1]
		s.set_gain(rx_gain)
	sys.stderr.write("the rx_gain = %d \n " %(rx_gain))


	tb.connect(src, ofdm_rx)
	print 'connect'
	tb.run()
Esempio n. 14
0
    def __init__(self):
        gr.top_block.__init__(self)
        #build graph now

        #usrp_source
        self.usrp = usrp.source_c()
        adc_rate  = self.usrp.adc_rate()  #64MHz
        hw_decim  = 16                    #so Sample rate into host is 4MHz
        self.usrp.set_decim_rate(hw_decim)
        self.subdev = usrp.selected_subdev(self.usrp, usrp.pick_rx_subdevice(self.usrp))
        self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, usrp.pick_rx_subdevice(self.usrp)))
        print "Using RX d'board %s" % (self.subdev.side_and_name(),)
        self.subdev.set_gain(30)
        rf_freq = 106800000               # 106.8MHz
        self.set_freq(rf_freq)
        print "Freq: ", rf_freq
        self.subdev.select_rx_antenna("TX/RX")

        #low pass filter
        self.sample_rate = adc_rate / hw_decim
        self.lpf_decim = 20               # so after channel filter, the sample rate is 200KHz
        self.lp_filter = gr.fir_filter_ccf( self.lpf_decim, gr.firdes.low_pass ( 1, 
                                                                                self.sample_rate, 
                                                                                100e3, # cut off freq
                                                                                10e3,  # transition band
                                                                                gr.firdes.WIN_BLACKMAN, # Window function
                                                                                6.76              # not used
                                                                                 ))
        # WBFM receiver
        quad_rate = self.sample_rate  #input rate of demodulator
        max_dev = 75e3        #max deviation of FM Broadcast
        fm_demod_gain = quad_rate/(2 * math.pi * max_dev)
        self.fm_decoder = gr.quadrature_demod_cf (fm_demod_gain)


        # Rational Resampler
        self.audio_sample_rate  = 96000
        self.rational_resampler = blks2.rational_resampler_fff ( interpolation = int(self.audio_sample_rate/1000),
                                                                decimation    = int(self.sample_rate/self.lpf_decim/1000),
                                                                taps          = None,
                                                                fractional_bw = None,
                                                              )
        self.audio_sink = audio.sink (int(self.audio_sample_rate), "", True)

        #connections
        self.connect ( self.usrp, self.lp_filter, self.fm_decoder, self.rational_resampler, self.audio_sink )
Esempio n. 15
0
    def __init__(self, options):
        gr.top_block.__init__(self)

        # Create a USRP source with GPIO FPGA build, then configure
        u = usrp.source_s(decim_rate=options.decim,
                          fpga_filename=gpio.fpga_filename)

        if options.force_complex_RXA:
            # This is a dirty hack to force complex mode (receive both I and Q) on basicRX or LFRX
            # This forces the receive board in RXA (side A) to be used
            # FIXME: This has as a side effect that the gain for Q is not set. So only use with gain 0 (--gain 0)
            options.rx_subdev_spec = (0, 0)
            u.set_mux(0x10)
            if not (0 == options.gain):
                print "WARNING, you should set the gain to 0 with --gain 0 when using --force-complex-RXA"
                print "The gain for Q will now still be zero while the gain for I is not"
                #options.gain=0
        else:
            if options.rx_subdev_spec is None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(u)
            u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec))

        subdev = usrp.selected_subdev(u, options.rx_subdev_spec)
        print "Using RX d'board %s" % (subdev.side_and_name(), )
        input_rate = u.adc_freq() / u.decim_rate()
        print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = subdev.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        #TODO setting gain on basicRX only sets the I channel, use a second subdev to set gain of Q channel
        #see gnuradio-examples/multi-antenna for possible solutions
        subdev.set_gain(options.gain)

        #TODO check if freq has same problem as gain when trying to use complex mode on basicRX
        r = u.tune(0, subdev, options.freq)
        if not r:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1

# Connect pipeline
        src = u
        if options.nsamples is not None:
            head = gr.head(gr.sizeof_short, int(options.nsamples) * 2)
            self.connect(u, head)
            src = head

        ana_strip = gr.and_const_ss(0xFFFE)
        dig_strip = gr.and_const_ss(0x0001)
        ana_sink = gr.file_sink(gr.sizeof_short, options.ana_filename)
        dig_sink = gr.file_sink(gr.sizeof_short, options.dig_filename)

        self.connect(src, ana_strip, ana_sink)
        self.connect(src, dig_strip, dig_sink)
    def __init__(self, options):
        gr.top_block.__init__(self)

	# Create a USRP source with GPIO FPGA build, then configure
        u = usrp.source_s(decim_rate=options.decim,fpga_filename=gpio.fpga_filename)

        if options.force_complex_RXA:
           # This is a dirty hack to force complex mode (receive both I and Q) on basicRX or LFRX
           # This forces the receive board in RXA (side A) to be used 
           # FIXME: This has as a side effect that the gain for Q is not set. So only use with gain 0 (--gain 0)
           options.rx_subdev_spec=(0,0)
           u.set_mux(0x10)
           if not (0==options.gain):
             print "WARNING, you should set the gain to 0 with --gain 0 when using --force-complex-RXA"
             print "The gain for Q will now still be zero while the gain for I is not" 
             #options.gain=0
        else:
          if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_rx_subdevice(u)
          u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec))

        subdev = usrp.selected_subdev(u, options.rx_subdev_spec)
        print "Using RX d'board %s" % (subdev.side_and_name(),)
        input_rate = u.adc_freq()/u.decim_rate()
        print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = subdev.gain_range()
            options.gain = float(g[0]+g[1])/2


        #TODO setting gain on basicRX only sets the I channel, use a second subdev to set gain of Q channel
        #see gnuradio-examples/multi-antenna for possible solutions
        subdev.set_gain(options.gain)

        #TODO check if freq has same problem as gain when trying to use complex mode on basicRX
        r = u.tune(0, subdev, options.freq)
        if not r:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1

	# Connect pipeline
	src = u
	if options.nsamples is not None:
	    head = gr.head(gr.sizeof_short, int(options.nsamples)*2)
	    self.connect(u, head)
	    src = head

	ana_strip = gpio.and_const_ss(0xFFFE)
	dig_strip = gpio.and_const_ss(0x0001)
        ana_sink = gr.file_sink(gr.sizeof_short, options.ana_filename)
	dig_sink = gr.file_sink(gr.sizeof_short, options.dig_filename)
    
	self.connect(src, ana_strip, ana_sink)
	self.connect(src, dig_strip, dig_sink)
Esempio n. 17
0
 def _setup_usrp1(self):
     self._u = usrp.source_c (self._which,
                             fusb_block_size=self._fusb_block_size,
                             fusb_nblocks=self._fusb_nblocks)
     # determine the daughterboard subdevice we're using
     if self._subdev_spec is None:
         self._subdev_spec = usrp.pick_rx_subdevice(self._u)
     self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
     self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec))
     self._dxc = 0
Esempio n. 18
0
 def _setup_usrp1(self):
     self._u = usrp.source_c(self._which,
                             fusb_block_size=self._fusb_block_size,
                             fusb_nblocks=self._fusb_nblocks)
     # determine the daughterboard subdevice we're using
     if self._subdev_spec is None:
         self._subdev_spec = usrp.pick_rx_subdevice(self._u)
     self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
     self._u.set_mux(usrp.determine_rx_mux_value(self._u,
                                                 self._subdev_spec))
     self._dxc = 0
Esempio n. 19
0
    def _setup_usrp(self):
        self._u = usrp.source_c(fpga_filename='usrp_radar_mono.rbf')
        if self._subdev_spec == None:
            self._subdev_spec = usrp.pick_rx_subdevice(self._u)
        self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec))
        self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)

        if self._verbose:
            print "Using", self._subdev.side_and_name(), "for radar receiver."
            print "Setting receiver gain to", self._gain
        self.set_gain(self._gain)
	self.tune(self._frequency)
Esempio n. 20
0
    def _setup_usrp_source(self):
        self.u = usrp.source_c (fusb_block_size=self._fusb_block_size,
                                fusb_nblocks=self._fusb_nblocks)
        adc_rate = self.u.adc_rate()

        self.u.set_decim_rate(self._decim)

        # determine the daughterboard subdevice we're using
        if self._rx_subdev_spec is None:
            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        self.subdev = usrp.selected_subdev(self.u, self._rx_subdev_spec)

        self.u.set_mux(usrp.determine_rx_mux_value(self.u, self._rx_subdev_spec))
Esempio n. 21
0
    def _setup_usrp(self):
        self._u = usrp.source_c(fpga_filename='usrp_radar_mono.rbf')
        if self._subdev_spec == None:
            self._subdev_spec = usrp.pick_rx_subdevice(self._u)
        self._u.set_mux(usrp.determine_rx_mux_value(self._u,
                                                    self._subdev_spec))
        self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)

        if self._verbose:
            print "Using", self._subdev.side_and_name(), "for radar receiver."
            print "Setting receiver gain to", self._gain
        self.set_gain(self._gain)
        self.tune(self._frequency)
Esempio n. 22
0
    def _setup_usrp_source(self):
        self.u = usrp.source_c (fusb_block_size=self._fusb_block_size,
                                fusb_nblocks=self._fusb_nblocks)
        adc_rate = self.u.adc_rate()

        self.u.set_decim_rate(self._decim)

        # determine the daughterboard subdevice we're using
        if self._rx_subdev_spec is None:
            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        self.subdev = usrp.selected_subdev(self.u, self._rx_subdev_spec)

        self.u.set_mux(usrp.determine_rx_mux_value(self.u, self._rx_subdev_spec))
Esempio n. 23
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self, "usrp_flex_all")

        if options.from_file is not None:
            src = gr.file_source(gr.sizeof_gr_complex, options.from_file)
            if options.verbose:
                print "Reading samples from file", options.from_file
        else:
            src = usrp.source_c()
            if options.rx_subdev_spec is None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(src)
            subdev = usrp.selected_subdev(src, options.rx_subdev_spec)
            src.set_mux(
                usrp.determine_rx_mux_value(src, options.rx_subdev_spec))
            src.set_decim_rate(20)
            result = usrp.tune(src, 0, subdev,
                               930.5125e6 + options.calibration)
            if options.verbose:
                print "Using", subdev.name(), " for receiving."
                print "Tuned USRP to", 930.5125e6 + options.calibration

        taps = gr.firdes.low_pass(1.0, 1.0, 1.0 / 128.0 * 0.4,
                                  1.0 / 128.0 * 0.1, gr.firdes.WIN_HANN)

        if options.verbose:
            print "Channel filter has", len(taps), "taps"

        bank = blks2.analysis_filterbank(128, taps)
        self.connect(src, bank)

        if options.log and options.from_file == None:
            src_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
            self.connect(src, src_sink)

        for i in range(128):
            if i < 64:
                freq = 930.5e6 + i * 25e3
            else:
                freq = 928.9e6 + (i - 64) * 25e3

            if (freq < 929.0e6 or freq > 932.0e6):
                self.connect((bank, i), gr.null_sink(gr.sizeof_gr_complex))
            else:
                self.connect((bank, i),
                             pager.flex_demod(queue, freq, options.verbose,
                                              options.log))
                if options.log:
                    self.connect(
                        (bank, i),
                        gr.file_sink(gr.sizeof_gr_complex, 'chan_' + '%3.3f' %
                                     (freq / 1e6) + '.dat'))
Esempio n. 24
0
    def __init__(self, options, queue):
	gr.top_block.__init__(self, "usrp_flex_all")

        if options.from_file is not None:
            src = gr.file_source(gr.sizeof_gr_complex, options.from_file)
            if options.verbose:
                print "Reading samples from file", options.from_file
        else:
            src = usrp.source_c()
            if options.rx_subdev_spec is None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(src)
            subdev = usrp.selected_subdev(src, options.rx_subdev_spec)
            src.set_mux(usrp.determine_rx_mux_value(src, options.rx_subdev_spec))
            src.set_decim_rate(20)
            result = usrp.tune(src, 0, subdev, 930.5125e6+options.calibration)
            if options.verbose:
                print "Using", subdev.name(), " for receiving."
                print "Tuned USRP to", 930.5125e6+options.calibration
                
        taps = gr.firdes.low_pass(1.0,
                                  1.0,
                                  1.0/128.0*0.4,
                                  1.0/128.0*0.1,
                                  gr.firdes.WIN_HANN)

        if options.verbose:
            print "Channel filter has", len(taps), "taps"

        bank = blks2.analysis_filterbank(128, taps)
        self.connect(src, bank)

        if options.log and options.from_file == None:
            src_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
            self.connect(src, src_sink)

        for i in range(128):
	    if i < 64:
		freq = 930.5e6+i*25e3
	    else:
		freq = 928.9e6+(i-64)*25e3

	    if (freq < 929.0e6 or freq > 932.0e6):
                self.connect((bank, i), gr.null_sink(gr.sizeof_gr_complex))
	    else:
            	self.connect((bank, i), pager.flex_demod(queue, freq, options.verbose, options.log))
                if options.log:
                    self.connect((bank, i), gr.file_sink(gr.sizeof_gr_complex, 'chan_'+'%3.3f'%(freq/1e6)+'.dat'))
Esempio n. 25
0
 def _setup_usrp(self, which, decim, subdev_spec, freq, gain):
     self._usrp = usrp.source_c(which=which, decim_rate=decim)
     if subdev_spec is None:
         subdev_spec = usrp.pick_rx_subdevice(self._usrp)
     self._subdev = usrp.selected_subdev(self._usrp, subdev_spec)
     mux = usrp.determine_rx_mux_value(self._usrp, subdev_spec)
     self._usrp.set_mux(mux)
     tr = self._usrp.tune(0, self._subdev, freq)
     if not (tr):
         print "Failed to tune to center frequency!"
     else:
         print "Center frequency:", n2s(freq)
     if gain is None:
         g = self._subdev.gain_range()
         gain = float(g[0] + g[1]) / 2.0
     self._subdev.set_gain(gain)
     print "RX d'board:", self._subdev.side_and_name()
Esempio n. 26
0
    def _setup_usrp(self, which, decim, subdev_spec, freq, gain):
        self._usrp = usrp.source_c(which=which, decim_rate=decim)
	if subdev_spec is None:
	    subdev_spec = usrp.pick_rx_subdevice(self._usrp)
	self._subdev = usrp.selected_subdev(self._usrp, subdev_spec)
        mux = usrp.determine_rx_mux_value(self._usrp, subdev_spec)
	self._usrp.set_mux(mux)
	tr = self._usrp.tune(0, self._subdev, freq)
        if not (tr):
            print "Failed to tune to center frequency!"
        else:
            print "Center frequency:", n2s(freq)
        if gain is None:
            g = self._subdev.gain_range();
            gain = float(g[0]+g[1])/2.0
	self._subdev.set_gain(gain)
        print "RX d'board:", self._subdev.side_and_name()
Esempio n. 27
0
def setup_usrp(freq):

  # Constants
  interp = 128
  decim = 64
  
  # Make USRP instances to TX and RX
  utx = usrp.sink_c(fpga_filename="local_rssi5.rbf")
  urx = usrp.source_c(fpga_filename="local_rssi5.rbf")

  # Set decim and interp rates
  utx.set_interp_rate(interp)
  urx.set_decim_rate(decim)

  # Pick subdevice
  subdev_spec_tx = usrp.pick_tx_subdevice(utx)
  subdev_spec_rx = usrp.pick_rx_subdevice(urx)

  # Set up mux
  mux_tx = usrp.determine_tx_mux_value(utx, subdev_spec_tx)
  mux_rx = usrp.determine_rx_mux_value(urx, subdev_spec_rx)
  utx.set_mux(mux_tx)
  urx.set_mux(mux_rx)

  # pick d'board
  subdev_tx = usrp.selected_subdev(utx, subdev_spec_tx)
  subdev_rx = usrp.selected_subdev(urx, subdev_spec_rx)
  print "Using TX d'board %s" %(subdev_tx.side_and_name())
  print "Using RX d'board %s" %(subdev_rx.side_and_name())

  # Gain
  subdev_tx.set_gain((subdev_tx.gain_range()[0] + subdev_tx.gain_range()[1]) / 2)
  subdev_rx.set_gain((subdev_rx.gain_range()[0] + subdev_rx.gain_range()[1]) / 2)

  # Tune
  if not utx.tune(subdev_tx._which, subdev_tx, freq):
      DEBUG( "error tuning TX")
  if not urx.tune(subdev_rx._which, subdev_rx, freq):
      DEBUG( "error tuning RX")

  # Power on
  subdev_tx.set_enable(True)
  subdev_rx.set_enable(True)
  sys.stdout.flush()

  return utx, urx
Esempio n. 28
0
    def _setup_usrp_source(self):
        self.u = usrp.source_c (fusb_block_size=self._fusb_block_size,
                                fusb_nblocks=self._fusb_nblocks)
        adc_rate = self.u.adc_rate()

        # derive values of bitrate, samples_per_symbol, and decim from desired info
        (self._bitrate, self._samples_per_symbol, self._decim) = \
            pick_rx_bitrate(self._bitrate, self._demod_class.bits_per_symbol(), \
                            self._samples_per_symbol, self._decim, adc_rate)

        self.u.set_decim_rate(self._decim)

        # determine the daughterboard subdevice we're using
        if self._rx_subdev_spec is None:
            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        self.subdev = usrp.selected_subdev(self.u, self._rx_subdev_spec)

        self.u.set_mux(usrp.determine_rx_mux_value(self.u, self._rx_subdev_spec))
Esempio n. 29
0
    def _setup_usrp_source(self):
        self.u = usrp.source_c(self._which,
                               fusb_block_size=self._fusb_block_size,
                               fusb_nblocks=self._fusb_nblocks)
        adc_rate = self.u.adc_rate()

        # derive values of bitrate, samples_per_symbol, and decim from desired info
        (self._bitrate, self._samples_per_symbol, self._decim) = \
            pick_rx_bitrate(self._bitrate, self._demod_class.bits_per_symbol(), \
                            self._samples_per_symbol, self._decim, adc_rate)

        self.u.set_decim_rate(self._decim)

        # determine the daughterboard subdevice we're using
        if self._rx_subdev_spec is None:
            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        self.subdev = usrp.selected_subdev(self.u, self._rx_subdev_spec)

        self.u.set_mux(
            usrp.determine_rx_mux_value(self.u, self._rx_subdev_spec))
Esempio n. 30
0
    def __init__(self, subdev_spec, decim, gain=None, calibration=0.0):
	gr.hier_block2.__init__(self, "usrp_src",
				gr.io_signature(0, 0, 0),                    # Input signature
				gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

	self._decim = decim
        self._src = usrp.source_c()
        if subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(self._src)
        self._subdev = usrp.selected_subdev(self._src, subdev_spec)
        self._src.set_mux(usrp.determine_rx_mux_value(self._src, subdev_spec))
        self._src.set_decim_rate(self._decim)

	# If no gain specified, set to midrange
	if gain is None:
	    g = self._subdev.gain_range()
	    gain = (g[0]+g[1])/2.0

        self._subdev.set_gain(gain)
        self._cal = calibration
	self.connect(self._src, self)
Esempio n. 31
0
    def set_subdev (self, spec=None):
        """ assumes nchannels has been set """
        """ call set_freq after subdev is set """
        self.subdev = ()
        if self.fake_rf: return     # no subdev for fake rf
        """ get subdev spec """
        if spec is None:
            srx1 = usrp.pick_rx_subdevice(self.src)
        else:
            srx1 = spec

        """ configure USRP mux and set rx/tx subdev """
        ulist = [self.src]
        if self.nchannels == 1:
            assert len(ulist) == 1, "[radiorx]: Invalid number of USRP boards!"
            src = ulist[0]
            src.set_mux (usrp.determine_rx_mux_value(src, srx1) )
            self.subdev += (usrp.selected_subdev(src, srx1), )
            for s in self.subdev: exec("if not hasattr(s, '_u'): s._u = src")
        elif self.nchannels == 2:
            assert len(ulist) == 1, "[radiorx]: Invalid number of USRP boards!"
            srx2 = ((srx1[0]+1)%2, srx1[1])
            src = ulist[0]
            src.set_mux(gru.hexint(0x23012301) )
            #src.set_mux(gru.hexint(0x32103210) )
            self.subdev += (usrp.selected_subdev(src, srx1), )
            self.subdev += (usrp.selected_subdev(src, srx2), )
            for s in self.subdev: exec("if not hasattr(s, '_u'): s._u = src")
        elif self.nchannels == 4:
            assert len(ulist) == 2, "[radiorx]: Invalid number of USRP boards!"
            srx2 = ((srx1[0]+1)%2, srx1[1])
            for src in ulist:
                src.set_mux(gru.hexint(0x23012301) )
                self.subdev += (usrp.selected_subdev(src, srx1), )
                self.subdev += (usrp.selected_subdev(src, srx2), )
                for s in self.subdev: exec("if not hasattr(s, '_u'): s._u = src")
        else:
            return self.error("Unable to set subdev; invalid value for " \
                              + "nchannels=%d"%(self.nchannels) )
        self.set_auto_tr(True)  # enable Automatic Tx/Rx Switching
Esempio n. 32
0
    def __init__(self, subdev_spec, decim, gain=None, calibration=0.0):
        gr.hier_block2.__init__(
            self,
            "usrp_src",
            gr.io_signature(0, 0, 0),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex))  # Output signature

        self._decim = decim
        self._src = usrp.source_c()
        if subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(self._src)
        self._subdev = usrp.selected_subdev(self._src, subdev_spec)
        self._src.set_mux(usrp.determine_rx_mux_value(self._src, subdev_spec))
        self._src.set_decim_rate(self._decim)

        # If no gain specified, set to midrange
        if gain is None:
            g = self._subdev.gain_range()
            gain = (g[0] + g[1]) / 2.0

        self._subdev.set_gain(gain)
        self._cal = calibration
        self.connect(self._src, self)
Esempio n. 33
0
    def _setup_usrp_source(self):
        self.u_src = usrp.source_c(which = self._usrp,
                                   fusb_block_size = self._fusb_block_size,
                                   fusb_nblocks = self._fusb_nblocks)
        self.u_src.set_verbose(self._verbose)

        self.u_src.set_decim_rate(int(self.u_src.converter_rate() / self._sample_rate))

        # determine the daughterboard subdevice we're using
        if self._rx_subdev_spec is None:
            self._rx_subdev_spec = usrp.pick_rx_subdevice(self.u_src)

        self.u_src.set_mux(usrp.determine_rx_mux_value(self.u_src, self._rx_subdev_spec))
        self.rx_subdev = usrp.selected_subdev(self.u_src, self._rx_subdev_spec)
        self.rx_subdev.set_auto_tr(False)

        if self._rx_antenna != None:
            self.rx_subdev.select_rx_antenna(self._rx_antenna)

        gain = self._rx_gain
        if gain is None:
            gain = (self.rx_subdev.gain_range()[0] + self.rx_subdev.gain_range()[1]) / 2
        self.rx_subdev.set_gain(gain)
Esempio n. 34
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-m", "--dab-mode", type="int", default=1,
            help="DAB mode [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=206352000,
            help="Carrier frequency [default=%default]")
        parser.add_option("-g", "--gain", type="eng_float", default=8,
            help="USRP gain (dB) [default=%default]")
        parser.add_option("-n", "--config", type="string", default="channel.conf",
            help="DAB+ channel configuration file [default=%default]")
        
        (options, args) = parser.parse_args ()
        
        if len(args)>0:
            parser.print_help()
            raise SystemExit, 1
        
        self.conf=options.config
        
        ######## set up usrp
        self.u = usrp.source_c(decim_rate=32) # 2M sampling freq
        rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        #print "u.db(0,0).dbid() = ", self.u.db(0,0).dbid()
        #print "u.db(1,0).dbid() = ", self.u.db(1,0).dbid()
        #print "rx_subdev_spec = ", options.rx_subdev_spec
        
        mux=usrp.determine_rx_mux_value(self.u, rx_subdev_spec)
        #print "mux = ", mux
        self.u.set_mux(mux)

        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
        #print "Using RX d'board %s" % (self.subdev.side_and_name(),)
        input_rate = self.u.adc_freq() / self.u.decim_rate()
        #print "ADC sampling @ ", eng_notation.num_to_str(self.u.adc_freq())
        #print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.subdev.set_gain(options.gain)
        r = self.u.tune(0, self.subdev, options.freq)
        
        #print "freq range = [%s, %s]" % (eng_notation.num_to_str(self.subdev.freq_min()), eng_notation.num_to_str(self.subdev.freq_max()))
        if not r:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1
        
        
        mode=options.dab_mode
        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(0, mode)
        # depuncturer
        punc = dabp.depuncturer_fic(mode)
        I=punc.getI()
        # viterbi
        vit = dabp.vitdec(I)
        # descrambler
        scram = dabp.scrambler(I)
        # FIB sink
        self.dst = dabp.fib_sink()
        
        nullsink = gr.null_sink(gr.sizeof_char)
        # connect everything
        self.connect(self.u, nulldet)
        self.connect(self.u, (demod,0))
        self.connect(nulldet, (demod,1))
        self.connect((demod,0), demux, punc, vit, scram, self.dst)
        self.connect((demod,1), nullsink)
Esempio n. 35
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-d", "--decim", type="int", default=16,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option( "--no-hb", action="store_true", default=False,
                          help="don't use halfband filter in usrp")
        parser.add_option( "-s","--output-shorts", action="store_true", default=False,
                          help="output interleaved shorts in stead of complex floats")
        parser.add_option("-N", "--nsamples", type="eng_float", default=None,
                          help="number of samples to collect [default=+inf]")
        (options, args) = parser.parse_args ()
        if len(args) != 1:
            parser.print_help()
            raise SystemExit, 1
        filename = args[0]

        if options.freq is None:
            parser.print_help()
            sys.stderr.write('You must specify the frequency with -f FREQ\n');
            raise SystemExit, 1

        # build the graph
        if options.no_hb or (options.decim<8):
          self.fpga_filename="std_4rx_0tx.rbf" #Min decimation of this firmware is 4. contains 4 Rx paths without halfbands and 0 tx paths.
          if options.output_shorts:
            self.u = usrp.source_s(decim_rate=options.decim,fpga_filename=self.fpga_filename)
          else:
            self.u = usrp.source_c(decim_rate=options.decim,fpga_filename=self.fpga_filename)
        else:
          #standard fpga firmware "std_2rxhb_2tx.rbf" contains 2 Rx paths with halfband filters and 2 tx paths (the default) min decimation 8
          if options.output_shorts:
            self.u = usrp.source_s(decim_rate=options.decim)
          else:
            self.u = usrp.source_c(decim_rate=options.decim)
        if options.width_8:
            sample_width = 8
            sample_shift = 8
            format = self.u.make_format(sample_width, sample_shift)
            r = self.u.set_format(format)
        if options.output_shorts:
          self.dst = gr.file_sink(gr.sizeof_short, filename)
        else:
          self.dst = gr.file_sink(gr.sizeof_gr_complex, filename)
        if options.nsamples is None:
            self.connect(self.u, self.dst)
        else:
            if options.output_shorts:
              self.head = gr.head(gr.sizeof_short, int(options.nsamples)*2)
            else:
              self.head = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
            self.connect(self.u, self.head, self.dst)

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))

        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
        print "Using RX d'board %s" % (self.subdev.side_and_name(),)
        input_rate = self.u.adc_freq() / self.u.decim_rate()
        print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0]+g[1])/2

        self.subdev.set_gain(options.gain)

        r = self.u.tune(0, self.subdev, options.freq)
        if not r:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1
Esempio n. 36
0
    def __init__(self, subdev_spec, gain, audio_output):
        gr.hier_block2.__init__(
            self,
            "receive_path",
            gr.io_signature(0, 0, 0),  # Input signature
            gr.io_signature(0, 0, 0))  # Output signature

        self.u = usrp.source_c()
        adc_rate = self.u.adc_rate()

        self.if_rate = 256e3  # 256 kS/s
        usrp_decim = int(adc_rate // self.if_rate)
        if_decim = 4
        self.u.set_decim_rate(usrp_decim)
        self.quad_rate = self.if_rate // if_decim  #  64 kS/s
        audio_decim = 2
        self.audio_rate = self.quad_rate // audio_decim  #  32 kS/s

        if subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(self.u)
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "Using RX d'board %s" % (self.subdev.side_and_name(), )

        self.u.set_mux(usrp.determine_rx_mux_value(self.u, subdev_spec))

        # Create filter to get actual channel we want
        chan_coeffs = gr.firdes.low_pass(
            1.0,  # gain
            self.if_rate,  # sampling rate
            8e3,  # low pass cutoff freq
            2e3,  # width of trans. band
            gr.firdes.WIN_HANN)  # filter type

        print "len(rx_chan_coeffs) =", len(chan_coeffs)

        # Decimating Channel filter with frequency translation
        # complex in and out, float taps
        self.ddc = gr.freq_xlating_fir_filter_ccf(
            if_decim,  # decimation rate
            chan_coeffs,  # taps
            0,  # frequency translation amount
            self.if_rate)  # input sample rate

        if USE_SIMPLE_SQUELCH:
            self.squelch = gr.simple_squelch_cc(20)
        else:
            self.squelch = blks2.standard_squelch(self.audio_rate)

    # instantiate the guts of the single channel receiver
        self.fmrx = blks2.nbfm_rx(self.audio_rate, self.quad_rate)

        # audio gain / mute block
        self._audio_gain = gr.multiply_const_ff(1.0)

        # sound card as final sink
        audio_sink = audio.sink(int(self.audio_rate), audio_output)

        # now wire it all together
        if USE_SIMPLE_SQUELCH:
            self.connect(self.u, self.ddc, self.squelch, self.fmrx,
                         self._audio_gain, audio_sink)
        else:
            self.connect(self.u, self.ddc, self.fmrx, self.squelch,
                         self._audio_gain, audio_sink)

        if gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            gain = float(g[0] + g[1]) / 2

        self.set_gain(gain)

        v = self.volume_range()
        self.set_volume((v[0] + v[1]) / 2)
        s = self.squelch_range()
        self.set_squelch((s[0] + s[1]) / 2)
Esempio n. 37
0
    def __init__(self, subdev_spec, center_freq, offset_freq, decim, squelch, gain):

        gr.top_block.__init__(self)

        # configure USRP
        u = usrp.source_c()
        u.set_decim_rate(decim)
        capture_rate = u.adc_freq() / u.decim_rate()
        if subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(u)
        subdev = usrp.selected_subdev(u, subdev_spec)
        u.set_mux(usrp.determine_rx_mux_value(u, subdev_spec))
        print "Using RX d'board %s" % (subdev.side_and_name(),)

        if gain is None:
            g = subdev.gain_range()
            gain = float(g[0] + g[1]) / 2
        subdev.set_gain(gain)
        u.tune(0, subdev, center_freq)
                
        # setup receiver attributes
        channel_rate = 125000
        symbol_rate = 4800
        
        # channel filter
        self.channel_offset = offset_freq
        channel_decim = capture_rate // channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2;
        trans_centre = trans_width + (trans_width / 2)
        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, self.channel_offset, capture_rate)
        self.connect(u, self.channel_filter)

        # power squelch
        power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True)
        self.connect(self.channel_filter, power_squelch)

        # FM demodulator
        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        self.connect(power_squelch, fm_demod)

        # symbol filter        
        symbol_decim = 1
        samples_per_symbol = channel_rate // symbol_rate
        symbol_coeffs = (1.0/samples_per_symbol,) * samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        self.connect(fm_demod, symbol_filter)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate)
        self.connect(symbol_filter, demod_fsk4)

        # symbol slicer
        levels = [ -2.0, 0.0, 2.0, 4.0 ]
        slicer = op25.fsk4_slicer_fb(levels)
        self.connect(demod_fsk4, slicer)

        # frame decoder
        decoder = op25.decoder_bf()
        self.connect(slicer, decoder)

        # try to connect audio output device
        try:
            audio_sink = audio.sink(8000, "plughw:0,0", True)
            self.connect(decoder, audio_sink)
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)
            self.connect(decoder, sink)
Esempio n. 38
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self, "usrp_flex")
        self.options = options
        self.offset = 0.0
        self.adj_time = time.time()
        self.verbose = options.verbose

        if options.from_file is None:
            # Set up USRP source with specified RX daughterboard
            self.src = usrp.source_c()
            if options.rx_subdev_spec == None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(self.src)
            self.subdev = usrp.selected_subdev(self.src,
                                               options.rx_subdev_spec)
            self.src.set_mux(
                usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))

            # Grab 250 KHz of spectrum (sample rate becomes 250 ksps complex)
            self.src.set_decim_rate(256)

            # If no gain specified, set to midrange
            if options.gain is None:
                g = self.subdev.gain_range()
                options.gain = (g[0] + g[1]) / 2.0
            self.subdev.set_gain(options.gain)

            # Tune daughterboard
            actual_frequency = options.frequency + options.calibration
            tune_result = usrp.tune(self.src, 0, self.subdev, actual_frequency)
            if not tune_result:
                sys.stderr.write("Failed to set center frequency to " +
                                 ` actual_frequency ` + "\n")
                sys.exit(1)

            if options.verbose:
                print "Using RX daughterboard", self.subdev.side_and_name()
                print "USRP gain is", options.gain
                print "USRP tuned to", actual_frequency

        else:
            # Use supplied file as source of samples
            self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file)
            if options.verbose:
                print "Reading samples from", options.from_file

        if options.log and not options.from_file:
            usrp_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
            self.connect(self.src, usrp_sink)

        # Set up 22KHz-wide bandpass about center frequency. Decimate by 10
        # to get channel rate of 25Ksps
        taps = optfir.low_pass(
            1.0,  # Filter gain
            250e3,  # Sample rate
            11000,  # One-sided modulation bandwidth
            12500,  # One-sided channel bandwidth
            0.1,  # Passband ripple
            60)  # Stopband attenuation

        if options.verbose:
            print "Channel filter has", len(taps), "taps."

        self.chan = gr.freq_xlating_fir_filter_ccf(
            10,  # Decimation rate
            taps,  # Filter taps
            0.0,  # Offset frequency
            250e3)  # Sample rate

        if options.log:
            chan_sink = gr.file_sink(gr.sizeof_gr_complex, 'chan.dat')
            self.connect(self.chan, chan_sink)

        # FLEX protocol demodulator
        self.flex = pager.flex_demod(queue, options.frequency, options.verbose,
                                     options.log)

        self.connect(self.src, self.chan, self.flex)
Esempio n. 39
0
def main():
    parser = OptionParser(option_class=eng_option)
    parser.add_option("-R",
                      "--rx-subdev-spec",
                      type="subdev",
                      default=None,
                      help="select USRP Rx side A or B (default=A)")
    parser.add_option("-f",
                      "--freq",
                      type="eng_float",
                      default=144.800e6,
                      help="set frequency to FREQ",
                      metavar="FREQ")
    parser.add_option("-g",
                      "--gain",
                      type="eng_float",
                      default=None,
                      help="set gain in dB (default is midpoint)")
    parser.add_option("-d",
                      "--do-logging",
                      action="store_true",
                      default=False,
                      help="enable logging on datafiles")
    parser.add_option("-s",
                      "--use-datafile",
                      action="store_true",
                      default=False,
                      help="use usrp.dat (256kbps) as input")
    (options, args) = parser.parse_args()
    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    markfreq = 2200
    spacefreq = 1200
    bitrate = 1200
    usrp_decim = 250
    if_rate = 64e6 / usrp_decim  #256e3
    sf = (if_rate * 3) / 5  #153600
    bit_oversampling = 8
    sw_decim = int(sf / bitrate / bit_oversampling)  #8
    bf = sf / sw_decim

    symdev = abs(markfreq - spacefreq) / 2
    symcf = min(markfreq, spacefreq) + symdev
    nbfmdev = 3e3
    nbfmk = if_rate / (2 * pi * nbfmdev)
    symk = bf / (2 * pi * symdev)

    fg = gr.flow_graph()

    if options.do_logging:
        logger1 = gr.file_sink(gr.sizeof_gr_complex, "usrpout.dat")
        logger2 = gr.file_sink(gr.sizeof_float, "demod.dat")
        logger3 = gr.file_sink(gr.sizeof_float, "clkrec.dat")
        logger4 = gr.file_sink(gr.sizeof_char, "slicer.dat")

    if options.use_datafile:
        src = gr.file_source(gr.sizeof_gr_complex, "usrp.dat")
    else:
        u = usrp.source_c()
        u.set_decim_rate(usrp_decim)
        if options.rx_subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(u)
        else:
            subdev_spec = options.rx_subdev_spec
        subdev = usrp.selected_subdev(u, subdev_spec)
        print "Using RX d'board %s" % (subdev.side_and_name(), )
        u.set_mux(usrp.determine_rx_mux_value(u, subdev_spec))
        print "MUX:%x" % (usrp.determine_rx_mux_value(u, subdev_spec))
        if options.gain is None:
            g = subdev.gain_range()
            gain = float(g[0] + g[1]) / 2
        else:
            gain = options.gain
        subdev.set_gain(gain)
        print "Gain set to", str(gain)
        r = usrp.tune(u, 0, subdev, options.freq)
        if r:
            print "Frequency set to", options.freq
        else:
            print "Frequency set to", options.freq, "failed"
        src = u

    chan_taps = gr.firdes.low_pass(1, if_rate, 13e3, 4e3, gr.firdes.WIN_HANN)
    chan = gr.fir_filter_ccf(1, chan_taps)  #256e3

    dee = blks.fm_deemph(fg, if_rate, 75e-6)

    fmdem = gr.quadrature_demod_cf(nbfmk)

    res_taps = blks.design_filter(3, 5, 0.4)
    res = blks.rational_resampler_fff(fg, 3, 5, res_taps)  #153600

    lo = gr.sig_source_c(sf, gr.GR_SIN_WAVE, -symcf, 1)
    mix = gr.multiply_cc()
    r2c = gr.float_to_complex()
    lp_taps = gr.firdes.low_pass(sw_decim, sf, 600, 2e3, gr.firdes.WIN_HANN)
    lp = gr.fir_filter_ccf(sw_decim, lp_taps)

    dem = gr.quadrature_demod_cf(symk)

    alpha = 0.0001
    freqoff = gr.single_pole_iir_filter_ff(alpha)
    sub = gr.sub_ff()

    _def_gain_mu = 0.05
    _def_mu = 0.5
    _def_freq_error = 0.00
    _def_omega_relative_limit = 0.005

    _omega = bit_oversampling * (1 + _def_freq_error)
    _gain_omega = .25 * _def_gain_mu * _def_gain_mu

    clkrec = gr.clock_recovery_mm_ff(_omega, _gain_omega, _def_mu,
                                     _def_gain_mu, _def_omega_relative_limit)

    slicer = gr.binary_slicer_fb()

    pktq = gr.msg_queue()
    sink = packetradio.hdlc_framer(pktq, 0)
    watcher = queue_watcher_thread(pktq, rx_callback)

    fg.connect(src, chan, fmdem, dee, res, r2c, (mix, 0))
    fg.connect(lo, (mix, 1))
    fg.connect(mix, lp, dem)
    fg.connect(dem, (sub, 0))
    fg.connect(dem, freqoff, (sub, 1))
    fg.connect(sub, clkrec, slicer)
    fg.connect(slicer, sink)

    if options.do_logging:
        fg.connect(src, logger1)
        fg.connect(sub, logger2)
        fg.connect(clkrec, logger3)
        fg.connect(slicer, logger4)

    fg.start()
    fg.wait()
Esempio n. 40
0
    def __init__(self, subdev_spec, center_freq, offset_freq, decim, squelch,
                 gain):

        gr.top_block.__init__(self)

        # configure USRP
        u = usrp.source_c()
        u.set_decim_rate(decim)
        capture_rate = u.adc_freq() / u.decim_rate()
        if subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(u)
        subdev = usrp.selected_subdev(u, subdev_spec)
        u.set_mux(usrp.determine_rx_mux_value(u, subdev_spec))
        print "Using RX d'board %s" % (subdev.side_and_name(), )

        if gain is None:
            g = subdev.gain_range()
            gain = float(g[0] + g[1]) / 2
        subdev.set_gain(gain)
        u.tune(0, subdev, center_freq)

        # setup receiver attributes
        channel_rate = 125000
        symbol_rate = 4800

        # channel filter
        self.channel_offset = offset_freq
        channel_decim = capture_rate // channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2
        trans_centre = trans_width + (trans_width / 2)
        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, self.channel_offset, capture_rate)
        self.connect(u, self.channel_filter)

        # power squelch
        power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True)
        self.connect(self.channel_filter, power_squelch)

        # FM demodulator
        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        self.connect(power_squelch, fm_demod)

        # symbol filter
        symbol_decim = 1
        samples_per_symbol = channel_rate // symbol_rate
        symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        self.connect(fm_demod, symbol_filter)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq,
                                           self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate)
        self.connect(symbol_filter, demod_fsk4)

        # symbol slicer
        levels = [-2.0, 0.0, 2.0, 4.0]
        slicer = op25.fsk4_slicer_fb(levels)
        self.connect(demod_fsk4, slicer)

        # frame decoder
        decoder = op25.decoder_bf()
        self.connect(slicer, decoder)

        # try to connect audio output device
        try:
            audio_sink = audio.sink(8000, "plughw:0,0", True)
            self.connect(decoder, audio_sink)
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)
            self.connect(decoder, sink)
Esempio n. 41
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self, "usrp_flex")
        self.options = options
	self.offset = 0.0
	self.adj_time = time.time()
	self.verbose = options.verbose
			
	if options.from_file is None:
            # Set up USRP source with specified RX daughterboard
            self.src = usrp.source_c()
            if options.rx_subdev_spec == None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(self.src)
            self.subdev = usrp.selected_subdev(self.src, options.rx_subdev_spec)
            self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))

            # Grab 250 KHz of spectrum (sample rate becomes 250 ksps complex)
            self.src.set_decim_rate(256)
	    	    
            # If no gain specified, set to midrange
            if options.gain is None:
                g = self.subdev.gain_range()
                options.gain = (g[0]+g[1])/2.0
            self.subdev.set_gain(options.gain)

            # Tune daughterboard
            actual_frequency = options.frequency+options.calibration
            tune_result = usrp.tune(self.src, 0, self.subdev, actual_frequency)
            if not tune_result:
                sys.stderr.write("Failed to set center frequency to "+`actual_frequency`+"\n")
                sys.exit(1)

            if options.verbose:
                print "Using RX daughterboard", self.subdev.side_and_name()
                print "USRP gain is", options.gain
                print "USRP tuned to", actual_frequency
            
        else:
            # Use supplied file as source of samples
            self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file)
            if options.verbose:
                print "Reading samples from", options.from_file
	    
        if options.log and not options.from_file:
            usrp_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
            self.connect(self.src, usrp_sink)

        # Set up 22KHz-wide bandpass about center frequency. Decimate by 10
        # to get channel rate of 25Ksps
        taps = optfir.low_pass(1.0,   # Filter gain
                               250e3, # Sample rate
                               11000, # One-sided modulation bandwidth
                               12500, # One-sided channel bandwidth
                               0.1,   # Passband ripple
                               60)    # Stopband attenuation
	
	if options.verbose:
	    print "Channel filter has", len(taps), "taps."

        self.chan = gr.freq_xlating_fir_filter_ccf(10,    # Decimation rate
                                                   taps,  # Filter taps
                                                   0.0,   # Offset frequency
                                                   250e3) # Sample rate

	if options.log:
	    chan_sink = gr.file_sink(gr.sizeof_gr_complex, 'chan.dat')
	    self.connect(self.chan, chan_sink)

        # FLEX protocol demodulator
        self.flex = pager.flex_demod(queue, options.frequency, options.verbose, options.log)

        self.connect(self.src, self.chan, self.flex)
Esempio n. 42
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-d", "--decim", type="int", default=128,
                          help="set selfpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=0.0,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-n", "--nchan", type="intx", default=2,
                          help="set nchannels to NCHAN")
        parser.add_option("-N", "--nsamples", type="eng_float", default=None,
                          help="number of samples to collect [default=+inf]")
        parser.add_option ("-o", "--output-file-m", default="usrp_rx_m.dat",
                       help="write master data to FILE", metavar="FILE")
        parser.add_option ("--output-file-m2", default="usrp_rx_m2.dat",
                       help="write master data from second channel to FILE", metavar="FILE")
        parser.add_option ("-p", "--output-file-s", default="usrp_rx_s.dat",
                       help="write slave data to FILE", metavar="FILE")
        parser.add_option ("--output-file-s2", default="usrp_rx_s2.dat",
                       help="write slave data from second channel to FILE", metavar="FILE")
        parser.add_option("-x", "--master-serialno", type="string", default=None, 
                          help="Serial_no of the usrp which should be the MASTER (default= select any)")
        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        if options.freq is None:
            parser.print_help()
            sys.stderr.write('You must specify the frequency with -f FREQ\n');
            raise SystemExit, 1

        # build the graph
        self.multi=usrp_multi.multi_source_align( fg=self, master_serialno=options.master_serialno, decim=options.decim, 
                                                  nchan=options.nchan )
        self.um=self.multi.get_master_usrp()
        self.us=self.multi.get_slave_usrp()

        dst_m=gr.file_sink (gr.sizeof_gr_complex, options.output_file_m)
        dst_s=gr.file_sink (gr.sizeof_gr_complex, options.output_file_s)
        if options.nsamples is None:
            self.connect((self.multi.get_master_source_c(),1),dst_m)
            self.connect((self.multi.get_slave_source_c(),1),dst_s)
        else:
            head_m = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
            head_s = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
            self.connect((self.multi.get_master_source_c(),1),head_m,dst_m)
            self.connect((self.multi.get_slave_source_c(),1),head_s,dst_s)

        if(4==options.nchan):
            dst_m2=gr.file_sink (gr.sizeof_gr_complex, options.output_file_m2)
            dst_s2=gr.file_sink (gr.sizeof_gr_complex, options.output_file_s2)
            if options.nsamples is None:
                self.connect((self.multi.get_master_source_c(),2),dst_m2)
                self.connect((self.multi.get_slave_source_c(),2),dst_s2) 
            else:
                head_m2 = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
                head_s2 = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
                self.connect((self.multi.get_master_source_c(),2),head_m2,dst_m2)
                self.connect((self.multi.get_slave_source_c(),2),head_s2,dst_s2) 

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_rx_subdevice(self.um)

        if (options.nchan!=4):
          mux=usrp.determine_rx_mux_value(self.um, options.rx_subdev_spec)
          mux= (mux<<8 & 0xffffffff) | (mux & 0xff)
          self.um.set_mux(mux)
          self.us.set_mux(mux)

        # determine the daughterboard subdevice we're using
        self.subdevm = usrp.selected_subdev(self.um, options.rx_subdev_spec)
        self.subdevs = usrp.selected_subdev(self.us, options.rx_subdev_spec)
        print "Using MASTER RX d'board %s" % (self.subdevm.side_and_name(),)
        print "Using SLAVE RX d'board %s" % (self.subdevs.side_and_name(),)
        input_rate = self.um.adc_freq() / self.um.decim_rate()
        print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdevm.gain_range()
            options.gain = float(g[0]+g[1])/2

        self.multi.set_gain_all_rx(options.gain)
        result,r1,r2,r3,r4 = self.multi.tune_all_rx(options.freq)
        if not result:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1
Esempio n. 43
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-m", "--dab-mode", type="int", default=1,
            help="DAB mode [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=206352000,
            help="Carrier frequency [default=%default]")
        parser.add_option("-g", "--gain", type="eng_float", default=8,
            help="USRP gain (dB) [default=%default]")
        parser.add_option("-i", "--subchid", type="int", default=-1,
            help="Subchannel ID")
        parser.add_option("-n", "--config", type="string", default="channel3.conf",
            help="DAB+ channel configuration file [default=%default]")
        parser.add_option("-o", "--output", type="string", default="-",
            help="Output AAC file [default=%default]")
        parser.add_option("-p", "--mplayer", action="store_true", default=False,
            help="Play the program by MPlayer [default=%default, stdout]")
        (options, args) = parser.parse_args ()
        
        if len(args)>0:
            parser.print_help()
            raise SystemExit, 1
        
        ######## set up usrp
        self.u = usrp.source_c(decim_rate=32) # 2M sampling freq
        rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        #print "u.db(0,0).dbid() = ", self.u.db(0,0).dbid()
        #print "u.db(1,0).dbid() = ", self.u.db(1,0).dbid()
        #print "rx_subdev_spec = ", options.rx_subdev_spec
        
        mux=usrp.determine_rx_mux_value(self.u, rx_subdev_spec)
        #print "mux = ", mux
        self.u.set_mux(mux)

        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
        #print "Using RX d'board %s" % (self.subdev.side_and_name(),)
        input_rate = self.u.adc_freq() / self.u.decim_rate()
        #print "ADC sampling @ ", eng_notation.num_to_str(self.u.adc_freq())
        #print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.subdev.set_gain(options.gain)
        r = self.u.tune(0, self.subdev, options.freq)
        
        #print "freq range = [%s, %s]" % (eng_notation.num_to_str(self.subdev.freq_min()), eng_notation.num_to_str(self.subdev.freq_max()))
        if not r:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1
        
        
        # channel configuration
        cc = dabp.channel_conf(options.config)
        sys.stderr.write("Playing Channel: "+cc.get_label(options.subchid)+"\n")
        
        start_addr = cc.get_start_addr(options.subchid)
        subchsz = cc.get_subchsz(options.subchid)
        optprot = cc.get_optprot(options.subchid)
        #print "start_addr=%d, subchsz=%d, optprot=%d" % (start_addr, subchsz, optprot)
        
        mode=options.dab_mode
        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 options.mplayer:
            mplayer = subprocess.Popen(['mplayer', '-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, options.output)
        
        nullsink = gr.null_sink(gr.sizeof_char)
        # connect everything
        self.connect(self.u, nulldet)
        self.connect(self.u, (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)
Esempio n. 44
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] output_filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option(
            "-d",
            "--decim",
            type="int",
            default=16,
            help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-8",
                          "--width-8",
                          action="store_true",
                          default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("--no-hb",
                          action="store_true",
                          default=False,
                          help="don't use halfband filter in usrp")
        parser.add_option(
            "-s",
            "--output-shorts",
            action="store_true",
            default=False,
            help="output interleaved shorts in stead of complex floats")
        parser.add_option("-N",
                          "--nsamples",
                          type="eng_float",
                          default=None,
                          help="number of samples to collect [default=+inf]")
        (options, args) = parser.parse_args()
        if len(args) != 1:
            parser.print_help()
            raise SystemExit, 1
        filename = args[0]

        if options.freq is None:
            parser.print_help()
            sys.stderr.write('You must specify the frequency with -f FREQ\n')
            raise SystemExit, 1

        # build the graph
        if options.no_hb or (options.decim < 8):
            self.fpga_filename = "std_4rx_0tx.rbf"  #Min decimation of this firmware is 4. contains 4 Rx paths without halfbands and 0 tx paths.
            if options.output_shorts:
                self.u = usrp.source_s(decim_rate=options.decim,
                                       fpga_filename=self.fpga_filename)
            else:
                self.u = usrp.source_c(decim_rate=options.decim,
                                       fpga_filename=self.fpga_filename)
        else:
            #standard fpga firmware "std_2rxhb_2tx.rbf" contains 2 Rx paths with halfband filters and 2 tx paths (the default) min decimation 8
            if options.output_shorts:
                self.u = usrp.source_s(decim_rate=options.decim)
            else:
                self.u = usrp.source_c(decim_rate=options.decim)
        if options.width_8:
            sample_width = 8
            sample_shift = 8
            format = self.u.make_format(sample_width, sample_shift)
            r = self.u.set_format(format)
        if options.output_shorts:
            self.dst = gr.file_sink(gr.sizeof_short, filename)
        else:
            self.dst = gr.file_sink(gr.sizeof_gr_complex, filename)
        if options.nsamples is None:
            self.connect(self.u, self.dst)
        else:
            if options.output_shorts:
                self.head = gr.head(gr.sizeof_short, int(options.nsamples) * 2)
            else:
                self.head = gr.head(gr.sizeof_gr_complex,
                                    int(options.nsamples))
            self.connect(self.u, self.head, self.dst)

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        self.u.set_mux(
            usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))

        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
        print "Using RX d'board %s" % (self.subdev.side_and_name(), )
        input_rate = self.u.adc_freq() / self.u.decim_rate()
        print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        self.subdev.set_gain(options.gain)

        r = self.u.tune(0, self.subdev, options.freq)
        if not r:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1
Esempio n. 45
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename. \n Special output_filename \"sdl\" will use video_sink_sdl as realtime output window. " \
              "You then need to have gr-video-sdl installed. \n" \
              "Make sure your input capture file containes interleaved shorts not complex floats"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-c", "--contrast", type="eng_float", default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b", "--brightness", type="eng_float", default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option("-d", "--decim", type="int", default=8,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-i", "--in-filename", type="string", default=None,
                          help="Use input file as source. samples must be interleaved shorts \n " +
                               "Use usrp_rx_file.py or usrp_rx_cfile.py --output-shorts. \n"
                               "Special name \"usrp\"  results in realtime capturing and processing using usrp. \n" +
                               "You then probably need a decimation factor of 64 or higher.")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                          help="set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-p", "--pal", action="store_true", default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n", "--ntsc", action="store_true", default=False,
                          help="NTSC video format")
        parser.add_option("-r", "--repeat", action="store_false", default=True,
                          help="repeat in_file in a loop")
        parser.add_option("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("-N", "--nframes", type="eng_float", default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option( "--no-hb", action="store_true", default=False,
                          help="don't use halfband filter in usrp")
        (options, args) = parser.parse_args ()
        if not (len(args) == 1):
            parser.print_help()
            sys.stderr.write('You must specify the output. FILENAME or sdl \n');
            sys.exit(1)
        
        filename = args[0]

        if options.in_filename is None:
            parser.print_help()
            sys.stderr.write('You must specify the input -i FILENAME or -i usrp\n');
            raise SystemExit, 1

        if not (filename=="sdl"):
          options.repeat=False

        if not (options.in_filename=="usrp"):
          self.filesource = gr.file_source(gr.sizeof_short,options.in_filename,options.repeat) # file is data source, capture with usr_rx_csfile.py
          self.istoc = gr.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          self.adc_rate=64e6
          self.src=self.istoc
        else:
          if options.freq is None:
            parser.print_help()
            sys.stderr.write('You must specify the frequency with -f FREQ\n');
            raise SystemExit, 1
          if abs(options.freq) < 1e6:
              options.freq *= 1e6
          if options.no_hb or (options.decim<8):
            self.fpga_filename="std_4rx_0tx.rbf" #contains 4 Rx paths without halfbands and 0 tx paths
          else:
            self.fpga_filename="std_2rxhb_2tx.rbf" # contains 2 Rx paths with halfband filters and 2 tx paths (the default)

          # build the graph
          self.u = usrp.source_c(decim_rate=options.decim,fpga_filename=self.fpga_filename)
          self.src=self.u
          if options.width_8:
              sample_width = 8
              sample_shift = 8
              format = self.u.make_format(sample_width, sample_shift)
              r = self.u.set_format(format)
          self.adc_rate=self.u.adc_freq()
          if options.rx_subdev_spec is None:
              options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
          self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
          # determine the daughterboard subdevice we're using
          self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
          print "Using RX d'board %s" % (self.subdev.side_and_name(),)

          if options.gain is None:
              # if no gain was specified, use the mid-point in dB
              g = self.subdev.gain_range()
              options.gain = float(g[0]+g[1])/2
          self.subdev.set_gain(options.gain)

          r = self.u.tune(0, self.subdev, options.freq)
          if not r:
              sys.stderr.write('Failed to set frequency\n')
              raise SystemExit, 1

        input_rate = self.adc_rate / options.decim
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel=gr.add_const_ff(options.brightness +255.0)
        self.invert_and_scale = gr.multiply_const_ff (-options.contrast *128.0*255.0/(200.0))
        self.f2uc=gr.float_to_uchar()

          # sdl window as final sink
        if not (options.pal or options.ntsc):
          options.pal=True #set default to PAL
        if options.pal:
          lines_per_frame=625.0
          frames_per_sec=25.0
          show_width=768
        elif options.ntsc:
          lines_per_frame=525.0
          frames_per_sec=29.97002997
          show_width=640
        width=int(input_rate/(lines_per_frame*frames_per_sec))
        height=int(lines_per_frame)

        if filename=="sdl":
          #Here comes the tv screen, you have to build and install gr-video-sdl for this (subproject of gnuradio, only in cvs for now)
          try:
            video_sink = video_sdl.sink_uc ( frames_per_sec, width, height,0,show_width,height)
          except:
            print "gr-video-sdl is not installed"
            print "realtime \"sdl\" video output window is not available"
            raise SystemExit, 1
          self.dst=video_sink
        else:
          print "You can use the imagemagick display tool to show the resulting imagesequence"
          print "use the following line to show the demodulated TV-signal:"
          print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" +filename
          print "(Use the spacebar to advance to next frames)" 
          file_sink=gr.file_sink(gr.sizeof_char, filename)
          self.dst =file_sink 

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.head(gr.sizeof_gr_complex, int(options.nframes*width*height))
            self.connect(self.src, self.head, self.agc)

        self.connect (self.agc,self.am_demod,self.invert_and_scale, self.set_blacklevel,self.f2uc,self.dst)
Esempio n. 46
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-m",
                          "--dab-mode",
                          type="int",
                          default=1,
                          help="DAB mode [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=206352000,
                          help="Carrier frequency [default=%default]")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=8,
                          help="USRP gain (dB) [default=%default]")
        parser.add_option(
            "-n",
            "--config",
            type="string",
            default="channel.conf",
            help="DAB+ channel configuration file [default=%default]")

        (options, args) = parser.parse_args()

        if len(args) > 0:
            parser.print_help()
            raise SystemExit, 1

        self.conf = options.config

        ######## set up usrp
        self.u = usrp.source_c(decim_rate=32)  # 2M sampling freq
        rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        #print "u.db(0,0).dbid() = ", self.u.db(0,0).dbid()
        #print "u.db(1,0).dbid() = ", self.u.db(1,0).dbid()
        #print "rx_subdev_spec = ", options.rx_subdev_spec

        mux = usrp.determine_rx_mux_value(self.u, rx_subdev_spec)
        #print "mux = ", mux
        self.u.set_mux(mux)

        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
        #print "Using RX d'board %s" % (self.subdev.side_and_name(),)
        input_rate = self.u.adc_freq() / self.u.decim_rate()
        #print "ADC sampling @ ", eng_notation.num_to_str(self.u.adc_freq())
        #print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.subdev.set_gain(options.gain)
        r = self.u.tune(0, self.subdev, options.freq)

        #print "freq range = [%s, %s]" % (eng_notation.num_to_str(self.subdev.freq_min()), eng_notation.num_to_str(self.subdev.freq_max()))
        if not r:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1

        mode = options.dab_mode
        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(0, mode)
        # depuncturer
        punc = dabp.depuncturer_fic(mode)
        I = punc.getI()
        # viterbi
        vit = dabp.vitdec(I)
        # descrambler
        scram = dabp.scrambler(I)
        # FIB sink
        self.dst = dabp.fib_sink()

        nullsink = gr.null_sink(gr.sizeof_char)
        # connect everything
        self.connect(self.u, nulldet)
        self.connect(self.u, (demod, 0))
        self.connect(nulldet, (demod, 1))
        self.connect((demod, 0), demux, punc, vit, scram, self.dst)
        self.connect((demod, 1), nullsink)
    def __init__(self):
        gr.flow_graph.__init__(self)

        usage="%prog: [options] output_filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-d", "--decim", type="int", default=128,
                          help="set selfpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=0.0,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-n", "--nchan", type="intx", default=2,
                          help="set nchannels to NCHAN")
        parser.add_option("-N", "--nsamples", type="eng_float", default=None,
                          help="number of samples to collect [default=+inf]")
        parser.add_option ("-o", "--output-file-m", default="usrp_rx_m.dat",
                       help="write master data to FILE", metavar="FILE")
        parser.add_option ("--output-file-m2", default="usrp_rx_m2.dat",
                       help="write master data from second channel to FILE", metavar="FILE")
        parser.add_option ("-p", "--output-file-s", default="usrp_rx_s.dat",
                       help="write slave data to FILE", metavar="FILE")
        parser.add_option ("--output-file-s2", default="usrp_rx_s2.dat",
                       help="write slave data from second channel to FILE", metavar="FILE")
        parser.add_option("-x", "--master-serialno", type="string", default=None, 
                          help="Serial_no of the usrp which should be the MASTER (default= select any)")
        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        if options.freq is None:
            parser.print_help()
            sys.stderr.write('You must specify the frequency with -f FREQ\n');
            raise SystemExit, 1

        # build the graph
        self.multi=usrp_multi.multi_source_align( fg=self, master_serialno=options.master_serialno, decim=options.decim, 
                                                  nchan=options.nchan )
        self.um=self.multi.get_master_usrp()
        self.us=self.multi.get_slave_usrp()

        dst_m=gr.file_sink (gr.sizeof_gr_complex, options.output_file_m)
        dst_s=gr.file_sink (gr.sizeof_gr_complex, options.output_file_s)
        if options.nsamples is None:
            self.connect((self.multi.get_master_source_c(),1),dst_m)
            self.connect((self.multi.get_slave_source_c(),1),dst_s)
        else:
            head_m = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
            head_s = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
            self.connect((self.multi.get_master_source_c(),1),head_m,dst_m)
            self.connect((self.multi.get_slave_source_c(),1),head_s,dst_s)

        if(4==options.nchan):
            dst_m2=gr.file_sink (gr.sizeof_gr_complex, options.output_file_m2)
            dst_s2=gr.file_sink (gr.sizeof_gr_complex, options.output_file_s2)
            if options.nsamples is None:
                self.connect((self.multi.get_master_source_c(),2),dst_m2)
                self.connect((self.multi.get_slave_source_c(),2),dst_s2) 
            else:
                head_m2 = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
                head_s2 = gr.head(gr.sizeof_gr_complex, int(options.nsamples))
                self.connect((self.multi.get_master_source_c(),2),head_m2,dst_m2)
                self.connect((self.multi.get_slave_source_c(),2),head_s2,dst_s2) 

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_rx_subdevice(self.um)

        if (options.nchan!=4):
          mux=usrp.determine_rx_mux_value(self.um, options.rx_subdev_spec)
          mux= (mux<<8 & 0xffffffff) | (mux & 0xff)
          self.um.set_mux(mux)
          self.us.set_mux(mux)

        # determine the daughterboard subdevice we're using
        self.subdevm = usrp.selected_subdev(self.um, options.rx_subdev_spec)
        self.subdevs = usrp.selected_subdev(self.us, options.rx_subdev_spec)
        print "Using MASTER RX d'board %s" % (self.subdevm.side_and_name(),)
        print "Using SLAVE RX d'board %s" % (self.subdevs.side_and_name(),)
        input_rate = self.um.adc_freq() / self.um.decim_rate()
        print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdevm.gain_range()
            options.gain = float(g[0]+g[1])/2

        self.multi.set_gain_all_rx(options.gain)
        result,r1,r2,r3,r4 = self.multi.tune_all_rx(options.freq)
        if not result:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1
Esempio n. 48
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self, "usrp_flex")
        self.options = options
        self.offset = 0.0
        self.file_offset = 0.0
        self.adj_time = time.time()
        self.verbose = options.verbose

        if options.from_file is None:
            # Set up USRP source with specified RX daughterboard
            self.src = usrp.source_c()
            if options.rx_subdev_spec == None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(self.src)
            self.subdev = usrp.selected_subdev(self.src,
                                               options.rx_subdev_spec)
            self.src.set_mux(
                usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))

            # set FPGA decimation rate
            self.src.set_decim_rate(options.decim)

            # If no gain specified, set to midrange
            if options.gain is None:
                g = self.subdev.gain_range()
                options.gain = (g[0] + g[1]) / 2.0
            self.subdev.set_gain(options.gain)

            # Tune daughterboard
            actual_frequency = options.frequency + options.calibration
            tune_result = usrp.tune(self.src, 0, self.subdev, actual_frequency)
            if not tune_result:
                sys.stderr.write("Failed to set center frequency to " +
                                 ` actual_frequency ` + "\n")
                sys.exit(1)

            if options.verbose:
                print "Using RX daughterboard", self.subdev.side_and_name()
                print "USRP gain is", options.gain
                print "USRP tuned to", actual_frequency

        else:
            # Use supplied file as source of samples
            self.file_offset = options.calibration
            print "File input offset", self.offset
            self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file)
            if options.verbose:
                print "Reading samples from", options.from_file

        if options.log and not options.from_file:
            usrp_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
            self.connect(self.src, usrp_sink)

        # following is rig to allow fast and easy swapping of signal configuration
        # blocks between this example and the oscope example which uses self.msgq
        self.msgq = queue

        #-------------------------------------------------------------------------------

        if options.protocol == 0:

            # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel,
            self.symbol_rate = 9600  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
            self.channel_decimation = 10  # decimation (final rate should be at least several symbol rate)
            self.max_frequency_offset = 12000.0  # coarse carrier tracker leash, ~ half a channel either way
            self.symbol_deviation = 1200.0  # this is frequency offset from center of channel to +1 / -1 symbols
            self.input_sample_rate = 64e6 / options.decim  # for USRP: 64MHz / FPGA decimation rate
            self.protocol_processing = fsk4.rdlap_f(
                self.msgq,
                0)  # desired protocol processing block selected here

            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # channel selection filter characteristics
            channel_taps = optfir.low_pass(
                1.0,  # Filter gain
                self.input_sample_rate,  # Sample rate
                10000,  # One-sided modulation bandwidth
                12000,  # One-sided channel bandwidth
                0.1,  # Passband ripple
                60)  # Stopband attenuation

            # symbol shaping filter characteristics
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # width of trans. band
                500)  # filter type

        if options.protocol == 1:

            # ---------- APCO-25 C4FM Test Data
            self.symbol_rate = 4800  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
            self.channel_decimation = 20  # decimation
            self.max_frequency_offset = 6000.0  # coarse carrier tracker leash
            self.symbol_deviation = 600.0  # this is frequency offset from center of channel to +1 / -1 symbols
            self.input_sample_rate = 64e6 / options.decim  # for USRP: 64MHz / FPGA decimation rate
            self.protocol_processing = fsk4.apco25_f(self.msgq, 0)
            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # channel selection filter
            channel_taps = optfir.low_pass(
                1.0,  # Filter gain
                self.input_sample_rate,  # Sample rate
                5000,  # One-sided modulation bandwidth
                6500,  # One-sided channel bandwidth
                0.1,  # Passband ripple
                60)  # Stopband attenuation

            # symbol shaping filter
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # width of trans. band
                500)  # filter type

        # ---------- End of configuration

        if options.verbose:
            print "Channel filter has", len(channel_taps), "taps."

        self.chan = gr.freq_xlating_fir_filter_ccf(
            self.channel_decimation,  # Decimation rate
            channel_taps,  # Filter taps
            0.0,  # Offset frequency
            self.input_sample_rate)  # Sample rate

        # also note:
        # this specifies the nominal frequency deviation for the 4-level fsk signal
        self.fm_demod_gain = self.channel_rate / (2.0 * pi *
                                                  self.symbol_deviation)
        self.fm_demod = gr.quadrature_demod_cf(self.fm_demod_gain)
        symbol_decim = 1
        self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # eventually specify: sample rate, symbol rate
        self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate,
                                        self.symbol_rate)

        if options.log:
            chan_sink = gr.file_sink(gr.sizeof_gr_complex, 'chan.dat')
            self.connect(self.chan, chan_sink)

        if options.log:
            chan_sink2 = gr.file_sink(gr.sizeof_float, 'demod.dat')
            self.connect(self.demod_fsk4, chan_sink2)

        self.connect(self.src, self.chan, self.fm_demod, self.symbol_filter,
                     self.demod_fsk4, self.protocol_processing)
Esempio n. 49
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename. \n Special output_filename \"sdl\" will use video_sink_sdl as realtime output window. " \
              "You then need to have gr-video-sdl installed. \n" \
              "Make sure your input capture file containes interleaved shorts not complex floats"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-c",
                          "--contrast",
                          type="eng_float",
                          default=1.0,
                          help="set contrast (default is 1.0)")
        parser.add_option("-b",
                          "--brightness",
                          type="eng_float",
                          default=0.0,
                          help="set brightness (default is 0)")
        parser.add_option(
            "-d",
            "--decim",
            type="int",
            default=8,
            help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option(
            "-i",
            "--in-filename",
            type="string",
            default=None,
            help=
            "Use input file as source. samples must be interleaved shorts \n "
            + "Use usrp_rx_file.py or usrp_rx_cfile.py --output-shorts. \n"
            "Special name \"usrp\"  results in realtime capturing and processing using usrp. \n"
            + "You then probably need a decimation factor of 64 or higher.")
        parser.add_option(
            "-f",
            "--freq",
            type="eng_float",
            default=None,
            help=
            "set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel",
            metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-p",
                          "--pal",
                          action="store_true",
                          default=False,
                          help="PAL video format (this is the default)")
        parser.add_option("-n",
                          "--ntsc",
                          action="store_true",
                          default=False,
                          help="NTSC video format")
        parser.add_option("-r",
                          "--repeat",
                          action="store_false",
                          default=True,
                          help="repeat in_file in a loop")
        parser.add_option("-8",
                          "--width-8",
                          action="store_true",
                          default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("-N",
                          "--nframes",
                          type="eng_float",
                          default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option("--no-hb",
                          action="store_true",
                          default=False,
                          help="don't use halfband filter in usrp")
        (options, args) = parser.parse_args()
        if not (len(args) == 1):
            parser.print_help()
            sys.stderr.write('You must specify the output. FILENAME or sdl \n')
            sys.exit(1)

        filename = args[0]

        if options.in_filename is None:
            parser.print_help()
            sys.stderr.write(
                'You must specify the input -i FILENAME or -i usrp\n')
            raise SystemExit, 1

        if not (filename == "sdl"):
            options.repeat = False

        if not (options.in_filename == "usrp"):
            self.filesource = gr.file_source(
                gr.sizeof_short, options.in_filename, options.repeat
            )  # file is data source, capture with usr_rx_csfile.py
            self.istoc = gr.interleaved_short_to_complex()
            self.connect(self.filesource, self.istoc)
            self.adc_rate = 64e6
            self.src = self.istoc
        else:
            if options.freq is None:
                parser.print_help()
                sys.stderr.write(
                    'You must specify the frequency with -f FREQ\n')
                raise SystemExit, 1
            if abs(options.freq) < 1e6:
                options.freq *= 1e6
            if options.no_hb or (options.decim < 8):
                self.fpga_filename = "std_4rx_0tx.rbf"  #contains 4 Rx paths without halfbands and 0 tx paths
            else:
                self.fpga_filename = "std_2rxhb_2tx.rbf"  # contains 2 Rx paths with halfband filters and 2 tx paths (the default)

            # build the graph
            self.u = usrp.source_c(decim_rate=options.decim,
                                   fpga_filename=self.fpga_filename)
            self.src = self.u
            if options.width_8:
                sample_width = 8
                sample_shift = 8
                format = self.u.make_format(sample_width, sample_shift)
                r = self.u.set_format(format)
            self.adc_rate = self.u.adc_freq()
            if options.rx_subdev_spec is None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
            self.u.set_mux(
                usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
            # determine the daughterboard subdevice we're using
            self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
            print "Using RX d'board %s" % (self.subdev.side_and_name(), )

            if options.gain is None:
                # if no gain was specified, use the mid-point in dB
                g = self.subdev.gain_range()
                options.gain = float(g[0] + g[1]) / 2
            self.subdev.set_gain(options.gain)

            r = self.u.tune(0, self.subdev, options.freq)
            if not r:
                sys.stderr.write('Failed to set frequency\n')
                raise SystemExit, 1

        input_rate = self.adc_rate / options.decim
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.agc = gr.agc_cc(1e-7, 1.0, 1.0)  #1e-7
        self.am_demod = gr.complex_to_mag()
        self.set_blacklevel = gr.add_const_ff(options.brightness + 255.0)
        self.invert_and_scale = gr.multiply_const_ff(-options.contrast *
                                                     128.0 * 255.0 / (200.0))
        self.f2uc = gr.float_to_uchar()

        # sdl window as final sink
        if not (options.pal or options.ntsc):
            options.pal = True  #set default to PAL
        if options.pal:
            lines_per_frame = 625.0
            frames_per_sec = 25.0
            show_width = 768
        elif options.ntsc:
            lines_per_frame = 525.0
            frames_per_sec = 29.97002997
            show_width = 640
        width = int(input_rate / (lines_per_frame * frames_per_sec))
        height = int(lines_per_frame)

        if filename == "sdl":
            #Here comes the tv screen, you have to build and install gr-video-sdl for this (subproject of gnuradio, only in cvs for now)
            try:
                video_sink = video_sdl.sink_uc(frames_per_sec, width, height,
                                               0, show_width, height)
            except:
                print "gr-video-sdl is not installed"
                print "realtime \"sdl\" video output window is not available"
                raise SystemExit, 1
            self.dst = video_sink
        else:
            print "You can use the imagemagick display tool to show the resulting imagesequence"
            print "use the following line to show the demodulated TV-signal:"
            print "display -depth 8 -size " + str(width) + "x" + str(
                height) + " gray:" + filename
            print "(Use the spacebar to advance to next frames)"
            file_sink = gr.file_sink(gr.sizeof_char, filename)
            self.dst = file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.head(gr.sizeof_gr_complex,
                                int(options.nframes * width * height))
            self.connect(self.src, self.head, self.agc)

        self.connect(self.agc, self.am_demod, self.invert_and_scale,
                     self.set_blacklevel, self.f2uc, self.dst)
Esempio n. 50
0
    def __init__(self, subdev_spec, gain, audio_output):
	gr.hier_block2.__init__(self, "receive_path",
				gr.io_signature(0, 0, 0), # Input signature
				gr.io_signature(0, 0, 0)) # Output signature

        self.u = usrp.source_c ()
        adc_rate = self.u.adc_rate()

        self.if_rate = 256e3                         # 256 kS/s
        usrp_decim = int(adc_rate // self.if_rate)
        if_decim = 4
        self.u.set_decim_rate(usrp_decim)
        self.quad_rate = self.if_rate // if_decim    #  64 kS/s
        audio_decim = 2
        audio_rate = self.quad_rate // audio_decim   #  32 kS/s

        if subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(self.u)
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "RX using", self.subdev.name()

        self.u.set_mux(usrp.determine_rx_mux_value(self.u, subdev_spec))

        # Create filter to get actual channel we want
        chan_coeffs = gr.firdes.low_pass (1.0,                # gain
                                          self.if_rate,       # sampling rate
                                          13e3,               # low pass cutoff freq
                                          4e3,                # width of trans. band
                                          gr.firdes.WIN_HANN) # filter type 

        print "len(rx_chan_coeffs) =", len(chan_coeffs)

        # Decimating Channel filter with frequency translation
        # complex in and out, float taps
        self.ddc = gr.freq_xlating_fir_filter_ccf(if_decim,       # decimation rate
                                                  chan_coeffs,    # taps
                                                  0,              # frequency translation amount
                                                  self.if_rate)   # input sample rate

        # instantiate the guts of the single channel receiver
        self.fmrx = blks2.nbfm_rx(audio_rate, self.quad_rate)

        # standard squelch block
        self.squelch = blks2.standard_squelch(audio_rate)

        # audio gain / mute block
        self._audio_gain = gr.multiply_const_ff(1.0)

        # sound card as final sink
        audio_sink = audio.sink (int(audio_rate), audio_output)
        
        # now wire it all together
        self.connect (self.u, self.ddc, self.fmrx, self.squelch, self._audio_gain, audio_sink)

        if gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            gain = float(g[0]+g[1])/2

        self.enabled = True
        self.set_gain(gain)
        v = self.volume_range()
        self.set_volume((v[0]+v[1])/2)
        s = self.squelch_range()
        self.set_squelch((s[0]+s[1])/2)
Esempio n. 51
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-m",
                          "--dab-mode",
                          type="int",
                          default=1,
                          help="DAB mode [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=206352000,
                          help="Carrier frequency [default=%default]")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=8,
                          help="USRP gain (dB) [default=%default]")
        parser.add_option("-i",
                          "--subchid",
                          type="int",
                          default=-1,
                          help="Subchannel ID")
        parser.add_option(
            "-n",
            "--config",
            type="string",
            default="channel3.conf",
            help="DAB+ channel configuration file [default=%default]")
        parser.add_option("-o",
                          "--output",
                          type="string",
                          default="-",
                          help="Output AAC file [default=%default]")
        parser.add_option(
            "-p",
            "--mplayer",
            action="store_true",
            default=False,
            help="Play the program by MPlayer [default=%default, stdout]")
        (options, args) = parser.parse_args()

        if len(args) > 0:
            parser.print_help()
            raise SystemExit, 1

        ######## set up usrp
        self.u = usrp.source_c(decim_rate=32)  # 2M sampling freq
        rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
        #print "u.db(0,0).dbid() = ", self.u.db(0,0).dbid()
        #print "u.db(1,0).dbid() = ", self.u.db(1,0).dbid()
        #print "rx_subdev_spec = ", options.rx_subdev_spec

        mux = usrp.determine_rx_mux_value(self.u, rx_subdev_spec)
        #print "mux = ", mux
        self.u.set_mux(mux)

        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
        #print "Using RX d'board %s" % (self.subdev.side_and_name(),)
        input_rate = self.u.adc_freq() / self.u.decim_rate()
        #print "ADC sampling @ ", eng_notation.num_to_str(self.u.adc_freq())
        #print "USB sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.subdev.set_gain(options.gain)
        r = self.u.tune(0, self.subdev, options.freq)

        #print "freq range = [%s, %s]" % (eng_notation.num_to_str(self.subdev.freq_min()), eng_notation.num_to_str(self.subdev.freq_max()))
        if not r:
            sys.stderr.write('Failed to set frequency\n')
            raise SystemExit, 1

        # channel configuration
        cc = dabp.channel_conf(options.config)
        sys.stderr.write("Playing Channel: " + cc.get_label(options.subchid) +
                         "\n")

        start_addr = cc.get_start_addr(options.subchid)
        subchsz = cc.get_subchsz(options.subchid)
        optprot = cc.get_optprot(options.subchid)
        #print "start_addr=%d, subchsz=%d, optprot=%d" % (start_addr, subchsz, optprot)

        mode = options.dab_mode
        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 options.mplayer:
            mplayer = subprocess.Popen([
                'mplayer', '-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, options.output)

        nullsink = gr.null_sink(gr.sizeof_char)
        # connect everything
        self.connect(self.u, nulldet)
        self.connect(self.u, (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)