def __init__(self, seed,fD,chan_pwrs,path_delays,flag_indep=False,flag_norm=True,flag_fadeEnable=False):
        gr.hier_block2.__init__(self,
            "multipath_rayleigh_cc",
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1)) # Output signature

        ##################################################
        # Parameters
        ##################################################
        self.fD = fD #Doppler Bandwidth = fd*(1.0/chan_rate)
        self.chan_pwrs = chan_pwrs
        self.path_delays_samples = path_delays
        self.chan_seed = seed
        self.mode = flag_fadeEnable #Enables fading for underlaying single path fading block

        # Checks that there is the same number of delays as there are powers.
        if len(self.chan_pwrs) != len(self.path_delays_us):
            raise ValueError, "The vector length of chan_pwrs does not match the vector length of path_delays."
            # Could this be improved?
            sys.exit(1)

        self.c2f_blks = []      # for list of gr.complex_to_float().
        self.delay_blks = []    # for list of gr.filter_delay_fc ().
        self.chan_blks = []     # for list of tait.flat_rayleigh_channel_cc().

        # Normalizes the channel powers if required
        if flag_norm is True:
            self.chan_pwrs = 1.0*np.array(chan_pwrs)/np.sqrt((chan_pwrs ** 2).sum(-1))

        # Populate the lists above with the correct number of blocks.
        for i in range (len(self.path_delays_samples)):
            print "create delay block %d" %(i)
            
            # Delay block is required.
            self.delay_blks.append(gr.delay(gr.sizeof_gr_complex*1, int(self.path_delays_samples[i])))
                
            self.chan_blks.append(rccBlocks.rayleighChan_cc(chan_seed + i, self.fD, self.chan_pwrs[i], flag_indep,self.mode))

        self.sum = gr.add_vcc(1)  

        # Create multiple instances of the "src -> delay -> channel" connection.
        for i in range (len(self.chan_blks)):
            print i
            self.connect( (self,0), (self.chan_blks[i],0) )
            self.connect( (self.chan_blks[i],0), (self.delay_blks[i],0) )
            self.connect( (self.delay_blks[i],0), (self.sum, i) )
        #self.connect( (self,0), (self.chan_blks[0],0) )
        #self.connect( (self.chan_blks[0],0), (self.delay_blks[0],0) )
        #self.connect( (self.delay_blks[0],0), (self, 0) )  
        self.connect((self.sum, 0), (self,0) )         
    def __init__(self):
        gr.top_block.__init__(self, "Static RF or Single Path Rayleigh Faded RF")

        ##################################################
        # Variables
        ##################################################
        self.usrpRate = usrpRate = 250e3
        self.fd = fd = 20
        self.fdTs = fdTs = fd*(1.0/usrpRate)
        self.fadeMode = fadeMode = 0
        self.centreFreq = centreFreq = 1e6
        self.baseband_multiplier = baseband_multiplier = 0.25
        self.atten = atten = 0

        ##################################################
        # Blocks
        ##################################################
        self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(("0.0.0.0", 1234), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        threading.Thread(target=self.xmlrpc_server_0.serve_forever).start()
        self.uhd_usrp_sink_0_0_0 = uhd.usrp_sink(
        	device_addr="",
        	stream_args=uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink_0_0_0.set_subdev_spec("B:AB", 0)
        self.uhd_usrp_sink_0_0_0.set_samp_rate(usrpRate)
        self.uhd_usrp_sink_0_0_0.set_center_freq(centreFreq, 0)
        self.uhd_usrp_sink_0_0_0.set_gain(0, 0)
        self.rccBlocks_rayleighChan_cc_0 = rccBlocks.rayleighChan_cc(randint(-10e3, 0), fdTs, 1.0, False, bool(fadeMode))
        self.rccBlocks_VNXLabBrick_0 = rccBlocks.VNXLabBrick(atten)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, usrpRate,True)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((baseband_multiplier, ))
        self.analog_const_source_x_1 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 1)
        self.analog_const_source_x_0 = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1+1j)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.uhd_usrp_sink_0_0_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.rccBlocks_VNXLabBrick_0, 0))
        self.connect((self.analog_const_source_x_1, 0), (self.blocks_throttle_0, 0))
        self.connect((self.rccBlocks_rayleighChan_cc_0, 0), (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.analog_const_source_x_0, 0), (self.rccBlocks_rayleighChan_cc_0, 0))
    def __init__(self):
        gr.top_block.__init__(self, "Static RF or Single Path Rayleigh Faded RF")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Static RF or Single Path Rayleigh Faded RF")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "pc_fading_vaunix_qtgui")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.usrpRate = usrpRate = 250e3
        self.fd = fd = 50
        self.fdTs = fdTs = fd*(1.0/usrpRate)
        self.fadeMode = fadeMode = False
        self.centreFreq = centreFreq = 1e6
        self.baseband_multiplier = baseband_multiplier = 0.25
        self.atten = atten = 0

        ##################################################
        # Blocks
        ##################################################
        _fadeMode_check_box = Qt.QCheckBox("Fading Enabled")
        self._fadeMode_choices = {True: True, False: False}
        self._fadeMode_choices_inv = dict((v,k) for k,v in self._fadeMode_choices.iteritems())
        self._fadeMode_callback = lambda i: Qt.QMetaObject.invokeMethod(_fadeMode_check_box, "setChecked", Qt.Q_ARG("bool", self._fadeMode_choices_inv[i]))
        self._fadeMode_callback(self.fadeMode)
        _fadeMode_check_box.stateChanged.connect(lambda i: self.set_fadeMode(self._fadeMode_choices[bool(i)]))
        self.top_layout.addWidget(_fadeMode_check_box)
        self._atten_layout = Qt.QVBoxLayout()
        self._atten_tool_bar = Qt.QToolBar(self)
        self._atten_layout.addWidget(self._atten_tool_bar)
        self._atten_tool_bar.addWidget(Qt.QLabel("RF Attenuator Setting, dB"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._atten_counter = qwt_counter_pyslot()
        self._atten_counter.setRange(0, 63, 2)
        self._atten_counter.setNumButtons(2)
        self._atten_counter.setValue(self.atten)
        self._atten_tool_bar.addWidget(self._atten_counter)
        self._atten_counter.valueChanged.connect(self.set_atten)
        self._atten_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._atten_slider.setRange(0, 63, 2)
        self._atten_slider.setValue(self.atten)
        self._atten_slider.setMinimumWidth(200)
        self._atten_slider.valueChanged.connect(self.set_atten)
        self._atten_layout.addWidget(self._atten_slider)
        self.top_layout.addLayout(self._atten_layout)
        self.uhd_usrp_sink_0_0_0 = uhd.usrp_sink(
        	device_addr="",
        	stream_args=uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink_0_0_0.set_subdev_spec("B:AB", 0)
        self.uhd_usrp_sink_0_0_0.set_samp_rate(usrpRate)
        self.uhd_usrp_sink_0_0_0.set_center_freq(centreFreq, 0)
        self.uhd_usrp_sink_0_0_0.set_gain(0, 0)
        self.rccBlocks_rayleighChan_cc_0 = rccBlocks.rayleighChan_cc(randint(-10e3, 0), fdTs, 1.0, False, bool(fadeMode))
        self.rccBlocks_VNXLabBrick_0 = rccBlocks.VNXLabBrick(atten)
        self._fd_tool_bar = Qt.QToolBar(self)
        self._fd_tool_bar.addWidget(Qt.QLabel("Doppler Rate, Hz"+": "))
        self._fd_line_edit = Qt.QLineEdit(str(self.fd))
        self._fd_tool_bar.addWidget(self._fd_line_edit)
        self._fd_line_edit.returnPressed.connect(
        	lambda: self.set_fd(eng_notation.str_to_num(self._fd_line_edit.text().toAscii())))
        self.top_layout.addWidget(self._fd_tool_bar)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, usrpRate,True)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((baseband_multiplier, ))
        self.analog_const_source_x_1 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 1)
        self.analog_const_source_x_0 = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1+1j)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.uhd_usrp_sink_0_0_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.rccBlocks_VNXLabBrick_0, 0))
        self.connect((self.analog_const_source_x_0, 0), (self.rccBlocks_rayleighChan_cc_0, 0))
        self.connect((self.analog_const_source_x_1, 0), (self.blocks_throttle_0, 0))
        self.connect((self.rccBlocks_rayleighChan_cc_0, 0), (self.blocks_multiply_const_vxx_1, 0))
Exemplo n.º 4
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.fd = fd = 50
        self.chan_rate = chan_rate = 250000
        self.fdTs = fdTs = fd*(1.0/chan_rate)
        self.fadeMode = fadeMode = False

        ##################################################
        # Blocks
        ##################################################
        _fadeMode_check_box = Qt.QCheckBox("Fading Enabled")
        self._fadeMode_choices = {True: True, False: False}
        self._fadeMode_choices_inv = dict((v,k) for k,v in self._fadeMode_choices.iteritems())
        self._fadeMode_callback = lambda i: Qt.QMetaObject.invokeMethod(_fadeMode_check_box, "setChecked", Qt.Q_ARG("bool", self._fadeMode_choices_inv[i]))
        self._fadeMode_callback(self.fadeMode)
        _fadeMode_check_box.stateChanged.connect(lambda i: self.set_fadeMode(self._fadeMode_choices[bool(i)]))
        self.top_layout.addWidget(_fadeMode_check_box)
        self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(("0.0.0.0", 1234), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        threading.Thread(target=self.xmlrpc_server_0.serve_forever).start()
        self.rccBlocks_rayleighChan_cc_0 = rccBlocks.rayleighChan_cc(randint(-10e3, 0), fdTs, 1.0, False, fadeMode)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	25000, #size
        	chan_rate, #samp_rate
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-50, 20)
        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_histogram_sink_x_0 = qtgui.histogram_sink_f(
        	1500000,
        	100,
                0,
                4,
        	"QT GUI Plot",
        	1
        )
        self.qtgui_histogram_sink_x_0.set_update_time(0.10)
        self._qtgui_histogram_sink_x_0_win = sip.wrapinstance(self.qtgui_histogram_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_histogram_sink_x_0_win)
        self._fd_tool_bar = Qt.QToolBar(self)
        self._fd_tool_bar.addWidget(Qt.QLabel("Doppler Rate, Hz"+": "))
        self._fd_line_edit = Qt.QLineEdit(str(self.fd))
        self._fd_tool_bar.addWidget(self._fd_line_edit)
        self._fd_line_edit.returnPressed.connect(
        	lambda: self.set_fd(eng_notation.str_to_num(self._fd_line_edit.text().toAscii())))
        self.top_layout.addWidget(self._fd_tool_bar)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, chan_rate,True)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(1, 1, 0)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((20, ))
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)
        self.analog_const_source_x_0 = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1+1j)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.rccBlocks_rayleighChan_cc_0, 0))
        self.connect((self.rccBlocks_rayleighChan_cc_0, 0), (self.blocks_complex_to_mag_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_nlog10_ff_0, 0))
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0), (self.qtgui_histogram_sink_x_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_time_sink_x_0, 0))