コード例 #1
0
ファイル: tx.py プロジェクト: luwangg/gr-ofdm-1
    def __init__(self, options):
        gr.top_block.__init__(self)

        if (options.to_file is not None):
            self.file = blocks.file_sink(gr.sizeof_gr_complex, options.to_file)
            self.sink = blocks.throttle(gr.sizeof_gr_complex, 1e6)
            self.connect(self.sink, self.file)
        elif (options.tx_freq is not None):
            self.sink = uhd_transmitter(options.args, options.bandwidth,
                                        options.tx_freq, options.lo_offset,
                                        options.tx_gain, options.spec,
                                        options.antenna, options.clock_source,
                                        options.verbose)
        else:
            self.sink = blocks.null_sink(gr.sizeof_gr_complex)

        self._setup_tx_path(options)
        self._setup_rpc_manager()

        if options.freqoff is not None:
            freq_off = self.freq_off = channel.freq_offset(options.freqoff)
            self.connect(self.txpath, freq_off)
            self.txpath = freq_off
            self.rpc_mgr_tx.add_interface("set_freq_offset",
                                          self.freq_off.set_freqoff)

        if options.multipath:
            if options.itu_channel:
                self.fad_chan = channel.itpp_channel(options.bandwidth)
                self.rpc_mgr_tx.add_interface(
                    "set_channel_profile", self.fad_chan.set_channel_profile)
            else:
                self.fad_chan = filter.fir_filter_ccc(
                    1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j])

            self.connect(self.txpath, self.fad_chan)
            self.txpath = self.fad_chan

        self.connect(self.txpath, self.sink)
コード例 #2
0
ファイル: tx.py プロジェクト: WindyCitySDR/gr-ofdm
    def __init__(self, options):
        gr.top_block.__init__(self)

        if(options.to_file is not None):
            self.file = blocks.file_sink(gr.sizeof_gr_complex, options.to_file)
            self.sink = blocks.throttle(gr.sizeof_gr_complex,1e6)
            self.connect( self.sink, self.file )
        elif(options.tx_freq is not None):
            self.sink = uhd_transmitter(options.args,
                                        options.bandwidth, options.tx_freq, 
                                        options.lo_offset, options.tx_gain,
                                        options.spec, options.antenna,
                                        options.clock_source, options.verbose)
        else:
            self.sink = blocks.null_sink(gr.sizeof_gr_complex)



        self._setup_tx_path(options)
        self._setup_rpc_manager()

        if options.freqoff is not None:
            freq_off = self.freq_off = channel.freq_offset(options.freqoff )
            self.connect(self.txpath, freq_off)
            self.txpath = freq_off
            self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff)

        if options.multipath:
          if options.itu_channel:
            self.fad_chan = channel.itpp_channel(options.bandwidth)
            self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile)
          else:
            self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])

          self.connect(self.txpath, self.fad_chan)
          self.txpath = self.fad_chan


        self.connect(self.txpath, self.sink)
コード例 #3
0
    def __init__(self, options):
        gr.top_block.__init__(self, "ofdm_benchmark")

        self._bandwidth = options.bandwidth
        self.servants = []
        self._verbose = options.verbose

        self._options = copy.copy(options)

        self.ideal = options.ideal
        self.ideal2 = options.ideal2

        rms_amp = options.rms_amplitude

        self._interpolation = 1

        f1 = numpy.array([
            -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0,
            82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959,
            0, -1271, 0, 445, 0, -107
        ], numpy.float64) / 262144.

        print "Software interpolation: %d" % (self._interpolation)

        bw = 1.0 / self._interpolation
        tb = bw / 5
        if self._interpolation > 1:
            self.tx_filter = gr.hier_block2(
                "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex),
                gr.io_signature(1, 1, gr.sizeof_gr_complex))
            self.tx_filter.connect(self.tx_filter,
                                   gr.interp_fir_filter_ccf(2, f1),
                                   gr.interp_fir_filter_ccf(2, f1),
                                   self.tx_filter)

            print "New"

        else:
            self.tx_filter = None

        self.decimation = 1

        if self.decimation > 1:
            bw = 0.5 / self.decimation * 1
            tb = bw / 5
            # gain, sampling rate, passband cutoff, stopband cutoff
            # passband ripple in dB, stopband attenuation in dB
            # extra taps
            filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw + tb, 0.1, 60.0, 1)
            print "Software decimation filter length: %d" % (len(filt_coeff))
            self.rx_filter = gr.fir_filter_ccf(self.decimation, filt_coeff)
        else:
            self.rx_filter = None

        self._setup_tx_path(options)
        self._setup_rx_path(options)
        self._setup_rpc_manager()

        config = self.config = station_configuration()

        if options.imgxfer:
            self.rxpath.setup_imgtransfer_sink()

        if not options.no_decoding:
            self.rxpath.publish_rx_performance_measure()

            # capture transmitter's stream to disk
        #self.dst  = gr.file_sink(gr.sizeof_gr_complex,options.to_file)
        self.dst = self.rxpath
        if options.force_rx_filter:
            print "Forcing rx filter usage"
            self.connect(self.rx_filter, self.dst)
            self.dst = self.rx_filter

        if options.ideal or self.ideal2:
            self._amplifier = ofdm.multiply_const_ccf(1.0)
            self.connect(self._amplifier, self.dst)
            self.dst = self._amplifier
            self.set_rms_amplitude(rms_amp)

        if options.measure:
            self.m = throughput_measure(gr.sizeof_gr_complex)
            self.connect(self.m, self.dst)
            self.dst = self.m

        if options.snr is not None:
            if options.berm is not None:
                noise_sigma = 380 / 32767.0  #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py
                #check for fading channel
            else:
                snr_db = options.snr
                snr = 10.0**(snr_db / 10.0)
                noise_sigma = sqrt(config.rms_amplitude**2 / snr)

            print " Noise St. Dev. %f" % (noise_sigma)

            awgn_chan = blocks.add_cc()
            #awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma )
            awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN,
                                                       noise_sigma, 0, 8192)
            self.connect(awgn_noise_src, (awgn_chan, 1))
            self.connect(awgn_chan, self.dst)
            self.dst = awgn_chan

        if options.freqoff is not None:
            freq_off = self.freq_off = channel.freq_offset(options.freqoff)
            dst = self.dst
            self.connect(freq_off, dst)
            self.dst = freq_off
            self.rpc_mgr_tx.add_interface("set_freq_offset",
                                          self.freq_off.set_freqoff)

        if options.multipath:
            if options.itu_channel:
                self.fad_chan = channel.itpp_channel(options.bandwidth)
                self.rpc_mgr_tx.add_interface(
                    "set_channel_profile", self.fad_chan.set_channel_profile)
                self.rpc_mgr_tx.add_interface("set_norm_doppler",
                                              self.fad_chan.set_norm_doppler)
            else:
                #self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
                # filter coefficients for the lab exercise
                self.fad_chan = filter.fir_filter_ccc(1,
                                                      [0.3267, 0.8868, 0.3267])
                #self.fad_chan = filter.fir_filter_ccc(1,[0,0,0.1,0.2,0.01,0.3])#0.3267,0.8868,0.3267])
                #self.fad_chan = channels.selective_fading_model(5, 0.1, False, 1, -1, [0, 0, 0], [0.3267,0.8868,0.3267], 10 )
                #self.fad_chan = channels.fading_model(6, 0.05, False);
                #self.fad_chan = channels.dynamic_channel_model(1000000, 0, 0, 0, 0, 3, 0.01, False, 0, [2e-6,4e-6,8e-6],[0.3267,0.8868,0.3267], 20, 0, 0)

            self.connect(self.fad_chan, self.dst)
            self.dst = self.fad_chan

        if options.samplingoffset is not None:
            soff = options.samplingoffset
            interp = moms(1000000 * (1.0 + soff), 1000000)
            #interp = filter.fractional_resampler_cc(0,1000000*(1.0+soff)/1000000.0)
            self.connect(interp, self.dst)
            self.dst = interp

            if options.record:
                log_to_file(self, interp, "data/interp_out.compl")

        tmm = blocks.throttle(gr.sizeof_gr_complex, options.bandwidth)
        self.connect(tmm, self.dst)
        self.dst = tmm
        if options.force_tx_filter:
            print "Forcing tx filter usage"
            self.connect(self.tx_filter, self.dst)
            self.dst = self.tx_filter
        if options.record:
            log_to_file(self, self.txpath, "data/txpath_out.compl")

        if options.scatterplot:
            print "Scatterplot enabled"

        self.connect(self.txpath, self.dst)

        print "Hit Strg^C to terminate"

        print "Hit Strg^C to terminate"

        # Display some information about the setup
        if self._verbose:
            self._print_verbage()
コード例 #4
0
  def __init__ (self, options):
    gr.top_block.__init__(self, "ofdm_mrrc_benchmark")

    ##self._tx_freq            = options.tx_freq         # tranmitter's center frequency
    ##self._tx_subdev_spec     = options.tx_subdev_spec  # daughterboard to use
    ##self._fusb_block_size    = options.fusb_block_size # usb info for USRP
    ##self._fusb_nblocks       = options.fusb_nblocks    # usb info for USRP
    ##self._which              = options.which_usrp
    self._bandwidth          = options.bandwidth
    self.servants = []
    self._verbose            = options.verbose
    
    ##self._interface          = options.interface
    ##self._mac_addr           = options.mac_addr

    self._options = copy.copy( options )


    self._interpolation = 1
    
    f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953,
                      0,-24706,0,82359,262144/2,82359,0,-24706,0,
                      11953,0,-6107,0,2959,0,-1271,0,445,0,-107],
                      numpy.float64)/262144.
    
    print "Software interpolation: %d" % (self._interpolation)

    bw = 1.0/self._interpolation
    tb = bw/5
    if self._interpolation > 1:
      self.tx_filter = gr.hier_block2("filter",
                                   gr.io_signature(1,1,gr.sizeof_gr_complex),
                                   gr.io_signature(1,1,gr.sizeof_gr_complex))
      self.tx_filter2 = gr.hier_block2("filter",
                                   gr.io_signature(1,1,gr.sizeof_gr_complex),
                                   gr.io_signature(1,1,gr.sizeof_gr_complex))
      self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1),
                           gr.interp_fir_filter_ccf(2,f1), self.tx_filter )
      self.tx_filter2.connect( self.tx_filter2, gr.interp_fir_filter_ccf(2,f1),
                           gr.interp_fir_filter_ccf(2,f1), self.tx_filter2 )
      print "New"

    else:
      self.tx_filter = None
      self.tx_filter2 = None
      
    self.decimation = 1
    
    if self.decimation > 1:
      bw = 0.5/self.decimation * 1
      tb = bw/5
      # gain, sampling rate, passband cutoff, stopband cutoff
      # passband ripple in dB, stopband attenuation in dB
      # extra taps
      filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1)
      print "Software decimation filter length: %d" % (len(filt_coeff))
      self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff)
      self.rx_filter2 = gr.fir_filter_ccf(self.decimation,filt_coeff)
    else:
      self.rx_filter = None
      self.rx_filter2 = None
      
      
##    if not options.from_file is None:
##      # sent captured file to usrp
##      self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file)
##      self._setup_usrp_sink()
##      if hasattr(self, "filter"):
##        self.connect(self.src,self.filter,self.u) #,self.filter
##      else:
##        self.connect(self.src,self.u)
##      
##      return 
    
    
    
    self._setup_tx_path(options)
    self._setup_rx_path(options)
    self._setup_rpc_manager()
    
    config = self.config = station_configuration()
    
    #self.enable_txfreq_adjust("txfreq")
    
    

    if options.imgxfer:
      self.rxpath.setup_imgtransfer_sink()
    
    if not options.no_decoding:
      self.rxpath.publish_rx_performance_measure()
      
    


    self.dst	= (self.rxpath,0)
    self.dst2 	= (self.rxpath,1)
    
    if options.force_rx_filter:
      print "Forcing rx filter usage"
      self.connect( self.rx_filter, self.dst )
      self.connect( self.rx_filter2, self.dst2 )
      self.dst = self.rx_filter
      self.dst2 = self.rx_filter2
    
    
    if options.measure:
      self.m = throughput_measure(gr.sizeof_gr_complex)
      self.m2 = throughput_measure(gr.sizeof_gr_complex)
      self.connect( self.m, self.dst )
      self.connect( self.m2, self.dst2 )
      self.dst = self.m
      self.dst2 = self.m2


    if options.snr is not None:
      if options.berm is not None:
          noise_sigma = 380/32767.0 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py
          print " Noise St. Dev. %f" % (noise_sigma)#check for fading channel 
      else:
          snr_db = options.snr
          snr = 10.0**(snr_db/10.0)
          noise_sigma = sqrt( config.rms_amplitude**2 / snr )
          
      print " Noise St. Dev. %f" % (noise_sigma)
      awgn_chan = blocks.add_cc()
      awgn_chan2 = blocks.add_cc()
      awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192)
      awgn_noise_src2 = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma*2, 0, 2192)
      self.connect( awgn_chan, self.dst )
      self.connect( awgn_chan2, self.dst2 )
      self.connect( awgn_noise_src, (awgn_chan,1) )
      self.connect( awgn_noise_src2, (awgn_chan2,1) )  
      self.dst = awgn_chan
      self.dst2 = awgn_chan2



    if options.freqoff is not None:
      freq_off = self.freq_off = channel.freq_offset(options.freqoff )
      freq_off2 = self.freq_off2  = channel.freq_offset(options.freqoff )
      dst = self.dst
      dst2 = self.dst2
      self.connect( freq_off, dst )
      self.connect( freq_off2, dst2 )
      self.dst = freq_off
      self.dst2 = freq_off2
      self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff)
      self.rpc_mgr_tx.add_interface("set_freq_offset2",self.freq_off2.set_freqoff)


    if options.multipath:
      if options.itu_channel:
        self.fad_chan = channel.itpp_channel(options.bandwidth)
          #fad_chan.set_norm_doppler( 1e-9 )
          #fad_chan.set_LOS( [500.,0,0] )
        self.fad_chan2 = channel.itpp_channel(options.bandwidth)
        self.fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 )
        self.fad_chan.set_norm_doppler( 1e-8 )
        self.fad_chan2.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 )
        self.fad_chan2.set_norm_doppler( 1e-8 )
        self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile)
        self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan2.set_channel_profile)
      else:
        fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
        fad_chan2 = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
        
      self.connect( self.fad_chan, self.dst )
      self.connect( self.fad_chan2, self.dst2 )
      self.dst = self.fad_chan
      self.dst2 = self.fad_chan2

    if options.samplingoffset is not None:
      soff = options.samplingoffset
      interp = moms(1000000*(1.0+soff),1000000)
      interp2 = moms(1000000*(1.0+soff),1000000)
      self.connect( interp, self.dst )
      self.connect( interp2, self.dst2 )
      self.dst = interp
      self.dst2 = interp2
      
      if options.record:
       log_to_file( self, interp, "data/interp_out.compl" )
       log_to_file( self, interp2, "data/interp2_out.compl" )
    
    tmm =blocks.throttle(gr.sizeof_gr_complex, 1e6)
    #tmm2 =blocks.throttle(gr.sizeof_gr_complex, 1e6)
    
    #self.connect( tmm, self.dst )
    #self.connect( tmm2, self.dst2 )
    #self.dst = tmm
    #self.dst2 = tmm2
    
    #inter = blocks.interleave(gr.sizeof_gr_complex)
    #deinter = blocks.deinterleave(gr.sizeof_gr_complex)
    
    # Interleaving input/output streams
    ##self.connect(inter, deinter)
    #self.connect((deinter,0),self.dst)
    #self.connect((deinter,1),self.dst2)
    #self.dst = inter
    #self.dst2 = (inter,1)
    
    
    if options.force_tx_filter:
      print "Forcing tx filter usage"
      self.connect( self.tx_filter, self.dst )
      self.connect( self.tx_filter2, self.dst2 )
      self.dst = self.tx_filter
      self.dst2 = self.tx_filter2
    if options.record:
      log_to_file( self, self.txpath, "data/txpath_out.compl" )
      log_to_file( self, self.txpath2, "data/txpath2_out.compl" )
      
    if options.nullsink:
        self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst)
        self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2)
        self.dst = gr.null_sink(gr.sizeof_gr_complex)
        self.dst2 = gr.null_sink(gr.sizeof_gr_complex)
        
    
    self.connect( self.txpath,tmm,self.dst )
    self.connect( tmm,self.dst2 )
    #self.connect( self.txpath,self.dst2 )
    
    print "Hit Strg^C to terminate"

    if self._verbose:
        self._print_verbage()
コード例 #5
0
  def __init__ (self, options):
    gr.top_block.__init__(self, "fbmc_benchmark")

    self._bandwidth          = options.bandwidth
    self.servants = []
    self._verbose            = options.verbose

    self._options = copy.copy( options )
    
    self.ideal = options.ideal
    self.ideal2 = options.ideal2
    rms_amp                    = options.rms_amplitude
    
    #Disable OFDM channel estimation preamble -> Still experimental
    options.est_preamble = 0

    self._interpolation = 1

    f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953,
                      0,-24706,0,82359,262144/2,82359,0,-24706,0,
                      11953,0,-6107,0,2959,0,-1271,0,445,0,-107],
                      numpy.float64)/262144.

    print "Software interpolation: %d" % (self._interpolation)

    bw = 1.0/self._interpolation
    tb = bw/5
    if self._interpolation > 1:
      self.tx_filter = gr.hier_block2("filter",
                                   gr.io_signature(1,1,gr.sizeof_gr_complex),
                                   gr.io_signature(1,1,gr.sizeof_gr_complex))
      self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1),
                           gr.interp_fir_filter_ccf(2,f1), self.tx_filter )

      print "New"

    else:
      self.tx_filter = None

    self.decimation = 1

    if self.decimation > 1:
      bw = 0.5/self.decimation * 1
      tb = bw/5
      # gain, sampling rate, passband cutoff, stopband cutoff
      # passband ripple in dB, stopband attenuation in dB
      # extra taps
      filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1)
      print "Software decimation filter length: %d" % (len(filt_coeff))
      self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff)
    else:
      self.rx_filter = None

    self._setup_tx_path(options)
    self._setup_rx_path(options)
    self._setup_rpc_manager()

    config = self.config = station_configuration()


    if options.imgxfer:
      self.rxpath.setup_imgtransfer_sink()

    if not options.no_decoding:
      self.rxpath.publish_rx_performance_measure()

      # capture transmitter's stream to disk
    #self.dst  = gr.file_sink(gr.sizeof_gr_complex,options.to_file)
    self.dst= self.rxpath
    if options.force_rx_filter:
      print "Forcing rx filter usage"
      self.connect( self.rx_filter, self.dst )
      self.dst = self.rx_filter

    if options.ideal or self.ideal2:
       self._amplifier = ofdm.multiply_const_ccf( 1.0 )
       self.connect( self._amplifier, self.dst  )
       self.dst = self._amplifier
       self.set_rms_amplitude(rms_amp)
       
    if options.measure:
      self.m = throughput_measure(gr.sizeof_gr_complex)
      self.connect( self.m, self.dst )
      self.dst = self.m

    
    if options.snr is not None:
      if options.berm is not None:
          #noise_sigma = 0.0001/32767.0
          noise_sigma = 380/32767.0#250/32767.0 #380/32767.0 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py
          #check for fading channel
      else:
          snr_db = options.snr
          snr = 10.0**(snr_db/10.0)
          noise_sigma = sqrt( config.rms_amplitude**2 / snr )

      print " Noise St. Dev. %d" % (noise_sigma)
      awgn_chan = blocks.add_cc()
      #awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma )
      #noise_sigma = 0.000000000001
      awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192)
      self.connect( awgn_noise_src, (awgn_chan,1) )
      self.connect( awgn_chan,self.dst )
      #self.connect( awgn_chan, blocks.skiphead( gr.sizeof_gr_complex, 3* config.fft_length ),self.dst )
      self.dst = awgn_chan
      


    if options.freqoff is not None:
      freq_off = self.freq_off = channel.freq_offset(options.freqoff )
      dst = self.dst
      self.connect(freq_off, dst) 
      self.dst = freq_off
      self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff)
      #log_to_file( self, self.freq_off, "data/TRANSMITTER_OUT.compl" )



    if options.multipath:
      if options.itu_channel:
        self.fad_chan = channel.itpp_channel(options.bandwidth)
        self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile)
      else:
        #self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
        # filter coefficients for the lab exercise
        self.fad_chan = filter.fir_filter_ccc(1,[0,0,0.3267,0.8868,0.3267])

      self.connect(self.fad_chan, self.dst)
      self.dst = self.fad_chan

    if options.samplingoffset is not None:
      soff = options.samplingoffset
      interp = moms(1000000*(1.0+soff),1000000)
      self.connect( interp, self.dst )
      self.dst = interp

      if options.record:
       log_to_file( self, interp, "data/interp_out.compl" )

    tmm =blocks.throttle(gr.sizeof_gr_complex,1e6)
    self.connect( tmm, self.dst )
    self.dst = tmm
    if options.force_tx_filter:
      print "Forcing tx filter usage"
      self.connect( self.tx_filter, self.dst )
      self.dst = self.tx_filter
    if options.record:
      log_to_file( self, self.txpath, "data/txpath_out.compl" )

    if options.scatterplot:
      print "Scatterplot enabled"

    self.connect( self.txpath,self.dst )
    #log_to_file( self, self.txpath, "data/fbmc_rx_input.compl" )



    print "Hit Strg^C to terminate"

    print "Hit Strg^C to terminate"


    # Display some information about the setup
    if self._verbose:
        self._print_verbage()
コード例 #6
0
ファイル: benchmark_ofdm.py プロジェクト: luwangg/gr-ofdm-1
  def __init__ (self, options):
    gr.top_block.__init__(self, "ofdm_benchmark")

    self._bandwidth          = options.bandwidth
    self.servants = []
    self._verbose            = options.verbose

    self._options = copy.copy( options )
    
    self.ideal = options.ideal
    self.ideal2 = options.ideal2
    
    rms_amp                    = options.rms_amplitude

    self._interpolation = 1

    f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953,
                      0,-24706,0,82359,262144/2,82359,0,-24706,0,
                      11953,0,-6107,0,2959,0,-1271,0,445,0,-107],
                      numpy.float64)/262144.

    print "Software interpolation: %d" % (self._interpolation)

    bw = 1.0/self._interpolation
    tb = bw/5
    if self._interpolation > 1:
      self.tx_filter = gr.hier_block2("filter",
                                   gr.io_signature(1,1,gr.sizeof_gr_complex),
                                   gr.io_signature(1,1,gr.sizeof_gr_complex))
      self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1),
                           gr.interp_fir_filter_ccf(2,f1), self.tx_filter )

      print "New"

    else:
      self.tx_filter = None

    self.decimation = 1

    if self.decimation > 1:
      bw = 0.5/self.decimation * 1
      tb = bw/5
      # gain, sampling rate, passband cutoff, stopband cutoff
      # passband ripple in dB, stopband attenuation in dB
      # extra taps
      filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1)
      print "Software decimation filter length: %d" % (len(filt_coeff))
      self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff)
    else:
      self.rx_filter = None

    self._setup_tx_path(options)
    self._setup_rx_path(options)
    self._setup_rpc_manager()

    config = self.config = station_configuration()


    if options.imgxfer:
      self.rxpath.setup_imgtransfer_sink()

    if not options.no_decoding:
      self.rxpath.publish_rx_performance_measure()

      # capture transmitter's stream to disk
    #self.dst  = gr.file_sink(gr.sizeof_gr_complex,options.to_file)
    self.dst= self.rxpath
    if options.force_rx_filter:
      print "Forcing rx filter usage"
      self.connect( self.rx_filter, self.dst )
      self.dst = self.rx_filter
      
    if options.ideal or self.ideal2:
       self._amplifier = ofdm.multiply_const_ccf( 1.0 )
       self.connect( self._amplifier, self.dst  )
       self.dst = self._amplifier
       self.set_rms_amplitude(rms_amp)
       


    if options.measure:
      self.m = throughput_measure(gr.sizeof_gr_complex)
      self.connect( self.m, self.dst )
      self.dst = self.m


    if options.snr is not None:
      if options.berm is not None:
          # empirically determined to reach 30db SNR max in simulation mode
          noise_sigma = 0.0035
      else:
          snr_db = options.snr
          snr = 10.0**(snr_db/10.0)
          noise_sigma = sqrt( config.rms_amplitude**2 / snr )

      print " Noise St. Dev. %f" % (noise_sigma)

      awgn_chan = blocks.add_cc()
      #awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma )
      awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise_sigma, 0, 8192)
      self.connect( awgn_noise_src, (awgn_chan,1) )
      self.connect( awgn_chan, self.dst  )
      self.dst = awgn_chan


    if options.freqoff is not None:
      freq_off = self.freq_off = channel.freq_offset(options.freqoff )
      dst = self.dst
      self.connect(freq_off, dst) 
      self.dst = freq_off
      self.rpc_mgr_tx.add_interface("set_freq_offset",self.freq_off.set_freqoff)


    if options.multipath:
      if options.itu_channel:
        self.fad_chan = channel.itpp_channel(options.bandwidth)
        self.rpc_mgr_tx.add_interface("set_channel_profile",self.fad_chan.set_channel_profile)
        self.rpc_mgr_tx.add_interface("set_norm_doppler",self.fad_chan.set_norm_doppler)
      else:
        #self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
        # filter coefficients for the lab exercise
        self.fad_chan = filter.fir_filter_ccc(1,[0.3267,0.8868,0.3267])
        #self.fad_chan = filter.fir_filter_ccc(1,[0,0,0.1,0.2,0.01,0.3])#0.3267,0.8868,0.3267])
        #self.fad_chan = channels.selective_fading_model(5, 0.1, False, 1, -1, [0, 0, 0], [0.3267,0.8868,0.3267], 10 )
        #self.fad_chan = channels.fading_model(6, 0.05, False);
        #self.fad_chan = channels.dynamic_channel_model(1000000, 0, 0, 0, 0, 3, 0.01, False, 0, [2e-6,4e-6,8e-6],[0.3267,0.8868,0.3267], 20, 0, 0)


      self.connect(self.fad_chan, self.dst)
      self.dst = self.fad_chan

    if options.samplingoffset is not None:
      soff = options.samplingoffset
      interp = moms(1000000*(1.0+soff),1000000)
      #interp = filter.fractional_resampler_cc(0,1000000*(1.0+soff)/1000000.0)
      self.connect( interp, self.dst )
      self.dst = interp

      if options.record:
       log_to_file( self, interp, "data/interp_out.compl" )

    tmm =blocks.throttle(gr.sizeof_gr_complex,options.bandwidth)
    self.connect( tmm, self.dst )
    self.dst = tmm
    if options.force_tx_filter:
      print "Forcing tx filter usage"
      self.connect( self.tx_filter, self.dst )
      self.dst = self.tx_filter
    if options.record:
      log_to_file( self, self.txpath, "data/txpath_out.compl" )


    if options.scatterplot:
      print "Scatterplot enabled"

    self.connect( self.txpath,self.dst )


    print "Hit Strg^C to terminate"

    print "Hit Strg^C to terminate"


    # Display some information about the setup
    if self._verbose:
        self._print_verbage()
コード例 #7
0
    def __init__(self, options):
        gr.top_block.__init__(self, "ofdm_mrrc_benchmark")

        ##self._tx_freq            = options.tx_freq         # tranmitter's center frequency
        ##self._tx_subdev_spec     = options.tx_subdev_spec  # daughterboard to use
        ##self._fusb_block_size    = options.fusb_block_size # usb info for USRP
        ##self._fusb_nblocks       = options.fusb_nblocks    # usb info for USRP
        ##self._which              = options.which_usrp
        self._bandwidth = options.bandwidth
        self.servants = []
        self._verbose = options.verbose

        ##self._interface          = options.interface
        ##self._mac_addr           = options.mac_addr

        self._options = copy.copy(options)

        self._interpolation = 1

        f1 = numpy.array([
            -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0,
            82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959,
            0, -1271, 0, 445, 0, -107
        ], numpy.float64) / 262144.

        print "Software interpolation: %d" % (self._interpolation)

        bw = 1.0 / self._interpolation
        tb = bw / 5
        if self._interpolation > 1:
            self.tx_filter = gr.hier_block2(
                "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex),
                gr.io_signature(1, 1, gr.sizeof_gr_complex))
            self.tx_filter2 = gr.hier_block2(
                "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex),
                gr.io_signature(1, 1, gr.sizeof_gr_complex))
            self.tx_filter.connect(self.tx_filter,
                                   gr.interp_fir_filter_ccf(2, f1),
                                   gr.interp_fir_filter_ccf(2, f1),
                                   self.tx_filter)
            self.tx_filter2.connect(self.tx_filter2,
                                    gr.interp_fir_filter_ccf(2, f1),
                                    gr.interp_fir_filter_ccf(2, f1),
                                    self.tx_filter2)
            print "New"

        else:
            self.tx_filter = None
            self.tx_filter2 = None

        self.decimation = 1

        if self.decimation > 1:
            bw = 0.5 / self.decimation * 1
            tb = bw / 5
            # gain, sampling rate, passband cutoff, stopband cutoff
            # passband ripple in dB, stopband attenuation in dB
            # extra taps
            filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw + tb, 0.1, 60.0, 1)
            print "Software decimation filter length: %d" % (len(filt_coeff))
            self.rx_filter = gr.fir_filter_ccf(self.decimation, filt_coeff)
            self.rx_filter2 = gr.fir_filter_ccf(self.decimation, filt_coeff)
        else:
            self.rx_filter = None
            self.rx_filter2 = None

##    if not options.from_file is None:
##      # sent captured file to usrp
##      self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file)
##      self._setup_usrp_sink()
##      if hasattr(self, "filter"):
##        self.connect(self.src,self.filter,self.u) #,self.filter
##      else:
##        self.connect(self.src,self.u)
##
##      return

        self._setup_tx_path(options)
        self._setup_rx_path(options)
        self._setup_rpc_manager()

        config = self.config = station_configuration()

        #self.enable_txfreq_adjust("txfreq")

        if options.imgxfer:
            self.rxpath.setup_imgtransfer_sink()

        if not options.no_decoding:
            self.rxpath.publish_rx_performance_measure()

        self.dst = (self.rxpath, 0)
        self.dst2 = (self.rxpath, 1)

        if options.force_rx_filter:
            print "Forcing rx filter usage"
            self.connect(self.rx_filter, self.dst)
            self.connect(self.rx_filter2, self.dst2)
            self.dst = self.rx_filter
            self.dst2 = self.rx_filter2

        if options.measure:
            self.m = throughput_measure(gr.sizeof_gr_complex)
            self.m2 = throughput_measure(gr.sizeof_gr_complex)
            self.connect(self.m, self.dst)
            self.connect(self.m2, self.dst2)
            self.dst = self.m
            self.dst2 = self.m2

        if options.snr is not None:
            if options.berm is not None:
                noise_sigma = 380 / 32767.0  #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py
                print " Noise St. Dev. %f" % (noise_sigma
                                              )  #check for fading channel
            else:
                snr_db = options.snr
                snr = 10.0**(snr_db / 10.0)
                noise_sigma = sqrt(config.rms_amplitude**2 / snr)

            print " Noise St. Dev. %f" % (noise_sigma)
            awgn_chan = blocks.add_cc()
            awgn_chan2 = blocks.add_cc()
            awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN,
                                                       noise_sigma, 0, 8192)
            awgn_noise_src2 = analog.fastnoise_source_c(
                analog.GR_GAUSSIAN, noise_sigma * 2, 0, 2192)
            self.connect(awgn_chan, self.dst)
            self.connect(awgn_chan2, self.dst2)
            self.connect(awgn_noise_src, (awgn_chan, 1))
            self.connect(awgn_noise_src2, (awgn_chan2, 1))
            self.dst = awgn_chan
            self.dst2 = awgn_chan2

        if options.freqoff is not None:
            freq_off = self.freq_off = channel.freq_offset(options.freqoff)
            freq_off2 = self.freq_off2 = channel.freq_offset(options.freqoff)
            dst = self.dst
            dst2 = self.dst2
            self.connect(freq_off, dst)
            self.connect(freq_off2, dst2)
            self.dst = freq_off
            self.dst2 = freq_off2
            self.rpc_mgr_tx.add_interface("set_freq_offset",
                                          self.freq_off.set_freqoff)
            self.rpc_mgr_tx.add_interface("set_freq_offset2",
                                          self.freq_off2.set_freqoff)

        if options.multipath:
            if options.itu_channel:
                self.fad_chan = channel.itpp_channel(options.bandwidth)
                #fad_chan.set_norm_doppler( 1e-9 )
                #fad_chan.set_LOS( [500.,0,0] )
                self.fad_chan2 = channel.itpp_channel(options.bandwidth)
                self.fad_chan.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8)
                self.fad_chan.set_norm_doppler(1e-8)
                self.fad_chan2.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8)
                self.fad_chan2.set_norm_doppler(1e-8)
                self.rpc_mgr_tx.add_interface(
                    "set_channel_profile", self.fad_chan.set_channel_profile)
                self.rpc_mgr_tx.add_interface(
                    "set_channel_profile", self.fad_chan2.set_channel_profile)
            else:
                fad_chan = filter.fir_filter_ccc(
                    1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j])
                fad_chan2 = filter.fir_filter_ccc(
                    1, [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j])

            self.connect(self.fad_chan, self.dst)
            self.connect(self.fad_chan2, self.dst2)
            self.dst = self.fad_chan
            self.dst2 = self.fad_chan2

        if options.samplingoffset is not None:
            soff = options.samplingoffset
            interp = moms(1000000 * (1.0 + soff), 1000000)
            interp2 = moms(1000000 * (1.0 + soff), 1000000)
            self.connect(interp, self.dst)
            self.connect(interp2, self.dst2)
            self.dst = interp
            self.dst2 = interp2

            if options.record:
                log_to_file(self, interp, "data/interp_out.compl")
                log_to_file(self, interp2, "data/interp2_out.compl")

        tmm = blocks.throttle(gr.sizeof_gr_complex, 1e6)
        #tmm2 =blocks.throttle(gr.sizeof_gr_complex, 1e6)

        #self.connect( tmm, self.dst )
        #self.connect( tmm2, self.dst2 )
        #self.dst = tmm
        #self.dst2 = tmm2

        #inter = blocks.interleave(gr.sizeof_gr_complex)
        #deinter = blocks.deinterleave(gr.sizeof_gr_complex)

        # Interleaving input/output streams
        ##self.connect(inter, deinter)
        #self.connect((deinter,0),self.dst)
        #self.connect((deinter,1),self.dst2)
        #self.dst = inter
        #self.dst2 = (inter,1)

        if options.force_tx_filter:
            print "Forcing tx filter usage"
            self.connect(self.tx_filter, self.dst)
            self.connect(self.tx_filter2, self.dst2)
            self.dst = self.tx_filter
            self.dst2 = self.tx_filter2
        if options.record:
            log_to_file(self, self.txpath, "data/txpath_out.compl")
            log_to_file(self, self.txpath2, "data/txpath2_out.compl")

        if options.nullsink:
            self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst)
            self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2)
            self.dst = gr.null_sink(gr.sizeof_gr_complex)
            self.dst2 = gr.null_sink(gr.sizeof_gr_complex)

        self.connect(self.txpath, tmm, self.dst)
        self.connect(tmm, self.dst2)
        #self.connect( self.txpath,self.dst2 )

        print "Hit Strg^C to terminate"

        if self._verbose:
            self._print_verbage()