Ejemplo n.º 1
0
def simulation(flame=1000, user=4, user_antenna=1, BS=1, BS_antenna=4, select_user=4, Nc=128, CP=1, path=1, Ps=1.0, data_symbol=128, M=4, conv_type='soft', code_rate=1/2, zad_len=16, zad_num=1, zad_shift=0, channel_type='Rayleigh', last_snr=30):

    code_symbol = int(data_symbol * 1/code_rate)
    bit_rate = Bitrate(M).count_bit_rate()
    selection = Selection(user, user_antenna, BS, BS_antenna, select_user)
    channel = Channel(user, user_antenna, BS_antenna, Nc, path, CP, Ps, code_symbol)
    convcode = Convcode(select_user, user_antenna, BS_antenna, data_symbol, bit_rate, code_rate, conv_type)
    modulation = Modulation(M, code_symbol, data_symbol, bit_rate, select_user, user_antenna, BS_antenna)
    equalization = Equalization(code_symbol, select_user, user_antenna, BS_anntena, Nc)

    for SNRdB in range(0,31):
        SNR = 10 ** (SNRdB / 10)
        No = 1 / SNR
        sigma = math.sqrt(No/2)
        true = Result(flame, user, BS, data_symbol, Nc)

        for count in tqdm(range(flame)):

            # Create channel
            true_channel = channel.create_rayleigh_channel()

            # User selection
            seleced_channel = selection.selection(true_channel)

            # Randomly create send bit with 0 and 1
            send_data = np.random.randint(0,2, select_user * user_antenna * data_symbol * bit_rate)

            # Serial to Parallel
            send_bit = Serial2Parallel(send_data, select_user, user_antenna, bit_rate, data_symbol).create_parallel()

            # Conv coding
            encode_bit = convcode.encoding(send_bit)

            # Modulation
            mod_signal = modulation.modulation(encode_bit)

            # Channel multiplication
            receive_signal = channel.channel_multiplication(seleced_channel, mod_signal)

            # Create noise
            noise = Noise().create_noise(code_symbol, sigma, BS_anntena)

            # Add noise
            receive_signal += noise

            # ZF equalization
            receive_weight_signal = equalization.MMSE(receive_signal, seleced_channel, SNR)

            # Demodulation
            demod_bit = modulation.demodulation(receive_weight_signal, conv_type, sigma)

            # Conv decoding
            decode_bit = convcode.decoding(demod_bit)

            # Parallel to Serial
            receive_data = Parallel2Serial(decode_bit).create_serial()

            # BER & NMSE & TRP
            true.calculate(count, send_data, receive_data, mod_signal, noise, SNR, M, bit_rate, code_rate)
Ejemplo n.º 2
0
def simulation(flame=1000, user=16, BS=1, Nc=128, CP=1, path=1, Ps=1.0, BW=1/6, data_symbol=128, conv_type='soft', total_bit=8, zad_len=16, zad_num=1, zad_shift=0, channel_type='Rayleigh', last_snr=30):

    convcode = Convcode(user, BS, data_symbol, conv_type)
    modulation = Modulation(user, BS)
    channel = Channel(user, BS, Nc, path, CP, Ps)
    weight = Weight(user, BS)

    for SNR in range(0,31):
        sigma = math.sqrt( Ps / (2 * math.pow(10.0, SNR/10)))
        true = Result(flame, user, BS, data_symbol, Nc)

        for count in tqdm(range(flame)):

            # Create channel
            true_channel = channel.create_rayleigh_channel()

            # Bit allocation & Send power control
            num_stream, bit_rate, send_power, code_rate = BERControl(user, BS, true_channel, sigma, Ps, total_bit).bit_allocation()

            # Randomly create send bit with 0 and 1
            send_data = np.random.randint(0,2,data_symbol*total_bit)

            # Serial to Parallel
            send_bit = Serial2Parallel(send_data, bit_rate, data_symbol).create_parallel()

            # Conv coding
            encode_bit, code_symbol = convcode.encoding(send_bit, num_stream, bit_rate, code_rate)

            # Modulation
            send_signal = modulation.modulation(encode_bit, num_stream, bit_rate, code_symbol)

            # Send weight multiplication
            send_weight_signal = weight.send_weight_multiplication(send_signal, true_channel, num_stream, send_power)

            # Channel multiplication
            receive_signal = channel.channel_multiplication(send_weight_signal, code_symbol)

            # Create noise
            noise = Noise().create_noise(code_symbol, sigma, BS)

            # Add noise
            receive_signal += noise

            # receive weight multiplication
            receive_weight_signal = weight.receive_weight_multiplication(receive_signal)

            # Demodulation
            demod_bit = modulation.demodulation(receive_weight_signal, conv_type, sigma)

            # Conv decoding
            decode_bit = convcode.decoding(demod_bit)

            # Parallel to Serial
            receive_data = Parallel2Serial(decode_bit, bit_rate, data_symbol).create_serial()

            # BER
            true.calculate(count, send_data, receive_data, send_weight_signal, noise, SNR, total_bit)
Ejemplo n.º 3
0
channel = Channel(user, user_antenna, BS_antenna, Nc, path, CP, Ps, symbol)
selection = Selection(user, user_antenna, BS, BS_antenna, select_user)

CDUS = []
RAND = []
ALL = []
for SNRdB in tqdm(range(0, 31)):
    SNR = 10**(SNRdB / 10)
    cdus = 0
    rand = 0
    all = 0

    for _ in range(frame):

        true_channel = channel.create_rayleigh_channel()

        cdus_channel = selection.CDUS(true_channel)
        cdus += MMSE_channel_capacity(cdus_channel, select_user, user_antenna,
                                      BS_antenna, SNR)

        rand_channel = selection.RAND(true_channel)
        rand += MMSE_channel_capacity(rand_channel, select_user, user_antenna,
                                      BS_antenna, SNR)

        all_channel, tmp = selection.ALL(true_channel, SNR)
        all += tmp

    CDUS.append(cdus / frame)
    RAND.append(rand / frame)
    ALL.append(all / frame)