def get_data_to_be_plotted(self): ber = self.results.get_result_values_list('ber') ser = self.results.get_result_values_list('ser') # Get the SNR from the simulation parameters SNR = np.array(self.params['SNR']) # Number of bits per symbol k = mod.level2bits(self.modulator.M) Eb_over_N0 = SNR - 10 * np.log10(k) # Calculates the Theoretical SER and BER theoretical_ser = self.modulator.calcTheoreticalSER(SNR) theoretical_ber = self.modulator.calcTheoreticalBER(SNR) return SNR, Eb_over_N0, ber, ser, theoretical_ber, theoretical_ser
def _run_simulation(self, current_parameters): """The _run_simulation method is where the actual code to simulate the system is. The implementation of this method is required by every subclass of SimulationRunner. """ # xxxxx Input parameters (set in the constructor) xxxxxxxxxxxxxxxxx NSymbs = current_parameters['NSymbs'] modulator = current_parameters['modulator'] M = modulator.M SNR = current_parameters["SNR"] # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx inputData = np.random.randint(0, M, NSymbs) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Modulate input data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx modulatedData = modulator.modulate(inputData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Pass through the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx noiseVar = 1. / dB2Linear(SNR) noise = misc.randn_c(NSymbs) * np.sqrt(noiseVar) receivedData = modulatedData + noise # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate received data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx demodulatedData = 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 * 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): # pylint: disable=R0914,R0915 # xxxxxxxxxx Prepare the scenario for this iteration. xxxxxxxxxxxxx # This will create user in random positons and calculate pathloss # (if the scenario includes it). After that, it will generate # random channels from all transmitters to all receivers. self._create_users_channels_according_to_scenario(current_parameters) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input parameters (set in the constructor) xxxxxxxxxxxxxxxxx M = self.modulator.M NSymbs = current_parameters["NSymbs"] K = current_parameters["num_cells"] # Nr = current_parameters["Nr"] # Nt = current_parameters["Nt"] Ns = current_parameters["Ns"] SNR = current_parameters["SNR"] if current_parameters["scenario"] == "NoPathLoss": pt = self._calc_transmit_power(SNR, self.noise_var) elif current_parameters["scenario"] == "Random": pt = self._calc_transmit_power(SNR, self.noise_var, self._path_loss_border) else: raise ValueError("Invalid scenario") # Store the original (maximum) number of streams for each user for # later usage if isinstance(Ns, int): orig_Ns = np.ones(K, dtype=int) * Ns else: orig_Ns = Ns.copy() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calc. precoders and receive filters for IA xxxxxxxxxxxxxxxx # We need to perform IA before generating any data so that we know # how many streams we need to send (and thus generate data. Note # that it is not always equal to Ns. It can be lower for some user # if the IA algorithm chooses a precoder that sends zero energy in # some stream. self.ia_solver.clear() self.ia_solver.initialize_with = current_parameters["initialize_with"] try: self.ia_top_object.solve(Ns=Ns, P=pt) except (RuntimeError, LinAlgError): raise SkipThisOne("Could not find the IA solution. Skipping this repetition") # If any of the Nr, Nt or Ns variables were integers (meaning all # users have the same value) we will convert them by numpy arrays # with correct size (K). # Nr = self.ia_solver.Nr # Nt = self.ia_solver.Nt Ns = self.ia_solver.Ns cumNs = np.cumsum(self.ia_solver.Ns) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # inputData has the data of all users (vertically stacked) inputData = self.data_RS.randint(0, M, [np.sum(Ns), NSymbs]) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Modulate input data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # modulatedData has the data of all users (vertically stacked) modulatedData = self.modulator.modulate(inputData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Perform the Interference Alignment xxxxxxxxxxxxxxxxxxx # Split the data. transmit_signal will be a list and each element # is a numpy array with the data of a user transmit_signal = np.split(modulatedData, cumNs[:-1]) transmit_signal_precoded = map(np.dot, self.ia_solver.full_F, transmit_signal) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Pass through the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # noinspection PyProtectedMember multi_user_channel = self.ia_solver._multiUserChannel # received_data is an array of matrices, one matrix for each receiver. received_data = multi_user_channel.corrupt_data(transmit_signal_precoded) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Perform the Interference Cancelation xxxxxxxxxxxxxxxxxxxxxx received_data_no_interference = map(np.dot, self.ia_solver.full_W_H, received_data) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx received_data_no_interference = np.vstack(received_data_no_interference) demodulated_data = self.modulator.demodulate(received_data_no_interference) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calculates the symbol and bit error rates xxxxxxxxxxxxxxxxx symbolErrors = np.sum(inputData != demodulated_data) bitErrors = misc.count_bit_errors(inputData, demodulated_data) numSymbols = inputData.size numBits = inputData.size * fundamental.level2bits(M) ia_cost = self.ia_solver.get_cost() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Calculates the Sum Capacity xxxxxxxxxxxxxxxxxxxxxxxxxx sirn_all_k = self.ia_solver.calc_SINR() calc_capacity = lambda sirn: np.sum(np.log2(1 + sirn)) # Array with the sum capacity of each user sum_capacity = list(map(calc_capacity, sirn_all_k)) # Total sum capacity total_sum_capacity = np.sum(sum_capacity) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Number of iterations of the IA algorithm xxxxxxxxxxxxx ia_runned_iterations = self.ia_solver.runned_iterations # 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, accumulate_values=False) serResult = Result.create("ser", Result.RATIOTYPE, symbolErrors, numSymbols, accumulate_values=False) ia_costResult = Result.create("ia_cost", Result.RATIOTYPE, ia_cost, 1, accumulate_values=False) sum_capacityResult = Result.create( "sum_capacity", Result.RATIOTYPE, total_sum_capacity, 1, accumulate_values=False ) ia_runned_iterationsResult = Result.create( "ia_runned_iterations", Result.RATIOTYPE, ia_runned_iterations, 1, accumulate_values=False ) # xxxxxxxxxx chosen stream configuration index xxxxxxxxxxxxxxxxxxxx # Interpret Ns as a multidimensional index stream_index_multi = Ns - 1 # Convert to a 1D index suitable for storing stream_index = int(np.ravel_multi_index(stream_index_multi, orig_Ns)) num_choices = int(np.prod(orig_Ns)) stream_statistics = Result.create("stream_statistics", Result.CHOICETYPE, stream_index, num_choices) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 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) simResults.add_result(ia_costResult) simResults.add_result(sum_capacityResult) simResults.add_result(ia_runned_iterationsResult) simResults.add_result(stream_statistics) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx return simResults
received_signal = multiuser_channel.corrupt_concatenated_data(all_data) # Filter the received data receive_filter = np.linalg.pinv(newH) received_symbols = np.dot(receive_filter, received_signal) # Demodulate the filtered symbols decoded_symbols = modulator.demodulate(received_symbols) # Calculates the number of symbol errors num_symbol_errors += np.sum(decoded_symbols != input_data) num_symbols += input_data.size # Calculates the number of bit errors num_bit_errors += misc.count_bit_errors(input_data, decoded_symbols) num_bits += input_data.size * fundamental.level2bits(M) pbar.progress(rep + 1) # Calculate the Symbol Error Rate print() print(num_symbol_errors) print(num_symbols) print("SER: {0}".format(float(num_symbol_errors) / float(num_symbols))) print("BER: {0}".format(float(num_bit_errors) / float(num_bits))) # xxxxxxxxxx Finished xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx toc = time() print(misc.pretty_time(toc - tic)) # Resultados
def _run_simulation( self, # pylint: disable=R0914,R0915 current_parameters): # xxxxxxxxxx Prepare the scenario for this iteration. xxxxxxxxxxxxx # This will create user in random positions and calculate pathloss # (if the scenario includes it). After that, it will generate # random channels from all transmitters to all receivers. self._create_users_channels_according_to_scenario(current_parameters) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input parameters (set in the constructor) xxxxxxxxxxxxxxxxx M = self.modulator.M NSymbs = current_parameters["NSymbs"] K = current_parameters["num_cells"] # Nr = current_parameters["Nr"] # Nt = current_parameters["Nt"] Ns = current_parameters["Ns"] SNR = current_parameters["SNR"] if current_parameters['scenario'] == 'NoPathLoss': pt = self._calc_transmit_power(SNR, self.noise_var) elif current_parameters['scenario'] == 'Random': pt = self._calc_transmit_power(SNR, self.noise_var, self._path_loss_border) else: raise ValueError('Invalid scenario') # Store the original (maximum) number of streams for each user for # later usage if isinstance(Ns, int): orig_Ns = np.ones(K, dtype=int) * Ns else: orig_Ns = Ns.copy() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calc. precoders and receive filters for IA xxxxxxxxxxxxxxxx # We need to perform IA before generating any data so that we know # how many streams we need to send (and thus generate data. Note # that it is not always equal to Ns. It can be lower for some user # if the IA algorithm chooses a precoder that sends zero energy in # some stream. self.ia_solver.clear() self.ia_solver.initialize_with = current_parameters['initialize_with'] try: self.ia_top_object.solve(Ns=Ns, P=pt) except (RuntimeError, LinAlgError): raise SkipThisOne( "Could not find the IA solution. Skipping this repetition") # If any of the Nr, Nt or Ns variables were integers (meaning all # users have the same value) we will convert them by numpy arrays # with correct size (K). # Nr = self.ia_solver.Nr # Nt = self.ia_solver.Nt Ns = self.ia_solver.Ns cumNs = np.cumsum(self.ia_solver.Ns) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # inputData has the data of all users (vertically stacked) inputData = self.data_RS.randint(0, M, [np.sum(Ns), NSymbs]) ":type: np.ndarray" # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Modulate input data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # modulatedData has the data of all users (vertically stacked) modulatedData = self.modulator.modulate(inputData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Perform the Interference Alignment xxxxxxxxxxxxxxxxxxx # Split the data. transmit_signal will be a list and each element # is a numpy array with the data of a user transmit_signal = np.split(modulatedData, cumNs[:-1]) transmit_signal_precoded = map(np.dot, self.ia_solver.full_F, transmit_signal) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Pass through the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # noinspection PyProtectedMember multi_user_channel = self.ia_solver._multiUserChannel # received_data is an array of matrices, one matrix for each receiver. received_data = multi_user_channel.corrupt_data( transmit_signal_precoded) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Perform the Interference Cancellation xxxxxxxxxxxxxxxxxxxxx received_data_no_interference = map(np.dot, self.ia_solver.full_W_H, received_data) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx received_data_no_interference = np.vstack( received_data_no_interference) demodulated_data = self.modulator.demodulate( received_data_no_interference) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calculates the symbol and bit error rates xxxxxxxxxxxxxxxxx symbolErrors = np.sum(inputData != demodulated_data) bitErrors = misc.count_bit_errors(inputData, demodulated_data) numSymbols = inputData.size numBits = inputData.size * fundamental.level2bits(M) ia_cost = self.ia_solver.get_cost() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Calculates the Sum Capacity xxxxxxxxxxxxxxxxxxxxxxxxxx sirn_all_k = self.ia_solver.calc_SINR() calc_capacity = lambda sirn: np.sum(np.log2(1 + sirn)) # Array with the sum capacity of each user sum_capacity = list(map(calc_capacity, sirn_all_k)) # Total sum capacity total_sum_capacity = np.sum(sum_capacity) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Number of iterations of the IA algorithm xxxxxxxxxxxxx ia_runned_iterations = self.ia_solver.runned_iterations # 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, accumulate_values=False) serResult = Result.create("ser", Result.RATIOTYPE, symbolErrors, numSymbols, accumulate_values=False) ia_costResult = Result.create("ia_cost", Result.RATIOTYPE, ia_cost, 1, accumulate_values=False) sum_capacityResult = Result.create("sum_capacity", Result.RATIOTYPE, total_sum_capacity, 1, accumulate_values=False) ia_runned_iterationsResult = Result.create("ia_runned_iterations", Result.RATIOTYPE, ia_runned_iterations, 1, accumulate_values=False) # xxxxxxxxxx chosen stream configuration index xxxxxxxxxxxxxxxxxxxx # Interpret Ns as a multidimensional index stream_index_multi = Ns - 1 # Convert to a 1D index suitable for storing stream_index = int(np.ravel_multi_index(stream_index_multi, orig_Ns)) num_choices = int(np.prod(orig_Ns)) stream_statistics = Result.create("stream_statistics", Result.CHOICETYPE, stream_index, num_choices) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 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) simResults.add_result(ia_costResult) simResults.add_result(sum_capacityResult) simResults.add_result(ia_runned_iterationsResult) simResults.add_result(stream_statistics) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx return simResults
def _run_simulation(self, current_parameters): """The _run_simulation method is where the actual code to simulate the system is. The implementation of this method is required by every subclass of SimulationRunner. """ # xxxxx Input parameters (set in the constructor) xxxxxxxxxxxxxxxxx NSymbs = current_parameters['NSymbs'] modulator = current_parameters['modulator'] M = modulator.M SNR = current_parameters["SNR"] # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx inputData = np.random.randint(0, M, NSymbs) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Modulate input data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx modulatedData = modulator.modulate(inputData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Pass through the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx noiseVar = 1. / dB2Linear(SNR) noise = misc.randn_c(NSymbs) * np.sqrt(noiseVar) receivedData = modulatedData + noise # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate received data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx demodulatedData = 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 * 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, # pylint: disable=R0914,R0915 current_parameters): # xxxxx Input parameters (set in the constructor) xxxxxxxxxxxxxxxxx M = self.modulator.M NSymbs = current_parameters["NSymbs"] K = current_parameters["K"] Nr = current_parameters["Nr"] Nt = current_parameters["Nt"] Ns = current_parameters["Ns"] SNR = current_parameters["SNR"] # Dependent parameters noise_var = 1 / dB2Linear(SNR) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calc. precoders and receive filters for IA xxxxxxxxxxxxxxxx # We need to perform IA before generating any data so that we know # how many streams we need to send (and thus generate data. Note # that it is not always equal to Ns. It can be lower for some user # if the IA algorithm chooses a precoder that sends zero energy in # some stream. self.multiUserChannel.randomize(Nr, Nt, K) self.multiUserChannel.noise_var = noise_var self.ia_solver.clear() self.ia_solver.solve(Ns) # If any of the Nr, Nt or Ns variables were integers (meaning all # users have the same value) we will convert them by numpy arrays # with correct size (K). # Nr = self.ia_solver.Nr # Nt = self.ia_solver.Nt Ns = self.ia_solver.Ns cumNs = np.cumsum(self.ia_solver.Ns) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Input Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # inputData has the data of all users (vertically stacked) inputData = np.random.randint(0, M, [np.sum(Ns), NSymbs]) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Modulate input data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # modulatedData has the data of all users (vertically stacked) modulatedData = self.modulator.modulate(inputData) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Perform the Interference Alignment xxxxxxxxxxxxxxxxxxx # Split the data. transmit_signal will be a list and each element # is a numpy array with the data of a user transmit_signal = np.split(modulatedData, cumNs[:-1]) transmit_signal_precoded = map( np.dot, self.ia_solver.full_F, transmit_signal) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Pass through the channel xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # noinspection PyProtectedMember multi_user_channel = self.ia_solver._multiUserChannel # received_data is an array of matrices, one matrix for each receiver. received_data = multi_user_channel.corrupt_data( transmit_signal_precoded) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Perform the Interference Cancellation xxxxxxxxxxxxxxxxxxxxx received_data_no_interference = map( np.dot, self.ia_solver.full_W_H, received_data) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx received_data_no_interference = np.vstack( received_data_no_interference) demodulated_data = self.modulator.demodulate( received_data_no_interference) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calculates the symbol and bit error rates xxxxxxxxxxxxxxxxx symbolErrors = np.sum(inputData != demodulated_data) bitErrors = misc.count_bit_errors(inputData, demodulated_data) numSymbols = inputData.size numBits = inputData.size * fundamental.level2bits(M) ia_cost = self.ia_solver.get_cost() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Calculates the Sum Capacity xxxxxxxxxxxxxxxxxxxxxxxxxx sirn_all_k = self.ia_solver.calc_SINR() calc_capacity = lambda sirn: np.sum(np.log2(1 + sirn)) # Array with the sum capacity of each user sum_capacity = np.array(list(map(calc_capacity, sirn_all_k))) # Total sum capacity total_sum_capacity = np.sum(sum_capacity) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxx Number of iterations of the IA algorithm xxxxxxxxxxxxx ia_runned_iterations = self.ia_solver.runned_iterations # 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, accumulate_values=False) serResult = Result.create("ser", Result.RATIOTYPE, symbolErrors, numSymbols, accumulate_values=False) ia_costResult = Result.create( "ia_cost", Result.RATIOTYPE, ia_cost, 1, accumulate_values=False) sum_capacityResult = Result.create( "sum_capacity", Result.RATIOTYPE, total_sum_capacity, 1, accumulate_values=False) ia_runned_iterationsResult = Result.create( "ia_runned_iterations", Result.RATIOTYPE, ia_runned_iterations, 1, accumulate_values=False) 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) simResults.add_result(ia_costResult) simResults.add_result(sum_capacityResult) simResults.add_result(ia_runned_iterationsResult) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx return simResults
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
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx received_data_no_interference = np.vstack( received_data_no_interference) # received_data_no_interference = np.vstack(received_data_no_interference2) demodulated_data = modulator.demodulate(received_data_no_interference) # demodulated_data = map(modulator.demodulate, received_data_no_interference) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calculates the symbol and bit error rates xxxxxxxxxxxxxxxxx symbolErrors = symbolErrors + np.sum(inputData != demodulated_data) bitErrors = bitErrors + misc.count_bit_errors(inputData, demodulated_data) numSymbols = numSymbols + inputData.size numBits = numBits + inputData.size * fundamental.level2bits(M) #ia_cost = ia_solver.get_cost() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx print() print(bitErrors) print(numBits) BER = bitErrors / numBits print("BER: {0}".format(BER)) SINRs = multi_user_channel.calc_SINR(ia_solver.F, ia_solver.W) sum_capacity = np.sum(np.log2(1 + np.hstack(SINRs))) print("Sum Capacity: {0}".format(sum_capacity)) # # SINR_0 = ia_solver._calc_SINR_k(0)
received_data_no_interference = map(np.dot, ia_solver.W_H, received_data) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Demodulate Data xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx received_data_no_interference = np.vstack(received_data_no_interference) # received_data_no_interference = np.vstack(received_data_no_interference2) demodulated_data = modulator.demodulate(received_data_no_interference) # demodulated_data = map(modulator.demodulate, received_data_no_interference) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # xxxxx Calculates the symbol and bit error rates xxxxxxxxxxxxxxxxx symbolErrors = symbolErrors + np.sum(inputData != demodulated_data) bitErrors = bitErrors + misc.count_bit_errors(inputData, demodulated_data) numSymbols = numSymbols + inputData.size numBits = numBits + inputData.size * fundamental.level2bits(M) #ia_cost = ia_solver.get_cost() # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx print() print(bitErrors) print(numBits) BER = bitErrors / numBits print("BER: {0}".format(BER)) SINRs = multi_user_channel.calc_SINR(ia_solver.F, ia_solver.W) sum_capacity = np.sum(np.log2(1+np.hstack(SINRs))) print("Sum Capacity: {0}".format(sum_capacity))
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 _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