def _test_drawwf(): import os print("Inicio") vtChannels = np.array([9.32904521e-13, 2.63321084e-13, 5.06505202e-14]) noiseVar = 2.5119e-14 Pt = 0.2512 (vtOptP, mu) = waterfilling.doWF(vtChannels, Pt, noiseVar) # print (vtOptP, mu) drawWF(vtChannels, mu, noiseVar) os.system("pdflatex texCode.tex > /dev/null") os.system("rm texCode.log texCode.aux texCode.tex")
def test_doWF(self): """ - `vtChannels`: Numpy array with the channel POWER gains (power of the parallel AWGN channels). - `dPt`: Total available power. - `noiseVar`: Noise variance (power in linear scale) - `Es`: Symbol energy (in linear scale) """ # See the link below this example # http://jungwon.comoj.com/ucsd_ece287b_spr12/lecture_slides/lecture4.pdf # Abs of the parallel channels vtChannels_abs = np.array( [1.90, 1.76, 1.76, 1.35, 1.35, .733, .733, .100]) # Power of the parallel channels channel_power_gains = vtChannels_abs**2 # Total power available to be distributed total_power = 8. noise_var = 0.181 # Calculates the optimum powers and water level (vtOptP, mu) = waterfilling.doWF(channel_power_gains, total_power, noise_var) # The sum of the powers in each channel must be equal to the # total_power self.assertAlmostEqual(np.sum(vtOptP), total_power) # Test the water level expected_mu = 1.29134061296 self.assertAlmostEqual(mu, expected_mu) # test the powers in each channel expected_vtOptP = np.array([ 1.24120211, 1.23290828, 1.23290828, 1.19202648, 1.19202648, 0.95446418, 0.95446418, 0. ]) np.testing.assert_array_almost_equal(vtOptP, expected_vtOptP)
def test_doWF(self): """ - `vtChannels`: Numpy array with the channel POWER gains (power of the parallel AWGN channels). - `dPt`: Total available power. - `noiseVar`: Noise variance (power in linear scale) - `Es`: Symbol energy (in linear scale) """ # See the link below this example # http://jungwon.comoj.com/ucsd_ece287b_spr12/lecture_slides/lecture4.pdf # Abs of the parallel channels vtChannels_abs = np.array([1.90, 1.76, 1.76, 1.35, 1.35, .733, .733, .100]) # Power of the parallel channels channel_power_gains = vtChannels_abs ** 2 # Total power available to be distributed total_power = 8. noise_var = 0.181 # Calculates the optimum powers and water level (vtOptP, mu) = waterfilling.doWF( channel_power_gains, total_power, noise_var) # The sum of the powers in each channel must be equal to the # total_power self.assertAlmostEqual(np.sum(vtOptP), total_power) # Test the water level expected_mu = 1.29134061296 self.assertAlmostEqual(mu, expected_mu) # test the powers in each channel expected_vtOptP = np.array([1.24120211, 1.23290828, 1.23290828, 1.19202648, 1.19202648, 0.95446418, 0.95446418, 0.]) np.testing.assert_array_almost_equal(vtOptP, expected_vtOptP)
(vtOptP, mu) = waterfilling.doWF(vtChannels, Pt, noiseVar) # print (vtOptP, mu) drawWF(vtChannels, mu, noiseVar) os.system("pdflatex texCode.tex > /dev/null") os.system("rm texCode.log texCode.aux texCode.tex") # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if __name__ == '__main__': # pragma: no cover _test_drawwf() if __name__ == '__main__1': # pragma: no cover # vtChannels = np.abs(randn_c(4,1)) vtChannels = np.array([0.49702888, 0.59012981, 0.43485267, 0.6692608]) Power = 4 noise_var = 0.1 Es = 1 (vtOptP, mu) = waterfilling.doWF(vtChannels, Power, noise_var) print("vtOptP") print(vtOptP) print("mu") print(mu) print(sum(vtOptP)) # drawWF(vtChannels, mu, noise_var)
Pt = 0.2512 (vtOptP, mu) = waterfilling.doWF(vtChannels, Pt, noiseVar) # print (vtOptP, mu) drawWF(vtChannels, mu, noiseVar) os.system("pdflatex texCode.tex > /dev/null") os.system("rm texCode.log texCode.aux texCode.tex") # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if __name__ == '__main__': # pragma: no cover _test_drawwf() if __name__ == '__main__1': # pragma: no cover # vtChannels = np.abs(randn_c(4,1)) vtChannels = np.array([0.49702888, 0.59012981, 0.43485267, 0.6692608]) Power = 4 noise_var = 0.1 Es = 1 (vtOptP, mu) = waterfilling.doWF(vtChannels, Power, noise_var) print("vtOptP") print(vtOptP) print("mu") print(mu) print(sum(vtOptP)) # drawWF(vtChannels, mu, noise_var)