コード例 #1
0
        /// <summary>
        /// Naive inverse DHT, useful e.g. to verify faster algorithms.
        /// </summary>
        /// <param name="frequencySpace">Frequency-space sample vector.</param>
        /// <param name="options">Hartley Transform Convention Options.</param>
        /// <returns>Corresponding time-space vector.</returns>
        public double[] NaiveInverse(double[] frequencySpace, HartleyOptions options)
        {
            var timeSpace = Naive(frequencySpace);

            InverseScaleByOptions(options, timeSpace);
            return(timeSpace);
        }
コード例 #2
0
        /// <summary>
        /// Naive forward DHT, useful e.g. to verify faster algorithms.
        /// </summary>
        /// <param name="timeSpace">Time-space sample vector.</param>
        /// <param name="options">Hartley Transform Convention Options.</param>
        /// <returns>Corresponding frequency-space vector.</returns>
        public double[] NaiveForward(double[] timeSpace, HartleyOptions options)
        {
            var frequencySpace = Naive(timeSpace);

            ForwardScaleByOptions(options, frequencySpace);
            return(frequencySpace);
        }
コード例 #3
0
        public void HartleyNaiveIsReversible(HartleyOptions options)
        {
            var dht = new DiscreteHartleyTransform();

            VerifyIsReversibleReal(
                0x80,
                1e-9,
                s => dht.NaiveForward(s, options),
                s => dht.NaiveInverse(s, options));
        }
コード例 #4
0
        public void HartleyNaiveIsReversible([Values(HartleyOptions.Default, HartleyOptions.AsymmetricScaling)] HartleyOptions options)
        {
            var dht = new DiscreteHartleyTransform();

            VerifyIsReversibleReal(
                0x80,
                1e-9,
                s => dht.NaiveForward(s, options),
                s => dht.NaiveInverse(s, options));
        }
コード例 #5
0
        public void HartleyNaiveIsReversible(HartleyOptions options)
        {
            var samples = Generate.Random(0x80, GetUniform(1));
            var work    = new double[samples.Length];

            samples.CopyTo(work, 0);

            work = Hartley.NaiveForward(work, options);
            Assert.IsFalse(work.ListAlmostEqual(samples, 6));

            work = Hartley.NaiveInverse(work, options);
            AssertHelpers.AlmostEqual(samples, work, 12);
        }
コード例 #6
0
        /// <summary>
        /// Rescale FFT-the resulting vector according to the provided convention options.
        /// </summary>
        /// <param name="options">Fourier Transform Convention Options.</param>
        /// <param name="samples">Sample Vector.</param>
        private static void ForwardScaleByOptions(HartleyOptions options, double[] samples)
        {
            if ((options & HartleyOptions.NoScaling) == HartleyOptions.NoScaling ||
                (options & HartleyOptions.AsymmetricScaling) == HartleyOptions.AsymmetricScaling)
            {
                return;
            }

            var scalingFactor = Math.Sqrt(1.0 / samples.Length);
            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] *= scalingFactor;
            }
        }
コード例 #7
0
        /// <summary>
        /// Rescale FFT-the resulting vector according to the provided convention options.
        /// </summary>
        /// <param name="options">Fourier Transform Convention Options.</param>
        /// <param name="samples">Sample Vector.</param>
        private static void ForwardScaleByOptions(HartleyOptions options, double[] samples)
        {
            if ((options & HartleyOptions.NoScaling) == HartleyOptions.NoScaling ||
                (options & HartleyOptions.AsymmetricScaling) == HartleyOptions.AsymmetricScaling)
            {
                return;
            }

            var scalingFactor = Math.Sqrt(1.0 / samples.Length);

            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] *= scalingFactor;
            }
        }
コード例 #8
0
        public void HartleyNaiveIsReversible(HartleyOptions options)
        {
            var dht = new DiscreteHartleyTransform();

            var samples = SignalGenerator.Random(x => x, GetUniform(1), 0x80);
            var work    = new double[samples.Length];

            samples.CopyTo(work, 0);

            work = dht.NaiveForward(work, options);
            Assert.IsFalse(work.ListAlmostEqual(samples, 6));

            work = dht.NaiveInverse(work, options);
            AssertHelpers.ListAlmostEqual(samples, work, 12);
        }
コード例 #9
0
        public void NaiveMatchesDft(HartleyOptions hartleyOptions, FourierOptions fourierOptions)
        {
            var samples = Generate.Random(0x80, GetUniform(1));

            VerifyMatchesDft(
                samples,
                5,
                false,
                s => Fourier.Forward(s, fourierOptions),
                s => Hartley.NaiveForward(s, hartleyOptions));
            VerifyMatchesDft(
                samples,
                5,
                true,
                s => Fourier.Inverse(s, fourierOptions),
                s => Hartley.NaiveInverse(s, hartleyOptions));
        }
コード例 #10
0
        public void NaiveMatchesDft(HartleyOptions hartleyOptions, FourierOptions fourierOptions)
        {
            var samples = Generate.Random(0x80, GetUniform(1));

            VerifyMatchesDft(
                samples,
                5,
                false,
                s => Fourier.Forward(s, fourierOptions),
                s => Hartley.NaiveForward(s, hartleyOptions));
            VerifyMatchesDft(
                samples,
                5,
                true,
                s => Fourier.Inverse(s, fourierOptions),
                s => Hartley.NaiveInverse(s, hartleyOptions));
        }
コード例 #11
0
        public void NaiveMatchesDft(HartleyOptions hartleyOptions, FourierOptions fourierOptions)
        {
            var dht = new DiscreteHartleyTransform();
            var samples = SignalGenerator.Random(x => x, GetUniform(1), 0x80);

            VerifyMatchesDft(
                samples,
                1e-5,
                false,
                s => Transform.FourierForward(s, fourierOptions),
                s => dht.NaiveForward(s, hartleyOptions));
            VerifyMatchesDft(
                samples,
                1e-5,
                true,
                s => Transform.FourierInverse(s, fourierOptions),
                s => dht.NaiveInverse(s, hartleyOptions));
        }
コード例 #12
0
        /// <summary>
        /// Rescale the iFFT-resulting vector according to the provided convention options.
        /// </summary>
        /// <param name="options">Fourier Transform Convention Options.</param>
        /// <param name="samples">Sample Vector.</param>
        private static void InverseScaleByOptions(HartleyOptions options, double[] samples)
        {
            if ((options & HartleyOptions.NoScaling) == HartleyOptions.NoScaling)
            {
                return;
            }

            var scalingFactor = 1.0 / samples.Length;
            if ((options & HartleyOptions.AsymmetricScaling) != HartleyOptions.AsymmetricScaling)
            {
                scalingFactor = Math.Sqrt(scalingFactor);
            }

            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] *= scalingFactor;
            }
        }
コード例 #13
0
        public void NaiveMatchesDft(HartleyOptions hartleyOptions, FourierOptions fourierOptions)
        {
            var dht     = new DiscreteHartleyTransform();
            var samples = SignalGenerator.Random(x => x, GetUniform(1), 0x80);

            VerifyMatchesDft(
                samples,
                1e-5,
                false,
                s => Transform.FourierForward(s, fourierOptions),
                s => dht.NaiveForward(s, hartleyOptions));
            VerifyMatchesDft(
                samples,
                1e-5,
                true,
                s => Transform.FourierInverse(s, fourierOptions),
                s => dht.NaiveInverse(s, hartleyOptions));
        }
コード例 #14
0
        public void NaiveMatchesDft([Values(HartleyOptions.Default, HartleyOptions.AsymmetricScaling, HartleyOptions.NoScaling)] HartleyOptions hartleyOptions, [Values(FourierOptions.Default, FourierOptions.AsymmetricScaling, FourierOptions.NoScaling)] FourierOptions fourierOptions)
        {
            var dht     = new DiscreteHartleyTransform();
            var samples = SignalGenerator.Random(x => x, _uniform, 0x80);

            VerifyMatchesDft(
                samples,
                1e-5,
                false,
                s => Transform.FourierForward(s, fourierOptions),
                s => dht.NaiveForward(s, hartleyOptions));
            VerifyMatchesDft(
                samples,
                1e-5,
                true,
                s => Transform.FourierInverse(s, fourierOptions),
                s => dht.NaiveInverse(s, hartleyOptions));
        }
コード例 #15
0
        public void NaiveMatchesDFT(HartleyOptions hartleyOptions, FourierOptions fourierOptions)
        {
            var dht     = new DiscreteHartleyTransform();
            var samples = Sample.Random(x => x, _uniform, 0x80);

            VerifyMatchesDFT(
                samples,
                1e-10,
                false,
                s => Transform.FourierForward(s, fourierOptions),
                s => dht.NaiveForward(s, hartleyOptions));

            VerifyMatchesDFT(
                samples,
                1e-10,
                true,
                s => Transform.FourierInverse(s, fourierOptions),
                s => dht.NaiveInverse(s, hartleyOptions));
        }
コード例 #16
0
        /// <summary>
        /// Rescale the iFFT-resulting vector according to the provided convention options.
        /// </summary>
        /// <param name="options">Fourier Transform Convention Options.</param>
        /// <param name="samples">Sample Vector.</param>
        private static void InverseScaleByOptions(HartleyOptions options, double[] samples)
        {
            if ((options & HartleyOptions.NoScaling) == HartleyOptions.NoScaling)
            {
                return;
            }

            var scalingFactor = 1.0 / samples.Length;

            if ((options & HartleyOptions.AsymmetricScaling) != HartleyOptions.AsymmetricScaling)
            {
                scalingFactor = Math.Sqrt(scalingFactor);
            }

            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] *= scalingFactor;
            }
        }
コード例 #17
0
        public void NaiveMatchesDFT(HartleyOptions hartleyOptions, FourierOptions fourierOptions)
        {
            var dht = new DiscreteHartleyTransform();
            var samples = Sample.Random(x => x, _uniform, 0x80);

            VerifyMatchesDFT(
                samples,
                1e-10,
                false,
                s => Transform.FourierForward(s, fourierOptions),
                s => dht.NaiveForward(s, hartleyOptions));

            VerifyMatchesDFT(
                samples,
                1e-10,
                true,
                s => Transform.FourierInverse(s, fourierOptions),
                s => dht.NaiveInverse(s, hartleyOptions));
        }
コード例 #18
0
        public void HartleyNaiveIsReversible(HartleyOptions options)
        {
            var dht = new DiscreteHartleyTransform();

            var samples = Generate.Random(0x80, GetUniform(1));
            var work = new double[samples.Length];
            samples.CopyTo(work, 0);

            work = dht.NaiveForward(work, options);
            Assert.IsFalse(work.ListAlmostEqual(samples, 6));

            work = dht.NaiveInverse(work, options);
            AssertHelpers.ListAlmostEqual(samples, work, 12);
        }
コード例 #19
0
 /// <summary>
 /// Naive forward DHT, useful e.g. to verify faster algorithms.
 /// </summary>
 /// <param name="timeSpace">Time-space sample vector.</param>
 /// <param name="options">Hartley Transform Convention Options.</param>
 /// <returns>Corresponding frequency-space vector.</returns>
 public double[] NaiveForward(double[] timeSpace, HartleyOptions options)
 {
     var frequencySpace = Naive(timeSpace);
     ForwardScaleByOptions(options, frequencySpace);
     return frequencySpace;
 }
コード例 #20
0
        public void HartleyNaiveIsReversible(HartleyOptions options)
        {
            var dht = new DiscreteHartleyTransform();

            VerifyIsReversibleReal(
                0x80,
                1e-9,
                s => dht.NaiveForward(s, options),
                s => dht.NaiveInverse(s, options));
        }
コード例 #21
0
 /// <summary>
 /// Naive inverse DHT, useful e.g. to verify faster algorithms.
 /// </summary>
 /// <param name="frequencySpace">Frequency-space sample vector.</param>
 /// <param name="options">Hartley Transform Convention Options.</param>
 /// <returns>Corresponding time-space vector.</returns>
 public double[] NaiveInverse(double[] frequencySpace, HartleyOptions options)
 {
     var timeSpace = Naive(frequencySpace);
     InverseScaleByOptions(options, timeSpace);
     return timeSpace;
 }