Esempio n. 1
0
 def setUp(self):
     """Called before each test."""
     self.mrc_object = MRC()
Esempio n. 2
0
class MRCTestCase(unittest.TestCase):
    def setUp(self):
        """Called before each test."""
        self.mrc_object = MRC()

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

        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # Test with an identity channel
        channel = np.eye(num_streams)
        self.mrc_object.set_channel_matrix(channel)
        encoded_data = self.mrc_object.encode(data)
        decoded_data1 = self.mrc_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.mrc_object.set_noise_var(None)  # This should use the ZF filter
        channel = randn_c(4, num_streams)  # 4 receive antennas
        self.mrc_object.set_channel_matrix(channel)
        received_data2 = np.dot(channel, encoded_data)
        decoded_data2 = self.mrc_object.decode(received_data2)
        np.testing.assert_array_almost_equal(decoded_data2, data)

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

        # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        # test with a single stream
        self.mrc_object.set_noise_var(None)  # This should use the ZF filter
        channel = randn_c(4)  # 4 receive antennas
        self.mrc_object.set_channel_matrix(channel)
        encoded_data2 = self.mrc_object.encode(data)
        received_data4 = np.dot(channel[:,np.newaxis], encoded_data2)
        decoded_data4 = self.mrc_object.decode(received_data4)
        np.testing.assert_array_almost_equal(decoded_data4, data)

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

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