Esempio n. 1
0
    def test_getNumberOfLayers(self):
        channel = np.eye(3)
        self.blast_object.set_channel_matrix(channel)

        self.assertEqual(self.blast_object.getNumberOfLayers(), 3)

        channel2 = np.eye(5)
        blast2 = Blast(channel2)
        self.assertEqual(blast2.getNumberOfLayers(), 5)
Esempio n. 2
0
 def setUp(self):
     """Called before each test."""
     self.blast_object = Blast()
Esempio n. 3
0
class BlastTestCase(unittest.TestCase):
    """Unittests for the Blast class in the mimo module.
    """
    def setUp(self):
        """Called before each test."""
        self.blast_object = Blast()

    def test_set_channel_matrix(self):
        # Test if a warning is raised when the number of transmit antennas
        # is greater then the number of receive antennas
        #
        # For that we capture the warnings ...
        with warnings.catch_warnings(record=True) as w:
            # then we call the set_channel_matrix method
            self.blast_object.set_channel_matrix(np.random.randn(3, 4))
            # and we test if captured 1 warning.
            self.assertEqual(len(w), 1, msg='Warning was not raised')

    def test_getNumberOfLayers(self):
        channel = np.eye(3)
        self.blast_object.set_channel_matrix(channel)

        self.assertEqual(self.blast_object.getNumberOfLayers(), 3)

        channel2 = np.eye(5)
        blast2 = Blast(channel2)
        self.assertEqual(blast2.getNumberOfLayers(), 5)

    def test_encode(self):
        channel = np.eye(3)
        # Set the channel so that the getNumberOfLayers method works
        self.blast_object.set_channel_matrix(channel)

        # Test if an exception is raised when the number of input symbols
        # is not multiple of the number of transmit antennas
        data = np.r_[0:14]
        with self.assertRaises(ValueError):
            self.blast_object.encode(data)

        # Test if the data is encoded correctly
        data = np.r_[0:15]
        expected_encoded_data = data.reshape(3, 5, order='F') / np.sqrt(3)
        np.testing.assert_array_almost_equal(
            self.blast_object.encode(data),
            expected_encoded_data)

    def test_set_noise_var(self):
        self.blast_object.set_noise_var(0.001)
        self.assertAlmostEqual(self.blast_object._noise_var, 0.001)

        self.blast_object.set_noise_var(None)
        self.assertAlmostEqual(self.blast_object._noise_var, 0.0)

        with self.assertRaises(ValueError):
            self.blast_object.set_noise_var(-0.001)

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

        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # Test with an identity channel
        channel = np.eye(3)
        self.blast_object.set_channel_matrix(channel)
        encoded_data = self.blast_object.encode(data)
        decoded_data1 = self.blast_object.decode(encoded_data)
        np.testing.assert_array_almost_equal(decoded_data1, data)

        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # Test with a random channel and a zero-force filter
        self.blast_object.set_noise_var(None)  # This should use the ZF filter
        channel = randn_c(4, 3)  # 3 transmitt antennas and 4 receive antennas
        self.blast_object.set_channel_matrix(channel)
        received_data2 = np.dot(channel, encoded_data)
        decoded_data2 = self.blast_object.decode(received_data2)
        np.testing.assert_array_almost_equal(decoded_data2, data)

        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # Test with a random channel and a MMSE filter
        self.blast_object.set_noise_var(0.00000001)
        channel = randn_c(4, 3)  # 3 transmitt antennas and 4 receive antennas
        self.blast_object.set_channel_matrix(channel)
        received_data3 = np.dot(channel, encoded_data)
        decoded_data3 = self.blast_object.decode(received_data3)
        np.testing.assert_array_almost_equal(decoded_data3.round(7), data)

    def test_calc_post_processing_SINRs(self):
        Nr = 4
        Nt = 3
        noise_var = 0.001
        channel = randn_c(Nr, Nt)
        self.blast_object.set_noise_var(noise_var)
        self.blast_object.set_channel_matrix(channel)

        W = self.blast_object._calc_precoder(channel)
        G_H = self.blast_object._calc_receive_filter(channel, noise_var)
        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.blast_object.calc_linear_SINRs(noise_var)
        np.testing.assert_array_almost_equal(sinrs_other, expected_sinrs, 2)