def do(self, nb_tx, nb_rx): def check_noise(mod, chan, corrected_SNR_lin): msg = choice(mod, self.msg_length) chan.propagate(msg) P_msg = signal_power(msg) # previous test asserted that channel neither add nor remove energy P_noise = signal_power(chan.noises) assert_allclose(abs(chan.noises.mean()), 0., atol=0.5, err_msg='Noise mean is not 0') if corrected_SNR_lin == inf: assert_allclose(P_noise, 0, atol=1e-2, err_msg='There is noise that should not be here') else: assert_allclose(chan.nb_tx * P_msg / P_noise, corrected_SNR_lin, atol=0.2, err_msg='Wrong SNR') fading_param = zeros((nb_rx, nb_tx), complex), identity(nb_tx), identity(nb_rx) chan = MIMOFlatChannel(nb_tx, nb_rx, fading_param=fading_param) for mod in self.all_mods: chan.noise_std = 0 check_noise(mod, chan, inf) chan.set_SNR_lin(6, Es=signal_power(mod)) check_noise(mod, chan, 6) chan.set_SNR_lin(6, .5, signal_power(mod)) check_noise(mod, chan, 3) chan.set_SNR_dB(0, Es=signal_power(mod)) check_noise(mod, chan, 1) chan.set_SNR_dB(0, .5, signal_power(mod)) check_noise(mod, chan, .5)
def do(self, nb_tx, nb_rx): # Set seed seed(17121996) def check_noise(mod, chan, corrected_SNR_lin): msg = choice(mod, self.msg_length) chan.propagate(msg) P_msg = signal_power(msg) # previous test asserted that channel neither add nor remove energy P_noise = signal_power(chan.noises) assert_allclose(abs(chan.noises.mean()), 0., atol=0.5, err_msg='Noise mean is not 0') if corrected_SNR_lin == inf: assert_allclose(P_noise, 0, atol=1e-2, err_msg='There is noise that should not be here') else: assert_allclose(chan.nb_tx * P_msg / P_noise, corrected_SNR_lin, atol=0.2, err_msg='Wrong SNR') fading_param = zeros((nb_rx, nb_tx), complex), identity(nb_tx), identity(nb_rx) chan = MIMOFlatChannel(nb_tx, nb_rx, fading_param=fading_param) for mod in self.all_mods: chan.noise_std = 0 check_noise(mod, chan, inf) chan.set_SNR_lin(6, Es=signal_power(mod)) check_noise(mod, chan, 6) chan.set_SNR_lin(6, .5, signal_power(mod)) check_noise(mod, chan, 3) chan.set_SNR_dB(0, Es=signal_power(mod)) check_noise(mod, chan, 1) chan.set_SNR_dB(0, .5, signal_power(mod)) check_noise(mod, chan, .5)
def test_noise_generation(self): def check_noise(mod, chan, corrected_SNR_lin): msg = choice(mod, self.msg_length) chan.propagate(msg) P_msg = signal_power(msg) # previous test asserted that channel neither add nor remove energy P_noise = signal_power(chan.noises) assert_allclose(absolute(chan.noises.mean()), 0., atol=5e-2, err_msg='Noise mean is not 0') if corrected_SNR_lin == inf: assert_allclose(P_noise, 0, atol=1e-2, err_msg='There is noise that should not be here') else: assert_allclose(P_msg / P_noise, corrected_SNR_lin, atol=0.2, err_msg='Wrong SNR') chan = SISOFlatChannel(fading_param=(1 + 0j, 0)) for mod in self.all_mods: chan.noise_std = 0 check_noise(mod, chan, inf) chan.set_SNR_lin(6, Es=signal_power(mod)) check_noise(mod, chan, 6) chan.set_SNR_lin(6, .5, signal_power(mod)) check_noise(mod, chan, 3) chan.set_SNR_dB(0, Es=signal_power(mod)) check_noise(mod, chan, 1) chan.set_SNR_dB(0, .5, signal_power(mod)) check_noise(mod, chan, .5)
def check_chan_gain(mod, chan): msg = choice(mod, self.msg_length) chan.propagate(msg) P_msg = signal_power(msg) P_unnoisy = signal_power(chan.unnoisy_output) assert_allclose(P_unnoisy, P_msg, rtol=0.2, err_msg='Channel add or remove energy')
def check_chan_gain(mod, chan): msg = choice(mod, self.msg_length) chan.propagate(msg) P_msg = signal_power(msg) P_unnoisy = signal_power(chan.unnoisy_output) assert_allclose(P_unnoisy, P_msg, rtol=0.2, err_msg='Channel add or remove energy')
def check_noise(mod, chan, corrected_SNR_lin): msg = choice(mod, self.msg_length) chan.propagate(msg) P_msg = signal_power(msg) # previous test asserted that channel neither add nor remove energy P_noise = signal_power(chan.noises) assert_allclose(abs(chan.noises.mean()), 0., atol=0.5, err_msg='Noise mean is not 0') if corrected_SNR_lin == inf: assert_allclose(P_noise, 0, atol=1e-2, err_msg='There is noise that should not be here') else: assert_allclose(chan.nb_tx * P_msg / P_noise, corrected_SNR_lin, atol=0.2, err_msg='Wrong SNR')
def check_noise(mod, chan, corrected_SNR_lin): msg = choice(mod, self.msg_length) chan.propagate(msg) P_msg = signal_power(msg) # previous test asserted that channel neither add nor remove energy P_noise = signal_power(chan.noises) assert_allclose(abs(chan.noises.mean()), 0., atol=0.5, err_msg='Noise mean is not 0') if corrected_SNR_lin == inf: assert_allclose(P_noise, 0, atol=1e-2, err_msg='There is noise that should not be here') else: assert_allclose(chan.nb_tx * P_msg / P_noise, corrected_SNR_lin, atol=0.2, err_msg='Wrong SNR')
def test_noise_generation(self): def check_noise(mod, chan, corrected_SNR_lin): msg = choice(mod, self.msg_length) chan.propagate(msg) P_msg = signal_power( msg ) # previous test asserted that channel neither add nor remove energy P_noise = signal_power(chan.noises) assert_allclose(absolute(chan.noises.mean()), 0., atol=5e-2, err_msg='Noise mean is not 0') if corrected_SNR_lin == inf: assert_allclose( P_noise, 0, atol=1e-2, err_msg='There is noise that should not be here') else: assert_allclose(P_msg / P_noise, corrected_SNR_lin, atol=0.2, err_msg='Wrong SNR') chan = SISOFlatChannel(fading_param=(1 + 0j, 0)) for mod in self.all_mods: chan.noise_std = 0 check_noise(mod, chan, inf) chan.set_SNR_lin(6, Es=signal_power(mod)) check_noise(mod, chan, 6) chan.set_SNR_lin(6, .5, signal_power(mod)) check_noise(mod, chan, 3) chan.set_SNR_dB(0, Es=signal_power(mod)) check_noise(mod, chan, 1) chan.set_SNR_dB(0, .5, signal_power(mod)) check_noise(mod, chan, .5) chan = SISOFlatChannel(fading_param=(1, 0)) for mod in self.real_mods: chan.noise_std = 0 check_noise(mod, chan, inf) chan.set_SNR_lin(6, Es=signal_power(mod)) check_noise(mod, chan, 6) chan.set_SNR_lin(6, .5, signal_power(mod)) check_noise(mod, chan, 3) chan.set_SNR_dB(0, Es=signal_power(mod)) check_noise(mod, chan, 1) chan.set_SNR_dB(0, .5, signal_power(mod)) check_noise(mod, chan, .5)
def constellation(self, value): # Check value input num_bits_symbol = log2(len(value)) if num_bits_symbol != int(num_bits_symbol): raise ValueError('Constellation length must be a power of 2.') # Set constellation as an array self._constellation = array(value) # Update other attributes self.Es = signal_power(self.constellation) self.m = self._constellation.size self.num_bits_symbol = int(num_bits_symbol)
decodedCodes[i] = deCompAlgo[i](sourceCodes[i]) timeStop = perf_counter_ns() timeDe[i] = timeStop - timeStart ''' #Number of Flops papi_high.flops() decodedCodes[i] = deCompAlgo[i](sourceCodes[i]) result = papi_high.flops() flopsDe[i] = result.mflops papi_high.stop_counters() ''' for i in range(0, noOfSources): M = 16 mod = PSKModem(M) sigPower[i] = signal_power(np.array(list(sourceCodes[i]), dtype=int)) print("Normally our code would be of size ", len(sourceCodes[0])) print("") for i in range(0, noOfSources): if decodedCodes[i] != decodedCodes[0]: print('There is an error in', sourceNames[i]) print('Original Code is', decodedCodes[0]) print('Recieved Code is', decodedCodes[i]) print("") print("Using ", sourceNames[i], " The size is ", str(len(sourceCodes[i])) + ":") print("Compression ratio of ", len(sourceCodes[0]) / len(sourceCodes[i])) print("The time taken to compress", timeEn[i]) print("The time taken to decompress", timeDe[i])
def do_qam(self, modem): assert_allclose(signal_power(modem.constellation), 2 * (modem.m - 1) / 3)