def test_001_ff(self): N = 10000 # number of samples to use fs = 1000 # baseband sampling rate rrate = 1.123 # resampling rate freq = 10 data = sig_source_f(fs, freq, 1, N) signal = blocks.vector_source_f(data) op = filter.fractional_interpolator_ff(0, rrate) snk = blocks.vector_sink_f() self.tb.connect(signal, op, snk) self.tb.run() Ntest = 5000 L = len(snk.data()) t = map(lambda x: float(x) / (fs / rrate), xrange(L)) phase = 0.1884 expected_data = map( lambda x: math.sin(2. * math.pi * freq * x + phase), t) dst_data = snk.data() self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
def __init__(self): gr.hier_block2.__init__(self, "transmitter_amssb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.rate = 44.1e3 / 200e3 self.interp = filter.fractional_interpolator_ff(0.0, self.rate) self.mul = blocks.multiply_const_ff(1.0) self.add = blocks.add_const_ff(1.0) self.src = analog.sig_source_f(200e3, analog.GR_SIN_WAVE, 0e3, 1.0) self.mod = blocks.multiply_ff() self.filt = filter.hilbert_fc(401) self.connect(self, self.interp, self.mul, self.add, self.mod, self.filt, self) self.connect(self.src, (self.mod, 1))
def __init__(self): gr.hier_block2.__init__(self, "transmitter_am", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.rate = 44.1e3/200e3 #self.rate = 200e3/44.1e3 self.interp = filter.fractional_interpolator_ff(0.0, self.rate) self.cnv = blocks.float_to_complex() self.mul = blocks.multiply_const_cc(1.0) self.add = blocks.add_const_cc(1.0) self.src = analog.sig_source_c(200e3, analog.GR_SIN_WAVE, 0e3, 1.0) #self.src = analog.sig_source_c(200e3, analog.GR_SIN_WAVE, 50e3, 1.0) self.mod = blocks.multiply_cc() self.connect( self, self.interp, self.cnv, self.mul, self.add, self.mod, self ) self.connect( self.src, (self.mod,1) )
def __init__(self): gr.hier_block2.__init__(self, "transmitter_amssb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.rate = 44.1e3/200e3 #self.rate = 200e3/44.1e3 self.interp = filter.fractional_interpolator_ff(0.0, self.rate) # self.cnv = blocks.float_to_complex() self.mul = blocks.multiply_const_ff(1.0) self.add = blocks.add_const_ff(1.0) self.src = analog.sig_source_f(200e3, analog.GR_SIN_WAVE, 0e3, 1.0) #self.src = analog.sig_source_c(200e3, analog.GR_SIN_WAVE, 50e3, 1.0) self.mod = blocks.multiply_ff() #self.filt = filter.fir_filter_ccf(1, firdes.band_pass(1.0, 200e3, 10e3, 60e3, 0.25e3, firdes.WIN_HAMMING, 6.76)) self.filt = filter.hilbert_fc(401) self.connect( self, self.interp, self.mul, self.add, self.mod, self.filt, self ) self.connect( self.src, (self.mod,1) )
def test_001_ff(self): N = 10000 # number of samples to use fs = 1000 # baseband sampling rate rrate = 1.123 # resampling rate freq = 10 data = sig_source_f(fs, freq, 1, N) signal = blocks.vector_source_f(data) op = filter.fractional_interpolator_ff(0, rrate) snk = blocks.vector_sink_f() self.tb.connect(signal, op, snk) self.tb.run() Ntest = 5000 L = len(snk.data()) t = map(lambda x: float(x)/(fs/rrate), xrange(L)) phase = 0.1884 expected_data = map(lambda x: math.sin(2.*math.pi*freq*x+phase), t) dst_data = snk.data() self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="fmReceiver2") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rep = samp_rep = 44.1e3 self.samp_rate = samp_rate = 2e6 self.freq = freq = 99.3e6 ################################################## # Blocks ################################################## _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="freq", 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=87e6, maximum=108e6, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_freq_sizer) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_f( self.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", ) self.Add(self.wxgui_waterfallsink2_0.win) self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(freq, 0) self.rtlsdr_source_0.set_freq_corr(0, 0) self.rtlsdr_source_0.set_dc_offset_mode(0, 0) self.rtlsdr_source_0.set_iq_balance_mode(0, 0) self.rtlsdr_source_0.set_gain_mode(0, 0) self.rtlsdr_source_0.set_gain(10, 0) self.rtlsdr_source_0.set_if_gain(20, 0) self.rtlsdr_source_0.set_bb_gain(20, 0) self.rtlsdr_source_0.set_antenna("", 0) self.rtlsdr_source_0.set_bandwidth(0, 0) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 75e3, 150e3, firdes.WIN_HAMMING, 6.76)) self.fractional_interpolator_xx_1 = filter.fractional_interpolator_ff(0, 4) self.fractional_interpolator_xx_0 = filter.fractional_interpolator_cc(0, 3.968) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((4, )) self.audio_sink_0 = audio.sink(44100, "", True) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=5e5, audio_decimation=4, ) self.analog_fm_deemph_0 = analog.fm_deemph(fs=samp_rep, tau=50e-6) ################################################## # Connections ################################################## self.connect((self.rtlsdr_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.fractional_interpolator_xx_0, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.fractional_interpolator_xx_1, 0)) self.connect((self.fractional_interpolator_xx_1, 0), (self.analog_fm_deemph_0, 0)) self.connect((self.analog_fm_deemph_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.wxgui_waterfallsink2_0, 0))
def __init__(self, freq=93.4e6, inputfile='jen_ai_marre.wav', ppm=0): grc_wxgui.top_block_gui.__init__(self, title="Wbfm Tx Hackrf") _icon_path = "C:\Program Files\GNURadio-3.7\share\icons\hicolor\scalable/apps\gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq = freq self.inputfile = inputfile self.ppm = ppm ################################################## # Blocks ################################################## self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=2e6, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title='FFT Plot', peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=8, decimation=1, taps=None, fractional_bw=None, ) self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + '') self.osmosdr_sink_0.set_sample_rate(8e6) self.osmosdr_sink_0.set_center_freq(freq, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(14, 0) self.osmosdr_sink_0.set_if_gain(40, 0) self.osmosdr_sink_0.set_bb_gain(20, 0) self.osmosdr_sink_0.set_antenna('', 0) self.osmosdr_sink_0.set_bandwidth(250e3, 0) self.fractional_interpolator_xx_0 = filter.fractional_interpolator_ff( 1, 875e-3) self.audio_source_0 = audio.source(48000, '', True) self.analog_wfm_tx_0 = analog.wfm_tx( audio_rate=32000, quad_rate=320000, tau=300e-6, max_dev=75e3, fh=-1.0, ) ################################################## # Connections ################################################## self.connect((self.analog_wfm_tx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.audio_source_0, 0), (self.fractional_interpolator_xx_0, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.analog_wfm_tx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.wxgui_fftsink2_0, 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.samp_rate = samp_rate = 32000 self.pam4_constellation = pam4_constellation = digital.constellation_calcdist( ([0, 1, 3, 2]), ([0, 1, 3, 2]), 4, 1).base() self.noiseamp = noiseamp = (10**(-0.9) + 10) / 2 self.noise_enable = noise_enable = 0 self.mod_select = mod_select = 1 self.ebw_range = ebw_range = 0.35 self.a_src_freq = a_src_freq = 200e3 ################################################## # Blocks ################################################## self._noiseamp_range = Range(10**(-0.9), 10, 0.001, (10**(-0.9) + 10) / 2, 200) self._noiseamp_win = RangeWidget(self._noiseamp_range, self.set_noiseamp, "Noise Amplitude", "counter_slider", float) self.top_grid_layout.addWidget(self._noiseamp_win, 0, 2) _noise_enable_check_box = Qt.QCheckBox("Noise Enable") self._noise_enable_choices = {True: 1, False: 0} self._noise_enable_choices_inv = dict( (v, k) for k, v in self._noise_enable_choices.iteritems()) self._noise_enable_callback = lambda i: Qt.QMetaObject.invokeMethod( _noise_enable_check_box, "setChecked", Qt.Q_ARG("bool", self._noise_enable_choices_inv[i])) self._noise_enable_callback(self.noise_enable) _noise_enable_check_box.stateChanged.connect( lambda i: self.set_noise_enable(self._noise_enable_choices[bool(i)] )) self.top_grid_layout.addWidget(_noise_enable_check_box, 0, 1) self._mod_select_options = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] self._mod_select_labels = [ "BPSK", "QPSK", "8PSK", "QAM16", "QAM64", "PAM4", "GFSK", "CPFSK", "WBFM", "AM-DSB", "AM-SSB" ] self._mod_select_tool_bar = Qt.QToolBar(self) self._mod_select_tool_bar.addWidget(Qt.QLabel("mod_select" + ": ")) self._mod_select_combo_box = Qt.QComboBox() self._mod_select_tool_bar.addWidget(self._mod_select_combo_box) for label in self._mod_select_labels: self._mod_select_combo_box.addItem(label) self._mod_select_callback = lambda i: Qt.QMetaObject.invokeMethod( self._mod_select_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._mod_select_options.index(i))) self._mod_select_callback(self.mod_select) self._mod_select_combo_box.currentIndexChanged.connect( lambda i: self.set_mod_select(self._mod_select_options[i])) self.top_grid_layout.addWidget(self._mod_select_tool_bar, 0, 0) self._a_src_freq_range = Range(44100, 200e3, 10, 200e3, 200) self._a_src_freq_win = RangeWidget(self._a_src_freq_range, self.set_a_src_freq, "Analog Source Frequency", "counter_slider", float) self.top_layout.addWidget(self._a_src_freq_win) self.uhd_usrp_sink_0 = uhd.usrp_sink( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0.set_center_freq(0, 0) self.uhd_usrp_sink_0.set_gain(0, 0) self.sig_source_0 = analog.sig_source_f(samp_rate, analog.GR_TRI_WAVE, 44100, 1, 0) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 2048, #size samp_rate, #samp_rate "Times Series", #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(-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(True) self.qtgui_time_sink_x_0.enable_control_panel(False) if not True: 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 * 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.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 1, 2) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "Frequency Spectrum", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) 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(True) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: 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.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 2, 0, 1, 3) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 2048, #size "Constellation", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0.enable_autoscale(True) self.qtgui_const_sink_x_0.enable_grid(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [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_const_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win, 1, 0, 1, 2) self.hilbert_fc_0 = filter.hilbert_fc(401, firdes.WIN_HAMMING, 6.76) self.fractional_interpolator_xx_0 = filter.fractional_interpolator_ff( 0, 44100 / a_src_freq) self.digital_qam_mod_0_1 = digital.qam.qam_mod( constellation_points=64, mod_code="gray", differential=True, samples_per_symbol=8, excess_bw=ebw_range, verbose=False, log=False, ) self.digital_qam_mod_0_0 = digital.qam.qam_mod( constellation_points=16, mod_code="gray", differential=True, samples_per_symbol=8, excess_bw=ebw_range, verbose=False, log=False, ) self.digital_psk_mod_1 = digital.psk.psk_mod( constellation_points=8, mod_code="gray", differential=True, samples_per_symbol=8, excess_bw=ebw_range, verbose=False, log=False, ) self.digital_psk_mod_0_0 = digital.psk.psk_mod( constellation_points=2, mod_code="gray", differential=True, samples_per_symbol=8, excess_bw=ebw_range, verbose=False, log=False, ) self.digital_psk_mod_0 = digital.psk.psk_mod( constellation_points=4, mod_code="gray", differential=True, samples_per_symbol=8, excess_bw=ebw_range, verbose=False, log=False, ) self.digital_gfsk_mod_0 = digital.gfsk_mod( samples_per_symbol=8, sensitivity=0.1, bt=ebw_range, verbose=False, log=False, ) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=pam4_constellation, differential=True, samples_per_symbol=8, pre_diff_code=True, excess_bw=ebw_range, verbose=False, log=False, ) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.blocks_packed_to_unpacked_xx_1 = blocks.packed_to_unpacked_bb( 1, gr.GR_MSB_FIRST) self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb( 1, gr.GR_LSB_FIRST) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_vff((0.1, )) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((0.1, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc( (1 + 1j, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blocks_add_const_vxx_0_0 = blocks.add_const_vff((1, )) self.blocks_add_const_vxx_0 = blocks.add_const_vcc((1, )) self.blks2_selector_1 = grc_blks2.selector( item_size=gr.sizeof_gr_complex * 1, num_inputs=2, num_outputs=1, input_index=noise_enable, output_index=0, ) self.blks2_selector_0 = grc_blks2.selector( item_size=gr.sizeof_gr_complex * 1, num_inputs=11, num_outputs=1, input_index=mod_select, output_index=0, ) self.analog_wfm_tx_0 = analog.wfm_tx( audio_rate=44100, quad_rate=220500, tau=75e-6, max_dev=75e3, ) self.analog_sig_source_x_0_0 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, a_src_freq, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, a_src_freq, 1, 0) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, 64, 8192)), True) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, noiseamp, 31415) self.analog_cpfsk_bc_0 = analog.cpfsk_bc(0.5, 1.0, 8) self.analog_const_source_x_1 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_const_source_x_0 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blks2_selector_1, 0)) self.connect((self.analog_const_source_x_1, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.analog_cpfsk_bc_0, 0), (self.blks2_selector_0, 7)) self.connect((self.analog_noise_source_x_0, 0), (self.blks2_selector_1, 1)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_packed_to_unpacked_xx_1, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.analog_wfm_tx_0, 0), (self.blks2_selector_0, 8)) self.connect((self.blks2_selector_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blks2_selector_1, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_add_const_vxx_0_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blks2_selector_0, 1)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.blocks_add_const_vxx_0_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blks2_selector_0, 9)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.hilbert_fc_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.analog_cpfsk_bc_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_psk_mod_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_psk_mod_0_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_psk_mod_1, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_qam_mod_0_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_qam_mod_0_1, 0)) self.connect((self.blocks_packed_to_unpacked_xx_1, 0), (self.digital_gfsk_mod_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.blks2_selector_0, 5)) self.connect((self.digital_gfsk_mod_0, 0), (self.blks2_selector_0, 6)) self.connect((self.digital_psk_mod_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.digital_psk_mod_0_0, 0), (self.blks2_selector_0, 0)) self.connect((self.digital_psk_mod_1, 0), (self.blks2_selector_0, 2)) self.connect((self.digital_qam_mod_0_0, 0), (self.blks2_selector_0, 3)) self.connect((self.digital_qam_mod_0_1, 0), (self.blks2_selector_0, 4)) self.connect((self.fractional_interpolator_xx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.blocks_multiply_const_vxx_1_0, 0)) self.connect((self.hilbert_fc_0, 0), (self.blks2_selector_0, 10)) self.connect((self.sig_source_0, 0), (self.analog_wfm_tx_0, 0)) self.connect((self.sig_source_0, 0), (self.fractional_interpolator_xx_0, 0))
def __init__(self): gr.top_block.__init__(self, "rx APT") Qt.QWidget.__init__(self) self.setWindowTitle("rx APT") 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", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.path_to_save_dir = path_to_save_dir = os.path.expanduser( "~/Desktop") self.samp_rate = samp_rate = 2205000 self.rf_gain = rf_gain = 20 self.if_gain = if_gain = 40 self.freq = freq = 137.62e6 self.file_path = file_path = path_to_save_dir + "/APT_" + datetime.now( ).strftime("%d%m%Y_%H%M") ################################################## # Blocks ################################################## self._rf_gain_range = Range(0, 45, 5, 20, 200) self._rf_gain_win = RangeWidget(self._rf_gain_range, self.set_rf_gain, 'RF Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._rf_gain_win) self._if_gain_range = Range(1, 80, 5, 40, 200) self._if_gain_win = RangeWidget(self._if_gain_range, self.set_if_gain, 'IF Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._if_gain_win) self._freq_options = ( 137.62e6, 137.9125e6, 137.1e6, 99.8e6, ) self._freq_labels = ( 'NOAA-15 (137.62MHz)', 'NOAA-18 (137.9125MHz)', 'NOAA-19 (137.1MHz)', 'Test FM', ) self._freq_tool_bar = Qt.QToolBar(self) self._freq_tool_bar.addWidget(Qt.QLabel('Frequency' + ": ")) self._freq_combo_box = Qt.QComboBox() self._freq_tool_bar.addWidget(self._freq_combo_box) for label in self._freq_labels: self._freq_combo_box.addItem(label) self._freq_callback = lambda i: Qt.QMetaObject.invokeMethod( self._freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._freq_options.index(i))) self._freq_callback(self.freq) self._freq_combo_box.currentIndexChanged.connect( lambda i: self.set_freq(self._freq_options[i])) self.top_grid_layout.addWidget(self._freq_tool_bar) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", "")), 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(freq, 0) self.uhd_usrp_source_0.set_gain(rf_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(True, 0) self.uhd_usrp_source_0.set_auto_iq_balance(True, 0) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=samp_rate / 44100, taps=None, fractional_bw=None, ) self.qtgui_sink_x_0 = qtgui.sink_c( 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_grid_layout.addWidget(self._qtgui_sink_x_0_win) self.qtgui_sink_x_0.enable_rf_freq(False) self.low_pass_filter_1 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 40000, 4100, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_fff( 1, firdes.low_pass(5, 11025, 2400, 100, firdes.WIN_HAMMING, 6.76)) self.fractional_interpolator_xx_0_0 = filter.fractional_interpolator_ff( 0, 4.8 / 4.16) self.fractional_interpolator_xx_0 = filter.fractional_interpolator_ff( 0, 1.1484375) self.blocks_wavfile_sink_1 = blocks.wavfile_sink( file_path + "_rawIQ.wav", 2, samp_rate, 8) self.blocks_wavfile_sink_0_0 = blocks.wavfile_sink( file_path + ".wav", 1, 4160, 8) self.blocks_wavfile_sink_0 = blocks.wavfile_sink( file_path + ".wav", 1, 11025, 8) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc( (if_gain, )) self.blocks_float_to_uchar_0 = blocks.float_to_uchar() self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1, file_path + ".dat", False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_deinterleave_0 = blocks.deinterleave( gr.sizeof_float * 1, 1) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.audio_sink_0 = audio.sink(44100, '', False) self.analog_rail_ff_0 = analog.rail_ff(0, 1) self.analog_fm_demod_cf_0_0 = analog.fm_demod_cf( channel_rate=44100, audio_decim=1, deviation=75000, audio_pass=18000, audio_stop=20000, gain=1.0, tau=75e-6, ) self.analog_fm_demod_cf_0 = analog.fm_demod_cf( channel_rate=44100, audio_decim=4, deviation=75000, audio_pass=15000, audio_stop=16000, gain=1.0, tau=75e-6, ) self.analog_const_source_x_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 255) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_fm_demod_cf_0, 0), (self.blocks_wavfile_sink_0, 0)) self.connect((self.analog_fm_demod_cf_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.analog_fm_demod_cf_0_0, 0), (self.audio_sink_0, 0)) self.connect((self.analog_rail_ff_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_wavfile_sink_1, 1)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_wavfile_sink_1, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.fractional_interpolator_xx_0_0, 0)) self.connect((self.blocks_deinterleave_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_deinterleave_0, 1), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.blocks_float_to_uchar_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_float_to_uchar_0, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.blocks_deinterleave_0, 0)) self.connect((self.fractional_interpolator_xx_0_0, 0), (self.analog_rail_ff_0, 0)) self.connect((self.fractional_interpolator_xx_0_0, 0), (self.blocks_wavfile_sink_0_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.fractional_interpolator_xx_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_fm_demod_cf_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_fm_demod_cf_0_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_multiply_const_vxx_0, 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.samp_rate = samp_rate = 25000 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc( interpolation=8, decimation=1, taps=None, fractional_bw=None, ) self.qtgui_time_sink_x_3_0 = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate "after_interpolator", #name 1 #number of inputs ) self.qtgui_time_sink_x_3_0.set_update_time(0.10) self.qtgui_time_sink_x_3_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_3_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_3_0.enable_tags(-1, True) self.qtgui_time_sink_x_3_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_3_0.enable_autoscale(False) self.qtgui_time_sink_x_3_0.enable_grid(False) self.qtgui_time_sink_x_3_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_3_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(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_3_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_3_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_3_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_3_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_3_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_3_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_3_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_3_0_win = sip.wrapinstance(self.qtgui_time_sink_x_3_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_3_0_win) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_c( 500, #size samp_rate, #samp_rate "after_FM", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(True) self.qtgui_time_sink_x_0_0.enable_grid(False) self.qtgui_time_sink_x_0_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_0_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*1): if len(labels[i]) == 0: if(i % 2 == 0): self.qtgui_time_sink_x_0_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_0_win) self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + "" ) self.osmosdr_sink_0.set_sample_rate(1e6) self.osmosdr_sink_0.set_center_freq(1000e6, 0) self.osmosdr_sink_0.set_freq_corr(6, 0) self.osmosdr_sink_0.set_gain(0, 0) self.osmosdr_sink_0.set_if_gain(40, 0) self.osmosdr_sink_0.set_bb_gain(30, 0) self.osmosdr_sink_0.set_antenna("", 0) self.osmosdr_sink_0.set_bandwidth(250e3, 0) self.fractional_interpolator_xx_0 = filter.fractional_interpolator_ff(1, 0.875) self.file_input = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate "file_input", #name 1 #number of inputs ) self.file_input.set_update_time(0.10) self.file_input.set_y_axis(-1, 1) self.file_input.set_y_label("Amplitude", "") self.file_input.enable_tags(-1, True) self.file_input.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.file_input.enable_autoscale(False) self.file_input.enable_grid(False) self.file_input.enable_control_panel(False) if not True: self.file_input.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(1): if len(labels[i]) == 0: self.file_input.set_line_label(i, "Data {0}".format(i)) else: self.file_input.set_line_label(i, labels[i]) self.file_input.set_line_width(i, widths[i]) self.file_input.set_line_color(i, colors[i]) self.file_input.set_line_style(i, styles[i]) self.file_input.set_line_marker(i, markers[i]) self.file_input.set_line_alpha(i, alphas[i]) self._file_input_win = sip.wrapinstance(self.file_input.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._file_input_win) self.blocks_vector_source_x_0 = blocks.vector_source_f((0, 0, 0), True, 1, []) self.blocks_stream_mux_0 = blocks.stream_mux(gr.sizeof_float*1, (1, 1)) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_float*1, 10) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/andy/code.txt", True) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-0.5, )) self.bipolar_wave = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate "bipolar_wave", #name 1 #number of inputs ) self.bipolar_wave.set_update_time(0.10) self.bipolar_wave.set_y_axis(-1, 1) self.bipolar_wave.set_y_label("Amplitude", "") self.bipolar_wave.enable_tags(-1, True) self.bipolar_wave.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.bipolar_wave.enable_autoscale(False) self.bipolar_wave.enable_grid(False) self.bipolar_wave.enable_control_panel(False) if not True: self.bipolar_wave.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(1): if len(labels[i]) == 0: self.bipolar_wave.set_line_label(i, "Data {0}".format(i)) else: self.bipolar_wave.set_line_label(i, labels[i]) self.bipolar_wave.set_line_width(i, widths[i]) self.bipolar_wave.set_line_color(i, colors[i]) self.bipolar_wave.set_line_style(i, styles[i]) self.bipolar_wave.set_line_marker(i, markers[i]) self.bipolar_wave.set_line_alpha(i, alphas[i]) self._bipolar_wave_win = sip.wrapinstance(self.bipolar_wave.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._bipolar_wave_win) self.analog_wfm_tx_0 = analog.wfm_tx( audio_rate=int(25e3), quad_rate=int(500e3), tau=3e-6, max_dev=50e3, ) self.analog_sig_source_x_0_0 = analog.sig_source_f(samp_rate, analog.GR_CONST_WAVE, 1000, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_CONST_WAVE, 1000, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.analog_wfm_tx_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.analog_wfm_tx_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.file_input, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_stream_mux_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.bipolar_wave, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.fractional_interpolator_xx_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_stream_mux_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_stream_mux_0, 1)) self.connect((self.fractional_interpolator_xx_0, 0), (self.analog_wfm_tx_0, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.qtgui_time_sink_x_3_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.osmosdr_sink_0, 0))
def __init__(self): gr.top_block.__init__(self, "Testaudiostreamport") self.freq_wavelength = 8000 ################################################## # Variables ################################################## self.samp_rate = samp_rate = 48000 self.fundamental_wavelength_samples = fundamental_wavelength_samples = 800 self.freq_wavelength = freq_wavelength = 8000 self.myVectorLength = myVectorLength = 32 self.lowpass_cutoff_freq = 4000 self.n_keep = (self.samp_rate/2)/self.lowpass_cutoff_freq # allow the rms post suppression thread to track if changes aren't happening, which suggests a dead flowgraph. self.rmspostsup_nochange_count = 0 ################################################## # Blocks ################################################## self.probe_avg_frequency = blocks.probe_signal_f() if ("getfreq_alpha" in SETTINGS["streamer"]): myGetfreqAlpha = SETTINGS["streamer"]["getfreq_alpha"] else: myGetfreqAlpha = 0.1 self.powerquality_getfreqcpp_0 = powerquality.getfreqcpp(myGetfreqAlpha) self.fractional_interpolator_xx_0_0 = filter.fractional_interpolator_ff(0, 0.1) self.fractional_interpolator_xx_0 = filter.fractional_interpolator_ff(0, 0.1) self.blocks_wavfile_sink_0 = blocks.wavfile_sink('/dev/stdout', 2, samp_rate, 16) self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_float*1, samp_rate*10,True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate*10,True) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((-1, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((-1, )) # self.blocks_getfreq_average_value = blocks.moving_average_ff(1000, 0.001, 40) self.blocks_keep_one_in_n_0_0 = blocks.keep_one_in_n(gr.sizeof_float*1, 10) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float*1, 10) self.blocks_delay_1 = blocks.delay(gr.sizeof_float*1, int(round(freq_wavelength))) self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, int(round(freq_wavelength))) self.blocks_add_xx_1 = blocks.add_vff(1) self.blocks_add_xx_0 = blocks.add_vff(1) # Calculation of RMS power post-suppression (amplitude of harmonics), also will vary based on effectiveness of the muting. rmsPostSuppressionAlpha = SETTINGS["streamer"]["rmsPostSuppressionAlpha"] # TODO: tune this rmsPostSuppressionAverageLength = SETTINGS["streamer"]["rmsPostSuppressionAverageLength"] # TODO: tune this rmsPostSuppressionAverageScale = SETTINGS["streamer"]["rmsPostSuppressionAverageScale"] # TODO: tune this log("TODO: Tune the Post suppression Alpha value for both RMS and average RMS. Or even remove the averaging if possible.") # Channel 1: Define the blocks needed to calculate and probe the average RMS harmonic power self.blocks_rmsPostSuppression_ch1 = blocks.rms_ff(rmsPostSuppressionAlpha) self.blocks_averagePostSuppression_ch1 = blocks.moving_average_ff(rmsPostSuppressionAverageLength,rmsPostSuppressionAverageScale,4000) # TODO: tune this self.probe_rmsPostSuppression_ch1 = blocks.probe_signal_f() # Channel 2: Define the blocks needed to calculate and probe the average RMS harmonic power self.blocks_rmsPostSuppression_ch2 = blocks.rms_ff(rmsPostSuppressionAlpha) self.blocks_averagePostSuppression_ch2 = blocks.moving_average_ff(rmsPostSuppressionAverageLength,rmsPostSuppressionAverageScale,4000) # TODO: tune this self.probe_rmsPostSuppression_ch2 = blocks.probe_signal_f() # channel 1: Connect the RMS harmonic blocks self.connect((self.blocks_rmsPostSuppression_ch1,0),(self.blocks_averagePostSuppression_ch1,0)) self.connect((self.blocks_averagePostSuppression_ch1,0),(self.probe_rmsPostSuppression_ch1,0)) # Channel 2: Connect the RMS harmonic blocks self.connect((self.blocks_rmsPostSuppression_ch2,0),(self.blocks_averagePostSuppression_ch2,0)) self.connect((self.blocks_averagePostSuppression_ch2,0),(self.probe_rmsPostSuppression_ch2,0)) # Connect Channels 1 and 2 to the larger flow. self.connect((self.blocks_keep_one_in_n_0,0),(self.blocks_rmsPostSuppression_ch1,0)) self.connect((self.blocks_keep_one_in_n_0_0,0),(self.blocks_rmsPostSuppression_ch2,0)) # Left channel TCP connection # log("Connecting to " + getConfigValue("pqserver") + ":" + str(getConfigValue("left_channel_tap_port"))) # self.blocks_socket_pdu_left_inputchannel = blocks.socket_pdu( # "TCP_CLIENT", # getConfigValue("pqserver"), # str(getConfigValue("left_channel_tap_port")), # 10000, # this arg is unused because we are client # False) # this arg is unused because we are client # self.blocks_pdu_to_tagged_stream_left = blocks.pdu_to_tagged_stream( # blocks.float_t, # SETTINGS["networking_tap1"]["length_tag_name"]) self.zeromq_sub_source_left = zeromq.sub_source(gr.sizeof_float, 1, SETTINGS["streamer"]["zmq_server_uri_left_channel"], 5000, True, -1) # optimization: if left and right channels are specified as the same source then make a single connection to the source. if SETTINGS["streamer"]["zmq_server_uri_left_channel"] == SETTINGS["streamer"]["zmq_server_uri_right_channel"]: self.zeromq_sub_source_right = self.zeromq_sub_source_left log("Optimization: Only making a single connection to PQ server since left and right streamer channels have same ZMQ URI.") else: # Connection URI/address to server is different for left and right channel so make a second connection for right channel. self.zeromq_sub_source_right = zeromq.sub_source(gr.sizeof_float, 1, SETTINGS["streamer"]["zmq_server_uri_right_channel"], 5000, True, -1) # self.msg_connect((self.blocks_socket_pdu_left_inputchannel,"pdus"),(self.blocks_pdu_to_tagged_stream_left,"pdus")) # # # Right Channel TCP connection # log("Connecting to " + getConfigValue("pqserver") + ":" + str(getConfigValue("right_channel_tap_port"))) # self.blocks_socket_pdu_right_inputchannel = blocks.socket_pdu( # "TCP_CLIENT", # getConfigValue("pqserver"), # str(getConfigValue("right_channel_tap_port")), # 10000, # this arg is unused because we are client # False) # this arg is unused because we are client # self.blocks_pdu_to_tagged_stream_right = blocks.pdu_to_tagged_stream( # blocks.float_t, # SETTINGS["networking_tap1"]["length_tag_name"]) # self.msg_connect((self.blocks_socket_pdu_right_inputchannel, "pdus"), (self.blocks_pdu_to_tagged_stream_right, "pdus")) self.analog_rail_ff_1 = analog.rail_ff(-0.8, 0.8) self.analog_rail_ff_0 = analog.rail_ff(-0.8, 0.8) # myDecay of 1e-2 (0.01) sounds great when input voltage to the Pi is clean (dirty rectifier voltage can introduce periodic bumps and thumbs that mess up AGC). # myDecay of 0.1: pretty quick. Useful for exposing the thumb phenomenon that I'm currently investigating. 1e-2 (0.01) gets drown down due to thump but thump not very audible. # Sensible default myDecay = 1e-2 # Allow overriding in config file. if ("agc_decay_rate" in SETTINGS["streamer"]): myDecay = SETTINGS["streamer"]["agc_decay_rate"] self.analog_agc2_xx_1 = analog.agc2_ff(0.1, myDecay, 0.1, 1.0) self.analog_agc2_xx_1.set_max_gain(65536) self.analog_agc2_xx_0 = analog.agc2_ff(0.1, myDecay, 0.1, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc2_xx_0, 0), (self.analog_rail_ff_0, 0)) self.connect((self.analog_agc2_xx_1, 0), (self.analog_rail_ff_1, 0)) self.connect((self.analog_rail_ff_0, 0), (self.blocks_wavfile_sink_0, 0)) self.connect((self.analog_rail_ff_1, 0), (self.blocks_wavfile_sink_0, 1)) self.connect((self.zeromq_sub_source_left, 0), (self.fractional_interpolator_xx_0, 0)) self.connect((self.zeromq_sub_source_right, 0), (self.fractional_interpolator_xx_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.blocks_keep_one_in_n_0_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_delay_1, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.blocks_keep_one_in_n_0_0, 0), (self.analog_agc2_xx_1, 0)) self.connect((self.powerquality_getfreqcpp_0, 0), (self.probe_avg_frequency, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_xx_1, 1)) self.connect((self.blocks_throttle_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.powerquality_getfreqcpp_0, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.blocks_add_xx_1, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.blocks_delay_1, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.fractional_interpolator_xx_0_0, 0), (self.blocks_throttle_0_0, 0)) # self.connect((self.powerquality_getfreqcpp_0, 0), (self.blocks_getfreq_average_value, 0)) ### Define FFT related blocks LEFT-CHANNEL ONLY FOR NOW. self.fft_vxx_0 = fft.fft_vfc(myVectorLength, True, (window.blackmanharris(myVectorLength)), 1) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_float*1, myVectorLength) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float*1, self.n_keep) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(myVectorLength) self.blocks_throttle = blocks.throttle(gr.sizeof_float * 1, self.samp_rate, True) self.blocks_fft_vector_sink_0 = blocks.vector_sink_f(self.myVectorLength) ### Connect FFT BLOCKS. # Down-sample / decimate the input. We pick up the flowgraph after AGC but before the rail. self.connect((self.analog_agc2_xx_0, 0), (self.blocks_keep_one_in_n_0, 0)) # Convert the stream to a vector in preparation for FFT self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_stream_to_vector_0, 0)) # Perform FFT analysis of the stream. self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) # Send FFT data (phase and magnitude) into a mag^2 block to get strength of each bin self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) # Send the final result (magnitudes in each fft bin) into vector sink. # self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_fft_vector_sink_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_fft_vector_sink_0, 0))
def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") 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", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 25e3 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=8, decimation=1, taps=None, fractional_bw=None, ) self.qtgui_time_sink_x_3 = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate 'before_mod', #name 1 #number of inputs ) self.qtgui_time_sink_x_3.set_update_time(0.10) self.qtgui_time_sink_x_3.set_y_axis(-1, 1) self.qtgui_time_sink_x_3.set_y_label('Amplitude', "") self.qtgui_time_sink_x_3.enable_tags(-1, True) self.qtgui_time_sink_x_3.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_3.enable_autoscale(False) self.qtgui_time_sink_x_3.enable_grid(False) self.qtgui_time_sink_x_3.enable_axis_labels(True) self.qtgui_time_sink_x_3.enable_control_panel(False) if not True: self.qtgui_time_sink_x_3.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(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_3.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_3.set_line_label(i, labels[i]) self.qtgui_time_sink_x_3.set_line_width(i, widths[i]) self.qtgui_time_sink_x_3.set_line_color(i, colors[i]) self.qtgui_time_sink_x_3.set_line_style(i, styles[i]) self.qtgui_time_sink_x_3.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_3.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_3_win = sip.wrapinstance(self.qtgui_time_sink_x_3.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_3_win) self.qtgui_time_sink_x_1 = qtgui.time_sink_c( 500, #size samp_rate, #samp_rate 'after_resampler', #name 1 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.10) self.qtgui_time_sink_x_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1.enable_tags(-1, True) self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1.enable_autoscale(False) self.qtgui_time_sink_x_1.enable_grid(False) self.qtgui_time_sink_x_1.enable_axis_labels(True) self.qtgui_time_sink_x_1.enable_control_panel(False) if not True: self.qtgui_time_sink_x_1.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_1.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_1.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_win = sip.wrapinstance(self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_1_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 500, #size samp_rate, #samp_rate 'after_mod', #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(-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(False) if not True: 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.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + '' ) self.osmosdr_sink_0.set_sample_rate(1e6) self.osmosdr_sink_0.set_center_freq(1000e6, 0) self.osmosdr_sink_0.set_freq_corr(6, 0) self.osmosdr_sink_0.set_gain(0, 0) self.osmosdr_sink_0.set_if_gain(40, 0) self.osmosdr_sink_0.set_bb_gain(30, 0) self.osmosdr_sink_0.set_antenna('', 0) self.osmosdr_sink_0.set_bandwidth(250e3, 0) self.fractional_interpolator_xx_0 = filter.fractional_interpolator_ff(1, 0.875) self.before_interpolator = qtgui.time_sink_f( 500, #size samp_rate, #samp_rate 'before_interpolator', #name 1 #number of inputs ) self.before_interpolator.set_update_time(0.10) self.before_interpolator.set_y_axis(-1, 1) self.before_interpolator.set_y_label('Amplitude', "") self.before_interpolator.enable_tags(-1, True) self.before_interpolator.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.before_interpolator.enable_autoscale(False) self.before_interpolator.enable_grid(False) self.before_interpolator.enable_axis_labels(True) self.before_interpolator.enable_control_panel(False) if not True: self.before_interpolator.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(1): if len(labels[i]) == 0: self.before_interpolator.set_line_label(i, "Data {0}".format(i)) else: self.before_interpolator.set_line_label(i, labels[i]) self.before_interpolator.set_line_width(i, widths[i]) self.before_interpolator.set_line_color(i, colors[i]) self.before_interpolator.set_line_style(i, styles[i]) self.before_interpolator.set_line_marker(i, markers[i]) self.before_interpolator.set_line_alpha(i, alphas[i]) self._before_interpolator_win = sip.wrapinstance(self.before_interpolator.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._before_interpolator_win) self.analog_wfm_tx_0 = analog.wfm_tx( audio_rate=int(32e3), quad_rate=int(320e3), tau=3e-6, max_dev=50e3, fh=0, ) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SQR_WAVE, 1000, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.analog_wfm_tx_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.before_interpolator, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.fractional_interpolator_xx_0, 0)) self.connect((self.analog_wfm_tx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.analog_wfm_tx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.qtgui_time_sink_x_3, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.qtgui_time_sink_x_1, 0))
def __init__(self): gr.top_block.__init__(self, "Testautocancellation") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 48000 self.func_getfreq = func_getfreq = 800 * 10 ################################################## # Blocks ################################################## self.probe_getfreq = blocks.probe_signal_f() def _func_getfreq_probe(): while True: val = self.probe_getfreq.level() try: self.set_func_getfreq(val) except AttributeError: pass time.sleep(1.0 / (1)) _func_getfreq_thread = threading.Thread(target=_func_getfreq_probe) _func_getfreq_thread.daemon = True _func_getfreq_thread.start() self.fractional_interpolator_xx_0 = filter.fractional_interpolator_ff( 0, 0.1) self.blocks_wavfile_sink_0 = blocks.wavfile_sink( '/dev/stdout', 1, samp_rate, 16) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((-1, )) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_float * 1, 10) self.blocks_delay_1 = blocks.delay(gr.sizeof_float * 1, int(func_getfreq)) self.blocks_add_xx_1 = blocks.add_vff(1) self.audio_source_0 = audio.source(samp_rate, 'hw:1', True) self.analog_rail_ff_0 = analog.rail_ff(-0.8, 0.8) self.analog_agc2_xx_1 = analog.agc2_ff(1e-1, 1e-2, 0.1, 1.0) self.analog_agc2_xx_1.set_max_gain(65536) self.powerquality_getfreqcpp_0 = powerquality.getfreqcpp(0.1) ################################################## # Connections ################################################## self.connect((self.powerquality_getfreqcpp_0, 0), (self.probe_getfreq, 0)) self.connect((self.analog_agc2_xx_1, 0), (self.analog_rail_ff_0, 0)) self.connect((self.analog_rail_ff_0, 0), (self.blocks_wavfile_sink_0, 0)) self.connect((self.audio_source_0, 0), (self.fractional_interpolator_xx_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_delay_1, 0), (self.blocks_add_xx_1, 1)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.analog_agc2_xx_1, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_delay_1, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.powerquality_getfreqcpp_0, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.blocks_add_xx_1, 0)) self.connect((self.fractional_interpolator_xx_0, 0), (self.blocks_multiply_const_vxx_1, 0))