Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
        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);
        }
        /// <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;
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
        /// <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;
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
        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));
        }
Ejemplo n.º 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;
            }
        }
        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));
        }
        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);
        }
 /// <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;
 }
        public void HartleyNaiveIsReversible(HartleyOptions options)
        {
            var dht = new DiscreteHartleyTransform();

            VerifyIsReversibleReal(
                0x80,
                1e-9,
                s => dht.NaiveForward(s, options),
                s => dht.NaiveInverse(s, options));
        }
 /// <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;
 }