Example #1
0
    def _calculateGrayMappingIndexQAM(L):
        """
        Calculates the indexes that should be applied to the
        constellation created by _createConstellation in order to
        correspond to Gray mapping.

        Notice that the square M-QAM constellation is a matrix of dimension
        L x L, where L is the square root of M. Since the constellation was
        generated without taking into account the Gray mapping, then we
        need to reorder the generated constellation and this function
        calculates the indexes that can be applied to the original
        constellation in order to do exactly that.

        As an example, for the 16-QAM modulation the indexes can be
        organized (row order) in the matrix below

        .. aafig::
                  00     01     11     10
               +------+------+------+------+
            00 | 0000 | 0001 | 0011 | 0010 |
            01 | 0100 | 0101 | 0111 | 0110 |
            11 | 1100 | 1101 | 1111 | 1110 |
            10 | 1000 | 1001 | 1011 | 1010 |
               +------+------+------+------+

        This is equivalent to concatenate a Gray mapping for the row with a
        Gray mapping for the column, and the corresponding indexes are
        [0, 1, 3, 2, 4, 5, 7, 6, 12, 13, 15, 14, 8, 9, 11, 10]

        Parameters
        ----------
        L : int
            Square root of the modulation cardinality (must be an integer).

        Returns
        -------
        indexes : np.ndarray
            indexes that should be applied to the constellation created by
            _createConstellation in order to correspond to Gray mapping

        """
        # Row vector with the column variation (second half of the index in
        # binary form)
        column = binary2gray(np.arange(0, L, dtype=int))

        # Column vector with the row variation
        #
        # Column vector with the row variation (first half of the index in
        # binary form)
        row = column.reshape(L, 1)
        columns = np.tile(column, (L, 1))
        rows = np.tile(row, (1, L))
        # Shift the first part by half the number of bits and sum with the
        # second part to form each element in the index matrix
        index_matrix = (rows << (level2bits(L ** 2) // 2)) + columns

        # Return the indexes as a vector (row order, which is the default
        # in numpy)
        return np.reshape(index_matrix, L ** 2)
Example #2
0
 def test_binary2gray(self):
     np.testing.assert_array_equal(conversion.binary2gray(np.arange(0, 8)),
                                   np.array([0, 1, 3, 2, 6, 7, 5, 4]))
Example #3
0
 def test_gray2binary(self):
     vec = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
     np.testing.assert_array_equal(
         conversion.gray2binary(conversion.binary2gray(vec)),
         vec)
Example #4
0
 def test_binary2gray(self):
     np.testing.assert_array_equal(conversion.binary2gray(np.arange(0, 8)),
                                   np.array([0, 1, 3, 2, 6, 7, 5, 4]))