Exemplo n.º 1
0
        public static bool DCTUnitTest()
        {
            int    precisionDigits = 10;
            var    tolerance       = new RealNumber(32 - 64 * precisionDigits, IntegerNumber.One, precisionDigits);
            Random random          = new Random(1001);
            int    n     = 3 * 5 * 7 * 2 * 2;
            var    dcti1 = new RealNumber[n];
            var    dcti2 = new RealNumber[n];
            var    dcti3 = new RealNumber[n];

            for (int i = n; --i >= 0;)
            {
                dcti1[i] = dcti2[i] = dcti3[i] = new RealNumber(random.NextDouble() * 256 - 128, precisionDigits);
            }
            dcti2.EvenDCTType2();
            SlowDCT2(dcti3);
            var maximumError1 = dcti2.GetMaximumError(dcti3) * new RealNumber(n, precisionDigits).GetInverseSqrt();

            dcti2.EvenDCTType3();
            RealNumber scale = new RealNumber(n, precisionDigits).Inverse();

            for (int i = n; --i >= 0;)
            {
                dcti2[i] *= scale;
            }
            var maximumError2 = dcti1.GetMaximumError(dcti2);

            return(maximumError1 < tolerance && maximumError2 < tolerance);
        }