Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- # -*- coding: utf-8 -*-
- ##################################################
- # GNU Radio Python Flow Graph
- # Title: Top Block
- # Generated: Fri Oct 12 15:29:47 2018
- ##################################################
- 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 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.filter import pfb
- from gnuradio.qtgui import Range, RangeWidget
- from optparse import OptionParser
- import math
- import sip
- import sys
- class top_block(gr.top_block, Qt.QWidget):
- 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.constel = constel = digital.constellation_rect((digital.psk_4()[0]), (digital.psk_4()[1]), 4, 2, 2, 1, 1).base()
- self.sps = sps = len(constel.points())
- self.nfilts = nfilts = 32
- self.bps = bps = 2
- self.timing_loop_bw = timing_loop_bw = 6.28/100.0
- self.samp_rate = samp_rate = 2.5e6
- self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0, 0.35, 11*sps*nfilts)
- self.phase_bw = phase_bw = 6.28/100.0
- self.gain_tx = gain_tx = 60
- self.excess_bw = excess_bw = 0.35
- self.eq_gain = eq_gain = 0.01
- self.bandwidth_tx = bandwidth_tx = 5e6
- self.arity = arity = pow(2, bps)
- self.LO_freq = LO_freq = 2450e6
- ##################################################
- # Blocks
- ##################################################
- self._timing_loop_bw_range = Range(0.0, 0.2, 0.01, 6.28/100.0, 200)
- self._timing_loop_bw_win = RangeWidget(self._timing_loop_bw_range, self.set_timing_loop_bw, "Loop Bandwidth (Clock Sync)", "slider", float)
- self.top_layout.addWidget(self._timing_loop_bw_win)
- self._phase_bw_range = Range(0.0, 1.0, 0.01, 6.28/100.0, 200)
- self._phase_bw_win = RangeWidget(self._phase_bw_range, self.set_phase_bw, "Loop Bandwidth (Costas Loop)", "slider", float)
- self.top_layout.addWidget(self._phase_bw_win)
- self._eq_gain_range = Range(0.0, 0.1, 0.001, 0.01, 200)
- self._eq_gain_win = RangeWidget(self._eq_gain_range, self.set_eq_gain, "Gain (Equilizer)", "slider", float)
- self.top_layout.addWidget(self._eq_gain_win)
- self.qtgui_sink_x_0 = qtgui.sink_c(
- 1024, #fftsize
- firdes.WIN_BLACKMAN_hARRIS, #wintype
- 0, #fc
- samp_rate, #bw
- "Constellation output", #name
- True, #plotfreq
- True, #plotwaterfall
- True, #plottime
- True, #plotconst
- )
- self.qtgui_sink_x_0.set_update_time(1.0/10)
- self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget)
- self.top_layout.addWidget(self._qtgui_sink_x_0_win)
- self.qtgui_sink_x_0.enable_rf_freq(False)
- self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c(
- 1024, #size
- "Costas Loop output", #name
- 1 #number of inputs
- )
- self.qtgui_const_sink_x_0_0.set_update_time(0.10)
- self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2)
- self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2)
- self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
- self.qtgui_const_sink_x_0_0.enable_autoscale(False)
- self.qtgui_const_sink_x_0_0.enable_grid(False)
- if not True:
- self.qtgui_const_sink_x_0_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_0.set_line_label(i, "Data {0}".format(i))
- else:
- self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i])
- self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i])
- self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i])
- self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i])
- self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i])
- self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i])
- self._qtgui_const_sink_x_0_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget)
- self.top_layout.addWidget(self._qtgui_const_sink_x_0_0_win)
- self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccc(
- 4,
- taps=(rrc_taps),
- flt_size=nfilts)
- self.pfb_arb_resampler_xxx_0.declare_sample_delay(0)
- 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)
- self.digital_map_bb_0_0 = digital.map_bb((constel.pre_diff_code()))
- self.digital_map_bb_0 = digital.map_bb((constel.pre_diff_code()))
- self.digital_lms_dd_equalizer_cc_0 = digital.lms_dd_equalizer_cc(15, eq_gain, sps/2, constel)
- self.digital_diff_encoder_bb_0 = digital.diff_encoder_bb(int(arity))
- self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(int(arity))
- self.digital_costas_loop_cc_0 = digital.costas_loop_cc(phase_bw, int(arity), False)
- self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constel)
- self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((constel.points()), 1)
- self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
- self.blocks_repack_bits_bb_1_0 = blocks.repack_bits_bb(int(bps), 8, "", False, gr.GR_MSB_FIRST)
- self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, int(bps), "", False, gr.GR_MSB_FIRST)
- self.blocks_file_source_0_0_0 = blocks.file_source(gr.sizeof_char*1, "/home/limesdr/datal.txt", True)
- self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, "/home/limesdr/demod2", False)
- self.blocks_file_sink_0_0.set_unbuffered(False)
- ##################################################
- # Connections
- ##################################################
- self.connect((self.blocks_file_source_0_0_0, 0), (self.blocks_repack_bits_bb_0, 0))
- self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_map_bb_0_0, 0))
- self.connect((self.blocks_repack_bits_bb_1_0, 0), (self.blocks_file_sink_0_0, 0))
- self.connect((self.blocks_throttle_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0))
- self.connect((self.blocks_throttle_0, 0), (self.qtgui_sink_x_0, 0))
- self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.pfb_arb_resampler_xxx_0, 0))
- self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_map_bb_0, 0))
- self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_constellation_decoder_cb_0, 0))
- self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0_0, 0))
- self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_repack_bits_bb_1_0, 0))
- self.connect((self.digital_diff_encoder_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
- self.connect((self.digital_lms_dd_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0))
- self.connect((self.digital_map_bb_0, 0), (self.digital_diff_decoder_bb_0, 0))
- self.connect((self.digital_map_bb_0_0, 0), (self.digital_diff_encoder_bb_0, 0))
- self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_lms_dd_equalizer_cc_0, 0))
- self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_throttle_0, 0))
- def closeEvent(self, event):
- self.settings = Qt.QSettings("GNU Radio", "top_block")
- self.settings.setValue("geometry", self.saveGeometry())
- event.accept()
- def get_constel(self):
- return self.constel
- def set_constel(self, constel):
- self.constel = constel
- self.set_sps(len(self.constel.points()))
- self.digital_chunks_to_symbols_xx_0.set_symbol_table((self.constel.points()))
- def get_sps(self):
- return self.sps
- def set_sps(self, sps):
- self.sps = sps
- self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0, 0.35, 11*self.sps*self.nfilts))
- def get_nfilts(self):
- return self.nfilts
- def set_nfilts(self, nfilts):
- self.nfilts = nfilts
- self.set_rrc_taps(firdes.root_raised_cosine(self.nfilts, self.nfilts, 1.0, 0.35, 11*self.sps*self.nfilts))
- def get_bps(self):
- return self.bps
- def set_bps(self, bps):
- self.bps = bps
- self.set_arity(pow(2, self.bps))
- self.blocks_repack_bits_bb_1_0.set_k_and_l(int(self.bps),8)
- self.blocks_repack_bits_bb_0.set_k_and_l(8,int(self.bps))
- def get_timing_loop_bw(self):
- return self.timing_loop_bw
- def set_timing_loop_bw(self, timing_loop_bw):
- self.timing_loop_bw = timing_loop_bw
- self.digital_pfb_clock_sync_xxx_0.set_loop_bandwidth(self.timing_loop_bw)
- def get_samp_rate(self):
- return self.samp_rate
- def set_samp_rate(self, samp_rate):
- self.samp_rate = samp_rate
- self.blocks_throttle_0.set_sample_rate(self.samp_rate)
- self.qtgui_sink_x_0.set_frequency_range(0, self.samp_rate)
- def get_rrc_taps(self):
- return self.rrc_taps
- def set_rrc_taps(self, rrc_taps):
- self.rrc_taps = rrc_taps
- self.digital_pfb_clock_sync_xxx_0.update_taps((self.rrc_taps))
- self.pfb_arb_resampler_xxx_0.set_taps((self.rrc_taps))
- def get_phase_bw(self):
- return self.phase_bw
- def set_phase_bw(self, phase_bw):
- self.phase_bw = phase_bw
- self.digital_costas_loop_cc_0.set_loop_bandwidth(self.phase_bw)
- def get_gain_tx(self):
- return self.gain_tx
- def set_gain_tx(self, gain_tx):
- self.gain_tx = gain_tx
- def get_excess_bw(self):
- return self.excess_bw
- def set_excess_bw(self, excess_bw):
- self.excess_bw = excess_bw
- def get_eq_gain(self):
- return self.eq_gain
- def set_eq_gain(self, eq_gain):
- self.eq_gain = eq_gain
- self.digital_lms_dd_equalizer_cc_0.set_gain(self.eq_gain)
- def get_bandwidth_tx(self):
- return self.bandwidth_tx
- def set_bandwidth_tx(self, bandwidth_tx):
- self.bandwidth_tx = bandwidth_tx
- def get_arity(self):
- return self.arity
- def set_arity(self, arity):
- self.arity = arity
- def get_LO_freq(self):
- return self.LO_freq
- def set_LO_freq(self, LO_freq):
- self.LO_freq = LO_freq
- def main(top_block_cls=top_block, options=None):
- from distutils.version import StrictVersion
- if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
- style = gr.prefs().get_string('qtgui', 'style', 'raster')
- Qt.QApplication.setGraphicsSystem(style)
- qapp = Qt.QApplication(sys.argv)
- tb = top_block_cls()
- tb.start()
- tb.show()
- def quitting():
- tb.stop()
- tb.wait()
- qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
- qapp.exec_()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement