#!/usr/bin/env python2 ################################################## # GNU Radio Python Flow Graph # Title: Rx Syncd # Generated: Fri Apr 1 08:56:52 2016 ################################################## if __name__ == '__main__': import ctypes import sys if sys.platform.startswith('linux'): try: x11 = ctypes.cdll.LoadLibrary('libX11.so') x11.XInitThreads() except: print "Warning: failed to XInitThreads()" from PyQt4 import Qt from gnuradio import analog from gnuradio import blocks from gnuradio import digital from gnuradio import eng_notation from gnuradio import gr from gnuradio import qtgui from gnuradio.eng_option import eng_option from gnuradio.filter import firdes from gnuradio.qtgui import Range, RangeWidget from optparse import OptionParser import cmath import math import numpy as np import pmt import sip import sys class Rx_syncd(gr.top_block, Qt.QWidget): def __init__(self): gr.top_block.__init__(self, "Rx Syncd") Qt.QWidget.__init__(self) self.setWindowTitle("Rx Syncd") 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", "Rx_syncd") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.tx_sps = tx_sps = 10 self.preamble_bytes = preamble_bytes = [0xfc, 0x0c, 0x30, 0x00] self.eb = eb = 0.35 self.constel_rx = constel_rx = digital.constellation_rect((digital.psk_4()[0]), (digital.psk_4()[1]), 4 , 2, 2, 1, 1).base() self.constel_rx.gen_soft_dec_lut(8) self.sps = sps = 2 self.samp_rate = samp_rate = 320000 self.modulated_preamble_untrimmed = modulated_preamble_untrimmed = digital.modulate_vector_bc(digital.generic_mod(constellation=constel_rx,differential=False,samples_per_symbol=tx_sps,pre_diff_code=True,excess_bw=eb,verbose=False,log=False) .to_basic_block(), (preamble_bytes*6), ([1])) self.tx_samp_rate = tx_samp_rate = samp_rate*tx_sps/sps self.taps = taps = firdes.root_raised_cosine(32, 32,1.0, eb, 11*sps*32) self.phase_offset = phase_offset = 0 self.modulated_preamble = modulated_preamble = [modulated_preamble_untrimmed[i] for i in range(709,860)] self.const_order = const_order = 4 ################################################## # Blocks ################################################## self._phase_offset_range = Range(-math.pi, math.pi, math.pi/200.0, 0, 200) self._phase_offset_win = RangeWidget(self._phase_offset_range, self.set_phase_offset, "Phase Offset", "counter_slider", float) self.top_layout.addWidget(self._phase_offset_win) self.qtgui_time_sink_x_2_0_0 = qtgui.time_sink_f( 1024*4, #size tx_samp_rate, #samp_rate "Correlation Outputs", #name 2 #number of inputs ) self.qtgui_time_sink_x_2_0_0.set_update_time(0.10) self.qtgui_time_sink_x_2_0_0.set_y_axis(-1.5, 1.5) self.qtgui_time_sink_x_2_0_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_2_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_2_0_0.set_trigger_mode(qtgui.TRIG_MODE_TAG, qtgui.TRIG_SLOPE_POS, 0.5, 0.0005, 0, "corr_start") self.qtgui_time_sink_x_2_0_0.enable_autoscale(False) self.qtgui_time_sink_x_2_0_0.enable_grid(True) self.qtgui_time_sink_x_2_0_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_2_0_0.disable_legend() labels = ["Rx Phase", "|Correlation|^2", "", "", "", "", "", "", "", ""] 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: self.qtgui_time_sink_x_2_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_2_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_2_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_2_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_2_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_2_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_2_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_2_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_2_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_2_0_0_win) self.qtgui_time_sink_x_1 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "Bits", #name 2 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.10) self.qtgui_time_sink_x_1.set_y_axis(-2, 2) 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_TAG, qtgui.TRIG_SLOPE_POS, 0, 0.0001, 0, "corr_start") self.qtgui_time_sink_x_1.enable_autoscale(False) self.qtgui_time_sink_x_1.enable_grid(True) self.qtgui_time_sink_x_1.enable_control_panel(False) if not True: self.qtgui_time_sink_x_1.disable_legend() labels = ["Soft Bits", "Hard Bits", "", "", "", "", "", "", "", ""] 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: self.qtgui_time_sink_x_1.set_line_label(i, "Data {0}".format(i)) 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_const_sink_x_0_1 = qtgui.const_sink_c( 1024, #size "pf clock / mm sync out", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_1.set_update_time(0.10) self.qtgui_const_sink_x_0_1.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_1.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_1.set_trigger_mode(qtgui.TRIG_MODE_TAG, qtgui.TRIG_SLOPE_POS, 0.0, 0, "phase_est") self.qtgui_const_sink_x_0_1.enable_autoscale(False) self.qtgui_const_sink_x_0_1.enable_grid(False) if not True: self.qtgui_const_sink_x_0_1.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 = [1, 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_1.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_1.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_1.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_1.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_1.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_1.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_1.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_1_win = sip.wrapinstance(self.qtgui_const_sink_x_0_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_x_0_1_win) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(tx_sps, 2.0*math.pi/100.0, (firdes.root_raised_cosine(32, 32*tx_sps, 1.0, eb, int(5*sps*32))), 32, 33*0, 1.5, sps) self.digital_costas_loop_cc_1 = digital.costas_loop_cc(2.0*math.pi/100.0, const_order, False) self.digital_corr_est_cc_0 = digital.corr_est_cc((modulated_preamble), tx_sps, len(modulated_preamble)-1, 0.81) self.digital_constellation_soft_decoder_cf_0 = digital.constellation_soft_decoder_cf(constel_rx) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=constel_rx, differential=False, samples_per_symbol=tx_sps, pre_diff_code=True, excess_bw=eb, verbose=False, log=False, ) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(23, 1, 1e-3, sps) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.blocks_vector_source_x_0 = blocks.vector_source_b([0x00]*2 + [0x4b]*34 + preamble_bytes + [0x20, 0x20, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x20, 0x20] + [0x4b]*3 +[0xaa]*4, True, 1, 0*[gr.tag_utils.python_to_tag([0, pmt.intern("start"), pmt.PMT_T, pmt.intern("vector_source")])]) self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, tx_samp_rate,True) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_vcc((cmath.exp(1.0j*phase_offset), )) self.blocks_multiply_const_vxx_1_0_0 = blocks.multiply_const_vff((1.0/20e3, )) self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_vff((1.0/math.pi, )) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_arg_1 = blocks.complex_to_arg(1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 0.5) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1.0, )) self.analog_feedforward_agc_cc_0 = analog.feedforward_agc_cc(2048, 1.5) ################################################## # Connections ################################################## self.connect((self.analog_feedforward_agc_cc_0, 0), (self.digital_corr_est_cc_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.qtgui_time_sink_x_1, 1)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_complex_to_arg_1, 0), (self.blocks_multiply_const_vxx_1_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_multiply_const_vxx_1_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.qtgui_time_sink_x_2_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_1_0_0, 0), (self.qtgui_time_sink_x_2_0_0, 1)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.analog_feedforward_agc_cc_0, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_1, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.blocks_throttle_0_0, 0)) self.connect((self.digital_constellation_soft_decoder_cf_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.digital_constellation_soft_decoder_cf_0, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.digital_corr_est_cc_0, 0), (self.blocks_complex_to_arg_1, 0)) self.connect((self.digital_corr_est_cc_0, 1), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.digital_corr_est_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_costas_loop_cc_1, 0), (self.digital_constellation_soft_decoder_cf_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_cma_equalizer_cc_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.qtgui_const_sink_x_0_1, 0)) def closeEvent(self, event): self.settings = Qt.QSettings("GNU Radio", "Rx_syncd") self.settings.setValue("geometry", self.saveGeometry()) event.accept() def get_tx_sps(self): return self.tx_sps def set_tx_sps(self, tx_sps): self.tx_sps = tx_sps self.set_tx_samp_rate(self.samp_rate*self.tx_sps/self.sps) self.digital_pfb_clock_sync_xxx_0.set_taps((firdes.root_raised_cosine(32, 32*self.tx_sps, 1.0, self.eb, int(5*self.sps*32)))) def get_preamble_bytes(self): return self.preamble_bytes def set_preamble_bytes(self, preamble_bytes): self.preamble_bytes = preamble_bytes self.blocks_vector_source_x_0.set_data([0x00]*2 + [0x4b]*34 + self.preamble_bytes + [0x20, 0x20, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x20, 0x20] + [0x4b]*3 +[0xaa]*4, 0*[gr.tag_utils.python_to_tag([0, pmt.intern("start"), pmt.PMT_T, pmt.intern("vector_source")])]) def get_eb(self): return self.eb def set_eb(self, eb): self.eb = eb self.set_taps(firdes.root_raised_cosine(32, 32,1.0, self.eb, 11*self.sps*32)) self.digital_pfb_clock_sync_xxx_0.set_taps((firdes.root_raised_cosine(32, 32*self.tx_sps, 1.0, self.eb, int(5*self.sps*32)))) def get_constel_rx(self): return self.constel_rx def set_constel_rx(self, constel_rx): self.constel_rx = constel_rx def get_sps(self): return self.sps def set_sps(self, sps): self.sps = sps self.set_taps(firdes.root_raised_cosine(32, 32,1.0, self.eb, 11*self.sps*32)) self.set_tx_samp_rate(self.samp_rate*self.tx_sps/self.sps) self.digital_pfb_clock_sync_xxx_0.set_taps((firdes.root_raised_cosine(32, 32*self.tx_sps, 1.0, self.eb, int(5*self.sps*32)))) def get_samp_rate(self): return self.samp_rate def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate self.set_tx_samp_rate(self.samp_rate*self.tx_sps/self.sps) self.qtgui_time_sink_x_1.set_samp_rate(self.samp_rate) def get_modulated_preamble_untrimmed(self): return self.modulated_preamble_untrimmed def set_modulated_preamble_untrimmed(self, modulated_preamble_untrimmed): self.modulated_preamble_untrimmed = modulated_preamble_untrimmed self.set_modulated_preamble([self.modulated_preamble_untrimmed[i] for i in range(709,860)]) def get_tx_samp_rate(self): return self.tx_samp_rate def set_tx_samp_rate(self, tx_samp_rate): self.tx_samp_rate = tx_samp_rate self.blocks_throttle_0_0.set_sample_rate(self.tx_samp_rate) self.qtgui_time_sink_x_2_0_0.set_samp_rate(self.tx_samp_rate) def get_taps(self): return self.taps def set_taps(self, taps): self.taps = taps def get_phase_offset(self): return self.phase_offset def set_phase_offset(self, phase_offset): self.phase_offset = phase_offset self.blocks_multiply_const_vxx_2.set_k((cmath.exp(1.0j*self.phase_offset), )) def get_modulated_preamble(self): return self.modulated_preamble def set_modulated_preamble(self, modulated_preamble): self.modulated_preamble = modulated_preamble self.digital_corr_est_cc_0.set_mark_delay(len(self.modulated_preamble)-1) def get_const_order(self): return self.const_order def set_const_order(self, const_order): self.const_order = const_order if __name__ == '__main__': parser = OptionParser(option_class=eng_option, usage="%prog: [options]") (options, args) = parser.parse_args() from distutils.version import StrictVersion if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"): Qt.QApplication.setGraphicsSystem(gr.prefs().get_string('qtgui','style','raster')) qapp = Qt.QApplication(sys.argv) tb = Rx_syncd() tb.start() tb.show() print tb.get_modulated_preamble_untrimmed() def quitting(): tb.stop() tb.wait() qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting) qapp.exec_() tb = None # to clean up Qt widgets