def setUp(self): """Called before each test.""" self.alamouti_object = Alamouti()
class AlamoutiTestCase(unittest.TestCase): """Unittests for the Alamouti class in the mimo module. """ def setUp(self): """Called before each test.""" self.alamouti_object = Alamouti() def test_getNumberOfLayers(self): # The number of layers in the Alamouti scheme is always equal to # one. self.assertEqual(self.alamouti_object.getNumberOfLayers(), 1) def test_set_channel_matrix(self): self.alamouti_object.set_channel_matrix(randn_c(2)) self.assertEqual(self.alamouti_object.Nt, 2) self.assertEqual(self.alamouti_object.Nr, 1) self.alamouti_object.set_channel_matrix(randn_c(4, 2)) self.assertEqual(self.alamouti_object.Nt, 2) self.assertEqual(self.alamouti_object.Nr, 4) with self.assertRaises(ValueError): self.alamouti_object.set_channel_matrix(randn_c(4, 3)) def test_encode(self): data = np.r_[0:16] + np.r_[0:16] * 1j expected_encoded_data = np.array( [[0 + 0j, -1 + 1j, 2 + 2j, -3 + 3j, 4 + 4j, -5 + 5j, 6 + 6j, -7 + 7j, 8 + 8j, -9 + 9j, 10 + 10j, -11 + 11j, 12 + 12j, -13 + 13j, 14 + 14j, -15 + 15j], [1 + 1j, 0 - 0j, 3 + 3j, 2 - 2j, 5 + 5j, 4 - 4j, 7 + 7j, 6 - 6j, 9 + 9j, 8 - 8j, 11 + 11j, 10 - 10j, 13 + 13j, 12 - 12j, 15 + 15j, 14 - 14j]] ) / np.sqrt(2) np.testing.assert_array_almost_equal( self.alamouti_object.encode(data), expected_encoded_data) def test_decode(self): data = np.r_[0:16] + np.r_[0:16] * 1j encoded_data = self.alamouti_object.encode(data) # We will test the deconding with a random channel channel = randn_c(3, 2) self.alamouti_object.set_channel_matrix(channel) received_data = np.dot(channel, encoded_data) decoded_data = self.alamouti_object.decode(received_data) np.testing.assert_array_almost_equal(decoded_data, data) def test_calc_post_processing_SINRs(self): Nr = 1 Nt = 2 noise_var = 0.01 channel = randn_c(Nr, Nt) self.alamouti_object.set_channel_matrix(channel) # W = self.alamouti_object._calc_precoder(channel) # G_H = self.alamouti_object._calc_receive_filter(channel, noise_var) expected_sinrs = linear2dB( (np.linalg.norm(channel, 'fro')**2)/noise_var) # Calculate the SINR using method in the Alamouti class. Note that # we only need to pass the noise variance, since the mimo object # knows the channel. sinrs = self.alamouti_object.calc_SINRs(noise_var) np.testing.assert_array_almost_equal(sinrs, expected_sinrs, 2)