def __init__(self, param_samp_rate, param_freq, param_gain, address, address2): grc_wxgui.top_block_gui.__init__(self, title="UHD FFT") ################################################## # Parameters ################################################## param_freq = 5.792e9 self.if_freq = 960e6 self.square_freq = 4e6 self.num_steps = 32 self.lo_start_freq = 5.312e9 self.param_samp_rate = param_samp_rate self.param_freq = param_freq self.param_gain = param_gain self.address = address self.address2 = address2 self.offset_freq = 10e3 ################################################## # Variables ################################################## self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value("", False, "") self.samp_rate = samp_rate = param_samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain = gain = param_gain self.freq = freq = param_freq self.ant = ant = "J1" self.test = options.test self.tofile = options.tofile ################################################## # Blocks ################################################## _gain_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, label="RX Gain", converter=forms.float_converter(), proportion=0, ) self._gain_slider = forms.slider( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, minimum=0, maximum=112.5, num_steps=225, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 2, 0, 1, 8) if self.test == False: self.source = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.source.set_subdev_spec("A:0 B:0") self.source.set_center_freq(self.if_freq, 0) self.source.set_gain(g.stop(), 0) self.source.set_bandwidth(64e6, 0) #Channel 1 g = self.source.get_gain_range(1) self.source.set_center_freq(self.if_freq, 1) #Mixer @ 4992 MHz self.source.set_gain(g.stop(), 1) self.source.set_bandwidth(64e6, 1) self.source.set_samp_rate(samp_rate) self.source2 = uhd.usrp_source( device_addr=address2, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source2.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.source2.set_subdev_spec("A:0 B:0") self.source2.set_center_freq(self.if_freq, 0) self.source2.set_gain(g.stop(), 0) self.source2.set_bandwidth(64e6, 0) #Channel 1 g = self.source2.get_gain_range(1) self.source2.set_center_freq(self.if_freq, 1) #Mixer @ 4992 MHz self.source2.set_gain(g.stop(), 1) self.source2.set_bandwidth(64e6, 1) self.source2.set_samp_rate(samp_rate) else: self.source_pre = blocks.file_source(gr.sizeof_gr_complex, "test.dat", True) self.source = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.connect(self.source_pre, self.source) self.source_freqs_pre = blocks.file_source(gr.sizeof_gr_complex, "test_freqs.dat", True) self.source_freqs = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.connect(self.source_freqs_pre, self.source_freqs) ################################################## # Connections ################################################## #Actual demo code #self.stitcher = fast_square.freq_stitcher("cal.dat",14*4) if self.test == True: self.connect(self.source_freqs, self.stitcher) else: if self.tofile == True: self.logfile0 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan0.dat") self.connect((self.source, 0), self.logfile0) self.logfile1 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan1.dat") self.connect((self.source, 1), self.logfile1) self.logfile2 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan2.dat") self.connect((self.source2, 0), self.logfile2) self.logfile3 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan3.dat") self.connect((self.source2, 1), self.logfile3) self.connect((self.source, 1), self.stitcher)
def __init__(self, antenna="RX2", args="", fft_size=1024, freq=833e6, gain=20, samp_rate=13e6, spec="", stream_args="", update_rate=.1, wire_format=""): gr.top_block.__init__(self, "Spectrum Analyzer") Qt.QWidget.__init__(self) self.setWindowTitle("Spectrum Analyzer") 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", "spectrum_analyzer") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.antenna = antenna self.args = args self.fft_size = fft_size self.freq = freq self.gain = gain self.samp_rate = samp_rate self.spec = spec self.stream_args = stream_args self.update_rate = update_rate self.wire_format = wire_format ################################################## # Variables ################################################## self.freq_c = freq_c = freq self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value("", False, "") self.usrp_device_info = usrp_device_info = uhd.get_version_string() self.uhd_version_info = uhd_version_info = uhd.get_version_string() self.samp_rate_ = samp_rate_ = samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain_ = gain_ = gain self.current_freq_c = current_freq_c = freq_c self.ant = ant = antenna ################################################## # Blocks ################################################## self._samp_rate__tool_bar = Qt.QToolBar(self) self._samp_rate__tool_bar.addWidget(Qt.QLabel("Sampling Rate"+": ")) self._samp_rate__line_edit = Qt.QLineEdit(str(self.samp_rate_)) self._samp_rate__tool_bar.addWidget(self._samp_rate__line_edit) self._samp_rate__line_edit.returnPressed.connect( lambda: self.set_samp_rate_(eng_notation.str_to_num(str(self._samp_rate__line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._samp_rate__tool_bar, 3,2,1,2) self._gain__layout = Qt.QVBoxLayout() self._gain__tool_bar = Qt.QToolBar(self) self._gain__layout.addWidget(self._gain__tool_bar) self._gain__tool_bar.addWidget(Qt.QLabel("RX Gain"+": ")) 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._gain__counter = qwt_counter_pyslot() self._gain__counter.setRange(0, 31.5, .5) self._gain__counter.setNumButtons(2) self._gain__counter.setValue(self.gain_) self._gain__tool_bar.addWidget(self._gain__counter) self._gain__counter.valueChanged.connect(self.set_gain_) self._gain__slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._gain__slider.setRange(0, 31.5, .5) self._gain__slider.setValue(self.gain_) self._gain__slider.setMinimumWidth(200) self._gain__slider.valueChanged.connect(self.set_gain_) self._gain__layout.addWidget(self._gain__slider) self.top_grid_layout.addLayout(self._gain__layout, 2,0,1,4) self._freq_c_tool_bar = Qt.QToolBar(self) self._freq_c_tool_bar.addWidget(Qt.QLabel("RX Tune Frequency"+": ")) self._freq_c_line_edit = Qt.QLineEdit(str(self.freq_c)) self._freq_c_tool_bar.addWidget(self._freq_c_line_edit) self._freq_c_line_edit.returnPressed.connect( lambda: self.set_freq_c(eng_notation.str_to_num(str(self._freq_c_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._freq_c_tool_bar, 3,0,1,2) self._ant_options = ("RX2", "TX/RX", "J1", "J2", ) self._ant_labels = ("RX2", "TX/RX", "J1", "J2", ) self._ant_tool_bar = Qt.QToolBar(self) self._ant_tool_bar.addWidget(Qt.QLabel("Antenna"+": ")) self._ant_combo_box = Qt.QComboBox() self._ant_tool_bar.addWidget(self._ant_combo_box) for label in self._ant_labels: self._ant_combo_box.addItem(label) self._ant_callback = lambda i: Qt.QMetaObject.invokeMethod(self._ant_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._ant_options.index(i))) self._ant_callback(self.ant) self._ant_combo_box.currentIndexChanged.connect( lambda i: self.set_ant(self._ant_options[i])) self.top_grid_layout.addWidget(self._ant_tool_bar, 4,2,1,2) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join((args, "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate_) self.uhd_usrp_source_0.set_center_freq(float(freq_c), 0) self.uhd_usrp_source_0.set_gain(gain_, 0) self.uhd_usrp_source_0.set_antenna(ant, 0) self.uhd_usrp_source_0.set_bandwidth(samp_rate, 0) self.display = Qt.QTabWidget() self.display_widget_0 = Qt.QWidget() self.display_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.display_widget_0) self.display_grid_layout_0 = Qt.QGridLayout() self.display_layout_0.addLayout(self.display_grid_layout_0) self.display.addTab(self.display_widget_0, "Spectrum") self.display_widget_1 = Qt.QWidget() self.display_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.display_widget_1) self.display_grid_layout_1 = Qt.QGridLayout() self.display_layout_1.addLayout(self.display_grid_layout_1) self.display.addTab(self.display_widget_1, "Waterfall") self.display_widget_2 = Qt.QWidget() self.display_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.display_widget_2) self.display_grid_layout_2 = Qt.QGridLayout() self.display_layout_2.addLayout(self.display_grid_layout_2) self.display.addTab(self.display_widget_2, "Scope") self.top_grid_layout.addWidget(self.display, 0,0,1,4) self._usrp_device_info_tool_bar = Qt.QToolBar(self) if None: self._usrp_device_info_formatter = None else: self._usrp_device_info_formatter = lambda x: x self._usrp_device_info_tool_bar.addWidget(Qt.QLabel("Device Information"+": ")) self._usrp_device_info_label = Qt.QLabel(str(self._usrp_device_info_formatter(self.usrp_device_info))) self._usrp_device_info_tool_bar.addWidget(self._usrp_device_info_label) self.top_grid_layout.addWidget(self._usrp_device_info_tool_bar, 1,2,1,2) self._uhd_version_info_tool_bar = Qt.QToolBar(self) if None: self._uhd_version_info_formatter = None else: self._uhd_version_info_formatter = lambda x: x self._uhd_version_info_tool_bar.addWidget(Qt.QLabel("UHD Version"+": ")) self._uhd_version_info_label = Qt.QLabel(str(self._uhd_version_info_formatter(self.uhd_version_info))) self._uhd_version_info_tool_bar.addWidget(self._uhd_version_info_label) self.top_grid_layout.addWidget(self._uhd_version_info_tool_bar, 1,0,1,2) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype freq, #fc samp_rate_, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(update_rate) self.qtgui_waterfall_sink_x_0.enable_grid(False) if complex == type(float()): self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.display_grid_layout_1.addWidget(self._qtgui_waterfall_sink_x_0_win, 0,0,1,4) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 1024, #size samp_rate_, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(update_rate) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label("Amplitude", "") 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.enable_autoscale(True) self.qtgui_time_sink_x_0.enable_grid(False) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue"] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2*1): if len(labels[i]) == 0: if(i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.display_grid_layout_2.addWidget(self._qtgui_time_sink_x_0_win, 0,0,1,4) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( fft_size, #size firdes.WIN_BLACKMAN_hARRIS, #wintype freq, #fc samp_rate_, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(update_rate) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(0.1) if complex == type(float()): self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.display_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,1,4) self._lo_locked_probe_tool_bar = Qt.QToolBar(self) if None: self._lo_locked_probe_formatter = None else: self._lo_locked_probe_formatter = lambda x: x self._lo_locked_probe_tool_bar.addWidget(Qt.QLabel("LO locked"+": ")) self._lo_locked_probe_label = Qt.QLabel(str(self._lo_locked_probe_formatter(self.lo_locked_probe))) self._lo_locked_probe_tool_bar.addWidget(self._lo_locked_probe_label) self.top_grid_layout.addWidget(self._lo_locked_probe_tool_bar, 4,0,1,2) def _current_freq_c_probe(): while True: val = self.uhd_usrp_source_0.get_sensor('lo_locked') try: self.set_current_freq_c(val) except AttributeError: pass time.sleep(1.0 / (10)) _current_freq_c_thread = threading.Thread(target=_current_freq_c_probe) _current_freq_c_thread.daemon = True _current_freq_c_thread.start() def _chan0_lo_locked_probe(): while True: val = self.uhd_usrp_source_0.get_sensor('lo_locked') try: self.set_chan0_lo_locked(val) except AttributeError: pass time.sleep(1.0 / (10)) _chan0_lo_locked_thread = threading.Thread(target=_chan0_lo_locked_probe) _chan0_lo_locked_thread.daemon = True _chan0_lo_locked_thread.start() ################################################## # Connections ################################################## self.msg_connect((self.qtgui_freq_sink_x_0, 'freq'), (self.qtgui_freq_sink_x_0, 'freq')) self.msg_connect((self.qtgui_freq_sink_x_0, 'freq'), (self.uhd_usrp_source_0, 'command')) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
def __init__(self, param_samp_rate, param_freq, param_gain, address): grc_wxgui.top_block_gui.__init__(self, title="UHD FFT") ################################################## # Parameters ################################################## param_freq = 5.792e9 self.if_freq = 960e6 self.square_freq = 4e6 self.num_steps = 32 self.lo_start_freq = 5.312e9 self.param_samp_rate = param_samp_rate self.param_freq = param_freq self.param_gain = param_gain self.address = address self.offset_freq = 10e3 ################################################## # Variables ################################################## self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value( "", False, "") self.samp_rate = samp_rate = param_samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain = gain = param_gain self.freq = freq = param_freq self.ant = ant = "J1" self.test = options.test self.tofile = options.tofile ################################################## # Blocks ################################################## _gain_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, label="RX Gain", converter=forms.float_converter(), proportion=0, ) self._gain_slider = forms.slider( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, minimum=0, maximum=112.5, num_steps=225, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 2, 0, 1, 8) if self.test == False: self.source = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 self.source.set_subdev_spec("A:0 B:0") self.source.set_center_freq(freq, 0) self.source.set_gain(gain, 0) self.source.set_antenna(ant, 0) self.source.set_bandwidth(samp_rate, 0) #Channel 1 g = self.source.get_gain_range(1) print "rx gain range is (%f,%f)" % (g.start(), g.stop()) self.source.set_center_freq(self.if_freq, 1) #Mixer @ 4992 MHz self.source.set_gain(g.stop(), 1) #self.source.set_antenna(ant, 1) self.source.set_bandwidth(36e6, 1) #Need Turbo mode! self.source.set_samp_rate(samp_rate) else: self.source_pre = blocks.file_source(gr.sizeof_gr_complex, "test.dat", True) self.source = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate) self.connect(self.source_pre, self.source) self.source_freqs_pre = blocks.file_source(gr.sizeof_gr_complex, "test_freqs.dat", True) self.source_freqs = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate) self.connect(self.source_freqs_pre, self.source_freqs) self.nb0 = self.nb0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "FFT") self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Waterfall") self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Scope") self.GridAdd(self.nb0, 0, 0, 1, 8) # self.scopesink_0 = scopesink2.scope_sink_c( # self.nb0.GetPage(0).GetWin(), # title="Scope Plot", # sample_rate=samp_rate, # v_scale=0, # v_offset=0, # t_scale=0, # ac_couple=False, # xy_mode=False, # num_inputs=1, # trig_mode=wxgui.TRIG_MODE_AUTO, # y_axis_label="Counts", # ) # self.nb0.GetPage(0).Add(self.scopesink_0.win) self.scopesink_0 = fftsink2.fft_sink_c( self.nb0.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=15, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, size=((-1, 400)), ) self.nb0.GetPage(0).Add(self.scopesink_0.win) self.scopesink_1 = scopesink2.scope_sink_c( self.nb0.GetPage(1).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb0.GetPage(1).Add(self.scopesink_1.win) self.scopesink_2 = scopesink2.scope_sink_c( self.nb0.GetPage(2).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb0.GetPage(2).Add(self.scopesink_2.win) ################################################## # Connections ################################################## #Actual demo code self.multiply_0 = blocks.multiply_vcc(1) self.multiply_1 = blocks.multiply_vcc(1) self.carrier_est = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 100000, 1, 0) self.subcarrier_est = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -300000, 1, 0) chan_coeffs = filter.firdes.low_pass(1.0, 1.0, 0.05, 0.05, filter.firdes.WIN_HANN) self.carrier_tracking_filter = filter.fft_filter_ccc(1, chan_coeffs) self.carrier_tracking = analog.pll_refout_cc(0.0003, .15, -.15) self.carrier_tracking_conj = blocks.conjugate_cc() self.subcarrier_tracking_filter = filter.fft_filter_ccc(1, chan_coeffs) self.subcarrier_tracking = analog.pll_carriertracking_cc( 0.0005, .001, -0.001) self.stitcher = fast_square.freq_stitcher("cal.dat", 14 * 4) if self.test == True: self.connect(self.source_freqs, self.stitcher) else: if self.tofile == True: self.logfile0 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan0.dat") self.connect((self.source, 0), self.logfile0) self.logfile1 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan1.dat") self.connect((self.source, 1), self.logfile1) self.connect((self.source, 1), self.stitcher) self.connect((self.source, 0), (self.multiply_0, 0)) self.connect(self.carrier_est, (self.multiply_0, 1)) self.connect(self.multiply_0, self.carrier_tracking_filter, self.carrier_tracking, self.carrier_tracking_conj) self.connect(self.carrier_tracking_conj, (self.multiply_1, 0)) self.connect((self.source, 0), (self.multiply_1, 1)) self.connect(self.subcarrier_est, (self.multiply_1, 2)) self.connect(self.multiply_1, self.subcarrier_tracking_filter, self.subcarrier_tracking) # self.connect((self.source, 0), self.scopesink_0) self.connect(self.multiply_1, self.scopesink_0) self.connect(self.subcarrier_tracking, self.scopesink_1) # self.connect(self.subcarrier_tracking, self.scopesink_2) def _freq_tracker(): loop_count = 0 while True: loop_count = loop_count + 1 #TODO: Is this whole calculation section correct? carrier_freq = self.carrier_tracking.get_frequency( ) / 2 / math.pi * self.samp_rate subcarrier_freq = self.subcarrier_tracking.get_frequency( ) / 2 / math.pi * self.samp_rate print "carrier_freq = %f, \t subcarrier_freq = %f" % ( carrier_freq, subcarrier_freq) #TODO: DEBUG ONLY #if loop_count > 100: # print "GOING DOWN" # #carrier_freq = self.offset_freq # carrier_freq = carrier_freq + self.offset_freq # self.offset_freq = self.offset_freq - 1e2 #Translate to absolute frequency carrier_freq = self.param_freq + carrier_freq - 100e3 subcarrier_freq = self.square_freq + subcarrier_freq #Figure out what harmonic we will be centered on next_harmonic = math.ceil( ((self.lo_start_freq + self.if_freq) - (self.param_freq + self.square_freq)) / self.square_freq / 2) next_harmonic_freq = self.param_freq + self.square_freq + next_harmonic * self.square_freq * 2 target_freq = next_harmonic_freq - self.square_freq actual_freq = carrier_freq + next_harmonic * subcarrier_freq * 2 carrier_mixer_freq = -(actual_freq - target_freq) subcarrier_mixer_freq = subcarrier_freq carrier_reg = carrier_mixer_freq / 64e6 if carrier_reg < 0: carrier_reg = carrier_reg + 1.0 carrier_reg = int(carrier_reg * (2**32)) if self.test == False: self.source.set_user_register( 64 + 0, carrier_reg) #Write to FR_USER_0 (Carrier offset reg) subcarrier_reg = subcarrier_mixer_freq / 64e6 #Subcarrier freq register is absolute freq, not error subcarrier_reg = int(subcarrier_reg * (2**32)) if self.test == False: self.source.set_user_register( 64 + 1, subcarrier_reg ) #Write to FR_USER_1 (Subcarrier freq reg) freq_step = ((self.square_freq - subcarrier_freq) * 8) / 64e6 if freq_step < 0: freq_step = freq_step + 1.0 freq_step_reg = int(freq_step * (2**32)) if self.test == False: self.source.set_user_register(64 + 2, freq_step_reg) print "carrier_freq = %f, \t subcarrier_freq = %f, \t freq_step = %f, \t carrier_reg = %d, \t subcarrier_reg = %d, \t freq_step_reg = %d" % ( carrier_freq, subcarrier_freq, freq_step, carrier_reg, subcarrier_reg, freq_step_reg) time.sleep(1.0 / (10)) _freq_tracker_thread = threading.Thread(target=_freq_tracker) _freq_tracker_thread.daemon = True _freq_tracker_thread.start()
def __init__(self, antenna="RX2", args="", fft_size=1024, freq=2.45e9, gain=20, samp_rate=1e6, spec="", stream_args="", update_rate=.1, wire_format=""): gr.top_block.__init__(self, "UHD FFT") Qt.QWidget.__init__(self) self.setWindowTitle("UHD FFT") 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", "astrotest12") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.antenna = antenna self.args = args self.fft_size = fft_size self.freq = freq self.gain = gain self.samp_rate = samp_rate self.spec = spec self.stream_args = stream_args self.update_rate = update_rate self.wire_format = wire_format ################################################## # Variables ################################################## self.freq_c = freq_c = freq self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value("", False, "") self.usrp_device_info = usrp_device_info = uhd.get_version_string() self.uhd_version_info = uhd_version_info = uhd.get_version_string() self.samp_rate_ = samp_rate_ = samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain_ = gain_ = gain self.current_freq_c = current_freq_c = freq_c self.ant = ant = antenna ################################################## # Blocks ################################################## self._samp_rate__tool_bar = Qt.QToolBar(self) self._samp_rate__tool_bar.addWidget(Qt.QLabel("Sampling Rate"+": ")) self._samp_rate__line_edit = Qt.QLineEdit(str(self.samp_rate_)) self._samp_rate__tool_bar.addWidget(self._samp_rate__line_edit) self._samp_rate__line_edit.returnPressed.connect( lambda: self.set_samp_rate_(eng_notation.str_to_num(str(self._samp_rate__line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._samp_rate__tool_bar, 3,2,1,2) self._gain__range = Range(0, 31.5, .5, gain, 200) self._gain__win = RangeWidget(self._gain__range, self.set_gain_, "RX Gain", "counter_slider", float) self.top_grid_layout.addWidget(self._gain__win, 2,0,1,4) self._freq_c_tool_bar = Qt.QToolBar(self) self._freq_c_tool_bar.addWidget(Qt.QLabel("RX Tune Frequency"+": ")) self._freq_c_line_edit = Qt.QLineEdit(str(self.freq_c)) self._freq_c_tool_bar.addWidget(self._freq_c_line_edit) self._freq_c_line_edit.returnPressed.connect( lambda: self.set_freq_c(eng_notation.str_to_num(str(self._freq_c_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._freq_c_tool_bar, 3,0,1,2) self._ant_options = ("RX2", "TX/RX", "J1", "J2", ) self._ant_labels = ("RX2", "TX/RX", "J1", "J2", ) self._ant_tool_bar = Qt.QToolBar(self) self._ant_tool_bar.addWidget(Qt.QLabel("Antenna"+": ")) self._ant_combo_box = Qt.QComboBox() self._ant_tool_bar.addWidget(self._ant_combo_box) for label in self._ant_labels: self._ant_combo_box.addItem(label) self._ant_callback = lambda i: Qt.QMetaObject.invokeMethod(self._ant_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._ant_options.index(i))) self._ant_callback(self.ant) self._ant_combo_box.currentIndexChanged.connect( lambda i: self.set_ant(self._ant_options[i])) self.top_grid_layout.addWidget(self._ant_tool_bar, 4,2,1,2) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join((args, "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate_) self.uhd_usrp_source_0.set_center_freq(float(freq_c), 0) self.uhd_usrp_source_0.set_gain(gain_, 0) self.uhd_usrp_source_0.set_antenna(ant, 0) self.uhd_usrp_source_0.set_bandwidth(samp_rate, 0) self.volume = blocks.multiply_const_vcc((20, )) self._usrp_device_info_tool_bar = Qt.QToolBar(self) if None: self._usrp_device_info_formatter = None else: self._usrp_device_info_formatter = lambda x: x self._usrp_device_info_tool_bar.addWidget(Qt.QLabel("Device Information"+": ")) self._usrp_device_info_label = Qt.QLabel(str(self._usrp_device_info_formatter(self.usrp_device_info))) self._usrp_device_info_tool_bar.addWidget(self._usrp_device_info_label) self.top_grid_layout.addWidget(self._usrp_device_info_tool_bar, 1,2,1,2) self._uhd_version_info_tool_bar = Qt.QToolBar(self) if None: self._uhd_version_info_formatter = None else: self._uhd_version_info_formatter = lambda x: x self._uhd_version_info_tool_bar.addWidget(Qt.QLabel("UHD Version"+": ")) self._uhd_version_info_label = Qt.QLabel(str(self._uhd_version_info_formatter(self.uhd_version_info))) self._uhd_version_info_tool_bar.addWidget(self._uhd_version_info_label) self.top_grid_layout.addWidget(self._uhd_version_info_tool_bar, 1,0,1,2) self.qtgui_sink_x_0 = qtgui.sink_f( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype freq, #fc samp_rate_, #bw "", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0/10) self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_win) self.qtgui_sink_x_0.enable_rf_freq(False) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 200e3, 30e3, firdes.WIN_HANN, 6.76)) self._lo_locked_probe_tool_bar = Qt.QToolBar(self) if None: self._lo_locked_probe_formatter = None else: self._lo_locked_probe_formatter = lambda x: x self._lo_locked_probe_tool_bar.addWidget(Qt.QLabel("LO locked"+": ")) self._lo_locked_probe_label = Qt.QLabel(str(self._lo_locked_probe_formatter(self.lo_locked_probe))) self._lo_locked_probe_tool_bar.addWidget(self._lo_locked_probe_label) self.top_grid_layout.addWidget(self._lo_locked_probe_tool_bar, 4,0,1,2) def _current_freq_c_probe(): while True: val = self.uhd_usrp_source_0.get_sensor('lo_locked') try: self.set_current_freq_c(val) except AttributeError: pass time.sleep(1.0 / (10)) _current_freq_c_thread = threading.Thread(target=_current_freq_c_probe) _current_freq_c_thread.daemon = True _current_freq_c_thread.start() def _chan0_lo_locked_probe(): while True: val = self.uhd_usrp_source_0.get_sensor('lo_locked') try: self.set_chan0_lo_locked(val) except AttributeError: pass time.sleep(1.0 / (10)) _chan0_lo_locked_thread = threading.Thread(target=_chan0_lo_locked_probe) _chan0_lo_locked_thread.daemon = True _chan0_lo_locked_thread.start() self.analog_wfm_rcv = analog.wfm_rcv( quad_rate=samp_rate, audio_decimation=10, ) ################################################## # Connections ################################################## self.connect((self.analog_wfm_rcv, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.volume, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.volume, 0), (self.analog_wfm_rcv, 0))
def __init__(self, param_samp_rate, param_freq, param_gain, address, address2): grc_wxgui.top_block_gui.__init__(self, title="UHD FFT") ################################################## # Parameters ################################################## param_freq = 5.792e9 self.if_freq = 960e6 self.square_freq = 4e6 self.num_steps = 32 self.lo_start_freq = 5.312e9 self.param_samp_rate = param_samp_rate self.param_freq = param_freq self.param_gain = param_gain self.address = address self.address2 = address2 self.offset_freq = 10e3 ################################################## # Variables ################################################## self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value("", False, "") self.samp_rate = samp_rate = param_samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain = gain = param_gain self.freq = freq = param_freq self.ant = ant = "J1" self.test = options.test self.tofile = options.tofile ################################################## # Blocks ################################################## if self.test == False: self.source = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.source.set_subdev_spec("A:0 B:0") self.source.set_center_freq(self.if_freq, 0) self.source.set_gain(g.stop(), 0) self.source.set_bandwidth(64e6, 0) #Channel 1 g = self.source.get_gain_range(1) self.source.set_center_freq(self.if_freq, 1) #Mixer @ 4992 MHz self.source.set_gain(g.stop(), 1) self.source.set_bandwidth(64e6, 1) self.source.set_samp_rate(samp_rate) self.source2 = uhd.usrp_source( device_addr=address2, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source2.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.source2.set_subdev_spec("A:0 B:0") self.source2.set_center_freq(self.if_freq, 0) self.source2.set_gain(g.stop(), 0) self.source2.set_bandwidth(64e6, 0) #Channel 1 g = self.source2.get_gain_range(1) self.source2.set_center_freq(self.if_freq, 1) #Mixer @ 4992 MHz self.source2.set_gain(g.stop(), 1) self.source2.set_bandwidth(64e6, 1) self.source2.set_samp_rate(samp_rate) else: self.source_pre = blocks.file_source(gr.sizeof_gr_complex, "test.dat", True) self.source = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.connect(self.source_pre, self.source) self.source_freqs_pre = blocks.file_source(gr.sizeof_gr_complex, "test_freqs.dat", True) self.source_freqs = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.connect(self.source_freqs_pre, self.source_freqs) ################################################## # Connections ################################################## #Actual demo code #self.stitcher = fast_square.freq_stitcher("cal.dat",14*4) if self.test == True: self.connect(self.source_freqs, self.stitcher) else: if self.tofile == True: self.logfile0 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan0.dat") self.connect((self.source, 0), self.logfile0) self.logfile1 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan1.dat") self.connect((self.source, 1), self.logfile1) self.logfile2 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan2.dat") self.connect((self.source2, 0), self.logfile2) self.logfile3 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan3.dat") self.connect((self.source2, 1), self.logfile3)
def __init__(self, param_samp_rate, param_freq, param_gain, address, address2): grc_wxgui.top_block_gui.__init__(self, title="UHD FFT") ################################################## # Parameters ################################################## param_freq = 5.792e9 self.bbg=0 self.gc1=70 self.if_freq = 990e6 self.bw = 64e6#40e6 self.square_freq = 4e6 self.num_steps = 32 self.lo_start_freq = 5.312e9 self.param_samp_rate = param_samp_rate self.param_freq = param_freq self.param_gain = param_gain self.address = address self.address2 = address2 self.dead_on_freq = 5.792e9 self.tag_freq = 5.792042e9#5.7919847e9 self.tune_freq = self.if_freq+self.tag_freq-self.dead_on_freq self.offset_freq = 10e3 ################################################## # Variables ################################################## self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value("", False, "") self.samp_rate = samp_rate = param_samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain = gain = param_gain self.freq = freq = param_freq self.ant = ant = "J1" self.test = options.test self.tofile = options.tofile ################################################## # Blocks ################################################## if self.test == False: self.source = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.source.set_subdev_spec("A:0 B:0") self.source.set_center_freq(self.tune_freq, 0) self.source.set_gain(gain, 0) #self.source.set_antenna("RX2", 0) #self.source.set_gain(self.bbg, "BBG", 0) #self.source.set_gain(self.gc1, "GC1", 0) self.source.set_bandwidth(self.bw, 0) #Channel 1 g = self.source.get_gain_range(1) self.source.set_center_freq(self.tune_freq, 1) #Mixer @ 4992 MHz self.source.set_gain(gain, 1) #self.source.set_antenna("RX2", 1) #self.source.set_gain(self.bbg, "BBG", 1) #self.source.set_gain(self.gc1, "GC1", 1) self.source.set_bandwidth(self.bw, 1) self.source2 = uhd.usrp_source( device_addr=address2, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source2.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.source2.set_subdev_spec("A:0 B:0") self.source2.set_center_freq(self.tune_freq, 0) self.source2.set_gain(gain, 0) #self.source2.set_antenna("RX2", 0) #self.source2.set_gain(self.bbg, "BBG", 0) #self.source2.set_gain(self.gc1, "GC1", 0) self.source2.set_bandwidth(self.bw, 0) #Channel 1 g = self.source2.get_gain_range(1) self.source2.set_center_freq(self.tune_freq, 1) #Mixer @ 4992 MHz self.source2.set_gain(gain, 1) #self.source2.set_antenna("RX2", 1) #self.source2.set_gain(self.bbg, "BBG", 1) #self.source2.set_gain(self.gc1, "GC1", 1) self.source2.set_bandwidth(self.bw, 1) else: self.source_pre = blocks.file_source(gr.sizeof_gr_complex, "test.dat", True) self.source = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.connect(self.source_pre, self.source) self.source_freqs_pre = blocks.file_source(gr.sizeof_gr_complex, "test_freqs.dat", True) self.source_freqs = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.connect(self.source_freqs_pre, self.source_freqs) ################################################## # Connections ################################################## #Actual demo code #self.stitcher = fast_square.freq_stitcher("cal.dat",14*4) if self.test == True: self.connect(self.source_freqs, self.stitcher) else: if self.tofile == True: self.logfile0 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan0.dat") self.connect((self.source, 0), self.logfile0) self.logfile1 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan1.dat") self.connect((self.source, 1), self.logfile1) self.logfile2 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan2.dat") self.connect((self.source2, 0), self.logfile2) self.logfile3 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan3.dat") self.connect((self.source2, 1), self.logfile3)
def __init__(self, param_samp_rate, param_freq, param_gain, address, address2): super(uhd_fft, self).__init__() ################################################## # Parameters ################################################## param_freq = 5.792e9 self.bbg=0 self.gc1=70 self.if_freq = 990e6 self.bw = 64e6#40e6 self.square_freq = 4e6 self.num_steps = 32 self.lo_start_freq = 5.312e9 self.param_samp_rate = param_samp_rate self.param_freq = param_freq self.param_gain = param_gain self.address = address self.address2 = address2 self.dead_on_freq = 5.792e9 self.tag_freq = 5.792042e9#5.7919847e9 self.tune_freq = self.if_freq+self.tag_freq-self.dead_on_freq self.offset_freq = 10e3 ################################################## # Variables ################################################## self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value("", False, "") self.samp_rate = samp_rate = param_samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain = gain = param_gain self.freq = freq = param_freq self.ant = ant = "J1" self.fromfile = options.fromfile self.tofile = options.tofile ################################################## # Blocks ################################################## if self.fromfile == False: self.source = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.source.set_subdev_spec("A:0 B:0") self.source.set_center_freq(self.tune_freq, 0) self.source.set_gain(gain, 0) #self.source.set_antenna("RX2", 0) #self.source.set_gain(self.bbg, "BBG", 0) #self.source.set_gain(self.gc1, "GC1", 0) self.source.set_bandwidth(self.bw, 0) #Channel 1 g = self.source.get_gain_range(1) self.source.set_center_freq(self.tune_freq, 1) #Mixer @ 4992 MHz self.source.set_gain(gain, 1) #self.source.set_antenna("RX2", 1) #self.source.set_gain(self.bbg, "BBG", 1) #self.source.set_gain(self.gc1, "GC1", 1) self.source.set_bandwidth(self.bw, 1) self.source2 = uhd.usrp_source( device_addr=address2, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source2.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.source2.set_subdev_spec("A:0 B:0") self.source2.set_center_freq(self.tune_freq, 0) self.source2.set_gain(gain, 0) #self.source2.set_antenna("RX2", 0) #self.source2.set_gain(self.bbg, "BBG", 0) #self.source2.set_gain(self.gc1, "GC1", 0) self.source2.set_bandwidth(self.bw, 0) #Channel 1 g = self.source2.get_gain_range(1) self.source2.set_center_freq(self.tune_freq, 1) #Mixer @ 4992 MHz self.source2.set_gain(gain, 1) #self.source2.set_antenna("RX2", 1) #self.source2.set_gain(self.bbg, "BBG", 1) #self.source2.set_gain(self.gc1, "GC1", 1) self.source2.set_bandwidth(self.bw, 1) ################################################## # Connections ################################################## #Actual demo code #self.stitcher = fast_square.freq_stitcher("cal.dat",14*4) if self.tofile == True: self.logfile0 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan0.dat") self.connect((self.source, 0), self.logfile0) self.logfile1 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan1.dat") self.connect((self.source, 1), self.logfile1) self.logfile2 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan2.dat") self.connect((self.source2, 0), self.logfile2) self.logfile3 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan3.dat") self.connect((self.source2, 1), self.logfile3) #Also connect to the stream parser so we get timestamps as well! self.parser = fast_square.stream_parser() self.connect((self.source, 0), (self.parser, 0)) self.connect((self.source, 1), (self.parser, 1)) self.connect((self.source2, 0), (self.parser, 2)) self.connect((self.source2, 1), (self.parser, 3)) else: self.parser = fast_square.stream_parser() if self.fromfile == True: self.logfile0 = blocks.file_source(gr.sizeof_gr_complex, "usrp_chan0.dat", True) self.logfile1 = blocks.file_source(gr.sizeof_gr_complex, "usrp_chan1.dat", True) self.logfile2 = blocks.file_source(gr.sizeof_gr_complex, "usrp_chan2.dat", True) self.logfile3 = blocks.file_source(gr.sizeof_gr_complex, "usrp_chan3.dat", True) self.connect(self.logfile0, (self.parser, 0)) self.connect(self.logfile1, (self.parser, 1)) self.connect(self.logfile2, (self.parser, 2)) self.connect(self.logfile3, (self.parser, 3)) else: self.connect((self.source, 0), (self.parser, 0)) self.connect((self.source, 1), (self.parser, 1)) self.connect((self.source2, 0), (self.parser, 2)) self.connect((self.source2, 1), (self.parser, 3)) ##The rest of the harmonia flowgraph self.prf_est = fast_square.prf_estimator(1024, True, [], False, 1, "prf_est") self.connect((self.parser, 0), (self.prf_est, 0)) self.connect((self.parser, 1), (self.prf_est, 1)) self.connect((self.parser, 2), (self.prf_est, 2)) self.connect((self.parser, 3), (self.prf_est, 3)) self.h_extract = fast_square.harmonic_extractor(1024, 1, "prf_est", "phasor_calc", "harmonic_freqs") self.connect((self.prf_est, 0), (self.h_extract, 0)) self.connect((self.prf_est, 1), (self.h_extract, 1)) self.connect((self.prf_est, 2), (self.h_extract, 2)) self.connect((self.prf_est, 3), (self.h_extract, 3)) self.h_locate = fast_square.harmonic_localizer("phasor_calc", "harmonic_freqs", "prf_est", "Sek5SXpFPa", 1) self.connect((self.h_extract, 0), (self.h_locate, 0)) self.connect((self.h_extract, 1), (self.h_locate, 1)) self.connect((self.h_extract, 2), (self.h_locate, 2)) self.connect((self.h_extract, 3), (self.h_locate, 3)) #TODO: Put this back in once we want to push to gatd # self.socket_pdu = blocks.socket_pdu("UDP_CLIENT", "inductor.eecs.umich.edu", "4001", 10000) # self.msg_connect(self.h_locate, "frame_out", self.socket_pdu, "pdus") ##WebSocket output for connection to remote visualization interface self.ws_port = sdrp.ws_sink_c(True, 18000, "FLOAT", "") self.msg_connect(self.h_locate, "frame_out", self.ws_port, "ws_pdu_in")
def __init__(self, param_samp_rate, param_freq, param_gain, address): grc_wxgui.top_block_gui.__init__(self, title="UHD FFT") ################################################## # Parameters ################################################## param_freq = 5.78666666667e9 self.param_samp_rate = param_samp_rate self.param_freq = param_freq self.param_gain = param_gain self.address = address ################################################## # Variables ################################################## self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value("", False, "") self.samp_rate = samp_rate = param_samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain = gain = param_gain self.freq = freq = param_freq self.ant = ant = "J1" ################################################## # Blocks ################################################## self._samp_rate_text_box = forms.text_box( parent=self.GetWin(), value=self.samp_rate, callback=self.set_samp_rate, label="Sample Rate", converter=forms.float_converter(), ) self.GridAdd(self._samp_rate_text_box, 1, 0, 1, 3) _gain_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, label="RX Gain", converter=forms.float_converter(), proportion=0, ) self._gain_slider = forms.slider( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, minimum=0, maximum=112.5, num_steps=225, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 2, 0, 1, 8) _freq_sizer = wx.BoxSizer(wx.VERTICAL) self._freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, label="RX Tune Frequency", converter=forms.float_converter(), proportion=0, ) self._freq_slider = forms.slider( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, minimum=50e6, maximum=6e9, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_freq_sizer, 3, 0, 1, 8) self._ant_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.ant, callback=self.set_ant, label="Antenna", choices=["J1","J2"], labels=["J1","J2"], style=wx.RA_HORIZONTAL, ) self.GridAdd(self._ant_chooser, 1, 4, 1, 2) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_subdev_spec("A:0", 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(gain, 0) self.uhd_usrp_source_0.set_antenna(ant, 0) self.uhd_usrp_source_0.set_bandwidth(samp_rate, 0) g = self.uhd_usrp_source_0.get_gain_range() print "rx gain range is (%f,%f)" % (g.start(),g.stop()) self.nb0 = self.nb0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "FFT") self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Waterfall") self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Scope") self.GridAdd(self.nb0, 0, 0, 1, 8) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.nb0.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", size=((-1, 400)), ) self.nb0.GetPage(1).Add(self.wxgui_waterfallsink2_0.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.nb0.GetPage(2).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb0.GetPage(2).Add(self.wxgui_scopesink2_0.win) self._lo_locked_probe_static_text = forms.static_text( parent=self.GetWin(), value=self.lo_locked_probe, callback=self.set_lo_locked_probe, label="LO Locked", converter=forms.str_converter(formatter=lambda x: x and "True" or "False"), ) self.GridAdd(self._lo_locked_probe_static_text, 1, 7, 1, 1) self.fft = fftsink2.fft_sink_c( self.nb0.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=15, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, size=((-1, 400)), ) self.nb0.GetPage(0).Add(self.fft.win) def _chan0_lo_locked_probe(): while True: val = self.uhd_usrp_source_0.get_sensor('lo_locked') try: self.set_chan0_lo_locked(val) except AttributeError, e: pass time.sleep(1.0/(10)) _chan0_lo_locked_thread = threading.Thread(target=_chan0_lo_locked_probe) _chan0_lo_locked_thread.daemon = True _chan0_lo_locked_thread.start() ################################################## # Connections ################################################## self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.fft, 0))
def __init__(self, param_samp_rate, param_freq, param_gain, address, address2): super(uhd_fft, self).__init__() ################################################## # Parameters ################################################## param_freq = 5.792e9 self.bbg = 0 self.gc1 = 70 self.if_freq = 990e6 self.bw = 64e6 #40e6 self.square_freq = 4e6 self.num_steps = 32 self.lo_start_freq = 5.312e9 self.param_samp_rate = param_samp_rate self.param_freq = param_freq self.param_gain = param_gain self.address = address self.address2 = address2 self.dead_on_freq = 5.792e9 self.tag_freq = 5.792042e9 #5.7919847e9 self.tune_freq = self.if_freq + self.tag_freq - self.dead_on_freq self.offset_freq = 10e3 ################################################## # Variables ################################################## self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value( "", False, "") self.samp_rate = samp_rate = param_samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain = gain = param_gain self.freq = freq = param_freq self.ant = ant = "J1" self.fromfile = options.fromfile self.tofile = options.tofile ################################################## # Blocks ################################################## if self.fromfile == False: self.source = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(), g.stop()) self.source.set_subdev_spec("A:0 B:0") self.source.set_center_freq(self.tune_freq, 0) self.source.set_gain(gain, 0) #self.source.set_antenna("RX2", 0) #self.source.set_gain(self.bbg, "BBG", 0) #self.source.set_gain(self.gc1, "GC1", 0) self.source.set_bandwidth(self.bw, 0) #Channel 1 g = self.source.get_gain_range(1) self.source.set_center_freq(self.tune_freq, 1) #Mixer @ 4992 MHz self.source.set_gain(gain, 1) #self.source.set_antenna("RX2", 1) #self.source.set_gain(self.bbg, "BBG", 1) #self.source.set_gain(self.gc1, "GC1", 1) self.source.set_bandwidth(self.bw, 1) self.source2 = uhd.usrp_source( device_addr=address2, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) #Channel 0 g = self.source2.get_gain_range(0) print "rx gain range is (%f,%f)" % (g.start(), g.stop()) self.source2.set_subdev_spec("A:0 B:0") self.source2.set_center_freq(self.tune_freq, 0) self.source2.set_gain(gain, 0) #self.source2.set_antenna("RX2", 0) #self.source2.set_gain(self.bbg, "BBG", 0) #self.source2.set_gain(self.gc1, "GC1", 0) self.source2.set_bandwidth(self.bw, 0) #Channel 1 g = self.source2.get_gain_range(1) self.source2.set_center_freq(self.tune_freq, 1) #Mixer @ 4992 MHz self.source2.set_gain(gain, 1) #self.source2.set_antenna("RX2", 1) #self.source2.set_gain(self.bbg, "BBG", 1) #self.source2.set_gain(self.gc1, "GC1", 1) self.source2.set_bandwidth(self.bw, 1) ################################################## # Connections ################################################## #Actual demo code #self.stitcher = fast_square.freq_stitcher("cal.dat",14*4) if self.tofile == True: self.logfile0 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan0.dat") self.connect((self.source, 0), self.logfile0) self.logfile1 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan1.dat") self.connect((self.source, 1), self.logfile1) self.logfile2 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan2.dat") self.connect((self.source2, 0), self.logfile2) self.logfile3 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_chan3.dat") self.connect((self.source2, 1), self.logfile3) #Also connect to the stream parser so we get timestamps as well! self.parser = fast_square.stream_parser() self.connect((self.source, 0), (self.parser, 0)) self.connect((self.source, 1), (self.parser, 1)) self.connect((self.source2, 0), (self.parser, 2)) self.connect((self.source2, 1), (self.parser, 3)) else: self.parser = fast_square.stream_parser() if self.fromfile == True: self.logfile0 = blocks.file_source(gr.sizeof_gr_complex, "usrp_chan0.dat", True) self.logfile1 = blocks.file_source(gr.sizeof_gr_complex, "usrp_chan1.dat", True) self.logfile2 = blocks.file_source(gr.sizeof_gr_complex, "usrp_chan2.dat", True) self.logfile3 = blocks.file_source(gr.sizeof_gr_complex, "usrp_chan3.dat", True) self.connect(self.logfile0, (self.parser, 0)) self.connect(self.logfile1, (self.parser, 1)) self.connect(self.logfile2, (self.parser, 2)) self.connect(self.logfile3, (self.parser, 3)) else: self.connect((self.source, 0), (self.parser, 0)) self.connect((self.source, 1), (self.parser, 1)) self.connect((self.source2, 0), (self.parser, 2)) self.connect((self.source2, 1), (self.parser, 3)) ##The rest of the harmonia flowgraph self.prf_est = fast_square.prf_estimator(1024, True, [], False, 1, "prf_est") self.connect((self.parser, 0), (self.prf_est, 0)) self.connect((self.parser, 1), (self.prf_est, 1)) self.connect((self.parser, 2), (self.prf_est, 2)) self.connect((self.parser, 3), (self.prf_est, 3)) self.h_extract = fast_square.harmonic_extractor( 1024, 1, "prf_est", "phasor_calc", "harmonic_freqs") self.connect((self.prf_est, 0), (self.h_extract, 0)) self.connect((self.prf_est, 1), (self.h_extract, 1)) self.connect((self.prf_est, 2), (self.h_extract, 2)) self.connect((self.prf_est, 3), (self.h_extract, 3)) self.h_locate = fast_square.harmonic_localizer( "phasor_calc", "harmonic_freqs", "prf_est", "Sek5SXpFPa", 1) self.connect((self.h_extract, 0), (self.h_locate, 0)) self.connect((self.h_extract, 1), (self.h_locate, 1)) self.connect((self.h_extract, 2), (self.h_locate, 2)) self.connect((self.h_extract, 3), (self.h_locate, 3)) #TODO: Put this back in once we want to push to gatd # self.socket_pdu = blocks.socket_pdu("UDP_CLIENT", "inductor.eecs.umich.edu", "4001", 10000) # self.msg_connect(self.h_locate, "frame_out", self.socket_pdu, "pdus") ##WebSocket output for connection to remote visualization interface self.ws_port = sdrp.ws_sink_c(True, 18000, "FLOAT", "") self.msg_connect(self.h_locate, "frame_out", self.ws_port, "ws_pdu_in")
def __init__(self, antenna='RX2', args='', fft_size=1024, freq=466.05e6, gain=20, samp_rate=1e6, spec='', stream_args='', update_rate=.1, wire_format=''): gr.top_block.__init__(self, "UHD FFT") Qt.QWidget.__init__(self) self.setWindowTitle("UHD FFT") qtgui.util.check_set_qss() 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", "uhd_fft") self.restoreGeometry( self.settings.value("geometry", type=QtCore.QByteArray)) ################################################## # Parameters ################################################## self.antenna = antenna self.args = args self.fft_size = fft_size self.freq = freq self.gain = gain self.samp_rate = samp_rate self.spec = spec self.stream_args = stream_args self.update_rate = update_rate self.wire_format = wire_format ################################################## # Variables ################################################## self.freq_c = freq_c = freq self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value( "", False, "") self.usrp_device_info = usrp_device_info = uhd.get_version_string() self.uhd_version_info = uhd_version_info = uhd.get_version_string() self.samp_rate_ = samp_rate_ = samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain_ = gain_ = gain self.current_freq_c = current_freq_c = freq_c self.ant = ant = antenna ################################################## # Blocks ################################################## self._samp_rate__tool_bar = Qt.QToolBar(self) self._samp_rate__tool_bar.addWidget(Qt.QLabel('Sampling Rate' + ": ")) self._samp_rate__line_edit = Qt.QLineEdit(str(self.samp_rate_)) self._samp_rate__tool_bar.addWidget(self._samp_rate__line_edit) self._samp_rate__line_edit.returnPressed.connect( lambda: self.set_samp_rate_( eng_notation.str_to_num( str(self._samp_rate__line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._samp_rate__tool_bar, 3, 2, 1, 2) for r in range(3, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 4): self.top_grid_layout.setColumnStretch(c, 1) self._gain__range = Range(0, 31.5, .5, gain, 200) self._gain__win = RangeWidget(self._gain__range, self.set_gain_, 'RX Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._gain__win, 2, 0, 1, 4) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self._freq_c_tool_bar = Qt.QToolBar(self) self._freq_c_tool_bar.addWidget(Qt.QLabel('RX Tune Frequency' + ": ")) self._freq_c_line_edit = Qt.QLineEdit(str(self.freq_c)) self._freq_c_tool_bar.addWidget(self._freq_c_line_edit) self._freq_c_line_edit.returnPressed.connect(lambda: self.set_freq_c( eng_notation.str_to_num( str(self._freq_c_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._freq_c_tool_bar, 3, 0, 1, 2) for r in range(3, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join((args, "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate_) self.uhd_usrp_source_0.set_center_freq(float(freq_c), 0) self.uhd_usrp_source_0.set_gain(gain_, 0) self.uhd_usrp_source_0.set_antenna('TX/RX', 0) self.uhd_usrp_source_0.set_bandwidth(samp_rate, 0) self.uhd_usrp_source_0.set_auto_dc_offset("", 0) self.uhd_usrp_source_0.set_auto_iq_balance("", 0) self.display = Qt.QTabWidget() self.display_widget_0 = Qt.QWidget() self.display_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.display_widget_0) self.display_grid_layout_0 = Qt.QGridLayout() self.display_layout_0.addLayout(self.display_grid_layout_0) self.display.addTab(self.display_widget_0, 'Spectrum') self.display_widget_1 = Qt.QWidget() self.display_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.display_widget_1) self.display_grid_layout_1 = Qt.QGridLayout() self.display_layout_1.addLayout(self.display_grid_layout_1) self.display.addTab(self.display_widget_1, 'Waterfall') self.display_widget_2 = Qt.QWidget() self.display_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.display_widget_2) self.display_grid_layout_2 = Qt.QGridLayout() self.display_layout_2.addLayout(self.display_grid_layout_2) self.display.addTab(self.display_widget_2, 'Scope') self.top_grid_layout.addWidget(self.display, 0, 0, 1, 4) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self._usrp_device_info_tool_bar = Qt.QToolBar(self) if None: self._usrp_device_info_formatter = None else: self._usrp_device_info_formatter = lambda x: repr(x) self._usrp_device_info_tool_bar.addWidget( Qt.QLabel('Device Information' + ": ")) self._usrp_device_info_label = Qt.QLabel( str(self._usrp_device_info_formatter(self.usrp_device_info))) self._usrp_device_info_tool_bar.addWidget(self._usrp_device_info_label) self.top_grid_layout.addWidget(self._usrp_device_info_tool_bar, 1, 2, 1, 2) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 4): self.top_grid_layout.setColumnStretch(c, 1) self._uhd_version_info_tool_bar = Qt.QToolBar(self) if None: self._uhd_version_info_formatter = None else: self._uhd_version_info_formatter = lambda x: str(x) self._uhd_version_info_tool_bar.addWidget( Qt.QLabel('UHD Version' + ": ")) self._uhd_version_info_label = Qt.QLabel( str(self._uhd_version_info_formatter(self.uhd_version_info))) self._uhd_version_info_tool_bar.addWidget(self._uhd_version_info_label) self.top_grid_layout.addWidget(self._uhd_version_info_tool_bar, 1, 0, 1, 2) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype freq, #fc samp_rate_, #bw '', #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(update_rate) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.display_grid_layout_1.addWidget( self._qtgui_waterfall_sink_x_0_win, 0, 0, 1, 4) for r in range(0, 1): self.display_grid_layout_1.setRowStretch(r, 1) for c in range(0, 4): self.display_grid_layout_1.setColumnStretch(c, 1) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 1024, #size samp_rate_, #samp_rate '', #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(update_rate) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") 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.enable_autoscale(True) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(True) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not False: self.qtgui_time_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "blue" ] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.display_grid_layout_2.addWidget(self._qtgui_time_sink_x_0_win, 0, 0, 1, 4) for r in range(0, 1): self.display_grid_layout_2.setRowStretch(r, 1) for c in range(0, 4): self.display_grid_layout_2.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( fft_size, #size firdes.WIN_BLACKMAN_hARRIS, #wintype freq, #fc samp_rate_, #bw '', #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(update_rate) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(0.1) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(True) if not False: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.display_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 0, 0, 1, 4) for r in range(0, 1): self.display_grid_layout_0.setRowStretch(r, 1) for c in range(0, 4): self.display_grid_layout_0.setColumnStretch(c, 1) self.low_pass_filter_0 = filter.fir_filter_ccf( 25, firdes.low_pass(1, samp_rate, 7500, 5000, firdes.WIN_HAMMING, 6.76)) self._lo_locked_probe_tool_bar = Qt.QToolBar(self) if None: self._lo_locked_probe_formatter = None else: self._lo_locked_probe_formatter = lambda x: str(x) self._lo_locked_probe_tool_bar.addWidget(Qt.QLabel('LO locked' + ": ")) self._lo_locked_probe_label = Qt.QLabel( str(self._lo_locked_probe_formatter(self.lo_locked_probe))) self._lo_locked_probe_tool_bar.addWidget(self._lo_locked_probe_label) self.top_grid_layout.addWidget(self._lo_locked_probe_tool_bar, 4, 0, 1, 2) for r in range(4, 5): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) def _current_freq_c_probe(): while True: val = self.uhd_usrp_source_0.get_sensor('lo_locked') try: self.set_current_freq_c(val) except AttributeError: pass time.sleep(1.0 / (10)) _current_freq_c_thread = threading.Thread(target=_current_freq_c_probe) _current_freq_c_thread.daemon = True _current_freq_c_thread.start() def _chan0_lo_locked_probe(): while True: val = self.uhd_usrp_source_0.get_sensor('lo_locked') try: self.set_chan0_lo_locked(val) except AttributeError: pass time.sleep(1.0 / (10)) _chan0_lo_locked_thread = threading.Thread( target=_chan0_lo_locked_probe) _chan0_lo_locked_thread.daemon = True _chan0_lo_locked_thread.start() self.audio_sink_0 = audio.sink(48000, '', True) self._ant_options = ( 'RX2', 'TX/RX', 'J1', 'J2', ) self._ant_labels = ( 'RX2', 'TX/RX', 'J1', 'J2', ) self._ant_tool_bar = Qt.QToolBar(self) self._ant_tool_bar.addWidget(Qt.QLabel('Antenna' + ": ")) self._ant_combo_box = Qt.QComboBox() self._ant_tool_bar.addWidget(self._ant_combo_box) for label in self._ant_labels: self._ant_combo_box.addItem(label) self._ant_callback = lambda i: Qt.QMetaObject.invokeMethod( self._ant_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._ant_options.index(i))) self._ant_callback(self.ant) self._ant_combo_box.currentIndexChanged.connect( lambda i: self.set_ant(self._ant_options[i])) self.top_grid_layout.addWidget(self._ant_tool_bar, 4, 2, 1, 2) for r in range(4, 5): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 4): self.top_grid_layout.setColumnStretch(c, 1) self.analog_nbfm_rx_0 = analog.nbfm_rx( audio_rate=32000, quad_rate=32000, tau=75e-6, max_dev=5e3, ) ################################################## # Connections ################################################## self.msg_connect((self.qtgui_freq_sink_x_0, 'freq'), (self.qtgui_freq_sink_x_0, 'freq')) self.msg_connect((self.qtgui_freq_sink_x_0, 'freq'), (self.uhd_usrp_source_0, 'command')) self.connect((self.analog_nbfm_rx_0, 0), (self.audio_sink_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_nbfm_rx_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
def __init__(self, options, param_samp_rate, param_freq, param_gain, address): grc_wxgui.top_block_gui.__init__(self, title="UHD FFT") ################################################## # Parameters ################################################## self.param_samp_rate = param_samp_rate self.param_freq = param_freq self.param_gain = param_gain self.address = address ################################################## # Variables ################################################## self.chan0_lo_locked = chan0_lo_locked = uhd.sensor_value( "", False, "") self.samp_rate = samp_rate = param_samp_rate self.lo_locked_probe = lo_locked_probe = chan0_lo_locked.to_bool() self.gain = gain = param_gain self.freq = freq = param_freq self.ant = ant = "J1" ################################################## # Blocks ################################################## self._samp_rate_text_box = forms.text_box( parent=self.GetWin(), value=self.samp_rate, callback=self.set_samp_rate, label="Sample Rate", converter=forms.float_converter(), ) self.GridAdd(self._samp_rate_text_box, 1, 0, 1, 3) _gain_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, label="RX Gain", converter=forms.float_converter(), proportion=0, ) self._gain_slider = forms.slider( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, minimum=0, maximum=112.5, num_steps=225, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 2, 0, 1, 8) _freq_sizer = wx.BoxSizer(wx.VERTICAL) self._freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, label="RX Tune Frequency", converter=forms.float_converter(), proportion=0, ) self._freq_slider = forms.slider( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, minimum=50e6, maximum=6e9, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_freq_sizer, 3, 0, 1, 8) self._ant_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.ant, callback=self.set_ant, label="Antenna", choices=["J1", "J2"], labels=["J1", "J2"], style=wx.RA_HORIZONTAL, ) self.GridAdd(self._ant_chooser, 1, 4, 1, 2) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_subdev_spec("A:0", 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(gain, 0) self.uhd_usrp_source_0.set_antenna(ant, 0) self.uhd_usrp_source_0.set_bandwidth(samp_rate, 0) if options.tofile == True: self.logfile0 = blocks.file_sink(gr.sizeof_gr_complex, "usrp_fft_iq.dat") self.connect(self.uhd_usrp_source_0, self.logfile0) g = self.uhd_usrp_source_0.get_gain_range() print "rx gain range is (%f,%f)" % (g.start(), g.stop()) self.nb0 = self.nb0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "FFT") self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Waterfall") self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Scope") self.GridAdd(self.nb0, 0, 0, 1, 8) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.nb0.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", size=((-1, 400)), ) self.nb0.GetPage(1).Add(self.wxgui_waterfallsink2_0.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.nb0.GetPage(2).GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb0.GetPage(2).Add(self.wxgui_scopesink2_0.win) self._lo_locked_probe_static_text = forms.static_text( parent=self.GetWin(), value=self.lo_locked_probe, callback=self.set_lo_locked_probe, label="LO Locked", converter=forms.str_converter( formatter=lambda x: x and "True" or "False"), ) self.GridAdd(self._lo_locked_probe_static_text, 1, 7, 1, 1) self.fft = fftsink2.fft_sink_c( self.nb0.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=15, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, size=((-1, 400)), ) self.nb0.GetPage(0).Add(self.fft.win) def _chan0_lo_locked_probe(): while True: val = self.uhd_usrp_source_0.get_sensor('lo_locked') try: self.set_chan0_lo_locked(val) except AttributeError, e: pass time.sleep(1.0 / (10))