def set_freq_chan0(self, target_freq, sync=True):
        """
        Set the center frequency we're interested in for rx chan 0 only on MASTER and SLAVE.

        @param target_freq: frequency in Hz
        @param sync: sync the usrps after setting the freqs (this will clear any phase differences in the DDCS)
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        rm = usrp.tune(self.um, 0, self.subdevm, target_freq)
        rs = usrp.tune(self.us, 0, self.subdevs, target_freq)
        r=rm
        if sync:
          self.sync_usrps()  #sync master and slave and clear any DDC phase differences
        if r:
            self.myform['freq'].set_value(target_freq)     # update displayed value
            if self.show_debug_info:
                self.myform['baseband'].set_value(r.baseband_freq)
                self.myform['ddc'].set_value(r.dxc_freq)
            return True

        return False
示例#2
0
    def set_freq_chan0(self, target_freq, sync=True):
        """
        Set the center frequency we're interested in for rx chan 0 only on MASTER and SLAVE.

        @param target_freq: frequency in Hz
        @param sync: sync the usrps after setting the freqs (this will clear any phase differences in the DDCS)
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        rm = usrp.tune(self.um, 0, self.subdevm, target_freq)
        rs = usrp.tune(self.us, 0, self.subdevs, target_freq)
        r=rm
        if sync:
          self.sync_usrps()  #sync master and slave and clear any DDC phase differences
        if r:
            self.myform['freq'].set_value(target_freq)     # update displayed value
            if self.show_debug_info:
                self.myform['baseband'].set_value(r.baseband_freq)
                self.myform['ddc'].set_value(r.dxc_freq)
            return True

        return False
示例#3
0
文件: input.py 项目: GREO/GNU-Radio
    def __init__( self, decim ):
        self.freq = -2.5e6
        self.src = usrp.source_c( )
        self.subdev = usrp.pick_subdev( self.src,
                                        (usrp_dbid.BASIC_RX,
                                         usrp_dbid.TV_RX,
                                         usrp_dbid.TV_RX_REV_2,
                                         usrp_dbid.TV_RX_REV_3,
                                         usrp_dbid.TV_RX_MIMO,
                                         usrp_dbid.TV_RX_REV_2_MIMO,
                                         usrp_dbid.TV_RX_REV_3_MIMO))

        print self.subdev

        self.subdevice = usrp.selected_subdev( self.src,
                                               self.subdev )

        self.mux = usrp.determine_rx_mux_value( self.src,
                                                self.subdev )
        self.decim = decim

        self.adc_rate = self.src.adc_rate()
        self.usrp_rate = self.adc_rate / self.decim
        self.src.set_decim_rate( self.decim )
        self.src.set_mux( self.mux )
        usrp.tune( self.src, 0, self.subdevice, self.freq )
示例#4
0
 def tune_all_rx(self, target_freq):
     result = True
     r1 = usrp.tune(self.usrp_master, 0, self.subdev_mAr, target_freq)
     if r1 is None:
         result = False
     r2 = usrp.tune(self.usrp_master, 1, self.subdev_mBr, target_freq)
     if r2 is None:
         result = False
     r3 = usrp.tune(self.usrp_slave, 0, self.subdev_sAr, target_freq)
     if r3 is None:
         result = False
     r4 = usrp.tune(self.usrp_slave, 1, self.subdev_sBr, target_freq)
     if r4 is None:
         result = False
     return result, r1, r2, r3, r4
 def tune_all_rx(self,target_freq):
     result = True
     r1 =  usrp.tune(self.usrp_master, 0, self.subdev_mAr, target_freq)
     if r1 is None:
       result=False
     r2 = usrp.tune(self.usrp_master, 1, self.subdev_mBr, target_freq)
     if r2 is None:
       result=False
     r3 = usrp.tune(self.usrp_slave, 0, self.subdev_sAr, target_freq)
     if r3 is None:
       result=False
     r4 = usrp.tune(self.usrp_slave, 1, self.subdev_sBr, target_freq)
     if r4 is None:
       result=False
     return result,r1,r2,r3,r4
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        r = usrp.tune(self.u, 0, self.subdev, target_freq  + self.IF_freq)
        #TODO: check if db is inverting the spectrum or not to decide if we should do + self.IF_freq  or - self.IF_freq
        
        if r:
            self.freq = target_freq
            self.myform['freq'].set_value(target_freq)         # update displayed value
            self.myform['freq_slider'].set_value(target_freq)  # update displayed value
            self.update_status_bar()
            self._set_status_msg("OK", 0)
            return True

        self._set_status_msg("Failed", 0)
        return False
示例#7
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.u = usrp.source_c(0, usrp_decim)
        print "USRP Serial: ", self.u.serial_number()
        usrp_rate = self.u.adc_rate() / usrp_decim  # 256 kS/s
        rx_subdev_spec = usrp.pick_subdev(self.u, dblist)
        self.u.set_mux(usrp.determine_rx_mux_value(self.u, rx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
        print "Using d'board", self.subdev.side_and_name()

        self.gain = self.subdev.gain_range()[1]
        self.subdev.set_gain(self.gain)
        r = usrp.tune(self.u, 0, self.subdev, freq)
        if r:
            print "Freq: ", freq / 1e6, "MHz"
        else:
            print "Failed to set frequency, quitting!"
            sys.exit(1)

        chan_filter_coeffs = gr.firdes.low_pass(
            1.0,  # gain
            usrp_rate,  # sampling rate
            80e3,  # passband cutoff
            35e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs)
        print "# channel filter:", len(chan_filter_coeffs), "taps"

        self.file_sink = gr.file_sink(gr.sizeof_gr_complex * 1,
                                      "/home/sdr/rds_samples.dat")

        self.connect(self.u, self.chan_filter, self.file_sink)
    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')
示例#9
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')
示例#10
0
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        r = usrp.tune(self.u, 0, self.subdev, target_freq)

        if r:
            self.freq = target_freq
            self.myform['freq'].set_value(
                target_freq)  # update displayed value
            self.myform['freq_slider'].set_value(
                target_freq)  # update displayed value
            self.update_status_bar()
            self._set_status_msg("OK", 0)
            return True

        self._set_status_msg("Failed", 0)
        return False
示例#11
0
	def __init__(self):
		gr.top_block.__init__ (self)
		
		self.u = usrp.source_c(0, usrp_decim)
		print "USRP Serial: ", self.u.serial_number()
		usrp_rate = self.u.adc_rate() / usrp_decim		# 256 kS/s
		rx_subdev_spec = usrp.pick_subdev(self.u, dblist)
		self.u.set_mux(usrp.determine_rx_mux_value(self.u, rx_subdev_spec))
		self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
		print "Using d'board", self.subdev.side_and_name()
		
		self.gain = self.subdev.gain_range()[1]
		self.subdev.set_gain(self.gain)
		r = usrp.tune(self.u, 0, self.subdev, freq)
		if r:
			print "Freq: ", freq/1e6, "MHz"
		else:
			print "Failed to set frequency, quitting!"
			sys.exit(1)
		
		chan_filter_coeffs = gr.firdes.low_pass(
			1.0,			# gain
			usrp_rate,		# sampling rate
			80e3,			# passband cutoff
			35e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs)
		print "# channel filter:", len(chan_filter_coeffs), "taps"
		
		self.file_sink = gr.file_sink(gr.sizeof_gr_complex*1, "/home/sdr/rds_samples.dat")
		
		self.connect(self.u, self.chan_filter, self.file_sink)
示例#12
0
文件: howto_rx.py 项目: sherlock/ofdm
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()
示例#13
0
	def set_freq(self, target_freq):
		r = usrp.tune(self.u, 0, self.subdev, target_freq)
		if r:
			self.freq = target_freq
			self.bpsk_demod.reset()
			self.rds_decoder.reset()
			return True
		else:
			return False
示例#14
0
 def set_freq(self, target_freq):
     r = usrp.tune(self.u, 0, self.subdev, target_freq)
     if r:
         self.freq = target_freq
         self.bpsk_demod.reset()
         self.rds_decoder.reset()
         return True
     else:
         return False
示例#15
0
	def tune(self, freq):
		result = usrp.tune(self.u, 0, self.subdev, freq)
		if result:
			# Use residual_freq in s/w freq translator
			#self.ddc.set_center_freq(-result.residual_freq)
			print "residual_freq =", result.residual_freq
			return True

		return False
    def tune(self, freq):
        result = usrp.tune(self.u, 0, self.subdev, freq)
        if result:
            # Use residual_freq in s/w freq translator
            #self.ddc.set_center_freq(-result.residual_freq)
            print "residual_freq =", result.residual_freq
            return True

        return False
    def set_freq(self, target_freq):
        ok = True
        for i in range(len(self.subdev)):
            r = usrp.tune(self.u, i, self.subdev[i], target_freq)
            if not r:
                ok = False
                print "set_freq: failed to set subdev[%d] freq to %f" % (
                    i, target_freq)

        return ok
示例#18
0
    def set_freq(self, target_freq):
        ok = True
        for i in range(len(self.subdev)):
            r = usrp.tune(self.u, i, self.subdev[i], target_freq)
            if not r:
                ok = False
                print "set_freq: failed to set subdev[%d] freq to %f" % (
                    i, target_freq)

        return ok
示例#19
0
    def __init__(self, decim):
        self.freq = -2.5e6
        self.src = usrp.source_c()
        self.subdev = usrp.pick_subdev(
            self.src,
            (usrp_dbid.BASIC_RX, usrp_dbid.TV_RX, usrp_dbid.TV_RX_REV_2,
             usrp_dbid.TV_RX_REV_3, usrp_dbid.TV_RX_MIMO,
             usrp_dbid.TV_RX_REV_2_MIMO, usrp_dbid.TV_RX_REV_3_MIMO))

        print self.subdev

        self.subdevice = usrp.selected_subdev(self.src, self.subdev)

        self.mux = usrp.determine_rx_mux_value(self.src, self.subdev)
        self.decim = decim

        self.adc_rate = self.src.adc_rate()
        self.usrp_rate = self.adc_rate / self.decim
        self.src.set_decim_rate(self.decim)
        self.src.set_mux(self.mux)
        usrp.tune(self.src, 0, self.subdevice, self.freq)
def build_graph (filename, IF_freq, decim_rate, sample_count):

    # Initialize empty flow graph
    fg = gr.top_block ()

    # Pick USRP 0 and set the decimation rate
    src = usrp.source_c (0)
    src.set_decim_rate(decim_rate)

    # Select side-A of the board, set the mux, get a handle
    # to the board, and then tune it to the specified freq
    subdev_spec = (0,0)
    src.set_mux(usrp.determine_rx_mux_value(src, subdev_spec))
    subdev = usrp.selected_subdev(src, subdev_spec)
    usrp.tune(src, 0, subdev, IF_freq)

    # Connect the flow graph
    dst = gr.file_sink (gr.sizeof_gr_complex, filename)
    head = gr.head(gr.sizeof_gr_complex, sample_count)
    fg.connect(src, head, dst)

    return fg
示例#21
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'))
示例#22
0
    def _setup_usrp(self, which, interp, subdev_spec, freq):
        self._usrp = usrp.sink_c(which=which, interp_rate=interp)
	if subdev_spec is None:
	    subdev_spec = usrp.pick_tx_subdevice(self._usrp)
	self._usrp.set_mux(usrp.determine_tx_mux_value(self._usrp, subdev_spec))
	self._subdev = usrp.selected_subdev(self._usrp, subdev_spec)
	tr = usrp.tune(self._usrp, self._subdev.which(), self._subdev, freq)
        if not (tr):
            print "Failed to tune to center frequency!"
        else:
            print "Center frequency:", n2s(freq)
        gain = float(self._subdev.gain_range()[1]) # Max TX gain
	self._subdev.set_gain(gain)
	self._subdev.set_enable(True)
        print "TX d'board:", self._subdev.side_and_name()
示例#23
0
	def set_freq(self, target_freq):
		"""
		Set the center frequency we're interested in.

		@param target_freq: frequency in Hz

		"""
		#
		#
		r = usrp.tune(self.u, self.subdev[0].which(), self.subdev[0], target_freq)
		r = usrp.tune(self.u, self.subdev[1].which(), self.subdev[1], target_freq)
		if r:
			self.myform['freq'].set_value(target_freq)	   # update displayed value
			#
			# Make sure calibrator knows our target freq
			#

			# Remember centerfreq---used for doppler calcs
			delta = self.centerfreq - target_freq
			self.centerfreq = target_freq
			self.observing -= delta
			self.scope.set_baseband_freq (self.observing)
			self.myform['baseband'].set_value(r.baseband_freq)
			self.myform['ddc'].set_value(r.dxc_freq)
			
			if (self.use_notches):
				self.compute_notch_taps(self.notches)
				if self.dual_mode == False and self.interferometer == False:
					self.notch_filt.set_taps(self.notch_taps)
				else:
					self.notch_filt1.set_taps(self.notch_taps)
					self.notch_filt2.set_taps(self.notch_taps)

			return True

		return False
示例#24
0
 def set_freq (self, f):
     """ assumes subdev has been set """
     if abs(f) < 1e6: f = f*1e6
     self.freq = f
     if self.fake_rf: return     # no subdev for fake rf
     for s in self.subdev:
         r = usrp.tune(s._u, s.which(), s, self.freq)
         if r and (self.verbose > 0):
             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)) )
             sys.stderr.write("   residual frequency  = %s\n"%(eng_notation.num_to_str(r.residual_freq)) )
             sys.stderr.write("   inverted            = %s\n"%(r.inverted) )
         elif not r:
             self.error("Unable to set frequency of " \
                        + "%s to %g MHz"%(str(s),self.freq/1.0e6) )
示例#25
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'))
示例#26
0
	def set_freq(self, target_freq):
		if (88<target_freq<108): target_freq *= 1e6
		elif (target_freq<88e6) or (target_freq>108e6): return False
		r = usrp.tune(self.u, 0, self.subdev, target_freq)
		if r:
			self.freq = target_freq
			self.myform['freq'].set_value(target_freq)
			self.myform['freq_slider'].set_value(target_freq)
			self.rdspanel.frequency.SetLabel('%3.2f' % (target_freq/1e6))
			self.update_status_bar()
			self.bpsk_demod.reset()
			self.rds_decoder.reset()
			self.rdspanel.clear_data()
			self._set_status_msg("OK", 0)
			return True
		else:
			self._set_status_msg("Failed", 0)
			return False
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        #
        # Everything except BASIC_RX should support usrp.tune()
        #
        if not (self.cardtype == usrp_dbid.BASIC_RX):
            r = usrp.tune(self.u, 0, self.subdev, target_freq)
        else:
            r = self.u.set_rx_freq(0, target_freq)
            f = self.u.rx_freq(0)
            if abs(f-target_freq) > 2.0e3:
                r = 0
        if r:
            self.myform['freq'].set_value(target_freq)     # update displayed value
            #
            # Make sure calibrator knows our target freq
            #

            # Remember centerfreq---used for doppler calcs
            delta = self.centerfreq - target_freq
            self.centerfreq = target_freq
            self.observing -= delta
            self.scope.set_baseband_freq (self.observing)

            self.myform['baseband'].set_value(r.baseband_freq)
            self.myform['ddc'].set_value(r.dxc_freq)

            if self.use_notches == True:
                self.compute_notch_taps(self.notches)
                self.notch_filt.set_taps(self.notch_taps)

            return True

        return False
    def _setup_usrp_sink(self, options):
        """
        Creates a USRP sink, determines the settings for best bitrate,
        and attaches to the transmitter's subdevice.
        """
        #self.u = usrp_options.create_usrp_sink(options)
        self.rs_rate = options.rate    # Store requested bit rate
        
        if_rate = options.rate*options.sps
        self._interp = int(_dac_rate/if_rate)
        options.interp = self._interp
        
        self.u = usrp.sink_c(which = options.which, interp_rate = options.interp)
        if options.tx_subdev_spec is None: 
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec))
        
        self._subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        
        tr = usrp.tune(self.u, self._subdev.which(), self._subdev, options.freq)
        if not (tr):
            print "Failed to tune to center frequency!"
        else:
            print "Center frequency:", n2s(options.freq)
            
        gain = float(self._subdev.gain_range()[1]) # Max TX gain
        self._subdev.set_gain(gain)
        self._subdev.set_enable(True)
        print "TX d'board:", self._subdev.side_and_name()
        
        #initiate hardly the value of bits per symbol to 1
        self.bits_per_symbol = 1
            
#        (self._bitrate, self._samples_per_symbol, self._interp) = \
#                        pick_bitrate.pick_tx_bitrate(options.bitrate, self.bits_per_symbol,
#                                        options.samples_per_symbol, options.interp,
#                                        dac_rate, self.u.get_interp_rates())
        

        if options.verbose:
            print 'USRP Sink:', self.u
            print "Interpolation Rate: ", self._interp
示例#29
0
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        r = usrp.tune(self.u, 0, self.subdev, target_freq)

        if r:
            self.myform['freq'].set_value(
                target_freq)  # update displayed value
            self.myform['baseband'].set_value(r.baseband_freq)
            self.myform['ddc'].set_value(r.dxc_freq)
            # Adjust self.frequency, and self.observing_freq
            # We pick up the difference between the current self.frequency
            #   and the just-programmed one, and use this to adjust
            #   self.observing_freq.  We have to do it this way to
            #   make the dedispersion filtering work out properly.
            delta = target_freq - self.frequency
            self.frequency = target_freq
            self.observing_freq += delta

            # Now that we're adjusted, compute a new dispfilter, and
            #   set the taps for the FFT filter.
            ntaps = self.compute_disp_ntaps(self.dm, self.bw,
                                            self.observing_freq)
            self.disp_taps = Numeric.zeros(ntaps, Numeric.Complex64)
            self.compute_dispfilter(self.dm, self.doppler, self.bw,
                                    self.observing_freq)
            self.dispfilt.set_taps(self.disp_taps)

            return True

        return False
示例#30
0
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        r = usrp.tune(self.u, 0, self.subdev, target_freq)

        if r:
            self.myform['freq'].set_value(target_freq)     # update displayed value
            if self.show_debug_info:
                self.myform['baseband'].set_value(r.baseband_freq)
                self.myform['ddc'].set_value(r.dxc_freq)
            return True

        return False
示例#31
0
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        r = usrp.tune(self.u, 0, self.subdev, target_freq)

        if r:
            self.myform['freq'].set_value(target_freq)     # update displayed value
            self.myform['baseband'].set_value(r.baseband_freq)
            self.myform['ddc'].set_value(r.dxc_freq)
            # Adjust self.frequency, and self.observing_freq
            # We pick up the difference between the current self.frequency
            #   and the just-programmed one, and use this to adjust
            #   self.observing_freq.  We have to do it this way to
            #   make the dedispersion filtering work out properly.
            delta = target_freq - self.frequency
            self.frequency = target_freq
            self.observing_freq += delta

            # Now that we're adjusted, compute a new dispfilter, and
            #   set the taps for the FFT filter.
            ntaps = self.compute_disp_ntaps(self.dm, self.bw, self.observing_freq)
            self.disp_taps = Numeric.zeros(ntaps, Numeric.Complex64)
            self.compute_dispfilter(self.dm,self.doppler,self.bw,
                self.observing_freq)
            self.dispfilt.set_taps(self.disp_taps)

            return True

        return False
示例#32
0
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter in the
        FPGA.  Finally, we feed any residual_freq to the s/w freq
        translator.
        """

        r = usrp.tune(self.u, 0, self.subdev, target_freq)
        if r:
            # Use residual_freq in s/w freq translater
            # print "residual_freq =", r.residual_freq
            self.ddc.set_center_freq(-r.residual_freq)
            return True

        return False
示例#33
0
    def set_freq2(self, target_freq):
        """
        Set the center frequency of we're interested in for the second channel.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        r = usrp.tune(self.u, 1, self.subdev, target_freq)

        if r:
            self.myform['freq2'].set_value(
                target_freq)  # update displayed value
            if self.show_debug_info:
                self.myform['baseband2'].set_value(r.baseband_freq)
                self.myform['ddc2'].set_value(r.dxc_freq)
            return True

        return False
示例#34
0
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter in the
        FPGA.  Finally, we feed any residual_freq to the s/w freq
        translator.
        """

        r = usrp.tune(self.u, 0, self.subdev, target_freq)
        if r:
            # Use residual_freq in s/w freq translater
            # print "residual_freq =", r.residual_freq
            self.ddc.set_center_freq(-r.residual_freq)
            return True

        return False
示例#35
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)
示例#36
0
 def set_freq(self, x):
     r = usrp.tune(self.src, 0, self.subdevice, -x)
     if r:
         self.freq = -x
示例#37
0
    def __init__(self):
        gr.top_block.__init__(self)
           
        amplitude = 5000        
        interp_rate = 256
        dec_rate = 16
        sw_dec = 5

        num_taps = int(64000 / ( (dec_rate * 4) * 40 )) #Filter matched to 1/4 of the 40 kHz tag cycle
        taps = [complex(1,1)] * num_taps
        
        matched_filt = gr.fir_filter_ccc(sw_dec, taps);  
          
        agc = gr.agc2_cc(0.3, 1e-3, 1, 1, 100) 
     
        to_mag = gr.complex_to_mag()

        center = rfid.center_ff(10)

        omega = 5
        mu = 0.25
        gain_mu = 0.25
        gain_omega = .25 * gain_mu * gain_mu
        omega_relative_limit = .05

        mm = gr.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_relative_limit)


        self.reader = rfid.reader_f(int(128e6/interp_rate)); 
        
        tag_decoder = rfid.tag_decoder_f()
        
        command_gate = rfid.command_gate_cc(12, 250, 64000000 / dec_rate / sw_dec)
        
        
        to_complex = gr.float_to_complex()
        amp = gr.multiply_const_ff(amplitude)
        
        #output the TX and RX signals only
        f_txout = gr.file_sink(gr.sizeof_gr_complex, 'f_txout.out');
        f_rxout = gr.file_sink(gr.sizeof_gr_complex, 'f_rxout.out');
        
#TX
		# working frequency at 915 MHz by default and RX Gain of 20
        freq = options.center_freq #915e6 
        rx_gain = options.rx_gain #20  
    
        tx = usrp.sink_c(fusb_block_size = 512, fusb_nblocks=4)
        tx.set_interp_rate(256)
        tx_subdev = (0,0)
        tx.set_mux(usrp.determine_tx_mux_value(tx, tx_subdev))
        subdev = usrp.selected_subdev(tx, tx_subdev)
        subdev.set_enable(True)
        subdev.set_gain(subdev.gain_range()[2])
        t = tx.tune(subdev.which(), subdev, freq)
        if not t:
            print "Couldn't set tx freq"
#End TX
             
#RX
        rx = usrp.source_c(0, dec_rate, fusb_block_size = 512, fusb_nblocks = 4)
        rx_subdev_spec = (1,0)
        rx.set_mux(usrp.determine_rx_mux_value(rx, rx_subdev_spec))
        rx_subdev = usrp.selected_subdev(rx, rx_subdev_spec)
        rx_subdev.set_gain(rx_gain)
        rx_subdev.set_auto_tr(False)
        rx_subdev.set_enable(True)
        
        r = usrp.tune(rx, 0, rx_subdev, freq)

        self.rx = rx
        if not r:
            print "Couldn't set rx freq"

#End RX

        command_gate.set_ctrl_out(self.reader.ctrl_q())
        tag_decoder.set_ctrl_out(self.reader.ctrl_q())



#########Build Graph
        self.connect(rx, matched_filt)
        self.connect(matched_filt, command_gate)
        self.connect(command_gate, agc)
        self.connect(agc, to_mag) 
        self.connect(to_mag, center, mm, tag_decoder)
        self.connect(tag_decoder, self.reader, amp, to_complex, tx);
#################
		
		#Output dumps for debug
        self.connect(rx, f_rxout);
        self.connect(to_complex, f_txout);
示例#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)
 def set_freq( self, x ):
     r = usrp.tune( self.src, 0, self.subdevice, -x )
     if r:
         self.freq = -x
示例#40
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)
示例#41
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()
def main():

    # Parsing command line parameter
    parser = OptionParser(option_class=eng_option)
    parser.add_option(
        "-f",
        "--freq",
        type="eng_float",
        dest="freq",
        default=866.5,
        help="set USRP center frequency (provide frequency in MHz)")
    parser.add_option("-m",
                      "--miller",
                      type="int",
                      dest="miller",
                      default=2,
                      help="set number of Miller subcarriers (2,4 or 8)")
    (options, args) = parser.parse_args()

    which_usrp = 0
    fpga = "gen2_reader_2ch_mod_pwr.rbf"  # Modified firmware --> you can set TX amplitude directly from Python (see below)
    freq = options.freq  # Default value = 866.5 --> center frequency of 2 MHz European RFID Band
    freq = freq * 1e6
    miller = options.miller
    deviation_corr = 1  # Maximum deviation for Early/Late gate correlator in Buettner's reader
    amplitude = 30000  # Amplitude of READER TX signal. 30000 is the maximum allowed.
    rx_gain = 20
    us_per_sample = float(1 / (64.0 / (dec_rate * sw_dec)))
    samp_freq = (64 / dec_rate) * 1e6

    # BUETTNER'S READER HARDWARE SUB-SYSTEM for TX SIDE
    tx = usrp.sink_c(which_usrp,
                     fusb_block_size=1024,
                     fusb_nblocks=4,
                     fpga_filename=fpga)
    tx.set_interp_rate(interp)
    tx_subdev = (0, 0)  # TX/RX port of RFX900 daugtherboard on SIDE A
    tx.set_mux(usrp.determine_tx_mux_value(tx, tx_subdev))
    subdev = usrp.selected_subdev(tx, tx_subdev)
    subdev.set_enable(True)
    subdev.set_gain(subdev.gain_range()[2])

    t = tx.tune(subdev.which(), subdev,
                freq)  # Tuning TX Daughterboard @ Center Frequency
    if not t:
        print "Couldn't set READER TX frequency"

    tx._write_fpga_reg(usrp.FR_USER_1, int(
        amplitude))  # SET FPGA register value with the desired tx amplitude
    # END BUETTNER'S READER HARDWARE SUB-SYSTEM for TX SIDE

    # BUETTNER'S READER HARDWARE SUB-SYSTEM for RX SIDE
    rx = usrp.source_c(
        which_usrp,
        dec_rate,
        nchan=2,
        fusb_block_size=512,
        fusb_nblocks=16,
        fpga_filename=fpga)  # USRP source: 2 channels (reader + listener)
    rx.set_mux(rx.determine_rx_mux_value(
        (0, 0), (1, 0)
    ))  # 2 channel mux --> rx from (0,0) to reader - rx from (1,0) to listener
    rx_reader_subdev_spec = (0, 0)  # Reader RFX900 daugtherboard on SIDE A
    rx_reader_subdev = rx.selected_subdev(rx_reader_subdev_spec)
    rx_reader_subdev.set_gain(rx_gain)
    rx_reader_subdev.set_auto_tr(False)
    rx_reader_subdev.set_enable(True)
    rx_reader_subdev.select_rx_antenna(
        'RX2'
    )  # RX2 port of RFX900 on side A --> RX antenna of Buettner's reader

    r = usrp.tune(rx, 0, rx_reader_subdev,
                  freq)  # Tuning READER RX Daughterboard @ Center Frequency
    if not r:
        print "Couldn't set READER RX frequency"
    # END BUETTNER'S READER HARDWARE SUB-SYSTEM for TX SIDE

    # LISTENER HARDWARE SUB-SYSTEM
    rx_listener_subdev_spec = (1, 0)  # Listener DB RFX900 on side B
    rx_listener_subdev = rx.selected_subdev(rx_listener_subdev_spec)
    rx_listener_subdev.set_gain(rx_gain)
    rx_listener_subdev.set_auto_tr(False)
    rx_listener_subdev.set_enable(True)
    rx_listener_subdev.select_rx_antenna(
        'RX2'
    )  # RX Antenna on RX2 Connector of side B RFX900 (comment this line if you want TX/RX connector)

    r = usrp.tune(rx, 1, rx_listener_subdev,
                  freq)  # Tuning Listener Daughterboard @ Center Frequency
    if not r:
        print "Couldn't set LISTENER RX frequency"
    # END LISTENER HARDWARE SUB-SYSTEM

    print ""
    print "********************************************************"
    print "************ Gen2 RFID Monitoring Platform *************"
    print "********* Reader and Listener on the same USRP *********"
    print "********************************************************\n"

    print "USRP center frequency: %s MHz" % str(freq / 1e6)
    print "Sampling Frequency: " + str(
        samp_freq /
        1e6) + " MHz" + " --- microsec. per Sample: " + str(us_per_sample)

    # BUETTNER's READER SOFTWARE SUB-SYSTEM (GNU-Radio flow-graph)
    gen2_reader = rfid.gen2_reader(dec_rate * sw_dec * samples_per_pulse,
                                   interp, int(miller), True,
                                   int(deviation_corr))
    zc = rfid.clock_recovery_zc_ff(samples_per_pulse, 1, float(us_per_sample),
                                   float(up_link_freq), True)
    # END BUETTNER's READER SOFTWARE SUB-SYSTEM (GNU-Radio flow-graph)

    # LISTENER SOFTWARE SUB-SYSTEM (GNU-Radio flow-graph)
    # MATCHED FILTER
    num_taps = int(
        64000 / (dec_rate * up_link_freq * 4))  #Matched filter for 1/4 cycle
    taps = [complex(1, 1)] * num_taps
    matched_filter = gr.fir_filter_ccc(sw_dec, taps)
    # Tag Decoding Block --> the boolean value in input indicate if real-time output of EPC is enabled or not
    tag_monitor = listener.tag_monitor(True, int(miller), float(up_link_freq))
    # Clock recovery
    cr = listener.clock_recovery(samples_per_pulse, us_per_sample,
                                 tag_monitor.STATE_PTR, float(up_link_freq))
    # Reader Decoding Block and Command gate--> the boolean value indicate if real-time output of reader commands is enabled or not
    reader_monitor_cmd_gate = listener.reader_monitor_cmd_gate(
        False, us_per_sample, tag_monitor.STATE_PTR, float(up_link_freq),
        float(rtcal))
    # END LISTENER SOFTWARE SUB-SYSTEM (GNU-Radio flow-graph)

    # Create GNU-Radio flow-graph
    tb = my_top_block(tx, zc, gen2_reader, rx, matched_filter,
                      reader_monitor_cmd_gate, cr, tag_monitor, amplitude)

    # Start application
    tb.start()

    # GETTING LOGs from BUETTNER's READER
    video_output = False  # Set as True if you want real time video output of Buettner's reader logs
    log_reader_buettner_file = open("log_reader_buettner.log", "w")
    finish = 0
    succ_reads = 0
    epc_errors = 0

    while 1:
        log_reader_buettner = gen2_reader.get_log()
        i = log_reader_buettner.count()
        for k in range(0, i):
            msg = log_reader_buettner.delete_head_nowait()
            print_msg(msg, log_reader_buettner_file, video_output)
            if msg.type() == 99:  # All cycles are terminated
                finish = 1
            if msg.type() == LOG_EPC:  # EPC
                if msg.arg2() == LOG_ERROR:
                    epc_errors = epc_errors + 1
                    # CRC Error on EPC
                else:
                    succ_reads = succ_reads + 1
                    # Successful EPc
        if finish:
            break

    # Stop application
    tb.stop()
    log_reader_buettner_file.close()
    rec_frames = succ_reads + epc_errors
    print "\nReader --> Total Received Frames: " + str(rec_frames)
    print "Reader --> Successful reads: " + str(succ_reads)
    print "Reader --> CRC error frames: " + str(epc_errors)
    print ""

    # GETTING LOGs from LISTENER
    log_READER = reader_monitor_cmd_gate.get_reader_log()
    log_TAG = tag_monitor.get_tag_log()
    print "Listener collected %s Entries for READER LOG" % str(
        log_READER.count())
    print "Listener collected %s Entries for TAG LOG" % str(log_TAG.count())

    c = raw_input("PRESS 'f' to write LOG files, 'q' to QUIT\n")
    if c == "q":
        print "\n Shutting Down...\n"
        return
    if c == "f":
        print "\n Writing READER LOG on file...\n\n"
        reader_file = open("reader_log.out", "w")
        reader_file.close()
        reader_file = open("reader_log.out", "a")
        i = log_READER.count()
        for k in range(0, i):
            decode_reader_log_msg(log_READER.delete_head_nowait(), reader_file)
            k = k + 1
        reader_file.close()

        print "\n Writing TAG LOG on file...\n"
        tag_file = open("tag_log.out", "w")
        tag_file.close()
        tag_file = open("tag_log.out", "a")
        i = log_TAG.count()
        for k in range(0, i):
            decode_tag_log_msg(log_TAG.delete_head_nowait(), tag_file)
            k = k + 1
        tag_file.close()
def main():
    

    #TX
    which_usrp = 0
    fpga = "gen2_reader.rbf"

    freq = 915e6
    rx_gain = 20
    
    samp_freq = (64 / dec_rate) * 1e6

    

    tx = usrp.sink_c(which_usrp,fusb_block_size = 1024, fusb_nblocks=4, fpga_filename=fpga)
    tx.set_interp_rate(interp)
    tx_subdev = (0,0)
    tx.set_mux(usrp.determine_tx_mux_value(tx, tx_subdev))
    subdev = usrp.selected_subdev(tx, tx_subdev)
    subdev.set_enable(True)
    subdev.set_gain(subdev.gain_range()[2])
    
    t = tx.tune(subdev.which(), subdev, freq)
    if not t:
        print "Couldn't set tx freq"
#End TX

#RX
            

    rx = usrp.source_c(which_usrp, dec_rate, fusb_block_size = 512, fusb_nblocks = 16, fpga_filename=fpga)
    rx_subdev_spec = (1,0)
    rx.set_mux(usrp.determine_rx_mux_value(rx, rx_subdev_spec))
    rx_subdev = usrp.selected_subdev(rx, rx_subdev_spec)
    rx_subdev.set_gain(rx_gain)
    rx_subdev.set_auto_tr(False)
    rx_subdev.set_enable(True)
    
    us_per_sample = 1 / (64.0 / dec_rate / sw_dec)
    print "Sample Frequency: "+ str(samp_freq) + " us Per Sample: " + str(us_per_sample)
    r = usrp.tune(rx, 0, rx_subdev, freq)
    if not r:
        print "Couldn't set rx freq"

#End RX

    
    gen2_reader = rfid.gen2_reader(dec_rate * sw_dec * samples_per_pulse, interp)

    tb = my_top_block(rx, gen2_reader, tx)
    tb.start()
    

    log_file = open("log_out.log", "w")
    

    
    while 1:
            
        c = raw_input("'Q' to quit\n")
        if c == "q":
            break

        if c == "A" or c == "a":
            log_file.write("T,CMD,ERROR,BITS,SNR\n")
            log = gen2_reader.get_log()
            print "Log has %s Entries"% (str(log.count()))
            i = log.count();
                             
            
            for k in range(0, i):
                msg = log.delete_head_nowait()
                print_log_msg(msg, log_file)

    
    
        
    tb.stop()
   
    log_file.close()
示例#44
0
 def tune(self, freq):
 	result = usrp.tune(self._src, 0, self._subdev, freq+self._cal)
def main():

    #TX
    which_usrp = 0
    fpga = "gen2_reader.rbf"

    freq = 915e6
    rx_gain = 20

    samp_freq = (64 / dec_rate) * 1e6

    tx = usrp.sink_c(which_usrp,
                     fusb_block_size=1024,
                     fusb_nblocks=4,
                     fpga_filename=fpga)
    tx.set_interp_rate(interp)
    tx_subdev = (0, 0)
    tx.set_mux(usrp.determine_tx_mux_value(tx, tx_subdev))
    subdev = usrp.selected_subdev(tx, tx_subdev)
    subdev.set_enable(True)
    subdev.set_gain(subdev.gain_range()[2])

    t = tx.tune(subdev.which(), subdev, freq)
    if not t:
        print "Couldn't set tx freq"
#End TX

#RX

    rx = usrp.source_c(which_usrp,
                       dec_rate,
                       fusb_block_size=512,
                       fusb_nblocks=16,
                       fpga_filename=fpga)
    rx_subdev_spec = (1, 0)
    rx.set_mux(usrp.determine_rx_mux_value(rx, rx_subdev_spec))
    rx_subdev = usrp.selected_subdev(rx, rx_subdev_spec)
    rx_subdev.set_gain(rx_gain)
    rx_subdev.set_auto_tr(False)
    rx_subdev.set_enable(True)

    us_per_sample = 1 / (64.0 / dec_rate / sw_dec)
    print "Sample Frequency: " + str(samp_freq) + " us Per Sample: " + str(
        us_per_sample)
    r = usrp.tune(rx, 0, rx_subdev, freq)
    if not r:
        print "Couldn't set rx freq"


#End RX

    gen2_reader = rfid.gen2_reader(dec_rate * sw_dec * samples_per_pulse,
                                   interp)

    tb = my_top_block(rx, gen2_reader, tx)
    tb.start()

    log_file = open("log_out.log", "w")

    while 1:

        c = raw_input("'Q' to quit\n")
        if c == "q":
            break

        if c == "A" or c == "a":
            log_file.write("T,CMD,ERROR,BITS,SNR\n")
            log = gen2_reader.get_log()
            print "Log has %s Entries" % (str(log.count()))
            i = log.count()

            for k in range(0, i):
                msg = log.delete_head_nowait()
                print_log_msg(msg, log_file)

    tb.stop()

    log_file.close()
示例#46
0
    def __init__(self):
        gr.top_block.__init__(self)
           
        amplitude = 30000

        filt_out = gr.file_sink(gr.sizeof_gr_complex, "./filt.out")
        filt2_out = gr.file_sink(gr.sizeof_gr_complex, "./filt2.out")
        ffilt_out = gr.file_sink(gr.sizeof_float, "./ffilt.out")
        ffilt2_out = gr.file_sink(gr.sizeof_float, "./ffilt2.out")

        interp_rate = 128
        dec_rate = 8
        sw_dec = 4

        num_taps = int(64000 / ( (dec_rate * 4) * 256 )) #Filter matched to 1/4 of the 256 kHz tag cycle
        taps = [complex(1,1)] * num_taps
        
        matched_filt = gr.fir_filter_ccc(sw_dec, taps);  
          
        agc = gr.agc2_cc(0.3, 1e-3, 1, 1, 100) 
     
        to_mag = gr.complex_to_mag()

        center = rfid.center_ff(4)

        omega = 2
        mu = 0.25
        gain_mu = 0.25
        gain_omega = .25 * gain_mu * gain_mu
        omega_relative_limit = .05

        mm = gr.clock_recovery_mm_ff(omega, gain_omega, mu, gain_mu, omega_relative_limit)


        self.reader = rfid.reader_f(int(128e6/interp_rate)); 
        
        tag_decoder = rfid.tag_decoder_f()
        
        command_gate = rfid.command_gate_cc(12, 60, 64000000 / dec_rate / sw_dec)
        

       
       
        to_complex = gr.float_to_complex()
        amp = gr.multiply_const_ff(amplitude)
        
        f_sink = gr.file_sink(gr.sizeof_gr_complex, 'f_sink.out');
        f_sink2 = gr.file_sink(gr.sizeof_gr_complex, 'f_sink2.out');


            #TX
      


        freq = 915e6
        rx_gain = 20  
    
        tx = usrp.sink_c(fusb_block_size = 1024, fusb_nblocks=8)
        tx.set_interp_rate(interp_rate)
        tx_subdev = (0,0)
        tx.set_mux(usrp.determine_tx_mux_value(tx, tx_subdev))
        subdev = usrp.selected_subdev(tx, tx_subdev)
        subdev.set_enable(True)
        subdev.set_gain(subdev.gain_range()[2])
        t = tx.tune(subdev.which(), subdev, freq)
        if not t:
            print "Couldn't set tx freq"
#End TX
             
#RX
        rx = usrp.source_c(0, dec_rate, fusb_block_size = 512 * 4, fusb_nblocks = 16)
        rx_subdev_spec = (1,0)
        rx.set_mux(usrp.determine_rx_mux_value(rx, rx_subdev_spec))
        rx_subdev = usrp.selected_subdev(rx, rx_subdev_spec)
        rx_subdev.set_gain(rx_gain)
        rx_subdev.set_auto_tr(False)
        rx_subdev.set_enable(True)
        
        r = usrp.tune(rx, 0, rx_subdev, freq)

        self.rx = rx
        if not r:
            print "Couldn't set rx freq"

#End RX

        command_gate.set_ctrl_out(self.reader.ctrl_q())
        tag_decoder.set_ctrl_out(self.reader.ctrl_q())
        agc2 = gr.agc2_ff(0.3, 1e-3, 1, 1, 100) 


#########Build Graph
        self.connect(rx, matched_filt)
        self.connect(matched_filt, command_gate)
        self.connect(command_gate, agc)
        self.connect(agc, to_mag) 
        self.connect(to_mag, center, agc2, mm, tag_decoder)
        self.connect(tag_decoder, self.reader, amp, to_complex, tx);
#################

        
        self.connect(matched_filt, filt_out)
示例#47
0
 def tune(self, freq):
     result = usrp.tune(self._src, 0, self._subdev, freq + self._cal)