Exemplo n.º 1
0
    def test_distorted_iq_data(self):
        """Test if uncertainty can consider correlation.

        SVD projects IQ data onto I-axis, and input different data sets that
        have the same mean and same variance but squeezed along different axis.
        """
        svd_node = SVD()
        svd_node._scales = [1.0]
        svd_node._main_axes = [np.array([1, 0])]
        svd_node._means = [(0.0, 0.0)]

        processor = DataProcessor("memory", [AverageData(axis=1), svd_node])

        dist_i_axis = {
            "memory": [[[-1, 0]], [[-0.5, 0]], [[0.0, 0]], [[0.5, 0]], [[1,
                                                                         0]]]
        }
        dist_q_axis = {
            "memory": [[[0, -1]], [[0, -0.5]], [[0, 0.0]], [[0, 0.5]], [[0,
                                                                         1]]]
        }

        out_i = processor(dist_i_axis)
        self.assertAlmostEqual(out_i[0].nominal_value, 0.0)
        self.assertAlmostEqual(out_i[0].std_dev, 0.31622776601683794)

        out_q = processor(dist_q_axis)
        self.assertAlmostEqual(out_q[0].nominal_value, 0.0)
        self.assertAlmostEqual(out_q[0].std_dev, 0.0)
Exemplo n.º 2
0
    def test_svd_error(self):
        """Test the error formula of the SVD."""

        iq_svd = SVD()
        iq_svd._main_axes = np.array([[1.0, 0.0]])
        iq_svd._scales = [1.0]
        iq_svd._means = [[0.0, 0.0]]

        # Since the axis is along the real part the imaginary error is irrelevant.
        processed, error = iq_svd([[1.0, 0.2]], [[0.2, 0.1]])
        self.assertEqual(processed, np.array([1.0]))
        self.assertEqual(error, np.array([0.2]))

        # Since the axis is along the real part the imaginary error is irrelevant.
        processed, error = iq_svd([[1.0, 0.2]], [[0.2, 0.3]])
        self.assertEqual(processed, np.array([1.0]))
        self.assertEqual(error, np.array([0.2]))

        # Tilt the axis to an angle of 36.9... degrees
        iq_svd._main_axes = np.array([[0.8, 0.6]])
        processed, error = iq_svd([[1.0, 0.0]], [[0.2, 0.3]])
        cos_ = np.cos(np.arctan(0.6 / 0.8))
        sin_ = np.sin(np.arctan(0.6 / 0.8))
        self.assertEqual(processed, np.array([cos_]))
        expected_error = np.sqrt((0.2 * cos_)**2 + (0.3 * sin_)**2)
        self.assertEqual(error, np.array([expected_error]))