def test_xor_bb (self):
     src1_data =       [1,  2,  3,  4,   0x50]
     src2_data =       [8,  2,  1 , 8,   0x05]
     expected_result = [9,  0,  2,  0xC, 0x55]
     op = blocks.xor_bb ()
     self.help_bb ((src1_data, src2_data),
                   expected_result, op)
Beispiel #2
0
 def test_001_t(self):
     energy_dispersal_undone = (0x05, 0x00, 0x10, 0xea, 0x04, 0x24, 0x06,
                                0x02, 0xd3, 0xa6, 0x01, 0x3f, 0x06, 0xff,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x4c, 0x89)
     energy_dispersal_done = (0x02, 0xBE, 0x3E, 0x8E, 0x16, 0xB9, 0xA5,
                              0xCD, 0x48, 0xB3, 0x22, 0xB2, 0xAD, 0x76,
                              0x88, 0x80, 0x42, 0x30, 0x9C, 0xAB, 0x0D,
                              0xE9, 0xB9, 0x14, 0x2B, 0x4F, 0xD9, 0x25,
                              0xBF, 0x26, 0xEA, 0xE9)
     fib_packed_to_unpacked = blocks.packed_to_unpacked_bb(
         1, gr.GR_MSB_FIRST)
     fib_unpacked_to_packed = blocks.unpacked_to_packed_bb(
         1, gr.GR_MSB_FIRST)
     src = blocks.vector_source_b(energy_dispersal_undone)
     self.dp = grdab.parameters.dab_parameters(1, 2e6, False)
     prbs_src = blocks.vector_source_b(
         self.dp.prbs(self.dp.energy_dispersal_fic_vector_length), True)
     add_mod_2 = blocks.xor_bb()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, fib_packed_to_unpacked, add_mod_2,
                     fib_unpacked_to_packed, dst)
     self.tb.connect(prbs_src, (add_mod_2, 1))
     self.tb.run()
     result_data = dst.data()
     self.assertFloatTuplesAlmostEqual(energy_dispersal_done, result_data,
                                       6)
 def test_xor_bb (self):
     src1_data =       (1,  2,  3,  4,   0x50)
     src2_data =       (8,  2,  1 , 8,   0x05)
     expected_result = (9,  0,  2,  0xC, 0x55)
     op = blocks.xor_bb ()
     self.help_bb ((src1_data, src2_data),
                   expected_result, op)
Beispiel #4
0
    def __init__(self, n_bits=1000, bits_per_symbol=3):
        gr.hier_block2.__init__(
            self, "Custom Ber",
            gr.io_signaturev(2, 2, [gr.sizeof_char*1, gr.sizeof_char*1]),
            gr.io_signature(1, 1, gr.sizeof_float*1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.n_bits = n_bits
        self.bits_per_symbol = bits_per_symbol

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 8e6

        ##################################################
        # Blocks
        ##################################################
        self.blocks_xor_xx_0 = blocks.xor_bb()
        self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_symbol)
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_moving_average_xx_0 = blocks.moving_average_ff(n_bits, 1/float(n_bits), n_bits*4)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_moving_average_xx_0, 0), (self, 0))
        self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_moving_average_xx_0, 0))
        self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_uchar_to_float_0, 0))
        self.connect((self.blocks_xor_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0))
        self.connect((self, 1), (self.blocks_xor_xx_0, 1))
        self.connect((self, 0), (self.blocks_xor_xx_0, 0))
Beispiel #5
0
    def __init__(self):
        gr.hier_block2.__init__(
            self,
            "Bit Error Rate",
            gr.io_signaturev(2, 2, [gr.sizeof_char * 1, gr.sizeof_char * 1]),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
        )

        ##################################################
        # Variables
        ##################################################
        self._msgLength_config = ConfigParser.ConfigParser()
        self._msgLength_config.read("./configs/sdrConfig.txt")
        try:
            msgLength = self._msgLength_config.getint("main", "key")
        except:
            msgLength = 10000
        self.msgLength = msgLength
        self._bits_per_byte_config = ConfigParser.ConfigParser()
        self._bits_per_byte_config.read("./configs/sdrConfig.txt")
        try:
            bits_per_byte = self._bits_per_byte_config.getint("main", "key")
        except:
            bits_per_byte = 8
        self.bits_per_byte = bits_per_byte

        intdecim = 100000
        if msgLength < intdecim:
            intdecim = msgLength

        ##################################################
        # Blocks
        ##################################################
        self.blocks_xor_xx_0 = blocks.xor_bb()
        self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_byte)
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff(
            (1.0 / msgLength, ))
        self.blocks_integrate_xx_0 = blocks.integrate_ff(intdecim)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_integrate_xx_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self, 1), (self.blocks_xor_xx_0, 1))
        self.connect((self, 0), (self.blocks_xor_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0))
        self.connect((self.blocks_xor_xx_0, 0),
                     (self.blocks_unpack_k_bits_bb_0, 0))
        self.connect((self.blocks_unpack_k_bits_bb_0, 0),
                     (self.blocks_uchar_to_float_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.blocks_integrate_xx_0, 0))
Beispiel #6
0
    def __init__(self, dtype="discrete", limit=10000, randomize=False):
        if dtype == "discrete":
            gr.hier_block2.__init__(self, "source_alphabet",
                                    gr.io_signature(0, 0, 0),
                                    gr.io_signature(1, 1, gr.sizeof_char))

            self.src = blocks.file_source(
                gr.sizeof_char, "source_material/gutenberg_shakespeare.txt")
            self.convert = blocks.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST)
            # self.convert = blocks.packed_to_unpacked_bb(8, gr.GR_LSB_FIRST);
            self.limit = blocks.head(gr.sizeof_char, limit)
            self.connect(self.src, self.convert)
            last = self.convert

            # whiten our sequence with a random block scrambler (optionally)
            if randomize:
                rand_len = 256
                rand_bits = np.random.randint(2, size=rand_len)
                self.rand_src = blocks.vector_source_b(rand_bits, True)
                self.xor = blocks.xor_bb()
                self.connect(self.rand_src, (self.xor, 1))
                self.connect(last, self.xor)
                last = self.xor
        elif dtype == "continuous":  # continuous
            gr.hier_block2.__init__(self, "source_alphabet",
                                    gr.io_signature(0, 0, 0),
                                    gr.io_signature(1, 1, gr.sizeof_float))

            self.src = blocks.wavfile_source(
                "source_material/serial-s01-e01.mp3", True)
            self.float_short = blocks.float_to_short(1, 1)
            self.convert2 = blocks.interleaved_short_to_complex()
            self.convert3 = blocks.multiply_const_cc(1.0 / 65535)
            self.convert = blocks.complex_to_float()
            self.limit = blocks.head(gr.sizeof_float, limit)
            self.connect(self.src, self.convert2, self.convert3, self.convert)
            last = self.convert
        else:  # noise
            gr.hier_block2.__init__(
                self, "source_alphabet", gr.io_signature(0, 0, 0),
                gr.io_signature(1, 1, gr.sizeof_gr_complex))

            self.src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, 1e-4, 0,
                                                 8192)
            self.limit = blocks.head(gr.sizeof_gr_complex, limit)
            last = self.src

        # connect head or not, and connect to output
        if limit is None:
            self.connect(last, self)
        else:
            self.connect(last, self.limit, self)
    def __init__(self,
                 dtype="discrete",
                 limit=10000,
                 randomize=False,
                 repeat=False):
        if (dtype == "discrete"):
            gr.hier_block2.__init__(self, "source_alphabet",
                                    gr.io_signature(0, 0, 0),
                                    gr.io_signature(1, 1, gr.sizeof_char))

            self.src = blocks.file_source(
                gr.sizeof_char,
                "source_material/gutenberg_shakespeare.txt",
                repeat=repeat)
            self.convert = blocks.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST)
            #self.convert = blocks.packed_to_unpacked_bb(8, gr.GR_LSB_FIRST);
            if limit is not None:
                self.limit = blocks.head(gr.sizeof_char, limit)
            self.connect(self.src, self.convert)
            last = self.convert

            # whiten our sequence with a random block scrambler (optionally)
            if (randomize):
                rand_len = 256
                rand_bits = np.random.randint(2, size=rand_len)
                self.randsrc = blocks.vector_source_b(rand_bits, True)
                self.xor = blocks.xor_bb()
                self.connect(self.randsrc, (self.xor, 1))
                self.connect(last, self.xor)
                last = self.xor

        else:  # "type_continuous"
            gr.hier_block2.__init__(self, "source_alphabet",
                                    gr.io_signature(0, 0, 0),
                                    gr.io_signature(1, 1, gr.sizeof_float))

            self.src = mediatools.audiosource_s(
                ["source_material/serial-s01-e01.mp3"])
            self.convert2 = blocks.interleaved_short_to_complex()
            self.convert3 = blocks.multiply_const_cc(1.0 / 65535)
            self.convert = blocks.complex_to_float()
            if limit is not None:
                self.limit = blocks.head(gr.sizeof_float, limit)
            self.connect(self.src, self.convert2, self.convert3, self.convert)
            last = self.convert

        # connect head or not, and connect to output
        if (limit is None):
            self.connect(last, self)
        else:
            self.connect(last, self.limit, self)
Beispiel #8
0
 def __init__(self, bits_per_byte):
     gr.hier_block2.__init__(self, "BitErrors",
                             gr.io_signature(2, 2, gr.sizeof_char),
                             gr.io_signature(1, 1, gr.sizeof_int))
     # Bit comparison
     comp = blocks.xor_bb()
     intdump_decim = 100000
     if N_BITS < intdump_decim:
         intdump_decim = int(N_BITS)
     self.connect(self, comp, blocks.unpack_k_bits_bb(bits_per_byte),
                  blocks.uchar_to_float(),
                  blocks.integrate_ff(intdump_decim),
                  blocks.multiply_const_ff(1.0 / N_BITS), self)
     self.connect((self, 1), (comp, 1))
Beispiel #9
0
 def test_001_t (self):
     energy_dispersal_undone = (0x05, 0x00, 0x10, 0xea, 0x04, 0x24, 0x06, 0x02, 0xd3, 0xa6, 0x01, 0x3f, 0x06, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x89)
     energy_dispersal_done = (0x02, 0xBE, 0x3E, 0x8E, 0x16, 0xB9, 0xA5, 0xCD, 0x48, 0xB3, 0x22, 0xB2, 0xAD, 0x76, 0x88, 0x80, 0x42, 0x30, 0x9C, 0xAB, 0x0D, 0xE9, 0xB9, 0x14, 0x2B, 0x4F, 0xD9, 0x25, 0xBF, 0x26, 0xEA, 0xE9)
     fib_packed_to_unpacked = blocks.packed_to_unpacked_bb(1,gr.GR_MSB_FIRST)
     fib_unpacked_to_packed = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     src = blocks.vector_source_b(energy_dispersal_undone)
     self.dp = grdab.parameters.dab_parameters(1, 2e6, False)
     prbs_src = blocks.vector_source_b(self.dp.prbs(self.dp.energy_dispersal_fic_vector_length), True)
     add_mod_2 = blocks.xor_bb()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, fib_packed_to_unpacked, add_mod_2, fib_unpacked_to_packed, dst)
     self.tb.connect(prbs_src, (add_mod_2, 1))
     self.tb.run ()
     result_data = dst.data()
     self.assertFloatTuplesAlmostEqual(energy_dispersal_done, result_data, 6)
Beispiel #10
0
    def __init__(self, dab_params):
        gr.hier_block2.__init__(
            self,
            "fic_encode",
            gr.io_signature(1, 1, gr.sizeof_char),
            # Input signature
            gr.io_signature(1, 1, gr.sizeof_char))
        # Output signature
        self.dp = dab_params

        # crc
        self.unpacked_to_packed_crc = blocks.unpacked_to_packed_bb_make(
            1, gr.GR_MSB_FIRST)
        self.s2v_crc = blocks.stream_to_vector(gr.sizeof_char, 32)
        self.crc16 = dab.crc16_bb(32, 0x1021, 0xffff)
        self.v2s_crc = blocks.vector_to_stream(gr.sizeof_char, 32)
        self.packed_to_unpacked_crc = blocks.packed_to_unpacked_bb_make(
            1, gr.GR_MSB_FIRST)

        # energy dispersal
        self.prbs_src = blocks.vector_source_b(
            self.dp.prbs(self.dp.energy_dispersal_fic_vector_length), True)
        self.add_mod_2 = blocks.xor_bb()

        # convolutional encoder
        self.conv_pack = blocks.unpacked_to_packed_bb_make(1, gr.GR_MSB_FIRST)
        self.conv_encoder = dab.conv_encoder_bb_make(
            self.dp.energy_dispersal_fic_vector_length / 8)
        self.conv_unpack = blocks.packed_to_unpacked_bb_make(
            1, gr.GR_MSB_FIRST)

        # puncturing
        self.puncture = dab.puncture_bb_make(
            self.dp.assembled_fic_puncturing_sequence)

        # pack bits
        self.unpacked_to_packed_encoded = blocks.unpacked_to_packed_bb_make(
            1, gr.GR_MSB_FIRST)

        # connect everything
        self.connect((self, 0), self.unpacked_to_packed_crc, self.s2v_crc,
                     self.crc16, self.v2s_crc, self.packed_to_unpacked_crc,
                     (self.add_mod_2, 0), self.conv_pack, self.conv_encoder,
                     self.conv_unpack, self.puncture,
                     self.unpacked_to_packed_encoded, self)

        #connect prbs
        self.connect(self.prbs_src, (self.add_mod_2, 1))
Beispiel #11
0
    def __init__(self, bits_per_byte):
        gr.hier_block2.__init__(self, "BitErrors",
                gr.io_signature(2, 2, gr.sizeof_char),
                gr.io_signature(1, 1, gr.sizeof_int))

        # Bit comparison
        comp = blocks.xor_bb()
        intdump_decim = 100000
        if N_BITS < intdump_decim:
            intdump_decim = int(N_BITS)
        self.connect(self,
                     comp,
                     blocks.unpack_k_bits_bb(bits_per_byte),
                     blocks.uchar_to_float(),
                     blocks.integrate_ff(intdump_decim),
                     blocks.multiply_const_ff(1.0 / N_BITS),
                     self)
        self.connect((self, 1), (comp, 1))
Beispiel #12
0
  def sim ( self, arity, snr_db, N ):
    
    vlen = 1
    N = int( N )
    snr = 10.0**(snr_db/10.0)
    
    sigpow = 1.0
    noise_pow = sigpow / snr
    
    demapper = ofdm.generic_demapper_vcb( vlen )
    const = demapper.get_constellation( arity )
    assert( len( const ) == 2**arity )
    
    symsrc = ofdm.symbol_random_src( const, vlen )
    noise_src = ofdm.complex_white_noise( 0.0, sqrt( noise_pow ) )
    channel = blocks.add_cc()
    bitmap_src = blocks.vector_source_b( [arity] * vlen, True, vlen )
    bm_trig_src = blocks.vector_source_b( [1], True )
    ref_bitstream = blocks.unpack_k_bits_bb( arity )
    bitstream_xor = blocks.xor_bb()
    bitstream_c2f = blocks.char_to_float()
    acc_biterr = ofdm.accumulator_ff()
    skiphead = blocks.skiphead( gr.sizeof_float, N-1 )
    limit = blocks.head( gr.sizeof_float, 1 )
    dst = blocks.vector_sink_f()
    
    tb = gr.top_block ( "test_block" )
    
    tb.connect( (symsrc,0), (channel,0) )
    tb.connect( noise_src,  (channel,1) )
    tb.connect( channel,     (demapper,0), (bitstream_xor,0) )
    tb.connect( bitmap_src,  (demapper,1) )
    tb.connect( bm_trig_src, (demapper,2) )
    tb.connect( (symsrc,1), ref_bitstream, (bitstream_xor,1) )
    tb.connect( bitstream_xor, bitstream_c2f, acc_biterr )
    tb.connect( acc_biterr, skiphead, limit, dst )

    tb.run()
    
    bit_errors = numpy.array( dst.data() )
    assert( len( bit_errors ) == 1 )
    bit_errors = bit_errors[0]
    
    return bit_errors / N
Beispiel #13
0
    def __init__(self):
        gr.hier_block2.__init__(
            self, "Bit Error Rate",
            gr.io_signaturev(2, 2, [gr.sizeof_char*1, gr.sizeof_char*1]),
            gr.io_signature(1, 1, gr.sizeof_float*1),
        )

        ##################################################
        # Variables
        ##################################################
        self._msgLength_config = ConfigParser.ConfigParser()
        self._msgLength_config.read("./configs/sdrConfig.txt")
        try: msgLength = self._msgLength_config.getint("main", "key")
        except: msgLength = 10000
        self.msgLength = msgLength
        self._bits_per_byte_config = ConfigParser.ConfigParser()
        self._bits_per_byte_config.read("./configs/sdrConfig.txt")
        try: bits_per_byte = self._bits_per_byte_config.getint("main", "key")
        except: bits_per_byte = 8
        self.bits_per_byte = bits_per_byte

        intdecim = 100000
        if msgLength < intdecim:
            intdecim = msgLength
        
        ##################################################
        # Blocks
        ##################################################
        self.blocks_xor_xx_0 = blocks.xor_bb()
        self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_byte)
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((1.0/msgLength, ))
        self.blocks_integrate_xx_0 = blocks.integrate_ff(intdecim)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self, 1), (self.blocks_xor_xx_0, 1))
        self.connect((self, 0), (self.blocks_xor_xx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0))
        self.connect((self.blocks_xor_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0))
        self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_uchar_to_float_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_integrate_xx_0, 0))
	def sim ( self, arity, snr_db, N ):
		M = 1024
		theta_sel = 0
		syms_per_frame = 10
		zero_pads = 1
		center_preamble = [1, -1j, -1, 1j] # assumed to be normalized to 1
		qam_size = 2**arity
		preamble = [0]*M*zero_pads+center_preamble*((int)(M/len(center_preamble)))+[0]*M*zero_pads
		# num_symbols = 2**12
		exclude_preamble = 0
		exclude_multipath =0
		sel_taps = 0 # epa=0, eva = 1, etu=3
		freq_offset=0
		exclude_noise = 0
		sel_noise_type =0 # gaussian
		eq_select = 3
		# SNR = 20
		K = 4
		N = int( N ) # num of !samples!
		num_bits = N*arity
		# amp = math.sqrt(M/(10**(float(snr_db)/10)))/math.sqrt(2)
		# amp = math.sqrt((10**(float(-1*snr_db)/20))*(2*K*M+(2*syms_per_frame-1)*M)/(4*syms_per_frame))/math.sqrt(2)
		if exclude_preamble:
			amp = math.sqrt((10**(float(-1*snr_db)/10))*(2*K*M+(2*syms_per_frame-1)*M)/(4*syms_per_frame))/math.sqrt(2)
		else:
			amp = math.sqrt((10**(float(-1*snr_db)/10))*(M*(syms_per_frame+1)/(syms_per_frame+1+2*zero_pads))*((K*M+(2*syms_per_frame-1)*M/2)/(M*syms_per_frame)))/math.sqrt(2)
		# print amp
		# print amp2
		tx = transmitter_hier_bc(M, K, qam_size, syms_per_frame, theta_sel, exclude_preamble, center_preamble,1)
		rx = receiver_hier_cb(M, K, qam_size, syms_per_frame, theta_sel, eq_select, exclude_preamble, center_preamble,1)
		ch = channel_hier_cc(M, K, syms_per_frame, exclude_multipath, sel_taps, freq_offset, exclude_noise, sel_noise_type, snr_db, exclude_preamble, zero_pads)

		# # src = blocks.vector_source_b(src_data, vlen=1)
		xor_block = blocks.xor_bb()
		head1 = blocks.head(gr.sizeof_char*1, N)
		head0 = blocks.head(gr.sizeof_char*1, N)
		add_block = blocks.add_vcc(1)
		src = blocks.vector_source_b(map(int, numpy.random.randint(0, qam_size, 100000)), True)
		noise = analog.fastnoise_source_c(analog.GR_GAUSSIAN, amp, 0, 8192)
		dst = blocks.vector_sink_b(vlen=1)

		tb = gr.top_block ( "test_block" )
		tb.connect((src, 0), (head1, 0)) #esas
		tb.connect((head1, 0), (xor_block, 0)) #esas
		tb.connect((src, 0), (tx, 0)) #esas
		tb.connect((tx, 0), (add_block, 0)) #esas
		tb.connect((noise, 0), (add_block, 1)) #esas
		# tb.connect((head0, 0), (add_block, 1)) #esas
		tb.connect((add_block, 0), (rx, 0)) #esas
		tb.connect((rx, 0),(head0, 0)) #esas
		tb.connect((head0, 0), (xor_block, 1)) #esas
		tb.connect((xor_block, 0), (dst, 0)) #esas  

		tb.run()

		# what we record in dst.data will be output of xor_block. now we have to process those data
		# so as to find bit errors.
		result_data = dst.data()

		bit_errors = 0
		for i in range(len(result_data)):
			# print bin(result_data[i])
			bit_errors = bit_errors + (bin(result_data[i]).count('1'))

		# print len(result_data)

		# return 1

		return float(bit_errors) / num_bits
Beispiel #15
0
    def __init__(self,
                 dab_params,
                 address,
                 size,
                 protection,
                 verbose=False,
                 debug=False):
        gr.hier_block2.__init__(
            self,
            "msc_decode",
            # Input signature
            gr.io_signature(1, 1,
                            gr.sizeof_float * dab_params.num_carriers * 2),
            # Output signature
            gr.io_signature(1, 1, gr.sizeof_char))
        self.dp = dab_params
        self.address = address
        self.size = size
        self.protect = protection
        self.verbose = verbose
        self.debug = debug

        # calculate n factor (multiple of 8kbits etc.)
        self.n = self.size / self.dp.subch_size_multiple_n[self.protect]

        # calculate puncturing factors (EEP, table 33, 34)
        self.msc_I = self.n * 192
        if (self.n > 1 or self.protect != 1):
            self.puncturing_L1 = [
                6 * self.n - 3, 2 * self.n - 3, 6 * self.n - 3, 4 * self.n - 3
            ]
            self.puncturing_L2 = [3, 4 * self.n + 3, 3, 2 * self.n + 3]
            self.puncturing_PI1 = [24, 14, 8, 3]
            self.puncturing_PI2 = [23, 13, 7, 2]
            # calculate length of punctured codeword (11.3.2)
            self.msc_punctured_codeword_length = self.puncturing_L1[self.protect] * 4 * self.dp.puncturing_vectors_ones[
                self.puncturing_PI1[self.protect]] + self.puncturing_L2[self.protect] * 4 * \
                                                     self.dp.puncturing_vectors_ones[
                                                         self.puncturing_PI2[self.protect]] + 12
            self.assembled_msc_puncturing_sequence = int(self.puncturing_L1[
                self.protect]) * 4 * self.dp.puncturing_vectors[
                    self.puncturing_PI1[self.protect]] + int(
                        self.puncturing_L2[self.protect]
                    ) * 4 * self.dp.puncturing_vectors[self.puncturing_PI2[
                        self.protect]] + self.dp.puncturing_tail_vector
            self.msc_conv_codeword_length = 4 * self.msc_I + 24  # 4*I + 24 ()
        # exception in table
        else:
            self.msc_punctured_codeword_length = 5 * 4 * self.dp.puncturing_vectors_ones[13] + 1 * 4 * \
                                                                                               self.dp.puncturing_vectors_ones[
                                                                                                   12] + 12
        #sanity check
        assert (6 * self.n == self.puncturing_L1[self.protect] +
                self.puncturing_L2[self.protect])

        # MSC selection and block partitioning
        # select OFDM carriers with MSC
        self.select_msc_syms = grdab.select_vectors(gr.sizeof_float,
                                                    self.dp.num_carriers * 2,
                                                    self.dp.num_msc_syms,
                                                    self.dp.num_fic_syms)
        # repartition MSC data in CIFs (left out due to heavy burden for scheduler and not really necessary)
        #self.repartition_msc_to_CIFs = grdab.repartition_vectors_make(gr.sizeof_float, self.dp.num_carriers * 2,
        #                                                            self.dp.cif_bits, self.dp.num_msc_syms,
        #                                                            self.dp.num_cifs)
        #repartition MSC to CUs
        self.repartition_msc_to_cus = grdab.repartition_vectors_make(
            gr.sizeof_float, self.dp.num_carriers * 2, self.dp.msc_cu_size,
            self.dp.num_msc_syms, self.dp.num_cus * self.dp.num_cifs)

        # select CUs of one subchannel of each CIF and form logical frame vector
        self.select_subch = grdab.select_subch_vfvf_make(
            self.dp.msc_cu_size, self.dp.msc_cu_size * self.size, self.address,
            self.dp.num_cus)

        # time deinterleaving
        self.time_v2s = blocks.vector_to_stream_make(
            gr.sizeof_float, self.dp.msc_cu_size * self.size)
        self.time_deinterleaver = grdab.time_deinterleave_ff_make(
            self.dp.msc_cu_size * self.size, self.dp.scrambling_vector)
        # unpuncture
        self.conv_v2s = blocks.vector_to_stream(
            gr.sizeof_float, self.msc_punctured_codeword_length)
        self.unpuncture = grdab.unpuncture_ff_make(
            self.assembled_msc_puncturing_sequence, 0)

        # convolutional decoding
        self.fsm = trellis.fsm(
            1, 4, [0o133, 0o171, 0o145, 0o133
                   ])  # OK (dumped to text and verified partially)
        table = [
            0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1,
            0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0,
            1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1
        ]
        assert (len(table) / 4 == self.fsm.O())
        table = [(1 - 2 * x) / sqrt(2) for x in table]
        self.conv_decode = trellis.viterbi_combined_fb(
            self.fsm, self.msc_I + self.dp.conv_code_add_bits_input, 0, 0, 4,
            table, trellis.TRELLIS_EUCLIDEAN)
        self.conv_s2v = blocks.stream_to_vector(
            gr.sizeof_char, self.msc_I + self.dp.conv_code_add_bits_input)
        self.conv_prune = grdab.prune(gr.sizeof_char,
                                      self.msc_conv_codeword_length / 4, 0,
                                      self.dp.conv_code_add_bits_input)

        #energy descramble
        self.prbs_src = blocks.vector_source_b(self.dp.prbs(int(self.msc_I)),
                                               True)
        self.energy_v2s = blocks.vector_to_stream(gr.sizeof_char, self.msc_I)
        self.add_mod_2 = blocks.xor_bb()
        #self.energy_s2v = blocks.stream_to_vector(gr.sizeof_char, self.msc_I)

        #pack bits
        self.pack_bits = blocks.unpacked_to_packed_bb_make(1, gr.GR_MSB_FIRST)

        # connect blocks
        self.connect(
            (self, 0),
            (self.select_msc_syms),
            #(self.repartition_msc_to_CIFs, 0),
            (self.repartition_msc_to_cus),
            (self.select_subch, 0),
            #(self.repartition_cus_to_logical_frame, 0),
            self.time_v2s,
            self.time_deinterleaver,
            #self.conv_v2s,
            self.unpuncture,
            self.conv_decode,
            #self.conv_s2v,
            self.conv_prune,
            #self.energy_v2s,
            self.add_mod_2,
            self.pack_bits,
            #self.energy_s2v, #better output stream or vector??
            (self))
        self.connect(self.prbs_src, (self.add_mod_2, 1))

        #debug
        if debug is True:
            #msc_select_syms
            self.sink_msc_select_syms = blocks.file_sink_make(
                gr.sizeof_float * self.dp.num_carriers * 2,
                "debug/msc_select_syms.dat")
            self.connect(self.select_msc_syms, self.sink_msc_select_syms)

            #msc repartition cus
            self.sink_repartition_msc_to_cus = blocks.file_sink_make(
                gr.sizeof_float * self.dp.msc_cu_size,
                "debug/msc_repartitioned_to_cus.dat")
            self.connect((self.repartition_msc_to_cus),
                         self.sink_repartition_msc_to_cus)

            #data of one sub channel not decoded
            self.sink_select_subch = blocks.file_sink_make(
                gr.sizeof_float * self.dp.msc_cu_size * self.size,
                "debug/select_subch.dat")
            self.connect(self.select_subch, self.sink_select_subch)

            #sub channel time_deinterleaved
            self.sink_subch_time_deinterleaved = blocks.file_sink_make(
                gr.sizeof_float, "debug/subch_time_deinterleaved.dat")
            self.connect(self.time_deinterleaver,
                         self.sink_subch_time_deinterleaved)

            #sub channel unpunctured
            self.sink_subch_unpunctured = blocks.file_sink_make(
                gr.sizeof_float, "debug/subch_unpunctured.dat")
            self.connect(self.unpuncture, self.sink_subch_unpunctured)

            # sub channel convolutional decoded
            self.sink_subch_decoded = blocks.file_sink_make(
                gr.sizeof_char, "debug/subch_decoded.dat")
            self.connect(self.conv_decode, self.sink_subch_decoded)

            # sub channel convolutional decoded
            self.sink_subch_pruned = blocks.file_sink_make(
                gr.sizeof_char, "debug/subch_pruned.dat")
            self.connect(self.conv_prune, self.sink_subch_pruned)

            # sub channel energy dispersal undone unpacked
            self.sink_subch_energy_disp_undone = blocks.file_sink_make(
                gr.sizeof_char, "debug/subch_energy_disp_undone_unpacked.dat")
            self.connect(self.add_mod_2, self.sink_subch_energy_disp_undone)

            # sub channel energy dispersal undone packed
            self.sink_subch_energy_disp_undone_packed = blocks.file_sink_make(
                gr.sizeof_char, "debug/subch_energy_disp_undone_packed.dat")
            self.connect(self.pack_bits,
                         self.sink_subch_energy_disp_undone_packed)
Beispiel #16
0
 def test_xor_bb(self):
     src1_data = (1, 2, 3, 4, 0x50)
     src2_data = (8, 2, 1, 8, 0x05)
     expected_result = (9, 0, 2, 0xC, 0x55)
     op = blocks.xor_bb()
     self.help_bb((src1_data, src2_data), expected_result, op)
	def sim ( self, arity, snr_db, N ):
		M = 1024
		theta_sel = 0
		syms_per_frame = 20
		zero_pads = 1
		# center_preamble = [1, -1j, -1, 1j] # assumed to be normalized to 1
		qam_size = 2**arity
		# preamble = [0]*M*zero_pads+center_preamble*((int)(M/len(center_preamble)))+[0]*M*zero_pads
		# print preamble
		# num_symbols = 2**12
		exclude_preamble = 1
		exclude_multipath = 1
		sel_taps = 2 # epa=0, eva = 1, etu=2
		freq_offset= 0
		exclude_noise = 0
		sel_noise_type =0 # gaussian
		eq_select = 0 # 0=1-tap 1=3-taps w/linear intrp 2=3-taps w/ geo. intrp. 3= no eq.
		carriers = M
		sel_preamble = 0 # 0: IAM-C 1: IAM-C with 3 rep. 2: IAM-R
		extra_pad=False
		# SNR = 20
		K = 4
		N = int( N ) # num of !samples!
		num_bits = N*arity
		normalizing_factor = float(1)/(M*.6863)#*.6863)
		# print normalizing_factor
		# amp = math.sqrt(M/(10**(float(snr_db)/10)))/math.sqrt(2)
		# amp = math.sqrt((10**(float(-1*snr_db)/20))*(2*K*M+(2*syms_per_frame-1)*M)/(4*syms_per_frame))/math.sqrt(2)
		if exclude_preamble:
			amp = normalizing_factor*math.sqrt((10**(float(-1*snr_db)/10))*(2*K*M+(2*syms_per_frame-1)*M)/(4*syms_per_frame))/math.sqrt(2)
			# amp = normalizing_factor*math.sqrt((10**(float(-1*snr_db)/10))*(2*K*M+(2*syms_per_frame-1)*M)/(4*syms_per_frame))/math.sqrt(2)
		else:
			amp = normalizing_factor*math.sqrt((10**(float(-1*snr_db)/10))*(M*(syms_per_frame+1)/(syms_per_frame+1+2*zero_pads))*((K*M+(2*syms_per_frame-1)*M/2)/(M*syms_per_frame)))/math.sqrt(2)
		# print amp
		# print amp2
		taps = (1)
		if sel_taps == 0: #epa
				taps = (0.998160541385960,0.0605566335500750,0.00290305927764350)
		elif sel_taps == 1: #eva
				taps = (0.748212004186014,0.317358833370450,0.572776845645705,0,0.0538952624324030,0.0874078808126807,0,0,0,0.0276407988816600,0,0,0,0.00894438719057275)
		elif sel_taps ==2: #etu
				taps = (0.463990169152204,0.816124099344485,0,0.292064507384192,0,0,0,0,0.146379002496595,0,0,0,0.0923589067029112,0,0,0,0,0,0,0,0,0,0,0,0,0.0582745305123628)
		tx = ofdm.fbmc_transmitter_hier_bc(M, K, qam_size, syms_per_frame, carriers, theta_sel, exclude_preamble, sel_preamble,zero_pads,extra_pad)
		rx = ofdm.fbmc_receiver_hier_cb(M, K, qam_size, syms_per_frame, carriers, theta_sel, eq_select, exclude_preamble, sel_preamble, zero_pads,extra_pad)
				# def __init__(self, M=1024, K=4, qam_size=16, syms_per_frame=10, carriers=924, theta_sel=0, sel_eq=0, exclude_preamble=0, sel_preamble=0, zero_pads=1, extra_pad=False):

		# ch = ofdm.fbmc_channel_hier_cc(M, K, syms_per_frame, exclude_multipath, sel_taps, freq_offset, exclude_noise, sel_noise_type, snr_db, exclude_preamble, zero_pads)

		# src = blocks.vector_source_b(src_data, vlen=1)
		xor_block = blocks.xor_bb()
		head1 = blocks.head(gr.sizeof_char*1, N)
		head0 = blocks.head(gr.sizeof_char*1, N)
		add_block = blocks.add_vcc(1)
		src = blocks.vector_source_b(map(int, numpy.random.randint(0, qam_size, 100000)), True)
		noise = analog.fastnoise_source_c(analog.GR_GAUSSIAN, amp, 0, 8192)
		dst = blocks.vector_sink_b(vlen=1)
		# ch_model = channels.channel_model(
		# 				noise_voltage=0.0,
		# 				frequency_offset=freq_offset,
		# 				epsilon=1.0,
		# 				taps=taps,
		# 				noise_seed=0,
		# 				block_tags=False
		# 		)

		tb = gr.top_block ( "test_block" )
		tb.connect((src, 0), (head1, 0)) #esas
		tb.connect((head1, 0), (xor_block, 0)) #esas
		tb.connect((src, 0), (tx, 0)) #esas
		# tb.connect((tx, 0), (add_block, 0)) #esas
		if exclude_multipath:
			tb.connect((tx, 0), (add_block, 0)) #esas
		else:
			tb.connect((tx, 0), (ch_model, 0))
			tb.connect((ch_model, 0), (add_block, 0)) 
		tb.connect((noise, 0), (add_block, 1)) #esas
		tb.connect((add_block, 0), (rx, 0)) #esas
		tb.connect((rx, 0),(head0, 0)) #esas
		tb.connect((head0, 0), (xor_block, 1)) #esas
		tb.connect((xor_block, 0), (dst, 0)) #esas  

		tb.run()

		# what we record in dst.data will be output of xor_block. now we have to process those data
		# so as to find bit errors.
		result_data = dst.data()

		bit_errors = 0
		for i in range(len(result_data)):
			# print bin(result_data[i])
			bit_errors = bit_errors + (bin(result_data[i]).count('1'))

		# print len(result_data)

		# return 1

		return float(bit_errors) / num_bits
Beispiel #18
0
    def __init__(self):
        gr.top_block.__init__(self, "And or xor")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("And or xor")
        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", "logicalsignal")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_time_sink_x_0_0_0 = qtgui.time_sink_f(
            128,  #size
            samp_rate,  #samp_rate
            "",  #name
            2  #number of inputs
        )
        self.qtgui_time_sink_x_0_0_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0_0_0.set_y_axis(-1, 1)

        self.qtgui_time_sink_x_0_0_0.set_y_label('XOR', "")

        self.qtgui_time_sink_x_0_0_0.enable_tags(True)
        self.qtgui_time_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                      qtgui.TRIG_SLOPE_POS,
                                                      0.0, 0, 0, "")
        self.qtgui_time_sink_x_0_0_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0_0_0.enable_grid(False)
        self.qtgui_time_sink_x_0_0_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0_0_0.enable_control_panel(False)
        self.qtgui_time_sink_x_0_0_0.enable_stem_plot(False)

        labels = [
            'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow',
            'dark red', 'dark green', 'dark blue'
        ]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

        for i in range(2):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0_0_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0_0_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0_0_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0_0_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0_0_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0_0_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0_0_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_0_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0_0_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_0_win)
        self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f(
            128,  #size
            samp_rate,  #samp_rate
            "",  #name
            2  #number of inputs
        )
        self.qtgui_time_sink_x_0_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1)

        self.qtgui_time_sink_x_0_0.set_y_label('OR', "")

        self.qtgui_time_sink_x_0_0.enable_tags(True)
        self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                    qtgui.TRIG_SLOPE_POS, 0.0,
                                                    0, 0, "")
        self.qtgui_time_sink_x_0_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0_0.enable_grid(False)
        self.qtgui_time_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0_0.enable_control_panel(False)
        self.qtgui_time_sink_x_0_0.enable_stem_plot(False)

        labels = [
            'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow',
            'dark red', 'dark green', 'dark blue'
        ]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

        for i in range(2):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            128,  #size
            samp_rate,  #samp_rate
            "",  #name
            2  #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)

        self.qtgui_time_sink_x_0.set_y_label('AND', "")

        self.qtgui_time_sink_x_0.enable_tags(True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                  qtgui.TRIG_SLOPE_POS, 0.0, 0,
                                                  0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        self.qtgui_time_sink_x_0.enable_stem_plot(False)

        labels = [
            'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5',
            'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow',
            'dark red', 'dark green', 'dark blue'
        ]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

        for i in range(2):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.blocks_xor_xx_0_0 = blocks.xor_bb()
        self.blocks_xor_xx_0 = blocks.xor_bb()
        self.blocks_uchar_to_float_0_0_0_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0_0_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0_0 = blocks.uchar_to_float()
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate,
                                                 True)
        self.blocks_or_xx_0 = blocks.or_bb()
        self.blocks_null_source_0 = blocks.null_source(gr.sizeof_char * 1)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char * 1)
        self.blocks_and_xx_0 = blocks.and_bb()
        self.analog_sig_source_x_1 = analog.sig_source_b(
            samp_rate, analog.GR_SQR_WAVE, 4000, 1, 0, 0)
        self.analog_sig_source_x_0 = analog.sig_source_b(
            samp_rate, analog.GR_SQR_WAVE, 1000, 1, 0, 0)
        self.analog_const_source_x_0 = analog.sig_source_b(
            0, analog.GR_CONST_WAVE, 0, 0, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0, 0),
                     (self.blocks_xor_xx_0, 1))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_and_xx_0, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_or_xx_0, 0))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_uchar_to_float_0, 0))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_xor_xx_0_0, 0))
        self.connect((self.analog_sig_source_x_1, 0),
                     (self.blocks_xor_xx_0, 0))
        self.connect((self.blocks_and_xx_0, 0),
                     (self.blocks_uchar_to_float_0_0_0_0, 0))
        self.connect((self.blocks_null_source_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_or_xx_0, 0),
                     (self.blocks_uchar_to_float_0_0_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_null_sink_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.qtgui_time_sink_x_0_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.qtgui_time_sink_x_0_0_0, 0))
        self.connect((self.blocks_uchar_to_float_0_0, 0),
                     (self.qtgui_time_sink_x_0_0_0, 1))
        self.connect((self.blocks_uchar_to_float_0_0_0, 0),
                     (self.qtgui_time_sink_x_0_0, 1))
        self.connect((self.blocks_uchar_to_float_0_0_0_0, 0),
                     (self.qtgui_time_sink_x_0, 1))
        self.connect((self.blocks_xor_xx_0, 0), (self.blocks_and_xx_0, 1))
        self.connect((self.blocks_xor_xx_0, 0), (self.blocks_or_xx_0, 1))
        self.connect((self.blocks_xor_xx_0, 0), (self.blocks_xor_xx_0_0, 1))
        self.connect((self.blocks_xor_xx_0_0, 0),
                     (self.blocks_uchar_to_float_0_0, 0))
Beispiel #19
0
    def __init__(self, dab_params, data_rate_n, protection):
        gr.hier_block2.__init__(self,
            "msc_encode",
            gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
        self.dp = dab_params
        self.n = data_rate_n
        self.msc_I = self.n * 192
        self.protect = protection

        # unpack
        self.unpack = blocks.packed_to_unpacked_bb_make(1, gr.GR_MSB_FIRST)

        # energy dispersal
        self.prbs_src = blocks.vector_source_b(self.dp.prbs(self.msc_I), True)
        self.add_mod_2 = blocks.xor_bb()

        # convolutional encoder
        self.conv_pack = blocks.unpacked_to_packed_bb_make(1, gr.GR_MSB_FIRST)
        self.conv_encoder = dab.conv_encoder_bb_make(self.msc_I / 8)
        self.conv_unpack = blocks.packed_to_unpacked_bb_make(1, gr.GR_MSB_FIRST)


        # calculate puncturing factors (EEP, table 33, 34)
        if (self.n > 1 or self.protect != 1):
            self.puncturing_L1 = [6 * self.n - 3, 2 * self.n - 3, 6 * self.n - 3, 4 * self.n - 3]
            self.puncturing_L2 = [3, 4 * self.n + 3, 3, 2 * self.n + 3]
            self.puncturing_PI1 = [24, 14, 8, 3]
            self.puncturing_PI2 = [23, 13, 7, 2]
            # calculate length of punctured codeword (11.3.2)
            self.msc_punctured_codeword_length = self.puncturing_L1[self.protect] * 4 * self.dp.puncturing_vectors_ones[
                self.puncturing_PI1[self.protect]] + self.puncturing_L2[self.protect] * 4 * \
                                                     self.dp.puncturing_vectors_ones[
                                                         self.puncturing_PI2[self.protect]] + 12
            self.assembled_msc_puncturing_sequence = self.puncturing_L1[self.protect] * 4 * self.dp.puncturing_vectors[
                self.puncturing_PI1[self.protect]] + self.puncturing_L2[self.protect] * 4 * self.dp.puncturing_vectors[
                self.puncturing_PI2[self.protect]] + self.dp.puncturing_tail_vector
            self.msc_conv_codeword_length = 4 * self.msc_I + 24  # 4*I + 24 ()
        # exception in table
        else:
            self.msc_punctured_codeword_length = 5 * 4 * self.dp.puncturing_vectors_ones[13] + 1 * 4 * \
                                                                                               self.dp.puncturing_vectors_ones[
                                                                                                   12] + 12
        # sanity check
        assert (6 * self.n == self.puncturing_L1[self.protect] + self.puncturing_L2[self.protect])

        # puncturing
        self.puncture = dab.puncture_bb_make(self.assembled_msc_puncturing_sequence)

        # time interleaving
        self.s2v_time_interleave = blocks.stream_to_vector_make(gr.sizeof_char, self.msc_punctured_codeword_length)
        self.time_interleaver = dab.time_interleave_bb_make(self.msc_punctured_codeword_length, self.dp.scrambling_vector)
        self.v2s_time_interleave = blocks.vector_to_stream_make(gr.sizeof_char, self.msc_punctured_codeword_length)

        # pack bits
        self.unpacked_to_packed_encoded = blocks.unpacked_to_packed_bb_make(1, gr.GR_MSB_FIRST)

        # connect everything
        self.connect(self,
                     self.unpack,
                     self.add_mod_2,
                     self.conv_pack,
                     self.conv_encoder,
                     self.conv_unpack,
                     self.puncture,
                     self.s2v_time_interleave,
                     self.time_interleaver,
                     self.v2s_time_interleave,
                     self.unpacked_to_packed_encoded,
                     self)
        # connect prbs
        self.connect(self.prbs_src, (self.add_mod_2, 1))
Beispiel #20
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.thresh = thresh = 900*10**-3
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        _thresh_sizer = wx.BoxSizer(wx.VERTICAL)
        self._thresh_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_thresh_sizer,
        	value=self.thresh,
        	callback=self.set_thresh,
        	label='thresh',
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._thresh_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_thresh_sizer,
        	value=self.thresh,
        	callback=self.set_thresh,
        	minimum=0,
        	maximum=1,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_thresh_sizer)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
        	self.GetWin(),
        	title="Scope Plot",
        	sample_rate=samp_rate,
        	v_scale=200*10**-3,
        	v_offset=0,
        	t_scale=100*10**-3,
        	ac_couple=False,
        	xy_mode=False,
        	num_inputs=2,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.win)
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
        	self.GetWin(),
        	unit="Units",
        	minval=0,
        	maxval=1,
        	factor=1.0,
        	decimal_places=6,
        	ref_level=0,
        	sample_rate=samp_rate,
        	number_rate=15,
        	average=False,
        	avg_alpha=None,
        	label="Number Plot",
        	peak_hold=False,
        	show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)
        self.digital_glfsr_source_x_0 = digital.glfsr_source_b(6, True, 0, 1)
        self.blocks_xor_xx_0 = blocks.xor_bb()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate,True)
        self.blocks_threshold_ff_0 = blocks.threshold_ff(thresh, thresh, 0)
        self.blocks_float_to_char_0 = blocks.float_to_char(1, 1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((0.5, ))
        self.blks2_error_rate_0 = grc_blks2.error_rate(
        	type='BER',
        	win_size=1280,
        	bits_per_symbol=1,
        )
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_UNIFORM, 0.5, 32)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_const_vxx_0, 0))    
        self.connect((self.blks2_error_rate_0, 0), (self.wxgui_numbersink2_0, 0))    
        self.connect((self.blks2_error_rate_0, 0), (self.wxgui_scopesink2_0, 0))    
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_threshold_ff_0, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.blocks_xor_xx_0, 1))    
        self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_threshold_ff_0, 0), (self.wxgui_scopesink2_0, 1))    
        self.connect((self.blocks_throttle_0, 0), (self.blks2_error_rate_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_xor_xx_0, 0))    
        self.connect((self.blocks_xor_xx_0, 0), (self.blks2_error_rate_0, 1))    
        self.connect((self.digital_glfsr_source_x_0, 0), (self.blocks_throttle_0, 0))    
Beispiel #21
0
    def sim(self, arity, snr_db, N):
        M = 1024
        theta_sel = 0
        syms_per_frame = 20
        zero_pads = 1
        # center_preamble = [1, -1j, -1, 1j] # assumed to be normalized to 1
        qam_size = 2**arity
        # preamble = [0]*M*zero_pads+center_preamble*((int)(M/len(center_preamble)))+[0]*M*zero_pads
        # print preamble
        # num_symbols = 2**12
        exclude_preamble = 1
        exclude_multipath = 1
        sel_taps = 2  # epa=0, eva = 1, etu=2
        freq_offset = 0
        exclude_noise = 0
        sel_noise_type = 0  # gaussian
        eq_select = 0  # 0=1-tap 1=3-taps w/linear intrp 2=3-taps w/ geo. intrp. 3= no eq.
        carriers = M
        sel_preamble = 0  # 0: IAM-C 1: IAM-C with 3 rep. 2: IAM-R
        extra_pad = False
        # SNR = 20
        K = 4
        N = int(N)  # num of !samples!
        num_bits = N * arity
        normalizing_factor = float(1) / (M * .6863)  #*.6863)
        # print normalizing_factor
        # amp = math.sqrt(M/(10**(float(snr_db)/10)))/math.sqrt(2)
        # amp = math.sqrt((10**(float(-1*snr_db)/20))*(2*K*M+(2*syms_per_frame-1)*M)/(4*syms_per_frame))/math.sqrt(2)
        if exclude_preamble:
            amp = normalizing_factor * math.sqrt(
                (10**(float(-1 * snr_db) / 10)) *
                (2 * K * M + (2 * syms_per_frame - 1) * M) /
                (4 * syms_per_frame)) / math.sqrt(2)
            # amp = normalizing_factor*math.sqrt((10**(float(-1*snr_db)/10))*(2*K*M+(2*syms_per_frame-1)*M)/(4*syms_per_frame))/math.sqrt(2)
        else:
            amp = normalizing_factor * math.sqrt(
                (10**(float(-1 * snr_db) / 10)) *
                (M * (syms_per_frame + 1) /
                 (syms_per_frame + 1 + 2 * zero_pads)) *
                ((K * M + (2 * syms_per_frame - 1) * M / 2) /
                 (M * syms_per_frame))) / math.sqrt(2)
        # print amp
        # print amp2
        taps = (1)
        if sel_taps == 0:  #epa
            taps = (0.998160541385960, 0.0605566335500750, 0.00290305927764350)
        elif sel_taps == 1:  #eva
            taps = (0.748212004186014, 0.317358833370450, 0.572776845645705, 0,
                    0.0538952624324030, 0.0874078808126807, 0, 0, 0,
                    0.0276407988816600, 0, 0, 0, 0.00894438719057275)
        elif sel_taps == 2:  #etu
            taps = (0.463990169152204, 0.816124099344485, 0, 0.292064507384192,
                    0, 0, 0, 0, 0.146379002496595, 0, 0, 0, 0.0923589067029112,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0582745305123628)
        tx = ofdm.fbmc_transmitter_hier_bc(M, K, qam_size, syms_per_frame,
                                           carriers, theta_sel,
                                           exclude_preamble, sel_preamble,
                                           zero_pads, extra_pad)
        rx = ofdm.fbmc_receiver_hier_cb(M, K, qam_size, syms_per_frame,
                                        carriers, theta_sel, eq_select,
                                        exclude_preamble, sel_preamble,
                                        zero_pads, extra_pad)
        # def __init__(self, M=1024, K=4, qam_size=16, syms_per_frame=10, carriers=924, theta_sel=0, sel_eq=0, exclude_preamble=0, sel_preamble=0, zero_pads=1, extra_pad=False):

        # ch = ofdm.fbmc_channel_hier_cc(M, K, syms_per_frame, exclude_multipath, sel_taps, freq_offset, exclude_noise, sel_noise_type, snr_db, exclude_preamble, zero_pads)

        # src = blocks.vector_source_b(src_data, vlen=1)
        xor_block = blocks.xor_bb()
        head1 = blocks.head(gr.sizeof_char * 1, N)
        head0 = blocks.head(gr.sizeof_char * 1, N)
        add_block = blocks.add_vcc(1)
        src = blocks.vector_source_b(
            map(int, numpy.random.randint(0, qam_size, 100000)), True)
        noise = analog.fastnoise_source_c(analog.GR_GAUSSIAN, amp, 0, 8192)
        dst = blocks.vector_sink_b(vlen=1)
        # ch_model = channels.channel_model(
        # 				noise_voltage=0.0,
        # 				frequency_offset=freq_offset,
        # 				epsilon=1.0,
        # 				taps=taps,
        # 				noise_seed=0,
        # 				block_tags=False
        # 		)

        tb = gr.top_block("test_block")
        tb.connect((src, 0), (head1, 0))  #esas
        tb.connect((head1, 0), (xor_block, 0))  #esas
        tb.connect((src, 0), (tx, 0))  #esas
        # tb.connect((tx, 0), (add_block, 0)) #esas
        if exclude_multipath:
            tb.connect((tx, 0), (add_block, 0))  #esas
        else:
            tb.connect((tx, 0), (ch_model, 0))
            tb.connect((ch_model, 0), (add_block, 0))
        tb.connect((noise, 0), (add_block, 1))  #esas
        tb.connect((add_block, 0), (rx, 0))  #esas
        tb.connect((rx, 0), (head0, 0))  #esas
        tb.connect((head0, 0), (xor_block, 1))  #esas
        tb.connect((xor_block, 0), (dst, 0))  #esas

        tb.run()

        # what we record in dst.data will be output of xor_block. now we have to process those data
        # so as to find bit errors.
        result_data = dst.data()

        bit_errors = 0
        for i in range(len(result_data)):
            # print bin(result_data[i])
            bit_errors = bit_errors + (bin(result_data[i]).count('1'))

        # print len(result_data)

        # return 1

        return float(bit_errors) / num_bits
Beispiel #22
0
    def __init__(self):
        gr.top_block.__init__(self, "Dsss")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Dsss")
        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", "dsss")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.spread_factor = spread_factor = 8
        self.spc = spc = 4

        self.const = const = digital.constellation_qpsk().base()

        self.sps = sps = spc * spread_factor
        self.samp_rate = samp_rate = 100e3
        self.point = point = const.points()

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            2048,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "",  #name
            1  #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0,
                                                  "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(False)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)

        if not True:
            self.qtgui_freq_sink_x_0.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
            self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "dark blue"
        ]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(
            self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self.digital_psk_mod_0 = digital.psk.psk_mod(
            constellation_points=4,
            mod_code="gray",
            differential=True,
            samples_per_symbol=sps,
            excess_bw=0.35,
            verbose=False,
            log=False,
        )
        self.digital_glfsr_source_x_0 = digital.glfsr_source_b(16, True, 0, 1)
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=0.0001,
            frequency_offset=0.0,
            epsilon=1.0,
            taps=(1.0, ),
            noise_seed=0,
            block_tags=False)
        self.blocks_xor_xx_0 = blocks.xor_bb()
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)
        self.analog_random_source_x_0 = blocks.vector_source_b(
            map(int, numpy.random.randint(0, 256, 10000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_random_source_x_0, 0),
                     (self.blocks_xor_xx_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.blocks_xor_xx_0, 0), (self.digital_psk_mod_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.digital_glfsr_source_x_0, 0),
                     (self.blocks_xor_xx_0, 1))
        self.connect((self.digital_psk_mod_0, 0),
                     (self.channels_channel_model_0, 0))
Beispiel #23
0
    def __init__(self, dab_params, verbose=False, debug=False):
        """
        Hierarchical block for FIC decoding

        @param dab_params DAB parameter object (grdab.parameters.dab_parameters)
        """
        gr.hier_block2.__init__(self, "fic",
                                gr.io_signature(1, 1, gr.sizeof_float * dab_params.num_carriers * 2),
                                gr.io_signature(1, 1, gr.sizeof_char * 32))

        self.dp = dab_params
        self.verbose = verbose
        self.debug = debug

        # FIB selection and block partitioning
        self.select_fic_syms = grdab.select_vectors(gr.sizeof_float, self.dp.num_carriers * 2, self.dp.num_fic_syms, 0)
        self.repartition_fic = grdab.repartition_vectors(gr.sizeof_float, self.dp.num_carriers * 2,
                                                       self.dp.fic_punctured_codeword_length, self.dp.num_fic_syms,
                                                       self.dp.num_cifs)

        # unpuncturing
        self.unpuncture = grdab.unpuncture_vff(self.dp.assembled_fic_puncturing_sequence, 0)

        # convolutional coding
        # self.fsm = trellis.fsm(self.dp.conv_code_in_bits, self.dp.conv_code_out_bits, self.dp.conv_code_generator_polynomials)
        self.fsm = trellis.fsm(1, 4, [0133, 0171, 0145, 0133])  # OK (dumped to text and verified partially)
        self.conv_v2s = blocks.vector_to_stream(gr.sizeof_float, self.dp.fic_conv_codeword_length)
        # self.conv_decode = trellis.viterbi_combined_fb(self.fsm, 20, 0, 0, 1, [1./sqrt(2),-1/sqrt(2)] , trellis.TRELLIS_EUCLIDEAN)
        table = [
            0, 0, 0, 0,
            0, 0, 0, 1,
            0, 0, 1, 0,
            0, 0, 1, 1,
            0, 1, 0, 0,
            0, 1, 0, 1,
            0, 1, 1, 0,
            0, 1, 1, 1,
            1, 0, 0, 0,
            1, 0, 0, 1,
            1, 0, 1, 0,
            1, 0, 1, 1,
            1, 1, 0, 0,
            1, 1, 0, 1,
            1, 1, 1, 0,
            1, 1, 1, 1
        ]
        assert (len(table) / 4 == self.fsm.O())
        table = [(1 - 2 * x) / sqrt(2) for x in table]
        self.conv_decode = trellis.viterbi_combined_fb(self.fsm, 774, 0, 0, 4, table, trellis.TRELLIS_EUCLIDEAN)
        #self.conv_s2v = blocks.stream_to_vector(gr.sizeof_char, 774)
        self.conv_prune = grdab.prune(gr.sizeof_char, self.dp.fic_conv_codeword_length / 4, 0,
                                            self.dp.conv_code_add_bits_input)

        # energy dispersal
        self.prbs_src = blocks.vector_source_b(self.dp.prbs(self.dp.energy_dispersal_fic_vector_length), True)
        #self.energy_v2s = blocks.vector_to_stream(gr.sizeof_char, self.dp.energy_dispersal_fic_vector_length)
        self.add_mod_2 = blocks.xor_bb()
        self.energy_s2v = blocks.stream_to_vector(gr.sizeof_char, self.dp.energy_dispersal_fic_vector_length)
        self.cut_into_fibs = grdab.repartition_vectors(gr.sizeof_char, self.dp.energy_dispersal_fic_vector_length,
                                                     self.dp.fib_bits, 1, self.dp.energy_dispersal_fic_fibs_per_vector)

        # connect all
        self.nullsink = blocks.null_sink(gr.sizeof_char)
        self.pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        self.fibout = blocks.stream_to_vector(1, 32)
        # self.filesink = gr.file_sink(gr.sizeof_char, "debug/fic.dat")
        self.fibsink = grdab.fib_sink_vb()

        # self.connect((self,0), (self.select_fic_syms,0), (self.repartition_fic,0), self.unpuncture, self.conv_v2s, self.conv_decode, self.conv_s2v, self.conv_prune, self.energy_v2s, self.add_mod_2, self.energy_s2v, (self.cut_into_fibs,0), gr.vector_to_stream(1,256), gr.unpacked_to_packed_bb(1,gr.GR_MSB_FIRST), self.filesink)
        self.connect((self, 0),
                     (self.select_fic_syms, 0),
                     (self.repartition_fic, 0),
                     self.unpuncture,
                     self.conv_v2s,
                     self.conv_decode,
                     #self.conv_s2v,
                     self.conv_prune,
                     #self.energy_v2s,
                     self.add_mod_2,
                     self.energy_s2v,
                     (self.cut_into_fibs, 0),
                     blocks.vector_to_stream(1, 256),
                     self.pack,
                     self.fibout,
                     self.fibsink)
        self.connect(self.fibout, self)
        self.connect(self.prbs_src, (self.add_mod_2, 1))

        if self.debug:
            self.connect((self, 0), blocks.file_sink(gr.sizeof_float * self.dp.num_carriers * 2, "debug/transmission_frame.dat"))
            self.connect((self, 1), blocks.file_sink(gr.sizeof_char, "debug/transmission_frame_trigger.dat"))
            self.connect(self.select_fic_syms, blocks.file_sink(gr.sizeof_float * self.dp.num_carriers * 2, "debug/fic_select_syms.dat"))
            self.connect(self.repartition_fic, blocks.file_sink(gr.sizeof_float * self.dp.fic_punctured_codeword_length, "debug/fic_repartitioned.dat"))
            self.connect(self.unpuncture, blocks.file_sink(gr.sizeof_float * self.dp.fic_conv_codeword_length, "debug/fic_unpunctured.dat"))
            self.connect(self.conv_decode, blocks.file_sink(gr.sizeof_char, "debug/fic_decoded.dat"))
            self.connect(self.conv_prune, blocks.file_sink(gr.sizeof_char, "debug/fic_decoded_pruned.dat"))
            #self.connect(self.conv_decode, blocks.file_sink(gr.sizeof_char * self.dp.energy_dispersal_fic_vector_length, "debug/fic_energy_dispersal_undone.dat"))
            self.connect(self.pack, blocks.file_sink(gr.sizeof_char, "debug/fic_energy_undone.dat"))
    def sim(self, arity, snr_db, N):
        M = 1024
        theta_sel = 0
        syms_per_frame = 10
        zero_pads = 1
        center_preamble = [1, -1j, -1, 1j]  # assumed to be normalized to 1
        qam_size = 2**arity
        preamble = [0] * M * zero_pads + center_preamble * (
            (int)(M / len(center_preamble))) + [0] * M * zero_pads
        # num_symbols = 2**12
        exclude_preamble = 0
        exclude_multipath = 0
        sel_taps = 0  # epa=0, eva = 1, etu=3
        freq_offset = 0
        exclude_noise = 0
        sel_noise_type = 0  # gaussian
        eq_select = 3
        start = 10
        end = 29
        # SNR = 20
        K = 4
        N = int(N)  # num of !samples!
        num_bits = N * arity

        # if sel_preamble == 0: # standard one vector center preamble [1,-j,-1,j]
        #     self.center_preamble = center_preamble = [1, -1j, -1, 1j]*((int)(M/4))
        # elif sel_preamble == 1: # standard preamble with triple repetition
        #     self.center_preamble = center_preamble = [1, -1j, -1, 1j]*((int)(M/4))*3 #[1/math.sqrt(3), -1j/math.sqrt(3), -1/math.sqrt(3), 1j/math.sqrt(3)]*((int)(M/4))*3
        # elif sel_preamble ==2: # IAM-R preamble [1, -1,-1, 1]
        #     self.center_preamble = center_preamble = [1, -1, -1, 1]*((int)(M/4))
        # else: # standard one vector center preamble [1,-j,-1,j]
        #     self.center_preamble = center_preamble = [1, -1j, -1, 1j]*((int)(M/4))
        sel_preamble = 0
        zero_pads = 1
        extra_pad = False

        if exclude_preamble:
            amp = math.sqrt((10**(float(-1 * snr_db) / 10)) *
                            (2 * K * M + (2 * syms_per_frame - 1) * M) /
                            (4 * syms_per_frame)) / math.sqrt(2)
        else:
            amp = math.sqrt((10**(float(-1 * snr_db) / 10)) *
                            (M * (syms_per_frame + 1) /
                             (syms_per_frame + 1 + 2 * zero_pads)) *
                            ((K * M + (2 * syms_per_frame - 1) * M / 2) /
                             (M * syms_per_frame))) / math.sqrt(2)
        # print amp
        # print amp2
        tx = fbmc_transmitter_multiuser_bc(M, K, qam_size, syms_per_frame,
                                           start, end, theta_sel,
                                           exclude_preamble, sel_preamble,
                                           zero_pads, extra_pad)
        rx = fbmc_receiver_hier_cb(M,
                                   K,
                                   qam_size,
                                   syms_per_frame,
                                   carriers=924,
                                   theta_sel=0,
                                   sel_eq=0,
                                   exclude_preamble=0,
                                   sel_preamble=0,
                                   zero_pads=1,
                                   extra_pad=False)
        ch = channel_hier_cc(M, K, syms_per_frame, exclude_multipath, sel_taps,
                             freq_offset, exclude_noise, sel_noise_type,
                             snr_db, exclude_preamble, zero_pads)

        # # src = blocks.vector_source_b(src_data, vlen=1)
        xor_block = blocks.xor_bb()
        head1 = blocks.head(gr.sizeof_char * 1, N)
        head0 = blocks.head(gr.sizeof_char * 1, N)
        add_block = blocks.add_vcc(1)
        src = blocks.vector_source_b(
            map(int, numpy.random.randint(0, qam_size, 100000)), True)
        noise = analog.fastnoise_source_c(analog.GR_GAUSSIAN, amp, 0, 8192)
        dst = blocks.vector_sink_b(vlen=1)

        tb = gr.top_block("test_block")
        tb.connect((src, 0), (head1, 0))  #esas
        tb.connect((head1, 0), (xor_block, 0))  #esas
        tb.connect((src, 0), (tx, 0))  #esas
        tb.connect((tx, 0), (add_block, 0))  #esas
        tb.connect((noise, 0), (add_block, 1))  #esas
        # tb.connect((head0, 0), (add_block, 1)) #esas
        tb.connect((add_block, 0), (rx, 0))  #esas
        tb.connect((rx, 0), (head0, 0))  #esas
        tb.connect((head0, 0), (xor_block, 1))  #esas
        tb.connect((xor_block, 0), (dst, 0))  #esas

        tb.run()

        # what we record in dst.data will be output of xor_block. now we have to process those data
        # so as to find bit errors.
        result_data = dst.data()

        bit_errors = 0
        for i in range(len(result_data)):
            # print bin(result_data[i])
            bit_errors = bit_errors + (bin(result_data[i]).count('1'))

        # print len(result_data)

        # return 1

        return float(bit_errors) / num_bits
Beispiel #25
0
    def __init__(self, dab_params, address, size, protection, verbose=False, debug=False):
        gr.hier_block2.__init__(self,
                                "msc_decode",
                                # Input signature
                                gr.io_signature(1, 1, gr.sizeof_float * dab_params.num_carriers * 2),
                                # Output signature
                                gr.io_signature(1, 1, gr.sizeof_char))
        self.dp = dab_params
        self.address = address
        self.size = size
        self.protect = protection
        self.verbose = verbose
        self.debug = debug

        # calculate n factor (multiple of 8kbits etc.)
        self.n = self.size / self.dp.subch_size_multiple_n[self.protect]

        # calculate puncturing factors (EEP, table 33, 34)
        self.msc_I = self.n * 192
        if (self.n > 1 or self.protect != 1):
            self.puncturing_L1 = [6 * self.n - 3, 2 * self.n - 3, 6 * self.n - 3, 4 * self.n - 3]
            self.puncturing_L2 = [3, 4 * self.n + 3, 3, 2 * self.n + 3]
            self.puncturing_PI1 = [24, 14, 8, 3]
            self.puncturing_PI2 = [23, 13, 7, 2]
            # calculate length of punctured codeword (11.3.2)
            self.msc_punctured_codeword_length = self.puncturing_L1[self.protect] * 4 * self.dp.puncturing_vectors_ones[
                self.puncturing_PI1[self.protect]] + self.puncturing_L2[self.protect] * 4 * \
                                                     self.dp.puncturing_vectors_ones[
                                                         self.puncturing_PI2[self.protect]] + 12
            self.assembled_msc_puncturing_sequence = self.puncturing_L1[self.protect] * 4 * self.dp.puncturing_vectors[
                self.puncturing_PI1[self.protect]] + self.puncturing_L2[self.protect] * 4 * self.dp.puncturing_vectors[
                self.puncturing_PI2[self.protect]] + self.dp.puncturing_tail_vector
            self.msc_conv_codeword_length = 4*self.msc_I + 24 # 4*I + 24 ()
        # exception in table
        else:
            self.msc_punctured_codeword_length = 5 * 4 * self.dp.puncturing_vectors_ones[13] + 1 * 4 * \
                                                                                               self.dp.puncturing_vectors_ones[
                                                                                                   12] + 12
        #sanity check
        assert(6*self.n == self.puncturing_L1[self.protect] + self.puncturing_L2[self.protect])


        # MSC selection and block partitioning
        # select OFDM carriers with MSC
        self.select_msc_syms = grdab.select_vectors(gr.sizeof_float, self.dp.num_carriers * 2, self.dp.num_msc_syms,
                                                  self.dp.num_fic_syms)
        # repartition MSC data in CIFs (left out due to heavy burden for scheduler and not really necessary)
        #self.repartition_msc_to_CIFs = grdab.repartition_vectors_make(gr.sizeof_float, self.dp.num_carriers * 2,
        #                                                            self.dp.cif_bits, self.dp.num_msc_syms,
        #                                                            self.dp.num_cifs)
        #repartition MSC to CUs
        self.repartition_msc_to_cus = grdab.repartition_vectors_make(gr.sizeof_float, self.dp.num_carriers*2, self.dp.msc_cu_size, self.dp.num_msc_syms, self.dp.num_cus * self.dp.num_cifs)

        # select CUs of one subchannel of each CIF and form logical frame vector
        self.select_subch = grdab.select_subch_vfvf_make(self.dp.msc_cu_size, self.dp.msc_cu_size * self.size, self.address, self.dp.num_cus)

        # time deinterleaving
        self.time_v2s = blocks.vector_to_stream_make(gr.sizeof_float, self.dp.msc_cu_size * self.size)
        self.time_deinterleaver = grdab.time_deinterleave_ff_make(self.dp.msc_cu_size * self.size, self.dp.scrambling_vector)
        # unpuncture
        self.conv_v2s = blocks.vector_to_stream(gr.sizeof_float, self.msc_punctured_codeword_length)
        self.unpuncture = grdab.unpuncture_ff_make(self.assembled_msc_puncturing_sequence, 0)

        # convolutional decoding
        self.fsm = trellis.fsm(1, 4, [0133, 0171, 0145, 0133])  # OK (dumped to text and verified partially)
        table = [
            0, 0, 0, 0,
            0, 0, 0, 1,
            0, 0, 1, 0,
            0, 0, 1, 1,
            0, 1, 0, 0,
            0, 1, 0, 1,
            0, 1, 1, 0,
            0, 1, 1, 1,
            1, 0, 0, 0,
            1, 0, 0, 1,
            1, 0, 1, 0,
            1, 0, 1, 1,
            1, 1, 0, 0,
            1, 1, 0, 1,
            1, 1, 1, 0,
            1, 1, 1, 1
        ]
        assert (len(table) / 4 == self.fsm.O())
        table = [(1 - 2 * x) / sqrt(2) for x in table]
        self.conv_decode = trellis.viterbi_combined_fb(self.fsm, self.msc_I + self.dp.conv_code_add_bits_input, 0, 0, 4, table, trellis.TRELLIS_EUCLIDEAN)
        self.conv_s2v = blocks.stream_to_vector(gr.sizeof_char, self.msc_I + self.dp.conv_code_add_bits_input)
        self.conv_prune = grdab.prune(gr.sizeof_char, self.msc_conv_codeword_length / 4, 0,
                                            self.dp.conv_code_add_bits_input)

        #energy descramble
        self.prbs_src = blocks.vector_source_b(self.dp.prbs(self.msc_I), True)
        self.energy_v2s = blocks.vector_to_stream(gr.sizeof_char, self.msc_I)
        self.add_mod_2 = blocks.xor_bb()
        #self.energy_s2v = blocks.stream_to_vector(gr.sizeof_char, self.msc_I)

        #pack bits
        self.pack_bits = blocks.unpacked_to_packed_bb_make(1, gr.GR_MSB_FIRST)

        # connect blocks
        self.connect((self, 0),
                     (self.select_msc_syms),
                     #(self.repartition_msc_to_CIFs, 0),
                     (self.repartition_msc_to_cus),
                     (self.select_subch, 0),
                     #(self.repartition_cus_to_logical_frame, 0),
                     self.time_v2s,
                     self.time_deinterleaver,
                     #self.conv_v2s,
                     self.unpuncture,
                     self.conv_decode,
                     #self.conv_s2v,
                     self.conv_prune,
                     #self.energy_v2s,
                     self.add_mod_2,
                     self.pack_bits,
                     #self.energy_s2v, #better output stream or vector??
                     (self))
        self.connect(self.prbs_src, (self.add_mod_2, 1))


#debug
        if debug is True:
            #msc_select_syms
            self.sink_msc_select_syms = blocks.file_sink_make(gr.sizeof_float * self.dp.num_carriers * 2, "debug/msc_select_syms.dat")
            self.connect(self.select_msc_syms, self.sink_msc_select_syms)

            #msc repartition cus
            self.sink_repartition_msc_to_cus = blocks.file_sink_make(gr.sizeof_float * self.dp.msc_cu_size, "debug/msc_repartitioned_to_cus.dat")
            self.connect((self.repartition_msc_to_cus), self.sink_repartition_msc_to_cus)

            #data of one sub channel not decoded
            self.sink_select_subch = blocks.file_sink_make(gr.sizeof_float * self.dp.msc_cu_size * self.size, "debug/select_subch.dat")
            self.connect(self.select_subch, self.sink_select_subch)

            #sub channel time_deinterleaved
            self.sink_subch_time_deinterleaved = blocks.file_sink_make(gr.sizeof_float, "debug/subch_time_deinterleaved.dat")
            self.connect(self.time_deinterleaver, self.sink_subch_time_deinterleaved)

            #sub channel unpunctured
            self.sink_subch_unpunctured = blocks.file_sink_make(gr.sizeof_float, "debug/subch_unpunctured.dat")
            self.connect(self.unpuncture, self.sink_subch_unpunctured)

            # sub channel convolutional decoded
            self.sink_subch_decoded = blocks.file_sink_make(gr.sizeof_char, "debug/subch_decoded.dat")
            self.connect(self.conv_decode, self.sink_subch_decoded)

            # sub channel convolutional decoded
            self.sink_subch_pruned = blocks.file_sink_make(gr.sizeof_char, "debug/subch_pruned.dat")
            self.connect(self.conv_prune, self.sink_subch_pruned)

            # sub channel energy dispersal undone unpacked
            self.sink_subch_energy_disp_undone = blocks.file_sink_make(gr.sizeof_char, "debug/subch_energy_disp_undone_unpacked.dat")
            self.connect(self.add_mod_2, self.sink_subch_energy_disp_undone)

            # sub channel energy dispersal undone packed
            self.sink_subch_energy_disp_undone_packed = blocks.file_sink_make(gr.sizeof_char, "debug/subch_energy_disp_undone_packed.dat")
            self.connect(self.pack_bits, self.sink_subch_energy_disp_undone_packed)
Beispiel #26
0
  def sim ( self, arity, snr_db, N ):
    
    vlen = 10
    N = int( N )
    snr = 10.0**(snr_db/10.0)
    
    sigpow = 1.0
    noise_pow = sigpow / snr
    #skipping first symbol due to demapper implementation (demmaper assumes that the first symbol is ID and do not decode ui)
    skiphead_src = blocks.skiphead( gr.sizeof_char, vlen+3)#vlen+3 )
    demapper = ofdm.generic_demapper_vcb( vlen,N/vlen+1 )
    const = demapper.get_constellation( arity )
    assert( len( const ) == 2**arity )
    
    symsrc = ofdm.symbol_random_src( const, vlen )
    #noise_src = ofdm.complex_white_noise( 0.0, sqrt( noise_pow ) )
    noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN, 0.0, 0, 8192)
    channel = blocks.add_cc()
    ch_model = channels.channel_model(
            noise_voltage=0.0,
            frequency_offset=0.0,
            epsilon=1.0,
            #taps = (0.998160541385960,0.0605566335500750,0.00290305927764350),
            taps = (1,0),
            noise_seed=8192,
            block_tags=False
        )
    bitmap_src = blocks.vector_source_b( [arity] * vlen, True, vlen )
    #bm_trig_src = blocks.vector_source_b( [1], True )
    ref_bitstream = blocks.unpack_k_bits_bb( arity )
    bitstream_xor = blocks.xor_bb()
    bitstream_c2f = blocks.char_to_float()
    acc_biterr = ofdm.accumulator_ff()
    skiphead = blocks.skiphead( gr.sizeof_float, N-1 )
    limit = blocks.head( gr.sizeof_float, 1 )
    dst = blocks.vector_sink_f()
    
    rec_dst = blocks.vector_sink_b()
    ref_dst = blocks.vector_sink_b()
    
    tb = gr.top_block ( "test_block" )
    #tb.connect( (symsrc,0),blocks.vector_to_stream(gr.sizeof_gr_complex ,vlen),blocks.head(gr.sizeof_gr_complex,N/arity),blocks.null_sink(gr.sizeof_gr_complex))
    
    #tb.connect( (symsrc,0),fft.fft_vcc(vlen,False,[],True),blocks.vector_to_stream(gr.sizeof_gr_complex ,vlen), ch_model, (channel,0) )
    tb.connect( (symsrc,0),blocks.vector_to_stream(gr.sizeof_gr_complex ,vlen), ch_model, (channel,0) )
    tb.connect( noise_src,  (channel,1) )
    #tb.connect( channel, blocks.stream_to_vector(gr.sizeof_gr_complex ,vlen),fft.fft_vcc(vlen,True,[],True),  (demapper,0), (bitstream_xor,0) )
    tb.connect( channel, blocks.stream_to_vector(gr.sizeof_gr_complex ,vlen), (demapper,0), (bitstream_xor,0) )
    tb.connect( bitmap_src,  (demapper,1) )
    #tb.connect( bm_trig_src, (demapper,2) )
    tb.connect( (symsrc,1),blocks.vector_to_stream(gr.sizeof_char ,vlen),skiphead_src, ref_bitstream, (bitstream_xor,1) )
    tb.connect( bitstream_xor, bitstream_c2f, acc_biterr )
    tb.connect( acc_biterr, skiphead, limit, dst )
    tb.connect( demapper, rec_dst )
    tb.connect( ref_bitstream,  ref_dst )

    tb.run()
    
    bit_errors = numpy.array( dst.data() )
    assert( len( bit_errors ) == 1 )
    bit_errors = bit_errors[0]
    
    rec_data = list(rec_dst.data())
    ref_data = list(ref_dst.data())
    
    print "ref_data: ", ref_data[:2000]
    print "size ref_data: ", len(ref_data)#[:2320
    print "rec_data: ", rec_data[:500]
    print "size rec_data: ", len(rec_data)#[:2320
    
    return bit_errors / N