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)); } }
/// <summary> /// Performs convolution of two inputs. Result is stored in f. The g is transformed to frequency space. /// </summary> /// <param name="f">The first input.</param> /// <param name="g">The second input.</param> public static void ConvolutionInPlace([PowerOfTwoArray] Complexf[] f, [PowerOfTwoArray] Complexf[] g) { if (f.Length != g.Length) { throw new ArgumentException("The data must be the same lenght."); } DFT.TransformInPlace(f, FurierTransformType.Normal); DFT.TransformInPlace(g, FurierTransformType.Normal); // We merge inputs. for (int i = 0; i < f.Length; i++) { f[i] = g[i] * f[i]; } // Backtransform. DFT.TransformInPlace(f, FurierTransformType.Inverse); }
/// <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); }