private bool CompareFFTroundTrip(double[] x) { int N = x.Length; var xC = WWComplex.FromRealArray(x); var fft = new WWRadix2Fft(N); var X = fft.ForwardFft(xC); var xR = fft.InverseFft(X); return(WWComplex.AverageDistance(xC, xR) < 1e-8); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion private bool CompareFFT(double[] x) { int N = x.Length; var xC = WWComplex.FromRealArray(x); var Xexpected = WWDftCpu.Dft1d(xC); var fft = new WWRadix2Fft(N); var Xactual = fft.ForwardFft(xC, 1.0 / N); return(WWComplex.AverageDistance(Xactual, Xexpected) < 1e-8); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion public bool TestSDFT(double[] x) { WWComplex[] Xexpected = null; WWDftCpu.Dft1d(WWComplex.FromRealArray(x), out Xexpected); var sdft = new WWSlidingDFT(x.Length); WWComplex[] Xactual = null; for (int i = 0; i < x.Length; ++i) { Xactual = sdft.Filter(x[i]); } return(WWComplex.AverageDistance(Xexpected, Xactual) < 1e-8); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion private bool CompareDft(double[] x) { int N = 4; var Xexpected = WWDftCpu.Dft1d(WWComplex.FromRealArray(x), 1.0); var Xactual = new WWComplex[N]; for (int m = 0; m < N; ++m) { var g = new WWGoertzel(m, N); for (int i = 0; i < N; ++i) { Xactual[m] = g.Filter(x[i]); } } return(WWComplex.AverageDistance(Xexpected, Xactual) < 1e-8); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion bool Compare(WWComplex[] a, WWComplex[] b) { if (a == null || b == null) { return(false); } if (a.Length != b.Length) { return(false); } var d = WWComplex.AverageDistance(a, b); if (1.0e-8 < d) { return(false); } return(true); }
public bool TestSDFT_LastN(double[] x, int N) { System.Diagnostics.Debug.Assert(N <= x.Length); var xLastN = new double[N]; Array.Copy(x, x.Length - N, xLastN, 0, N); WWComplex[] Xexpected = null; WWDftCpu.Dft1d(WWComplex.FromRealArray(xLastN), out Xexpected); var sdft = new WWSlidingDFT(N); WWComplex[] Xactual = null; for (int i = 0; i < x.Length; ++i) { Xactual = sdft.Filter(x[i]); } return(WWComplex.AverageDistance(Xexpected, Xactual) < 1e-8); }