Esempio n. 1
0
 def test_001_(self):
     src_data = numpy.array([-1.0, 1.0, -1.0, 1.0])
     trg_data = src_data * 0.5
     src = gr.vector_source_f(src_data)
     dst = gr.vector_sink_f()
     rail = gr.rail_ff(-0.5, 0.5)
     self.tb.connect(src, rail)
     self.tb.connect(rail, dst)
     self.tb.run()
     rsl_data = dst.data()
     sum = 0
     for (u, v) in zip(trg_data, rsl_data):
         w = u - v
         sum += w * w
     sum /= float(len(trg_data))
     assert sum < 1e-6
 def test_001_(self):
     src_data = numpy.array([-1.0, 1.0, -1.0, 1.0])
     trg_data = src_data * 0.5
     src = gr.vector_source_f(src_data)
     dst = gr.vector_sink_f()
     rail = gr.rail_ff(-0.5, 0.5)
     self.tb.connect(src, rail)
     self.tb.connect(rail, dst)
     self.tb.run()
     rsl_data = dst.data()
     sum = 0
     for (u, v) in zip(trg_data, rsl_data):
         w = u - v
         sum += w * w
     sum /= float(len(trg_data))
     assert sum < 1e-6
Esempio n. 3
0
    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)
Esempio n. 4
0
  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)