def test_peak5(self): #print "\n\nTEST 5" tb = self.tb data = [0, 1, 3, 7, 5, 2, 1, 0] alpha = 0.1 expected_result_peak = [0, 0, 0, 1, 0, 0, 0, 0] expected_result_average = [0] for i in data: expected_result_average.append(expected_result_average[-1] * (1 - alpha) + i * alpha) src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(3.0, 2, alpha) dst = blocks.vector_sink_b() avg = blocks.vector_sink_f() tb.connect(src, regen) tb.connect((regen, 0), dst) tb.connect((regen, 1), avg) tb.run() dst_data = dst.data() dst_avg = avg.data() self.assertEqual(tuple(expected_result_peak), dst_data) self.assertFloatTuplesAlmostEqual(tuple(expected_result_average[1:]), dst_avg)
def test_peak2(self): # print "\n\nTEST 2" tb = self.tb n = 10 data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ] + n * [0, ] expected_result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + n * [0, ] src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb( 7.0, 1000, 0.001) # called with a LONG window dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() # here we know that the block will terminate prematurely, so we compare # only part of the expected_result self.assertEqual(expected_result[0:len(dst_data)], dst_data)
def test_peak1(self): #print "\n\nTEST 1" tb = self.tb n = 10 data = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ] + n * [ 0, ] expected_result = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] + n * [ 0, ] src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 25, 0.001) dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() self.assertEqual(expected_result, dst_data)
def test_peak4(self): # print "\n\nTEST 4" tb = self.tb l = 8100 m = 100 n = 10 data = l * [ 0, ] + [ 10, ] + m * [ 0, ] + [ 100, ] + n * [ 0, ] expected_result = l * [ 0, ] + [ 0, ] + m * [ 0, ] + [ 1, ] + n * [ 0, ] src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 150, 0.001) dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() # here we know that the block will terminate prematurely, so we compare # only part of the expected_result self.assertEqual(expected_result[0:len(dst_data)], dst_data)
def test_peak3(self): #print "\n\nTEST 3" tb = self.tb l = 8100 m = 100 n = 10 data = l * [ 0, ] + [ 10, ] + m * [ 0, ] + [ 100, ] + n * [ 0, ] expected_result = l * [ 0, ] + [ 0, ] + m * [ 0, ] + [ 1, ] + n * [ 0, ] src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 105, 0.001) dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() self.assertEqual(expected_result, dst_data)
def test_regen1(self): tb = self.tb data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb() dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() self.assertEqual(expected_result, dst_data)
def test_peak3(self): #print "\n\nTEST 3" tb = self.tb l = 8100 m = 100 n = 10 data = l*(0,)+ (10,)+ m*(0,)+(100,)+ n*(0,) expected_result = l*(0,)+ (0,)+ m*(0,)+(1,)+ n*(0,) src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 105, 0.001) dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() self.assertEqual(expected_result, dst_data)
def test_peak1(self): #print "\n\nTEST 1" tb = self.tb n=10 data = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,)+n*(0,) expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)+n*(0,) src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 25, 0.001) dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() self.assertEqual(expected_result, dst_data)
def test_peak4(self): #print "\n\nTEST 4" tb = self.tb l = 8100 m = 100 n = 10 data = l*(0,)+ (10,)+ m*(0,)+(100,)+ n*(0,) expected_result = l*(0,)+ (0,)+ m*(0,)+(1,)+ n*(0,) src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 150, 0.001) dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() # here we know that the block will terminate prematurely, so we compare only part of the expected_result self.assertEqual(expected_result[0:len(dst_data)], dst_data)
def test_peak2(self): #print "\n\nTEST 2" tb = self.tb n=10 data = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,)+n*(0,) expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)+n*(0,) src = blocks.vector_source_f(data, False) regen = blocks.peak_detector2_fb(7.0, 1000, 0.001) # called with a LONG window dst = blocks.vector_sink_b() tb.connect(src, regen) tb.connect(regen, dst) tb.run() dst_data = dst.data() # here we know that the block will terminate prematurely, so we compare only part of the expected_result self.assertEqual(expected_result[0:len(dst_data)], dst_data)
def __init__(self): gr.top_block.__init__(self, "Peak Detector Example") Qt.QWidget.__init__(self) self.setWindowTitle("Peak Detector Example") 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", "peak_detector_example") if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry(self.settings.value("geometry").toByteArray()) else: self.restoreGeometry( self.settings.value("geometry", type=QtCore.QByteArray)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 100e3 ################################################## # Blocks ################################################## self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "Peak detection example", #name 3 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(True) self.qtgui_time_sink_x_0.enable_grid(True) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(True) self.qtgui_time_sink_x_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0.disable_legend() labels = [ 'Signal', 'Peak', 'Signal avg ampl', '', '', '', '', '', '', '' ] widths = [1, 3, 2, 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 = [0.8, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(3): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_win) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate, True) self.blocks_peak_detector2_fb_0 = blocks.peak_detector2_fb( 2, 10, 0.001) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) self.blocks_add_xx_0 = blocks.add_vff(1) self.analog_sig_source_x_1 = analog.sig_source_f( samp_rate, analog.GR_TRI_WAVE, 1000, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f( samp_rate, analog.GR_SAW_WAVE, 1000, 5, 0) self.analog_noise_source_x_0 = analog.noise_source_f( analog.GR_GAUSSIAN, 2, 0) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.blocks_peak_detector2_fb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.blocks_peak_detector2_fb_0, 1), (self.qtgui_time_sink_x_0, 2)) self.connect((self.blocks_throttle_0, 0), (self.blocks_peak_detector2_fb_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_time_sink_x_0, 0))
def __init__(self, EbNo_dB=15): 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()) ################################################## # Parameters ################################################## self.EbNo_dB = EbNo_dB ################################################## # Variables ################################################## self.Nt = Nt = 2 self.dft_coef = dft_coef = np.exp(-2*np.pi*1j/Nt) self.A = A = np.arange(Nt)[np.newaxis] self.tlen = tlen = 128 self.dft_matrix = dft_matrix = np.power(dft_coef, np.dot(A.transpose(),A)) self.symbol_rate = symbol_rate = 100000 self.scramble_2 = scramble_2 = 2*np.random.random_integers(0,1,size=(tlen,Nt))-1 self.scramble_1 = scramble_1 = 2*np.random.random_integers(0,1,size=(tlen,Nt))-1 self.samp_rate = samp_rate = 400000 self.prefix = prefix = '/home/zhe/gr-PWF/examples' self.noise = noise = [np.identity(Nt), np.identity(Nt)] self.dft_pilot_seq = dft_pilot_seq = np.tile(dft_matrix,(tlen/Nt,1)) self.L = L = 1 self.sigmagenfile = sigmagenfile = prefix+'/sigmagens/sigmagen_10.bin' self.prewhiten1 = prewhiten1 = np.linalg.pinv(noise[1]) self.prewhiten0 = prewhiten0 = np.linalg.pinv(noise[0]) self.pilot_seq_2 = pilot_seq_2 = np.multiply(dft_pilot_seq,scramble_2) self.pilot_seq_1 = pilot_seq_1 = np.multiply(dft_pilot_seq,scramble_1) self.pilot2file = pilot2file = prefix+'/pilots/pilot2_4000.bin' self.pilot2 = pilot2 = np.array([1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,-1,1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,1,1,-1,1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1,1,1,-1,1,1,1,1,-1,1,1,1,-1,-1,-1,-1,1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,-1,1,-1,-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,1,1,-1,1,-1,-1,1,-1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,-1,1,-1,-1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,1,1,-1,1,-1,-1,1,-1,-1,-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,-1,1,-1,-1,1,-1]) self.pilot1file = pilot1file = prefix+'/pilots/pilot1_4000.bin' self.pilot1 = pilot1 = np.array([1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,-1,-1,-1,1,-1,-1,-1,1,-1,1,1,-1,1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,1,1,-1,1,1,1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1,1,1,1,-1,-1,-1,-1,1,1,1,-1,1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,-1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,-1,1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,1,1,1,-1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,-1]) self.payload_size = payload_size = 0 self.payload = payload = 172 self.noise_voltage = noise_voltage = (samp_rate/(2*symbol_rate)*10**(-EbNo_dB/10.0))**0.5 self.noise_hat = noise_hat = [np.identity(Nt), np.identity(Nt)] self.ichn_gain_dB = ichn_gain_dB = 10 self.channelfile = channelfile = prefix+'/channels/2x2channel_10dB_3.bin' self.channel = channel = np.true_divide(np.random.standard_normal(size=(L,L,Nt,Nt))+np.random.standard_normal(size=(L,L,Nt,Nt))*1j,np.sqrt(2)) self.Q = Q = 16 self.Pt = Pt = 100 ################################################## # Blocks ################################################## self.single_pole_iir_filter_xx_0_0_1 = filter.single_pole_iir_filter_cc(0.001, 1) self.fir_filter_xxx_0_3_0_0 = filter.fir_filter_ccf(1, (pilot1[1::2][::-1])) self.fir_filter_xxx_0_3_0_0.declare_sample_delay(0) self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise_voltage, frequency_offset=0.0, epsilon=1.0, taps=(0.8, ), noise_seed=0, block_tags=False ) self.blocks_vector_source_x_0 = blocks.vector_source_c(pilot1[1::2], True, 1, []) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_peak_detector2_fb_0_0 = blocks.peak_detector2_fb(20, tlen/2, 0.001) self.blocks_file_sink_0_0_0_0_2_0_1 = blocks.file_sink(gr.sizeof_gr_complex*1, '/home/zhe/Dropbox/gnuradio_trunk/gnufiles/rx_frame', False) self.blocks_file_sink_0_0_0_0_2_0_1.set_unbuffered(True) self.blocks_file_sink_0_0_0_0_2_0_0 = blocks.file_sink(gr.sizeof_gr_complex*1, '/home/zhe/Dropbox/gnuradio_trunk/gnufiles/rx', False) self.blocks_file_sink_0_0_0_0_2_0_0.set_unbuffered(True) self.blocks_file_sink_0_0_0_0_2_0 = blocks.file_sink(gr.sizeof_gr_complex*1, '/home/zhe/Dropbox/gnuradio_trunk/gnufiles/avged', False) self.blocks_file_sink_0_0_0_0_2_0.set_unbuffered(True) self.blocks_file_sink_0_0_0_0_2 = blocks.file_sink(gr.sizeof_char*1, '/home/zhe/Dropbox/gnuradio_trunk/gnufiles/flag2', False) self.blocks_file_sink_0_0_0_0_2.set_unbuffered(True) self.blocks_file_sink_0_0_0_0_1_0 = blocks.file_sink(gr.sizeof_float*1, '/home/zhe/Dropbox/gnuradio_trunk/gnufiles/matched2', False) self.blocks_file_sink_0_0_0_0_1_0.set_unbuffered(True) self.blocks_file_sink_0_0_0_0_1 = blocks.file_sink(gr.sizeof_float*1, '/home/zhe/Dropbox/gnuradio_trunk/gnufiles/avg2', False) self.blocks_file_sink_0_0_0_0_1.set_unbuffered(True) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.PWF_rx_frame_sync_0 = PWF.rx_frame_sync(tlen) ################################################## # Connections ################################################## self.connect((self.PWF_rx_frame_sync_0, 0), (self.blocks_file_sink_0_0_0_0_2_0_1, 0)) self.connect((self.PWF_rx_frame_sync_0, 0), (self.single_pole_iir_filter_xx_0_0_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_file_sink_0_0_0_0_1_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_peak_detector2_fb_0_0, 0)) self.connect((self.blocks_peak_detector2_fb_0_0, 0), (self.PWF_rx_frame_sync_0, 1)) self.connect((self.blocks_peak_detector2_fb_0_0, 1), (self.blocks_file_sink_0_0_0_0_1, 0)) self.connect((self.blocks_peak_detector2_fb_0_0, 0), (self.blocks_file_sink_0_0_0_0_2, 0)) self.connect((self.blocks_throttle_0, 0), (self.PWF_rx_frame_sync_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.fir_filter_xxx_0_3_0_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.blocks_file_sink_0_0_0_0_2_0_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.fir_filter_xxx_0_3_0_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.single_pole_iir_filter_xx_0_0_1, 0), (self.blocks_file_sink_0_0_0_0_2_0, 0))