示例#1
0
    def test_init(self):
        channel1 = randn_c(3)
        mrt_object1 = MRT(channel1)
        self.assertEqual(3, mrt_object1.Nt)
        self.assertEqual(1, mrt_object1.Nr)

        channel2 = randn_c(1, 3)
        mrt_object2 = MRT(channel2)
        self.assertEqual(3, mrt_object2.Nt)
        self.assertEqual(1, mrt_object2.Nr)

        channel3 = randn_c(2, 3)
        # Number of receive antennas must be exact 1. Since channel3 has 2
        # receive antennas, an exception should be raised
        with self.assertRaises(ValueError):
            MRT(channel3)
示例#2
0
 def setUp(self):
     """Called before each test."""
     self.mrt_object = MRT()
示例#3
0
class MRTTestCase(unittest.TestCase):
    def setUp(self):
        """Called before each test."""
        self.mrt_object = MRT()

    def test_init(self):
        channel1 = randn_c(3)
        mrt_object1 = MRT(channel1)
        self.assertEqual(3, mrt_object1.Nt)
        self.assertEqual(1, mrt_object1.Nr)

        channel2 = randn_c(1, 3)
        mrt_object2 = MRT(channel2)
        self.assertEqual(3, mrt_object2.Nt)
        self.assertEqual(1, mrt_object2.Nr)

        channel3 = randn_c(2, 3)
        # Number of receive antennas must be exact 1. Since channel3 has 2
        # receive antennas, an exception should be raised
        with self.assertRaises(ValueError):
            MRT(channel3)

    def test_getNumberOfLayers(self):
        self.assertEqual(self.mrt_object.getNumberOfLayers(), 1)

    def test_encode(self):
        data = np.r_[0:15]

        # xxxxxxxxxx test the case with Ntx=2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        Nt = 2
        channel = randn_c(Nt)
        self.mrt_object.set_channel_matrix(channel)

        data_aux = data.reshape(1, data.size)  # Useful for broadcasting
        W = np.exp(-1j * np.angle(channel)).reshape(Nt, 1) / math.sqrt(Nt)
        encoded_data = self.mrt_object.encode(data)

        expected_encoded_data = W * data_aux
        np.testing.assert_array_almost_equal(expected_encoded_data,
                                             encoded_data)
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        # xxxxxxxxxx test the case with Ntx=4 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        Nt = 4
        channel = randn_c(Nt)
        self.mrt_object.set_channel_matrix(channel)

        data_aux = data.reshape(1, data.size)  # Useful for broadcasting
        encoded_data = self.mrt_object.encode(data)
        W = np.exp(-1j * np.angle(channel)).reshape(Nt, 1)

        expected_encoded_data = (1. / math.sqrt(Nt)) * W * data_aux
        np.testing.assert_array_almost_equal(expected_encoded_data,
                                             encoded_data)
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        # xxxxxxxxxx Test the case where the channel is 2D xxxxxxxxxxxxxxxx
        # Note tha in this case even though the channel is a 2D numpy array
        # the size of the first dimension (receive antennas) must be equal
        # to 1.
        Nt = 4
        channel2 = randn_c(1, Nt)
        self.mrt_object.set_channel_matrix(channel2)

        data_aux = data.reshape(1, data.size)  # Useful for broadcasting
        encoded_data = self.mrt_object.encode(data)
        W = np.exp(-1j * np.angle(channel2)).reshape(Nt, 1)

        expected_encoded_data = (1. / math.sqrt(Nt)) * W * data_aux
        np.testing.assert_array_almost_equal(expected_encoded_data,
                                             encoded_data)
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    def test_decode(self):
        Nt = 4

        # xxxxxxxxxx test the case with a single receive antenna xxxxxxxxxx
        channel = randn_c(Nt)
        self.mrt_object.set_channel_matrix(channel)

        data = np.r_[0:15]
        encoded_data = self.mrt_object.encode(data)

        # Add '0.1' as a noise term
        received_data = channel.dot(encoded_data) + 0.0001
        decoded_data = self.mrt_object.decode(received_data)

        self.assertEqual(len(decoded_data.shape), 1)
        np.testing.assert_array_almost_equal(decoded_data, data, decimal=4)

        # Now we are explicitting changing the shape of the channel
        # variable to include the first dimension corresponding to a single
        # receive antenna
        channel.shape = (1, Nt)
        self.mrt_object.set_channel_matrix(channel)
        # The encoded data should be the same
        encoded_data = self.mrt_object.encode(data)

        # Add '0.1' as a noise term
        received_data = channel.dot(encoded_data) + 0.0001
        decoded_data = self.mrt_object.decode(received_data)

        self.assertEqual(len(decoded_data.shape), 1)
        np.testing.assert_array_almost_equal(decoded_data, data, decimal=4)
        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    def test_calc_post_processing_SINRs(self):
        Nr = 1
        Nt = 3
        noise_var = 0.001
        channel = randn_c(Nr, Nt)
        self.mrt_object.set_channel_matrix(channel)

        W = self.mrt_object._calc_precoder(channel)
        G_H = self.mrt_object._calc_receive_filter(channel, noise_var)
        G_H = np.array([[G_H]])
        expected_sinrs = linear2dB(calc_SINRs(channel, W, G_H, noise_var))

        # Calculate the SINR using the function in the mimo module. Note
        # that we need to pass the channel, the precoder, the receive
        # filter and the noise variance.
        sinrs = calc_post_processing_SINRs(channel, W, G_H, noise_var)
        np.testing.assert_array_almost_equal(sinrs, expected_sinrs, 2)

        # Calculate the SINR using method in the MIMO class. Note that we
        # only need to pass the noise variance, since the mimo object knows
        # the channel and it can calculate the precoder and receive filter.
        sinrs_other = self.mrt_object.calc_linear_SINRs(noise_var)
        np.testing.assert_array_almost_equal(sinrs_other, expected_sinrs, 2)