Mercurial > hg > svcore
comparison data/model/test/TestFFTModel.h @ 1099:0c351e061945 simple-fft-model
More tests
author | Chris Cannam |
---|---|
date | Mon, 15 Jun 2015 15:35:57 +0100 |
parents | bdebff3265ae |
children | 393134235fa0 |
comparison
equal
deleted
inserted
replaced
1098:329ddaf7415d | 1099:0c351e061945 |
---|---|
46 QCOMPARE(fftm.getHeight(), hs1); | 46 QCOMPARE(fftm.getHeight(), hs1); |
47 vector<float> reals(hs1 + 1, 0.f); | 47 vector<float> reals(hs1 + 1, 0.f); |
48 vector<float> imags(hs1 + 1, 0.f); | 48 vector<float> imags(hs1 + 1, 0.f); |
49 reals[hs1] = 999.f; // overrun guards | 49 reals[hs1] = 999.f; // overrun guards |
50 imags[hs1] = 999.f; | 50 imags[hs1] = 999.f; |
51 fftm.getValuesAt(columnNo, &reals[0], &imags[0]); | 51 for (int stepThrough = 0; stepThrough <= 1; ++stepThrough) { |
52 for (int i = 0; i < hs1; ++i) { | 52 if (stepThrough) { |
53 float eRe = expectedValues[ch][i].real(); | 53 // Read through the columns in order instead of |
54 float eIm = expectedValues[ch][i].imag(); | 54 // randomly accessing the one we want. This is to |
55 float thresh = 1e-5f; | 55 // exercise the case where the FFT model saves |
56 if (abs(reals[i] - eRe) > thresh || | 56 // part of each input frame and moves along by |
57 abs(imags[i] - eIm) > thresh) { | 57 // only the non-overlapping distance |
58 cerr << "ERROR: output is not as expected for column " | 58 for (int sc = 0; sc < columnNo; ++sc) { |
59 << i << " in channel " << ch << endl; | 59 fftm.getValuesAt(sc, &reals[0], &imags[0]); |
60 cerr << "expected : "; | |
61 for (int j = 0; j < hs1; ++j) { | |
62 cerr << expectedValues[ch][j] << " "; | |
63 } | 60 } |
64 cerr << "\nactual : "; | 61 } |
65 for (int j = 0; j < hs1; ++j) { | 62 fftm.getValuesAt(columnNo, &reals[0], &imags[0]); |
66 cerr << complex<float>(reals[j], imags[j]) << " "; | 63 for (int i = 0; i < hs1; ++i) { |
64 float eRe = expectedValues[ch][i].real(); | |
65 float eIm = expectedValues[ch][i].imag(); | |
66 float thresh = 1e-5f; | |
67 if (abs(reals[i] - eRe) > thresh || | |
68 abs(imags[i] - eIm) > thresh) { | |
69 cerr << "ERROR: output is not as expected for column " | |
70 << i << " in channel " << ch << " (stepThrough = " | |
71 << stepThrough << ")" << endl; | |
72 cerr << "expected : "; | |
73 for (int j = 0; j < hs1; ++j) { | |
74 cerr << expectedValues[ch][j] << " "; | |
75 } | |
76 cerr << "\nactual : "; | |
77 for (int j = 0; j < hs1; ++j) { | |
78 cerr << complex<float>(reals[j], imags[j]) << " "; | |
79 } | |
80 cerr << endl; | |
67 } | 81 } |
68 cerr << endl; | 82 COMPARE_FUZZIER_F(reals[i], eRe); |
83 COMPARE_FUZZIER_F(imags[i], eIm); | |
69 } | 84 } |
70 COMPARE_FUZZIER_F(reals[i], eRe); | 85 QCOMPARE(reals[hs1], 999.f); |
71 COMPARE_FUZZIER_F(imags[i], eIm); | 86 QCOMPARE(imags[hs1], 999.f); |
72 } | 87 } |
73 QCOMPARE(reals[hs1], 999.f); | |
74 QCOMPARE(imags[hs1], 999.f); | |
75 } | 88 } |
76 } | 89 } |
77 | 90 |
78 private slots: | 91 private slots: |
79 | 92 |
111 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); | 124 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); |
112 test(&mwm, HanningWindow, 8, 8, 8, 3, | 125 test(&mwm, HanningWindow, 8, 8, 8, 3, |
113 { { {}, {}, {}, {}, {} } }, 4); | 126 { { {}, {}, {}, {}, {} } }, 4); |
114 } | 127 } |
115 | 128 |
129 void dc_simple_hann_halfoverlap() { | |
130 MockWaveModel mwm({ DC }, 16, 4); | |
131 test(&mwm, HanningWindow, 8, 4, 8, 0, | |
132 { { {}, {}, {}, {}, {} } }, 7); | |
133 test(&mwm, HanningWindow, 8, 4, 8, 2, | |
134 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 7); | |
135 test(&mwm, HanningWindow, 8, 4, 8, 3, | |
136 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 7); | |
137 test(&mwm, HanningWindow, 8, 4, 8, 6, | |
138 { { {}, {}, {}, {}, {} } }, 7); | |
139 } | |
140 | |
116 void sine_simple_rect() { | 141 void sine_simple_rect() { |
117 MockWaveModel mwm({ Sine }, 16, 4); | 142 MockWaveModel mwm({ Sine }, 16, 4); |
118 // Sine: output is purely imaginary. Note the sign is flipped | 143 // Sine: output is purely imaginary. Note the sign is flipped |
119 // (normally the first half of the output would have negative | 144 // (normally the first half of the output would have negative |
120 // sign for a sine starting at 0) because the model does an | 145 // sign for a sine starting at 0) because the model does an |
186 { { {}, {}, {}, {}, {} } }, 5); | 211 { { {}, {}, {}, {}, {} } }, 5); |
187 test(&mwm, RectangularWindow, 8, 8, 8, 4, | 212 test(&mwm, RectangularWindow, 8, 8, 8, 4, |
188 { { {}, {}, {}, {}, {} } }, 5); | 213 { { {}, {}, {}, {}, {} } }, 5); |
189 } | 214 } |
190 | 215 |
216 void dirac_simple_rect_halfoverlap() { | |
217 MockWaveModel mwm({ Dirac }, 16, 4); | |
218 test(&mwm, RectangularWindow, 8, 4, 8, 0, | |
219 { { {}, {}, {}, {}, {} } }, 7); | |
220 test(&mwm, RectangularWindow, 8, 4, 8, 1, | |
221 { { { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f } } }, 7); | |
222 test(&mwm, RectangularWindow, 8, 4, 8, 2, | |
223 { { { 0.5f, 0.f }, { -0.5f, 0.f }, { 0.5f, 0.f }, { -0.5f, 0.f }, { 0.5f, 0.f } } }, 7); | |
224 test(&mwm, RectangularWindow, 8, 4, 8, 3, | |
225 { { {}, {}, {}, {}, {} } }, 7); | |
226 } | |
227 | |
191 }; | 228 }; |
192 | 229 |
193 #endif | 230 #endif |