Esempio n. 1
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 )
Esempio n. 2
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.frequency = 13.56e6
        self.gain = 100
        # for 4 MS/s, 32
        # 
        self.usrp_interpol = 32

        # USRP settings
        self.u_tx = usrp.sink_c() #create the USRP sink for TX
        #try and set the LF_RX for this
        self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX))
        #set the interpolation rate to match the USRP's 128 MS/s
        self.u_tx.set_interp_rate(self.usrp_interpol)

        #Configure the MUX for the daughterboard
        self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec))
        #Tell it to use the LF_TX
        self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec)
        #Make sure it worked 
        print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),)             

        #Set gain.. duh
        self.subdev_tx.set_gain(self.gain)

        #Tune the center frequency
        self.u_tx.tune(0, self.subdev_tx, self.frequency)

#        self.src = gr.wavfile_source("RFID_command_52_4M_1610.wav", True)
        self.src = gr.wavfile_source("wave52.wav", True)
        self.conv = gr.float_to_complex()
        self.amp = gr.multiply_const_cc(10.0 ** (self.gain / 20.0))
        
        self.connect(self.src, self.conv, self.amp, self.u_tx)
Esempio n. 3
0
    def __init__(self, usrp_offset):
        gr.flow_graph.__init__(self)

        print "decim = %d, gain = %d, offset = %.2f" % (decim, gain, usrp_offset)
        print "filter center %.2f, filter width %.2f" % (xcf, xtw)

        u = usrp.source_c(decim_rate=decim)
        s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX,))
        u.set_mux(usrp.determine_rx_mux_value(u, s))
        subdev = usrp.selected_subdev(u, s)

        if subdev.dbid() != usrp_dbid.DBS_RX:
            raise Exception("dbs daughterboard not detected!")

        subdev.set_gain(gain)

        sps = u.adc_freq() / u.decim_rate()
        if sps < 2 * gsm_rate:
            raise Exception("sample rate too low")

        u.tune(0, subdev, c0 + usrp_offset)

        xt = gr.firdes.low_pass(1.0, sps, xcf, xtw, gr.firdes.WIN_HAMMING)
        xf = gr.fir_filter_ccf(1, xt)

        self.gs = gs = gssm.sink(sps)

        self.connect(u, xf, gs)
Esempio n. 4
0
	def __init__(self, usrp_offset):
		gr.top_block.__init__(self)

		u = usrp.source_c(decim_rate = decim)
		s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX,))
		u.set_mux(usrp.determine_rx_mux_value(u, s))
		subdev = usrp.selected_subdev(u, s)

		if subdev.dbid() != usrp_dbid.DBS_RX:
			raise Exception('dbs daughterboard not detected!')

		subdev.set_gain(gain)

		sps = u.adc_freq() / u.decim_rate()
		if sps < 2 * gsm_rate:
			raise Exception('sample rate too low')

		u.tune(0, subdev, c0 + usrp_offset)

		xcf = 150e3
		xtw = 50e3
		xt = gr.firdes.low_pass(1.0, sps, xcf, xtw,
		   gr.firdes.WIN_HAMMING)
		xf = gr.fir_filter_ccf(1, xt)

		g = gssm.sink(sps)

		self.connect(u, xf, g)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
    def __init__(self, usrp_offset):
        gr.top_block.__init__(self)

        u = usrp.source_c(decim_rate=decim)
        s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX, ))
        u.set_mux(usrp.determine_rx_mux_value(u, s))
        subdev = usrp.selected_subdev(u, s)

        if subdev.dbid() != usrp_dbid.DBS_RX:
            raise Exception('dbs daughterboard not detected!')

        subdev.set_gain(gain)

        sps = u.adc_freq() / u.decim_rate()
        if sps < 2 * gsm_rate:
            raise Exception('sample rate too low')

        u.tune(0, subdev, c0 + usrp_offset)

        xcf = 150e3
        xtw = 50e3
        xt = gr.firdes.low_pass(1.0, sps, xcf, xtw, gr.firdes.WIN_HAMMING)
        xf = gr.fir_filter_ccf(1, xt)

        g = gssm.sink(sps)

        self.connect(u, xf, g)
Esempio n. 8
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.frequency = 13.56e6
        self.gain = 100
        self.usrp_interpol = 32

        # USRP settings
        self.u_tx = usrp.sink_c() #create the USRP sink for TX
        #try and set the LF_RX for this
        self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX))
        #set the interpolation rate to match the USRP's 128 MS/s
        self.u_tx.set_interp_rate(self.usrp_interpol)

        #Configure the MUX for the daughterboard
        self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec))
        #Tell it to use the LF_TX
        self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec)
        #Make sure it worked 
        print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),)             

        #Set gain.. duh
        self.subdev_tx.set_gain(self.gain)

        #Tune the center frequency
        self.u_tx.tune(0, self.subdev_tx, self.frequency)

        self.src = gr.wavfile_source("RFID_command_52_4M_1610.wav", False)
        self.conv = gr.float_to_complex()
        self.amp = gr.multiply_const_cc(10.0 ** (self.gain / 20.0))
        
        self.connect(self.src, self.conv, self.amp, self.u_tx)
def pick_subdevice(u):
    """
    The user didn't specify a subdevice on the command line.
    Try for one of these, in order: TV_RX, BASIC_RX, whatever is on side A.

    @return a subdev_spec
    """
    return usrp.pick_subdev(u, (usrp_dbid.TV_RX, usrp_dbid.TV_RX_REV_2, usrp_dbid.TV_RX_REV_3, usrp_dbid.BASIC_RX))
Esempio n. 10
0
def pick_subdevice(u):
    """
    The user didn't specify a subdevice on the command line.
    Try for one of these, in order: TV_RX, BASIC_RX, whatever is on side A.

    @return a subdev_spec
    """
    return usrp.pick_subdev(
        u, (usrp_dbid.TV_RX, usrp_dbid.TV_RX_REV_2, usrp_dbid.TV_RX_REV_3,
            usrp_dbid.DBS_RX, usrp_dbid.BASIC_RX))
Esempio n. 11
0
    def __init__(self):
        gr.hier_block2.__init__(self, "rx_path", gr.io_signature(0, 0, 0),
                                gr.io_signature(0, 0, 0))

        self.frequency = 13.56e6
        self.gain = 10

        # USRP settings
        self.u_rx = usrp.source_c()  #create the USRP source for RX
        #try and set the LF_RX for this
        rx_subdev_spec = usrp.pick_subdev(self.u_rx,
                                          (usrp_dbid.LF_RX, usrp_dbid.LF_TX))

        #Configure the MUX for the daughterboard
        self.u_rx.set_mux(
            usrp.determine_rx_mux_value(self.u_rx, rx_subdev_spec))
        #Tell it to use the LF_RX
        self.subdev_rx = usrp.selected_subdev(self.u_rx, rx_subdev_spec)
        #Make sure it worked
        print "Using RX dboard %s" % (self.subdev_rx.side_and_name(), )

        #Set gain.. duh
        self.subdev_rx.set_gain(self.gain)

        #Tune the center frequency
        self.u_rx.tune(0, self.subdev_rx, self.frequency)

        adc_rate = self.u_rx.adc_rate()  #64 MS/s
        usrp_decim = 256
        self.u_rx.set_decim_rate(usrp_decim)
        #BW = 64 MS/s / decim = 64,000,000 / 256 = 250 kHz
        #Not sure if this decim rate exceeds USRP capabilities,
        #if it does then some software decim may have to be done as well
        usrp_rx_rate = adc_rate / usrp_decim

        self.iir = gr.single_pole_iir_filter_ff(.001)
        self.mag = gr.complex_to_mag()
        self.snk = gr.probe_signal_f()

        # dst = audio.sink (sample_rate, "")
        # stv = gr.stream_to_vector (gr.sizeof_float, fft_size)
        # c2m = gr.complex_to_mag_squared (fft_size)

        self.connect(self.u_rx, self.mag, self.iir, self.snk)
Esempio n. 12
0
    def __init__(self):
        gr.hier_block2.__init__(self, "rx_path", 
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(0, 0, 0))

        self.frequency = 13.56e6
        self.gain = 10

        # USRP settings
        self.u_rx = usrp.source_c() #create the USRP source for RX
        #try and set the LF_RX for this
        rx_subdev_spec = usrp.pick_subdev(self.u_rx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX))

        #Configure the MUX for the daughterboard
        self.u_rx.set_mux(usrp.determine_rx_mux_value(self.u_rx, rx_subdev_spec))
        #Tell it to use the LF_RX
        self.subdev_rx = usrp.selected_subdev(self.u_rx, rx_subdev_spec)
        #Make sure it worked 
        print "Using RX dboard %s" % (self.subdev_rx.side_and_name(),)

        #Set gain.. duh
        self.subdev_rx.set_gain(self.gain)

        #Tune the center frequency
        self.u_rx.tune(0, self.subdev_rx, self.frequency)

        adc_rate = self.u_rx.adc_rate() #64 MS/s
        usrp_decim = 256
        self.u_rx.set_decim_rate(usrp_decim)
        #BW = 64 MS/s / decim = 64,000,000 / 256 = 250 kHz
        #Not sure if this decim rate exceeds USRP capabilities,
        #if it does then some software decim may have to be done as well
        usrp_rx_rate = adc_rate / usrp_decim

        self.iir = gr.single_pole_iir_filter_ff(.001)
        self.mag = gr.complex_to_mag()
        self.snk = gr.probe_signal_f()

        # dst = audio.sink (sample_rate, "")
        # stv = gr.stream_to_vector (gr.sizeof_float, fft_size)
        # c2m = gr.complex_to_mag_squared (fft_size)
        
        self.connect(self.u_rx, self.mag, self.iir, self.snk)
Esempio n. 13
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)
Esempio n. 14
0
    def __init__(self):
        gr.hier_block2.__init__(self, "tx_path", gr.io_signature(0, 0, 0),
                                gr.io_signature(0, 0, 0))

        self.frequency = 13.56e6
        self.normal_gain = 100
        self.k = 0
        self.usrp_interpol = int(128 / (SAMPLERATE / 1e6))
        print "[+] Using interpolation rate of", self.usrp_interpol

        # USRP settings
        self.u_tx = usrp.sink_c()  #create the USRP sink for TX
        #try and set the LF_RX for this
        self.tx_subdev_spec = usrp.pick_subdev(
            self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX))
        #set the interpolation rate to match the USRP's 128 MS/s
        self.u_tx.set_interp_rate(self.usrp_interpol)

        #Configure the MUX for the daughterboard
        self.u_tx.set_mux(
            usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec))
        #Tell it to use the LF_TX
        self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec)
        #Make sure it worked
        print "Using TX dboard %s" % (self.subdev_tx.side_and_name(), )

        #Set gain.. duh
        self.subdev_tx.set_gain(self.normal_gain)

        #Tune the center frequency
        self.u_tx.tune(0, self.subdev_tx, self.frequency)

        self.src = gr.wavfile_source("wave52.wav", True)
        self.conv = gr.float_to_complex()
        self.amp = gr.multiply_const_cc(10.0**(self.normal_gain / 20.0))

        self.connect(self.src, self.conv, self.amp, self.u_tx)
Esempio n. 15
0
    def __init__(self):
        gr.hier_block2.__init__(self, "tx_path", 
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(0, 0, 0))

        self.frequency = 13.56e6
        self.normal_gain = 100
        self.k = 0
        self.usrp_interpol = int(128/(SAMPLERATE/1e6))
        print "[+] Using interpolation rate of",self.usrp_interpol

        # USRP settings
        self.u_tx = usrp.sink_c() #create the USRP sink for TX
        #try and set the LF_RX for this
        self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX))
        #set the interpolation rate to match the USRP's 128 MS/s
        self.u_tx.set_interp_rate(self.usrp_interpol)

        #Configure the MUX for the daughterboard
        self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec))
        #Tell it to use the LF_TX
        self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec)
        #Make sure it worked 
        print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),)

        #Set gain.. duh
        self.subdev_tx.set_gain(self.normal_gain)

        #Tune the center frequency
        self.u_tx.tune(0, self.subdev_tx, self.frequency)

        self.src = gr.wavfile_source("wave52.wav", True)
        self.conv = gr.float_to_complex()
        self.amp = gr.multiply_const_cc(10.0 ** (self.normal_gain / 20.0))
        
        self.connect(self.src, self.conv, self.amp, self.u_tx)
Esempio n. 16
0
	def __init__(self):
		gr.top_block.__init__ (self)

		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=91.2e6,
						  help="set frequency to FREQ", metavar="FREQ")
		parser.add_option("-g", "--gain", type="eng_float", default=None,
						  help="set gain in dB")
		parser.add_option("-s", "--squelch", type="eng_float", default=0,
						  help="set squelch level (default is 0)")
		parser.add_option("-V", "--volume", type="eng_float", default=None,
						  help="set volume (default is midpoint)")
		parser.add_option("-O", "--audio-output", type="string", default="plughw:0,0",
						  help="pcm device name (default is plughw:0,0)")
		(options, args) = parser.parse_args()
		if len(args) != 0:
			parser.print_help()
			sys.exit(1)

		# connect to USRP
		usrp_decim = 250
		self.u = usrp.source_c(0, usrp_decim)
		print "USRP Serial: ", self.u.serial_number()
		demod_rate = self.u.adc_rate() / usrp_decim		# 256 kS/s
		audio_decim = 8
		audio_rate = demod_rate / audio_decim			# 32 kS/s
		if options.rx_subdev_spec is None:
			options.rx_subdev_spec = usrp.pick_subdev(self.u, dblist)

		self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
		self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
		print "Using d'board", self.subdev.side_and_name()


		# gain, volume, frequency
		self.gain = options.gain
		if options.gain is None:
			self.gain = self.subdev.gain_range()[1]

		self.vol = options.volume
		if self.vol is None:
			g = self.volume_range()
			self.vol = float(g[0]+g[1])/2

		self.freq = options.freq
		if abs(self.freq) < 1e6:
			self.freq *= 1e6
		
		print "Volume:%r, Gain:%r, Freq:%3.1f MHz" % (self.vol, self.gain, self.freq/1e6)

		# channel filter, wfm_rcv_pll
		chan_filt_coeffs = optfir.low_pass(
			1,				# gain
			demod_rate,		# rate
			80e3,			# passband cutoff
			115e3,			# stopband cutoff
			0.1,			# passband ripple
			60)				# stopband attenuation
		self.chan_filt = gr.fir_filter_ccf (1, chan_filt_coeffs)
		self.guts = blks2.wfm_rcv_pll (demod_rate, audio_decim)
		self.connect(self.u, self.chan_filt, self.guts)

		# volume control, audio sink
		self.volume_control_l = gr.multiply_const_ff(self.vol)
		self.volume_control_r = gr.multiply_const_ff(self.vol)
		self.audio_sink = audio.sink(int(audio_rate), options.audio_output, False)
		self.connect ((self.guts, 0), self.volume_control_l, (self.audio_sink, 0))
		self.connect ((self.guts, 1), self.volume_control_r, (self.audio_sink, 1))

		# pilot channel filter (band-pass, 18.5-19.5kHz)
		pilot_filter_coeffs = gr.firdes.band_pass(
			1,				# gain
			demod_rate,		# sampling rate
			18.5e3,			# low cutoff
			19.5e3,			# high cutoff
			1e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.pilot_filter = gr.fir_filter_fff(1, pilot_filter_coeffs)
		self.connect(self.guts.fm_demod, self.pilot_filter)

		# RDS channel filter (band-pass, 54-60kHz)
		rds_filter_coeffs = gr.firdes.band_pass(
			1,				# gain
			demod_rate,		# sampling rate
			54e3,			# low cutoff
			60e3,			# high cutoff
			3e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.rds_filter = gr.fir_filter_fff(1, rds_filter_coeffs)
		self.connect(self.guts.fm_demod, self.rds_filter)

		# create 57kHz subcarrier from 19kHz pilot, downconvert RDS channel
		self.mixer = gr.multiply_ff()
		self.connect(self.pilot_filter, (self.mixer, 0))
		self.connect(self.pilot_filter, (self.mixer, 1))
		self.connect(self.pilot_filter, (self.mixer, 2))
		self.connect(self.rds_filter, (self.mixer, 3))

		# low-pass the baseband RDS signal at 1.5kHz
		rds_bb_filter_coeffs = gr.firdes.low_pass(
			1,				# gain
			demod_rate,		# sampling rate
			1.5e3,			# passband cutoff
			2e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.rds_bb_filter = gr.fir_filter_fff(1, rds_bb_filter_coeffs)
		self.connect(self.mixer, self.rds_bb_filter)

		# 1187.5bps = 19kHz/16
		self.rds_clock = rds.freq_divider(16)
		clock_taps = gr.firdes.low_pass(
			1,				# gain
			demod_rate,		# sampling rate
			1.2e3,			# passband cutoff
			1.5e3,			# transition width
			gr.firdes.WIN_HANN)
		self.clock_filter = gr.fir_filter_fff(1, clock_taps)
		self.connect(self.pilot_filter, self.rds_clock, self.clock_filter)

		# bpsk_demod, diff_decoder, rds_decoder
		self.bpsk_demod = rds.bpsk_demod(demod_rate)
		self.differential_decoder = gr.diff_decoder_bb(2)
		self.msgq = gr.msg_queue()
		self.rds_decoder = rds.data_decoder(self.msgq)
		self.connect(self.rds_bb_filter, (self.bpsk_demod, 0))
		self.connect(self.clock_filter, (self.bpsk_demod, 1))
		self.connect(self.bpsk_demod, self.differential_decoder)
		self.connect(self.differential_decoder, self.rds_decoder)

		# set initial values
		self.subdev.set_gain(self.gain)
		self.set_vol(self.vol)
		self.set_freq(self.freq)
Esempio n. 17
0
    def __init__(self):
        gr.top_block.__init__(self)

        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=91.2e6,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB")
        parser.add_option("-s",
                          "--squelch",
                          type="eng_float",
                          default=0,
                          help="set squelch level (default is 0)")
        parser.add_option("-V",
                          "--volume",
                          type="eng_float",
                          default=None,
                          help="set volume (default is midpoint)")
        parser.add_option("-O",
                          "--audio-output",
                          type="string",
                          default="plughw:0,0",
                          help="pcm device name (default is plughw:0,0)")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        # connect to USRP
        usrp_decim = 250
        self.u = usrp.source_c(0, usrp_decim)
        print "USRP Serial: ", self.u.serial_number()
        demod_rate = self.u.adc_rate() / usrp_decim  # 256 kS/s
        audio_decim = 8
        audio_rate = demod_rate / audio_decim  # 32 kS/s
        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_subdev(self.u, dblist)

        self.u.set_mux(
            usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
        print "Using d'board", self.subdev.side_and_name()

        # gain, volume, frequency
        self.gain = options.gain
        if options.gain is None:
            self.gain = self.subdev.gain_range()[1]

        self.vol = options.volume
        if self.vol is None:
            g = self.volume_range()
            self.vol = float(g[0] + g[1]) / 2

        self.freq = options.freq
        if abs(self.freq) < 1e6:
            self.freq *= 1e6

        print "Volume:%r, Gain:%r, Freq:%3.1f MHz" % (self.vol, self.gain,
                                                      self.freq / 1e6)

        # channel filter, wfm_rcv_pll
        chan_filt_coeffs = optfir.low_pass(
            1,  # gain
            demod_rate,  # rate
            80e3,  # passband cutoff
            115e3,  # stopband cutoff
            0.1,  # passband ripple
            60)  # stopband attenuation
        self.chan_filt = gr.fir_filter_ccf(1, chan_filt_coeffs)
        self.guts = blks2.wfm_rcv_pll(demod_rate, audio_decim)
        self.connect(self.u, self.chan_filt, self.guts)

        # volume control, audio sink
        self.volume_control_l = gr.multiply_const_ff(self.vol)
        self.volume_control_r = gr.multiply_const_ff(self.vol)
        self.audio_sink = audio.sink(int(audio_rate), options.audio_output,
                                     False)
        self.connect((self.guts, 0), self.volume_control_l,
                     (self.audio_sink, 0))
        self.connect((self.guts, 1), self.volume_control_r,
                     (self.audio_sink, 1))

        # pilot channel filter (band-pass, 18.5-19.5kHz)
        pilot_filter_coeffs = gr.firdes.band_pass(
            1,  # gain
            demod_rate,  # sampling rate
            18.5e3,  # low cutoff
            19.5e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.pilot_filter = gr.fir_filter_fff(1, pilot_filter_coeffs)
        self.connect(self.guts.fm_demod, self.pilot_filter)

        # RDS channel filter (band-pass, 54-60kHz)
        rds_filter_coeffs = gr.firdes.band_pass(
            1,  # gain
            demod_rate,  # sampling rate
            54e3,  # low cutoff
            60e3,  # high cutoff
            3e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.rds_filter = gr.fir_filter_fff(1, rds_filter_coeffs)
        self.connect(self.guts.fm_demod, self.rds_filter)

        # create 57kHz subcarrier from 19kHz pilot, downconvert RDS channel
        self.mixer = gr.multiply_ff()
        self.connect(self.pilot_filter, (self.mixer, 0))
        self.connect(self.pilot_filter, (self.mixer, 1))
        self.connect(self.pilot_filter, (self.mixer, 2))
        self.connect(self.rds_filter, (self.mixer, 3))

        # low-pass the baseband RDS signal at 1.5kHz
        rds_bb_filter_coeffs = gr.firdes.low_pass(
            1,  # gain
            demod_rate,  # sampling rate
            1.5e3,  # passband cutoff
            2e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.rds_bb_filter = gr.fir_filter_fff(1, rds_bb_filter_coeffs)
        self.connect(self.mixer, self.rds_bb_filter)

        # 1187.5bps = 19kHz/16
        self.rds_clock = rds.freq_divider(16)
        clock_taps = gr.firdes.low_pass(
            1,  # gain
            demod_rate,  # sampling rate
            1.2e3,  # passband cutoff
            1.5e3,  # transition width
            gr.firdes.WIN_HANN)
        self.clock_filter = gr.fir_filter_fff(1, clock_taps)
        self.connect(self.pilot_filter, self.rds_clock, self.clock_filter)

        # bpsk_demod, diff_decoder, rds_decoder
        self.bpsk_demod = rds.bpsk_demod(demod_rate)
        self.differential_decoder = gr.diff_decoder_bb(2)
        self.msgq = gr.msg_queue()
        self.rds_decoder = rds.data_decoder(self.msgq)
        self.connect(self.rds_bb_filter, (self.bpsk_demod, 0))
        self.connect(self.clock_filter, (self.bpsk_demod, 1))
        self.connect(self.bpsk_demod, self.differential_decoder)
        self.connect(self.differential_decoder, self.rds_decoder)

        # set initial values
        self.subdev.set_gain(self.gain)
        self.set_vol(self.vol)
        self.set_freq(self.freq)