Selasa, 7 Julai 2015

Asingment QPSK use GNU RADIO

Simulation of Quadrature
Phase Shift Keying (QPSK) using GNURadio software

By: MEL / MKET 1413 students 2014201501
                                Mohd Hasruzairin Mohd Hashim      Suraya Khalid                             Haslini Awang                 
                                Khiruddin  Zakaria                            Nur Iryani Iylia  Abu Bakar        Saargunawathy Manogaran

Abstract — A simulation of how to deal with issues of receiving modulated digital signals. It is to understand many of the involved issues while transmitting and receiving real signals through channel effects.

I.                   INTRODUCTION


Phase-shift keying (PSK) is a digital modulation scheme that conveys data modulating the phase of a reference signal. Quadrature PSK (QPSK) combined with polarization multiplex quadruples channel capacity over state-of-the-art intensity-modulated systems. This scheme is very attractive because it uses existing fiber plants most efficiently. The synchronous down conversion of an optical signal is critically affected by phase noise of the lasers, and this problem is acknowledged and addressed in many publications on synchronous binary PSK (BPSK) and QPSK optical transmission [1].

The amount of radio frequency spectrum required to transmit QPSK reliably is half that required for BPSK signals, which in turn makes room for more users on the channel. QPSK uses four points on the constellation diagram, equispaced around a circle. With four phases, QPSK can encode two bits per symbol. It is to minimize the BER- twice the rate of BPSK; to double the data rate compared to a BPSK system while maintaining the bandwidth of the signal or to maintain the data rate of BPSK but half the bandwidth needed.


Figure 1: Constellation diagram for QPSK.

II.                  GNURADIO CODE


From figure 2 has show the block diagram for modulation and demodulation in QPSK.





  Figure 2: GNUradio block diagram shows the QPSK simulation.


Modulation:  At the PSK Demodulation is used to separate odd and even bits from the generated information bits. Each of the odd bits (quadrature arm) and even bits (in-phase arm) are converted to NRZ format in a parallel manner. The signal on the in-phase arm is multiplied by cosine component and the signal on the quadrature arm is multiplied by sine component. QPSK modulated signal is obtained by adding the signal from both in-phase and quadrature arm

Multiply Const: Signal is multiplied by a reference frequency generator.

ulaw Encoder :  Audio Encoder is implementing an algorithm that compresses digital audio data according to a given audio file format. The object of the algorithm is to represent the high-fidelity audio signal with minimum number of bits while retaining the quality. This can effectively the bandwidth required for transmission.

Virtual sink: When paired with a Virtual Source block, this is essentially the same as drawing a wire between two blocks. This block can be useful for tidying up a complex flowgraph.

Throttle: Limits the data throughput to the specified sampling rate. This prevents GNURadio from consuming all CPU resources when the flowgraph is not being regulated by external hardware (ie: audio source/sink or USRP source/sink).

Channel Model: This block implements a basic channel model simulator that can be used to help evaluate, design, and test various signals, waveforms, and algorithms.We use this block to set the voltage of an AWGN noise source.

File sink: Outputs raw data values in binary format to the specified file. This file can be read into any programming environment that can read binary files. It can also be played back in GRC using an appropriate File Source block.

Demodulation: For block PSK demodulator is received signal is multiplied by a reference frequency generators. The multiplied output on each arm is integrated over one bit period using an integrator.

Interpolating FIR filter: Filter will eliminate all the noise outside the signal band.

Simple Correlator: Correlator is the match filter. The match filter significantly modifies the temporal structure by gathering the signal energy matched to its template and at the end of each symbol time presenting the result as peak amplitude.

ulaw audio decoder : audio decoder is implementing an algorithm that decompresses digital audio data according to a given audio file coding format.

Audio Sink: Represents the audio output hardware within the GRC flow graph. In the A309 lab, the signal will be played through the speakers unless there is something plugged into the headphone output on the front panel of the computer.







III.             MATLAB CODE




function v = read_complex_binary (filename, count)
%% usage: read_complex_binary (filename, [count])
%%
%% open filename and return the contents as a column vector,
%% treating them as 32 bit complex numbers
%%
m = nargchk (1,2,nargin);
if (m)
usage (m);
end
if (nargin < 2)
count = Inf;
end
f = fopen (filename, 'rb');
if (f < 0)
v = 0;
else
t = fread (f, [2, count], 'float');
fclose (f);
v = t(1,:) + t(2,:)*i;
[r, c] = size (v);
v = reshape (v, c, r);
end



Source code matlab is to convert binary file from GNU radio to hexa. From hexa, the data will plot the graph. Graph is displayed in figure 3.







IV.             RESULTS


            
          Figure 3: Noise 0v                                           Figure 4: Noise 0.5v                                      

         
          Figure 5: Noise 0.10v                                Figure 6: Noise 10v



           Figure 7: Noise 5v



     The result is shown as in constellation diagram. Noise in receivers causes noise that we know of as AWGN. We set the noise power by adjusting the noise voltage value of the channel model. We specify the voltage here instead of power because we need to know the bandwidth of the signal in order to the power properly [3]. Additive White Gaussian Noise (AWGN) environments will show its impact on system performance. While many end-to-end links use advanced error control coding and equalization, attention to the effects of phase noise on encoded system performance allows us to examine some interesting trends. We can see the effects of phase noise on Bit Error Rates (BER), Adjacent Channel Power Ratio (ACPR), Intersymbol Interference (ISI) and other specifications.


V.                DISCUSSION

 

The performance of the of the QPSK

For QPSK systems, the bit error rate (BER) was evaluated in the presence of an additive white gaussian noise (AWGN) channel in the presence of noisy phase reference. Since the QPSK phase shift difference is 90° therefore it has less possibility to estimate the correct signal or bit.

BER = (Number of errors)/(Total number of bits sent)

If the medium between the transmitter and receiver is good and the signal to noise ratio is high, then the bit error rate will be very small. The main reasons for the degradation of a data channel and the corresponding bit error rate, BER is noise and changes to the propagation path (where radio signal paths are used).

Both effects have a random element to them, the noise following a Gaussian probability function Eb/No is the measure of signal to noise ratio for a digital communication system. It is measured at the input to the receiver and is used as the basic measure of how strong the signal is.

It can be seen from using Eb/No, that the bit error rate, BER can be affected by a number of factors.

1.         Interference:   The interference levels present in a system are generally set by external factors and cannot be changed by the system design. However it is possible to set the bandwidth of the system. By reducing the bandwidth the level of interference can be reduced. Reducing the bandwidth limits the data throughput that can be achieved.

2.         Increase transmitter power:   It is also possible to increase the power level of the system so that the power per bit is increased.

3.         Lower order modulation:   Lower order modulation schemes can be used, but this is at the expense of data throughput.

4.         Reduce bandwidth:   Another approach that can be adopted to reduce the bit error rate is to reduce the bandwidth. Lower levels of noise will be received and therefore the signal to noise ratio will improve.

VI.                CONCLUSION


Bit error rate BER is a parameter which gives an excellent indication of the performance of a data link such as radio or fibre optic system. Knowledge of the BER also enables other features of the link such as the power and bandwidth, etc. to be tailored to enable the required performance to be obtained.



     REFERENCES

[1] Reinhold NoĆ©, Member, IEEE, Phase Noise-Tolerant Synchronous QPSK/BPSK Baseband-Type Intradyne Receiver Concept  With Feedforward Carrier Recovery, JOURNAL OF LIGHTWAVE  TECHNOLOGY, VOL. 23, NO. 2, FEBRUARY 2005.


APPENDIX

Source Code QPSK modulation and demodulation from GNU Radio

#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: Bpsk
# Generated: Fri Jun 12 22:04:46 2015
##################################################
from PyQt4 import Qt
from PyQt4.QtCore import QObject, pyqtSlot
from gnuradio import audio
from gnuradio import blocks
from gnuradio import channels
from gnuradio import digital
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio import qtgui
from gnuradio import vocoder
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import PyQt4.Qwt5 as Qwt
import sip
import sys
from distutils.version import StrictVersion
class BPSK(gr.top_block, Qt.QWidget):
            def __init__(self):
            gr.top_block.__init__(self, "Bpsk")
            Qt.QWidget.__init__(self)
            self.setWindowTitle("Bpsk")
            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", "BPSK")
            self.restoreGeometry(self.settings.value("geometry").toByteArray())

            ##################################################
            # Variables
            ##################################################
            self.samp_rate = samp_rate = 256e3
            self.gain = gain = 0.63
            ##################################################
            # Blocks
            ##################################################
            self._gain_layout = Qt.QVBoxLayout()
            self._gain_tool_bar = Qt.QToolBar(self)
            self._gain_layout.addWidget(self._gain_tool_bar)
            self._gain_tool_bar.addWidget(Qt.QLabel("Normalization Factor"+": "))
            class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                        Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                        super(Qwt.QwtCounter, self).setValue(value)
            self._gain_counter = qwt_counter_pyslot()
            self._gain_counter.setRange(0, 1, 1/1000)
            self._gain_counter.setNumButtons(2)
            self._gain_counter.setValue(self.gain)
            self._gain_tool_bar.addWidget(self._gain_counter)
            self._gain_counter.valueChanged.connect(self.set_gain)
            self._gain_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
            self._gain_slider.setRange(0, 1, 1/1000)
            self._gain_slider.setValue(self.gain)
            self._gain_slider.setMinimumWidth(200)
            self._gain_slider.valueChanged.connect(self.set_gain)
            self._gain_layout.addWidget(self._gain_slider)
            self.top_layout.addLayout(self._gain_layout)
            self.vocoder_ulaw_encode_sb_0 = vocoder.ulaw_encode_sb()
            self.vocoder_ulaw_decode_bs_1 = vocoder.ulaw_decode_bs()
            self.qtgui_time_sink_x_2 = qtgui.time_sink_c(
             100, #size
             samp_rate, #samp_rate
             "", #name
             1 #number of inputs
            )
            self.qtgui_time_sink_x_2.set_update_time(0.10)
            self.qtgui_time_sink_x_2.set_y_axis(-1, 1)
           
            self.qtgui_time_sink_x_2.set_y_label("Amplitude (Rx)", "")
           
            self.qtgui_time_sink_x_2.enable_tags(-1, True)
            self.qtgui_time_sink_x_2.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
            self.qtgui_time_sink_x_2.enable_autoscale(False)
            self.qtgui_time_sink_x_2.enable_grid(False)
           
            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_2.set_line_label(i, "Re{{Data {0}}}".format(i/2))
                        else:
                        self.qtgui_time_sink_x_2.set_line_label(i, "Im{{Data {0}}}".format(i/2))
            else:
                        self.qtgui_time_sink_x_2.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_2.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_2.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_2.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_2.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_2.set_line_alpha(i, alphas[i])
           
            self._qtgui_time_sink_x_2_win = sip.wrapinstance(self.qtgui_time_sink_x_2.pyqwidget(), Qt.QWidget)
            self.top_grid_layout.addWidget(self._qtgui_time_sink_x_2_win, 10,0,1,1)
            self.qtgui_time_sink_x_1 = qtgui.time_sink_c(
             100, #size
             samp_rate, #samp_rate
             "", #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 (Tx)", "")
           
            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)
           
            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_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_grid_layout.addWidget(self._qtgui_time_sink_x_1_win, 0,0,1,1)
            self.qtgui_freq_sink_x_2 = qtgui.freq_sink_c(
             1024, #size
             firdes.WIN_BLACKMAN_hARRIS, #wintype
             0, #fc
             samp_rate, #bw
             "", #name
             1 #number of inputs
            )
            self.qtgui_freq_sink_x_2.set_update_time(0.10)
            self.qtgui_freq_sink_x_2.set_y_axis(-140, 10)
            self.qtgui_freq_sink_x_2.enable_autoscale(False)
            self.qtgui_freq_sink_x_2.enable_grid(False)
            self.qtgui_freq_sink_x_2.set_fft_average(1.0)
           
            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_2.set_line_label(i, "Data {0}".format(i))
            else:
                        self.qtgui_freq_sink_x_2.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_2.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_2.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_2.set_line_alpha(i, alphas[i])
           
            self._qtgui_freq_sink_x_2_win = sip.wrapinstance(self.qtgui_freq_sink_x_2.pyqwidget(), Qt.QWidget)
            self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_2_win, 10,1,2,1)
            self.qtgui_freq_sink_x_1 = qtgui.freq_sink_c(
             1024, #size
             firdes.WIN_BLACKMAN_hARRIS, #wintype
             0, #fc
             samp_rate, #bw
             "", #name
             1 #number of inputs
            )
            self.qtgui_freq_sink_x_1.set_update_time(0.10)
            self.qtgui_freq_sink_x_1.set_y_axis(-140, 10)
            self.qtgui_freq_sink_x_1.enable_autoscale(False)
            self.qtgui_freq_sink_x_1.enable_grid(False)
            self.qtgui_freq_sink_x_1.set_fft_average(1.0)
           
            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_1.set_line_label(i, "Data {0}".format(i))
            else:
                        self.qtgui_freq_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_1.set_line_alpha(i, alphas[i])
           
            self._qtgui_freq_sink_x_1_win = sip.wrapinstance(self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget)
            self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_1_win, 0,1,2,1)
            self.qtgui_const_sink_x_2 = qtgui.const_sink_c(
             1024, #size
             "", #name
             1 #number of inputs
            )
            self.qtgui_const_sink_x_2.set_update_time(0.10)
            self.qtgui_const_sink_x_2.set_y_axis(-2, 2)
            self.qtgui_const_sink_x_2.set_x_axis(-2, 2)
            self.qtgui_const_sink_x_2.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
            self.qtgui_const_sink_x_2.enable_autoscale(False)
            self.qtgui_const_sink_x_2.enable_grid(False)
           
            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_2.set_line_label(i, "Data {0}".format(i))
            else:
                        self.qtgui_const_sink_x_2.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_2.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_2.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_2.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_2.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_2.set_line_alpha(i, alphas[i])
           
            self._qtgui_const_sink_x_2_win = sip.wrapinstance(self.qtgui_const_sink_x_2.pyqwidget(), Qt.QWidget)
            self.top_grid_layout.addWidget(self._qtgui_const_sink_x_2_win, 15,0,1,1)
            self.qtgui_const_sink_x_1 = qtgui.const_sink_c(
             1024, #size
             "", #name
             1 #number of inputs
            )
            self.qtgui_const_sink_x_1.set_update_time(0.10)
            self.qtgui_const_sink_x_1.set_y_axis(-2, 2)
            self.qtgui_const_sink_x_1.set_x_axis(-2, 2)
            self.qtgui_const_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
            self.qtgui_const_sink_x_1.enable_autoscale(False)
            self.qtgui_const_sink_x_1.enable_grid(False)
           
            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_1.set_line_label(i, "Data {0}".format(i))
            else:
                        self.qtgui_const_sink_x_1.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_1.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_1.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_1.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_1.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_1.set_line_alpha(i, alphas[i])
           
            self._qtgui_const_sink_x_1_win = sip.wrapinstance(self.qtgui_const_sink_x_1.pyqwidget(), Qt.QWidget)
            self.top_grid_layout.addWidget(self._qtgui_const_sink_x_1_win, 1,0,1,1)
            self.interp_fir_filter_xxx_1 = filter.interp_fir_filter_fff(8, (filter.firdes.root_raised_cosine(8,8,1.0,0.5,21)))
            self.interp_fir_filter_xxx_1.declare_sample_delay(0)
            self.digital_simple_framer_0 = digital.simple_framer(20)
            self.digital_simple_correlator_1 = digital.simple_correlator(20)
            self.channels_channel_model_0 = channels.channel_model(
             noise_voltage=0.10,
             frequency_offset=0.0,
             epsilon=1.0,
             taps=(1.0 + 1.0j, ),
             noise_seed=0,
             block_tags=False
            )
            self.bpsk_mod = digital.psk.psk_mod(
            constellation_points=2,
            mod_code="gray",
            differential=False,
            samples_per_symbol=2,
            excess_bw=0.35,
            verbose=False,
            log=False,
            )
            self.bpsk_demod = digital.psk.psk_demod(
            constellation_points=2,
            differential=False,
            samples_per_symbol=2,
            excess_bw=1,
            phase_bw=6.28/100.0,
            timing_bw=6.28/100.0,
            mod_code="gray",
            verbose=False,
            log=False,
            )
            self.blocks_wavfile_source_0 = blocks.wavfile_source("/media/ubuntu/SANDISK/BPSK/PCM_Mono 16-bit  8kHz.wav", True)
            self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
            self.blocks_short_to_float_1 = blocks.short_to_float(1, 1)
            self.blocks_multiply_const_vxx_4 = blocks.multiply_const_vff((1.0/32768.0, ))
            self.blocks_multiply_const_vxx_3 = blocks.multiply_const_vff((2, ))
            self.blocks_multiply_const_vxx_2 = blocks.multiply_const_vcc((gain, ))
            self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((32768, ))
            self.blocks_float_to_short_0 = blocks.float_to_short(1, 1)
            self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, "/media/ubuntu/SANDISK/BPSK/noise0.10", False)
            self.blocks_file_sink_0.set_unbuffered(False)
            self.blocks_char_to_float_1 = blocks.char_to_float(1, 1)
            self.blocks_add_const_vxx_1 = blocks.add_const_vff((-1, ))
            self.audio_sink_1 = audio.sink(8000, "", True)
            ##################################################
            # Connections
            ##################################################
            self.connect((self.blocks_float_to_short_0, 0), (self.vocoder_ulaw_encode_sb_0, 0))
            self.connect((self.vocoder_ulaw_encode_sb_0, 0), (self.digital_simple_framer_0, 0))
            self.connect((self.digital_simple_correlator_1, 0), (self.vocoder_ulaw_decode_bs_1, 0))
            self.connect((self.interp_fir_filter_xxx_1, 0), (self.digital_simple_correlator_1, 0))
            self.connect((self.vocoder_ulaw_decode_bs_1, 0), (self.blocks_short_to_float_1, 0))
            self.connect((self.blocks_add_const_vxx_1, 0), (self.interp_fir_filter_xxx_1, 0))
            self.connect((self.blocks_multiply_const_vxx_3, 0), (self.blocks_add_const_vxx_1, 0))
            self.connect((self.blocks_short_to_float_1, 0), (self.blocks_multiply_const_vxx_4, 0))
            self.connect((self.blocks_multiply_const_vxx_4, 0), (self.audio_sink_1, 0))
            self.connect((self.bpsk_demod, 0), (self.blocks_char_to_float_1, 0))
            self.connect((self.digital_simple_framer_0, 0), (self.bpsk_mod, 0))
            self.connect((self.bpsk_mod, 0), (self.blocks_multiply_const_vxx_2, 0))
            self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_multiply_const_vxx_0, 0))
            self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_short_0, 0))
            self.connect((self.blocks_multiply_const_vxx_2, 0), (self.qtgui_const_sink_x_1, 0))
            self.connect((self.blocks_multiply_const_vxx_2, 0), (self.qtgui_freq_sink_x_1, 0))
            self.connect((self.blocks_char_to_float_1, 0), (self.blocks_multiply_const_vxx_3, 0))
            self.connect((self.blocks_multiply_const_vxx_2, 0), (self.qtgui_time_sink_x_1, 0))
            self.connect((self.channels_channel_model_0, 0), (self.bpsk_demod, 0))
            self.connect((self.channels_channel_model_0, 0), (self.qtgui_time_sink_x_2, 0))
            self.connect((self.channels_channel_model_0, 0), (self.qtgui_const_sink_x_2, 0))
            self.connect((self.channels_channel_model_0, 0), (self.qtgui_freq_sink_x_2, 0))
            self.connect((self.blocks_throttle_0, 0), (self.channels_channel_model_0, 0))
            self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_throttle_0, 0))
            self.connect((self.channels_channel_model_0, 0), (self.blocks_file_sink_0, 0))

            def closeEvent(self, event):
            self.settings = Qt.QSettings("GNU Radio", "BPSK")
            self.settings.setValue("geometry", self.saveGeometry())
            event.accept()
            def get_samp_rate(self):
            return self.samp_rate
            def set_samp_rate(self, samp_rate):
            self.samp_rate = samp_rate
            self.qtgui_time_sink_x_1.set_samp_rate(self.samp_rate)
            self.blocks_throttle_0.set_sample_rate(self.samp_rate)
            self.qtgui_time_sink_x_2.set_samp_rate(self.samp_rate)
            self.qtgui_freq_sink_x_2.set_frequency_range(0, self.samp_rate)
            self.qtgui_freq_sink_x_1.set_frequency_range(0, self.samp_rate)
            def get_gain(self):
            return self.gain
            def set_gain(self, gain):
            self.gain = gain
            Qt.QMetaObject.invokeMethod(self._gain_counter, "setValue", Qt.Q_ARG("double", self.gain))
            Qt.QMetaObject.invokeMethod(self._gain_slider, "setValue", Qt.Q_ARG("double", self.gain))
            self.blocks_multiply_const_vxx_2.set_k((self.gain, ))
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()"
            parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
            (options, args) = parser.parse_args()
            if(StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0")):
            Qt.QApplication.setGraphicsSystem(gr.prefs().get_string('qtgui','style','raster'))
            qapp = Qt.QApplication(sys.argv)
            tb = BPSK()
            tb.start()
            tb.show()
            def quitting():
            tb.stop()
            tb.wait()
            qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
            qapp.exec_()
            tb = None #to clean up Qt widgets