comparison tests/TestWindow.cpp @ 476:2de6184b2ce0

Untabify
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 30 May 2019 18:30:58 +0100
parents a73d94ee8072
children
comparison
equal deleted inserted replaced
475:64fc3009d0a3 476:2de6184b2ce0
14 BOOST_AUTO_TEST_SUITE(TestWindow) 14 BOOST_AUTO_TEST_SUITE(TestWindow)
15 15
16 using std::cout; 16 using std::cout;
17 using std::endl; 17 using std::endl;
18 18
19 #define COMPARE_ARRAY(a, b) \ 19 #define COMPARE_ARRAY(a, b) \
20 for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \ 20 for (int cmp_i = 0; cmp_i < (int)(sizeof(a)/sizeof(a[0])); ++cmp_i) { \
21 BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-4); \ 21 BOOST_CHECK_SMALL(a[cmp_i] - b[cmp_i], 1e-4); \
22 } 22 }
23 23
24 void 24 void
25 testSymmetric(double *d, int n) 25 testSymmetric(double *d, int n)
26 { 26 {
27 for (int i = 0; i <= n/2; ++i) { 27 for (int i = 0; i <= n/2; ++i) {
28 BOOST_CHECK_CLOSE(d[i], d[n-i-1], 1e-10); 28 BOOST_CHECK_CLOSE(d[i], d[n-i-1], 1e-10);
29 } 29 }
30 } 30 }
31 31
32 BOOST_AUTO_TEST_CASE(periodic) 32 BOOST_AUTO_TEST_CASE(periodic)
33 { 33 {
35 // only one cycle of it! But we can make sure that all but the 35 // only one cycle of it! But we can make sure that all but the
36 // first sample is symmetric, which is what a symmetric window 36 // first sample is symmetric, which is what a symmetric window
37 // becomes when generated in periodic mode 37 // becomes when generated in periodic mode
38 double d[9]; 38 double d[9];
39 for (int n = 8; n <= 9; ++n) { 39 for (int n = 8; n <= 9; ++n) {
40 for (int wt = (int)FirstWindow; wt <= (int)LastWindow; ++wt) { 40 for (int wt = (int)FirstWindow; wt <= (int)LastWindow; ++wt) {
41 for (int i = 0; i < n; ++i) d[i] = 1.0; 41 for (int i = 0; i < n; ++i) d[i] = 1.0;
42 Window<double> w((WindowType)wt, n); 42 Window<double> w((WindowType)wt, n);
43 w.cut(d); 43 w.cut(d);
44 testSymmetric(d + 1, n - 1); 44 testSymmetric(d + 1, n - 1);
45 } 45 }
46 } 46 }
47 } 47 }
48 48
49 template <int N> 49 template <int N>
50 void testWindow(WindowType type, const double expected[N]) 50 void testWindow(WindowType type, const double expected[N])
57 57
58 double d0[N], d1[N]; 58 double d0[N], d1[N];
59 for (int i = 0; i < N; ++i) d0[i] = 0.5 + (1.0 / (N * 2)) * (i + 1); 59 for (int i = 0; i < N; ++i) d0[i] = 0.5 + (1.0 / (N * 2)) * (i + 1);
60 w.cut(d0, d1); 60 w.cut(d0, d1);
61 for (int i = 0; i < N; ++i) { 61 for (int i = 0; i < N; ++i) {
62 BOOST_CHECK_SMALL(d1[i] - d0[i] * expected[i], 1e-4); 62 BOOST_CHECK_SMALL(d1[i] - d0[i] * expected[i], 1e-4);
63 } 63 }
64 } 64 }
65 65
66 BOOST_AUTO_TEST_CASE(bartlett) 66 BOOST_AUTO_TEST_CASE(bartlett)
67 { 67 {
88 { 88 {
89 double e1[] = { 1 }; 89 double e1[] = { 1 };
90 testWindow<1>(HammingWindow, e1); 90 testWindow<1>(HammingWindow, e1);
91 91
92 double e10[] = { 92 double e10[] = {
93 0.0800, 0.1679, 0.3979, 0.6821, 0.9121, 93 0.0800, 0.1679, 0.3979, 0.6821, 0.9121,
94 1.0000, 0.9121, 0.6821, 0.3979, 0.1679 94 1.0000, 0.9121, 0.6821, 0.3979, 0.1679
95 }; 95 };
96 testWindow<10>(HammingWindow, e10); 96 testWindow<10>(HammingWindow, e10);
97 } 97 }
98 98
177 177
178 double d0[N], d1[N]; 178 double d0[N], d1[N];
179 for (int i = 0; i < N; ++i) d0[i] = 0.5 + (1.0 / (N * 2)) * (i + 1); 179 for (int i = 0; i < N; ++i) d0[i] = 0.5 + (1.0 / (N * 2)) * (i + 1);
180 w.cut(d0, d1); 180 w.cut(d0, d1);
181 for (int i = 0; i < N; ++i) { 181 for (int i = 0; i < N; ++i) {
182 BOOST_CHECK_SMALL(d1[i] - d0[i] * expected[i], 1e-4); 182 BOOST_CHECK_SMALL(d1[i] - d0[i] * expected[i], 1e-4);
183 } 183 }
184 } 184 }
185 185
186 BOOST_AUTO_TEST_CASE(sinc) 186 BOOST_AUTO_TEST_CASE(sinc)
187 { 187 {