Exemplo n.º 1
0
def mod_bits_qpsk(strbits, syms=[0, 1, 3, 2], pts=[-1, 1j, 1, -1j]):
    src = gr.vector_source_b(es.string_to_vector(strbits))
    unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
    pack = gr.pack_k_bits_bb(2)
    bts = gr.map_bb((syms))
    mapper = gr.chunks_to_symbols_bc(pts, 1)
    rrc_taps = gr.firdes.root_raised_cosine(1.0, 2.0, 1.0, 0.35, 91)
    interp = gr.interp_fir_filter_ccc(2, (rrc_taps))
    sink = gr.vector_sink_c()
    tb = gr.top_block()
    tb.connect(src, unpack, pack, bts, mapper, interp, sink)
    tb.run()
    return sink.data()
Exemplo n.º 2
0
def mod_bits_qpsk(strbits, syms=[0,1,3,2], pts=[-1,1j,1,-1j]):
    src = gr.vector_source_b(es.string_to_vector(strbits));
    unpack = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST);
    pack = gr.pack_k_bits_bb(2);
    bts = gr.map_bb((syms));
    mapper =  gr.chunks_to_symbols_bc(pts, 1);
    rrc_taps = gr.firdes.root_raised_cosine(1.0, 2.0, 1.0, 0.35, 91);
    interp = gr.interp_fir_filter_ccc(2, (rrc_taps))
    sink = gr.vector_sink_c();
    tb=gr.top_block();
    tb.connect(src,unpack,pack,bts,mapper,interp,sink);
    tb.run();
    return sink.data();
    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
Exemplo n.º 4
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