/// <summary>
        /// Backward Walsh-Hadamard transform.
        /// </summary>
        /// <param name="B">Matrix</param>
        /// <returns>Matrix</returns>
        public Complex32[,] Backward(Complex32[,] B)
        {
            int N = B.GetLength(0), M = B.GetLength(1);

            if (!Maths.IsPower(N, 2) || !Maths.IsPower(M, 2))
            {
                throw new Exception("Dimension of the signal must be a power of 2");
            }

            float[,] U = WalshHadamardTransform.Matrix((int)Maths.Log2(N));
            float[,] V = WalshHadamardTransform.Matrix((int)Maths.Log2(M));
            Complex32[,] A;

            if (direction == Direction.Both)
            {
                A = U.Transponate().Dot(B).Dot(V);
                A = normalized ? A.Div(Math.Sqrt(N * M)) : A;
            }
            else if (direction == Direction.Vertical)
            {
                A = U.Transponate().Dot(B);
                A = normalized ? A.Div(Math.Sqrt(N)) : A;
            }
            else
            {
                A = B.Dot(V);
                A = normalized ? A.Div(Math.Sqrt(M)) : A;
            }

            return(A);
        }
        /// <summary>
        /// Forward Walsh-Hadamard transform.
        /// </summary>
        /// <param name="A">Matrix</param>
        /// <returns>Matrix</returns>
        public float[,] Forward(float[,] A)
        {
            int N = A.GetLength(0), M = A.GetLength(1);

            if (!Maths.IsPower(N, 2) || !Maths.IsPower(M, 2))
            {
                throw new Exception("Dimension of the signal must be a power of 2");
            }

            float[,] U = WalshHadamardTransform.Matrix((int)Maths.Log2(N));
            float[,] V = WalshHadamardTransform.Matrix((int)Maths.Log2(M));
            float[,] B;

            if (direction == Direction.Both)
            {
                B = U.Dot(A).Dot(V.Transponate());
                B = normalized ? B.Div(Maths.Sqrt(N * M)) : B;
            }
            else if (direction == Direction.Vertical)
            {
                B = U.Dot(A);
                B = normalized ? B.Div(Maths.Sqrt(N)) : B;
            }
            else
            {
                B = A.Dot(V.Transponate());
                B = normalized ? B.Div(Maths.Sqrt(M)) : B;
            }

            return(B);
        }
        /// <summary>
        /// Implements the construction of the Walsh-Hadamard matrix.
        /// </summary>
        /// <param name="powOf2">Power of 2</param>
        /// <returns>Matrix</returns>
        public static float[,] Matrix(int powOf2)
        {
            int iterations = powOf2 - 1;

            float[,] hadamard = WalshHadamardTransform.Matrix();

            if (iterations > 0)
            {
                float[,] H = WalshHadamardTransform.Matrix();

                for (int i = 0; i < iterations; i++)
                {
                    H = Matrice.Kronecker(H, hadamard);
                }
                return(H);
            }

            return(hadamard);
        }
        /// <summary>
        /// Backward Walsh-Hadamard transform.
        /// </summary>
        /// <param name="B">Array</param>
        /// <returns>Array</returns>
        public Complex32[] Backward(Complex32[] B)
        {
            int N = B.Length;

            if (!Maths.IsPower(N, 2))
            {
                throw new Exception("Dimension of the signal must be a power of 2");
            }

            int n = (int)Maths.Log2(N);

            float[,] U = WalshHadamardTransform.Matrix(n);
            Complex32[] A = Matrice.Dot(B, U.Transponate());

            if (normalized)
            {
                A = Matrice.Div(A, Math.Sqrt(N));
            }

            return(A);
        }
        /// <summary>
        /// Forward Walsh-Hadamard transform.
        /// </summary>
        /// <param name="A">Array</param>
        /// <returns>Array</returns>
        public Complex32[] Forward(Complex32[] A)
        {
            int N = A.Length;

            if (!Maths.IsPower(N, 2))
            {
                throw new Exception("Dimension of the signal must be a power of 2");
            }

            int n = (int)Maths.Log2(N);

            float[,] U = WalshHadamardTransform.Matrix(n);
            Complex32[] B = Matrice.Dot(A, U);

            if (normalized)
            {
                B = Matrice.Div(B, Math.Sqrt(N));
            }

            return(B);
        }