Example #1
0
  def __init__ ( self, noise_power, coherence_time, taps ):
    gr.hier_block2.__init__(self,
      "fading_channel", 
      gr.io_signature( 1, 1, gr.sizeof_gr_complex ),
      gr.io_signature( 1, 1, gr.sizeof_gr_complex ) )

    inp = gr.kludge_copy( gr.sizeof_gr_complex )
    self.connect( self, inp )
    
    tap1_delay = gr.delay( gr.sizeof_gr_complex, 1 )
    tap2_delay = gr.delay( gr.sizeof_gr_complex, 2 )
    self.connect( inp, tap1_delay )
    self.connect( inp, tap2_delay )
    
    fd = 100
    z = numpy.arange(-fd+0.1,fd,0.1)
    t = numpy.sqrt(1. / ( pi * fd * numpy.sqrt( 1. - (z/fd)**2 ) ) )
    
    tap1_noise = ofdm.complex_white_noise( 0.0, taps[0] )
    tap1_filter = gr.fft_filter_ccc(1, t)
    self.connect( tap1_noise, tap1_filter )
    
    tap1_mult = gr.multiply_cc()
    self.connect( tap1_filter, (tap1_mult,0) )
    self.connect( tap1_delay, (tap1_mult,1) )
    
    tap2_noise = ofdm.complex_white_noise( 0.0, taps[1] )
    tap2_filter = gr.fft_filter_ccc(1, t)
    
    self.connect( tap2_noise, tap2_filter )
    
    tap2_mult = gr.multiply_cc()
    self.connect( tap2_filter, (tap2_mult,0) )
    self.connect( tap2_delay, (tap2_mult,1) )
    
    noise_src = ofdm.complex_white_noise( 0.0, sqrt( noise_power ) )
    chan = gr.add_cc()
    
    self.connect( inp, (chan,0) )
    self.connect( tap1_mult, (chan,1) )
    self.connect( tap2_mult, (chan,2) )
    self.connect( noise_src, (chan,3) )
    
    self.connect( chan, self )
    
    log_to_file( self, tap1_filter, "data/tap1_filter.compl")
    log_to_file( self, tap1_filter, "data/tap1_filter.float", mag=True)
    log_to_file( self, tap2_filter, "data/tap2_filter.compl")
    log_to_file( self, tap2_filter, "data/tap2_filter.float", mag=True)
Example #2
0
    def __init__(self, noise_power, coherence_time, taps):
        gr.hier_block2.__init__(self, "fading_channel",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        inp = gr.kludge_copy(gr.sizeof_gr_complex)
        self.connect(self, inp)

        tap1_delay = gr.delay(gr.sizeof_gr_complex, 1)
        tap2_delay = gr.delay(gr.sizeof_gr_complex, 2)
        self.connect(inp, tap1_delay)
        self.connect(inp, tap2_delay)

        fd = 100
        z = numpy.arange(-fd + 0.1, fd, 0.1)
        t = numpy.sqrt(1. / (pi * fd * numpy.sqrt(1. - (z / fd)**2)))

        tap1_noise = ofdm.complex_white_noise(0.0, taps[0])
        tap1_filter = gr.fft_filter_ccc(1, t)
        self.connect(tap1_noise, tap1_filter)

        tap1_mult = gr.multiply_cc()
        self.connect(tap1_filter, (tap1_mult, 0))
        self.connect(tap1_delay, (tap1_mult, 1))

        tap2_noise = ofdm.complex_white_noise(0.0, taps[1])
        tap2_filter = gr.fft_filter_ccc(1, t)

        self.connect(tap2_noise, tap2_filter)

        tap2_mult = gr.multiply_cc()
        self.connect(tap2_filter, (tap2_mult, 0))
        self.connect(tap2_delay, (tap2_mult, 1))

        noise_src = ofdm.complex_white_noise(0.0, sqrt(noise_power))
        chan = gr.add_cc()

        self.connect(inp, (chan, 0))
        self.connect(tap1_mult, (chan, 1))
        self.connect(tap2_mult, (chan, 2))
        self.connect(noise_src, (chan, 3))

        self.connect(chan, self)

        log_to_file(self, tap1_filter, "data/tap1_filter.compl")
        log_to_file(self, tap1_filter, "data/tap1_filter.float", mag=True)
        log_to_file(self, tap2_filter, "data/tap2_filter.compl")
        log_to_file(self, tap2_filter, "data/tap2_filter.float", mag=True)
Example #3
0
  def test_100(self):
    vlen = 256
    N = int( 5e5 )
    soff=40
    taps = [1.0,0.0,2e-1+0.1j,1e-4-0.04j]
    freqoff = 0.0
    snr_db = 10
    rms_amplitude = 8000
    
    
    data = [1 + 1j] * vlen
    #data2 = [2] * vlen
    
    src = gr.vector_source_c( data, True, vlen )
    v2s = gr.vector_to_stream(gr.sizeof_gr_complex,vlen)
    
    
    #interp = gr.fractional_interpolator_cc(0.0,soff)
    interp = moms(1000000,1000000+soff)
    
    fad_chan = gr.fir_filter_ccc(1,taps)
    
    freq_shift = gr.multiply_cc()
    norm_freq = freqoff / vlen
    freq_off_src = gr.sig_source_c(1.0, gr.GR_SIN_WAVE, norm_freq, 1.0, 0.0 )
    
    snr = 10.0**(snr_db/10.0)
    noise_sigma = sqrt( rms_amplitude**2 / snr)
    awgn_chan = gr.add_cc()
    awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma )
    
    dst = gr.null_sink( gr.sizeof_gr_complex )

    limit = gr.head( gr.sizeof_gr_complex * vlen, N )
    
    
    self.tb.connect( src, limit, v2s, interp, fad_chan,freq_shift, awgn_chan, dst )
    self.tb.connect( freq_off_src,(freq_shift,1))
    self.tb.connect( awgn_noise_src,(awgn_chan,1))
    
    r = time_it( self.tb )
    
    print "Rate: %s Samples/second" \
      % eng_notation.num_to_str( float(N) * vlen / r ) 
Example #4
0
  def sim ( self, arity, snr_db, N ):
    
    vlen = 1
    N = int( N )
    snr = 10.0**(snr_db/10.0)
    
    sigpow = 1.0
    noise_pow = sigpow / snr
    
    demapper = ofdm.generic_demapper_vcb( vlen )
    const = demapper.get_constellation( arity )
    assert( len( const ) == 2**arity )
    
    symsrc = ofdm.symbol_random_src( const, vlen )
    noise_src = ofdm.complex_white_noise( 0.0, sqrt( noise_pow ) )
    channel = blocks.add_cc()
    bitmap_src = blocks.vector_source_b( [arity] * vlen, True, vlen )
    bm_trig_src = blocks.vector_source_b( [1], True )
    ref_bitstream = blocks.unpack_k_bits_bb( arity )
    bitstream_xor = blocks.xor_bb()
    bitstream_c2f = blocks.char_to_float()
    acc_biterr = ofdm.accumulator_ff()
    skiphead = blocks.skiphead( gr.sizeof_float, N-1 )
    limit = blocks.head( gr.sizeof_float, 1 )
    dst = blocks.vector_sink_f()
    
    tb = gr.top_block ( "test_block" )
    
    tb.connect( (symsrc,0), (channel,0) )
    tb.connect( noise_src,  (channel,1) )
    tb.connect( channel,     (demapper,0), (bitstream_xor,0) )
    tb.connect( bitmap_src,  (demapper,1) )
    tb.connect( bm_trig_src, (demapper,2) )
    tb.connect( (symsrc,1), ref_bitstream, (bitstream_xor,1) )
    tb.connect( bitstream_xor, bitstream_c2f, acc_biterr )
    tb.connect( acc_biterr, skiphead, limit, dst )

    tb.run()
    
    bit_errors = numpy.array( dst.data() )
    assert( len( bit_errors ) == 1 )
    bit_errors = bit_errors[0]
    
    return bit_errors / N
Example #5
0
    def test_100(self):
        vlen = 256
        N = int(5e5)
        soff = 40
        taps = [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j]
        freqoff = 0.0
        snr_db = 10
        rms_amplitude = 8000

        data = [1 + 1j] * vlen
        #data2 = [2] * vlen

        src = gr.vector_source_c(data, True, vlen)
        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)

        #interp = gr.fractional_interpolator_cc(0.0,soff)
        interp = moms(1000000, 1000000 + soff)

        fad_chan = gr.fir_filter_ccc(1, taps)

        freq_shift = gr.multiply_cc()
        norm_freq = freqoff / vlen
        freq_off_src = gr.sig_source_c(1.0, gr.GR_SIN_WAVE, norm_freq, 1.0,
                                       0.0)

        snr = 10.0**(snr_db / 10.0)
        noise_sigma = sqrt(rms_amplitude**2 / snr)
        awgn_chan = gr.add_cc()
        awgn_noise_src = ofdm.complex_white_noise(0.0, noise_sigma)

        dst = gr.null_sink(gr.sizeof_gr_complex)

        limit = gr.head(gr.sizeof_gr_complex * vlen, N)

        self.tb.connect(src, limit, v2s, interp, fad_chan, freq_shift,
                        awgn_chan, dst)
        self.tb.connect(freq_off_src, (freq_shift, 1))
        self.tb.connect(awgn_noise_src, (awgn_chan, 1))

        r = time_it(self.tb)

        print "Rate: %s Samples/second" \
          % eng_notation.num_to_str( float(N) * vlen / r )
  def __init__( self, snr_db, sigpow = 1.0, vlen = 1 ):
    gr.hier_block2.__init__( self,
          "awgn_channel",
          gr.io_signature( 1, 1, gr.sizeof_gr_complex * vlen ),
          gr.io_signature( 1, 1, gr.sizeof_gr_complex * vlen ) )

    snr = 10.0**(snr_db/10.0)
    noise_pow = float(sigpow) / snr

    noise_src = ofdm.complex_white_noise( 0.0, sqrt( noise_pow ) )
    if vlen > 1:
      channel = gr.add_vcc( vlen )
    else:
      channel = gr.add_cc()

    self.connect( self, channel, self )

    if vlen > 1:
      self.connect( noise_src, gr.stream_to_vector( gr.sizeof_gr_complex, vlen),
                    ( channel, 1) )
    else:
      self.connect( noise_src, ( channel, 1 ) )
Example #7
0
    def __init__(self, options):
        gr.top_block.__init__(self, "ofdm_tx")

        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._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 = 0.5 / self._interpolation
        tb = bw / 5
        if self._interpolation > 1:
            self.filter = gr.hier_block2(
                "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex),
                gr.io_signature(1, 1, gr.sizeof_gr_complex))
            self.filter.connect(self.filter, gr.interp_fir_filter_ccf(2, f1),
                                gr.interp_fir_filter_ccf(2, f1), self.filter)

            print "New"
#
#
#      self.filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.2, 60.0, 0)
#      self.filter = gr.interp_fir_filter_ccf(self._interpolation,self.filt_coeff)
#      print "Software interpolation filter length: %d" % (len(self.filt_coeff))
        else:
            self.filter = 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)

        config = station_configuration()

        self.enable_info_tx("info_tx", "pa_user")
        #    if not options.no_cheat:
        #      self.txpath.enable_channel_cheating("channelcheat")
        self.txpath.enable_txpower_adjust("txpower")
        self.txpath.publish_txpower("txpower_info")
        #self.enable_txfreq_adjust("txfreq")

        if options.nullsink:
            self.dst = gr.null_sink(gr.sizeof_gr_complex)
            self.dst_2 = gr.null_sink(gr.sizeof_gr_complex)

        else:
            if not options.to_file is None:
                # capture transmitter's stream to disk
                self.dst = gr.file_sink(gr.sizeof_gr_complex, options.to_file)
                self.dst_2 = gr.file_sink(gr.sizeof_gr_complex,
                                          options.to_file)
                tmp = gr.throttle(gr.sizeof_gr_complex, 1e5)
                tmp_2 = gr.throttle(gr.sizeof_gr_complex, 1e5)
                self.connect(tmp, self.dst)
                self.connect(tmp_2, self.dst_2)
                self.dst = tmp
                self.dst_2 = tmp_2

                if options.force_filter:
                    print "Forcing filter usage"
                    self.connect(self.filter, self.dst)
                    self.dst = self.filter

            else:
                # connect transmitter to usrp
                self._setup_usrp_sink()
                if options.dyn_freq:
                    self.enable_txfreq_adjust("txfreq")

                if self.filter is not None:
                    self.connect(self.filter, self.dst)
                    self.dst = self.filter

                if options.record:
                    log_to_file(self, self.txpath, "data/txpath_out.compl")

                #self.publish_spectrum( 256 )

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

        if options.samplingoffset is not None:
            soff = options.samplingoffset
            interp = gr.fractional_interpolator_cc(0.0, soff)
            self.connect(interp, self.dst)
            self.dst = interp

        if options.snr is not None:

            #      if options.berm is not None:
            #          noise_sigma = 380 #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 = gr.add_cc()
            awgn_noise_src = ofdm.complex_white_noise(0.0, noise_sigma)
            self.connect(awgn_noise_src, (awgn_chan, 1))
            self.connect(awgn_chan, self.dst)
            self.dst = awgn_chan

            if options.berm is False:
                fad_chan = itpp.tdl_channel()  #[0, -7, -20], [0, 2, 6]
                #fad_chan.set_norm_doppler( 1e-9 )
                #fad_chan.set_LOS( [500.,0,0] )
                fad_chan.set_channel_profile(itpp.ITU_Pedestrian_A, 5e-8)
                fad_chan.set_norm_doppler(1e-8)
                #        fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
                self.connect(fad_chan, self.dst)
                self.dst = fad_chan

        if options.freqoff is not None:
            freq_shift = gr.multiply_cc()
            norm_freq = options.freqoff / config.fft_length
            freq_off_src = gr.sig_source_c(1.0, gr.GR_SIN_WAVE, norm_freq, 1.0,
                                           0.0)
            self.connect(freq_off_src, (freq_shift, 1))
            dst = self.dst
            self.connect(freq_shift, dst)
            self.dst = freq_shift

        self.connect((self.txpath, 0), self.dst)
        self.connect((self.txpath, 1), self.dst_2)

        if options.cheat:
            self.txpath.enable_channel_cheating("channelcheat")

        print "Hit Strg^C to terminate"
Example #8
0
  def __init__ (self, options):
    gr.top_block.__init__(self, "ofdm_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)
    
    config = station_configuration()
    
    self.enable_info_tx("info_tx", "pa_user")
#    if not options.no_cheat:
#      self.txpath.enable_channel_cheating("channelcheat")
    self.txpath.enable_txpower_adjust("txpower")
    self.txpath.publish_txpower("txpower_info")
    
    if options.disable_equalization or options.ideal:
        #print "CHANGE set_k"
        self.rxpath.enable_estim_power_adjust("estim_power")
        #self.rxpath.publish_estim_power("txpower_info")
         
    #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 False:
          noise_sigma = 380 #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_chan2 = blocks.add_cc()
      awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma )
      awgn_noise_src2 = ofdm.complex_white_noise( 0.0, noise_sigma )
      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_shift = blocks.multiply_cc()
      freq_shift2 = blocks.multiply_cc()
      norm_freq = options.freqoff / config.fft_length
      freq_off_src = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0 )
      freq_off_src2 = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0 )
      self.connect( freq_off_src, ( freq_shift, 1 ) )
      self.connect( freq_off_src2, ( freq_shift2, 1 ) )
      dst = self.dst
      dst2 = self.dst2
      self.connect( freq_shift, dst )
      self.connect( freq_shift2, dst2 )
      self.dst = freq_shift
      self.dst2 = freq_shift2


    if options.multipath:
      if options.itu_channel:
        fad_chan = itpp.tdl_channel(  ) #[0, -7, -20], [0, 2, 6]
          #fad_chan.set_norm_doppler( 1e-9 )
          #fad_chan.set_LOS( [500.,0,0] )
        fad_chan2 = itpp.tdl_channel(  )
        fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 )
        fad_chan.set_norm_doppler( 1e-8 )
        fad_chan2.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 )
        fad_chan2.set_norm_doppler( 1e-8 )
      else:
        fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
        fad_chan2 = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
        
      self.connect( fad_chan, self.dst )
      self.connect( fad_chan2, self.dst2 )
      self.dst = fad_chan
      self.dst2 = fad_chan2

    if options.samplingoffset is not None:
      soff = options.samplingoffset
      interp = moms(1000000+soff,1000000)
      interp2 = moms(1000000+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,self._bandwidth)
    tmm2 =blocks.throttle(gr.sizeof_gr_complex,self._bandwidth)
    tmm_add = blocks.add_cc()
    tmm2_add = blocks.add_cc()
    self.connect( tmm, tmm_add )
    self.connect( tmm2, (tmm_add,1) )
    self.connect( tmm, tmm2_add )
    self.connect( tmm2, (tmm2_add,1) )
    self.connect( tmm_add, self.dst )
    self.connect( tmm2_add, self.dst2 )
    self.dst = tmm
    self.dst2 = tmm2
    
    inter = blocks.interleave(gr.sizeof_gr_complex)
    deinter = blocks.deinterleave(gr.sizeof_gr_complex)
    
    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,self.dst )
    self.connect( (self.txpath,1),self.dst2 )
    
    
    if options.cheat:
      self.txpath.enable_channel_cheating("channelcheat")

    
      
    print "Hit Strg^C to terminate"

    if options.event_rxbaseband:
      self.publish_rx_baseband_measure()
      
      
    if options.with_old_gui:
      self.publish_spectrum(256)
      self.rxpath.publish_ctf("ctf_display")
      self.rxpath.publish_ber_measurement(["ber"])
      self.rxpath.publish_average_snr(["totalsnr"])
      if options.sinr_est:
        self.rxpath.publish_sinrsc("sinrsc_display")
      

    
    print "Hit Strg^C to terminate"


    # Display some information about the setup
    if self._verbose:
        self._print_verbage()
Example #9
0
  def __init__ (self, options):
    gr.top_block.__init__(self, "ofdm_tx")

    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._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 = 0.5/self._interpolation
    tb = bw/5
    if self._interpolation > 1:
      self.filter = gr.hier_block2("filter",
                                   gr.io_signature(1,1,gr.sizeof_gr_complex),
                                   gr.io_signature(1,1,gr.sizeof_gr_complex))
      self.filter.connect( self.filter, gr.interp_fir_filter_ccf(2,f1),
                           gr.interp_fir_filter_ccf(2,f1), self.filter )
      
      print "New"
#      
#      
#      self.filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.2, 60.0, 0)
#      self.filter = gr.interp_fir_filter_ccf(self._interpolation,self.filt_coeff)
#      print "Software interpolation filter length: %d" % (len(self.filt_coeff))
    else:
      self.filter = 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)
    
    config = station_configuration()
    
    self.enable_info_tx("info_tx", "pa_user")
#    if not options.no_cheat:
#      self.txpath.enable_channel_cheating("channelcheat")
    self.txpath.enable_txpower_adjust("txpower")
    self.txpath.publish_txpower("txpower_info")
    #self.enable_txfreq_adjust("txfreq")
    
    
    
    if options.nullsink:
      self.dst = gr.null_sink( gr.sizeof_gr_complex )
    
    else:  
      if not options.to_file is None:
        # capture transmitter's stream to disk
        self.dst  = gr.file_sink(gr.sizeof_gr_complex,options.to_file)
        tmp = gr.throttle(gr.sizeof_gr_complex,1e5)
        self.connect( tmp, self.dst )
        self.dst = tmp
        
        if options.force_filter:
          print "Forcing filter usage"
          self.connect( self.filter, self.dst )
          self.dst = self.filter
        
      else:
        # connect transmitter to usrp
        self._setup_usrp_sink()
        if options.dyn_freq:
            self.enable_txfreq_adjust("txfreq")
            
        if self.filter is not None:
          self.connect( self.filter,self.dst )
          self.dst = self.filter
          
        if options.record:
          log_to_file( self, self.txpath, "data/txpath_out.compl" )
        
        #self.publish_spectrum( 256 )
        
      
        
        
        
    if options.measure:
      self.m = throughput_measure(gr.sizeof_gr_complex)
      self.connect( self.m, self.dst )
      self.dst = self.m
        
    if options.samplingoffset is not None:
      soff = options.samplingoffset
      interp = gr.fractional_interpolator_cc(0.0,soff)
      self.connect( interp, self.dst )
      self.dst = interp

    if options.snr is not None:
      
#      if options.berm is not None:
#          noise_sigma = 380 #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 = gr.add_cc()
      awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma )
      self.connect( awgn_noise_src, (awgn_chan,1) )
      self.connect( awgn_chan, self.dst )
      self.dst = awgn_chan
      
      if options.berm is False:
          fad_chan = itpp.tdl_channel(  ) #[0, -7, -20], [0, 2, 6]
          #fad_chan.set_norm_doppler( 1e-9 )
          #fad_chan.set_LOS( [500.,0,0] )
          fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 )
          fad_chan.set_norm_doppler( 1e-8 )
    #        fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
          self.connect( fad_chan, self.dst )
          self.dst = fad_chan


    if options.freqoff is not None:
      freq_shift = gr.multiply_cc()
      norm_freq = options.freqoff / config.fft_length
      freq_off_src = gr.sig_source_c(1.0, gr.GR_SIN_WAVE, norm_freq, 1.0, 0.0 )
      self.connect( freq_off_src, ( freq_shift, 1 ) )
      dst = self.dst
      self.connect( freq_shift, dst )
      self.dst = freq_shift
      



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

    if options.cheat:
      self.txpath.enable_channel_cheating("channelcheat")

    
      
    print "Hit Strg^C to terminate"