Ejemplo n.º 1
0
    def _setup_usrp_sink(self):
        """
        Creates a USRP sink, determines the settings for best bitrate,
        and attaches to the transmitter's subdevice.
        """
        self.tx_u = usrp.sink_c(fusb_block_size=self._fusb_block_size,
                             fusb_nblocks=self._fusb_nblocks)

        self.tx_u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if self._tx_subdev_spec is None:
            print 'tx subdev not set'
            self._tx_subdev_spec = usrp.pick_tx_subdevice(self.tx_u)
        self.tx_u.set_mux(usrp.determine_tx_mux_value(self.tx_u, self._tx_subdev_spec))
        self.tx_subdev = usrp.selected_subdev(self.tx_u, self._tx_subdev_spec)

        # Set center frequency of USRP
        ok = self.tx_u.tune(1, self.tx_subdev, self._tx_freq)
        if not ok:
            print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(self._tx_freq),)
            raise ValueError


        # enable Auto Transmit/Receive switching
        self.tx_subdev.set_auto_tr(True)
    def __init__(self, fg, subdev_spec, interp, spb, use_barker):

        self.normal_gain = 28000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate();

        self._spb = spb
        self._interp=int(interp)
        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(self.u)

        self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        # transmitter
        self.packet_transmitter = bbn_80211b_mod_pkts(fg, spb=spb,
                                                      alpha=0.5,
                                                      gain=self.normal_gain,
                                                      use_barker=use_barker)
        fg.connect(self.packet_transmitter, self.u)
        gr.hier_block.__init__(self, fg, None, None)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)    # enable Auto Transmit/Receive switching
Ejemplo n.º 3
0
    def _setup_usrp_sink(self):
        """
        Creates a USRP sink, determines the settings for best bitrate,
        and attaches to the transmitter's subdevice.
        """
        self.u = usrp.sink_c(fusb_block_size=self._fusb_block_size,
                             fusb_nblocks=self._fusb_nblocks)

        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if self._tx_subdev_spec is None:
            self._tx_subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, self._tx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, self._tx_subdev_spec)

        # Set center frequency of USRP
        ok = self.set_freq(self._tx_freq)
        if not ok:
            print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(self._tx_freq),)
            raise ValueError

        # Set the USRP for maximum transmit gain
        # (Note that on the RFX cards this is a nop.)
        self.set_gain(self.subdev.gain_range()[1])

        # enable Auto Transmit/Receive switching
        self.set_auto_tr(True)
Ejemplo n.º 4
0
    def _setup_usrp_sink(self):
        """
        Creates a USRP sink, determines the settings for best bitrate,
        and attaches to the transmitter's subdevice.
        """
        self.u = usrp.sink_c(fusb_block_size=self._fusb_block_size,
                             fusb_nblocks=self._fusb_nblocks)

        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if self._tx_subdev_spec is None:
            self._tx_subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(
            usrp.determine_tx_mux_value(self.u, self._tx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, self._tx_subdev_spec)

        # Set center frequency of USRP
        ok = self.set_freq(self._tx_freq)
        if not ok:
            print "Failed to set Tx frequency to %s" % (
                eng_notation.num_to_str(self._tx_freq), )
            raise ValueError

        # Set the USRP for maximum transmit gain
        # (Note that on the RFX cards this is a nop.)
        self.set_gain(self.subdev.gain_range()[1])

        # enable Auto Transmit/Receive switching
        self.set_auto_tr(True)
Ejemplo n.º 5
0
    def __init__(self, options):
        gr.flow_graph.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate()
        self._data_rate = 2000000
        self._spb = 2
        self._interp = int(128e6 / self._spb / self._data_rate)
        self.fs = 128e6 / self._interp

        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        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)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.u.tune(self.subdev._which, self.subdev, options.cordic_freq_tx)
        self.u.set_pga(0, options.gain)
        self.u.set_pga(1, options.gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(
            self, spb=self._spb, msgq_limit=2)
        self.gain = gr.multiply_const_cc(self.normal_gain)

        self.connect(self.packet_transmitter, self.gain, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)  # enable Auto Transmit/Receive switching
Ejemplo n.º 6
0
    def __init__(self, options):
        gr.flow_graph.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate();
        self._data_rate = 2000000
        self._spb = 2
        self._interp = int(128e6 / self._spb / self._data_rate)
        self.fs = 128e6 / self._interp

        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        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)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.u.tune(self.subdev._which, self.subdev, options.cordic_freq_tx)
        self.u.set_pga(0, options.gain)
        self.u.set_pga(1, options.gain)

        # transmitter
        self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2)
        self.gain = gr.multiply_const_cc (self.normal_gain)
        
        self.connect(self.packet_transmitter, self.gain, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching
Ejemplo n.º 7
0
    def _setup_usrp_sink(self):
        """
        Creates a USRP sink, determines the settings for best bitrate,
        and attaches to the transmitter's subdevice.
        """
        self.tx_u = usrp.sink_c(fusb_block_size=self._fusb_block_size,
                                fusb_nblocks=self._fusb_nblocks)

        self.tx_u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if self._tx_subdev_spec is None:
            print 'tx subdev not set'
            self._tx_subdev_spec = usrp.pick_tx_subdevice(self.tx_u)
        self.tx_u.set_mux(
            usrp.determine_tx_mux_value(self.tx_u, self._tx_subdev_spec))
        self.tx_subdev = usrp.selected_subdev(self.tx_u, self._tx_subdev_spec)

        # Set center frequency of USRP
        ok = self.tx_u.tune(1, self.tx_subdev, self._tx_freq)
        if not ok:
            print "Failed to set Tx frequency to %s" % (
                eng_notation.num_to_str(self._tx_freq), )
            raise ValueError

        # enable Auto Transmit/Receive switching
        self.tx_subdev.set_auto_tr(True)
Ejemplo n.º 8
0
    def __init__(self, subdev_spec, audio_input):
        gr.hier_block2.__init__(
            self,
            "transmit_path",
            gr.io_signature(0, 0, 0),  # Input signature
            gr.io_signature(0, 0, 0))  # Output signature

        self.u = usrp.sink_c()

        dac_rate = self.u.dac_rate()
        self.if_rate = 320e3  # 320 kS/s
        self.usrp_interp = int(dac_rate // self.if_rate)
        self.u.set_interp_rate(self.usrp_interp)
        self.sw_interp = 10
        self.audio_rate = self.if_rate // self.sw_interp  #  32 kS/s

        self.audio_gain = 10
        self.normal_gain = 32000

        self.audio = audio.source(int(self.audio_rate), audio_input)
        self.audio_amp = gr.multiply_const_ff(self.audio_gain)

        lpf = gr.firdes.low_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            3800,  # low pass cutoff freq
            300,  # width of trans. band
            gr.firdes.WIN_HANN)  # filter type

        hpf = gr.firdes.high_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            325,  # low pass cutoff freq
            50,  # width of trans. band
            gr.firdes.WIN_HANN)  # filter type

        audio_taps = convolve(array(lpf), array(hpf))
        self.audio_filt = gr.fir_filter_fff(1, audio_taps)

        self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0)
        self.add_pl = gr.add_ff()
        self.connect(self.pl, (self.add_pl, 1))

        self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate)
        self.amp = gr.multiply_const_cc(self.normal_gain)

        # determine the daughterboard subdevice we're using
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "TX using", self.subdev.name()

        self.connect(self.audio, self.audio_amp, self.audio_filt,
                     (self.add_pl, 0), self.fmtx, self.amp, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
Ejemplo n.º 9
0
    def __init__(self, subdev_spec, freq, subdev_gain, filename, delay):

        gr.top_block.__init__(self)

        # data sink and sink rate
        u = usrp.sink_c()

        # important vars (to be calculated from USRP when available
        dac_rate = u.dac_rate()
        usrp_rate = 320e3
        usrp_interp = int(dac_rate // usrp_rate)
        channel_rate = 32e3
        interp_factor = int(usrp_rate // channel_rate)

        # open the pcap source
        pcap = op25.pcap_source_b(filename, delay)
        #        pcap = gr.glfsr_source_b(16)

        # convert octets into dibits
        bits_per_symbol = 2
        unpack = gr.packed_to_unpacked_bb(bits_per_symbol, gr.GR_MSB_FIRST)

        # modulator
        c4fm = p25_mod_bf(output_rate=channel_rate)

        # setup low pass filter + interpolator
        low_pass = 2.88e3
        interp_taps = gr.firdes.low_pass(1.0, channel_rate, low_pass,
                                         low_pass * 0.1, gr.firdes.WIN_HANN)
        interpolator = gr.interp_fir_filter_fff(int(interp_factor),
                                                interp_taps)

        # frequency modulator
        max_dev = 12.5e3
        k = 2 * math.pi * max_dev / usrp_rate
        adjustment = 1.5  # adjust for proper c4fm deviation level
        fm = gr.frequency_modulator_fc(k * adjustment)

        # signal gain
        gain = gr.multiply_const_cc(4000)

        # configure USRP
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(u)
        u.set_mux(usrp.determine_tx_mux_value(u, subdev_spec))
        self.db = usrp.selected_subdev(u, subdev_spec)
        print "Using TX d'board %s" % (self.db.side_and_name(), )
        u.set_interp_rate(usrp_interp)

        if gain is None:
            g = self.db.gain_range()
            gain = float(g[0] + g[1]) / 2
        self.db.set_gain(self.db.gain_range()[0])
        u.tune(self.db.which(), self.db, freq)
        self.db.set_enable(True)

        self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
Ejemplo n.º 10
0
    def __init__(self, subdev_spec, audio_input):
        gr.hier_block2.__init__(
            self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)  # Input signature
        )  # Output signature

        self.u = usrp.sink_c()

        dac_rate = self.u.dac_rate()
        self.if_rate = 320e3  # 320 kS/s
        self.usrp_interp = int(dac_rate // self.if_rate)
        self.u.set_interp_rate(self.usrp_interp)
        self.sw_interp = 10
        self.audio_rate = self.if_rate // self.sw_interp  #  32 kS/s

        self.audio_gain = 10
        self.normal_gain = 32000

        self.audio = audio.source(int(self.audio_rate), audio_input)
        self.audio_amp = gr.multiply_const_ff(self.audio_gain)

        lpf = gr.firdes.low_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            3800,  # low pass cutoff freq
            300,  # width of trans. band
            gr.firdes.WIN_HANN,
        )  # filter type

        hpf = gr.firdes.high_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            325,  # low pass cutoff freq
            50,  # width of trans. band
            gr.firdes.WIN_HANN,
        )  # filter type

        audio_taps = convolve(array(lpf), array(hpf))
        self.audio_filt = gr.fir_filter_fff(1, audio_taps)

        self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0)
        self.add_pl = gr.add_ff()
        self.connect(self.pl, (self.add_pl, 1))

        self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate)
        self.amp = gr.multiply_const_cc(self.normal_gain)

        # determine the daughterboard subdevice we're using
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        print "TX using", self.subdev.name()

        self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
Ejemplo n.º 11
0
    def __init__(self):
        gr.flow_graph.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-T",
            "--tx-subdev-spec",
            type="subdev",
            default=None,
            help=
            "select USRP Tx side A or B (default=first one with a daughterboard)"
        )
        parser.add_option("-c",
                          "--cordic-freq",
                          type="eng_float",
                          default=434845200,
                          help="set Tx cordic frequency to FREQ",
                          metavar="FREQ")

        (options, args) = parser.parse_args()
        print "cordic_freq = %s" % (eng_notation.num_to_str(
            options.cordic_freq))

        self.normal_gain = 8000
        self.u = usrp.sink_s()
        dac_rate = self.u.dac_rate()
        self._freq = 1000
        self._spb = 256
        self._interp = int(128e6 / self._spb / self._freq)
        self.fs = 128e6 / self._interp
        print "Interpolation:", self._interp

        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        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)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.u.tune(self.subdev._which, self.subdev, options.cordic_freq)

        self.sin = gr.sig_source_f(self.fs, gr.GR_SIN_WAVE, self._freq, 1, 0)
        self.gain = gr.multiply_const_ff(self.normal_gain)
        self.ftos = gr.float_to_short()

        self.filesink = gr.file_sink(gr.sizeof_float, 'sin.dat')

        self.connect(self.sin, self.gain)
        self.connect(self.gain, self.ftos, self.u)
        #self.connect(self.gain, self.filesink)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)  # enable Auto Transmit/Receive switching
Ejemplo n.º 12
0
 def _setup_usrp1(self):
     self._u = usrp.sink_c (self._which,
                             fusb_block_size=self._fusb_block_size,
                             fusb_nblocks=self._fusb_nblocks)
     # determine the daughterboard subdevice we're using
     if self._subdev_spec is None:
         self._subdev_spec = usrp.pick_tx_subdevice(self._u)
     self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
     self._u.set_mux(usrp.determine_tx_mux_value(self._u, self._subdev_spec))
     self._dxc = self._subdev.which()
Ejemplo n.º 13
0
    def __init__(self, subdev_spec, freq, subdev_gain, filename, delay):

        gr.top_block.__init__ (self)

        # data sink and sink rate
        u = usrp.sink_c()

        # important vars (to be calculated from USRP when available
        dac_rate = u.dac_rate()
        usrp_rate = 320e3
        usrp_interp = int(dac_rate // usrp_rate)
        channel_rate = 32e3
        interp_factor = int(usrp_rate // channel_rate)

        # open the pcap source
        pcap = op25.pcap_source_b(filename, delay)
#        pcap = gr.glfsr_source_b(16)

        # convert octets into dibits
        bits_per_symbol = 2
        unpack = gr.packed_to_unpacked_bb(bits_per_symbol, gr.GR_MSB_FIRST)

        # modulator
        c4fm = p25_mod_bf(output_rate=channel_rate)

        # setup low pass filter + interpolator
        low_pass = 2.88e3
        interp_taps = gr.firdes.low_pass(1.0, channel_rate, low_pass, low_pass * 0.1, gr.firdes.WIN_HANN)
        interpolator = gr.interp_fir_filter_fff (int(interp_factor), interp_taps)

        # frequency modulator
        max_dev = 12.5e3
        k = 2 * math.pi * max_dev / usrp_rate
        adjustment = 1.5   # adjust for proper c4fm deviation level
        fm = gr.frequency_modulator_fc(k * adjustment)

        # signal gain
        gain = gr.multiply_const_cc(4000)

        # configure USRP
        if subdev_spec is None:
            subdev_spec = usrp.pick_tx_subdevice(u)
        u.set_mux(usrp.determine_tx_mux_value(u, subdev_spec))
        self.db = usrp.selected_subdev(u, subdev_spec)
        print "Using TX d'board %s" % (self.db.side_and_name(),)
        u.set_interp_rate(usrp_interp)

        if gain is None:
            g = self.db.gain_range()
            gain = float(g[0] + g[1]) / 2
        self.db.set_gain(self.db.gain_range()[0])
        u.tune(self.db.which(), self.db, freq)
        self.db.set_enable(True)

        self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
Ejemplo n.º 14
0
 def _setup_usrp1(self):
     self._u = usrp.sink_c(self._which,
                           fusb_block_size=self._fusb_block_size,
                           fusb_nblocks=self._fusb_nblocks)
     # determine the daughterboard subdevice we're using
     if self._subdev_spec is None:
         self._subdev_spec = usrp.pick_tx_subdevice(self._u)
     self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
     self._u.set_mux(usrp.determine_tx_mux_value(self._u,
                                                 self._subdev_spec))
     self._dxc = self._subdev.which()
Ejemplo n.º 15
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()
Ejemplo n.º 16
0
    def _setup_usrp_sink(self):
        self.u_snk = usrp.sink_c(which = self._usrp,
                                 fusb_block_size = self._fusb_block_size,
                                 fusb_nblocks = self._fusb_nblocks)
        self.u_snk.set_verbose(self._verbose)

        self.u_snk.set_interp_rate(int(self.u_snk.converter_rate() / self._sample_rate))

        # determine the daughterboard subdevice we're using
        if self._tx_subdev_spec is None:
            self._tx_subdev_spec = usrp.pick_tx_subdevice(self.u_snk)

        self.u_snk.set_mux(usrp.determine_tx_mux_value(self.u_snk, self._tx_subdev_spec))
        self.tx_subdev = usrp.selected_subdev(self.u_snk, self._tx_subdev_spec)
        self.tx_subdev.set_auto_tr(True)
        self.tx_subdev.set_gain(self.tx_subdev.gain_range()[1])
    def __init__(self, loopback=False,ampl=4096,verbose=False,debug=False):
	self._loopback=loopback
        self._amplitude = ampl
	self._verbose = verbose
	self._debug = debug
        self._u = usrp.sink_s(fpga_filename='usrp_sounder.rbf')
	if not self._loopback:
            self._subdev_spec = usrp.pick_tx_subdevice(self._u)
            self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
            if self._verbose:
                print "Using", self._subdev.name(), "for sounder transmitter."            
        self.set_amplitude(ampl)
	if not self._loopback:
          self._subdev.set_lo_offset(0.0)
        self._u.start()
	if not self._loopback:
	  self._subdev.set_enable(True)
Ejemplo n.º 18
0
    def __init__(self, loopback=False,ampl=4096,verbose=False,debug=False):
	self._loopback=loopback
        self._amplitude = ampl
	self._verbose = verbose
	self._debug = debug
        self._u = usrp.sink_s(fpga_filename='usrp_sounder.rbf')
	if not self._loopback:
            self._subdev_spec = usrp.pick_tx_subdevice(self._u)
            self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
            if self._verbose:
                print "Using", self._subdev.name(), "for sounder transmitter."            
        self.set_amplitude(ampl)
	if not self._loopback:
          self._subdev.set_lo_offset(0.0)
        self._u.start()
	if not self._loopback:
	  self._subdev.set_enable(True)
Ejemplo n.º 19
0
def setup_usrp(freq):

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

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

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

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

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

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

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

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

  return utx, urx
Ejemplo n.º 20
0
    def __init__(self, options):
        self._subdev_spec = options.tx_subdev_spec
        self._verbose = options.verbose
        self._debug = options.debug
        self._u = usrp.sink_s(fpga_filename='usrp_radar_mono.rbf')

        if self._subdev_spec == None:
            self._subdev_spec = usrp.pick_tx_subdevice(self._u)

        self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
        self._subdev.set_lo_offset(0.0)
        self._ton_ticks = 0
        self._tsw_ticks = 0
        self._tlook_ticks = 0
        self._tidle_ticks = 0

        if self._verbose:
            print "Using", self._subdev.name(), "for radar transmitter."
Ejemplo n.º 21
0
    def __init__(self, options):
        self._subdev_spec = options.tx_subdev_spec
	self._verbose = options.verbose
	self._debug = options.debug
        self._u = usrp.sink_s(fpga_filename='usrp_radar_mono.rbf')

        if self._subdev_spec == None:
            self._subdev_spec = usrp.pick_tx_subdevice(self._u)

        self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
	self._subdev.set_lo_offset(0.0)
	self._ton_ticks = 0
	self._tsw_ticks = 0
	self._tlook_ticks = 0
	self._tidle_ticks = 0
	
        if self._verbose:
            print "Using", self._subdev.name(), "for radar transmitter."            
Ejemplo n.º 22
0
    def __init__(self):
        gr.flow_graph.__init__(self)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B (default=first one with a daughterboard)")
        parser.add_option ("-c", "--cordic-freq", type="eng_float", default=434845200,
                           help="set Tx cordic frequency to FREQ", metavar="FREQ")

        (options, args) = parser.parse_args ()
        print "cordic_freq = %s" % (eng_notation.num_to_str (options.cordic_freq))

        self.normal_gain = 8000
        self.u = usrp.sink_s()
        dac_rate = self.u.dac_rate();
        self._freq = 1000
        self._spb = 256
        self._interp = int(128e6 / self._spb / self._freq)
        self.fs = 128e6 / self._interp
        print "Interpolation:", self._interp
        
        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        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)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.u.tune(self.subdev._which, self.subdev, options.cordic_freq)

        self.sin = gr.sig_source_f(self.fs, gr.GR_SIN_WAVE, self._freq, 1, 0)
        self.gain = gr.multiply_const_ff (self.normal_gain)
        self.ftos = gr.float_to_short()
        
        self.filesink = gr.file_sink(gr.sizeof_float, 'sin.dat')
        
        self.connect(self.sin, self.gain)
        self.connect(self.gain, self.ftos, self.u)
        #self.connect(self.gain, self.filesink)
        
        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching
Ejemplo n.º 23
0
    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
Ejemplo n.º 24
0
    def _setup_usrp_sink(self):
        """
        Creates a USRP sink, determines the settings for best bitrate,
        and attaches to the transmitter's subdevice.
        """
        self.u = usrp.sink_c(fusb_block_size=self._fusb_block_size,fusb_nblocks=self._fusb_nblocks)
        dac_rate = self.u.dac_rate();

        # derive values of bitrate, samples_per_symbol, and interp from desired info
        (self._bitrate, self._samples_per_symbol, self._interp) = \
            pick_tx_bitrate(self._bitrate, self._modulator_class.bits_per_symbol(),
                            self._samples_per_symbol, self._interp, dac_rate)
        
        self.u.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if self._tx_subdev_spec is None:
            self._tx_subdev_spec = usrp.pick_tx_subdevice(self.u)
        self.u.set_mux(usrp.determine_tx_mux_value(self.u, self._tx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, self._tx_subdev_spec)
Ejemplo n.º 25
0
    def _setup_usrp_sink(self):
        """
        Creates a USRP sink, determines the settings for best bitrate,
        and attaches to the transmitter's subdevice.
        """
        self.u_snk = usrp.sink_c(fusb_block_size=self._fusb_block_size,
                                 fusb_nblocks=self._fusb_nblocks)

        self.u_snk.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if self._tx_subdev_spec is None:
            self._tx_subdev_spec = usrp.pick_tx_subdevice(self.u_snk)
        self.u_snk.set_mux(usrp.determine_tx_mux_value(self.u_snk, self._tx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u_snk, self._tx_subdev_spec)

        # Set the USRP for maximum transmit gain
        # (Note that on the RFX cards this is a nop.)
        self.set_gain(self.subdev.gain_range()[1])

        # enable Auto Transmit/Receive switching
        self.set_auto_tr(True)
Ejemplo n.º 26
0
    def _setup_usrp_sink(self):
        """
        Creates a USRP sink, determines the settings for best bitrate,
        and attaches to the transmitter's subdevice.
        """
        self.u_snk = usrp.sink_c(fusb_block_size=self._fusb_block_size,
                                 fusb_nblocks=self._fusb_nblocks)

        self.u_snk.set_interp_rate(self._interp)

        # determine the daughterboard subdevice we're using
        if self._tx_subdev_spec is None:
            self._tx_subdev_spec = usrp.pick_tx_subdevice(self.u_snk)
        self.u_snk.set_mux(
            usrp.determine_tx_mux_value(self.u_snk, self._tx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u_snk, self._tx_subdev_spec)

        # Set the USRP for maximum transmit gain
        # (Note that on the RFX cards this is a nop.)
        self.set_gain(self.subdev.gain_range()[1])

        # enable Auto Transmit/Receive switching
        self.set_auto_tr(True)
Ejemplo n.º 27
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-T",
                          "--tx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set Tx frequency to FREQ [required]",
                          metavar="FREQ")
        parser.add_option("-n",
                          "--nchannels",
                          type="int",
                          default=4,
                          help="number of Tx channels [1,4]")
        #parser.add_option("","--debug", action="store_true", default=False,
        #                  help="Launch Tx debugger")
        (options, args) = parser.parse_args()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write(
                "fm_tx4: nchannels out of range.  Must be in [1,%d]\n" %
                MAX_CHANNELS)
            sys.exit(1)

        if options.freq is None:
            sys.stderr.write("fm_tx4: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c()  # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()  # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp  # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp  # 32 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.subdev.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(
                    options.freq), eng_notation.num_to_str(
                        freq_range[0]), eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)  # enable transmitter

        sum = gr.add_cc()

        # Instantiate N NBFM channels
        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step,
                  -3 * step)
        for i in range(options.nchannels):
            t = pipeline("audio-%d.dat" % (i % 4), offset[i], self.audio_rate,
                         self.usrp_rate)
            self.connect(t, (sum, i))

        gain = gr.multiply_const_cc(4000.0 / options.nchannels)

        # connect it all
        self.connect(sum, gain)
        self.connect(gain, self.u)

        # plot an FFT to verify we are sending what we want
        if 1:
            post_mod = fftsink2.fft_sink_c(panel,
                                           title="Post Modulation",
                                           fft_size=512,
                                           sample_rate=self.usrp_rate,
                                           y_per_div=20,
                                           ref_level=40)
            self.connect(sum, post_mod)
            vbox.Add(post_mod.win, 1, wx.EXPAND)
Ejemplo n.º 28
0
	def __init__(self, frame, panel, vbox, argv):
		stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

		parser = OptionParser (option_class=eng_option)
		parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
						help="select USRP Tx side A or B")
		parser.add_option("-f", "--freq", type="eng_float", default=107.2e6,
						help="set Tx frequency to FREQ [required]", metavar="FREQ")
		parser.add_option("--wavfile", type="string", default="",
						help="read input from FILE")
		(options, args) = parser.parse_args()
		if len(args) != 0:
			parser.print_help()
			sys.exit(1)

		self.usrp_interp = 200
		self.u = usrp.sink_c (0, self.usrp_interp)
		print "USRP Serial: ", self.u.serial_number()
		self.dac_rate = self.u.dac_rate()					# 128 MS/s
		self.usrp_rate = self.dac_rate / self.usrp_interp	# 640 kS/s
		self.sw_interp = 5
		self.audio_rate = self.usrp_rate / self.sw_interp	# 128 kS/s

		# determine the daughterboard subdevice we're using
		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)
		print "Using d'board: ", self.subdev.side_and_name()

		# set max Tx gain, tune frequency and enable transmitter
		self.subdev.set_gain(self.subdev.gain_range()[1])
		if self.u.tune(self.subdev.which(), self.subdev, options.freq):
			print "Tuned to", options.freq/1e6, "MHz"
		else:
			sys.exit(1)
		self.subdev.set_enable(True)

		# open wav file containing floats in the [-1, 1] range, repeat
		if options.wavfile is None:
			print "Please provide a wavfile to transmit! Exiting\n"
			sys.exit(1)
		self.src = gr.wavfile_source (options.wavfile, True)
		nchans = self.src.channels()
		sample_rate = self.src.sample_rate()
		bits_per_sample = self.src.bits_per_sample()
		print nchans, "channels,", sample_rate, "kS/s,", bits_per_sample, "bits/sample"

		# resample to 128kS/s
		if sample_rate == 44100:
			self.resample_left = blks2.rational_resampler_fff(32,11)
			self.resample_right = blks2.rational_resampler_fff(32,11)
		elif sample_rate == 48000:
			self.resample_left == blks2.rational_resampler_fff(8,3)
			self.resample_right == blks2.rational_resampler_fff(8,3)
		elif sample_rate == 8000:
			self.resample_left == blks2.rational_resampler_fff(16,1)
			self.resample_right == blks2.rational_resampler_fff(16,1)
		else:
			print sample_rate, "is an unsupported sample rate"
			sys.exit(1)
		self.connect ((self.src, 0), self.resample_left)
		self.connect ((self.src, 1), self.resample_right)

		# create L+R (mono) and L-R (stereo)
		self.audio_lpr = gr.add_ff()
		self.audio_lmr = gr.sub_ff()
		self.connect (self.resample_left, (self.audio_lpr, 0))
		self.connect (self.resample_left, (self.audio_lmr, 0))
		self.connect (self.resample_right, (self.audio_lpr, 1))
		self.connect (self.resample_right, (self.audio_lmr, 1))

		# low-pass filter for L+R
		audio_lpr_taps = gr.firdes.low_pass (0.3,	# gain
											self.audio_rate,	# sampling rate
											15e3,				# passband cutoff
											2e3,				# transition width
											gr.firdes.WIN_HANN)
		self.audio_lpr_filter = gr.fir_filter_fff (1, audio_lpr_taps)
		self.connect (self.audio_lpr, self.audio_lpr_filter)

		# create pilot tone at 19 kHz
		self.pilot = gr.sig_source_f(self.audio_rate,	# sampling freq
									gr.GR_SIN_WAVE,		# waveform
									19e3,				# frequency
									3e-2)				# amplitude

		# create the L-R signal carrier at 38 kHz, high-pass to remove 0Hz tone
		self.stereo_carrier = gr.multiply_ff()
		self.connect (self.pilot, (self.stereo_carrier, 0))
		self.connect (self.pilot, (self.stereo_carrier, 1))
		stereo_carrier_taps = gr.firdes.high_pass (1,			# gain
											self.audio_rate,	# sampling rate
											1e4,				# cutoff freq
											2e3,				# transition width
											gr.firdes.WIN_HANN)
		self.stereo_carrier_filter = gr.fir_filter_fff(1, stereo_carrier_taps)
		self.connect (self.stereo_carrier, self.stereo_carrier_filter)

		# upconvert L-R to 23-53 kHz and band-pass
		self.mix_stereo = gr.multiply_ff()
		audio_lmr_taps = gr.firdes.band_pass (3e3,				# gain
											self.audio_rate,	# sampling rate
											23e3,				# low cutoff
											53e3,				# high cuttof
											2e3,				# transition width
											gr.firdes.WIN_HANN)
		self.audio_lmr_filter = gr.fir_filter_fff (1, audio_lmr_taps)
		self.connect (self.audio_lmr, (self.mix_stereo, 0))
		self.connect (self.stereo_carrier_filter, (self.mix_stereo, 1))
		self.connect (self.mix_stereo, self.audio_lmr_filter)

		# mix L+R, pilot and L-R
		self.mixer = gr.add_ff()
		self.connect (self.audio_lpr_filter, (self.mixer, 0))
		self.connect (self.pilot, (self.mixer, 1))
		self.connect (self.audio_lmr_filter, (self.mixer, 2))

		# interpolation & pre-emphasis
		interp_taps = gr.firdes.low_pass (self.sw_interp,	# gain
										self.audio_rate,	# Fs
										60e3,				# cutoff freq
										5e3,				# transition width
										gr.firdes.WIN_HAMMING)
		self.interpolator = gr.interp_fir_filter_fff (self.sw_interp, interp_taps)
		self.pre_emph = blks2.fm_preemph(self.usrp_rate, tau=50e-6)
		self.connect (self.mixer, self.interpolator, self.pre_emph)

		# fm modulation, gain & TX
		max_dev = 100e3
		k = 2 * math.pi * max_dev / self.usrp_rate		# modulator sensitivity
		self.modulator = gr.frequency_modulator_fc (k)
		self.gain = gr.multiply_const_cc (1e3)
		self.connect (self.pre_emph, self.modulator, self.gain, self.u)

		# plot an FFT to verify we are sending what we want
		pre_mod = fftsink2.fft_sink_f(panel, title="Before Interpolation",
			fft_size=512, sample_rate=self.audio_rate, y_per_div=20, ref_level=20)
		self.connect (self.mixer, pre_mod)
		vbox.Add (pre_mod.win, 1, wx.EXPAND)
Ejemplo n.º 29
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-T",
                          "--tx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=107.2e6,
                          help="set Tx frequency to FREQ [required]",
                          metavar="FREQ")
        parser.add_option("--wavfile",
                          type="string",
                          default=None,
                          help="open .wav audio file FILE")
        parser.add_option("--xml",
                          type="string",
                          default="rds_data.xml",
                          help="open .xml RDS data FILE")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        usrp_interp = 500
        self.u = usrp.sink_c(0, usrp_interp)
        print "USRP Serial: ", self.u.serial_number()
        usrp_rate = self.u.dac_rate() / usrp_interp  # 256 kS/s

        # determine the daughterboard subdevice we're using
        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)
        print "Using d'board", self.subdev.side_and_name()

        # set max Tx gain, tune frequency and enable transmitter
        gain = self.subdev.gain_range()[1]
        self.subdev.set_gain(gain)
        print "Gain set to", gain
        if self.u.tune(self.subdev.which(), self.subdev, options.freq):
            print "Tuned to", options.freq / 1e6, "MHz"
        else:
            sys.exit(1)
        self.subdev.set_enable(True)

        # open wav file containing floats in the [-1, 1] range, repeat
        if options.wavfile is None:
            print "Please provide a wavfile to transmit! Exiting\n"
            sys.exit(1)
        self.src = gr.wavfile_source(options.wavfile, True)
        nchans = self.src.channels()
        sample_rate = self.src.sample_rate()
        bits_per_sample = self.src.bits_per_sample()
        print nchans, "channels,", sample_rate, "samples/sec,", \
         bits_per_sample, "bits/sample"

        # resample to usrp rate
        self.resample_left = blks2.rational_resampler_fff(
            usrp_rate, sample_rate)
        self.resample_right = blks2.rational_resampler_fff(
            usrp_rate, sample_rate)
        self.connect((self.src, 0), self.resample_left)
        self.connect((self.src, 1), self.resample_right)

        # create L+R (mono) and L-R (stereo)
        self.audio_lpr = gr.add_ff()
        self.audio_lmr = gr.sub_ff()
        self.connect(self.resample_left, (self.audio_lpr, 0))
        self.connect(self.resample_left, (self.audio_lmr, 0))
        self.connect(self.resample_right, (self.audio_lpr, 1))
        self.connect(self.resample_right, (self.audio_lmr, 1))

        # low-pass filter for L+R
        audio_lpr_taps = gr.firdes.low_pass(
            0.5,  # gain
            usrp_rate,  # sampling rate
            15e3,  # passband cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.audio_lpr_filter = gr.fir_filter_fff(1, audio_lpr_taps)
        self.connect(self.audio_lpr, self.audio_lpr_filter)

        # create pilot tone at 19 kHz
        self.pilot = gr.sig_source_f(
            usrp_rate,  # sampling rate
            gr.GR_SIN_WAVE,  # waveform
            19e3,  # frequency
            5e-2)  # amplitude

        # upconvert L-R to 38 kHz and band-pass
        self.mix_stereo = gr.multiply_ff()
        audio_lmr_taps = gr.firdes.band_pass(
            80,  # gain
            usrp_rate,  # sampling rate
            38e3 - 15e3,  # low cutoff
            38e3 + 15e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.audio_lmr_filter = gr.fir_filter_fff(1, audio_lmr_taps)
        self.connect(self.audio_lmr, (self.mix_stereo, 0))
        self.connect(self.pilot, (self.mix_stereo, 1))
        self.connect(self.pilot, (self.mix_stereo, 2))
        self.connect(self.mix_stereo, self.audio_lmr_filter)

        # create RDS bitstream
        # diff-encode, manchester-emcode, NRZ
        # enforce the 1187.5bps rate
        # pulse shaping filter (matched with receiver)
        # mix with 57kHz carrier (equivalent to BPSK)
        self.rds_enc = rds.data_encoder('rds_data.xml')
        self.diff_enc = gr.diff_encoder_bb(2)
        self.manchester1 = gr.map_bb([1, 2])
        self.manchester2 = gr.unpack_k_bits_bb(2)
        self.nrz = gr.map_bb([-1, 1])
        self.c2f = gr.char_to_float()
        self.rate_enforcer = rds.rate_enforcer(usrp_rate)
        pulse_shaping_taps = gr.firdes.low_pass(
            1,  # gain
            usrp_rate,  # sampling rate
            1.5e3,  # passband cutoff
            2e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.pulse_shaping = gr.fir_filter_fff(1, pulse_shaping_taps)
        self.bpsk_mod = gr.multiply_ff()
        self.connect (self.rds_enc, self.diff_enc, self.manchester1, \
         self.manchester2, self.nrz, self.c2f)
        self.connect(self.c2f, (self.rate_enforcer, 0))
        self.connect(self.pilot, (self.rate_enforcer, 1))
        self.connect(self.rate_enforcer, (self.bpsk_mod, 0))
        self.connect(self.pilot, (self.bpsk_mod, 1))
        self.connect(self.pilot, (self.bpsk_mod, 2))
        self.connect(self.pilot, (self.bpsk_mod, 3))

        # RDS band-pass filter
        rds_filter_taps = gr.firdes.band_pass(
            50,  # gain
            usrp_rate,  # sampling rate
            57e3 - 3e3,  # low cutoff
            57e3 + 3e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.rds_filter = gr.fir_filter_fff(1, rds_filter_taps)
        self.connect(self.bpsk_mod, self.rds_filter)

        # mix L+R, pilot, L-R and RDS
        self.mixer = gr.add_ff()
        self.connect(self.audio_lpr_filter, (self.mixer, 0))
        self.connect(self.pilot, (self.mixer, 1))
        self.connect(self.audio_lmr_filter, (self.mixer, 2))
        self.connect(self.rds_filter, (self.mixer, 3))

        # fm modulation, gain & TX
        max_dev = 75e3
        k = 2 * math.pi * max_dev / usrp_rate  # modulator sensitivity
        self.modulator = gr.frequency_modulator_fc(k)
        self.gain = gr.multiply_const_cc(5e3)
        self.connect(self.mixer, self.modulator, self.gain, self.u)

        # plot an FFT to verify we are sending what we want
        if 1:
            self.fft = fftsink2.fft_sink_f(panel,
                                           title="Pre FM modulation",
                                           fft_size=512 * 4,
                                           sample_rate=usrp_rate,
                                           y_per_div=20,
                                           ref_level=-20)
            self.connect(self.mixer, self.fft)
            vbox.Add(self.fft.win, 1, wx.EXPAND)
        if 0:
            self.scope = scopesink2.scope_sink_f(panel,
                                                 title="RDS encoder output",
                                                 sample_rate=usrp_rate)
            self.connect(self.rds_enc, self.scope)
            vbox.Add(self.scope.win, 1, wx.EXPAND)
Ejemplo n.º 30
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-T",
                          "--tx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e",
                          "--enable-fft",
                          action="store_true",
                          default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set Tx frequency to FREQ [required]",
                          metavar="FREQ")
        parser.add_option("-i",
                          "--file-input",
                          action="store_true",
                          default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g",
                          "--audio-gain",
                          type="eng_float",
                          default=1.0,
                          help="input audio gain multiplier")
        parser.add_option("-n",
                          "--nchannels",
                          type="int",
                          default=2,
                          help="number of Tx channels [1,4]")
        parser.add_option("-a",
                          "--udp-addr",
                          type="string",
                          default="127.0.0.1",
                          help="UDP host IP address")
        parser.add_option("-p",
                          "--udp-port",
                          type="int",
                          default=0,
                          help="UDP port number")
        parser.add_option("-r",
                          "--repeat",
                          action="store_true",
                          default=False,
                          help="continuously replay input file")
        parser.add_option("-S",
                          "--stretch",
                          type="int",
                          default=0,
                          help="elastic buffer trigger value")
        parser.add_option("-v",
                          "--verbose",
                          action="store_true",
                          default=False,
                          help="print out stats")
        parser.add_option(
            "-I",
            "--audio-input",
            type="string",
            default="",
            help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write(
                "op25_tx: nchannels out of range.  Must be in [1,%d]\n" %
                MAX_CHANNELS)
            sys.exit(1)

        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c()  # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()  # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp  # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp  # 32 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.subdev.set_gain(self.subdev.gain_range()[0])  # set min Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(
                    options.freq), eng_notation.num_to_str(
                        freq_range[0]), eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)  # enable transmitter

        # instantiate vocoders
        self.vocoders = []
        if options.file_input:
            for i in range(options.nchannels):
                t = gr.file_source(gr.sizeof_char, "baseband-%d.dat" % i,
                                   options.repeat)
                self.vocoders.append(t)

        elif options.udp_port > 0:
            self.udp_sources = []
            for i in range(options.nchannels):
                t = gr.udp_source(1, options.udp_addr, options.udp_port + i,
                                  216)
                self.udp_sources.append(t)
                arity = 2
                t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
                self.vocoders.append(t)
                self.connect(self.udp_sources[i], self.vocoders[i])

        else:
            self.audio_amps = []
            self.converters = []
            input_audio_rate = 8000
            self.audio_input = audio.source(input_audio_rate,
                                            options.audio_input)
            for i in range(options.nchannels):
                t = gr.multiply_const_ff(32767 * options.audio_gain)
                self.audio_amps.append(t)
                t = gr.float_to_short()
                self.converters.append(t)
                t = repeater.vocoder(
                    True,  # 0=Decode,True=Encode
                    options.verbose,  # Verbose flag
                    options.stretch,  # flex amount
                    "",  # udp ip address
                    0,  # udp port
                    False)  # dump raw u vectors
                self.vocoders.append(t)
                self.connect((self.audio_input, i), self.audio_amps[i],
                             self.converters[i], self.vocoders[i])

        sum = gr.add_cc()

        # Instantiate N NBFM channels
        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step,
                  -3 * step)
        for i in range(options.nchannels):
            t = pipeline(self.vocoders[i], offset[i], self.audio_rate,
                         self.usrp_rate)
            self.connect(t, (sum, i))

        gain = gr.multiply_const_cc(4000.0 / options.nchannels)

        # connect it all
        self.connect(sum, gain)
        self.connect(gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel,
                                           title="Post Modulation",
                                           fft_size=512,
                                           sample_rate=self.usrp_rate,
                                           y_per_div=20,
                                           ref_level=40)
            self.connect(sum, post_mod)
            vbox.Add(post_mod.win, 1, wx.EXPAND)
Ejemplo n.º 31
0
    def __init__(self):

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-T",
            "--tx-subdev-spec",
            type="subdev",
            default=None,
            help=
            "select USRP Tx side A or B (default=first one with a daughterboard)"
        )
        parser.add_option("-c",
                          "--cordic-freq1",
                          type="eng_float",
                          default=434845200,
                          help="set Tx cordic frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-d",
                          "--cordic-freq2",
                          type="eng_float",
                          default=434318512,
                          help="set rx cordic frequency for channel 2 to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=0,
                          help="set Rx PGA gain in dB [0,20]")

        (options, args) = parser.parse_args()
        print "cordic_freq1 = %s" % (eng_notation.num_to_str(
            options.cordic_freq1))
        print "cordic_freq2 = %s" % (eng_notation.num_to_str(
            options.cordic_freq2))

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

        self.data_rate = 38400
        self.samples_per_symbol = 8
        self.channel_fs = self.data_rate * self.samples_per_symbol
        self.fs = 4e6
        payload_size = 128  # bytes

        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "fs = ", eng_notation.num_to_str(self.fs)

        gr.flow_graph.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate()

        self.interp = int(dac_rate / self.fs)
        print "usrp interp = ", self.interp

        self.u.set_interp_rate(self.interp)

        # determine the daughterboard subdevice we're using
        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)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        if options.cordic_freq1 < options.cordic_freq2:
            self.usrp_freq = options.cordic_freq1
            self.freq_diff = options.cordic_freq2 - options.cordic_freq1
        else:
            self.usrp_freq = options.cordic_freq2
            self.freq_diff = options.cordic_freq1 - options.cordic_freq2
        print "freq_diff = ", eng_notation.num_to_str(self.freq_diff)

        self.u.tune(self.subdev._which, self.subdev, self.usrp_freq)
        print "tune USRP to = ", eng_notation.num_to_str(self.usrp_freq)
        self.u.set_pga(0, options.gain)
        self.u.set_pga(1, options.gain)

        interp_factor = int(self.fs / self.channel_fs)
        quad_rate = self.fs
        print "interp_factor = ", interp_factor

        # Create filter for the interpolation
        interp_taps = gr.firdes.low_pass(
            interp_factor,  # gain
            self.channel_fs * interp_factor,  # Fs
            self.channel_fs / 2,  # low pass cutoff freq
            self.channel_fs * 0.1,  # width of trans. band
            gr.firdes.WIN_HANN)  #filter type

        print "len(interp_taps) =", len(interp_taps)

        self.interpolator1 = gr.interp_fir_filter_ccc(interp_factor,
                                                      interp_taps)
        self.interpolator2 = gr.interp_fir_filter_ccc(interp_factor,
                                                      interp_taps)

        self.multiplicator = gr.multiply_cc()

        self.adder = gr.add_cc()

        self.sin = gr.sig_source_c(self.channel_fs * interp_factor,
                                   gr.GR_SIN_WAVE, self.freq_diff, 1,
                                   complex(0, 0))

        # transmitter
        self.packet_transmitter1 = cc1k_sos_pkt.cc1k_mod_pkts(
            self, spb=self.samples_per_symbol, msgq_limit=2)
        #self.packet_transmitter2 = cc1k_sos_pkt.cc1k_mod_pkts(self, spb=self.samples_per_symbol, msgq_limit=2)

        self.amp = gr.multiply_const_cc(self.normal_gain)
        self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'tx_test.dat')
        self.filesink2 = gr.file_sink(gr.sizeof_gr_complex, 'tx_test2.dat')
        self.filesink3 = gr.file_sink(gr.sizeof_gr_complex, 'tx_test3.dat')

        # interpolate the two transmitters
        self.connect(self.packet_transmitter1, self.interpolator1)
        #self.connect(self.packet_transmitter2, self.interpolator2)
        # upconvert the first transmitter)
        self.connect(self.interpolator1, (self.multiplicator, 1))
        self.connect(self.sin, (self.multiplicator, 0))
        # add the two signals
        #self.connect(self.multiplicator, (self.adder, 0))
        #self.connect(self.interpolator2, (self.adder, 1))
        # send the signal to the USRP
        self.connect(self.interpolator1, self.amp, self.filesink)
        self.connect(self.multiplicator, self.filesink2)
        self.connect(self.sin, self.filesink3)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)  # enable Auto Transmit/Receive switching
Ejemplo n.º 32
0
    def __init__(self):

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B (default=first one with a daughterboard)")
        parser.add_option ("-c", "--cordic-freq", type="eng_float", default=434845200,
                           help="set Tx cordic frequency to FREQ", metavar="FREQ")
        parser.add_option ("-r", "--data-rate", type="eng_float", default=38400)
        parser.add_option ("-f", "--filename", type="string",
                           default="rx.dat", help="write data to FILENAME")
        parser.add_option ("-g", "--gain", type="eng_float", default=0,
                           help="set Rx PGA gain in dB [0,20]")
        parser.add_option ("-N", "--no-gui", action="store_true", default=False)

        (options, args) = parser.parse_args ()
        print "cordic_freq = %s" % (eng_notation.num_to_str (options.cordic_freq))

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

        self.data_rate = options.data_rate
        self.samples_per_symbol = 8
        self.fs = self.data_rate * self.samples_per_symbol
        payload_size = 128             # bytes

        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "fs = ", eng_notation.num_to_str(self.fs)

        gr.flow_graph.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate();

        self.interp = int(128e6 / self.samples_per_symbol / self.data_rate)
        print "usrp interp = ", self.interp
        self.fs = 128e6 / self.interp

        self.u.set_interp_rate(self.interp)

        # determine the daughterboard subdevice we're using
        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)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.u.tune(self.subdev._which, self.subdev, options.cordic_freq)
        self.u.set_pga(0, options.gain)
        self.u.set_pga(1, options.gain)

        # transmitter
        self.packet_transmitter = cc1k_sos_pkt.cc1k_mod_pkts(self, spb=self.samples_per_symbol, msgq_limit=2)
        self.amp = gr.multiply_const_cc (self.normal_gain)
        self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'tx_test.dat')
        
        self.connect(self.amp, self.filesink)
        self.connect(self.packet_transmitter, self.amp, self.u)

        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching
Ejemplo n.º 33
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-d","--debug", action="store_true", default=False)
        parser.add_option("-e","--enable-fft", action="store_true", default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-n", "--nchannels", type="int", default=2,
                           help="number of Tx channels [1,4]")
        parser.add_option("-p", "--udp-port", type="int", default=32001,
                           help="initial UDP port number")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("op25_tx: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c ()       # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.subdev.set_gain(self.subdev.gain_range()[0])    # set min Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(options.freq),
                eng_notation.num_to_str(freq_range[0]),
                eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)                         # enable transmitter

        self.sum = gr.add_cc()

        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step, -3 * step)

        # Instantiate N TX channels
	for i in range(options.nchannels):
            t = tx_channel_usrp(options.udp_port + i, MAX_GAIN / options.nchannels, self.usrp_rate, offset[i])
            self.connect (t, (self.sum, i))
        self.connect (self.sum, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (self.sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
            

        if options.debug:
        #    self.debugger = tx_debug_gui.tx_debug_gui(self.subdev)
        #    self.debugger.Show(True)
          print "attach pid %d" % os.getpid()
          raw_input("press enter")
Ejemplo n.º 34
0
    def __init__(self):

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B (default=first one with a daughterboard)")
        parser.add_option ("-c", "--cordic-freq1", type="eng_float", default=434845200,
                           help="set Tx cordic frequency to FREQ", metavar="FREQ")
        parser.add_option ("-d", "--cordic-freq2", type="eng_float", default=434318512,
                           help="set rx cordic frequency for channel 2 to FREQ", metavar="FREQ")
        parser.add_option ("-g", "--gain", type="eng_float", default=0,
                           help="set Rx PGA gain in dB [0,20]")

        (options, args) = parser.parse_args ()
        print "cordic_freq1 = %s" % (eng_notation.num_to_str (options.cordic_freq1))
        print "cordic_freq2 = %s" % (eng_notation.num_to_str (options.cordic_freq2))

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

        self.data_rate = 38400
        self.samples_per_symbol = 8
        self.channel_fs = self.data_rate * self.samples_per_symbol
        self.fs = 4e6
        payload_size = 128             # bytes

        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "fs = ", eng_notation.num_to_str(self.fs)
        
        gr.flow_graph.__init__(self)
        self.normal_gain = 8000

        self.u = usrp.sink_c()
        dac_rate = self.u.dac_rate();

        self.interp = int(dac_rate / self.fs )
        print "usrp interp = ", self.interp

        self.u.set_interp_rate(self.interp)

        # determine the daughterboard subdevice we're using
        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)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        if options.cordic_freq1 < options.cordic_freq2:
            self.usrp_freq = options.cordic_freq1
            self.freq_diff = options.cordic_freq2 - options.cordic_freq1
        else:
            self.usrp_freq = options.cordic_freq2
            self.freq_diff = options.cordic_freq1 - options.cordic_freq2
        print "freq_diff = ", eng_notation.num_to_str(self.freq_diff)

        self.u.tune(self.subdev._which, self.subdev, self.usrp_freq)
        print "tune USRP to = ", eng_notation.num_to_str(self.usrp_freq)
        self.u.set_pga(0, options.gain)
        self.u.set_pga(1, options.gain)

        interp_factor = int(self.fs / self.channel_fs)
        quad_rate = self.fs
        print "interp_factor = ", interp_factor
        
        # Create filter for the interpolation
        interp_taps = gr.firdes.low_pass (interp_factor,   # gain
                                          self.channel_fs*interp_factor,       # Fs
                                          self.channel_fs/2, # low pass cutoff freq
                                          self.channel_fs*0.1,# width of trans. band
                                          gr.firdes.WIN_HANN) #filter type

        print "len(interp_taps) =", len(interp_taps)

        self.interpolator1 = gr.interp_fir_filter_ccc(interp_factor, interp_taps)
        self.interpolator2 = gr.interp_fir_filter_ccc(interp_factor, interp_taps)

        self.multiplicator = gr.multiply_cc()

        self.adder = gr.add_cc()
        
        self.sin = gr.sig_source_c(self.channel_fs * interp_factor, gr.GR_SIN_WAVE, self.freq_diff, 1, complex(0, 0))

        # transmitter
        self.packet_transmitter1 = cc1k_sos_pkt.cc1k_mod_pkts(self, spb=self.samples_per_symbol, msgq_limit=2)
        #self.packet_transmitter2 = cc1k_sos_pkt.cc1k_mod_pkts(self, spb=self.samples_per_symbol, msgq_limit=2)

        self.amp = gr.multiply_const_cc (self.normal_gain)
        self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'tx_test.dat')
        self.filesink2 = gr.file_sink(gr.sizeof_gr_complex, 'tx_test2.dat')
        self.filesink3 = gr.file_sink(gr.sizeof_gr_complex, 'tx_test3.dat')

        # interpolate the two transmitters
        self.connect(self.packet_transmitter1, self.interpolator1)
        #self.connect(self.packet_transmitter2, self.interpolator2)
        # upconvert the first transmitter)
        self.connect(self.interpolator1, (self.multiplicator, 1))
        self.connect(self.sin, (self.multiplicator, 0))
        # add the two signals
        #self.connect(self.multiplicator, (self.adder, 0))
        #self.connect(self.interpolator2, (self.adder, 1))
        # send the signal to the USRP
        self.connect(self.interpolator1, self.amp, self.filesink)
        self.connect(self.multiplicator, self.filesink2)
        self.connect(self.sin, self.filesink3)
        
        self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
        self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching
Ejemplo n.º 35
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None, help="select USRP Tx side A or B")
        parser.add_option(
            "-f",
            "--freq",
            type="eng_float",
            default=107.2e6,
            help="set Tx frequency to FREQ [required]",
            metavar="FREQ",
        )
        parser.add_option("--wavfile", type="string", default=None, help="open .wav audio file FILE")
        parser.add_option("--xml", type="string", default="rds_data.xml", help="open .xml RDS data FILE")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        usrp_interp = 500
        self.u = usrp.sink_c(0, usrp_interp)
        print "USRP Serial: ", self.u.serial_number()
        usrp_rate = self.u.dac_rate() / usrp_interp  # 256 kS/s

        # determine the daughterboard subdevice we're using
        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)
        print "Using d'board", self.subdev.side_and_name()

        # set max Tx gain, tune frequency and enable transmitter
        gain = self.subdev.gain_range()[1]
        self.subdev.set_gain(gain)
        print "Gain set to", gain
        if self.u.tune(self.subdev.which(), self.subdev, options.freq):
            print "Tuned to", options.freq / 1e6, "MHz"
        else:
            sys.exit(1)
        self.subdev.set_enable(True)

        # open wav file containing floats in the [-1, 1] range, repeat
        if options.wavfile is None:
            print "Please provide a wavfile to transmit! Exiting\n"
            sys.exit(1)
        self.src = gr.wavfile_source(options.wavfile, True)
        nchans = self.src.channels()
        sample_rate = self.src.sample_rate()
        bits_per_sample = self.src.bits_per_sample()
        print nchans, "channels,", sample_rate, "samples/sec,", bits_per_sample, "bits/sample"

        # resample to usrp rate
        self.resample_left = blks2.rational_resampler_fff(usrp_rate, sample_rate)
        self.resample_right = blks2.rational_resampler_fff(usrp_rate, sample_rate)
        self.connect((self.src, 0), self.resample_left)
        self.connect((self.src, 1), self.resample_right)

        # create L+R (mono) and L-R (stereo)
        self.audio_lpr = gr.add_ff()
        self.audio_lmr = gr.sub_ff()
        self.connect(self.resample_left, (self.audio_lpr, 0))
        self.connect(self.resample_left, (self.audio_lmr, 0))
        self.connect(self.resample_right, (self.audio_lpr, 1))
        self.connect(self.resample_right, (self.audio_lmr, 1))

        # low-pass filter for L+R
        audio_lpr_taps = gr.firdes.low_pass(
            0.5,  # gain
            usrp_rate,  # sampling rate
            15e3,  # passband cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING,
        )
        self.audio_lpr_filter = gr.fir_filter_fff(1, audio_lpr_taps)
        self.connect(self.audio_lpr, self.audio_lpr_filter)

        # create pilot tone at 19 kHz
        self.pilot = gr.sig_source_f(
            usrp_rate, gr.GR_SIN_WAVE, 19e3, 5e-2  # sampling rate  # waveform  # frequency
        )  # amplitude

        # upconvert L-R to 38 kHz and band-pass
        self.mix_stereo = gr.multiply_ff()
        audio_lmr_taps = gr.firdes.band_pass(
            80,  # gain
            usrp_rate,  # sampling rate
            38e3 - 15e3,  # low cutoff
            38e3 + 15e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING,
        )
        self.audio_lmr_filter = gr.fir_filter_fff(1, audio_lmr_taps)
        self.connect(self.audio_lmr, (self.mix_stereo, 0))
        self.connect(self.pilot, (self.mix_stereo, 1))
        self.connect(self.pilot, (self.mix_stereo, 2))
        self.connect(self.mix_stereo, self.audio_lmr_filter)

        # create RDS bitstream
        # diff-encode, manchester-emcode, NRZ
        # enforce the 1187.5bps rate
        # pulse shaping filter (matched with receiver)
        # mix with 57kHz carrier (equivalent to BPSK)
        self.rds_enc = rds.data_encoder("rds_data.xml")
        self.diff_enc = gr.diff_encoder_bb(2)
        self.manchester1 = gr.map_bb([1, 2])
        self.manchester2 = gr.unpack_k_bits_bb(2)
        self.nrz = gr.map_bb([-1, 1])
        self.c2f = gr.char_to_float()
        self.rate_enforcer = rds.rate_enforcer(usrp_rate)
        pulse_shaping_taps = gr.firdes.low_pass(
            1,  # gain
            usrp_rate,  # sampling rate
            1.5e3,  # passband cutoff
            2e3,  # transition width
            gr.firdes.WIN_HAMMING,
        )
        self.pulse_shaping = gr.fir_filter_fff(1, pulse_shaping_taps)
        self.bpsk_mod = gr.multiply_ff()
        self.connect(self.rds_enc, self.diff_enc, self.manchester1, self.manchester2, self.nrz, self.c2f)
        self.connect(self.c2f, (self.rate_enforcer, 0))
        self.connect(self.pilot, (self.rate_enforcer, 1))
        self.connect(self.rate_enforcer, (self.bpsk_mod, 0))
        self.connect(self.pilot, (self.bpsk_mod, 1))
        self.connect(self.pilot, (self.bpsk_mod, 2))
        self.connect(self.pilot, (self.bpsk_mod, 3))

        # RDS band-pass filter
        rds_filter_taps = gr.firdes.band_pass(
            50,  # gain
            usrp_rate,  # sampling rate
            57e3 - 3e3,  # low cutoff
            57e3 + 3e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING,
        )
        self.rds_filter = gr.fir_filter_fff(1, rds_filter_taps)
        self.connect(self.bpsk_mod, self.rds_filter)

        # mix L+R, pilot, L-R and RDS
        self.mixer = gr.add_ff()
        self.connect(self.audio_lpr_filter, (self.mixer, 0))
        self.connect(self.pilot, (self.mixer, 1))
        self.connect(self.audio_lmr_filter, (self.mixer, 2))
        self.connect(self.rds_filter, (self.mixer, 3))

        # fm modulation, gain & TX
        max_dev = 75e3
        k = 2 * math.pi * max_dev / usrp_rate  # modulator sensitivity
        self.modulator = gr.frequency_modulator_fc(k)
        self.gain = gr.multiply_const_cc(5e3)
        self.connect(self.mixer, self.modulator, self.gain, self.u)

        # plot an FFT to verify we are sending what we want
        if 1:
            self.fft = fftsink2.fft_sink_f(
                panel, title="Pre FM modulation", fft_size=512 * 4, sample_rate=usrp_rate, y_per_div=20, ref_level=-20
            )
            self.connect(self.mixer, self.fft)
            vbox.Add(self.fft.win, 1, wx.EXPAND)
        if 0:
            self.scope = scopesink2.scope_sink_f(panel, title="RDS encoder output", sample_rate=usrp_rate)
            self.connect(self.rds_enc, self.scope)
            vbox.Add(self.scope.win, 1, wx.EXPAND)
Ejemplo n.º 36
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-T",
                          "--tx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=107.2e6,
                          help="set Tx frequency to FREQ [required]",
                          metavar="FREQ")
        parser.add_option("--wavfile",
                          type="string",
                          default="",
                          help="read input from FILE")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.usrp_interp = 200
        self.u = usrp.sink_c(0, self.usrp_interp)
        print "USRP Serial: ", self.u.serial_number()
        self.dac_rate = self.u.dac_rate()  # 128 MS/s
        self.usrp_rate = self.dac_rate / self.usrp_interp  # 640 kS/s
        self.sw_interp = 5
        self.audio_rate = self.usrp_rate / self.sw_interp  # 128 kS/s

        # determine the daughterboard subdevice we're using
        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)
        print "Using d'board: ", self.subdev.side_and_name()

        # set max Tx gain, tune frequency and enable transmitter
        self.subdev.set_gain(self.subdev.gain_range()[1])
        if self.u.tune(self.subdev.which(), self.subdev, options.freq):
            print "Tuned to", options.freq / 1e6, "MHz"
        else:
            sys.exit(1)
        self.subdev.set_enable(True)

        # open wav file containing floats in the [-1, 1] range, repeat
        if options.wavfile is None:
            print "Please provide a wavfile to transmit! Exiting\n"
            sys.exit(1)
        self.src = gr.wavfile_source(options.wavfile, True)
        nchans = self.src.channels()
        sample_rate = self.src.sample_rate()
        bits_per_sample = self.src.bits_per_sample()
        print nchans, "channels,", sample_rate, "kS/s,", bits_per_sample, "bits/sample"

        # resample to 128kS/s
        if sample_rate == 44100:
            self.resample_left = blks2.rational_resampler_fff(32, 11)
            self.resample_right = blks2.rational_resampler_fff(32, 11)
        elif sample_rate == 48000:
            self.resample_left == blks2.rational_resampler_fff(8, 3)
            self.resample_right == blks2.rational_resampler_fff(8, 3)
        elif sample_rate == 8000:
            self.resample_left == blks2.rational_resampler_fff(16, 1)
            self.resample_right == blks2.rational_resampler_fff(16, 1)
        else:
            print sample_rate, "is an unsupported sample rate"
            sys.exit(1)
        self.connect((self.src, 0), self.resample_left)
        self.connect((self.src, 1), self.resample_right)

        # create L+R (mono) and L-R (stereo)
        self.audio_lpr = gr.add_ff()
        self.audio_lmr = gr.sub_ff()
        self.connect(self.resample_left, (self.audio_lpr, 0))
        self.connect(self.resample_left, (self.audio_lmr, 0))
        self.connect(self.resample_right, (self.audio_lpr, 1))
        self.connect(self.resample_right, (self.audio_lmr, 1))

        # low-pass filter for L+R
        audio_lpr_taps = gr.firdes.low_pass(
            0.3,  # gain
            self.audio_rate,  # sampling rate
            15e3,  # passband cutoff
            2e3,  # transition width
            gr.firdes.WIN_HANN)
        self.audio_lpr_filter = gr.fir_filter_fff(1, audio_lpr_taps)
        self.connect(self.audio_lpr, self.audio_lpr_filter)

        # create pilot tone at 19 kHz
        self.pilot = gr.sig_source_f(
            self.audio_rate,  # sampling freq
            gr.GR_SIN_WAVE,  # waveform
            19e3,  # frequency
            3e-2)  # amplitude

        # create the L-R signal carrier at 38 kHz, high-pass to remove 0Hz tone
        self.stereo_carrier = gr.multiply_ff()
        self.connect(self.pilot, (self.stereo_carrier, 0))
        self.connect(self.pilot, (self.stereo_carrier, 1))
        stereo_carrier_taps = gr.firdes.high_pass(
            1,  # gain
            self.audio_rate,  # sampling rate
            1e4,  # cutoff freq
            2e3,  # transition width
            gr.firdes.WIN_HANN)
        self.stereo_carrier_filter = gr.fir_filter_fff(1, stereo_carrier_taps)
        self.connect(self.stereo_carrier, self.stereo_carrier_filter)

        # upconvert L-R to 23-53 kHz and band-pass
        self.mix_stereo = gr.multiply_ff()
        audio_lmr_taps = gr.firdes.band_pass(
            3e3,  # gain
            self.audio_rate,  # sampling rate
            23e3,  # low cutoff
            53e3,  # high cuttof
            2e3,  # transition width
            gr.firdes.WIN_HANN)
        self.audio_lmr_filter = gr.fir_filter_fff(1, audio_lmr_taps)
        self.connect(self.audio_lmr, (self.mix_stereo, 0))
        self.connect(self.stereo_carrier_filter, (self.mix_stereo, 1))
        self.connect(self.mix_stereo, self.audio_lmr_filter)

        # mix L+R, pilot and L-R
        self.mixer = gr.add_ff()
        self.connect(self.audio_lpr_filter, (self.mixer, 0))
        self.connect(self.pilot, (self.mixer, 1))
        self.connect(self.audio_lmr_filter, (self.mixer, 2))

        # interpolation & pre-emphasis
        interp_taps = gr.firdes.low_pass(
            self.sw_interp,  # gain
            self.audio_rate,  # Fs
            60e3,  # cutoff freq
            5e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.interpolator = gr.interp_fir_filter_fff(self.sw_interp,
                                                     interp_taps)
        self.pre_emph = blks2.fm_preemph(self.usrp_rate, tau=50e-6)
        self.connect(self.mixer, self.interpolator, self.pre_emph)

        # fm modulation, gain & TX
        max_dev = 100e3
        k = 2 * math.pi * max_dev / self.usrp_rate  # modulator sensitivity
        self.modulator = gr.frequency_modulator_fc(k)
        self.gain = gr.multiply_const_cc(1e3)
        self.connect(self.pre_emph, self.modulator, self.gain, self.u)

        # plot an FFT to verify we are sending what we want
        pre_mod = fftsink2.fft_sink_f(panel,
                                      title="Before Interpolation",
                                      fft_size=512,
                                      sample_rate=self.audio_rate,
                                      y_per_div=20,
                                      ref_level=20)
        self.connect(self.mixer, pre_mod)
        vbox.Add(pre_mod.win, 1, wx.EXPAND)
Ejemplo n.º 37
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-e","--enable-fft", action="store_true", default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-i","--file-input", action="store_true", default=False,
                          help="input from baseband-0.dat, baseband-1.dat ...")
        parser.add_option("-g", "--audio-gain", type="eng_float", default=1.0,
                           help="input audio gain multiplier")
        parser.add_option("-n", "--nchannels", type="int", default=2,
                           help="number of Tx channels [1,4]")
        parser.add_option("-a", "--udp-addr", type="string", default="127.0.0.1",
                           help="UDP host IP address")
        parser.add_option("-p", "--udp-port", type="int", default=0,
                           help="UDP port number")
        parser.add_option("-r","--repeat", action="store_true", default=False,
                          help="continuously replay input file")
        parser.add_option("-S", "--stretch", type="int", default=0,
                           help="elastic buffer trigger value")
        parser.add_option("-v","--verbose", action="store_true", default=False,
                          help="print out stats")
        parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("op25_tx: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c ()       # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.subdev.set_gain(self.subdev.gain_range()[0])    # set min Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(options.freq),
                eng_notation.num_to_str(freq_range[0]),
                eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)                         # enable transmitter

        # instantiate vocoders
        self.vocoders   = []
        if options.file_input:
          for i in range (options.nchannels):
            t = gr.file_source(gr.sizeof_char, "baseband-%d.dat" % i, options.repeat)
            self.vocoders.append(t)

        elif options.udp_port > 0:
          self.udp_sources   = []
          for i in range (options.nchannels):
            t = gr.udp_source(1, options.udp_addr, options.udp_port + i, 216)
            self.udp_sources.append(t)
            arity = 2
            t = gr.packed_to_unpacked_bb(arity, gr.GR_MSB_FIRST)
            self.vocoders.append(t)
            self.connect(self.udp_sources[i], self.vocoders[i])

        else:
          self.audio_amps = []
          self.converters = []
          input_audio_rate = 8000
          self.audio_input = audio.source(input_audio_rate, options.audio_input)
          for i in range (options.nchannels):
            t = gr.multiply_const_ff(32767 * options.audio_gain)
            self.audio_amps.append(t)
            t = gr.float_to_short()
            self.converters.append(t)
            t = repeater.vocoder(True,			# 0=Decode,True=Encode
                                  options.verbose,	# Verbose flag
                                  options.stretch,	# flex amount
                                  "",			# udp ip address
                                  0,			# udp port
                                  False) 		# dump raw u vectors
            self.vocoders.append(t)
            self.connect((self.audio_input, i), self.audio_amps[i], self.converters[i], self.vocoders[i])

        sum = gr.add_cc ()

        # Instantiate N NBFM channels
        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step, -3 * step)
        for i in range (options.nchannels):
            t = pipeline(self.vocoders[i], offset[i],
                         self.audio_rate, self.usrp_rate)
            self.connect(t, (sum, i))

        gain = gr.multiply_const_cc (4000.0 / options.nchannels)

        # connect it all
        self.connect (sum, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
Ejemplo n.º 38
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("-n", "--nchannels", type="int", default=4,
                           help="number of Tx channels [1,4]")
        #parser.add_option("","--debug", action="store_true", default=False,
        #                  help="Launch Tx debugger")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write ("fm_tx4: nchannels out of range.  Must be in [1,%d]\n" % MAX_CHANNELS)
            sys.exit(1)
        
        if options.freq is None:
            sys.stderr.write("fm_tx4: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c ()       # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)

        self.subdev.set_gain(self.subdev.gain_range()[1])    # set max Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(options.freq),
                eng_notation.num_to_str(freq_range[0]),
                eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)                         # enable transmitter

        sum = gr.add_cc ()

        # Instantiate N NBFM channels
        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step, -3 * step)
        for i in range (options.nchannels):
            t = pipeline("audio-%d.dat" % (i % 4), offset[i],
                         self.audio_rate, self.usrp_rate)
            self.connect(t, (sum, i))

        gain = gr.multiply_const_cc (4000.0 / options.nchannels)

        # connect it all
        self.connect (sum, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if 1:
            post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation",
                                           fft_size=512, sample_rate=self.usrp_rate,
                                           y_per_div=20, ref_level=40)
            self.connect (sum, post_mod)
            vbox.Add (post_mod.win, 1, wx.EXPAND)
Ejemplo n.º 39
0
	def __init__(self, frame, panel, vbox, argv):
		stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

		parser = OptionParser (option_class=eng_option)
		parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
						help="select USRP Tx side A or B")
		parser.add_option("-f", "--freq", type="eng_float", default=107.2e6,
						help="set Tx frequency to FREQ [required]", metavar="FREQ")
		parser.add_option("-i", "--filename", type="string", default="",
						help="read input from FILE")
		(options, args) = parser.parse_args()
		if len(args) != 0:
			parser.print_help()
			sys.exit(1)

		self.u = usrp.sink_c ()

		self.dac_rate = self.u.dac_rate()					# 128 MS/s
		self.usrp_interp = 400
		self.u.set_interp_rate(self.usrp_interp)
		self.usrp_rate = self.dac_rate / self.usrp_interp	# 320 kS/s
		self.sw_interp = 10
		self.audio_rate = self.usrp_rate / self.sw_interp	# 32 kS/s

		# determine the daughterboard subdevice we're using
		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)
		print "Using TX d'board %s" % (self.subdev.side_and_name(),)

		# set max Tx gain, tune frequency and enable transmitter
		self.subdev.set_gain(self.subdev.gain_range()[1])
		self.u.tune(self.subdev._which, self.subdev, options.freq)
		self.subdev.set_enable(True)

		# open file containing floats in the [-1, 1] range, repeat
		self.src = gr.wavfile_source (options.filename, True)
		nchans = self.src.channels()
		sample_rate = self.src.sample_rate()
		bits_per_sample = self.src.bits_per_sample()
		print nchans, "channels,", sample_rate, "kS/s,", bits_per_sample, "bits/sample"

		# resample to 32kS/s
		if sample_rate == 44100:
			self.resample = blks2.rational_resampler_fff(8,11)
		elif sample_rate == 48000:
			self.resample == blks2.rational_resampler_fff(2,3)
		else:
			print sample_rate, "is an unsupported sample rate"
			exit()

		# interpolation, preemphasis, fm modulation & gain
		self.fmtx = blks2.wfm_tx (self.audio_rate, self.usrp_rate, tau=75e-6, max_dev=15e3)
		self.gain = gr.multiply_const_cc (4e3)

		# connect it all
		self.connect (self.src, self.resample, self.fmtx, self.gain, self.u)

		# plot an FFT to verify we are sending what we want
		pre_mod = fftsink2.fft_sink_f(panel, title="Pre-Modulation",
			fft_size=512, sample_rate=self.usrp_rate, y_per_div=10, ref_level=0)
		self.connect (self.emph, pre_mod)
		vbox.Add (pre_mod.win, 1, wx.EXPAND)
Ejemplo n.º 40
0
def main():
    parser = OptionParser(option_class=eng_option)
    parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Tx side A or B")
    parser.add_option("-f", "--rf-freq", type="eng_float", default=None, help="set RF center frequency to FREQ")
    parser.add_option(
        "-i", "--interp", type="int", default=64, help="set fgpa interpolation rate to INTERP [default=%default]"
    )

    parser.add_option(
        "--sine",
        dest="type",
        action="store_const",
        const=gr.GR_SIN_WAVE,
        help="generate a complex sinusoid [default]",
        default=gr.GR_SIN_WAVE,
    )
    parser.add_option(
        "--const", dest="type", action="store_const", const=gr.GR_CONST_WAVE, help="generate a constant output"
    )
    parser.add_option(
        "--gaussian", dest="type", action="store_const", const=gr.GR_GAUSSIAN, help="generate Gaussian random output"
    )
    parser.add_option(
        "--uniform", dest="type", action="store_const", const=gr.GR_UNIFORM, help="generate Uniform random output"
    )

    parser.add_option(
        "-w", "--waveform-freq", type="eng_float", default=0, help="set waveform frequency to FREQ [default=%default]"
    )
    parser.add_option(
        "-a",
        "--amplitude",
        type="eng_float",
        default=16e3,
        help="set waveform amplitude to AMPLITUDE [default=%default]",
        metavar="AMPL",
    )
    parser.add_option("-g", "--gain", type="eng_float", default=None, help="set output gain to GAIN [default=%default]")
    parser.add_option(
        "-o", "--offset", type="eng_float", default=0, help="set waveform offset to OFFSET [default=%default]"
    )
    parser.add_option(
        "-N", "--nsamples", type="eng_float", default=0, help="set number of samples to transmit [default=+inf]"
    )
    (options, args) = parser.parse_args()

    if len(args) != 0:
        parser.print_help()
        raise SystemExit

    if options.rf_freq is None:
        sys.stderr.write("usrp_siggen: must specify RF center frequency with -f RF_FREQ\n")
        parser.print_help()
        raise SystemExit

    tb = my_top_block(options.nsamples)
    tb.set_interpolator(options.interp)
    tb.set_waveform_type(options.type)
    tb.set_waveform_freq(options.waveform_freq)
    tb.set_waveform_ampl(options.amplitude)
    tb.set_waveform_offset(options.offset)

    # determine the daughterboard subdevice we're using
    if options.tx_subdev_spec is None:
        options.tx_subdev_spec = usrp.pick_tx_subdevice(tb.u)

    m = usrp.determine_tx_mux_value(tb.u, options.tx_subdev_spec)
    # print "mux = %#04x" % (m,)
    tb.u.set_mux(m)
    tb.subdev = usrp.selected_subdev(tb.u, options.tx_subdev_spec)
    print "Using TX d'board %s" % (tb.subdev.side_and_name(),)

    if options.gain is None:
        tb.subdev.set_gain(tb.subdev.gain_range()[1])  # set max Tx gain
    else:
        tb.subdev.set_gain(options.gain)  # set max Tx gain

    if not tb.set_freq(options.rf_freq):
        sys.stderr.write("Failed to set RF frequency\n")
        raise SystemExit

    tb.subdev.set_enable(True)  # enable transmitter

    try:
        tb.run()
    except KeyboardInterrupt:
        pass
Ejemplo n.º 41
0
    def __init__(self, frame, panel, vbox, argv):
        MAX_CHANNELS = 7
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-T",
                          "--tx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-d", "--debug", action="store_true", default=False)
        parser.add_option("-e",
                          "--enable-fft",
                          action="store_true",
                          default=False,
                          help="enable spectrum plot (and use more CPU)")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set Tx frequency to FREQ [required]",
                          metavar="FREQ")
        parser.add_option("-n",
                          "--nchannels",
                          type="int",
                          default=2,
                          help="number of Tx channels [1,4]")
        parser.add_option("-p",
                          "--udp-port",
                          type="int",
                          default=32001,
                          help="initial UDP port number")
        (options, args) = parser.parse_args()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.nchannels < 1 or options.nchannels > MAX_CHANNELS:
            sys.stderr.write(
                "op25_tx: nchannels out of range.  Must be in [1,%d]\n" %
                MAX_CHANNELS)
            sys.exit(1)

        if options.freq is None:
            sys.stderr.write("op25_tx: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

        # ----------------------------------------------------------------
        # Set up constants and parameters

        self.u = usrp.sink_c()  # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()  # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp  # 320 kS/s

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        #print "mux = %#04x" % (m,)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(), )

        self.subdev.set_gain(self.subdev.gain_range()[0])  # set min Tx gain
        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s.  Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(
                    options.freq), eng_notation.num_to_str(
                        freq_range[0]), eng_notation.num_to_str(freq_range[1]))
            raise SystemExit
        self.subdev.set_enable(True)  # enable transmitter

        self.sum = gr.add_cc()

        step = 25e3
        offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step,
                  -3 * step)

        # Instantiate N TX channels
        for i in range(options.nchannels):
            t = tx_channel_usrp(options.udp_port + i,
                                MAX_GAIN / options.nchannels, self.usrp_rate,
                                offset[i])
            self.connect(t, (self.sum, i))
        self.connect(self.sum, self.u)

        # plot an FFT to verify we are sending what we want
        if options.enable_fft:
            post_mod = fftsink2.fft_sink_c(panel,
                                           title="Post Modulation",
                                           fft_size=512,
                                           sample_rate=self.usrp_rate,
                                           y_per_div=20,
                                           ref_level=40)
            self.connect(self.sum, post_mod)
            vbox.Add(post_mod.win, 1, wx.EXPAND)

        if options.debug:
            #    self.debugger = tx_debug_gui.tx_debug_gui(self.subdev)
            #    self.debugger.Show(True)
            print "attach pid %d" % os.getpid()
            raw_input("press enter")
Ejemplo n.º 42
0
def main():
    parser = OptionParser(option_class=eng_option)
    parser.add_option("-f",
                      "--freq",
                      type="eng_float",
                      default=144.800e6,
                      help="set frequency to FREQ",
                      metavar="FREQ")
    parser.add_option("-m",
                      "--message",
                      type="string",
                      default=":ALL      :this is a test",
                      help="message to send",
                      metavar="MESSAGE")
    parser.add_option("-c",
                      "--mycall",
                      type="string",
                      default="MYCALL",
                      help="source callsign",
                      metavar="CALL")
    parser.add_option("-t",
                      "--tocall",
                      type="string",
                      default="CQ",
                      help="recipient callsign",
                      metavar="CALL")
    parser.add_option("-v",
                      "--via",
                      type="string",
                      default="RELAY",
                      help="digipeater callsign",
                      metavar="CALL")
    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 output")
    (options, args) = parser.parse_args()
    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    bitrate = 9600
    dac_rate = 128e6
    usrp_interp = 500
    cordic_freq = options.freq - dac_rate
    sf = 153600
    syminterp = sf / bitrate  #16
    nbfmdev = 3e3
    fmsens = 2 * pi * nbfmdev / (sf * 5 / 3)
    bit_oversampling = 8
    sw_interp = int(sf / bitrate / bit_oversampling)  #2

    fg = gr.flow_graph()

    p = buildpacket(options.mycall, 0, options.tocall, 0, options.via, 0, 0x03,
                    0xf0, options.message)
    if options.do_logging:
        dumppackettofile(p, "packet.dat")
    v = bits2syms(nrziencode(scrambler(hdlcpacket(p, 100, 1000))))
    src = gr.vector_source_f(v)
    gaussian_taps = gr.firdes.gaussian(
        1,  # gain
        bit_oversampling,  # symbol_rate
        0.3,  # bandwidth * symbol time
        4 * bit_oversampling  # number of taps
    )
    sqwave = (1, ) * syminterp  #rectangular window
    taps = Numeric.convolve(Numeric.array(gaussian_taps),
                            Numeric.array(sqwave))
    gaussian = gr.interp_fir_filter_fff(syminterp, taps)  #9600*16=153600

    res_taps = blks.design_filter(5, 3, 0.4)
    res = blks.rational_resampler_fff(fg, 5, 3, res_taps)  #153600*5/3=256000
    fmmod = gr.frequency_modulator_fc(fmsens)
    amp = gr.multiply_const_cc(32000)

    if options.use_datafile:
        dst = gr.file_sink(gr.sizeof_gr_complex, "usrp.dat")
    else:
        u = usrp.sink_c(0, usrp_interp)  #256000*500=128000000
        tx_subdev_spec = usrp.pick_tx_subdevice(u)
        m = usrp.determine_tx_mux_value(u, tx_subdev_spec)
        print "mux = %#04x" % (m, )
        u.set_mux(m)
        subdev = usrp.selected_subdev(u, tx_subdev_spec)
        print "Using TX d'board %s" % (subdev.side_and_name(), )
        u.set_tx_freq(0, cordic_freq)
        u.set_pga(0, 0)
        print "Actual frequency: ", u.tx_freq(0)
        dst = u

    fg.connect(src, gaussian, res, fmmod, amp, dst)

    fg.start()
    fg.wait()
Ejemplo n.º 43
0
    def __init__(self, frame, panel, vbox, argv):

        stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None,
                          help="select USRP Tx side A or B")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set Tx frequency to FREQ [required]", metavar="FREQ")
        parser.add_option("","--debug", action="store_true", default=False,
                          help="Launch Tx debugger")
        (options, args) = parser.parse_args ()

        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        if options.freq is None:
            sys.stderr.write("usrp_tx_video.py: must specify frequency with -f FREQ\n")
            parser.print_help()
            sys.exit(1)

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

        self.u = usrp.sink_c ()       # the USRP sink (consumes samples)

        self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        self.usrp_interp = 128
        self.usrp_rate = self.dac_rate / self.usrp_interp


        self.u.set_interp_rate(self.usrp_interp)

        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)
        print "Using TX d'board %s with rate %ld" % (self.subdev.side_and_name(), self.usrp_rate)

        self.subdev.set_gain(self.subdev.gain_range()[1])    # set max Tx gain
	self.u.tune(self.subdev._which, self.subdev, options.freq)
        self.subdev.set_enable(True)                         # enable transmitter

        t = pipeline(self, options.freq, self.usrp_rate)

        gain = gr.multiply_const_cc (32000.0)

        # connect it all
        self.connect (t, gain)
        self.connect (gain, self.u)

        # plot an FFT to verify we are sending what we want
        if 1:
            post_mod_fft = fftsink.fft_sink_c(self, panel, title="Signal in frequency domain",
                                              fft_size=64, sample_rate=self.usrp_rate,
                                              y_per_div=20, ref_level=40)

            #post_mod_oscope = scopesink.scope_sink_c(self, panel, sample_rate=self.usrp_rate,
            #                                         title="Signal in time domain", v_scale = 1,
            #                                         t_scale=0.0001)

            self.connect (t, post_mod_fft)
            #self.connect (t, post_mod_oscope)
            vbox.Add (post_mod_fft.win, 1, wx.EXPAND)
            #vbox.Add (post_mod_oscope.win, 1, wx.EXPAND)
            

        if options.debug:
            self.debugger = tx_debug_gui.tx_debug_gui(self.subdev)
            self.debugger.Show(True)