示例#1
0
文件: ofdm_tx.py 项目: ljxangus/ofdm
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.tx_freq is not None:
            u = uhd_transmitter(options.args, options.bandwidth,
                                options.tx_freq, options.tx_gain, options.spec,
                                options.antenna, options.external,
                                options.verbose)
        elif options.outfile is not None:
            u = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
        else:
            raise SystemExit("--freq or --outfile must be specified\n")

        if options.infile is not None:
            tx = gr.file_source(gr.sizeof_gr_complex,
                                options.infile,
                                repeat=options.repeat)
        else:
            tx = ofdm_rxtx.TX(options)
            data_tones = tx.params.data_tones
            if options.char > 0:
                # read char from file
                data = gr.stream_to_vector(gr.sizeof_float, data_tones * 2)
                # NOTE: we use repeat, assuming the file is long enough or properly aligned
                self.connect(
                    gr.file_source(gr.sizeof_char, options.txdata,
                                   repeat=True), gr.char_to_float(),
                    gr.multiply_const_ff(options.char * (2**-0.5) / 128.0),
                    data)
            else:
                data = ofdm_rxtx.make_data(data_tones, options.size,
                                           options.txdata)
                if options.log:
                    self.connect(
                        data,
                        gr.file_sink(data_tones * gr.sizeof_gr_complex,
                                     'tx-data.dat'))

            self.connect(data, tx)
            self.sender = ofdm_rxtx.sender_thread(tx, options)

        if options.amp != 1:
            amp = gr.multiply_const_cc(options.amp)
            self.connect(tx, amp, u)
        else:
            self.connect(tx, u)
示例#2
0
文件: ofdm_tx.py 项目: UpYou/ofdm
  def __init__(self, options):
    gr.top_block.__init__(self)

    if options.tx_freq is not None:
      u = uhd_transmitter(options.args,
                          options.bandwidth,
                          options.tx_freq, options.tx_gain,
                          options.spec, options.antenna,
                          options.external, options.verbose)
    elif options.outfile is not None:
      u = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
    else:
      raise SystemExit("--freq or --outfile must be specified\n")

    if options.infile is not None:
      tx = gr.file_source(gr.sizeof_gr_complex, options.infile, repeat = options.repeat)
    else:
      tx = ofdm_rxtx.TX(options)
      data_tones = tx.params.data_tones
      if options.char > 0:
        # read char from file
        data = gr.stream_to_vector(gr.sizeof_float, data_tones * 2)
        # NOTE: we use repeat, assuming the file is long enough or properly aligned
        self.connect(gr.file_source(gr.sizeof_char, options.txdata, repeat=True),
                     gr.char_to_float(),
                     gr.multiply_const_ff(options.char * (2**-0.5) / 128.0),
                     data)
      else:
        data = ofdm_rxtx.make_data(data_tones, options.size, options.txdata)
        if options.log:
          self.connect(data, gr.file_sink(data_tones * gr.sizeof_gr_complex, 'tx-data.dat'))

      self.connect(data, tx)
      self.sender = ofdm_rxtx.sender_thread(tx, options)

    if options.amp != 1:
      amp = gr.multiply_const_cc(options.amp)
      self.connect(tx, amp, u)
    else:
      self.connect(tx, u)
示例#3
0
文件: ofdm_rx.py 项目: ljxangus/ofdm
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.rx_freq is not None:
            u = uhd_receiver(options.args, options.bandwidth, options.rx_freq,
                             options.rx_gain, options.spec, options.antenna,
                             options.verbose)
        elif options.infile is not None:
            u = gr.file_source(gr.sizeof_gr_complex, options.infile)
        else:
            import sys
            sys.stderr.write("--freq or --infile must be specified\n")
            raise SystemExit

        self.scope = None

        if options.outfile is not None:
            rx = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
        else:
            rx = ofdm_rxtx.RX(options)
            data_tones = rx.params.data_tones
            if options.rxdata is not None:
                if options.rxdata == '.':
                    import scope
                    # scope it out
                    rxs = gr.vector_to_stream(gr.sizeof_gr_complex, data_tones)
                    self.connect(rx, rxs)
                    self.scope = scope.scope(self,
                                             rxs,
                                             'Frame SNR',
                                             isComplex=True)
                else:
                    if options.char > 0:
                        # rail and scale
                        self.connect(
                            rx,
                            gr.vector_to_stream(gr.sizeof_float,
                                                data_tones * 2),
                            gr.multiply_const_ff(128.0 * (2**0.5) /
                                                 options.char),
                            gr.rail_ff(-128.0, 127.0), gr.float_to_char(),
                            gr.file_sink(gr.sizeof_char, options.rxdata))
                    else:
                        self.connect(
                            rx,
                            gr.file_sink(data_tones * gr.sizeof_gr_complex,
                                         options.rxdata))

            if options.snrdata is not None:
                # select one of the snr modes
                snr = ofdm_rxtx.SNR(rx.params.data_tones,
                                    options.size,
                                    mode=options.snrmode)
                if options.char > 0:
                    # NOTE: we use repeat, assuming the file is long enough or properly aligned
                    data = gr.stream_to_vector(gr.sizeof_float, data_tones * 2)
                    self.connect(
                        gr.file_source(gr.sizeof_char,
                                       options.txdata,
                                       repeat=True), gr.char_to_float(),
                        gr.multiply_const_ff(options.char * (2**-0.5) / 128.0),
                        data)
                else:
                    data = ofdm_rxtx.make_data(rx.params.data_tones,
                                               options.size, options.txdata)
                self.connect(rx, (snr, 0))
                self.connect(data, (snr, 1))
                if options.snrdata == '-':
                    # print it out
                    msgq = gr.msg_queue(16)
                    self.connect(snr,
                                 gr.message_sink(gr.sizeof_float, msgq, True))
                    self.watcher = ofdm_rxtx.queue_watcher(msgq)
                elif options.snrdata == '.':
                    import scope
                    # scope it out
                    self.scope = scope.scope(self, snr, 'Frame SNR')
                else:
                    self.connect(
                        snr, gr.file_sink(gr.sizeof_float, options.snrdata))
            else:
                pass
                #self.connect(rx, gr.null_sink(symbol_size)) # XXX do we still need this?

        self.connect(u, rx)
示例#4
0
文件: ofdm_rx.py 项目: UpYou/ofdm
  def __init__(self, options):
    gr.top_block.__init__(self)

    if options.rx_freq is not None:
      u = uhd_receiver(options.args,
                       options.bandwidth,
                       options.rx_freq, options.rx_gain,
                       options.spec, options.antenna,
                       options.verbose)
    elif options.infile is not None:
      u = gr.file_source(gr.sizeof_gr_complex, options.infile)
    else:
      import sys
      sys.stderr.write("--freq or --infile must be specified\n")
      raise SystemExit

    self.scope = None

    if options.outfile is not None:
      rx = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
    else:
      rx = ofdm_rxtx.RX(options)
      data_tones = rx.params.data_tones
      if options.rxdata is not None:
        if options.rxdata == '.':
          import scope
          # scope it out
          rxs = gr.vector_to_stream(gr.sizeof_gr_complex, data_tones)
          self.connect(rx, rxs)
          self.scope = scope.scope(self, rxs, 'Frame SNR', isComplex=True)
        else:
          if options.char > 0:
            # rail and scale
            self.connect(rx,
                         gr.vector_to_stream(gr.sizeof_float, data_tones * 2),
                         gr.multiply_const_ff(128.0 * (2**0.5)/ options.char),
                         gr.rail_ff(-128.0, 127.0),
                         gr.float_to_char(),
                         gr.file_sink(gr.sizeof_char, options.rxdata))
          else:
            self.connect(rx, gr.file_sink(data_tones * gr.sizeof_gr_complex, options.rxdata))

      if options.snrdata is not None:
        # select one of the snr modes
        snr = ofdm_rxtx.SNR(rx.params.data_tones, options.size, mode=options.snrmode)
        if options.char > 0:
          # NOTE: we use repeat, assuming the file is long enough or properly aligned
          data = gr.stream_to_vector(gr.sizeof_float, data_tones * 2)
          self.connect(gr.file_source(gr.sizeof_char, options.txdata, repeat=True),
                      gr.char_to_float(),
                      gr.multiply_const_ff(options.char * (2**-0.5) / 128.0),
                      data)
        else:
          data = ofdm_rxtx.make_data(rx.params.data_tones, options.size, options.txdata)
        self.connect(rx, (snr,0))
        self.connect(data, (snr,1))
        if options.snrdata == '-':
          # print it out
          msgq = gr.msg_queue(16)
          self.connect(snr, gr.message_sink(gr.sizeof_float, msgq, True))
          self.watcher = ofdm_rxtx.queue_watcher(msgq)
        elif options.snrdata == '.':
          import scope
          # scope it out
          self.scope = scope.scope(self, snr, 'Frame SNR')
        else:
          self.connect(snr, gr.file_sink(gr.sizeof_float, options.snrdata))
      else:
        pass
        #self.connect(rx, gr.null_sink(symbol_size)) # XXX do we still need this?

    self.connect(u, rx)