Пример #1
0
    def _de_rate_match_by_accumulation(input_values):
        nrof_blocks = int(input_values.length() / input_block_size)
        de_rate_matched_values = vec(nrof_blocks * de_rate_matched_block_size)
        de_rate_matched_values.clear()

        # Determine the number of full repetitions of each input block
        nrof_repetitions = int(input_block_size / de_rate_matched_block_size)
        nrof_extra_values = input_block_size - nrof_repetitions * de_rate_matched_block_size

        # Pre-allocate vector to store accumulated values for efficiency
        current_de_rate_matched_block = vec(de_rate_matched_block_size)
        for block_index in range(nrof_blocks):
            current_de_rate_matched_block.clear()

            #First, accumulate the extra bits left over after complete block repeitions
            read_index = block_index * input_block_size + nrof_repetitions * de_rate_matched_block_size
            current_de_rate_matched_block.set_subvector(
                0, input_values.mid(read_index, nrof_extra_values))

            # Accumulate the input values into the de rate matched valuess
            for repetition_index in range(nrof_repetitions):
                read_index = block_index * input_block_size + repetition_index * de_rate_matched_block_size
                current_de_rate_matched_block += input_values.mid(
                    read_index, de_rate_matched_block_size)

            de_rate_matched_values.set_subvector(
                block_index * de_rate_matched_block_size,
                current_de_rate_matched_block)

        return de_rate_matched_values
Пример #2
0
def simluate_rayleigh_fading_channel(nrof_samples,
                                     avg_snr_dB,
                                     awgn_data,
                                     packet_sizes,
                                     norm_doppler=0.01,
                                     seed=9999,
                                     cqi_error_std=0.0):

    # Create a Rayleigh fading channel. The channel power is normalized to 1 by default
    channel = itpp.comm.TDL_Channel(itpp.vec('0.0'), itpp.ivec('0'))
    channel.set_norm_doppler(norm_doppler)

    channel_coeff_itpp = itpp.cmat()
    channel.generate(nrof_samples, channel_coeff_itpp)

    channel_coeff = np.array(channel_coeff_itpp.get_col(0))

    avg_snr = 10**(0.1 * avg_snr_dB)
    instantaneous_channel_snrs = (np.absolute(channel_coeff)**2) * avg_snr

    _, nrof_rates = awgn_data['snr_vs_per'].shape
    instantaneous_blers = []
    channel_quality_indices = []
    for i in range(nrof_samples):
        cqi_sinr_error = (itpp.random.randn() - 0.5) * cqi_error_std

        snr_dB = 10 * np.log10(instantaneous_channel_snrs[i])
        instantaneous_blers.append(determine_bler_at_sinr(snr_dB, awgn_data))
        channel_quality_indices.append(
            determine_cqi_from_sinr(snr_dB, packet_sizes, awgn_data,
                                    cqi_sinr_error))

    return (np.array(instantaneous_blers), np.array(channel_quality_indices))
def bit_error_ratio_hamming_awgn(snr_db):
    '''Hamming encoder and decoder instance'''
    k = 3 # (7,4) Hamming code
    hamm = itpp.comm.hamming_code(k)
    
    '''Generate random bits'''
    nrof_bits = k * 100000
    source_bits = itpp.random.randb(nrof_bits)
    
    '''Encode the bits'''
    encoded_bits = hamm.encode(source_bits)
    
    '''Modulate the bits'''
    modulator_ = itpp.comm.modulator_1d()
    constellation = itpp.vec('-1, 1')
    symbols = itpp.ivec('0, 1')
    modulator_.set(constellation, symbols)
    tx_signal = modulator_.modulate_bits(encoded_bits)
    
    '''Add the effect of channel to the signal'''
    noise_variance = 1.0 / (pow(10, 0.1 * snr_db))
    noise = itpp.random.randn(tx_signal.length())
    noise *= itpp.math.sqrt(noise_variance)
    rx_signal = tx_signal + noise
    
    '''Demodulate the signal'''
    demodulated_bits = modulator_.demodulate_bits(rx_signal)
    
    '''Decode the received bits'''
    decoded_bits = hamm.decode(demodulated_bits) 
    
    '''Calculate the bit error ratio'''
    return itpp.comm.BERC.count_errors(source_bits, decoded_bits, 0, 0, 0) / nrof_bits
Пример #4
0
def block_error_ratio_turbo_awgn(snr_db, interleaver_length):
    '''Create turbo_codec_instance'''
    codec = itpp.comm.turbo_codec()
    '''Set codec parameters'''
    gen = itpp.ivec(2)
    gen[0] = 11
    gen[1] = 13
    constraint_length = 4
    interleaver = itpp.ivec(
        '0, 19, 14, 33, 28, 47, 42, 13, 8, 27, 22, 41, 36, 7, 2, 21, 16, 35, 30, 1, 44, 15, 10, 29, 24, 43, 38, 9, 4, 23, 18, 37, 32, 3, 46, 17, 12, 31, 26, 45, 40, 11, 6, 25, 20, 39, 34, 5'
    )
    codec.set_parameters(gen, gen, constraint_length, itpp.ivec())
    codec.set_interleaver(interleaver)
    '''Generate random bits and encode them'''
    nrof_uncoded_bits = interleaver_length * 1000
    uncoded_bits = itpp.random.randb(nrof_uncoded_bits)
    encoded_bits = itpp.bvec()
    codec.encode(uncoded_bits, encoded_bits)
    '''Modulate bits using BPSK'''
    symbols = itpp.vec('1, -1')
    bits2symbol = itpp.ivec('0, 1')
    modulator_ = itpp.comm.modulator_1d(symbols, bits2symbol)
    tx_signal = modulator_.modulate_bits(encoded_bits)
    '''Add AWGN noise'''
    noise_variance = 1.0 / (pow(10, 0.1 * snr_db))
    noise = itpp.random.randn(tx_signal.length())
    noise *= itpp.math.sqrt(noise_variance)
    rx_signal = tx_signal + noise
    '''Demodulate received signal (soft bits, LOGMAP)'''
    soft_bits = itpp.vec()
    modulator_.demodulate_soft_bits(rx_signal, noise_variance, soft_bits,
                                    itpp.comm.Soft_Method.LOGMAP)
    '''Turbo decode the soft bits'''
    decoded_bits = itpp.bvec()
    codec.decode(soft_bits, decoded_bits, itpp.bvec())
    '''Count errors'''
    blerc = itpp.comm.BLERC(interleaver_length)
    blerc.count(decoded_bits, uncoded_bits)
    return blerc.get_errorrate()
Пример #5
0
def generateRaptorLDPC(numInfoBits, rate, outFilename):
    """
    Generates a left 4-degree regular, random right degree LDPC code with
    'numInfoBits' information bits.
    
    @param numInfoBits: the number of message bits the LDPC code will handle
    @param rate: the rate of the LDPC code
    @param outFilename: filename where the bits will be written
    """
    
    leftDegree = 4
    
    numVariables = int(numInfoBits / rate)
    print "numVariables:", numVariables
    
    dist = binom(numInfoBits, 1.0 * leftDegree / (numVariables - numInfoBits))
    maxRightDegree = int(dist.isf(1e-8))
    itRight = itpp.vec(maxRightDegree)
    for i in xrange(maxRightDegree):
        itRight[i] = dist.pmf(i+1)
    itRight[maxRightDegree-1] = itRight[maxRightDegree-1] + 1e-8

    itLeft = itpp.vec(leftDegree)
    for i in xrange(leftDegree-1):
        itLeft[i] = 0
    itLeft[leftDegree - 1] = 1.0
    print itLeft
    
    H = itpp.LDPC_Parity_Irregular()
    H.generate(numVariables, itLeft, itRight, "rand", itpp.ivec("150 8"))
    H.display_stats()
    print "got code with ", (H.get_nvar() - H.get_ncheck()), " nodes"
    
    
    G = itpp.LDPC_Generator_Systematic(H);
    C = itpp.LDPC_Code(H, G)
    C.save_code(outFilename);
Пример #6
0
def generateRaptorLDPC(numInfoBits, rate, outFilename):
    """
    Generates a left 4-degree regular, random right degree LDPC code with
    'numInfoBits' information bits.
    
    @param numInfoBits: the number of message bits the LDPC code will handle
    @param rate: the rate of the LDPC code
    @param outFilename: filename where the bits will be written
    """

    leftDegree = 4

    numVariables = int(numInfoBits / rate)
    print "numVariables:", numVariables

    dist = binom(numInfoBits, 1.0 * leftDegree / (numVariables - numInfoBits))
    maxRightDegree = int(dist.isf(1e-8))
    itRight = itpp.vec(maxRightDegree)
    for i in xrange(maxRightDegree):
        itRight[i] = dist.pmf(i + 1)
    itRight[maxRightDegree - 1] = itRight[maxRightDegree - 1] + 1e-8

    itLeft = itpp.vec(leftDegree)
    for i in xrange(leftDegree - 1):
        itLeft[i] = 0
    itLeft[leftDegree - 1] = 1.0
    print itLeft

    H = itpp.LDPC_Parity_Irregular()
    H.generate(numVariables, itLeft, itRight, "rand", itpp.ivec("150 8"))
    H.display_stats()
    print "got code with ", (H.get_nvar() - H.get_ncheck()), " nodes"

    G = itpp.LDPC_Generator_Systematic(H)
    C = itpp.LDPC_Code(H, G)
    C.save_code(outFilename)
def determine_bler_at_sinr(awgn_data, sinr_dB):
    awgn_snr_range_dB = awgn_data['snr_range_dB']
    awgn_snr_vs_bler = awgn_data['snr_vs_bler']

    _, nrof_cqi = awgn_snr_vs_bler.shape

    bler_at_sinr = itpp.vec(nrof_cqi)

    for i in range(nrof_cqi):
        bler = awgn_snr_vs_bler[:, i]
        if sinr_dB <= np.min(awgn_snr_range_dB):
            bler_at_sinr[i] = 1.0
        elif sinr_dB >= np.max(awgn_snr_range_dB):
            bler_at_sinr[i] = 0.0
        else:
            index1 = np.max(np.argwhere(awgn_snr_range_dB < sinr_dB))
            index2 = np.min(np.argwhere(awgn_snr_range_dB > sinr_dB))

            bler_at_sinr[i] = (bler[index1] + bler[index2]) / 2.0

    return bler_at_sinr
Пример #8
0
def block_error_ratio_uncoded_awgn(snr_db, block_size):
    '''Generate random bits'''
    nrof_bits = 3 * 10000 * block_size
    source_bits = itpp.random.randb(nrof_bits)
    '''Modulate the bits'''
    modulator_ = itpp.comm.modulator_1d()
    constellation = itpp.vec('-1, 1')
    symbols = itpp.ivec('0, 1')
    modulator_.set(constellation, symbols)
    tx_signal = modulator_.modulate_bits(source_bits)
    '''Add the effect of channel to the signal'''
    noise_variance = 1.0 / (pow(10, 0.1 * snr_db))
    noise = itpp.random.randn(tx_signal.length())
    noise *= itpp.math.sqrt(noise_variance)
    rx_signal = tx_signal + noise
    '''Demodulate the signal'''
    demodulated_bits = modulator_.demodulate_bits(rx_signal)
    '''Calculate the block error ratio'''
    blerc = itpp.comm.BLERC(block_size)
    blerc.count(source_bits, demodulated_bits)
    return blerc.get_errorrate()