Ejemplo n.º 1
0
    def test_001_t(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        freq = 100  # frequency of source signal

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = snr.channel_model_snr(
            0.0, 0.0, 1.0, [
                1,
            ], 0
        )  # noise_voltage, frequency_offset, epsilon, taps, noise_seed, block_tags
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        op.set_noise_voltage(0.1)
        op.set_frequency_offset(0.0)
        op.set_taps([
            1,
        ])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, snk)
        self.tb.connect(op, snk1)
        self.tb.run()

        dst_data = snk.data()
        exp_data = snk1.data()
        self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
Ejemplo n.º 2
0
def simulate_other_est(SNR_range, est_type):
    """ Create flow graph, run, read out estimated SNR with usage of gnuradio implemented estimator
    :param SNR_range: range of SNR for which noise voltage will be calculated
    """
    est_snr = []
    for SNR in SNR_range:
        noise_volt = noise_voltage(SNR)

        src = blocks.vector_source_c(bits.tolist(), False)
        chn = snr.channel_model_snr(0.0, 0.0, 1.0, [1, ],
                                    0)  # noise_voltage, frequency_offset, epsilon, taps, noise_seed, block_tags
        est = digital.mpsk_snr_est_cc(est_type, ntag, alpha)
        sink = blocks.null_sink(gr.sizeof_gr_complex)

        chn.set_noise_voltage(noise_volt)
        tb = gr.top_block()
        tb.connect(src, chn, est, sink)
        tb.run()

        est_snr.append(est.snr())
    return est_snr
Ejemplo n.º 3
0
def simulate_general_est(SNR_range):
    """ All the work's done here: create flow graph, run, read out estimated SNR
    :param SNR_range: range of SNR for which noise voltage will be calculated
    """
    est_snr = []
    for SNR in SNR_range:
        noise_volt = noise_voltage(SNR)

        src = blocks.vector_source_c(bits.tolist(), False)
        chn = snr.channel_model_snr(0.0, 0.0, 1.0, [1, ],
                                    0)  # noise_voltage, frequency_offset, epsilon, taps, noise_seed, block_tags
        chn.set_noise_voltage(noise_volt)
        est = snr.mpsk_receiver_snr_est_cc(ntag, alpha)
        sink = blocks.null_sink(gr.sizeof_gr_complex)

        tb = gr.top_block()
        tb.connect(src, chn, est, sink)
        tb.run()

        est_snr.append(est.snr())
    return est_snr
Ejemplo n.º 4
0
    def test_001_t (self):
        N = 1000                # number of samples to use
        fs = 1000               # baseband sampling rate
        freq = 100              # frequency of source signal
        noise_volt = 0.18       # noise voltage [V]

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = snr.channel_model_snr(0.0, 0.0, 1.0, [1,], 0) # noise_voltage, frequency_offset, epsilon, taps, noise_seed, block_tags
        est = snr.mpsk_receiver_snr_est_cc(1000, 0.001) # ntag, alpha
        snk = blocks.vector_sink_c()

        op.set_noise_voltage(0.18)
        op.set_frequency_offset(0.0)
        op.set_taps([1,])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, est, snk)
        self.tb.run()

        est_snr = est.snr()
        exp_snr = 20*math.log10(1/noise_volt)
Ejemplo n.º 5
0
    def test_001_t (self):
        N = 1000         # number of samples to use
        fs = 1000        # baseband sampling rate
        freq = 100       # frequency of source signal

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = snr.channel_model_snr(0.0, 0.0, 1.0, [1,], 0) # noise_voltage, frequency_offset, epsilon, taps, noise_seed, block_tags
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        op.set_noise_voltage(0.1)
        op.set_frequency_offset(0.0)
        op.set_taps([1,])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, snk)
        self.tb.connect(op, snk1)
        self.tb.run()

        dst_data = snk.data()
        exp_data = snk1.data()
        self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
Ejemplo n.º 6
0
    def test_001_t(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        freq = 100  # frequency of source signal
        noise_volt = 0.18  # noise voltage [V]

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = snr.channel_model_snr(
            0.0, 0.0, 1.0, [1], 0
        )  # noise_voltage, frequency_offset, epsilon, taps, noise_seed, block_tags
        est = snr.mpsk_receiver_snr_est_cc(1000, 0.001)  # ntag, alpha
        snk = blocks.vector_sink_c()

        op.set_noise_voltage(0.18)
        op.set_frequency_offset(0.0)
        op.set_taps([1])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, est, snk)
        self.tb.run()

        est_snr = est.snr()
        exp_snr = 20 * math.log10(1 / noise_volt)
Ejemplo n.º 7
0
    def __init__(self):
        gr.top_block.__init__(self, "Mpsk Simul")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Mpsk Simul")
        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", "mpsk_simul")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.sps = sps = 8
        self.nfilts = nfilts = 32
        self.timing_loop_bw = timing_loop_bw = 6.28/100.0
        self.time_offset = time_offset = 1.00
        self.taps = taps = [1.0 + 0.0j, ]
        self.samp_rate = samp_rate = 32000
        self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(sps), 0.35, 11*sps*nfilts)
        self.phase_bw = phase_bw = 6.28/100.0
        self.noise_volt = noise_volt = 0.001
        self.freq_offset = freq_offset = 0
        self.eq_gain = eq_gain = 0.01
        self.arity = arity = 8

        ##################################################
        # 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, "Time: BW", "slider", float)
        self.top_grid_layout.addWidget(self._timing_loop_bw_win, 3,1,1,1)
        self._time_offset_range = Range(0.999, 1.001, 0.0001, 1.00, 200)
        self._time_offset_win = RangeWidget(self._time_offset_range, self.set_time_offset, "Channel: Timing Offset", "slider", float)
        self.top_grid_layout.addWidget(self._time_offset_win, 3,0,1,1)
        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, "Phase: Bandwidth", "slider", float)
        self.top_grid_layout.addWidget(self._phase_bw_win, 4,1,1,1)
        self._noise_volt_range = Range(0, 1, 0.01, 0.001, 200)
        self._noise_volt_win = RangeWidget(self._noise_volt_range, self.set_noise_volt, "Channel: Noise Voltage", "slider", float)
        self.top_grid_layout.addWidget(self._noise_volt_win, 2,0,1,1)
        self._freq_offset_range = Range(-0.1, 0.1, 0.001, 0, 200)
        self._freq_offset_win = RangeWidget(self._freq_offset_range, self.set_freq_offset, "Channel: Frequency Offset", "slider", float)
        self.top_grid_layout.addWidget(self._freq_offset_win, 2,1,1,1)
        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, "Equalizer: rate", "slider", float)
        self.top_grid_layout.addWidget(self._eq_gain_win, 4,0,1,1)
        self.snr_mpsk_receiver_snr_est_cc_0 = snr.mpsk_receiver_snr_est_cc(10000, 0.001)
        self.snr_channel_model_snr_0 = snr.channel_model_snr(
          noise_voltage=noise_volt,
          frequency_offset=freq_offset,
          epsilon=time_offset,
          taps=(taps),
          noise_seed=0,
          block_tags=False
        )
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	4000, #size
        	samp_rate, #samp_rate
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.01)
        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(False)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        
        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_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 0,0,1,1)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
        	1024, #size
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(0.10)
        self.qtgui_const_sink_x_0.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_x_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
        self.qtgui_const_sink_x_0.enable_autoscale(False)
        self.qtgui_const_sink_x_0.enable_grid(False)
        
        if not True:
          self.qtgui_const_sink_x_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.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_const_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win, 0,1,1,1)
        self.digital_psk_mod_0 = digital.psk.psk_mod(
          constellation_points=arity,
          mod_code="gray",
          differential=True,
          samples_per_symbol=sps,
          excess_bw=0.35,
          verbose=False,
          log=False,
          )
        self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, timing_loop_bw, (rrc_taps), nfilts, nfilts/2, 1.5, 2)
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(phase_bw, arity, False)
        self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(15, 1, eq_gain, 2)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((1+1j, ))
        self.blocks_message_debug_0 = blocks.message_debug()
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 10000)), True)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.snr_channel_model_snr_0, 'snr_level_out'), (self.snr_mpsk_receiver_snr_est_cc_0, 'snr_level_in'))    
        self.connect((self.analog_random_source_x_0, 0), (self.digital_psk_mod_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.snr_channel_model_snr_0, 0))    
        self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0))    
        self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0))    
        self.connect((self.digital_costas_loop_cc_0, 1), (self.qtgui_time_sink_x_0, 0))    
        self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_cma_equalizer_cc_0, 0))    
        self.connect((self.digital_psk_mod_0, 0), (self.blocks_multiply_const_vxx_0, 0))    
        self.connect((self.snr_channel_model_snr_0, 0), (self.snr_mpsk_receiver_snr_est_cc_0, 0))    
        self.connect((self.snr_mpsk_receiver_snr_est_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0))