File indexing completed on 2024-05-05 16:00:21

0001 /***************************************************************************
0002     File                 : NSLSFWindowTest.cpp
0003     Project              : LabPlot
0004     Description          : NSL Tests for special window functions
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2019 Stefan Gerlach (stefan.gerlach@uni.kn)
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *  This program is free software; you can redistribute it and/or modify   *
0012  *  it under the terms of the GNU General Public License as published by   *
0013  *  the Free Software Foundation; either version 2 of the License, or      *
0014  *  (at your option) any later version.                                    *
0015  *                                                                         *
0016  *  This program is distributed in the hope that it will be useful,        *
0017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0019  *  GNU General Public License for more details.                           *
0020  *                                                                         *
0021  *   You should have received a copy of the GNU General Public License     *
0022  *   along with this program; if not, write to the Free Software           *
0023  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0024  *   Boston, MA  02110-1301  USA                                           *
0025  *                                                                         *
0026  ***************************************************************************/
0027 
0028 #include "NSLSFWindowTest.h"
0029 
0030 extern "C" {
0031 #include "backend/nsl/nsl_sf_window.h"
0032 }
0033 
0034 //##############################################################################
0035 //#################  window types
0036 //##############################################################################
0037 
0038 void NSLSFWindowTest::testWindowTypes() {
0039     const int N = 10;
0040     double data[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
0041     double result[][N] = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
0042         {0.1, 0.3, 0.5, 0.7, 0.9, 0.9, 0.7, 0.5, 0.3, 0.1},
0043         {0, 2/9., 4/9., 6/9., 8/9., 8/9., 6/9., 4/9., 2/9., 0},
0044         {2/11., 4/11., 6/11., 8/11., 10/11., 10/11., 8/11., 6/11., 4/11., 2/11.},
0045         {0.330578512396694, 0.59504132231405, 0.793388429752066, 0.925619834710744, 0.991735537190083, 0.991735537190083, 0.925619834710744, 0.793388429752066, 0.59504132231405, 0.330578512396694},
0046         {0, 0.116977778440511, 0.413175911166535, 0.75, 0.969846310392954, 0.969846310392954, 0.75, 0.413175911166535, 0.116977778440511, 0},
0047         {0.08, 0.18761955616527, 0.460121838273212, 0.77, 0.972258605561518, 0.972258605561518, 0.77, 0.460121838273212, 0.18761955616527, 0.08},
0048         {0, 0.0508696326538654, 0.258000501503662, 0.63, 0.951129865842472, 0.951129865842472, 0.63, 0.258000501503662, 0.0508696326538655, 0},
0049         {0, 0.0137486265628393, 0.141900826716656, 0.514746, 0.930560546720505, 0.930560546720505, 0.514746, 0.141900826716656, 0.0137486265628393, 0},
0050         {0.0003628, 0.01789099867138, 0.15559612641629, 0.5292298, 0.933220224912329, 0.93322022491233, 0.5292298, 0.155596126416291, 0.0178909986713801, 0.0003628},
0051         {6.e-05, 0.0150711734102182, 0.147039557862381, 0.520575, 0.9316592687274, 0.931659268727401, 0.520575, 0.147039557862382, 0.0150711734102182, 6.e-05},
0052         {0, -0.0867710194112928, -0.331895219303666, 0.918, 4.00066623871496, 4.00066623871496, 0.918, -0.331895219303665, -0.0867710194112926, 0},
0053         {0, 0.342020143325669, 0.642787609686539, 0.866025403784439, 0.984807753012208, 0.984807753012208, 0.866025403784439, 0.642787609686539, 0.342020143325669, 0},
0054         {0, 0.142236444948122, 0.420680359153233, 0.73, 0.950416529231978, 0.950416529231979, 0.73, 0.420680359153233, 0.142236444948122, 0},
0055         {0, 0.263064408273866, 0.564253278793615, 0.826993343132688, 0.979815536051017, 0.979815536051017, 0.826993343132688, 0.564253278793615, 0.263064408273866, 0}};
0056 
0057     for (int t = (int)nsl_sf_window_uniform; t <= (int)nsl_sf_window_lanczos; t++) {
0058         nsl_sf_apply_window(data, N, (nsl_sf_window_type)t);
0059         for (int i = 0; i < N; i++)
0060             QCOMPARE(data[i] + 1., result[t][i] + 1.);
0061     }
0062 }
0063 
0064 //##############################################################################
0065 //#################  performance
0066 //##############################################################################
0067 
0068 void NSLSFWindowTest::testPerformance_triangle() {
0069     const int N = 1e6;
0070     double* data = new double[N];
0071 
0072     QBENCHMARK {
0073         nsl_sf_apply_window(data, N, nsl_sf_window_triangle);
0074     }
0075     delete [] data;
0076 }
0077 
0078 void NSLSFWindowTest::testPerformance_welch() {
0079     const int N = 1e6;
0080     double* data = new double[N];
0081 
0082     QBENCHMARK {
0083         nsl_sf_apply_window(data, N, nsl_sf_window_welch);
0084     }
0085     delete [] data;
0086 }
0087 
0088 void NSLSFWindowTest::testPerformance_flat_top() {
0089     const int N = 1e6;
0090     double* data = new double[N];
0091 
0092     QBENCHMARK {
0093         nsl_sf_apply_window(data, N, nsl_sf_window_flat_top);
0094     }
0095     delete [] data;
0096 }
0097 
0098 QTEST_MAIN(NSLSFWindowTest)