Advertisement
Guest User

top_block.py

a guest
Oct 12th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.97 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. ##################################################
  4. # GNU Radio Python Flow Graph
  5. # Title: Top Block
  6. # Generated: Fri Oct 12 15:29:47 2018
  7. ##################################################
  8.  
  9. if __name__ == '__main__':
  10.     import ctypes
  11.     import sys
  12.     if sys.platform.startswith('linux'):
  13.         try:
  14.             x11 = ctypes.cdll.LoadLibrary('libX11.so')
  15.             x11.XInitThreads()
  16.         except:
  17.             print "Warning: failed to XInitThreads()"
  18.  
  19. from PyQt4 import Qt
  20. from gnuradio import blocks
  21. from gnuradio import digital
  22. from gnuradio import eng_notation
  23. from gnuradio import gr
  24. from gnuradio import qtgui
  25. from gnuradio.eng_option import eng_option
  26. from gnuradio.filter import firdes
  27. from gnuradio.filter import pfb
  28. from gnuradio.qtgui import Range, RangeWidget
  29. from optparse import OptionParser
  30. import math
  31. import sip
  32. import sys
  33.  
  34.  
  35. class top_block(gr.top_block, Qt.QWidget):
  36.  
  37.     def __init__(self):
  38.         gr.top_block.__init__(self, "Top Block")
  39.         Qt.QWidget.__init__(self)
  40.         self.setWindowTitle("Top Block")
  41.         try:
  42.             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
  43.         except:
  44.             pass
  45.         self.top_scroll_layout = Qt.QVBoxLayout()
  46.         self.setLayout(self.top_scroll_layout)
  47.         self.top_scroll = Qt.QScrollArea()
  48.         self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
  49.         self.top_scroll_layout.addWidget(self.top_scroll)
  50.         self.top_scroll.setWidgetResizable(True)
  51.         self.top_widget = Qt.QWidget()
  52.         self.top_scroll.setWidget(self.top_widget)
  53.         self.top_layout = Qt.QVBoxLayout(self.top_widget)
  54.         self.top_grid_layout = Qt.QGridLayout()
  55.         self.top_layout.addLayout(self.top_grid_layout)
  56.  
  57.         self.settings = Qt.QSettings("GNU Radio", "top_block")
  58.         self.restoreGeometry(self.settings.value("geometry").toByteArray())
  59.  
  60.         ##################################################
  61.         # Variables
  62.         ##################################################
  63.         self.constel = constel = digital.constellation_rect((digital.psk_4()[0]), (digital.psk_4()[1]), 4, 2, 2, 1, 1).base()
  64.         self.sps = sps = len(constel.points())
  65.         self.nfilts = nfilts = 32
  66.         self.bps = bps = 2
  67.         self.timing_loop_bw = timing_loop_bw = 6.28/100.0
  68.         self.samp_rate = samp_rate = 2.5e6
  69.         self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0, 0.35, 11*sps*nfilts)
  70.         self.phase_bw = phase_bw = 6.28/100.0
  71.         self.gain_tx = gain_tx = 60
  72.         self.excess_bw = excess_bw = 0.35
  73.         self.eq_gain = eq_gain = 0.01
  74.         self.bandwidth_tx = bandwidth_tx = 5e6
  75.         self.arity = arity = pow(2, bps)
  76.         self.LO_freq = LO_freq = 2450e6
  77.  
  78.         ##################################################
  79.         # Blocks
  80.         ##################################################
  81.         self._timing_loop_bw_range = Range(0.0, 0.2, 0.01, 6.28/100.0, 200)
  82.         self._timing_loop_bw_win = RangeWidget(self._timing_loop_bw_range, self.set_timing_loop_bw, "Loop Bandwidth (Clock Sync)", "slider", float)
  83.         self.top_layout.addWidget(self._timing_loop_bw_win)
  84.         self._phase_bw_range = Range(0.0, 1.0, 0.01, 6.28/100.0, 200)
  85.         self._phase_bw_win = RangeWidget(self._phase_bw_range, self.set_phase_bw, "Loop Bandwidth (Costas Loop)", "slider", float)
  86.         self.top_layout.addWidget(self._phase_bw_win)
  87.         self._eq_gain_range = Range(0.0, 0.1, 0.001, 0.01, 200)
  88.         self._eq_gain_win = RangeWidget(self._eq_gain_range, self.set_eq_gain, "Gain (Equilizer)", "slider", float)
  89.         self.top_layout.addWidget(self._eq_gain_win)
  90.         self.qtgui_sink_x_0 = qtgui.sink_c(
  91.             1024, #fftsize
  92.             firdes.WIN_BLACKMAN_hARRIS, #wintype
  93.             0, #fc
  94.             samp_rate, #bw
  95.             "Constellation output", #name
  96.             True, #plotfreq
  97.             True, #plotwaterfall
  98.             True, #plottime
  99.             True, #plotconst
  100.         )
  101.         self.qtgui_sink_x_0.set_update_time(1.0/10)
  102.         self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget)
  103.         self.top_layout.addWidget(self._qtgui_sink_x_0_win)
  104.        
  105.         self.qtgui_sink_x_0.enable_rf_freq(False)
  106.        
  107.        
  108.          
  109.         self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c(
  110.             1024, #size
  111.             "Costas Loop output", #name
  112.             1 #number of inputs
  113.         )
  114.         self.qtgui_const_sink_x_0_0.set_update_time(0.10)
  115.         self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2)
  116.         self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2)
  117.         self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
  118.         self.qtgui_const_sink_x_0_0.enable_autoscale(False)
  119.         self.qtgui_const_sink_x_0_0.enable_grid(False)
  120.        
  121.         if not True:
  122.           self.qtgui_const_sink_x_0_0.disable_legend()
  123.        
  124.         labels = ["", "", "", "", "",
  125.                   "", "", "", "", ""]
  126.         widths = [1, 1, 1, 1, 1,
  127.                   1, 1, 1, 1, 1]
  128.         colors = ["blue", "red", "red", "red", "red",
  129.                   "red", "red", "red", "red", "red"]
  130.         styles = [0, 0, 0, 0, 0,
  131.                   0, 0, 0, 0, 0]
  132.         markers = [0, 0, 0, 0, 0,
  133.                    0, 0, 0, 0, 0]
  134.         alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
  135.                   1.0, 1.0, 1.0, 1.0, 1.0]
  136.         for i in xrange(1):
  137.             if len(labels[i]) == 0:
  138.                 self.qtgui_const_sink_x_0_0.set_line_label(i, "Data {0}".format(i))
  139.             else:
  140.                 self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i])
  141.             self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i])
  142.             self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i])
  143.             self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i])
  144.             self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i])
  145.             self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i])
  146.        
  147.         self._qtgui_const_sink_x_0_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget)
  148.         self.top_layout.addWidget(self._qtgui_const_sink_x_0_0_win)
  149.         self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccc(
  150.               4,
  151.                   taps=(rrc_taps),
  152.               flt_size=nfilts)
  153.         self.pfb_arb_resampler_xxx_0.declare_sample_delay(0)
  154.            
  155.         self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, timing_loop_bw, (rrc_taps), nfilts, nfilts/2, 1.5, sps/2)
  156.         self.digital_map_bb_0_0 = digital.map_bb((constel.pre_diff_code()))
  157.         self.digital_map_bb_0 = digital.map_bb((constel.pre_diff_code()))
  158.         self.digital_lms_dd_equalizer_cc_0 = digital.lms_dd_equalizer_cc(15, eq_gain, sps/2, constel)
  159.         self.digital_diff_encoder_bb_0 = digital.diff_encoder_bb(int(arity))
  160.         self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(int(arity))
  161.         self.digital_costas_loop_cc_0 = digital.costas_loop_cc(phase_bw, int(arity), False)
  162.         self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constel)
  163.         self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((constel.points()), 1)
  164.         self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
  165.         self.blocks_repack_bits_bb_1_0 = blocks.repack_bits_bb(int(bps), 8, "", False, gr.GR_MSB_FIRST)
  166.         self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, int(bps), "", False, gr.GR_MSB_FIRST)
  167.         self.blocks_file_source_0_0_0 = blocks.file_source(gr.sizeof_char*1, "/home/limesdr/datal.txt", True)
  168.         self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, "/home/limesdr/demod2", False)
  169.         self.blocks_file_sink_0_0.set_unbuffered(False)
  170.  
  171.         ##################################################
  172.         # Connections
  173.         ##################################################
  174.         self.connect((self.blocks_file_source_0_0_0, 0), (self.blocks_repack_bits_bb_0, 0))    
  175.         self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_map_bb_0_0, 0))    
  176.         self.connect((self.blocks_repack_bits_bb_1_0, 0), (self.blocks_file_sink_0_0, 0))    
  177.         self.connect((self.blocks_throttle_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0))    
  178.         self.connect((self.blocks_throttle_0, 0), (self.qtgui_sink_x_0, 0))    
  179.         self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.pfb_arb_resampler_xxx_0, 0))    
  180.         self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_map_bb_0, 0))    
  181.         self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_constellation_decoder_cb_0, 0))    
  182.         self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0_0, 0))    
  183.         self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_repack_bits_bb_1_0, 0))    
  184.         self.connect((self.digital_diff_encoder_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))    
  185.         self.connect((self.digital_lms_dd_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0))    
  186.         self.connect((self.digital_map_bb_0, 0), (self.digital_diff_decoder_bb_0, 0))    
  187.         self.connect((self.digital_map_bb_0_0, 0), (self.digital_diff_encoder_bb_0, 0))    
  188.         self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_lms_dd_equalizer_cc_0, 0))    
  189.         self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_throttle_0, 0))    
  190.  
  191.     def closeEvent(self, event):
  192.         self.settings = Qt.QSettings("GNU Radio", "top_block")
  193.         self.settings.setValue("geometry", self.saveGeometry())
  194.         event.accept()
  195.  
  196.  
  197.     def get_constel(self):
  198.         return self.constel
  199.  
  200.     def set_constel(self, constel):
  201.         self.constel = constel
  202.         self.set_sps(len(self.constel.points()))
  203.         self.digital_chunks_to_symbols_xx_0.set_symbol_table((self.constel.points()))
  204.  
  205.     def get_sps(self):
  206.         return self.sps
  207.  
  208.     def set_sps(self, sps):
  209.         self.sps = sps
  210.         self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0, 0.35, 11*self.sps*self.nfilts))
  211.  
  212.     def get_nfilts(self):
  213.         return self.nfilts
  214.  
  215.     def set_nfilts(self, nfilts):
  216.         self.nfilts = nfilts
  217.         self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0, 0.35, 11*self.sps*self.nfilts))
  218.  
  219.     def get_bps(self):
  220.         return self.bps
  221.  
  222.     def set_bps(self, bps):
  223.         self.bps = bps
  224.         self.set_arity(pow(2, self.bps))
  225.         self.blocks_repack_bits_bb_1_0.set_k_and_l(int(self.bps),8)
  226.         self.blocks_repack_bits_bb_0.set_k_and_l(8,int(self.bps))
  227.  
  228.     def get_timing_loop_bw(self):
  229.         return self.timing_loop_bw
  230.  
  231.     def set_timing_loop_bw(self, timing_loop_bw):
  232.         self.timing_loop_bw = timing_loop_bw
  233.         self.digital_pfb_clock_sync_xxx_0.set_loop_bandwidth(self.timing_loop_bw)
  234.  
  235.     def get_samp_rate(self):
  236.         return self.samp_rate
  237.  
  238.     def set_samp_rate(self, samp_rate):
  239.         self.samp_rate = samp_rate
  240.         self.blocks_throttle_0.set_sample_rate(self.samp_rate)
  241.         self.qtgui_sink_x_0.set_frequency_range(0, self.samp_rate)
  242.  
  243.     def get_rrc_taps(self):
  244.         return self.rrc_taps
  245.  
  246.     def set_rrc_taps(self, rrc_taps):
  247.         self.rrc_taps = rrc_taps
  248.         self.digital_pfb_clock_sync_xxx_0.update_taps((self.rrc_taps))
  249.         self.pfb_arb_resampler_xxx_0.set_taps((self.rrc_taps))
  250.  
  251.     def get_phase_bw(self):
  252.         return self.phase_bw
  253.  
  254.     def set_phase_bw(self, phase_bw):
  255.         self.phase_bw = phase_bw
  256.         self.digital_costas_loop_cc_0.set_loop_bandwidth(self.phase_bw)
  257.  
  258.     def get_gain_tx(self):
  259.         return self.gain_tx
  260.  
  261.     def set_gain_tx(self, gain_tx):
  262.         self.gain_tx = gain_tx
  263.  
  264.     def get_excess_bw(self):
  265.         return self.excess_bw
  266.  
  267.     def set_excess_bw(self, excess_bw):
  268.         self.excess_bw = excess_bw
  269.  
  270.     def get_eq_gain(self):
  271.         return self.eq_gain
  272.  
  273.     def set_eq_gain(self, eq_gain):
  274.         self.eq_gain = eq_gain
  275.         self.digital_lms_dd_equalizer_cc_0.set_gain(self.eq_gain)
  276.  
  277.     def get_bandwidth_tx(self):
  278.         return self.bandwidth_tx
  279.  
  280.     def set_bandwidth_tx(self, bandwidth_tx):
  281.         self.bandwidth_tx = bandwidth_tx
  282.  
  283.     def get_arity(self):
  284.         return self.arity
  285.  
  286.     def set_arity(self, arity):
  287.         self.arity = arity
  288.  
  289.     def get_LO_freq(self):
  290.         return self.LO_freq
  291.  
  292.     def set_LO_freq(self, LO_freq):
  293.         self.LO_freq = LO_freq
  294.  
  295.  
  296. def main(top_block_cls=top_block, options=None):
  297.  
  298.     from distutils.version import StrictVersion
  299.     if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
  300.         style = gr.prefs().get_string('qtgui', 'style', 'raster')
  301.         Qt.QApplication.setGraphicsSystem(style)
  302.     qapp = Qt.QApplication(sys.argv)
  303.  
  304.     tb = top_block_cls()
  305.     tb.start()
  306.     tb.show()
  307.  
  308.     def quitting():
  309.         tb.stop()
  310.         tb.wait()
  311.     qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
  312.     qapp.exec_()
  313.  
  314.  
  315. if __name__ == '__main__':
  316.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement