public void Radix2ThrowsWhenNotPowerOfTwo()
        {
            var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x7F);

            var dft = new DiscreteFourierTransform();

            Assert.Throws(typeof(ArgumentException), () => dft.Radix2Forward(samples, FourierOptions.Default));
            Assert.Throws(typeof(ArgumentException), () => dft.Radix2Inverse(samples, FourierOptions.Default));
            Assert.Throws(typeof(ArgumentException), () => DiscreteFourierTransform.Radix2(samples, -1));
            Assert.Throws(typeof(ArgumentException), () => DiscreteFourierTransform.Radix2Parallel(samples, -1));
        }
Beispiel #2
0
        public void FourierRadix2IsReversible(FourierOptions options)
        {
            var dft = new DiscreteFourierTransform();

            var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x8000);
            var work    = new Complex[samples.Length];

            samples.CopyTo(work, 0);

            dft.Radix2Forward(work, options);
            Assert.IsFalse(work.ListAlmostEqual(samples, 6));

            dft.Radix2Inverse(work, options);
            AssertHelpers.ListAlmostEqual(samples, work, 12);
        }
Beispiel #3
0
        public void FourierRadix2MatchesNaiveOnRealSine(FourierOptions options)
        {
            var dft     = new DiscreteFourierTransform();
            var samples = SignalGenerator.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 16);

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveForward(s, options),
                s => dft.Radix2Forward(s, options));

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveInverse(s, options),
                s => dft.Radix2Inverse(s, options));
        }
Beispiel #4
0
        public void FourierRadix2MatchesNaiveOnRandom(FourierOptions options)
        {
            var dft     = new DiscreteFourierTransform();
            var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, 0x80);

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveForward(s, options),
                s => dft.Radix2Forward(s, options));

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveInverse(s, options),
                s => dft.Radix2Inverse(s, options));
        }
        public void FourierRadix2MatchesNaiveOnRealSine([Values(FourierOptions.Default, FourierOptions.Matlab, FourierOptions.NumericalRecipes)] FourierOptions options)
        {
            var dft = new DiscreteFourierTransform();
            var samples = SignalGenerator.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 16);

            VerifyMatchesNaiveComplex(
                samples, 
                1e-12, 
                s => dft.NaiveForward(s, options), 
                s => dft.Radix2Forward(s, options));

            VerifyMatchesNaiveComplex(
                samples, 
                1e-12, 
                s => dft.NaiveInverse(s, options), 
                s => dft.Radix2Inverse(s, options));
        }
Beispiel #6
0
        public void FourierRadix2IsReversible(FourierOptions options)
        {
            var dft = new DiscreteFourierTransform();

            VerifyIsReversibleComplex(
                0x8000,
                1e-12,
                s =>
            {
                dft.Radix2Forward(s, options);
                return(s);
            },
                s =>
            {
                dft.Radix2Inverse(s, options);
                return(s);
            });
        }
Beispiel #7
0
        public void Radix2ThrowsWhenNotPowerOfTwo()
        {
            var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x7F);

            var dft = new DiscreteFourierTransform();

            Assert.Throws(
                typeof (ArgumentException),
                () => dft.Radix2Forward(samples, FourierOptions.Default));

            Assert.Throws(
                typeof (ArgumentException),
                () => dft.Radix2Inverse(samples, FourierOptions.Default));

            Assert.Throws(
                typeof (ArgumentException),
                () => DiscreteFourierTransform.Radix2(samples, -1));
            Assert.Throws(
                typeof (ArgumentException),
                () => DiscreteFourierTransform.Radix2Parallel(samples, -1));
        }
        public void FourierRadix2IsReversible([Values(FourierOptions.Default, FourierOptions.Matlab)] FourierOptions options)
        {
            var dft = new DiscreteFourierTransform();

            VerifyIsReversibleComplex(
                0x8000, 
                1e-12, 
                s =>
                {
                    dft.Radix2Forward(s, options);
                    return s;
                }, 
                s =>
                {
                    dft.Radix2Inverse(s, options);
                    return s;
                });
        }
        public void FourierRadix2MatchesNaiveOnRandom(FourierOptions options)
        {
            var dft = new DiscreteFourierTransform();
            var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x80);

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveForward(s, options),
                s => dft.Radix2Forward(s, options));

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveInverse(s, options),
                s => dft.Radix2Inverse(s, options));
        }
        public void FourierRadix2MatchesNaiveOnRealSine(FourierOptions options)
        {
            var dft = new DiscreteFourierTransform();
            var samples = Sample.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 16);

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveForward(s, options),
                s => dft.Radix2Forward(s, options));

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveInverse(s, options),
                s => dft.Radix2Inverse(s, options));
        }
        public void FourierRadix2MatchesNaiveOnRandom([Values(FourierOptions.Default, FourierOptions.Matlab, FourierOptions.NumericalRecipes)] FourierOptions options)
        {
            var dft = new DiscreteFourierTransform();
            var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, 0x80);

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveForward(s, options),
                s => dft.Radix2Forward(s, options));

            VerifyMatchesNaiveComplex(
                samples,
                1e-12,
                s => dft.NaiveInverse(s, options),
                s => dft.Radix2Inverse(s, options));
        }