def test_001_t (self): self.create_frames = ofdm_create_frames_bc(constellation = digital.constellation_8psk()) self.receive_frames = ofdm_receive_frames_cb(constellation = digital.constellation_8psk()) self.data_sink = blocks.vector_sink_b() self.tb.connect(self.create_frames, self.receive_frames, self.data_sink) self.tb.run () # check data print(self.data_sink.data())
def test_001_t(self): self.create_frames = ofdm_create_frames_bc( constellation=digital.constellation_8psk()) self.receive_frames = ofdm_receive_frames_cb( constellation=digital.constellation_8psk()) self.data_sink = blocks.vector_sink_b() self.tb.connect(self.create_frames, self.receive_frames, self.data_sink) self.tb.run() # check data print(self.data_sink.data())
def get_constellation_from_string(self, const_string): self.const = { 'bpsk': digital.constellation_bpsk().base(), 'qpsk': digital.constellation_qpsk().base(), '8psk': digital.constellation_8psk().base(), '16qam': digital.constellation_16qam().base() }.get(const_string, digital.constellation_bpsk().base())
def get_constellation(bps): map = { 1: digital.constellation_bpsk(), 2: digital.constellation_qpsk(), 3: digital.constellation_8psk() } return map[bps]
def __init__(self, snr_db=10, num_symbols=1024, taps=[]): gr.top_block.__init__(self, "LMS Nonlinear Experiment") ################################################## # Variables ################################################## self.snr_db = snr_db self.samp_rate = samp_rate = 1000000 self.num_symbols = num_symbols self.taps = taps self.const = const = digital.constellation_8psk().base() ################################################## # Blocks ################################################## #self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_ccc(2, (firdes.low_pass_2(1, 1, .25, .1, 80))) #self.interp_fir_filter_xxx_0_0.declare_sample_delay(0) self.digital_lms_equalizer_cc_0 = digital.lms_dd_equalizer_cc(4, .01, 2, self.const) self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc((const.points()), 1) self.blocks_vector_sink_x_0 = blocks.vector_sink_c(1) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex*1, num_symbols) self.analog_random_source_x_1 = blocks.vector_source_b(map(int, numpy.random.randint(0, const.arity(), 1000)), True) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex * 1, 2) #self.interp_fir_filter_xxx_1 = filter.interp_fir_filter_ccc(1, ( #self.taps[0]/ numpy.sqrt((numpy.abs(self.taps[0]) ** 2 + numpy.abs(self.taps[1]) ** 2)), #self.taps[1]/ numpy.sqrt((numpy.abs(self.taps[0]) ** 2 + numpy.abs(self.taps[1]) ** 2)))) self.interp_fir_filter_xxx_1 = filter.interp_fir_filter_ccc(1, self.taps) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.analog_const_source_x_0 = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, .1) self.analog_noise_source_x_1 = analog.noise_source_c(analog.GR_GAUSSIAN, 10 ** (-20 / 20) / numpy.sqrt(2), 50) ################################################## # Connections ################################################## self.connect((self.analog_random_source_x_1, 0), (self.digital_chunks_to_symbols_xx_1, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_vector_sink_x_0, 0)) #self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_lms_equalizer_cc_0, 0)) self.connect((self.digital_lms_equalizer_cc_0, 0), (self.blocks_head_0, 0)) #self.connect((self.interp_fir_filter_xxx_0_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.interp_fir_filter_xxx_1, 0)) self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.blocks_repeat_0, 0)) self.connect((self.interp_fir_filter_xxx_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_noise_source_x_1, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.interp_fir_filter_xxx_1, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.interp_fir_filter_xxx_1, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_const_source_x_0, 0), (self.blocks_multiply_xx_0, 2))
def __init__(self, snr_db_ae = 15, signal_len = 1024, samp_rate = 100000, samples = 1000, const_index = 3): gr.top_block.__init__(self, "Eve Sim") ################################################## # Variables ################################################## self.const_qpsk = const_qpsk = digital.constellation_qpsk().base() self.const_bpsk = const_bpsk = digital.constellation_bpsk().base() self.const_8psk = const_8psk = digital.constellation_8psk().base() self.const_16qam = const_16qam = digital.constellation_16qam().base() self.snr_db_ae = snr_db_ae # = 15 self.signal_len = signal_len # = 1024 self.samp_rate = samp_rate # = 100000 self.constellations = constellations = [const_bpsk, const_qpsk, const_8psk, const_16qam] self.const_index = const_index ################################################## # Blocks ################################################## self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((constellations[const_index].points()), 1) self.classify_trained_model_classifier_vc_0 = classify.trained_model_classifier_vc(64, '/home/gvanhoy/gr-classify/apps/cumulant_classifier.pkl') self.channels_channel_model_0_0 = channels.channel_model( noise_voltage=numpy.sqrt(10.0**(-snr_db_ae/10.0)/2), frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=0, block_tags=False ) self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, 64) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, int(np.log2(constellations[const_index].arity())), "", False, gr.GR_MSB_FIRST) self.blocks_head_1 = blocks.head(gr.sizeof_gr_complex*64, samples) #message block to pull messages out of 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.classify_trained_model_classifier_vc_0, 'classification_info'), (self.blocks_message_debug_0, 'print')) self.msg_connect((self.classify_trained_model_classifier_vc_0, 'classification_info'), (self.blocks_message_debug_0, 'store')) self.connect((self.analog_random_source_x_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) #self.connect((self.blocks_stream_to_vector_0, 0), (self.classify_trained_model_classifier_vc_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_head_1, 0)) self.connect((self.blocks_head_1, 0), (self.classify_trained_model_classifier_vc_0, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.channels_channel_model_0_0, 0), (self.blocks_throttle_0_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.channels_channel_model_0_0, 0))
def __init__(self): constellation_source.__init__(self, mod_name="8psk", samp_per_sym=2, excess_bw=.35) self.const = digital.constellation_8psk().base() self.pack = blocks.packed_to_unpacked_bb(self.const.bits_per_symbol(), gr.GR_MSB_FIRST) self.map = digital.chunks_to_symbols_bc((self.const.points()), 1) self.connect(self.random_source, self.pack, self.map, self.rrc_filter, self)
def _get_constellation(bps): """ Returns a modulator block for a given number of bits per symbol """ constellation = { 1: digital.constellation_bpsk(), 2: digital.constellation_qpsk(), 3: digital.constellation_8psk() } try: return constellation[bps] except KeyError: print 'Modulation not supported.' exit(1)
def __init__(self, snr_db=10, num_symbols=1024, taps=[]): gr.top_block.__init__(self, "CMA Watterson Experiment") ################################################## # Variables ################################################## self.snr_db = snr_db self.samp_rate = samp_rate = 1000000 self.num_symbols = num_symbols self.taps = taps self.const = const = digital.constellation_8psk().base() ################################################## # Blocks ################################################## #self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_ccc(2, (firdes.low_pass_2(1, 1, .25, .1, 80))) #self.interp_fir_filter_xxx_0_0.declare_sample_delay(0) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc( 4, 1, .01, 2) self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc( (const.points()), 1) self.channels_channel_model_0 = channels.channel_model( noise_voltage=10**(-self.snr_db / 20.0) / numpy.sqrt(2), frequency_offset=0.0, epsilon=1.0, taps=self.taps, noise_seed=0, block_tags=False) self.blocks_vector_sink_x_0 = blocks.vector_sink_c(1) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex * 1, num_symbols) self.analog_random_source_x_1 = blocks.vector_source_b( map(int, numpy.random.randint(0, const.arity(), 1000)), True) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex * 1, 2) ################################################## # Connections ################################################## self.connect((self.analog_random_source_x_1, 0), (self.digital_chunks_to_symbols_xx_1, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_vector_sink_x_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.digital_cma_equalizer_cc_0, 0)) #self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_0_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.blocks_head_0, 0)) #self.connect((self.interp_fir_filter_xxx_0_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.blocks_repeat_0, 0))
def get_constellation_from_string(self, const_string): self.const = { 'ook': constellations.constellation_ook(), 'bpsk': digital.constellation_bpsk().base(), 'qpsk': digital.constellation_qpsk().base(), '4ask': constellations.constellation_4_ask(), '8psk': digital.constellation_8psk().base(), '8qam_cross': constellations.constellation_8qam_cross(), '8qam_circular': constellations.constellation_8qam_circular(), '16qam': digital.constellation_16qam().base(), '16psk': constellations.constellation_16_psk(), '32qam_cross': constellations.constellation_32qam_cross(), '64qam': constellations.constellation_64qam(), }.get(const_string, digital.constellation_bpsk().base())
def test_001_t (self): packet_len_tag = "packet_length" self.payload_constellation = digital.constellation_bpsk() self.data = [[0,],] self.create_frames = ofdm_create_frames_bc( data=self.data, constellation=digital.constellation_8psk()) self.data_sink = blocks.file_sink(gr.sizeof_gr_complex, 'testdata.dat') self.tb.connect(self.create_frames, self.data_sink) # set up fg self.tb.run ()
def test_001_t(self): packet_len_tag = "packet_length" self.payload_constellation = digital.constellation_bpsk() self.data = [ [ 0, ], ] self.create_frames = ofdm_create_frames_bc( data=self.data, constellation=digital.constellation_8psk()) self.data_sink = blocks.file_sink(gr.sizeof_gr_complex, 'testdata.dat') self.tb.connect(self.create_frames, self.data_sink) # set up fg self.tb.run()
#header_formatter = cdma.packet_header(bits_per_header,length_tag_name,num_tag_name,header_mod.bits_per_symbol()); #header_formatter = digital.packet_header_default(bits_per_header, length_tag_name,num_tag_name,header_mod.bits_per_symbol()); #tcm_indicator_symbols_per_frame=4; #Zhe added, 4 bits are used as tcm mode indicator, it is used as a part of header. # Achilles' comment: this may change later when filler bits are introduced... print "bits_per_header=", bits_per_header print "symbols_per_header=", symbols_per_header #print "tcm_indicator_symbols_per_frame=",tcm_indicator_symbols_per_frame print "\n" #trellis coding and modulation info payload_mod = [ digital.constellation_qpsk(), digital.constellation_8psk(), digital.constellation_16qam() ] pdir = prefix + "/python/fsm_files/" fsm = [ pdir + "awgn2o2_1.fsm", pdir + "awgn2o3_8ungerboecka.fsm", pdir + "awgn2o4_8_ungerboeckc.fsm" ] uncoded_fsm = [ trellis.fsm(2, 2, [1, 0, 0, 1]), trellis.fsm(3, 3, [1, 0, 0, 0, 1, 0, 0, 0, 1]), trellis.fsm(4, 4, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]) ] bits_per_coded_symbol = [
def main(): #self.data = ( [[random.randint(0,255) for x in xrange(self.data_len)] # +50*[0,],] ) #self.data = [[0 for x in xrange(self.data_len)],] \ # + self.nofdm_frames*[[random.randint(0,255) \ # for x in xrange(self.data_len)],] #self.data = self.nofdm_frames*[[x for x in xrange(self.data_len)],]\ # + [50*[0,],] args = get_arguments() constellation = { 1: digital.constellation_bpsk(), 2: digital.constellation_qpsk(), 3: digital.constellation_8psk(), } packet_len_tag = "packet_length" #fft_len = 64 #cp_len = 16 #occupied_carriers = (range(-26, -21) + range(-20, -7) + # range(-6, 0) + range(1, 7) + # range(8, 21) + range(22, 27),) #pilot_carriers = ((-21, -7, 7, 21),) #pilot_symbols = tuple([(1, -1, 1, -1),]) fft_len = 16 cp_len = 4 occupied_carriers = ((-5, -4, -2, -1, 1, 2, 4, 5), ) pilot_carriers = ((-3, 3), ) pilot_symbols = tuple([ (1, -1), ]) data_len = utils.ofdm_get_data_len(nofdm_symbols=args.nsymbols, noccupied_carriers=len( occupied_carriers[0]), constellation=constellation[args.bits]) data = args.nframes * [ [39 for x in xrange(data_len)], ] # sometimes Schmidl-Cox-Correlator ignores first frame # so a dummy-frame is a good idea if args.dummy_frame_start == True: data.insert(0, data_len * [0]) # if file-output GNURadio needs extra frame at the and to loop over all # OFDM-Frames before, last OFDM-Frame is ignored # not so in case of using UHD-devices because there exists incoming # input-data all the time if args.dummy_frame_end == True: data.append(data_len * [0]) tb = gr.top_block() (data_tosend, tags) = packet_utils.packets_to_vectors(data, packet_len_tag) data_source = blocks.vector_source_b(data=data_tosend, vlen=1, tags=tags, repeat=False) ofdm_mapper = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag, verbose=args.verbose) ofdm_framer = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag, verbose=args.verbose) ofdm_basebander = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag, verbose=args.verbose) if args.freq == None: data_sink = blocks.file_sink(itemsize=gr.sizeof_gr_complex, filename=args.to_file) else: data_sink = mimoots.uhd_sink(freq=args.freq, gain=args.gain) tb.connect(data_source, ofdm_mapper, ofdm_framer, ofdm_basebander, data_sink) tb.run() # need to wait until the GNURadio-graph is finished time.sleep(5)
def __init__(self): gr.top_block.__init__(self, "sic_mpsk_sim") Qt.QWidget.__init__(self) self.setWindowTitle("sic_mpsk_sim") 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", "sic_mpsk_sim") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.snr_db = snr_db = 10 self.const_type = const_type = 1 self.variable_qtgui_label_0 = variable_qtgui_label_0 = { 0: 'BPSK', 1: 'QPSK', 2: '8-PSK' }[const_type] + " - Change const_type for different constellation types!" self.noisevar = noisevar = 10**(-snr_db / 10) self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.block = block = 1000 self.alpha = alpha = .1 self.R = R = 100e3 ################################################## # Blocks ################################################## self._alpha_range = Range(0, 1, .01, .1, 200) self._alpha_win = RangeWidget(self._alpha_range, self.set_alpha, 'Alpha (P1/P)', "counter_slider", float) self.top_layout.addWidget(self._alpha_win) self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: x self._variable_qtgui_label_0_tool_bar.addWidget( Qt.QLabel('Constellation Type' + ": ")) self._variable_qtgui_label_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_formatter( self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget( self._variable_qtgui_label_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self._snr_db_range = Range(0, 20, 1, 10, 200) self._snr_db_win = RangeWidget(self._snr_db_range, self.set_snr_db, 'P/sigma^2 (dB)', "counter_slider", float) self.top_layout.addWidget(self._snr_db_win) self.qtgui_number_sink_0_0_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0_0_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0_0_0.set_title( 'BER 1 (after cancelling user 2)') labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0_0_0.set_min(i, 0) self.qtgui_number_sink_0_0_0_0.set_max(i, 1) self.qtgui_number_sink_0_0_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0_0_0.set_label( i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_0_0_win, 1, 0, 1, 1) self.qtgui_number_sink_0_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0_0.set_title( "BER 2 (after cancelling user 1)") labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0_0.set_min(i, 0) self.qtgui_number_sink_0_0_0.set_max(i, 1) self.qtgui_number_sink_0_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_0_win, 1, 1, 1, 1) self.qtgui_number_sink_0_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0.set_title("BER 2 (Without Cancellation)") labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0.set_min(i, 0) self.qtgui_number_sink_0_0.set_max(i, 1) self.qtgui_number_sink_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_win, 0, 1, 1, 1) self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title("BER1 (Without Cancellation)") labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0.set_min(i, 0) self.qtgui_number_sink_0.set_max(i, 1) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(False) self._qtgui_number_sink_0_win = sip.wrapinstance( self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_win, 0, 0, 1, 1) self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 1024, #size "Constellation", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_0.disable_legend() labels = [ "Constellation: " + str(const[const_type].arity()) + "-PSK", '', '', '', '', '', '', '', '', '' ] 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 = [0.6, 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_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_x_0_0_win) self.digital_constellation_decoder_cb_0_0_0_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_constellation_decoder_cb_0_0_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_chunks_to_symbols_xx_2 = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.digital_chunks_to_symbols_xx_1_0 = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.digital_chunks_to_symbols_xx = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.blocks_throttle_0_1 = blocks.throttle(gr.sizeof_char * 1, R, True) self.blocks_sub_xx_2_0 = blocks.sub_cc(1) self.blocks_sub_xx_2 = blocks.sub_cc(1) self.blocks_multiply_const_vxx_2_0 = blocks.multiply_const_vcc( ((1 - alpha)**0.5, )) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_vcc( (alpha**0.5, )) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc( ((1 - alpha)**0.5, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc( (alpha**0.5, )) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blks2_error_rate_0_0_0_0 = grc_blks2.error_rate( type='BER', win_size=block * 100, bits_per_symbol=2, ) self.blks2_error_rate_0_0_0 = grc_blks2.error_rate( type='BER', win_size=block * 100, bits_per_symbol=2, ) self.blks2_error_rate_0_0 = grc_blks2.error_rate( type='BER', win_size=block * 100, bits_per_symbol=2, ) self.blks2_error_rate_0 = grc_blks2.error_rate( type='BER', win_size=block * 100, bits_per_symbol=2, ) self.analog_random_source_x_1 = blocks.vector_source_b( map(int, numpy.random.randint(0, const[const_type].arity(), block)), True) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, const[const_type].arity(), block)), True) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, noisevar, -42) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.analog_random_source_x_0, 0), (self.blks2_error_rate_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blks2_error_rate_0_0_0_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_throttle_0_1, 0)) self.connect((self.analog_random_source_x_1, 0), (self.blks2_error_rate_0_0, 0)) self.connect((self.analog_random_source_x_1, 0), (self.blks2_error_rate_0_0_0, 0)) self.connect((self.analog_random_source_x_1, 0), (self.digital_chunks_to_symbols_xx_2, 0)) self.connect((self.blks2_error_rate_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blks2_error_rate_0_0, 0), (self.qtgui_number_sink_0_0, 0)) self.connect((self.blks2_error_rate_0_0_0, 0), (self.qtgui_number_sink_0_0_0, 0)) self.connect((self.blks2_error_rate_0_0_0_0, 0), (self.qtgui_number_sink_0_0_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_sub_xx_2, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_sub_xx_2_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_sub_xx_2, 1)) self.connect((self.blocks_multiply_const_vxx_2_0, 0), (self.blocks_sub_xx_2_0, 1)) self.connect((self.blocks_sub_xx_2, 0), (self.digital_constellation_decoder_cb_0_0_0, 0)) self.connect((self.blocks_sub_xx_2_0, 0), (self.digital_constellation_decoder_cb_0_0_0_0, 0)) self.connect((self.blocks_throttle_0_1, 0), (self.digital_chunks_to_symbols_xx, 0)) self.connect((self.digital_chunks_to_symbols_xx, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.digital_chunks_to_symbols_xx_1_0, 0), (self.blocks_multiply_const_vxx_2_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_2, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blks2_error_rate_0, 1)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_chunks_to_symbols_xx_1, 0)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.blks2_error_rate_0_0, 1)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.digital_chunks_to_symbols_xx_1_0, 0)) self.connect((self.digital_constellation_decoder_cb_0_0_0, 0), (self.blks2_error_rate_0_0_0, 1)) self.connect((self.digital_constellation_decoder_cb_0_0_0_0, 0), (self.blks2_error_rate_0_0_0_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.const_type = const_type = 1 self.variable_static_text_0 = variable_static_text_0 = { 0: 'BPSK', 1: 'QPSK', 2: '8-PSK' }[const_type] + " - Change const_type for different constellation types!" self.samp_rate = samp_rate = 100000 self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.EbN0 = EbN0 = 10 ################################################## # Blocks ################################################## _EbN0_sizer = wx.BoxSizer(wx.VERTICAL) self._EbN0_text_box = forms.text_box( parent=self.GetWin(), sizer=_EbN0_sizer, value=self.EbN0, callback=self.set_EbN0, label='Eb / N0 (dB)', converter=forms.float_converter(), proportion=0, ) self._EbN0_slider = forms.slider( parent=self.GetWin(), sizer=_EbN0_sizer, value=self.EbN0, callback=self.set_EbN0, minimum=-10, maximum=200, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_EbN0_sizer) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit='%', minval=0, maxval=1, factor=100, decimal_places=4, ref_level=0, sample_rate=100000, number_rate=15, average=True, avg_alpha=None, label='BER', peak_hold=False, show_gauge=False, ) self.GridAdd(self.wxgui_numbersink2_0.win, 1, 0, 1, 1) self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c( self.GetWin(), title='Constellation Plot', sample_rate=samp_rate, frame_rate=5, const_size=2048, M=2, theta=0, loop_bw=6.28 / 100.0, fmax=0.06, mu=0.5, gain_mu=0.005, symbol_rate=samp_rate / 4., omega_limit=0.005, ) self.GridAdd(self.wxgui_constellationsink2_0.win, 2, 0, 1, 1) self._variable_static_text_0_static_text = forms.static_text( parent=self.GetWin(), value=self.variable_static_text_0, callback=self.set_variable_static_text_0, label='Constellation Type', converter=forms.float_converter(), ) self.Add(self._variable_static_text_0_static_text) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blks2_error_rate_0 = grc_blks2.error_rate( type='BER', win_size=int(10e6), bits_per_symbol=const[const_type].bits_per_symbol(), ) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, const[const_type].arity(), int(10e6))), True) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, 1.0 / math.sqrt( 2.0 * const[const_type].bits_per_symbol() * 10**(EbN0 / 10)), 42) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.blks2_error_rate_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.wxgui_constellationsink2_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blks2_error_rate_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blks2_error_rate_0, 1))
def __init__(self): gr.top_block.__init__(self, "Bpsk Sender1") ################################################## # Variables ################################################## self.sps = sps = 8 self.nfilts = nfilts = 32 self.transistion = transistion = 100 self.sideband_rx = sideband_rx = 500 self.sideband = sideband = 500 self.samp_rate = samp_rate = 48000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(sps), 0.35, 11*sps*nfilts) self.qpsk = qpsk = digital.constellation_rect(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.preamble = preamble = [1,-1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1,-1,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 = 10 self.interpolation = interpolation = 2000 self.gap = gap = 0 self.eb = eb = 0.35 self.delay = delay = 0 self.decimation = decimation = 1 self.constel = constel = digital.constellation_calcdist(([1,- 1]), ([0,1]), 2, 1).base() self.const_type = const_type = 1 self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.carrier = carrier = 10000 self.arity = arity = 2 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=interpolation, decimation=decimation, taps=None, fractional_bw=None, ) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(1, (firdes.band_pass (0.5,samp_rate,10000-sideband,10000+sideband,transistion)), -carrier, samp_rate) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=constel, differential=True, samples_per_symbol=sps, pre_diff_code=True, excess_bw=0.35, verbose=False, log=False, ) self.blocks_wavfile_sink_1 = blocks.wavfile_sink("BPSK_output.wav", 1, 48000, 16) self.blocks_unpack_k_bits_bb_0_0 = blocks.unpack_k_bits_bb(8) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((0.1, )) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "TestData2", False) self.blocks_file_sink_0_0_0 = blocks.file_sink(gr.sizeof_char*1, "inputBinary", False) self.blocks_file_sink_0_0_0.set_unbuffered(False) self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, "inputBinary2", False) self.blocks_file_sink_0_0.set_unbuffered(False) script, sdelay= argv self.blocks_delay_0_0 = blocks.delay(gr.sizeof_char*1, int(sdelay)) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_file_sink_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_file_sink_0_0_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_unpack_k_bits_bb_0_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_wavfile_sink_1, 0)) self.connect((self.blocks_unpack_k_bits_bb_0_0, 0), (self.blocks_delay_0_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def __init__(self): gr.top_block.__init__(self, "BER Simulation") Qt.QWidget.__init__(self) self.setWindowTitle("BER Simulation") 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", "ber_simulation") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.const_type = const_type = 1 self.variable_qtgui_label_0 = variable_qtgui_label_0 = { 0: 'BPSK', 1: 'QPSK', 2: '8-PSK' }[const_type] + " - Change const_type for different constellation types!" self.samp_rate = samp_rate = 100e3 self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.EbN0 = EbN0 = 10 ################################################## # Blocks ################################################## self._EbN0_range = Range(-10, 200, 1, 10, 200) self._EbN0_win = RangeWidget(self._EbN0_range, self.set_EbN0, 'Eb / N0 (dB)', "counter_slider", float) self.top_layout.addWidget(self._EbN0_win) self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: str(x) self._variable_qtgui_label_0_tool_bar.addWidget( Qt.QLabel('Constellation Type' + ": ")) self._variable_qtgui_label_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_formatter( self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget( self._variable_qtgui_label_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title("") labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['x10^-6', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1e6, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0.set_min(i, 0) self.qtgui_number_sink_0.set_max(i, 1) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(True) self._qtgui_number_sink_0_win = sip.wrapinstance( self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_win, 1, 0, 1, 1) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "foo", #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) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = [ "Constellation: " + str(const[const_type].arity()) + "-PSK", '', '', '', '', '', '', '', '', '' ] 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 = [0.6, 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, 2, 0, 1, 1) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_chunks_to_symbols_xx = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.blocks_throttle = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1, 'test_output.txt', True) self.blocks_file_sink_0.set_unbuffered(True) self.blocks_add_xx = blocks.add_vcc(1) self.blks2_error_rate = grc_blks2.error_rate( type='BER', win_size=int(1e7), bits_per_symbol=const[const_type].bits_per_symbol(), ) self.analog_random_source_x = blocks.vector_source_b( map(int, numpy.random.randint(0, const[const_type].arity(), 10000000)), True) self.analog_noise_source_x = analog.noise_source_c( analog.GR_GAUSSIAN, 1.0 / math.sqrt( 2.0 * const[const_type].bits_per_symbol() * 10**(EbN0 / 10)), 42) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x, 0), (self.blocks_add_xx, 1)) self.connect((self.analog_random_source_x, 0), (self.blocks_throttle, 0)) self.connect((self.analog_random_source_x, 0), (self.digital_chunks_to_symbols_xx, 0)) self.connect((self.blks2_error_rate, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blocks_add_xx, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_add_xx, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.blocks_add_xx, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.blocks_throttle, 0), (self.blks2_error_rate, 0)) self.connect((self.digital_chunks_to_symbols_xx, 0), (self.blocks_add_xx, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blks2_error_rate, 1))
def __init__( self, const_1_name="BPSK", const_2_name="QPSK", element_separation=0, file_name="eigenvalues5.csv", noise_voltage_1=0, noise_voltage_2=0, phi_1=70, phi_2=41, theta_1=45, theta_2=75, ): gr.top_block.__init__(self, "Eigenvalues Grabber") ################################################## # Parameters ################################################## self.const_1_name = const_1_name self.const_2_name = const_2_name self.element_separation = element_separation self.file_name = file_name self.noise_voltage_1 = noise_voltage_1 self.noise_voltage_2 = noise_voltage_2 self.phi_1 = phi_1 self.phi_2 = phi_2 self.theta_1 = theta_1 self.theta_2 = theta_2 ################################################## # Variables ################################################## if const_1_name == "bpsk": self.const_1 = const_1 = digital.constellation_bpsk().base() elif const_1_name == "qpsk": self.const_1 = const_1 = digital.constellation_qpsk().base() elif const_1_name == "dqpsk": self.const_1 = const_1 = digital.constellation_dqpsk().base() elif const_1_name == "8psk": self.const_1 = const_1 = digital.constellation_8psk().base() elif const_1_name == "16qam": self.const_1 = const_1 = digital.constellation_16qam().base() if const_2_name == "bpsk": self.const_2 = const_2 = digital.constellation_bpsk().base() elif const_2_name == "qpsk": self.const_2 = const_2 = digital.constellation_qpsk().base() elif const_2_name == "dqpsk": self.const_2 = const_2 = digital.constellation_dqpsk().base() elif const_2_name == "8psk": self.const_2 = const_2 = digital.constellation_8psk().base() elif const_2_name == "16qam": self.const_2 = const_2 = digital.constellation_16qam().base() self.samp_rate = samp_rate = 150000 self.n = n = 2 self.my = my = 4 self.mx = mx = 4 self.fc = fc = 436e6 self.bps_2 = bps_2 = const_2.bits_per_symbol() self.bps_1 = bps_1 = const_1.bits_per_symbol() ################################################## # Blocks ################################################## self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc( const_2.points(), 1 ) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( const_1.points(), 1 ) self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) self.blocks_packed_to_unpacked_xx_0_0 = blocks.packed_to_unpacked_bb( bps_2, gr.GR_MSB_FIRST ) self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb( bps_1, gr.GR_MSB_FIRST ) self.blocks_add_xx_1 = blocks.add_vcc(mx * my) self.blocks_add_xx_0_0 = blocks.add_vcc(mx * my) self.blocks_add_xx_0 = blocks.add_vcc(mx * my) self.beamforming_randomsampler_0 = beamforming.randomsampler(mx * my, 8) self.beamforming_phasedarray_0_0 = beamforming.phasedarray( mx, my, theta_2, phi_2, 436e6, (299792458 / (2 * fc)), element_separation ) self.beamforming_phasedarray_0 = beamforming.phasedarray( mx, my, theta_1, phi_1, 436e6, (299792458 / (2 * fc)), element_separation ) self.beamforming_doaesprit_py_cf_0 = beamforming.doaesprit_py_cf( mx, my, fc, (299792458 / (2 * fc)), n, 128, file_name ) self.analog_vectornoise_source_0_0 = analog.vectornoise_source( noise_voltage_2, mx * my ) self.analog_vectornoise_source_0 = analog.vectornoise_source( noise_voltage_1, mx * my ) self.analog_random_source_x_0_0 = blocks.vector_source_b( list(map(int, numpy.random.randint(0, 256, 1000))), False ) self.analog_random_source_x_0 = blocks.vector_source_b( list(map(int, numpy.random.randint(0, 256, 1000))), False ) ################################################## # Connections ################################################## self.connect((self.analog_random_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect( (self.analog_random_source_x_0_0, 0), (self.blocks_throttle_0_0, 0) ) self.connect((self.analog_vectornoise_source_0, 0), (self.blocks_add_xx_0, 1)) self.connect( (self.analog_vectornoise_source_0_0, 0), (self.blocks_add_xx_0_0, 1) ) self.connect((self.beamforming_phasedarray_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.beamforming_phasedarray_0_0, 0), (self.blocks_add_xx_0_0, 0)) self.connect( (self.beamforming_randomsampler_0, 0), (self.beamforming_doaesprit_py_cf_0, 0), ) self.connect((self.blocks_add_xx_0, 0), (self.blocks_add_xx_1, 0)) self.connect((self.blocks_add_xx_0_0, 0), (self.blocks_add_xx_1, 1)) self.connect((self.blocks_add_xx_1, 0), (self.beamforming_randomsampler_0, 0)) self.connect( (self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_chunks_to_symbols_xx_0, 0), ) self.connect( (self.blocks_packed_to_unpacked_xx_0_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0), ) self.connect( (self.blocks_throttle_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0) ) self.connect( (self.blocks_throttle_0_0, 0), (self.blocks_packed_to_unpacked_xx_0_0, 0) ) self.connect( (self.digital_chunks_to_symbols_xx_0, 0), (self.beamforming_phasedarray_0, 0), ) self.connect( (self.digital_chunks_to_symbols_xx_0_0, 0), (self.beamforming_phasedarray_0_0, 0), )
def set_EbN0(self, EbN0): self.EbN0 = EbN0 self.analog_noise_source_x_0.set_amplitude(1.0 / math.sqrt(2*2.0 * digital.constellation_8psk().bits_per_symbol() * 10**(self.EbN0/10)))
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.variable_constellation_0_1 = variable_constellation_0_1 = digital.constellation_calcdist(([1+0j,0.707+0.707j, -0.707+0.707j, 0+1j, 0.707-0.707j, 0-1j, -1+0j, -0.707-0.707j]), ([0, 1, 2, 3, 4, 5, 6, 7]), 4, 1).base() self.variable_constellation_0_0 = variable_constellation_0_0 = digital.constellation_calcdist(([0.707+0.707j, -0.707-0.707j]), ([0, 1]), 4, 1).base() self.variable_constellation_0 = variable_constellation_0 = digital.constellation_calcdist(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 1).base() self.samp_rate = samp_rate = 10000 self.EbN0 = EbN0 = 10 ################################################## # Blocks ################################################## self.root_raised_cosine_filter_0_0 = filter.fir_filter_ccf(4, firdes.root_raised_cosine( 1, samp_rate, samp_rate/4, 0.35, 10*4)) self.root_raised_cosine_filter_0 = filter.interp_fir_filter_ccf(4, firdes.root_raised_cosine( 1, samp_rate, samp_rate/4, 0.35, 10*4)) self.qtgui_time_sink_x_1_0_0_1_0_0 = qtgui.time_sink_f( 24*2, #size samp_rate/10, #samp_rate "Tx Bits", #name 1 #number of inputs ) self.qtgui_time_sink_x_1_0_0_1_0_0.set_update_time(.10) self.qtgui_time_sink_x_1_0_0_1_0_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_1_0_0_1_0_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_1_0_0_1_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_1_0_0_1_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1_0_0_1_0_0.enable_autoscale(True) self.qtgui_time_sink_x_1_0_0_1_0_0.enable_grid(False) self.qtgui_time_sink_x_1_0_0_1_0_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_1_0_0_1_0_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_1_0_0_1_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1_0_0_1_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1_0_0_1_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1_0_0_1_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1_0_0_1_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1_0_0_1_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1_0_0_1_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_0_0_1_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_1_0_0_1_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_1_0_0_1_0_0_win) self.qtgui_time_sink_x_1_0_0_1_0 = qtgui.time_sink_f( 24*2, #size samp_rate/10, #samp_rate "RX bits", #name 1 #number of inputs ) self.qtgui_time_sink_x_1_0_0_1_0.set_update_time(.10) self.qtgui_time_sink_x_1_0_0_1_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_1_0_0_1_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_1_0_0_1_0.enable_tags(-1, True) self.qtgui_time_sink_x_1_0_0_1_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1_0_0_1_0.enable_autoscale(True) self.qtgui_time_sink_x_1_0_0_1_0.enable_grid(False) self.qtgui_time_sink_x_1_0_0_1_0.enable_control_panel(False) if not True: self.qtgui_time_sink_x_1_0_0_1_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_1_0_0_1_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1_0_0_1_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1_0_0_1_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1_0_0_1_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1_0_0_1_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1_0_0_1_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1_0_0_1_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_0_0_1_0_win = sip.wrapinstance(self.qtgui_time_sink_x_1_0_0_1_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_1_0_0_1_0_win) self.qtgui_number_sink_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1 ) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title("") labels = ["BER", "", "", "", "", "", "", "", "", ""] units = ["x10^-4", "", "", "", "", "", "", "", "", ""] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1e4, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0.set_min(i, 0) self.qtgui_number_sink_0.set_max(i, 10) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(True) self._qtgui_number_sink_0_win = sip.wrapinstance(self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_0_win) 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(True) self.qtgui_const_sink_x_2.enable_grid(False) if not True: self.qtgui_const_sink_x_2.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_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_layout.addWidget(self._qtgui_const_sink_x_2_win) self.fosphor_qt_sink_c_0 = fosphor.qt_sink_c() self.fosphor_qt_sink_c_0.set_fft_window(window.WIN_BLACKMAN_hARRIS) self.fosphor_qt_sink_c_0.set_frequency_range(0, samp_rate) self._fosphor_qt_sink_c_0_win = sip.wrapinstance(self.fosphor_qt_sink_c_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._fosphor_qt_sink_c_0_win) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(variable_constellation_0_1) self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc(([1+0j,0.707+0.707j, -0.707+0.707j, 0+1j, 0.707-0.707j, 0-1j, -1+0j, -0.707-0.707j]), 1) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(3) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(3) self.blocks_delay_1 = blocks.delay(gr.sizeof_char*1, 30) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blks2_error_rate_0 = grc_blks2.error_rate( type='SER', win_size=100000, bits_per_symbol=2, ) self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 2, 10000)), True) self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0 / math.sqrt(2*2.0 * digital.constellation_8psk().bits_per_symbol() * 10**(EbN0/10)), 0) ################################################## # Connections ################################################## self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_delay_1, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.blks2_error_rate_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.root_raised_cosine_filter_0_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.qtgui_time_sink_x_1_0_0_1_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.qtgui_time_sink_x_1_0_0_1_0_0, 0)) self.connect((self.blocks_delay_1, 0), (self.blks2_error_rate_0, 0)) self.connect((self.blocks_delay_1, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.digital_chunks_to_symbols_xx_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blks2_error_rate_0, 1)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.root_raised_cosine_filter_0, 0), (self.fosphor_qt_sink_c_0, 0)) self.connect((self.root_raised_cosine_filter_0_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.root_raised_cosine_filter_0_0, 0), (self.qtgui_const_sink_x_2, 0))
bits_per_header = (symbols_per_header + 1) * header_mod.bits_per_symbol() symbols_per_header = bits_per_header / header_mod.bits_per_symbol() #header_formatter = cdma.packet_header(bits_per_header,length_tag_name,num_tag_name,header_mod.bits_per_symbol()); #header_formatter = digital.packet_header_default(bits_per_header, length_tag_name,num_tag_name,header_mod.bits_per_symbol()); #tcm_indicator_symbols_per_frame=4; #Zhe added, 4 bits are used as tcm mode indicator, it is used as a part of header. # Achilles' comment: this may change later when filler bits are introduced... print "bits_per_header=", bits_per_header print "symbols_per_header=", symbols_per_header #print "tcm_indicator_symbols_per_frame=",tcm_indicator_symbols_per_frame print "\n" #trellis coding and modulation info payload_mod = [digital.constellation_qpsk(), digital.constellation_8psk()] pdir = prefix + "/python/fsm_files/" fsm = [pdir + "awgn2o2_1.fsm", pdir + "awgn2o3_8ungerboecka.fsm"] uncoded_fsm = [ trellis.fsm(2, 2, [1, 0, 0, 1]), trellis.fsm(3, 3, [1, 0, 0, 0, 1, 0, 0, 0, 1]) ] bits_per_coded_symbol = [ int(math.log(trellis.fsm(fsm[i]).O(), 2)) for i in range(len(payload_mod)) ] #coding_rate=[Fraction(int(math.log(trellis.fsm(fsm[i]).I(),2)), int(math.log(trellis.fsm(fsm[i]).O(),2))) for i in range(len(fsm))] if bits_per_coded_symbol != [
def __init__(self, address='serial=30AD34D'): gr.top_block.__init__(self, "MPSK TX RX") Qt.QWidget.__init__(self) self.setWindowTitle("MPSK TX RX") 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_TX_RX") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.address = address ################################################## # Variables ################################################## self.const_type = const_type = 2 self.bits_per_symbol = bits_per_symbol = int(const_type + 1) self.samples_per_symbol = samples_per_symbol = int(2 * (bits_per_symbol)) self.probe_SNR = probe_SNR = 0 self.nfilts = nfilts = 32 self.bitrate = bitrate = 64e3 self.variable_qtgui_label_0 = variable_qtgui_label_0 = { 0: 'BPSK', 1: 'QPSK', 2: '8-PSK' }[const_type] + " - Change const_type for different constellation types!" self.tun_gain_tx = tun_gain_tx = 40 self.tun_freq_tx = tun_freq_tx = 2.39e9 self.timing_bw = timing_bw = 2 * math.pi / 100.0 self.samp_rate = samp_rate = samples_per_symbol * bitrate self.phase_bw = phase_bw = 2 * math.pi / 100.0 self.ntaps = ntaps = 11 * int(samples_per_symbol * nfilts) self.lo_offset = lo_offset = 6e6 self.gain_rx = gain_rx = 0.75 self.freq_rx = freq_rx = 2390e6 self.freq_bw = freq_bw = 2 * math.pi / 100.0 self.fll_ntaps = fll_ntaps = 55 self.excess_bw = excess_bw = 0.35 self.constellation = constellation = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.arrity = arrity = pow(2, bits_per_symbol) self.ampl = ampl = 0.7 self.SNR = SNR = probe_SNR ################################################## # Blocks ################################################## self._tun_gain_tx_range = Range(0, 80, 1, 40, 200) self._tun_gain_tx_win = RangeWidget(self._tun_gain_tx_range, self.set_tun_gain_tx, 'UHD Tx Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._tun_gain_tx_win, 1, 0, 1, 1) self._tun_freq_tx_range = Range(2.3e9, 2.5e9, 1, 2.39e9, 200) self._tun_freq_tx_win = RangeWidget(self._tun_freq_tx_range, self.set_tun_freq_tx, 'UHD Tx Freq (Hz)', "counter_slider", float) self.top_grid_layout.addWidget(self._tun_freq_tx_win, 0, 0, 1, 1) self._lo_offset_options = ( 0, 6e6, 11e6, ) self._lo_offset_labels = ( str(self._lo_offset_options[0]), str(self._lo_offset_options[1]), str(self._lo_offset_options[2]), ) self._lo_offset_tool_bar = Qt.QToolBar(self) self._lo_offset_tool_bar.addWidget(Qt.QLabel("lo_offset" + ": ")) self._lo_offset_combo_box = Qt.QComboBox() self._lo_offset_tool_bar.addWidget(self._lo_offset_combo_box) for label in self._lo_offset_labels: self._lo_offset_combo_box.addItem(label) self._lo_offset_callback = lambda i: Qt.QMetaObject.invokeMethod( self._lo_offset_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._lo_offset_options.index(i))) self._lo_offset_callback(self.lo_offset) self._lo_offset_combo_box.currentIndexChanged.connect( lambda i: self.set_lo_offset(self._lo_offset_options[i])) self.top_grid_layout.addWidget(self._lo_offset_tool_bar, 2, 1, 1, 1) self._gain_rx_range = Range(0, 1, 0.01, 0.75, 200) self._gain_rx_win = RangeWidget(self._gain_rx_range, self.set_gain_rx, 'UHD Rx Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._gain_rx_win, 1, 1, 1, 1) self._freq_rx_range = Range(2350e6, 2500e6, 10e6, 2390e6, 200) self._freq_rx_win = RangeWidget(self._freq_rx_range, self.set_freq_rx, 'UHD Rx Freq (Hz)', "counter_slider", float) self.top_grid_layout.addWidget(self._freq_rx_win, 0, 1, 1, 1) self.digital_probe_mpsk_snr_est_c_0 = digital.probe_mpsk_snr_est_c( 2, 1000, 10 / bitrate) self._const_type_options = ( 0, 1, 2, ) self._const_type_labels = ( 'DBPSK', 'DQPSK', 'D8PSK', ) self._const_type_tool_bar = Qt.QToolBar(self) self._const_type_tool_bar.addWidget(Qt.QLabel("const_type" + ": ")) self._const_type_combo_box = Qt.QComboBox() self._const_type_tool_bar.addWidget(self._const_type_combo_box) for label in self._const_type_labels: self._const_type_combo_box.addItem(label) self._const_type_callback = lambda i: Qt.QMetaObject.invokeMethod( self._const_type_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._const_type_options.index(i))) self._const_type_callback(self.const_type) self._const_type_combo_box.currentIndexChanged.connect( lambda i: self.set_const_type(self._const_type_options[i])) self.top_layout.addWidget(self._const_type_tool_bar) self._ampl_range = Range(0, 1, 0.01, 0.7, 200) self._ampl_win = RangeWidget(self._ampl_range, self.set_ampl, 'Amplitude', "counter_slider", float) self.top_grid_layout.addWidget(self._ampl_win, 2, 0, 1, 1) self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: x self._variable_qtgui_label_0_tool_bar.addWidget( Qt.QLabel('Constellation Type' + ": ")) self._variable_qtgui_label_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_formatter( self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget( self._variable_qtgui_label_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join((address, "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_clock_rate(30.72e6, uhd.ALL_MBOARDS) self.uhd_usrp_source_0.set_subdev_spec('A:A', 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq( uhd.tune_request(freq_rx, rf_freq=freq_rx - lo_offset, rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 0) self.uhd_usrp_source_0.set_normalized_gain(gain_rx, 0) self.uhd_usrp_source_0.set_antenna('TX/RX', 0) self.uhd_usrp_sink_0_0 = uhd.usrp_sink( ",".join((address, "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0_0.set_clock_rate(30.72e6, uhd.ALL_MBOARDS) self.uhd_usrp_sink_0_0.set_subdev_spec('A:B', 0) self.uhd_usrp_sink_0_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0_0.set_center_freq(tun_freq_tx, 0) self.uhd_usrp_sink_0_0.set_gain(tun_gain_tx, 0) self.uhd_usrp_sink_0_0.set_antenna('TX/RX', 0) self.qtgui_number_sink_0_1 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0_1.set_update_time(0.10) self.qtgui_number_sink_0_1.set_title("BER") labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['x10^-6', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1e6, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_1.set_min(i, 0) self.qtgui_number_sink_0_1.set_max(i, 1) self.qtgui_number_sink_0_1.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_1.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_1.set_label(i, labels[i]) self.qtgui_number_sink_0_1.set_unit(i, units[i]) self.qtgui_number_sink_0_1.set_factor(i, factor[i]) self.qtgui_number_sink_0_1.enable_autoscale(True) self._qtgui_number_sink_0_1_win = sip.wrapinstance( self.qtgui_number_sink_0_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_0_1_win) self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 1024, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_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_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_0_win, 3, 0, 1, 1) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #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) self.qtgui_const_sink_x_0.enable_axis_labels(True) 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, 3, 1, 1, 1) def _probe_SNR_probe(): while True: val = self.digital_probe_mpsk_snr_est_c_0.snr() try: self.set_probe_SNR(val) except AttributeError: pass time.sleep(1.0 / (10)) _probe_SNR_thread = threading.Thread(target=_probe_SNR_probe) _probe_SNR_thread.daemon = True _probe_SNR_thread.start() self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf( samples_per_symbol, taps=(firdes.root_raised_cosine(nfilts, nfilts, 1.0, 0.35, ntaps)), flt_size=nfilts) self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) self.digital_scrambler_bb_0 = digital.scrambler_bb(0x8A, 0x7F, 7) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf( samples_per_symbol, timing_bw, (firdes.root_raised_cosine( nfilts, nfilts * samples_per_symbol, 1.0, 0.35, ntaps)), nfilts, nfilts // 2, 1.5, 1) self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc( samples_per_symbol, excess_bw, fll_ntaps, freq_bw) self.digital_diff_encoder_bb_0 = digital.diff_encoder_bb(arrity) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(arrity) self.digital_descrambler_bb_0 = digital.descrambler_bb(0x8A, 0x7F, 7) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( timing_bw, pow(2, bits_per_symbol), False) self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb( constellation[const_type].base()) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( (constellation[const_type].points()), 1) self.blocks_vector_source_x_0_0 = blocks.vector_source_b([ 1, ], True, 1, []) self.blocks_vector_source_x_0 = blocks.vector_source_b([ 1, ], True, 1, []) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb( bits_per_symbol) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(bits_per_symbol) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((ampl, )) self.blks2_error_rate_0 = grc_blks2.error_rate( type='BER', win_size=10000, bits_per_symbol=1, ) self.analog_agc2_xx_0 = analog.agc2_cc(0.6e-1, 1e-3, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) self._SNR_tool_bar = Qt.QToolBar(self) if None: self._SNR_formatter = None else: self._SNR_formatter = lambda x: x self._SNR_tool_bar.addWidget(Qt.QLabel("SNR" + ": ")) self._SNR_label = Qt.QLabel(str(self._SNR_formatter(self.SNR))) self._SNR_tool_bar.addWidget(self._SNR_label) self.top_layout.addWidget(self._SNR_tool_bar) ################################################## # Connections ################################################## self.connect((self.analog_agc2_xx_0, 0), (self.digital_fll_band_edge_cc_0, 0)) self.connect((self.blks2_error_rate_0, 0), (self.qtgui_number_sink_0_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.uhd_usrp_sink_0_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.digital_diff_encoder_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.digital_descrambler_bb_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.digital_scrambler_bb_0, 0)) self.connect((self.blocks_vector_source_x_0_0, 0), (self.blks2_error_rate_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_constellation_decoder_cb_0_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_probe_mpsk_snr_est_c_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.digital_descrambler_bb_0, 0), (self.blks2_error_rate_0, 1)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_diff_encoder_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_scrambler_bb_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.analog_agc2_xx_0, 0))
def main(): #self.data = ( [[random.randint(0,255) for x in xrange(self.data_len)] \ # +50*[0,],] ) #self.data = [[0 for x in xrange(self.data_len)],] \ # +self.nofdm_frames*[[random.randint(0,255) \ # for x in xrange(self.data_len)],] #self.data = self.nofdm_frames*[[x for x in xrange(self.data_len)],] \ # + [50*[0,],] args = get_arguments() constellation = { 1: digital.constellation_bpsk(), 2: digital.constellation_qpsk(), 3: digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27), ) pilot_carriers = ((-21, -7, 7, 21), ) pilot_symbols = tuple([ (1, -1, 1, -1), ]) data_len = utils.ofdm_get_data_len(nofdm_symbols=args.nsymbols, noccupied_carriers=len( occupied_carriers[0]), constellation=constellation[args.bits]) data0 = args.nframes * [ [1 for x in xrange(data_len)], ] data1 = args.nframes * [ [2 for x in xrange(data_len)], ] # sometimes Schmidl-Cox-Correlator ignores first frame # so a dummy-frame is a good idea if args.dummy_frame == True: data0.insert(0, data_len * [0]) data1.insert(0, data_len * [0]) # if file-output GNURadio needs extra frame at the and to loop over all # OFDM-Frames before, last OFDM-Frame is ignored # not so in case of using UHD-devices because there exists incoming # input-data all the time if args.freq == None: data0.append(data_len * [0]) data1.append(data_len * [0]) (data0_tosend, tags0) = packet_utils.packets_to_vectors(data0, packet_len_tag) (data1_tosend, tags1) = packet_utils.packets_to_vectors(data1, packet_len_tag) tb = gr.top_block() data_source0 = blocks.vector_source_b(data=data0_tosend, vlen=1, tags=tags0, repeat=False) data_source1 = blocks.vector_source_b(data=data1_tosend, vlen=1, tags=tags1, repeat=False) ofdm_mapper0 = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag) ofdm_mapper1 = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag) ofdm_framer0 = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag) ofdm_framer1 = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag) ofdm_basebander0 = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag) ofdm_basebander1 = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag) if args.freq == None: data_sink = mimoots.file_sink2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=('1.'.join(args.to_file.rsplit('.', 1)), '2.'.join(args.to_file.rsplit('.', 1)))) else: data_sink = mimoots.uhd_sink2(freq=args.freq, gain=args.gain) tb.connect(data_source0, ofdm_mapper0, ofdm_framer0, ofdm_basebander0, (data_sink, 0)) tb.connect(data_source1, ofdm_mapper1, ofdm_framer1, ofdm_basebander1, (data_sink, 1)) tb.run() time.sleep(5)
def __init__(self): gr.top_block.__init__(self, "SER Simulation") Qt.QWidget.__init__(self) self.setWindowTitle("SER Simulation") 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", "Lab_total") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk(), digital.qam.qam_constellation(16)) self.samp_rate = samp_rate = 100e3 self.Sps = Sps = 1 self.M = M = len(const) self.f_dev_max = f_dev_max = 1 / 10. self.Rs = Rs = samp_rate / Sps self.Nfdev = Nfdev = 32 self.Bps = Bps = int(math.log(M, 2)) self.run_stop = run_stop = True self.fase_correccion = fase_correccion = 0. self.f_dev = f_dev = numpy.linspace(-f_dev_max, f_dev_max, Nfdev + 1) self.f_correccion = f_correccion = 0 self.Rb = Rb = Rs * Bps self.MiconstellationObject = MiconstellationObject = digital.constellation_calcdist( (const[3].points()), (), 4, 1).base() ################################################## # Blocks ################################################## self.controls = Qt.QTabWidget() self.controls_widget_0 = Qt.QWidget() self.controls_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.controls_widget_0) self.controls_grid_layout_0 = Qt.QGridLayout() self.controls_layout_0.addLayout(self.controls_grid_layout_0) self.controls.addTab(self.controls_widget_0, 'Correccion para FLL y PLL') self.top_grid_layout.addWidget(self.controls, 0, 0, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self._fase_correccion_range = Range(-math.pi, math.pi, 2. * math.pi / 100., 0., 200) self._fase_correccion_win = RangeWidget(self._fase_correccion_range, self.set_fase_correccion, "correcion de Fase (PLL)", "counter_slider", float) self.controls_grid_layout_0.addWidget(self._fase_correccion_win, 0, 2, 1, 1) for r in range(0, 1): self.controls_grid_layout_0.setRowStretch(r, 1) for c in range(2, 3): self.controls_grid_layout_0.setColumnStretch(c, 1) self._f_correccion_range = Range(-f_dev_max, f_dev_max, f_dev_max * 2 / Nfdev, 0, 200) self._f_correccion_win = RangeWidget(self._f_correccion_range, self.set_f_correccion, "correcion de frecuencia (FLL)", "counter_slider", float) self.controls_grid_layout_0.addWidget(self._f_correccion_win, 0, 1, 1, 1) for r in range(0, 1): self.controls_grid_layout_0.setRowStretch(r, 1) for c in range(1, 2): self.controls_grid_layout_0.setColumnStretch(c, 1) _run_stop_check_box = Qt.QCheckBox('Inicial/Parar') self._run_stop_choices = {True: True, False: False} self._run_stop_choices_inv = dict( (v, k) for k, v in self._run_stop_choices.iteritems()) self._run_stop_callback = lambda i: Qt.QMetaObject.invokeMethod( _run_stop_check_box, "setChecked", Qt.Q_ARG("bool", self._run_stop_choices_inv[i])) self._run_stop_callback(self.run_stop) _run_stop_check_box.stateChanged.connect( lambda i: self.set_run_stop(self._run_stop_choices[bool(i)])) self.controls_grid_layout_0.addWidget(_run_stop_check_box, 0, 0, 1, 1) for r in range(0, 1): self.controls_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.controls_grid_layout_0.setColumnStretch(c, 1) self.qtgui_const_sink_x_0_1 = qtgui.const_sink_c( 1024, #size "Salida del Modulador", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_1.set_update_time(0.10) self.qtgui_const_sink_x_0_1.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_1.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_1.enable_autoscale(False) self.qtgui_const_sink_x_0_1.enable_grid(False) self.qtgui_const_sink_x_0_1.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_1.disable_legend() labels = ['', 'Tx', '', '', '', '', '', '', '', ''] widths = [4, 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 = [0.6, 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_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_1.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_1.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_1.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_1.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_1.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_1.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_1_win = sip.wrapinstance( self.qtgui_const_sink_x_0_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_1_win, 1, 0, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_const_sink_x_0_0_0 = qtgui.const_sink_c( 1024, #size "Salida del PLL", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_0_0.disable_legend() labels = ['', 'Tx', '', '', '', '', '', '', '', ''] widths = [4, 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 = [0.6, 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_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_0_0_win, 2, 1, 1, 1) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 1024, #size "Salida del FLL", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_0.disable_legend() labels = ['', 'Tx', '', '', '', '', '', '', '', ''] widths = [4, 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 = [0.6, 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_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_0_win, 2, 0, 1, 1) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "Salida del Canal", #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) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = ['', 'Tx', '', '', '', '', '', '', '', ''] widths = [4, 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 = [0.6, 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, 1, 1, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.b_symb_source_0 = b_symb_source( Constelacion=MiconstellationObject.points(), ) self.b_Canal_simple_cc_0 = b_Canal_simple_cc( Ch_Loss_dB=0, Ch_NodB=-60, Ch_Phoffset=random.uniform(-math.pi, math.pi), Ch_Toffset=0, Fluctuacion=0, Foffset=f_dev[randint(0, Nfdev)], T_fluct=M * 1024, samp_rate=Rs, ) self.analog_sig_source_x_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, f_correccion, 1, 0) self.analog_const_source_x_0 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, numpy.exp(fase_correccion * 1.j)) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.b_Canal_simple_cc_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.b_Canal_simple_cc_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.b_symb_source_0, 0), (self.b_Canal_simple_cc_0, 0)) self.connect((self.b_symb_source_0, 0), (self.qtgui_const_sink_x_0_1, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.qtgui_const_sink_x_0_0_0, 0))
def __init__(self, address='serial=30AD34D'): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") 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", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Parameters ################################################## self.address = address ################################################## # Variables ################################################## self.const_type = const_type = 1 self.bits_per_symbol = bits_per_symbol = int(const_type + 1) self.samples_per_symbol = samples_per_symbol = int(2 * (bits_per_symbol)) self.nfilts = nfilts = 32 self.bitrate = bitrate = 64e3 self.variable_qtgui_label_0 = variable_qtgui_label_0 = { 0: 'BPSK', 1: 'QPSK', 2: '8-PSK' }[const_type] + " - Change const_type for different constellation types!" self.tun_gain_tx = tun_gain_tx = 40 self.tun_freq_tx = tun_freq_tx = 2.39e9 self.samp_rate = samp_rate = samples_per_symbol * bitrate self.ntaps = ntaps = 11 * int(samples_per_symbol * nfilts) self.excess_bw = excess_bw = 0.35 self.constellation = constellation = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.arrity = arrity = pow(2, bits_per_symbol) self.ampl = ampl = 0.7 ################################################## # Blocks ################################################## self._tun_gain_tx_range = Range(0, 80, 1, 40, 200) self._tun_gain_tx_win = RangeWidget(self._tun_gain_tx_range, self.set_tun_gain_tx, 'UHD Tx Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._tun_gain_tx_win, 1, 0, 1, 1) self._tun_freq_tx_range = Range(2.3e9, 2.5e9, 1, 2.39e9, 200) self._tun_freq_tx_win = RangeWidget(self._tun_freq_tx_range, self.set_tun_freq_tx, 'UHD Tx Freq (Hz)', "counter_slider", float) self.top_grid_layout.addWidget(self._tun_freq_tx_win, 0, 0, 1, 1) self._const_type_options = ( 0, 1, 2, ) self._const_type_labels = ( 'DBPSK', 'DQPSK', 'D8PSK', ) self._const_type_tool_bar = Qt.QToolBar(self) self._const_type_tool_bar.addWidget(Qt.QLabel("const_type" + ": ")) self._const_type_combo_box = Qt.QComboBox() self._const_type_tool_bar.addWidget(self._const_type_combo_box) for label in self._const_type_labels: self._const_type_combo_box.addItem(label) self._const_type_callback = lambda i: Qt.QMetaObject.invokeMethod( self._const_type_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._const_type_options.index(i))) self._const_type_callback(self.const_type) self._const_type_combo_box.currentIndexChanged.connect( lambda i: self.set_const_type(self._const_type_options[i])) self.top_layout.addWidget(self._const_type_tool_bar) self._ampl_range = Range(0, 1, 0.01, 0.7, 200) self._ampl_win = RangeWidget(self._ampl_range, self.set_ampl, 'Amplitude', "counter_slider", float) self.top_grid_layout.addWidget(self._ampl_win, 2, 0, 1, 1) self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: str(x) self._variable_qtgui_label_0_tool_bar.addWidget( Qt.QLabel('Constellation Type' + ": ")) self._variable_qtgui_label_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_formatter( self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget( self._variable_qtgui_label_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self.uhd_usrp_sink_0_0 = uhd.usrp_sink( ",".join((address, "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0_0.set_clock_rate(30.72e6, uhd.ALL_MBOARDS) self.uhd_usrp_sink_0_0.set_subdev_spec('A:B', 0) self.uhd_usrp_sink_0_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0_0.set_center_freq(tun_freq_tx, 0) self.uhd_usrp_sink_0_0.set_gain(tun_gain_tx, 0) self.uhd_usrp_sink_0_0.set_antenna('TX/RX', 0) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf( samples_per_symbol, taps=(firdes.root_raised_cosine(nfilts, nfilts, 1.0, 0.35, ntaps)), flt_size=nfilts) self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) self.digital_scrambler_bb_0 = digital.scrambler_bb(0x8A, 0x7F, 7) self.digital_diff_encoder_bb_0 = digital.diff_encoder_bb(arrity) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( (constellation[const_type].points()), 1) self.blocks_vector_source_x_0 = blocks.vector_source_b([ 1, ], True, 1, []) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(bits_per_symbol) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((ampl, )) ################################################## # Connections ################################################## self.connect((self.blocks_multiply_const_vxx_0, 0), (self.uhd_usrp_sink_0_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.digital_diff_encoder_bb_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.digital_scrambler_bb_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.digital_diff_encoder_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_scrambler_bb_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Bpsk Sender1") ################################################## # Variables ################################################## self.sps = sps = 8 self.nfilts = nfilts = 32 self.transistion = transistion = 100 self.sideband_rx = sideband_rx = 500 self.sideband = sideband = 500 self.samp_rate = samp_rate = 48000 self.rrc_taps = rrc_taps = firdes.root_raised_cosine( nfilts, nfilts, 1.0 / float(sps), 0.35, 11 * sps * nfilts) self.qpsk = qpsk = digital.constellation_rect(([ 0.707 + 0.707j, -0.707 + 0.707j, -0.707 - 0.707j, 0.707 - 0.707j ]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base() self.preamble = preamble = [ 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 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 = 10 script, inter = argv self.interpolation = interpolation = int(inter) self.gap = gap = 0 self.eb = eb = 0.35 self.delay = delay = 0 self.decimation = decimation = 1 self.constel = constel = digital.constellation_calcdist( ([1, -1]), ([0, 1]), 2, 1).base() self.const_type = const_type = 1 self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.carrier = carrier = 10000 self.arity = arity = 2 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=interpolation, decimation=decimation, taps=None, fractional_bw=None, ) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 1, (firdes.band_pass(0.5, samp_rate, 10000 - sideband, 10000 + sideband, transistion)), -carrier, samp_rate) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=constel, differential=True, samples_per_symbol=sps, pre_diff_code=True, excess_bw=0.35, verbose=False, log=False, ) self.blocks_wavfile_sink_1 = blocks.wavfile_sink( "BPSK_output.wav", 1, 48000, 16) self.blocks_unpack_k_bits_bb_0_0 = blocks.unpack_k_bits_bb(8) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((0.1, )) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char * 1, "TestData1", False) self.blocks_file_sink_0_0_0 = blocks.file_sink(gr.sizeof_char * 1, "inputBinary", False) self.blocks_file_sink_0_0_0.set_unbuffered(False) self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char * 1, "inputBinary2", False) self.blocks_file_sink_0_0.set_unbuffered(False) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_char * 1, int(delay)) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_file_sink_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_file_sink_0_0_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_unpack_k_bits_bb_0_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.digital_constellation_modulator_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_wavfile_sink_1, 0)) self.connect((self.blocks_unpack_k_bits_bb_0_0, 0), (self.blocks_delay_0_0, 0)) self.connect((self.digital_constellation_modulator_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def __init__(self): gr.top_block.__init__(self, "BER Simulation") Qt.QWidget.__init__(self) self.setWindowTitle("BER Simulation") 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", "ber_simulation") 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.tx_amp = tx_amp = 10 self.samp_rate_0 = samp_rate_0 = 32000 self.samp_rate = samp_rate = 100e3 self.offset = offset = math.pi / 4 self.freq = freq = 1e3 self.const_type = const_type = 2 self.const = const = (digital.constellation_bpsk(), digital.constellation_qpsk(), digital.constellation_8psk()) self.EbN0 = EbN0 = 10 ################################################## # Blocks ################################################## self._offset_range = Range(0, math.pi / 2, math.pi / 20, math.pi / 4, 20) self._offset_win = RangeWidget(self._offset_range, self.set_offset, 'Offset', "dial", float) self.top_grid_layout.addWidget(self._offset_win, 3, 2, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(3, 4)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(2, 3)] self._EbN0_range = Range(-10, 200, 1, 10, 200) self._EbN0_win = RangeWidget(self._EbN0_range, self.set_EbN0, 'Eb / N0 (dB)', "counter_slider", float) self.top_grid_layout.addWidget(self._EbN0_win, 3, 0, 1, 2) [self.top_grid_layout.setRowStretch(r, 1) for r in range(3, 4)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 2)] self.qtgui_number_sink_0_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0_0_0.set_update_time(0.01) self.qtgui_number_sink_0_0_0.set_title("Combined") labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['x10^-6', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1e6, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0_0.set_min(i, 0) self.qtgui_number_sink_0_0_0.set_max(i, 1) self.qtgui_number_sink_0_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0_0.enable_autoscale(True) self._qtgui_number_sink_0_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_0_win, 1, 2, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(1, 2)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(2, 3)] self.qtgui_number_sink_0_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0_0.set_update_time(0.01) self.qtgui_number_sink_0_0.set_title("Vertical") labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['x10^-6', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1e6, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0.set_min(i, 0) self.qtgui_number_sink_0_0.set_max(i, 1) self.qtgui_number_sink_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0.enable_autoscale(True) self._qtgui_number_sink_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_win, 1, 1, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(1, 2)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(1, 2)] self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0.set_update_time(0.01) self.qtgui_number_sink_0.set_title("Horizontal") labels = ['BER', '', '', '', '', '', '', '', '', ''] units = ['x10^-6', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1e6, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0.set_min(i, 0) self.qtgui_number_sink_0.set_max(i, 1) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(True) self._qtgui_number_sink_0_win = sip.wrapinstance( self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_win, 1, 0, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(1, 2)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 1)] self.qtgui_const_sink_x_0_0_0 = qtgui.const_sink_c( 1024, #size "Result of Maximal Combining", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_0_0.disable_legend() labels = [ "Constellation: " + str(const[const_type].arity()) + "-PSK", '', '', '', '', '', '', '', '', '' ] 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 = [0.6, 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_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_0_0_win, 2, 2, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(2, 3)] self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 1024, #size "Vertical Channel", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_0.disable_legend() labels = [ "Constellation: " + str(const[const_type].arity()) + "-PSK", '', '', '', '', '', '', '', '', '' ] 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 = [0.6, 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_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_0_win, 2, 1, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(1, 2)] self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "Horizontal Channel", #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) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = [ "Constellation: " + str(const[const_type].arity()) + "-PSK", '', '', '', '', '', '', '', '', '' ] 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 = [0.6, 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, 2, 0, 1, 1) [self.top_grid_layout.setRowStretch(r, 1) for r in range(2, 3)] [self.top_grid_layout.setColumnStretch(c, 1) for c in range(0, 1)] self.digital_constellation_decoder_cb_0_0_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( const[const_type].base()) self.digital_chunks_to_symbols_xx = digital.chunks_to_symbols_bc( (const[const_type].points()), 1) self.blocks_throttle = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blocks_add_xx = blocks.add_vcc(1) self.blks2_error_rate_1 = grc_blks2.error_rate( type='BER', win_size=int(1e7), bits_per_symbol=const[const_type].bits_per_symbol(), ) self.blks2_error_rate_0 = grc_blks2.error_rate( type='BER', win_size=int(1e7), bits_per_symbol=const[const_type].bits_per_symbol(), ) self.blks2_error_rate = grc_blks2.error_rate( type='BER', win_size=int(1e7), bits_per_symbol=const[const_type].bits_per_symbol(), ) self.analog_random_source_x = blocks.vector_source_b( map(int, numpy.random.randint(0, const[const_type].arity(), 10000000)), True) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, 1.0 / math.sqrt(2.0 * const[const_type].bits_per_symbol() * 10**(math.cos(math.pi / 2 - offset) * math.cos(math.pi / 2 - offset) * EbN0 / 10)), -42) self.analog_noise_source_x = analog.noise_source_c( analog.GR_GAUSSIAN, 1.0 / math.sqrt(2.0 * const[const_type].bits_per_symbol() * 10**(math.cos(offset) * math.cos(offset) * EbN0 / 10)), -42) self.Maximal_Combining_0 = Maximal_Combining() ################################################## # Connections ################################################## self.connect((self.Maximal_Combining_0, 0), (self.digital_constellation_decoder_cb_0_0_0, 0)) self.connect((self.Maximal_Combining_0, 0), (self.qtgui_const_sink_x_0_0_0, 0)) self.connect((self.analog_noise_source_x, 0), (self.blocks_add_xx, 1)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_random_source_x, 0), (self.blocks_throttle, 0)) self.connect((self.analog_random_source_x, 0), (self.digital_chunks_to_symbols_xx, 0)) self.connect((self.blks2_error_rate, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blks2_error_rate_0, 0), (self.qtgui_number_sink_0_0, 0)) self.connect((self.blks2_error_rate_1, 0), (self.qtgui_number_sink_0_0_0, 0)) self.connect((self.blocks_add_xx, 0), (self.Maximal_Combining_0, 0)) self.connect((self.blocks_add_xx, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.blocks_add_xx, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.Maximal_Combining_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.blocks_throttle, 0), (self.blks2_error_rate, 0)) self.connect((self.blocks_throttle, 0), (self.blks2_error_rate_0, 0)) self.connect((self.blocks_throttle, 0), (self.blks2_error_rate_1, 0)) self.connect((self.digital_chunks_to_symbols_xx, 0), (self.blocks_add_xx, 0)) self.connect((self.digital_chunks_to_symbols_xx, 0), (self.blocks_add_xx_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blks2_error_rate, 1)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.blks2_error_rate_0, 1)) self.connect((self.digital_constellation_decoder_cb_0_0_0, 0), (self.blks2_error_rate_1, 1))
def __init__(self): gr.top_block.__init__(self, "Eve") Qt.QWidget.__init__(self) self.setWindowTitle("Eve") 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", "eve") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.const_qpsk = const_qpsk = digital.constellation_qpsk().base() self.const_bpsk = const_bpsk = digital.constellation_bpsk().base() self.const_8psk = const_8psk = digital.constellation_8psk().base() self.const_16qam = const_16qam = digital.constellation_16qam().base() self.snr_db_ae = snr_db_ae = 10 self.snr_db_ab = snr_db_ab = 10 self.signal_len = signal_len = 1024 self.samp_rate = samp_rate = 100000 self.constellations = constellations = [ const_bpsk, const_qpsk, const_8psk, const_16qam ] self.const_index = const_index = 3 self.ab_mute = ab_mute = False ################################################## # Blocks ################################################## self._snr_db_ae_range = Range(-10, 15, 1, 10, 200) self._snr_db_ae_win = RangeWidget(self._snr_db_ae_range, self.set_snr_db_ae, "snr_db_ae", "counter_slider", float) self.top_layout.addWidget(self._snr_db_ae_win) self._snr_db_ab_range = Range(-10, 15, 1, 10, 200) self._snr_db_ab_win = RangeWidget(self._snr_db_ab_range, self.set_snr_db_ab, "snr_db_ab", "counter_slider", float) self.top_layout.addWidget(self._snr_db_ab_win) self._const_index_options = ( 0, 1, 2, 3, ) self._const_index_labels = ( 'BPSK', 'QPSK', '8PSK', '16QAM', ) self._const_index_group_box = Qt.QGroupBox('Constellation') self._const_index_box = Qt.QHBoxLayout() class variable_chooser_button_group(Qt.QButtonGroup): def __init__(self, parent=None): Qt.QButtonGroup.__init__(self, parent) @pyqtSlot(int) def updateButtonChecked(self, button_id): self.button(button_id).setChecked(True) self._const_index_button_group = variable_chooser_button_group() self._const_index_group_box.setLayout(self._const_index_box) for i, label in enumerate(self._const_index_labels): radio_button = Qt.QRadioButton(label) self._const_index_box.addWidget(radio_button) self._const_index_button_group.addButton(radio_button, i) self._const_index_callback = lambda i: Qt.QMetaObject.invokeMethod( self._const_index_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._const_index_options.index(i))) self._const_index_callback(self.const_index) self._const_index_button_group.buttonClicked[int].connect( lambda i: self.set_const_index(self._const_index_options[i])) self.top_layout.addWidget(self._const_index_group_box) self._ab_mute_options = ( False, True, ) self._ab_mute_labels = ( "Don't Block", 'Block', ) self._ab_mute_group_box = Qt.QGroupBox('Mute AB Output') self._ab_mute_box = Qt.QVBoxLayout() class variable_chooser_button_group(Qt.QButtonGroup): def __init__(self, parent=None): Qt.QButtonGroup.__init__(self, parent) @pyqtSlot(int) def updateButtonChecked(self, button_id): self.button(button_id).setChecked(True) self._ab_mute_button_group = variable_chooser_button_group() self._ab_mute_group_box.setLayout(self._ab_mute_box) for i, label in enumerate(self._ab_mute_labels): radio_button = Qt.QRadioButton(label) self._ab_mute_box.addWidget(radio_button) self._ab_mute_button_group.addButton(radio_button, i) self._ab_mute_callback = lambda i: Qt.QMetaObject.invokeMethod( self._ab_mute_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._ab_mute_options.index(i))) self._ab_mute_callback(self.ab_mute) self._ab_mute_button_group.buttonClicked[int].connect( lambda i: self.set_ab_mute(self._ab_mute_options[i])) self.top_layout.addWidget(self._ab_mute_group_box) self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 1024, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0_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_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_x_0_0_win) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #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) self.qtgui_const_sink_x_0.enable_axis_labels(True) 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_layout.addWidget(self._qtgui_const_sink_x_0_win) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( (constellations[const_index].points()), 1) self.classify_trained_model_classifier_vc_0 = classify.trained_model_classifier_vc( 64, '/home/gvanhoy/gr-classify/apps/cumulant_classifier.pkl') self.channels_channel_model_0_0 = channels.channel_model( noise_voltage=numpy.sqrt(10.0**(-snr_db_ae / 10.0) / 2), frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=0, block_tags=False) self.channels_channel_model_0 = channels.channel_model( noise_voltage=numpy.sqrt(10.0**(-snr_db_ab / 10.0) / 2), frequency_offset=0.0, epsilon=1.0, taps=(1.0, ), noise_seed=0, block_tags=False) self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, 64) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb( 8, int(np.log2(constellations[const_index].arity())), "", False, gr.GR_MSB_FIRST) self.blocks_mute_xx_0 = blocks.mute_cc(bool(ab_mute)) 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.classify_trained_model_classifier_vc_0, 'classification_info'), (self.blocks_message_debug_0, 'print')) self.connect((self.analog_random_source_x_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.blocks_mute_xx_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.classify_trained_model_classifier_vc_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_mute_xx_0, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.channels_channel_model_0_0, 0), (self.blocks_throttle_0_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.channels_channel_model_0_0, 0))
def main(): args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } occupied_carriers=(range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) pilot_carriers=((-21, -7, 7, 21),) pilot_symbols=tuple([(1, -1, 1, -1),]) packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 tb = gr.top_block() if args.freq == None: data_source = mimoots.file_source2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=( '1.'.join(args.from_file.rsplit('.',1)), '2.'.join(args.from_file.rsplit('.',1)) ) ) else: data_source = mimoots.uhd_source(freq=args.freq, gain=args.gain) skip0 = blocks.skiphead( itemsize=gr.sizeof_gr_complex, nitems_to_skip=args.skiphead ) skip1 = blocks.skiphead( itemsize=gr.sizeof_gr_complex, nitems_to_skip=args.skiphead ) #ofdm_frames1 = mimoots.ofdm_receive_frames_cb( # nofdm_frames=args.nframes, # nofdm_symbols=args.nsymbols, # constellation=constellation[args.bits], # occupied_carriers=occupied_carriers, # pilot_carriers=pilot_carriers, # pilot_symbols=pilot_symbols, # debug=args.debug #) #ofdm_frames2 = mimoots.ofdm_receive_frames_cb( # nofdm_frames=args.nframes, # nofdm_symbols=args.nsymbols, # constellation=constellation[args.bits], # occupied_carriers=occupied_carriers, # pilot_carriers=pilot_carriers, # pilot_symbols=pilot_symbols, # debug=args.debug #) ofdm_framer0 = mimoots.ofdm_basebandsignal_to_frames_cvc( fft_len=fft_len, cp_len=cp_len, nofdm_symbols=args.nsymbols ) ofdm_framer1 = mimoots.ofdm_basebandsignal_to_frames_cvc( fft_len=fft_len, cp_len=cp_len, nofdm_symbols=args.nsymbols ) ofdm_symboler0 = mimoots.ofdm_frame_to_symbols_vcc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, constellation=constellation[args.bits], nofdm_symbols=args.nsymbols, packet_len_tag=packet_len_tag ) ofdm_symboler1 = mimoots.ofdm_frame_to_symbols_vcc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, constellation=constellation[args.bits], nofdm_symbols=args.nsymbols, packet_len_tag=packet_len_tag ) ofdm_demapper0 = mimoots.ofdm_symbol_demapper_cb( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ) ofdm_demapper1 = mimoots.ofdm_symbol_demapper_cb( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ) data_sink0 = blocks.vector_sink_b() data_sink1 = blocks.vector_sink_b() tb.connect((data_source, 0), skip0, ofdm_framer0, ofdm_symboler0, ofdm_demapper0, data_sink0) tb.connect((data_source, 1), skip1, ofdm_framer1, ofdm_symboler1, ofdm_demapper1, data_sink1) tb.run() random.seed(42) #data_expected = tuple(args.nframes*[random.randint(0,255) for x in xrange(args.bits*60)]) data_len = utils.ofdm_get_data_len( nofdm_symbols=args.nsymbols, noccupied_carriers=len(occupied_carriers[0]), constellation=constellation[args.bits] ) if args.dummy_frame == True: data_expected = [ tuple(data_len*[0] + args.nframes*[1 for x in xrange(data_len)]), tuple(data_len*[0] + args.nframes*[2 for x in xrange(data_len)]) ] else: data_expected = [ tuple(args.nframes*[1 for x in xrange(data_len)]), tuple(args.nframes*[2 for x in xrange(data_len)]) ] data = [data_sink0.data(), data_sink1.data()] len_data = [] len_data_expected = [] ignored_correlations = [] biterrors_complete = [] biterrorrate_complete = [] for data_index in range(2): biterror = 0 index = 0 for i,j in itertools.izip_longest(data[data_index], data_expected[data_index]): index += 1 if i != j: if i is None or j is None: biterror += 8 else: #print("Index: {} data: {} expected: {}".format(index, i, j)) biterror += bin(i^j).count("1") bits = args.bits len_data = len(data[data_index]) len_data_expected = len(data_expected[data_index]) ignored_correlations = (len(data_expected[data_index])-len(data[data_index]))/(args.bits*60) biterrors_complete = float(biterror)/float(8*len(data_expected[data_index])) biterrorrate_complete = float(biterror)/float(8*len(data_expected[data_index])) print '{}:len(data): {}'.format(data_index, len_data) print '{}:len(data_expected): {}'.format(data_index, len_data_expected) print '{}:Correlation didn\'t work: {} times'.format(data_index, ignored_correlations) print '{}:biterrors: {} biterrorrate: {}'.format(data_index, biterror, biterrorrate_complete) print "\n"
def main(): #self.data = ( [[random.randint(0,255) for x in xrange(self.data_len)] \ # +50*[0,],] ) #self.data = [[0 for x in xrange(self.data_len)],] \ # +self.nofdm_frames*[[random.randint(0,255) \ # for x in xrange(self.data_len)],] #self.data = self.nofdm_frames*[[x for x in xrange(self.data_len)],] \ # + [50*[0,],] args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers=(range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) pilot_carriers=((-21, -7, 7, 21),) pilot_symbols=tuple([(1, -1, 1, -1),]) data_len = utils.ofdm_get_data_len( nofdm_symbols=args.nsymbols, noccupied_carriers=len(occupied_carriers[0]), constellation=constellation[args.bits] ) data0 = args.nframes*[[1 for x in xrange(data_len)],] data1 = args.nframes*[[2 for x in xrange(data_len)],] # sometimes Schmidl-Cox-Correlator ignores first frame # so a dummy-frame is a good idea if args.dummy_frame == True: data0.insert(0, data_len*[0]) data1.insert(0, data_len*[0]) # if file-output GNURadio needs extra frame at the and to loop over all # OFDM-Frames before, last OFDM-Frame is ignored # not so in case of using UHD-devices because there exists incoming # input-data all the time if args.freq == None: data0.append(data_len*[0]) data1.append(data_len*[0]) (data0_tosend, tags0) = packet_utils.packets_to_vectors( data0, packet_len_tag ) (data1_tosend, tags1) = packet_utils.packets_to_vectors( data1, packet_len_tag ) tb = gr.top_block() data_source0 = blocks.vector_source_b( data=data0_tosend, vlen=1, tags=tags0, repeat=False ) data_source1 = blocks.vector_source_b( data=data1_tosend, vlen=1, tags=tags1, repeat=False ) ofdm_mapper0 = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ) ofdm_mapper1 = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ) ofdm_framer0 = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag ) ofdm_framer1 = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag ) ofdm_basebander0 = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag ) ofdm_basebander1 = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag ) if args.freq == None: data_sink = mimoots.file_sink2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=( '1.'.join(args.to_file.rsplit('.',1)), '2.'.join(args.to_file.rsplit('.',1)) ) ) else: data_sink = mimoots.uhd_sink2(freq=args.freq, gain=args.gain) tb.connect(data_source0, ofdm_mapper0, ofdm_framer0, ofdm_basebander0, (data_sink, 0)) tb.connect(data_source1, ofdm_mapper1, ofdm_framer1, ofdm_basebander1, (data_sink, 1)) tb.run() time.sleep(5)
def main(): args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers=(range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) pilot_carriers=((-21, -7, 7, 21),) pilot_symbols=tuple([(1, -1, 1, -1),]) data_len = utils.ofdm_get_data_len( nofdm_symbols=args.nsymbols, noccupied_carriers=len(occupied_carriers[0]), constellation=constellation[args.bits] ) data = args.nframes*[[1 for x in xrange(data_len)],] tb = gr.top_block() (data_tosend, tags) = packet_utils.packets_to_vectors( data, packet_len_tag ) data_source = blocks.vector_source_b( data=data_tosend, vlen=1, tags=tags, repeat=False ) ofdm_mapper = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ) ofdm_framer = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag ) ofdm_basebander = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag ) shifter = blocks.delay( itemsize=gr.sizeof_gr_complex, delay=(fft_len+cp_len)*(3) ) xor_source = blocks.vector_source_c( data=5*[0]+(3*(fft_len+cp_len)-10)*[1]+5*[0]+3*(fft_len+cp_len)*[0], repeat=True ) xor1 = blocks.multiply_cc() xor2 = blocks.multiply_cc() if args.freq == None: data_sink = mimoots.file_sink2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=( '1.'.join(args.to_file.rsplit('.',1)), '2.'.join(args.to_file.rsplit('.',1)) ) ) else: data_sink = mimoots.uhd_sink2(freq=args.freq, gain=args.gain) tb.connect(xor_source, (xor1, 1)) tb.connect(xor_source, (xor2, 1)) tb.connect(data_source, ofdm_mapper, ofdm_framer, ofdm_basebander) tb.connect(ofdm_basebander, (xor1, 0), (data_sink, 0)) tb.connect(ofdm_basebander, (xor2, 0), shifter, (data_sink, 1)) tb.run() time.sleep(5)
def main(): args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers=(range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) pilot_carriers=((-21, -7, 7, 21),) pilot_symbols=tuple([(1, -1, 1, -1),]) tb = gr.top_block() if args.freq == None: data_source = blocks.file_source( itemsize=gr.sizeof_gr_complex, filename=args.from_file ) else: data_source = mimoots.uhd_source(freq=args.freq, gain=args.gain) skip = blocks.skiphead( itemsize=gr.sizeof_gr_complex, nitems_to_skip=args.skiphead ) #ofdm_frames = mimoots.ofdm_receive_frames_cb( # nofdm_frames=args.nframes, # nofdm_symbols=args.nsymbols, # constellation=constellation[args.bits], # occupied_carriers=occupied_carriers, # pilot_carriers=pilot_carriers, # pilot_symbols=pilot_symbols, # debug=args.debug #) ofdm_framer = mimoots.ofdm_basebandsignal_to_frames_cvc( fft_len=fft_len, cp_len=cp_len, nofdm_symbols=args.nsymbols ) ofdm_symboler = mimoots.ofdm_frame_to_symbols_vcc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, constellation=constellation[args.bits], nofdm_symbols=args.nsymbols, packet_len_tag=packet_len_tag ); ofdm_demapper = mimoots.ofdm_symbol_demapper_cb( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ); data_sink = blocks.vector_sink_b() tb.connect(data_source, skip, ofdm_framer, ofdm_symboler, ofdm_demapper, data_sink) tb.run() random.seed(42) #data_expected = tuple(args.nframes*[random.randint(0,255) for x in xrange(args.bits*60)]) data_len = utils.ofdm_get_data_len( nofdm_symbols=args.nsymbols, noccupied_carriers=len(occupied_carriers[0]), constellation=constellation[args.bits] ) if args.dummy_frame == True: data_expected = tuple(data_len*[0] + args.nframes*[1 for x in xrange(data_len)]) else: data_expected = tuple(args.nframes*[1 for x in xrange(data_len)]) data = data_sink.data() # TODO: args.bits*60=datalen, 60 depends on len of data_carriers len_data = [] len_data_expected = [] ignored_correlations = [] biterrors_complete = [] biterrorrate_complete = [] biterror = 0 index = 0 for i,j in itertools.izip_longest(data, data_expected): index += 1 if i != j: if i is None or j is None: biterror += 8 else: #print("Index: {} data: {} expected: {}".format(index, i, j)) biterror += bin(i^j).count("1") bits = args.bits len_data = len(data) len_data_expected = len(data_expected) ignored_correlations = (len(data_expected)-len(data))/(args.bits*60) biterrors_complete = float(biterror)/float(8*len(data_expected)) biterrorrate_complete = float(biterror)/float(8*len(data_expected)) print 'len(data): {}'.format(len_data) print 'len(data_expected): {}'.format(len_data_expected) print 'Correlation didn\'t work: {} times'.format(ignored_correlations) print 'biterrors: {} biterrorrate: {}'.format(biterror, biterrorrate_complete)
def main(): args = get_arguments() constellation = { 1: digital.constellation_bpsk(), 2: digital.constellation_qpsk(), 3: digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27), ) pilot_carriers = ((-21, -7, 7, 21), ) pilot_symbols = tuple([ (1, -1, 1, -1), ]) tb = gr.top_block() if args.freq == None: data_source = blocks.file_source(itemsize=gr.sizeof_gr_complex, filename=args.from_file) else: data_source = mimoots.uhd_source(freq=args.freq, gain=args.gain) skip = blocks.skiphead(itemsize=gr.sizeof_gr_complex, nitems_to_skip=args.skiphead) #ofdm_frames = mimoots.ofdm_receive_frames_cb( # nofdm_frames=args.nframes, # nofdm_symbols=args.nsymbols, # constellation=constellation[args.bits], # occupied_carriers=occupied_carriers, # pilot_carriers=pilot_carriers, # pilot_symbols=pilot_symbols, # debug=args.debug #) ofdm_framer = mimoots.ofdm_basebandsignal_to_frames_cvc( fft_len=fft_len, cp_len=cp_len, nofdm_symbols=args.nsymbols) ofdm_symboler = mimoots.ofdm_frame_to_symbols_vcc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, constellation=constellation[args.bits], nofdm_symbols=args.nsymbols, packet_len_tag=packet_len_tag) ofdm_demapper = mimoots.ofdm_symbol_demapper_cb( constellation=constellation[args.bits], packet_len_tag=packet_len_tag) data_sink = blocks.vector_sink_b() tb.connect(data_source, skip, ofdm_framer, ofdm_symboler, ofdm_demapper, data_sink) tb.run() random.seed(42) #data_expected = tuple(args.nframes*[random.randint(0,255) for x in xrange(args.bits*60)]) data_len = utils.ofdm_get_data_len(nofdm_symbols=args.nsymbols, noccupied_carriers=len( occupied_carriers[0]), constellation=constellation[args.bits]) if args.dummy_frame == True: data_expected = tuple(data_len * [0] + args.nframes * [1 for x in xrange(data_len)]) else: data_expected = tuple(args.nframes * [1 for x in xrange(data_len)]) data = data_sink.data() # TODO: args.bits*60=datalen, 60 depends on len of data_carriers len_data = [] len_data_expected = [] ignored_correlations = [] biterrors_complete = [] biterrorrate_complete = [] biterror = 0 index = 0 for i, j in itertools.izip_longest(data, data_expected): index += 1 if i != j: if i is None or j is None: biterror += 8 else: #print("Index: {} data: {} expected: {}".format(index, i, j)) biterror += bin(i ^ j).count("1") bits = args.bits len_data = len(data) len_data_expected = len(data_expected) ignored_correlations = (len(data_expected) - len(data)) / (args.bits * 60) biterrors_complete = float(biterror) / float(8 * len(data_expected)) biterrorrate_complete = float(biterror) / float(8 * len(data_expected)) print 'len(data): {}'.format(len_data) print 'len(data_expected): {}'.format(len_data_expected) print 'Correlation didn\'t work: {} times'.format(ignored_correlations) print 'biterrors: {} biterrorrate: {}'.format(biterror, biterrorrate_complete)
def main(): #self.data = ( [[random.randint(0,255) for x in xrange(self.data_len)] # +50*[0,],] ) #self.data = [[0 for x in xrange(self.data_len)],] \ # + self.nofdm_frames*[[random.randint(0,255) \ # for x in xrange(self.data_len)],] #self.data = self.nofdm_frames*[[x for x in xrange(self.data_len)],]\ # + [50*[0,],] args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } packet_len_tag = "packet_length" #fft_len = 64 #cp_len = 16 #occupied_carriers = (range(-26, -21) + range(-20, -7) + # range(-6, 0) + range(1, 7) + # range(8, 21) + range(22, 27),) #pilot_carriers = ((-21, -7, 7, 21),) #pilot_symbols = tuple([(1, -1, 1, -1),]) fft_len = 16 cp_len = 4 occupied_carriers = ((-5, -4, -2, -1, 1, 2, 4, 5),) pilot_carriers = ((-3, 3),) pilot_symbols = tuple([(1, -1),]) data_len = utils.ofdm_get_data_len( nofdm_symbols=args.nsymbols, noccupied_carriers=len(occupied_carriers[0]), constellation=constellation[args.bits] ) data = args.nframes*[[39 for x in xrange(data_len)],] # sometimes Schmidl-Cox-Correlator ignores first frame # so a dummy-frame is a good idea if args.dummy_frame_start == True: data.insert(0, data_len*[0]) # if file-output GNURadio needs extra frame at the and to loop over all # OFDM-Frames before, last OFDM-Frame is ignored # not so in case of using UHD-devices because there exists incoming # input-data all the time if args.dummy_frame_end == True: data.append(data_len*[0]) tb = gr.top_block() (data_tosend, tags) = packet_utils.packets_to_vectors( data, packet_len_tag ) data_source = blocks.vector_source_b( data=data_tosend, vlen=1, tags=tags, repeat=False ) ofdm_mapper = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag, verbose=args.verbose ) ofdm_framer = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag, verbose=args.verbose ) ofdm_basebander = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag, verbose=args.verbose ) if args.freq == None: data_sink = blocks.file_sink( itemsize=gr.sizeof_gr_complex, filename=args.to_file ) else: data_sink = mimoots.uhd_sink(freq=args.freq, gain=args.gain) tb.connect(data_source, ofdm_mapper, ofdm_framer, ofdm_basebander, data_sink) tb.run() # need to wait until the GNURadio-graph is finished time.sleep(5)
def __init__(self, constellation=[-1, 1]): gr.top_block.__init__(self, "Channel Model") ################################################## # Parameters ################################################## self.constellation = constellation ################################################## # Variables ################################################## self.const_points = const_points = constellation self.taps = taps = [1.0, 0.25 - 0.25j, 0.50 + 0.10j, 0.3 + 0.2j] self.samp_rate = samp_rate = 8e6 self.noise_level = noise_level = 0.3 self.frequency = frequency = 2000000 self.const_type = const_type = 1 self.const_dist = const_dist = digital.constellation_calcdist( const_points, [], 0, 1) self.const = const = digital.constellation_8psk().bits_per_symbol() ################################################## # Blocks ################################################## self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb( const_dist.base()) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( const_dist.base()) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( (const_dist.points()), 1) self.custom_ber_0 = custom_ber(n_bits=10000, ) self.channels_channel_model_0_0 = channels.channel_model( noise_voltage=0, frequency_offset=0, epsilon=1, taps=([1, 0, 0, 0]), noise_seed=0, block_tags=False) self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise_level, frequency_offset=0, epsilon=1, taps=(taps), noise_seed=0, block_tags=False) self.blocks_vector_sink_x_1 = blocks.vector_sink_f(1) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, len(const_points), 10000)), False) ################################################## # Connections ################################################## self.connect((self.custom_ber_0, 0), (self.blocks_vector_sink_x_1, 0)) self.connect((self.channels_channel_model_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.custom_ber_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.custom_ber_0, 1)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.channels_channel_model_0_0, 0)) self.connect((self.channels_channel_model_0_0, 0), (self.digital_constellation_decoder_cb_0_0, 0))
def main(): args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } fft_len = 64 cp_len = 16 occupied_carriers=(range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) pilot_carriers=((-21, -7, 7, 21),) pilot_symbols=tuple([(1, -1, 1, -1),]) tb1 = gr.top_block() tb2 = gr.top_block() if args.freq == None: data_source = mimoots.file_source2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=( '1.'.join(args.from_file.rsplit('.',1)), '2.'.join(args.from_file.rsplit('.',1)) ) ) else: data_source = mimoots.uhd_source2(freq=args.freq, gain=args.gain) skip1 = blocks.skiphead( itemsize=gr.sizeof_gr_complex, nitems_to_skip=args.skiphead ) skip2 = blocks.skiphead( itemsize=gr.sizeof_gr_complex, nitems_to_skip=args.skiphead ) ofdm_frames1 = mimoots.ofdm_basebandsignal_to_frames_cvc( fft_len=fft_len, cp_len=cp_len, nofdm_symbols=args.nsymbols ) ofdm_frames2 = mimoots.ofdm_basebandsignal_to_frames_cvc( fft_len=fft_len, cp_len=cp_len, nofdm_symbols=args.nsymbols ) buffer1 = blocks.vector_sink_c(vlen=fft_len) buffer2 = blocks.vector_sink_c(vlen=fft_len) tb1.connect((data_source,0), skip1, ofdm_frames1, buffer1) tb1.connect((data_source,1), skip2, ofdm_frames2, buffer2) tb1.connect(ofdm_frames1, blocks.file_sink(gr.sizeof_gr_complex*fft_len, 'd1.gr')) tb1.connect(ofdm_frames2, blocks.file_sink(gr.sizeof_gr_complex*fft_len, 'd2.gr')) tb1.run() data1 = buffer1.data() data2 = buffer2.data() data1 = extract_channeldata(data1, 0, fft_len) data2 = extract_channeldata(data2, 1, fft_len) buf_source1 = blocks.vector_source_c(data1) buf_source2 = blocks.vector_source_c(data2) data_sink = mimoots.file_sink2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=('s1r1.gr', 's2r2.gr') ) tb2.connect(buf_source1, (data_sink, 0)) tb2.connect(buf_source2, (data_sink, 1)) tb2.run()