def __init__(self, noise_mag=0, alpha=0.1): gr.hier_block2.__init__( self, "Phase Noise Generator", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.noise_mag = noise_mag self.alpha = alpha ################################################## # Blocks ################################################## self.filter_single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(alpha, 1) self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, noise_mag, 42) ################################################## # Connections ################################################## self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_noise_source_x_0, 0), (self.filter_single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0, 1))
def __init__(self): gr.hier_block2.__init__( self, "Staticphaseshifter", gr.io_signaturev(2, 2, [gr.sizeof_gr_complex*1, gr.sizeof_float*1]), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Blocks ################################################## self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1) ################################################## # Connections ################################################## self.connect((self, 1), (self.blocks_transcendental_0_0, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self, 0)) self.connect((self.blocks_float_to_complex_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0_0, 0)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0_0, 1)) self.connect((self, 1), (self.blocks_transcendental_0, 0))
def __init__(self): gr.hier_block2.__init__( self, "Staticphaseshifter", gr.io_signaturev(2, 2, [gr.sizeof_gr_complex * 1, gr.sizeof_float * 1]), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) ################################################## # Blocks ################################################## self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1) ################################################## # Connections ################################################## self.connect((self, 1), (self.blocks_transcendental_0_0, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self, 0)) self.connect((self.blocks_float_to_complex_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0_0, 0)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0_0, 1)) self.connect((self, 1), (self.blocks_transcendental_0, 0))
def test_002_t(self): # Generate frames with AWGN and test SNR estimation sample_rate = 10.0e6 frame_duration = 1.0e-3 test_duration = 0.1 * frame_duration snr = 10 scale_value = 15.0 samples_per_frame = int(round(frame_duration * sample_rate)) samples_per_test = int(round(test_duration * sample_rate)) random_samples_skip = 0 #np.random.randint(samples_per_frame) preamble_seq = zadoffchu(63, 1, 0) preamble_pwr_sum = np.sum(np.abs(preamble_seq)**2) print "***** Start test 002 *****" framer = specmonitor.framer_c(sample_rate, frame_duration, preamble_seq) awgn = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0 / snr) add = blocks.add_cc() scaler = blocks.multiply_const_vcc([complex(scale_value)]) mag2 = blocks.complex_to_mag_squared() mavg = blocks.moving_average_ff( len(preamble_seq), 1.0 / len(preamble_seq) ) # i need to divide by the preamble size in case the preamble seq has amplitude 1 (sum of power is len) sqrtavg = blocks.transcendental("sqrt") # I have to compensate the amplitude of the input signal (scale) either through a feedback normalization loop that computes the scale, or manually (not practical) # additionally I have to scale down by the len(preamble)==sum(abs(preamble)^2) because the cross-corr does not divide by the preamble length #scaler2 = blocks.multiply_const_vcc([complex(1.0)/scale_value/len(preamble_seq)]) # if no feedback normalization loop, I have to scale the signal compensating additionally the scaling factor corr_est = specmonitor.corr_est_norm_cc( preamble_seq, 1, 0) #digital.corr_est_cc(preamble_seq, 1, 0) tag_db = blocks.tag_debug(gr.sizeof_gr_complex, "tag debugger") head = blocks.head(gr.sizeof_gr_complex, samples_per_test) dst = blocks.vector_sink_c() skiphead = blocks.skiphead(gr.sizeof_float, random_samples_skip) skiphead2 = blocks.skiphead(gr.sizeof_gr_complex, random_samples_skip) skiphead3 = blocks.skiphead(gr.sizeof_gr_complex, random_samples_skip) debug_vec = blocks.vector_sink_f() debug_vec2 = blocks.vector_sink_c() debug_vec3 = blocks.vector_sink_c() self.tb.connect(framer, (add, 0)) self.tb.connect(awgn, (add, 1)) self.tb.connect(add, scaler) self.tb.connect(scaler, mag2, mavg, sqrtavg) self.tb.connect(scaler, corr_est) self.tb.connect(corr_est, tag_db) self.tb.connect(corr_est, head, dst) self.tb.connect(sqrtavg, skiphead, debug_vec) self.tb.connect(scaler, skiphead2, debug_vec2) self.tb.run() result_data = dst.data() debug_vec_data = debug_vec.data() debug_vec_data2 = debug_vec2.data() debug_vec_data3 = debug_vec3.data()
def __init__(self, noise_mag=0, alpha=0.1): gr.hier_block2.__init__( self, "Phase Noise Generator", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) ################################################## # Parameters ################################################## self.noise_mag = noise_mag self.alpha = alpha ################################################## # Blocks ################################################## self.filter_single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( alpha, 1) self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.analog_noise_source_x_0 = analog.noise_source_f( analog.GR_GAUSSIAN, noise_mag, 42) ################################################## # Connections ################################################## self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_noise_source_x_0, 0), (self.filter_single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0, 1))
def test_03(self): tb = self.tb data = 100*[3,] expected_result = 100*[math.tanh(3),] src = blocks.vector_source_f(data, False) op = blocks.transcendental("tanh", "float") dst = blocks.vector_sink_f() tb.connect(src, op) tb.connect(op, dst) tb.run() dst_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
def test_03(self): tb = self.tb data = 100 * [ 3, ] expected_result = 100 * [ math.tanh(3), ] src = blocks.vector_source_f(data, False) op = blocks.transcendental("tanh", "float") dst = blocks.vector_sink_f() tb.connect(src, op) tb.connect(op, dst) tb.run() dst_data = dst.data() self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
def __init__(self, rxPort=52002, txPort=52001): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Parameters ################################################## self.rxPort = rxPort self.txPort = txPort ################################################## # Variables ################################################## self.localOscillator = localOscillator = 14070000 self.threshold = threshold = -200 self.samp_rate = samp_rate = 48000 self.rxPhase = rxPhase = .84 self.rxMagnitude = rxMagnitude = 0.854 self.freqFine = freqFine = 0 self.freq = freq = localOscillator self.bandwidth = bandwidth = 50 ################################################## # Blocks ################################################## _threshold_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_sizer, value=self.threshold, callback=self.set_threshold, label="threshold", converter=forms.float_converter(), proportion=0, ) self._threshold_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_sizer, value=self.threshold, callback=self.set_threshold, minimum=-500, maximum=500, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_threshold_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "tuning") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "scope") self.Add(self.notebook_0) _freqFine_sizer = wx.BoxSizer(wx.VERTICAL) self._freqFine_text_box = forms.text_box( parent=self.GetWin(), sizer=_freqFine_sizer, value=self.freqFine, callback=self.set_freqFine, label="Tuning", converter=forms.float_converter(), proportion=0, ) self._freqFine_slider = forms.slider( parent=self.GetWin(), sizer=_freqFine_sizer, value=self.freqFine, callback=self.set_freqFine, minimum=-500, maximum=500, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_freqFine_sizer) _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="Frequency", 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=localOscillator-samp_rate, maximum=localOscillator+samp_rate, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_freq_sizer) _bandwidth_sizer = wx.BoxSizer(wx.VERTICAL) self._bandwidth_text_box = forms.text_box( parent=self.GetWin(), sizer=_bandwidth_sizer, value=self.bandwidth, callback=self.set_bandwidth, label="Signal Bandwidth", converter=forms.float_converter(), proportion=0, ) self._bandwidth_slider = forms.slider( parent=self.GetWin(), sizer=_bandwidth_sizer, value=self.bandwidth, callback=self.set_bandwidth, minimum=30, maximum=5000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_bandwidth_sizer) self.wxgui_waterfallsink2_0_0_0 = waterfallsink2.waterfall_sink_c( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=125*8, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.notebook_0.GetPage(1).Add(self.wxgui_waterfallsink2_0_0_0.win) self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=125*8, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.notebook_0.GetPage(0).Add(self.wxgui_waterfallsink2_0_0.win) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=localOscillator, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.notebook_0.GetPage(0).Add(self.wxgui_waterfallsink2_0.win) self.low_pass_filter_0_1 = filter.fir_filter_ccf(samp_rate/125/8, firdes.low_pass( 1, samp_rate, 500, 500, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_0 = filter.interp_fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 30, 30, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(samp_rate/125/8, firdes.low_pass( 1, samp_rate, bandwidth, bandwidth, firdes.WIN_HAMMING, 6.76)) self.digital_mpsk_receiver_cc_0 = digital.mpsk_receiver_cc(2, 0, cmath.pi/100.0, -0.5, 0.5, 0.25, 0.01, 125*8/31.25, 0.001, 0.001) self.blocks_transcendental_1 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_throttle_0_1 = blocks.throttle(gr.sizeof_float*1, samp_rate) self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, 31.25) self.blocks_threshold_ff_0 = blocks.threshold_ff(1e-12, 1e-12, 0) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_float*1, int(samp_rate/31.25)) self.blocks_null_source_1 = blocks.null_source(gr.sizeof_float*1) self.blocks_null_source_0_0 = blocks.null_source(gr.sizeof_float*1) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_float*1) self.blocks_multiply_xx_0_2 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_vff((rxMagnitude, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((2, )) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_float_to_complex_1_0 = blocks.float_to_complex(1) self.blocks_float_to_complex_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_float_to_char_0 = blocks.float_to_char(1, 1) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, )) self.blks2_tcp_source_0 = grc_blks2.tcp_source( itemsize=gr.sizeof_char*1, addr="127.0.0.1", port=txPort, server=False, ) self.blks2_tcp_sink_0 = grc_blks2.tcp_sink( itemsize=gr.sizeof_char*1, addr="127.0.0.1", port=rxPort, server=False, ) self.audio_source_0 = audio.source(samp_rate, "", True) self.audio_sink_0 = audio.sink(samp_rate, "", True) self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(threshold, 1) self.analog_sig_source_x_1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -freqFine, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq+freqFine-localOscillator, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_SIN_WAVE, -(freq-localOscillator), 1, 0) self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, rxPhase*3.14159/180.0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.blks2_tcp_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.blocks_throttle_0_1, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_float_to_complex_0_1, 0), (self.blocks_multiply_xx_0_1, 1)) self.connect((self.analog_const_source_x_0, 0), (self.blocks_transcendental_1, 0)) self.connect((self.analog_const_source_x_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0_1, 0)) self.connect((self.blocks_transcendental_1, 0), (self.blocks_float_to_complex_0_1, 1)) self.connect((self.blocks_null_source_0, 0), (self.blocks_float_to_complex_1, 0)) self.connect((self.audio_source_0, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_float_to_complex_1, 1)) self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_multiply_xx_0_1, 0)) self.connect((self.blocks_null_source_0_0, 0), (self.blocks_float_to_complex_1_0, 1)) self.connect((self.audio_source_0, 1), (self.blocks_float_to_complex_1_0, 0)) self.connect((self.blocks_float_to_complex_1_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0_0, 0)) self.connect((self.blocks_null_source_1, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_throttle_0_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.blks2_tcp_sink_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.analog_simple_squelch_cc_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.analog_simple_squelch_cc_0, 0)) self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.blocks_delay_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_throttle_0_1, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_multiply_xx_0_2, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0_2, 1)) self.connect((self.blocks_multiply_xx_0_2, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0_1, 0)) self.connect((self.low_pass_filter_0_1, 0), (self.wxgui_waterfallsink2_0_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.digital_mpsk_receiver_cc_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.wxgui_waterfallsink2_0_0_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.audio_sink_0, 1)) self.connect((self.blocks_complex_to_float_0, 1), (self.audio_sink_0, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.wxgui_waterfallsink2_0, 0))
def __init__(self): gr.top_block.__init__(self, "Lab 4 Task 1b") Qt.QWidget.__init__(self) self.setWindowTitle("Lab 4 Task 1b") qtgui.util.check_set_qss() 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", "lab4_task1b") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry(self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.samp_rate = samp_rate = 320000 self.amplitude = amplitude = 10e-6 ################################################## # Blocks ################################################## self._amplitude_range = Range(10e-6, 100e-3, 1e-4, 10e-6, 200) self._amplitude_win = RangeWidget(self._amplitude_range, self.set_amplitude, 'amplitude', "slider", float) self.top_grid_layout.addWidget(self._amplitude_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw 'Differential Output', #name 1 ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') 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(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) 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 range(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_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.blocks_transcendental_0 = blocks.transcendental('tanh', "float") self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(amplitude/(0.025)) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_float*1, '/home/ipsit/Documents/EE 340/Lab 4/Input.bin', True, 0, 0) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) ################################################## # Connections ################################################## self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_throttle_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="FM_TX") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 200000 self.fm = fm = 2000 self.fc = fc = samp_rate / 8 self.beta = beta = 4 ################################################## # 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.notebook.AddPage(grc_wxgui.Panel(self.notebook), "tab3") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "tab4") self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "tab5") self.Add(self.notebook) _fm_sizer = wx.BoxSizer(wx.VERTICAL) self._fm_text_box = forms.text_box( parent=self.GetWin(), sizer=_fm_sizer, value=self.fm, callback=self.set_fm, label='fm', converter=forms.float_converter(), proportion=0, ) self._fm_slider = forms.slider( parent=self.GetWin(), sizer=_fm_sizer, value=self.fm, callback=self.set_fm, minimum=0, maximum=10000, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_fm_sizer) _fc_sizer = wx.BoxSizer(wx.VERTICAL) self._fc_text_box = forms.text_box( parent=self.GetWin(), sizer=_fc_sizer, value=self.fc, callback=self.set_fc, label='fc', converter=forms.float_converter(), proportion=0, ) self._fc_slider = forms.slider( parent=self.GetWin(), sizer=_fc_sizer, value=self.fc, callback=self.set_fc, minimum=0, maximum=samp_rate / 2, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_fc_sizer) _beta_sizer = wx.BoxSizer(wx.VERTICAL) self._beta_text_box = forms.text_box( parent=self.GetWin(), sizer=_beta_sizer, value=self.beta, callback=self.set_beta, label='beta', converter=forms.float_converter(), proportion=0, ) self._beta_slider = forms.slider( parent=self.GetWin(), sizer=_beta_sizer, value=self.beta, callback=self.set_beta, minimum=0, maximum=4, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_beta_sizer) self.wxgui_scopesink2_2_0 = scopesink2.scope_sink_f( self.notebook.GetPage(1).GetWin(), title='FM Scop Plot', sample_rate=samp_rate * 1, 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_2_0.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.notebook.GetPage(0).GetWin(), title='Integrated Message', 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(0).Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_1 = fftsink2.fft_sink_f( self.notebook.GetPage(2).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=False, avg_alpha=None, title='FM FFT Plot', peak_hold=False, ) self.notebook.GetPage(2).Add(self.wxgui_fftsink2_1.win) self.blocks_transcendental_1 = blocks.transcendental('sin', "float") self.blocks_transcendental_0 = blocks.transcendental('cos', "float") self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate, True) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((beta, )) self.blocks_add_xx_0 = blocks.add_vff(1) self.analog_sig_source_x_1_0 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, fc, 1, 0) self.analog_sig_source_x_1 = analog.sig_source_f( samp_rate, analog.GR_SIN_WAVE, fc, -1, 0) self.analog_sig_source_x_0_1 = analog.sig_source_f( samp_rate, analog.GR_SIN_WAVE, fm, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0_1, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.analog_sig_source_x_0_1, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.analog_sig_source_x_1_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_transcendental_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_transcendental_1, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.blocks_throttle_0, 0), (self.wxgui_scopesink2_2_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_transcendental_1, 0), (self.blocks_multiply_xx_0_0, 0))
def test_001_t (self): # to test we add gaussian phase jitter and additive gaussian noise to the source vector # Each vector has all constellation values number_of_vectors = 50000 dim_constellation = 16 #Our phase jitter probe estimator, estimates the jitter variance and the snr. #gaussian noise added in "volts", the channel add noise with variance noise*noise to each axe I and Q noise = 0.02 # the variance of the phase jitter is math.pow(10.0,phase_noise_mag/20.0) * math.pow(10.0,phase_noise_mag/20.0) # the estimator works fine with an error of around 5-10% with additive noise with standard deviation of 0.01 to 0.03 and phase_noise_mag between -20 (standard deviation = 0.1 radians, approx 6 degrees) and -40 (phase_noise_mag = -40, standard deviation = 0.01 radians approx 0.6 degrees). These values are assuming that pj and snr are filtered. We are averaging the results but we are not filtering the phase jitter noise. If the additive noise is very low the snr estimator has errors and if the additive noise is very high or the phase jitter noise is very high there are many decision errors. phase_noise_mag = -30 #In hardware impairments thre is a single pole iir filter to filter the gaussian noise, we are not filtering the noise using alpha equal one alpha = 1 # creates the probe_pj object withe the symbol table and alpha self.mer_probe_pj_cf_0 = mer.probe_pj_cf((0.9487+0.9487j,0.9487+0.3162j, 0.3162+0.9487j, 0.3162 +0.3162j,0.9487-0.9487j,0.9487- 0.3162j, 0.3162-0.9487j, 0.3162- 0.3162j,-0.9487+0.9487j,-0.9487+ 0.3162j,- 0.3162+0.9487j,- 0.3162+ 0.3162j,-0.9487-0.9487j,-0.9487- 0.3162j,-0.3162-0.9487j,-0.3162- 0.3162j),0.005) #creates a source with all possible symbols repited number_of_vectors src_const = (0.9487+0.9487j,0.9487+0.3162j, 0.3162+0.9487j, 0.3162 +0.3162j,0.9487-0.9487j,0.9487- 0.3162j, 0.3162-0.9487j, 0.3162- 0.3162j,-0.9487+0.9487j,-0.9487+ 0.3162j,- 0.3162+0.9487j,- 0.3162+ 0.3162j,-0.9487-0.9487j,-0.9487- 0.3162j,-0.3162-0.9487j,-0.3162- 0.3162j)*number_of_vectors #creates the blocks and sinks to receive the estimations self.src = blocks.vector_source_c(src_const,False) self.dst0 = blocks.vector_sink_f() self.dst1 = blocks.vector_sink_f() # add a channel model to add additive gaussian noise self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise, frequency_offset=0.0, epsilon=1.0, taps=(1, ), noise_seed=0, block_tags=False ) # A gaussian noise w is generated and filtered w1,a complex signal a= cos(w1) + j sin(w1) is generated # Source data src is added with white noise src1, the output signal with phase jitter and additive noise is a * src1 # the output signal a*src1 is send to the phase jitter probe and the pj and snr are estimated # to filter the gaussian noise added to the phase, we are using alpha equal 1 so we are not filtering self.filter_single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(alpha, 1) self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, math.pow(10.0,phase_noise_mag/20.0), 42) ################################################## # Connections ################################################## self.tb.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 1)) self.tb.connect((self.analog_noise_source_x_0, 0), (self.filter_single_pole_iir_filter_xx_0, 0)) self.tb.connect((self.blocks_multiply_xx_0, 0), (self.mer_probe_pj_cf_0, 0)) self.tb.connect((self.src, 0), (self.channels_channel_model_0, 0)) self.tb.connect((self.channels_channel_model_0, 0), (self.blocks_multiply_xx_0, 0)) self.tb.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0, 0)) self.tb.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0_0, 0)) self.tb.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0, 0)) self.tb.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0, 1)) self.tb.connect((self.mer_probe_pj_cf_0, 0),(self.dst0, 0)) self.tb.connect((self.mer_probe_pj_cf_0, 1),(self.dst1, 0)) self.tb.run () result_data1 = np.mean(self.dst0.data()[number_of_vectors*dim_constellation-dim_constellation*10000:number_of_vectors*dim_constellation]) result_data2 = np.mean(self.dst1.data()[number_of_vectors*dim_constellation-dim_constellation*10000:number_of_vectors*dim_constellation]) print " result phase jitter variance = ",result_data1 print " result snr = ",result_data2 expected_result1 = math.pow(10.0,phase_noise_mag/20.0) * math.pow(10.0,phase_noise_mag/20.0) print " expected result phase jitter variance = ", expected_result1 expected_result2 = 10*np.log10(1.0/noise/noise/2) print " expected result snr = ",expected_result2 #test an error in the phase jitter variance less than 10 %, self.assertLessEqual(abs((result_data1-expected_result1)/expected_result1), 0.1 ) #test an error in the snr less than 10 %, self.assertLessEqual(abs((result_data2-expected_result2)/expected_result2), 0.1 )
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.dn = dn = 10e-6 self.dA = dA = 0.01 ################################################## # Blocks ################################################## _dn_sizer = wx.BoxSizer(wx.VERTICAL) self._dn_text_box = forms.text_box( parent=self.GetWin(), sizer=_dn_sizer, value=self.dn, callback=self.set_dn, label='dn', converter=forms.float_converter(), proportion=0, ) self._dn_slider = forms.slider( parent=self.GetWin(), sizer=_dn_sizer, value=self.dn, callback=self.set_dn, minimum=0, maximum=30e-3, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_dn_sizer) _dA_sizer = wx.BoxSizer(wx.VERTICAL) self._dA_text_box = forms.text_box( parent=self.GetWin(), sizer=_dA_sizer, value=self.dA, callback=self.set_dA, label='dA', converter=forms.float_converter(), proportion=0, ) self._dA_slider = forms.slider( parent=self.GetWin(), sizer=_dA_sizer, value=self.dA, callback=self.set_dA, minimum=0.01, maximum=1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_dA_sizer) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.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=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.blocks_transcendental_0 = blocks.transcendental("tanh", "float") self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_vff((dn, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((20, )) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_float * 1, "/media/debarnab/Windows8_OS/Users/user/Desktop/5th Sem/EE340/Lab6/Input (1).bin", True) self.blocks_add_xx_0 = blocks.add_vff(1) self.analog_sig_source_x_0 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, 3.3e3, dA, 0) ################################################## # Connections ################################################## self.connect((self.blocks_transcendental_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_add_xx_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 1))
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_rate = samp_rate = 32000 self.amplitude = amplitude = 10e-6 ################################################## # Blocks ################################################## self._amplitude_range = Range(10e-6, 30e-3, 1e-3, 10e-6, 200) self._amplitude_win = RangeWidget(self._amplitude_range, self.set_amplitude, "amplitude", "counter_slider", float) self.top_layout.addWidget(self._amplitude_win) self.qtgui_sink_x_0 = qtgui.sink_f( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #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.blocks_transcendental_0 = blocks.transcendental("tanh", "float") self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate, True) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (1.0 / (2 * 0.025) * amplitude, )) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_float * 1, "/home/alok/Desktop/5TH-SEM/EE340/Lab6/Input.bin", True) ################################################## # Connections ################################################## self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_throttle_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.sliderFc = sliderFc = 20000 self.sliderBeta = sliderBeta = 1 self.samp_rate = samp_rate = 200000 ################################################## # Blocks ################################################## _sliderFc_sizer = wx.BoxSizer(wx.VERTICAL) self._sliderFc_text_box = forms.text_box( parent=self.GetWin(), sizer=_sliderFc_sizer, value=self.sliderFc, callback=self.set_sliderFc, label='sliderFc', converter=forms.float_converter(), proportion=0, ) self._sliderFc_slider = forms.slider( parent=self.GetWin(), sizer=_sliderFc_sizer, value=self.sliderFc, callback=self.set_sliderFc, minimum=0, maximum=100000, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_sliderFc_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.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=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) _sliderBeta_sizer = wx.BoxSizer(wx.VERTICAL) self._sliderBeta_text_box = forms.text_box( parent=self.GetWin(), sizer=_sliderBeta_sizer, value=self.sliderBeta, callback=self.set_sliderBeta, label='sliderBeta', converter=forms.float_converter(), proportion=0, ) self._sliderBeta_slider = forms.slider( parent=self.GetWin(), sizer=_sliderBeta_sizer, value=self.sliderBeta, callback=self.set_sliderBeta, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_sliderBeta_sizer) self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_integrate_xx_0 = blocks.integrate_ff(1) self.analog_sig_source_x_0_0_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, sliderFc, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, sliderFc, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 1000, 1, 0) self.Beta = blocks.multiply_const_vff((sliderBeta, )) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.Beta, 0)) self.connect((self.Beta, 0), (self.blocks_transcendental_0, 0)) self.connect((self.Beta, 0), (self.blocks_transcendental_0_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.analog_sig_source_x_0_0_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_sub_xx_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.wxgui_fftsink2_0, 0))
def test_001_t(self): # to test we add gaussian phase jitter and additive gaussian noise to the source vector # Each vector has all constellation values number_of_vectors = 50000 dim_constellation = 16 #Our phase jitter probe estimator, estimates the jitter variance and the snr. #gaussian noise added in "volts", the channel add noise with variance noise*noise to each axe I and Q noise = 0.02 # the variance of the phase jitter is math.pow(10.0,phase_noise_mag/20.0) * math.pow(10.0,phase_noise_mag/20.0) # the estimator works fine with an error of around 5-10% with additive noise with standard deviation of 0.01 to 0.03 and phase_noise_mag between -20 (standard deviation = 0.1 radians, approx 6 degrees) and -40 (phase_noise_mag = -40, standard deviation = 0.01 radians approx 0.6 degrees). These values are assuming that pj and snr are filtered. We are averaging the results but we are not filtering the phase jitter noise. If the additive noise is very low the snr estimator has errors and if the additive noise is very high or the phase jitter noise is very high there are many decision errors. phase_noise_mag = -30 #In hardware impairments thre is a single pole iir filter to filter the gaussian noise, we are not filtering the noise using alpha equal one alpha = 1 # creates the probe_pj object withe the symbol table and alpha self.mer_probe_pj_cf_0 = mer.probe_pj_cf( (0.9487 + 0.9487j, 0.9487 + 0.3162j, 0.3162 + 0.9487j, 0.3162 + 0.3162j, 0.9487 - 0.9487j, 0.9487 - 0.3162j, 0.3162 - 0.9487j, 0.3162 - 0.3162j, -0.9487 + 0.9487j, -0.9487 + 0.3162j, -0.3162 + 0.9487j, -0.3162 + 0.3162j, -0.9487 - 0.9487j, -0.9487 - 0.3162j, -0.3162 - 0.9487j, -0.3162 - 0.3162j), 0.005) #creates a source with all possible symbols repited number_of_vectors src_const = (0.9487 + 0.9487j, 0.9487 + 0.3162j, 0.3162 + 0.9487j, 0.3162 + 0.3162j, 0.9487 - 0.9487j, 0.9487 - 0.3162j, 0.3162 - 0.9487j, 0.3162 - 0.3162j, -0.9487 + 0.9487j, -0.9487 + 0.3162j, -0.3162 + 0.9487j, -0.3162 + 0.3162j, -0.9487 - 0.9487j, -0.9487 - 0.3162j, -0.3162 - 0.9487j, -0.3162 - 0.3162j) * number_of_vectors #creates the blocks and sinks to receive the estimations self.src = blocks.vector_source_c(src_const, False) self.dst0 = blocks.vector_sink_f() self.dst1 = blocks.vector_sink_f() # add a channel model to add additive gaussian noise self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise, frequency_offset=0.0, epsilon=1.0, taps=(1, ), noise_seed=0, block_tags=False) # A gaussian noise w is generated and filtered w1,a complex signal a= cos(w1) + j sin(w1) is generated # Source data src is added with white noise src1, the output signal with phase jitter and additive noise is a * src1 # the output signal a*src1 is send to the phase jitter probe and the pj and snr are estimated # to filter the gaussian noise added to the phase, we are using alpha equal 1 so we are not filtering self.filter_single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( alpha, 1) self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.analog_noise_source_x_0 = analog.noise_source_f( analog.GR_GAUSSIAN, math.pow(10.0, phase_noise_mag / 20.0), 42) ################################################## # Connections ################################################## self.tb.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 1)) self.tb.connect((self.analog_noise_source_x_0, 0), (self.filter_single_pole_iir_filter_xx_0, 0)) self.tb.connect((self.blocks_multiply_xx_0, 0), (self.mer_probe_pj_cf_0, 0)) self.tb.connect((self.src, 0), (self.channels_channel_model_0, 0)) self.tb.connect((self.channels_channel_model_0, 0), (self.blocks_multiply_xx_0, 0)) self.tb.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0, 0)) self.tb.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0_0, 0)) self.tb.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0, 0)) self.tb.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0, 1)) self.tb.connect((self.mer_probe_pj_cf_0, 0), (self.dst0, 0)) self.tb.connect((self.mer_probe_pj_cf_0, 1), (self.dst1, 0)) self.tb.run() result_data1 = np.mean( self.dst0.data()[number_of_vectors * dim_constellation - dim_constellation * 10000:number_of_vectors * dim_constellation]) result_data2 = np.mean( self.dst1.data()[number_of_vectors * dim_constellation - dim_constellation * 10000:number_of_vectors * dim_constellation]) print " result phase jitter variance = ", result_data1 print " result snr = ", result_data2 expected_result1 = math.pow(10.0, phase_noise_mag / 20.0) * math.pow( 10.0, phase_noise_mag / 20.0) print " expected result phase jitter variance = ", expected_result1 expected_result2 = 10 * np.log10(1.0 / noise / noise / 2) print " expected result snr = ", expected_result2 #test an error in the phase jitter variance less than 10 %, self.assertLessEqual( abs((result_data1 - expected_result1) / expected_result1), 0.1) #test an error in the snr less than 10 %, self.assertLessEqual( abs((result_data2 - expected_result2) / expected_result2), 0.1)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 self.s = s = 10e-6 ################################################## # Blocks ################################################## _s_sizer = wx.BoxSizer(wx.VERTICAL) self._s_text_box = forms.text_box( parent=self.GetWin(), sizer=_s_sizer, value=self.s, callback=self.set_s, label="s", converter=forms.float_converter(), proportion=0, ) self._s_slider = forms.slider( parent=self.GetWin(), sizer=_s_sizer, value=self.s, callback=self.set_s, minimum=0, maximum=100e-3, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_s_sizer) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.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=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.blocks_transcendental_0 = blocks.transcendental("exp", "float") self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate, True) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((0.9,)) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((-(1000 / 50) * s,)) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_float * 1, "/home/rs/sem_v/EE340/Lab 6/Input (1).bin", True ) self.blocks_divide_xx_0 = blocks.divide_ff(1) self.blocks_add_const_vxx_0 = blocks.add_const_vff((1,)) self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 1) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blocks_divide_xx_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.blocks_divide_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_multiply_const_vxx_1, 0))