Sunday, February 12, 2017

FM Receiver with GNU Radio Python Code

FM Receiver


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 gnuradio import analog
from gnuradio import audio
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio import uhd
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.fft import window
from gnuradio.filter import firdes
from gnuradio.wxgui import fftsink2
from gnuradio.wxgui import forms
from gnuradio.wxgui import scopesink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import time
import wx


class top_block(grc_wxgui.top_block_gui):

    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "C:\Program Files\GNURadio-3.7\share\icons\hicolor\48x48/apps\gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 4000000
        self.freq = freq = 99900000

        ##################################################
        # Blocks
        ##################################################
        self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "tab1")
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "tab2")
        self.Add(self.notebook)
        _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=95000000,
        maximum=108000000,
        num_steps=1000,
        style=wx.SL_VERTICAL,
        cast=float,
        proportion=1,
        )
        self.Add(_freq_sizer)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
        self.notebook.GetPage(1).GetWin(),
        title="Output ",
        sample_rate=samp_rate,
        v_scale=0,
        v_offset=0,
        t_scale=0,
        ac_couple=False,
        xy_mode=False,
        num_inputs=1,
        trig_mode=wxgui.TRIG_MODE_AUTO,
        y_axis_label="Counts",
        )
        self.notebook.GetPage(1).Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink2_1 = fftsink2.fft_sink_c(
        self.notebook.GetPage(0).GetWin(),
        baseband_freq=0,
        y_per_div=10,
        y_divs=10,
        ref_level=0,
        ref_scale=2.0,
        sample_rate=samp_rate,
        fft_size=1024,
        fft_rate=15,
        average=True,
        avg_alpha=None,
        title="Channel",
        peak_hold=False,
        )
        self.notebook.GetPage(0).Add(self.wxgui_fftsink2_1.win)
        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(50, 0)
        self.uhd_usrp_source_0.set_antenna("RX2", 0)
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccf(
                interpolation=192000,
                decimation=200000,
                taps=None,
                fractional_bw=None,
        )
        self.low_pass_filter_0 = filter.fir_filter_ccf(20, firdes.low_pass(
        1, samp_rate, 100000, 10e3, firdes.WIN_HAMMING, 6.76))
        self.audio_sink_0 = audio.sink(96000, "", True)
        self.analog_wfm_rcv_0 = analog.wfm_rcv(
        quad_rate=192000,
        audio_decimation=2,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_wfm_rcv_0, 0), (self.audio_sink_0, 0))  
        self.connect((self.analog_wfm_rcv_0, 0), (self.wxgui_scopesink2_0, 0))  
        self.connect((self.low_pass_filter_0, 0), (self.rational_resampler_xxx_0, 0))  
        self.connect((self.rational_resampler_xxx_0, 0), (self.analog_wfm_rcv_0, 0))  
        self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0))  
        self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_1, 0))  

    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, 100000, 10e3, firdes.WIN_HAMMING, 6.76))
        self.uhd_usrp_source_0.set_samp_rate(self.samp_rate)
        self.wxgui_fftsink2_1.set_sample_rate(self.samp_rate)
        self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate)

    def get_freq(self):
        return self.freq

    def set_freq(self, freq):
        self.freq = freq
        self._freq_slider.set_value(self.freq)
        self._freq_text_box.set_value(self.freq)
        self.uhd_usrp_source_0.set_center_freq(self.freq, 0)


def main(top_block_cls=top_block, options=None):

    tb = top_block_cls()
    tb.Start(True)
    tb.Wait()


if __name__ == '__main__':

    main()

FM Transmitter with GNU Radio Python Code

FM Transmitter


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 gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio import uhd
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from gnuradio.wxgui import forms
from gnuradio.wxgui import scopesink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import time
import wx


class Fm_transmitter(grc_wxgui.top_block_gui):

    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Fm Transmitter")
        _icon_path = "C:\Program Files\GNURadio-3.7\share\icons\hicolor\48x48/apps\gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_0 = samp_rate_0 = 4000000
        self.samp_rate = samp_rate = 192000
        self.gain = gain = 50

        ##################################################
        # Blocks
        ##################################################
        _gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_text_box = forms.text_box(
        parent=self.GetWin(),
        sizer=_gain_sizer,
        value=self.gain,
        callback=self.set_gain,
        label='gain',
        converter=forms.float_converter(),
        proportion=0,
        )
        self._gain_slider = forms.slider(
        parent=self.GetWin(),
        sizer=_gain_sizer,
        value=self.gain,
        callback=self.set_gain,
        minimum=0,
        maximum=100,
        num_steps=100,
        style=wx.SL_HORIZONTAL,
        cast=float,
        proportion=1,
        )
        self.Add(_gain_sizer)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_c(
        self.GetWin(),
        title="Channel_input",
        sample_rate=samp_rate_0,
        v_scale=0,
        v_offset=0,
        t_scale=0,
        ac_couple=False,
        xy_mode=False,
        num_inputs=1,
        trig_mode=wxgui.TRIG_MODE_AUTO,
        y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.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(4000000)
        self.uhd_usrp_sink_0.set_center_freq(200000000, 0)
        self.uhd_usrp_sink_0.set_gain(gain, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
                interpolation=samp_rate_0,
                decimation=192000,
                taps=None,
                fractional_bw=None,
        )
        self.blocks_wavfile_source_0 = blocks.wavfile_source("/Users/gunaratr/Downloads/Hanthana Sihine - W. D. Amaradeva ft Umaria New Sinhala Song Releases 2014.wav", True)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate_0,True)
        self.analog_wfm_tx_0 = analog.wfm_tx(
        audio_rate=48000,
        quad_rate=192000,
        tau=75e-6,
        max_dev=75e3,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_wfm_tx_0, 0), (self.rational_resampler_xxx_0, 0))  
        self.connect((self.blocks_throttle_0, 0), (self.uhd_usrp_sink_0, 0))  
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_scopesink2_0, 0))  
        self.connect((self.blocks_wavfile_source_0, 0), (self.analog_wfm_tx_0, 0))  
        self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_throttle_0, 0))  

    def get_samp_rate_0(self):
        return self.samp_rate_0

    def set_samp_rate_0(self, samp_rate_0):
        self.samp_rate_0 = samp_rate_0
        self.blocks_throttle_0.set_sample_rate(self.samp_rate_0)
        self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate_0)

    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate

    def get_gain(self):
        return self.gain

    def set_gain(self, gain):
        self.gain = gain
        self._gain_slider.set_value(self.gain)
        self._gain_text_box.set_value(self.gain)
        self.uhd_usrp_sink_0.set_gain(self.gain, 0)
       


def main(top_block_cls=Fm_transmitter, options=None):

    tb = top_block_cls()
    tb.Start(True)
    tb.Wait()


if __name__ == '__main__':

    main()

PSK Transmitter and Receiver with GUN Radio Python Code


PSK Transmitter and Receiver with Channel Coding



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 channels
from gnuradio import digital
from gnuradio import eng_notation
from gnuradio import fec
from gnuradio import filter
from gnuradio import gr
from gnuradio import qtgui
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
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.samp_per_bit = samp_per_bit = 2
        self.channel_samp_rate = channel_samp_rate = 1000000/2
        self.gain = gain = 0.1
        self.bit_rate = bit_rate = channel_samp_rate/samp_per_bit
        self.Max_tput = Max_tput = 100000

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_time_sink_x_0_1 = qtgui.time_sink_f(
        1024, #size
        bit_rate, #samp_rate
        "Output Bit stream", #name
        1 #number of inputs
        )
        self.qtgui_time_sink_x_0_1.set_update_time(0.10)
        self.qtgui_time_sink_x_0_1.set_y_axis(-1, 1)
       
        self.qtgui_time_sink_x_0_1.set_y_label("Amplitude", "")
       
        self.qtgui_time_sink_x_0_1.enable_tags(-1, True)
        self.qtgui_time_sink_x_0_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0_1.enable_autoscale(True)
        self.qtgui_time_sink_x_0_1.enable_grid(False)
        self.qtgui_time_sink_x_0_1.enable_control_panel(True)
       
        if not True:
          self.qtgui_time_sink_x_0_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(1):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0_1.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0_1.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0_1.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0_1.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0_1.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0_1.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0_1.set_line_alpha(i, alphas[i])
       
        self._qtgui_time_sink_x_0_1_win = sip.wrapinstance(self.qtgui_time_sink_x_0_1.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_1_win)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        400, #size
        bit_rate, #samp_rate
        "Input Bit stream", #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_control_panel(True)
       
        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(1):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
            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.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        1024, #size
        firdes.WIN_BLACKMAN_hARRIS, #wintype
        0, #fc
        channel_samp_rate, #bw
        "Channel Input", #name
        1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.50)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(True)
        self.qtgui_freq_sink_x_0.set_fft_average(0.05)
        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_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_fff(8, (1, ))
        self.interp_fir_filter_xxx_0_0.declare_sample_delay(0)
        self.fec_encode_ccsds_27_bb_0 = fec.encode_ccsds_27_bb()
        self.fec_decode_ccsds_27_fb_0 = fec.decode_ccsds_27_fb()
        self.digital_simple_framer_0 = digital.simple_framer(20)
        self.digital_simple_correlator_0 = digital.simple_correlator(20)
        self.digital_psk_mod_0 = digital.psk.psk_mod(
          constellation_points=2,
          mod_code="none",
          differential=False,
          samples_per_symbol=samp_per_bit,
          excess_bw=0.35,
          verbose=False,
          log=False,
          )
        self.digital_psk_demod_0 = digital.psk.psk_demod(
          constellation_points=2,
          differential=False,
          samples_per_symbol=samp_per_bit,
          excess_bw=0.35,
          phase_bw=6.28/100.0,
          timing_bw=6.28/100.0,
          mod_code="none",
          verbose=False,
          log=False,
          )
        self.digital_map_bb_0 = digital.map_bb((-1,1))
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(2*3.14/100, 2, True)
        self.channels_channel_model_0 = channels.channel_model(
        noise_voltage=0,
        frequency_offset=0.0,
        epsilon=1,
        taps=(1, ),
        noise_seed=0,
        block_tags=False
        )
        self.blocks_throttle_0_1_0_0_0 = blocks.throttle(gr.sizeof_char*1, Max_tput,True)
        self.blocks_throttle_0_1_0 = blocks.throttle(gr.sizeof_gr_complex*1, channel_samp_rate,True)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((gain*(1+1j), ))
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/Users/gunaratr/Documents/MATLAB/src_wav.bin", False)
        self.blocks_file_sink_0_0_1 = blocks.file_sink(gr.sizeof_char*1, "/Users/gunaratr/Documents/MATLAB/new.dat", False)
        self.blocks_file_sink_0_0_1.set_unbuffered(False)
        self.blocks_char_to_float_0_1_0_0_0_0_1_0_0_0_0 = blocks.char_to_float(1, 1)
        self.blocks_char_to_float_0_1_0_0_0_0_1_0_0 = blocks.char_to_float(1, 1)
        self.blocks_char_to_float_0_1_0_0_0_0_1_0 = blocks.char_to_float(1, 1)
        self.blocks_char_to_float_0_1_0_0_0_0_0 = blocks.char_to_float(1, 1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, ))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_add_const_vxx_0, 0), (self.digital_simple_correlator_0, 0))  
        self.connect((self.blocks_char_to_float_0_1_0_0_0_0_0, 0), (self.fec_decode_ccsds_27_fb_0, 0))  
        self.connect((self.blocks_char_to_float_0_1_0_0_0_0_1_0, 0), (self.interp_fir_filter_xxx_0_0, 0))  
        self.connect((self.blocks_char_to_float_0_1_0_0_0_0_1_0_0, 0), (self.qtgui_time_sink_x_0, 0))  
        self.connect((self.blocks_char_to_float_0_1_0_0_0_0_1_0_0_0_0, 0), (self.qtgui_time_sink_x_0_1, 0))  
        self.connect((self.blocks_file_source_0, 0), (self.blocks_char_to_float_0_1_0_0_0_0_1_0_0, 0))  
        self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0_1_0_0_0, 0))  
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_throttle_0_1_0, 0))  
        self.connect((self.blocks_throttle_0_1_0, 0), (self.channels_channel_model_0, 0))  
        self.connect((self.blocks_throttle_0_1_0, 0), (self.qtgui_freq_sink_x_0, 0))  
        self.connect((self.blocks_throttle_0_1_0_0_0, 0), (self.fec_encode_ccsds_27_bb_0, 0))  
        self.connect((self.channels_channel_model_0, 0), (self.digital_costas_loop_cc_0, 0))  
        self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_psk_demod_0, 0))  
        self.connect((self.digital_map_bb_0, 0), (self.blocks_char_to_float_0_1_0_0_0_0_0, 0))  
        self.connect((self.digital_psk_demod_0, 0), (self.blocks_char_to_float_0_1_0_0_0_0_1_0, 0))  
        self.connect((self.digital_psk_mod_0, 0), (self.blocks_multiply_const_vxx_0, 0))  
        self.connect((self.digital_simple_correlator_0, 0), (self.digital_map_bb_0, 0))  
        self.connect((self.digital_simple_framer_0, 0), (self.digital_psk_mod_0, 0))  
        self.connect((self.fec_decode_ccsds_27_fb_0, 0), (self.blocks_char_to_float_0_1_0_0_0_0_1_0_0_0_0, 0))  
        self.connect((self.fec_decode_ccsds_27_fb_0, 0), (self.blocks_file_sink_0_0_1, 0))  
        self.connect((self.fec_encode_ccsds_27_bb_0, 0), (self.digital_simple_framer_0, 0))  
        self.connect((self.interp_fir_filter_xxx_0_0, 0), (self.blocks_add_const_vxx_0, 0))  

    def closeEvent(self, event):
        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.settings.setValue("geometry", self.saveGeometry())
        event.accept()


    def get_samp_per_bit(self):
        return self.samp_per_bit

    def set_samp_per_bit(self, samp_per_bit):
        self.samp_per_bit = samp_per_bit
        self.set_bit_rate(self.channel_samp_rate/self.samp_per_bit)

    def get_channel_samp_rate(self):
        return self.channel_samp_rate

    def set_channel_samp_rate(self, channel_samp_rate):
        self.channel_samp_rate = channel_samp_rate
        self.set_bit_rate(self.channel_samp_rate/self.samp_per_bit)
        self.blocks_throttle_0_1_0.set_sample_rate(self.channel_samp_rate)
        self.qtgui_freq_sink_x_0.set_frequency_range(0, self.channel_samp_rate)

    def get_gain(self):
        return self.gain

    def set_gain(self, gain):
        self.gain = gain
        self.blocks_multiply_const_vxx_0.set_k((self.gain*(1+1j), ))

    def get_bit_rate(self):
        return self.bit_rate

    def set_bit_rate(self, bit_rate):
        self.bit_rate = bit_rate
        self.qtgui_time_sink_x_0.set_samp_rate(self.bit_rate)
        self.qtgui_time_sink_x_0_1.set_samp_rate(self.bit_rate)

    def get_Max_tput(self):
        return self.Max_tput

    def set_Max_tput(self, Max_tput):
        self.Max_tput = Max_tput
        self.blocks_throttle_0_1_0_0_0.set_sample_rate(self.Max_tput)


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()