Exemplo 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)
Exemplo 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)
Exemplo n.º 3
0
    def createDownloadDirectory(self, channel: Channel) -> Path:
        channelDirectory = Path(self.__downloadDirectory / channel.getTitle())
        if channelDirectory.exists():
            raise IOError('Channel "' + channel.getTitle() +
                          '" already has a directory. '
                          'Move or remove directory and try again.')

        channelDirectory.mkdir()
        return channelDirectory
Exemplo n.º 4
0
 def create_train(self):
     for sample in range(self.flame):
         self.channel = Channel(self.symbol, self.user, self.BS, 1,
                                self.path, self.CP,
                                self.Ps).create_rayleigh_channel()
         estimated_channel, receive_pilot_signal = Estimate(
             self.pilot_signal, self.channel, self.user, self.BS, self.path,
             self.sigma, 1).least_square_estimate()
         self.file_writing(sample, estimated_channel.reshape(1, self.user),
                           receive_pilot_signal.reshape(1, self.pilot_len),
                           self.channel.reshape(1, self.user))
Exemplo n.º 5
0
    def parse(self, url: str, feedContent: str) -> Iterator[Episode]:
        tree = cElementTree.fromstring(feedContent)

        channel = Channel(self.getChannelTitle(tree), url)

        for episode in tree.iter('item'):
            yield self.parseEpisode(episode, channel)
Exemplo n.º 6
0
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    for i in range(user):
        ax.plot(x, cumulative_matrix[i], linestyle='-', color='k')

    plt.gca().xaxis.set_tick_params(direction='in')
    plt.gca().yaxis.set_tick_params(direction='in')

    ax.set_xlabel('eigenvalue [dB]', fontsize=12)
    ax.set_ylabel('Cumulative probability', fontsize=12)

    plt.grid(which="both")

    plt.savefig('Image/CDF/user{}_BS{}.pdf'.format(user, BS))

    #-----------NMSE--------


symbol = 128
user = 4
BS = 4
Nc = 128
path = 1
CP = 1
Ps = 1

channel = Channel(symbol, user, BS, Nc, path, CP, Ps)

cumulative_probability(channel, user, BS)
Exemplo n.º 7
0
select_user = math.floor(BS_antenna / user_antenna)  # 選択されたユーザ数

Nc = 72  # 搬送波数

CP = 1  # CP数
path = 1  # パス数
Ps = 1.0  # 総送信電力

SNRdB = 10
SNR = 10**(SNRdB / 10)

symbol = 72

frame = 100

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()
Exemplo n.º 8
0
from Model.Channel import Channel
from Model.Estimate import Estimate

user = 19
BS = 2
path = 1
pilot_len = 9
size = 19
symbol = 128
Nc = 128
CP = 1
Ps = 1.0
EbN0 = 30
sigma = math.sqrt(0.5 * math.pow(10.0, (-1) * EbN0 * 0.1))

channel = Channel(symbol, user, BS, Nc, path, CP, Ps)
true_channel = channel.create_rayleigh_channel()

dft_pilot = DFTSequence(user, path, pilot_len, size).create_pilot()
frame_pilot = Frame(user, pilot_len).create_frame_matrix()

for r in range(BS):
    tmp_channel = np.zeros((user * path, 1), dtype=np.complex)

    for s in range(user):
        for p in range(path):
            tmp_channel[s * path + p, 0] = true_channel[p, user * r + s]

    tmp_receive = np.dot(frame_pilot, tmp_channel)

    A_ = np.linalg.pinv(frame_pilot)
Exemplo n.º 9
0
    path = 1
    CP = 1
    Ps = 1
    total_bit = user * 2

    code_rates = [1 / 2, 2 / 3, 3 / 4]
    frame = 2

    conv_type = 'soft'
    BW = 1 / 6

    bit_dict = []

    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 cnt in tqdm(range(count)):
        if is_random == True:
            SNRdB = random.randint(20, 25)

        SNR = 10**(SNRdB / 10)
        No = 1 / SNR
        sigma = math.sqrt(No / 2)

        true_channel = channel.create_rayleigh_channel()
        H = np.zeros((BS, user), dtype=np.complex)
        for r in range(BS):
            for s in range(user):
                H[r][s] = true_channel[0][BS * r + s]
Exemplo n.º 10
0
def simulation(flame=1000,
               user=16,
               BS=1,
               Nc=128,
               CP=1,
               path=1,
               Ps=1.0,
               BW=80,
               data_symbol=100,
               Ms=4,
               code_rates=1 / 2,
               conv_type='hard',
               zad_len=4,
               zad_num=0,
               zad_shift=1,
               channel_type='Rayleigh',
               csv_column=False,
               last_snr=30):

    for SNR in range(0, last_snr):

        sigma = math.sqrt(Ps / (2 * math.pow(10.0, SNR / 10)))
        zadoff_pilot = ZadoffSequence(user, path, zad_len, zad_num,
                                      zad_shift).create_pilot()
        zadoff_estimate = Estimate(zadoff_pilot, user, BS, path, sigma, Nc)

        # dft_pilot = DFTSequence(user, path, pilot_len, size).create_pilot()
        # frame_pilot = Frame(user, pilot_len).create_frame_matrix()

        true = Result(flame, user, BS, BW, data_symbol, Nc, conv_type,
                      channel_type, csv_column, last_snr)
        zadoff = Result(flame, user, BS, BW, data_symbol, Nc, conv_type,
                        channel_type, csv_column, last_snr)

        for code_rate in code_rates:
            for M in Ms:

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

                for count in tqdm(range(flame)):

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

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

                    # Conv coding
                    encode_bit = convcode.encoding(send_bit)

                    # Modulation
                    mod_signal = modulation.modulation(encode_bit)

                    # Create channel
                    true_channel = channel.create_channel()

                    # Channel multiplication
                    receive_signal = channel.channel_multiplication(mod_signal)

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

                    # Add noise
                    receive_signal += noise

                    # ZF equalization
                    receive_weight_signal = equalization.ZF(
                        receive_signal, true_channel)

                    # 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)

                    #---------------------------- zadoff -------------------------------------

                    # channel estimate
                    zadoff_channel = zadoff_estimate.least_square_estimate(
                        true_channel)

                    # Frequency domain equalization
                    zadoff_signal = equalization.ZF(receive_signal,
                                                    zadoff_channel)

                    # Demodulation
                    zadoff_demod_bit = modulation.demodulation(
                        zadoff_signal, conv_type, sigma)

                    # Conv decoding
                    zadoff_decode_bit = convcode.decoding(zadoff_demod_bit)

                    # Parallel to Serial
                    zadoff_receive_data = Parallel2Serial(
                        zadoff_decode_bit).create_serial()

                    # BER & NMSE & TRP
                    zadoff.calculate(count, send_data, zadoff_receive_data,
                                     mod_signal, noise, SNR, M, bit_rate,
                                     code_rate, true_channel, zadoff_channel)
Exemplo n.º 11
0
class Train:
    def __init__(self,
                 flame=10500,
                 symbol=128,
                 user=16,
                 BS=1,
                 CP=1,
                 path=1,
                 Ps=1.0,
                 EbN0=20,
                 pilot_len=16,
                 size=16,
                 type=None):
        self.flame = flame
        self.symbol = symbol
        self.user = user
        self.BS = BS
        self.CP = CP
        self.path = path
        self.Ps = Ps
        self.EbN0 = EbN0
        self.sigma = math.sqrt(0.5 * math.pow(10.0, (-1) * EbN0 * 0.1))
        self.pilot_len = pilot_len
        self.size = size
        self.type = type
        if self.type == 'DFT':
            self.pilot_signal = DFTSequence(user, path, pilot_len,
                                            size).create_pilot()
        if self.type == 'frame':
            self.pilot_signal = Frame(user, pilot_len).create_frame_matrix()

    def create_train(self):
        for sample in range(self.flame):
            self.channel = Channel(self.symbol, self.user, self.BS, 1,
                                   self.path, self.CP,
                                   self.Ps).create_rayleigh_channel()
            estimated_channel, receive_pilot_signal = Estimate(
                self.pilot_signal, self.channel, self.user, self.BS, self.path,
                self.sigma, 1).least_square_estimate()
            self.file_writing(sample, estimated_channel.reshape(1, self.user),
                              receive_pilot_signal.reshape(1, self.pilot_len),
                              self.channel.reshape(1, self.user))

    def file_writing(self, sample, estimated_channel, receive_pilot_signal,
                     channel):

        dir = "Data/train_data/{}".format(self.type)
        if not os.path.exists(dir):
            os.makedirs(dir)

        ls_dir = "{}/ls".format(dir)
        if not os.path.exists(ls_dir):
            os.makedirs(ls_dir)

        ls_file = "{}/size{}_pilot{}_user{}.csv".format(
            ls_dir, self.size, self.pilot_len, self.user)
        if not os.path.exists(ls_file):
            pathlib.Path(ls_file).touch()

        if sample == 0:
            with open(ls_file, 'w') as f:
                writer = csv.writer(f, lineterminator='\n')
                writer.writerows(
                    np.concatenate([
                        np.real(estimated_channel),
                        np.imag(estimated_channel)
                    ], 1))

        else:
            with open(ls_file, 'a') as f:
                writer = csv.writer(f, lineterminator='\n')
                writer.writerows(
                    np.concatenate([
                        np.real(estimated_channel),
                        np.imag(estimated_channel)
                    ], 1))

        receive_dir = "{}/receive".format(dir)
        if not os.path.exists(receive_dir):
            os.makedirs(receive_dir)

        receive_file = "{}/size{}_pilot{}_user{}.csv".format(
            receive_dir, self.size, self.pilot_len, self.user)
        if not os.path.exists(receive_file):
            pathlib.Path(receive_file).touch()

        if sample == 0:
            with open(receive_file, 'w') as f:
                writer = csv.writer(f, lineterminator='\n')
                writer.writerows(
                    np.concatenate([
                        np.real(receive_pilot_signal),
                        np.imag(receive_pilot_signal)
                    ], 1))

        else:
            with open(receive_file, 'a') as f:
                writer = csv.writer(f, lineterminator='\n')
                writer.writerows(
                    np.concatenate([
                        np.real(receive_pilot_signal),
                        np.imag(receive_pilot_signal)
                    ], 1))

        true_dir = "{}/true".format(dir)
        if not os.path.exists(true_dir):
            os.makedirs(true_dir)

        true_file = "{}/size{}_pilot{}_user{}.csv".format(
            true_dir, self.size, self.pilot_len, self.user)
        if not os.path.exists(true_file):
            pathlib.Path(true_file).touch()

        if sample == 0:
            with open(true_file, 'w') as f:
                writer = csv.writer(f, lineterminator='\n')
                writer.writerows(
                    np.concatenate(
                        [np.real(channel), np.imag(channel)], 1))

        else:
            with open(true_file, 'a') as f:
                writer = csv.writer(f, lineterminator='\n')
                writer.writerows(
                    np.concatenate(
                        [np.real(channel), np.imag(channel)], 1))