def __simulate_for_one_metric(self, Ns_all_users, external_int_data_all_metrics, MsPk_all_users, Wk_all_users, metric_name, current_parameters): """ This method is only called inside the _run_simulation method. This method has the common code that is execute for each metric inside the _run_simulation method. Parameters ---------- Ns_all_users : np.ndarray Number of streams for each user. This variable controls how many data streams will be generated for each user of the K users. This is a 1D numpy array of size K. external_int_data_all_metrics : np.ndarray The data of the external interference sources (2D numpy array). MsPk_all_users : np.ndarray The precoders of all users returned by the block diagonalize method for the given metric. This is a 1D numpy array of 2D numpy arrays. Wk_all_users : np.ndarray The receive filter for all users (1D numpy array of 2D numpy arrays). metric_name : string Metric name. This string will be appended to each result name. Returns ------- TODO: Write the rest of the docstring """ # pylint: disable=R0914 Ns_total = np.sum(Ns_all_users) self.data_RS = np.random.RandomState(self.data_gen_seed) input_data = self.data_RS.randint( 0, current_parameters['M'], [Ns_total, current_parameters['NSymbs']]) symbols = self.modulator.modulate(input_data) # Prepare the transmit data. That is, the precoded_data as well as # the external interference sources' data. precoded_data = np.dot(np.hstack(MsPk_all_users), symbols) # external_int_data_all_metrics = ( # np.sqrt(self.pe) # * misc.randn_c_RS( # self.ext_data_RS, self.ext_int_rank, self.NSymbs)) all_data = np.vstack([precoded_data, external_int_data_all_metrics]) # xxxxxxxxxx Pass the precoded data through the channel xxxxxxxxxxx self.multiuser_channel.set_noise_seed(self.noise_seed) received_signal = self.multiuser_channel.corrupt_concatenated_data( all_data) # xxxxxxxxxx Filter the received data xxxxxxxxxxxxxxxxxxxxxxxxxxxxx # noinspection PyArgumentList Wk = block_diag(*Wk_all_users) received_symbols = np.dot(Wk, received_signal) # xxxxxxxxxx Demodulate the filtered symbols xxxxxxxxxxxxxxxxxxxxxx decoded_symbols = self.modulator.demodulate(received_symbols) # xxxxxxxxxx Calculates the Symbol Error Rate xxxxxxxxxxxxxxxxxxxxx num_symbol_errors = np.sum(decoded_symbols != input_data, 1) # num_symbol_errors = sum_user_data(num_symbol_errors, # Ns_all_users) num_symbols = np.ones(Ns_total) * input_data.shape[1] # xxxxxxxxxx Calculates the Bit Error Rate xxxxxxxxxxxxxxxxxxxxxxxx num_bit_errors = misc.count_bit_errors(decoded_symbols, input_data, 1) # num_bit_errors = sum_user_data(num_bit_errors, # Ns_all_users) num_bits = num_symbols * np.log2(current_parameters['M']) # xxxxxxxxxx Calculates the Package Error Rate xxxxxxxxxxxxxxxxxxxx ber = num_bit_errors / num_bits per = 1. - ((1. - ber)**current_parameters['packet_length']) num_packages = num_bits / current_parameters['packet_length'] num_package_errors = per * num_packages # xxxxxxxxxx Calculates the Spectral Efficiency xxxxxxxxxxxxxxxxxxx # nominal spectral Efficiency per stream nominal_spec_effic = self.modulator.K effective_spec_effic = (1 - per) * nominal_spec_effic # xxxxx Map the per stream metric to a global metric xxxxxxxxxxxxxx num_bit_errors = np.sum(num_bit_errors) num_bits = np.sum(num_bits) num_symbol_errors = np.sum(num_symbol_errors) num_symbols = np.sum(num_symbols) num_package_errors = np.sum(num_package_errors) num_packages = np.sum(num_packages) effective_spec_effic = np.sum(effective_spec_effic) # xxxxx Calculate teh SINR xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Uk_all_users = np.empty(Wk_all_users.size, dtype=np.ndarray) for ii in range(Wk_all_users.size): Uk_all_users[ii] = Wk_all_users[ii].conjugate().T SINR_all_k = self.multiuser_channel.calc_JP_SINR( MsPk_all_users, Uk_all_users) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # None metric ber_result = Result.create('ber_{0}'.format(metric_name), Result.RATIOTYPE, num_bit_errors, num_bits) ser_result = Result.create('ser_{0}'.format(metric_name), Result.RATIOTYPE, num_symbol_errors, num_symbols) per_result = Result.create('per_{0}'.format(metric_name), Result.RATIOTYPE, num_package_errors, num_packages) spec_effic_result = Result.create('spec_effic_{0}'.format(metric_name), Result.RATIOTYPE, effective_spec_effic, 1) sinr_result = Result('sinr_{0}'.format(metric_name), Result.RATIOTYPE, accumulate_values=True) for k in range(Wk_all_users.size): sinr_k = SINR_all_k[k] for value in sinr_k: sinr_result.update(value, 1) return (ber_result, ser_result, per_result, spec_effic_result, sinr_result)
def _run_simulation(self, current_parameters): # xxxxx Input parameters (set in the constructor) xxxxxxxxxxxxxxxxx NSymbs = current_parameters["NSymbs"] M = self.modulator.M Nr = current_parameters["Nr"] Nt = current_parameters["Nt"] SNR = current_parameters["SNR"] # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Create the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx channel = misc.randn_c(Nr, Nt) self.mimo_object.set_channel_matrix(channel) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx num_layers = self.mimo_object.getNumberOfLayers() inputData = np.random.randint(0, M, NSymbs * num_layers) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Modulate input data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx modulatedData = self.modulator.modulate(inputData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Encode with the MIMO scheme xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx transmit_signal = self.mimo_object.encode(modulatedData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Pass through the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx noiseVar = 1 / dB2Linear(SNR) awgn_noise = (misc.randn_c(Nr, NSymbs) * np.sqrt(noiseVar)) received_signal = np.dot(channel, transmit_signal) + awgn_noise # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Decode with the MIMO Scheme xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mimo_decoded_data = self.mimo_object.decode(received_signal) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate received data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx demodulatedData = self.modulator.demodulate(mimo_decoded_data) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calculates the symbol and bit error rates xxxxxxxxxxxxxxxxx symbolErrors = sum(inputData != demodulatedData) bitErrors = misc.count_bit_errors(inputData, demodulatedData) numSymbols = inputData.size numBits = inputData.size * fundamental.level2bits(M) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Return the simulation results xxxxxxxxxxxxxxxxxxxxxxxxxxxxx symbolErrorsResult = Result.create( "symbol_errors", Result.SUMTYPE, symbolErrors) numSymbolsResult = Result.create( "num_symbols", Result.SUMTYPE, numSymbols) bitErrorsResult = Result.create("bit_errors", Result.SUMTYPE, bitErrors) numBitsResult = Result.create("num_bits", Result.SUMTYPE, numBits) berResult = Result.create("ber", Result.RATIOTYPE, bitErrors, numBits) serResult = Result.create( "ser", Result.RATIOTYPE, symbolErrors, numSymbols) simResults = SimulationResults() simResults.add_result(symbolErrorsResult) simResults.add_result(numSymbolsResult) simResults.add_result(bitErrorsResult) simResults.add_result(numBitsResult) simResults.add_result(berResult) simResults.add_result(serResult) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx return simResults
def _run_simulation(self, current_parameters): # To make sure that this function does not modify the object state, # we sobrescibe self to None. #self = None # xxxxx Input parameters (set in the constructor) xxxxxxxxxxxxxxxxx NSymbs = current_parameters["NSymbs"] M = current_parameters["M"] SNR = current_parameters["SNR"] # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx inputData = np.random.randint(0, M, NSymbs) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Modulate input data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx modulatedData = self.modulator.modulate(inputData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Pass through the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx noiseVar = 1 / dB2Linear(SNR) noise = ((np.random.standard_normal(NSymbs) + 1j * np.random.standard_normal(NSymbs)) * np.sqrt(noiseVar / 2)) receivedData = modulatedData + noise # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate received data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx demodulatedData = self.modulator.demodulate(receivedData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calculates the symbol and bit error rates xxxxxxxxxxxxxxxxx symbolErrors = sum(inputData != demodulatedData) bitErrors = misc.count_bit_errors(inputData, demodulatedData) numSymbols = inputData.size numBits = inputData.size * mod.level2bits(M) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Return the simulation results xxxxxxxxxxxxxxxxxxxxxxxxxxxxx symbolErrorsResult = Result.create( "symbol_errors", Result.SUMTYPE, symbolErrors) numSymbolsResult = Result.create( "num_symbols", Result.SUMTYPE, numSymbols) bitErrorsResult = Result.create("bit_errors", Result.SUMTYPE, bitErrors) numBitsResult = Result.create("num_bits", Result.SUMTYPE, numBits) berResult = Result.create("ber", Result.RATIOTYPE, bitErrors, numBits) serResult = Result.create( "ser", Result.RATIOTYPE, symbolErrors, numSymbols) simResults = SimulationResults() simResults.add_result(symbolErrorsResult) simResults.add_result(numSymbolsResult) simResults.add_result(bitErrorsResult) simResults.add_result(numBitsResult) simResults.add_result(berResult) simResults.add_result(serResult) return simResults
def __simulate_for_one_metric(self, Ns_all_users, external_int_data_all_metrics, MsPk_all_users, Wk_all_users, metric_name, current_parameters): """ This method is only called inside the _run_simulation method. This method has the common code that is execute for each metric inside the _run_simulation method. Parameters ---------- Ns_all_users : 1D numpy array of size K. Number of streams for each user. This variable controls how many data streams will be generated for each user of the K users. external_int_data_all_metrics : 2D numpy array The data of the external interference sources. MsPk_all_users : 1D numpy array of 2D numpy arrays The precoders of all users returned by the block diagonalize method for the given metric. Wk_all_users : 1D numpy array of 2D numpy arrays The receive filter for all users. metric_name : string Metric name. This string will be appended to each result name. Returns ------- TODO: Write the rest of the docstring """ # pylint: disable=R0914 Ns_total = np.sum(Ns_all_users) self.data_RS = np.random.RandomState(self.data_gen_seed) input_data = self.data_RS.randint( 0, current_parameters['M'], [Ns_total, current_parameters['NSymbs']]) symbols = self.modulator.modulate(input_data) # Prepare the transmit data. That is, the precoded_data as well as # the external interferece sources' data. precoded_data = np.dot(np.hstack(MsPk_all_users), symbols) # external_int_data_all_metrics = ( # np.sqrt(self.pe) # * misc.randn_c_RS( # self.ext_data_RS, self.ext_int_rank, self.NSymbs)) all_data = np.vstack([precoded_data, external_int_data_all_metrics]) # xxxxxxxxxx Pass the precoded data through the channel xxxxxxxxxxx self.multiuser_channel.set_noise_seed(self.noise_seed) received_signal = self.multiuser_channel.corrupt_concatenated_data( all_data ) # xxxxxxxxxx Filter the received data xxxxxxxxxxxxxxxxxxxxxxxxxxxxx # noinspection PyArgumentList Wk = block_diag(*Wk_all_users) received_symbols = np.dot(Wk, received_signal) # xxxxxxxxxx Demodulate the filtered symbols xxxxxxxxxxxxxxxxxxxxxx decoded_symbols = self.modulator.demodulate(received_symbols) # xxxxxxxxxx Calculates the Symbol Error Rate xxxxxxxxxxxxxxxxxxxxx num_symbol_errors = np.sum(decoded_symbols != input_data, 1) # num_symbol_errors = sum_user_data(num_symbol_errors, # Ns_all_users) num_symbols = np.ones(Ns_total) * input_data.shape[1] # xxxxxxxxxx Calculates the Bit Error Rate xxxxxxxxxxxxxxxxxxxxxxxx num_bit_errors = misc.count_bit_errors(decoded_symbols, input_data, 1) # num_bit_errors = sum_user_data(num_bit_errors, # Ns_all_users) num_bits = num_symbols * np.log2(current_parameters['M']) # xxxxxxxxxx Calculates the Package Error Rate xxxxxxxxxxxxxxxxxxxx ber = num_bit_errors / num_bits per = 1. - ((1. - ber) ** current_parameters['packet_length']) num_packages = num_bits / current_parameters['packet_length'] num_package_errors = per * num_packages # xxxxxxxxxx Calculates the Spectral Efficiency xxxxxxxxxxxxxxxxxxx # nominal spectral Efficiency per stream nominal_spec_effic = self.modulator.K effective_spec_effic = (1 - per) * nominal_spec_effic # xxxxx Map the per stream metric to a global metric xxxxxxxxxxxxxx num_bit_errors = np.sum(num_bit_errors) num_bits = np.sum(num_bits) num_symbol_errors = np.sum(num_symbol_errors) num_symbols = np.sum(num_symbols) num_package_errors = np.sum(num_package_errors) num_packages = np.sum(num_packages) effective_spec_effic = np.sum(effective_spec_effic) # xxxxx Calculate teh SINR xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Uk_all_users = np.empty(Wk_all_users.size, dtype=np.ndarray) for ii in range(Wk_all_users.size): Uk_all_users[ii] = Wk_all_users[ii].conjugate().T SINR_all_k = self.multiuser_channel.calc_JP_SINR(MsPk_all_users, Uk_all_users) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # None metric ber_result = Result.create( 'ber_{0}'.format(metric_name), Result.RATIOTYPE, num_bit_errors, num_bits) ser_result = Result.create( 'ser_{0}'.format(metric_name), Result.RATIOTYPE, num_symbol_errors, num_symbols) per_result = Result.create( 'per_{0}'.format(metric_name), Result.RATIOTYPE, num_package_errors, num_packages) spec_effic_result = Result.create( 'spec_effic_{0}'.format(metric_name), Result.RATIOTYPE, effective_spec_effic, 1) sinr_result = Result( 'sinr_{0}'.format(metric_name), Result.RATIOTYPE, accumulate_values=True) for k in range(Wk_all_users.size): sinr_k = SINR_all_k[k] for value in sinr_k: sinr_result.update(value, 1) return (ber_result, ser_result, per_result, spec_effic_result, sinr_result)
def _run_simulation(self, current_parameters): # To make sure that this function does not modify the object state, # we sobrescibe self to None. #self = None # xxxxx Input parameters (set in the constructor) xxxxxxxxxxxxxxxxx NSymbs = current_parameters["NSymbs"] M = current_parameters["M"] SNR = current_parameters["SNR"] # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx inputData = np.random.randint(0, M, NSymbs) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Modulate input data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx modulatedData = self.modulator.modulate(inputData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Pass through the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx noiseVar = 1 / dB2Linear(SNR) noise = ((np.random.standard_normal(NSymbs) + 1j * np.random.standard_normal(NSymbs)) * np.sqrt(noiseVar / 2)) receivedData = modulatedData + noise # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate received data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx demodulatedData = self.modulator.demodulate(receivedData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calculates the symbol and bit error rates xxxxxxxxxxxxxxxxx symbolErrors = sum(inputData != demodulatedData) bitErrors = misc.count_bit_errors(inputData, demodulatedData) numSymbols = inputData.size numBits = inputData.size * mod.level2bits(M) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Return the simulation results xxxxxxxxxxxxxxxxxxxxxxxxxxxxx symbolErrorsResult = Result.create("symbol_errors", Result.SUMTYPE, symbolErrors) numSymbolsResult = Result.create("num_symbols", Result.SUMTYPE, numSymbols) bitErrorsResult = Result.create("bit_errors", Result.SUMTYPE, bitErrors) numBitsResult = Result.create("num_bits", Result.SUMTYPE, numBits) berResult = Result.create("ber", Result.RATIOTYPE, bitErrors, numBits) serResult = Result.create("ser", Result.RATIOTYPE, symbolErrors, numSymbols) simResults = SimulationResults() simResults.add_result(symbolErrorsResult) simResults.add_result(numSymbolsResult) simResults.add_result(bitErrorsResult) simResults.add_result(numBitsResult) simResults.add_result(berResult) simResults.add_result(serResult) return simResults