Exemplo n.º 1
0
        public void SimpleTransform()
        {
            Complexd[] r1 = Complexd.ToComplexArray(new double[] { 1, 1, 2, 2, 1, 1, 0, 0 });
            Complexd[] r2 = Complexd.ToComplexArray(new double[] { 1, 1, 2, 2, 1, 1, 0, 0 });
            r2 = BruteForce(r2);
            r1 = DFT.Transform(r1, FurierTransformType.Normal);

            for (int i = 0; i < r1.Length; i++)
            {
                Assert.IsTrue(Complexd.NearEqual(r1[i], r2[i]));
            }
        }
Exemplo n.º 2
0
        public void FFTAndInverse()
        {
            double[] x = new double[] { 0, 0.5, 0.84, 1.0, 0.84, 0.5, 0, -0.5, -0.84, -1.0, -0.84, -0.5, 0, 0.5, 0.84, 1 };

            Complexd[] r = DFT.Transform(x, FurierTransformType.Normal);
            DFT.TransformInPlace(r, FurierTransformType.Inverse);

            for (int i = 0; i < x.Length; i++)
            {
                Assert.IsTrue(MathHelper.NearEqual(r[i].Re, x[i], 0.01));
                Assert.IsTrue(MathHelper.NearEqual(r[i].Im, 0.0, 0.01));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Performs convolution of two inputs.
        /// </summary>
        /// <param name="f">The first input.</param>
        /// <param name="g">The second input.</param>
        /// <returns></returns>
        public static Complexf[] Convolution([PowerOfTwoArray] Complexf[] f, [PowerOfTwoArray] Complexf[] g)
        {
            if (f.Length != g.Length)
            {
                throw new ArgumentException("The data must be the same length.");
            }

            Complexf[] t1 = DFT.Transform(f, FurierTransformType.Normal);
            Complexf[] t2 = DFT.Transform(g, FurierTransformType.Normal);

            // We merge inputs.
            for (int i = 0; i < f.Length; i++)
            {
                t1[i] = t1[i] * t2[i];
            }

            // Backtransform.
            DFT.TransformInPlace(t1, FurierTransformType.Inverse);
            return(t1);
        }