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); }
/// <summary> /// Verify matches naive complex. /// </summary> static void VerifyMatchesNaiveComplex( Complex[] samples, int maximumErrorDecimalPlaces, Func <Complex[], Complex[]> naive, Action <Complex[]> fast) { var spectrumNaive = naive(samples); var spectrumFast = new Complex[samples.Length]; samples.CopyTo(spectrumFast, 0); fast(spectrumFast); AssertHelpers.ListAlmostEqual(spectrumNaive, spectrumFast, maximumErrorDecimalPlaces); }
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); }
/// <summary> /// Verify if matches DFT. /// </summary> static void VerifyMatchesDft( double[] samples, int maximumErrorDecimalPlaces, bool inverse, Action <Complex[]> dft, Func <double[], double[]> hartley) { var hartleyReal = hartley(samples); var fourierComplex = ArrayHelpers.ConvertAll(samples, s => new Complex(s, inverse ? -s : s)); dft(fourierComplex); var fourierReal = ArrayHelpers.ConvertAll(fourierComplex, s => s.Real); AssertHelpers.ListAlmostEqual(fourierReal, hartleyReal, maximumErrorDecimalPlaces); }
public void FourierDefaultTransformIsReversible() { var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x7FFF); var work = new Complex[samples.Length]; samples.CopyTo(work, 0); Transform.FourierForward(work); Assert.IsFalse(work.ListAlmostEqual(samples, 6)); Transform.FourierInverse(work); AssertHelpers.ListAlmostEqual(samples, work, 10); Transform.FourierInverse(work, FourierOptions.Default); Assert.IsFalse(work.ListAlmostEqual(samples, 6)); Transform.FourierForward(work, FourierOptions.Default); AssertHelpers.ListAlmostEqual(samples, work, 10); }