Esempio n. 1
0
        public void ReferenceDftTransformsRealSineCorrectly64()
        {
            var samples = Generate.PeriodicMap(16, w => new Complex(Math.Sin(w), 0), 16, 1.0, Constants.Pi2);

            // real-odd transforms to imaginary odd
            ReferenceDiscreteFourierTransform.Forward(samples, FourierOptions.Matlab);

            // all real components must be zero
            foreach (var c in samples)
            {
                Assert.AreEqual(0, c.Real, 1e-12, "real");
            }

            // all imaginary components except second and last musth be zero
            for (var i = 0; i < samples.Length; i++)
            {
                if (i == 1)
                {
                    Assert.AreEqual(-8, samples[i].Imaginary, 1e-12, "imag second");
                }
                else if (i == samples.Length - 1)
                {
                    Assert.AreEqual(8, samples[i].Imaginary, 1e-12, "imag last");
                }
                else
                {
                    Assert.AreEqual(0, samples[i].Imaginary, 1e-12, "imag");
                }
            }
        }
        public void ReferenceDftSatisfiesParsevalsTheorem64(int count)
        {
            var samples         = Generate.RandomComplex(count, GetUniform(1));
            var timeSpaceEnergy = (from s in samples select s.MagnitudeSquared()).Mean();

            var spectrum = new Complex[samples.Length];

            samples.CopyTo(spectrum, 0);
            ReferenceDiscreteFourierTransform.Forward(spectrum);
            var frequencySpaceEnergy = (from s in spectrum select s.MagnitudeSquared()).Mean();

            Assert.AreEqual(timeSpaceEnergy, frequencySpaceEnergy, 1e-12);
        }
        public void ReferenceDftIsReversible64(FourierOptions options)
        {
            var samples = Generate.RandomComplex(0x80, GetUniform(1));
            var work    = new Complex[samples.Length];

            samples.CopyTo(work, 0);

            ReferenceDiscreteFourierTransform.Forward(work, options);
            Assert.IsFalse(work.ListAlmostEqual(samples, 6));

            ReferenceDiscreteFourierTransform.Inverse(work, options);
            AssertHelpers.AlmostEqual(samples, work, 12);
        }