File indexing completed on 2024-05-05 07:47:48
0001 /* 0002 File : NSLSFWindowTest.cpp 0003 Project : LabPlot 0004 Description : NSL Tests for special window functions 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2019 Stefan Gerlach <stefan.gerlach@uni.kn> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "NSLSFWindowTest.h" 0012 0013 extern "C" { 0014 #include "backend/nsl/nsl_sf_window.h" 0015 } 0016 0017 // ############################################################################## 0018 // ################# window types 0019 // ############################################################################## 0020 0021 void NSLSFWindowTest::testWindowTypes() { 0022 const int N = 10; 0023 double data[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 0024 double result[][N] = { 0025 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 0026 {0.1, 0.3, 0.5, 0.7, 0.9, 0.9, 0.7, 0.5, 0.3, 0.1}, 0027 {0, 2 / 9., 4 / 9., 6 / 9., 8 / 9., 8 / 9., 6 / 9., 4 / 9., 2 / 9., 0}, 0028 {2 / 11., 4 / 11., 6 / 11., 8 / 11., 10 / 11., 10 / 11., 8 / 11., 6 / 11., 4 / 11., 2 / 11.}, 0029 {0.330578512396694, 0030 0.59504132231405, 0031 0.793388429752066, 0032 0.925619834710744, 0033 0.991735537190083, 0034 0.991735537190083, 0035 0.925619834710744, 0036 0.793388429752066, 0037 0.59504132231405, 0038 0.330578512396694}, 0039 {0, 0.116977778440511, 0.413175911166535, 0.75, 0.969846310392954, 0.969846310392954, 0.75, 0.413175911166535, 0.116977778440511, 0}, 0040 {0.08, 0.18761955616527, 0.460121838273212, 0.77, 0.972258605561518, 0.972258605561518, 0.77, 0.460121838273212, 0.18761955616527, 0.08}, 0041 {0, 0.0508696326538654, 0.258000501503662, 0.63, 0.951129865842472, 0.951129865842472, 0.63, 0.258000501503662, 0.0508696326538655, 0}, 0042 {0, 0.0137486265628393, 0.141900826716656, 0.514746, 0.930560546720505, 0.930560546720505, 0.514746, 0.141900826716656, 0.0137486265628393, 0}, 0043 {0.0003628, 0044 0.01789099867138, 0045 0.15559612641629, 0046 0.5292298, 0047 0.933220224912329, 0048 0.93322022491233, 0049 0.5292298, 0050 0.155596126416291, 0051 0.0178909986713801, 0052 0.0003628}, 0053 {6.e-05, 0.0150711734102182, 0.147039557862381, 0.520575, 0.9316592687274, 0.931659268727401, 0.520575, 0.147039557862382, 0.0150711734102182, 6.e-05}, 0054 {0, -0.0867710194112928, -0.331895219303666, 0.918, 4.00066623871496, 4.00066623871496, 0.918, -0.331895219303665, -0.0867710194112926, 0}, 0055 {0, 0056 0.342020143325669, 0057 0.642787609686539, 0058 0.866025403784439, 0059 0.984807753012208, 0060 0.984807753012208, 0061 0.866025403784439, 0062 0.642787609686539, 0063 0.342020143325669, 0064 0}, 0065 {0, 0.142236444948122, 0.420680359153233, 0.73, 0.950416529231978, 0.950416529231979, 0.73, 0.420680359153233, 0.142236444948122, 0}, 0066 {0, 0067 0.263064408273866, 0068 0.564253278793615, 0069 0.826993343132688, 0070 0.979815536051017, 0071 0.979815536051017, 0072 0.826993343132688, 0073 0.564253278793615, 0074 0.263064408273866, 0075 0}}; 0076 0077 for (int t = (int)nsl_sf_window_uniform; t <= (int)nsl_sf_window_lanczos; t++) { 0078 nsl_sf_apply_window(data, N, (nsl_sf_window_type)t); 0079 for (int i = 0; i < N; i++) 0080 QCOMPARE(data[i] + 1., result[t][i] + 1.); 0081 } 0082 } 0083 0084 // ############################################################################## 0085 // ################# performance 0086 // ############################################################################## 0087 0088 void NSLSFWindowTest::testPerformance_triangle() { 0089 const int N = 1e6; 0090 double* data = new double[N]; 0091 0092 QBENCHMARK { nsl_sf_apply_window(data, N, nsl_sf_window_triangle); } 0093 delete[] data; 0094 } 0095 0096 void NSLSFWindowTest::testPerformance_welch() { 0097 const int N = 1e6; 0098 double* data = new double[N]; 0099 0100 QBENCHMARK { nsl_sf_apply_window(data, N, nsl_sf_window_welch); } 0101 delete[] data; 0102 } 0103 0104 void NSLSFWindowTest::testPerformance_flat_top() { 0105 const int N = 1e6; 0106 double* data = new double[N]; 0107 0108 QBENCHMARK { nsl_sf_apply_window(data, N, nsl_sf_window_flat_top); } 0109 delete[] data; 0110 } 0111 0112 QTEST_MAIN(NSLSFWindowTest)