Mercurial > hg > svcore
comparison data/model/test/TestFFTModel.h @ 1089:655cd4e68e9a simple-fft-model
More tests
author | Chris Cannam |
---|---|
date | Fri, 12 Jun 2015 13:46:44 +0100 |
parents | 5fab8e4f5f19 |
children | bdebff3265ae |
comparison
equal
deleted
inserted
replaced
1088:5fab8e4f5f19 | 1089:655cd4e68e9a |
---|---|
74 QCOMPARE(reals[hs1], 999.f); | 74 QCOMPARE(reals[hs1], 999.f); |
75 QCOMPARE(imags[hs1], 999.f); | 75 QCOMPARE(imags[hs1], 999.f); |
76 } | 76 } |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 private slots: | 80 private slots: |
81 | 81 |
82 // NB. FFTModel columns are centred on the sample frame, and in | 82 // NB. FFTModel columns are centred on the sample frame, and in |
83 // particular this means column 0 is centred at sample 0 (i.e. it | 83 // particular this means column 0 is centred at sample 0 (i.e. it |
84 // contains only half the window-size worth of real samples, the | 84 // contains only half the window-size worth of real samples, the |
86 // these tests we are padding our signal with half a window of | 86 // these tests we are padding our signal with half a window of |
87 // zeros, in order that the result for column 0 is all zeros | 87 // zeros, in order that the result for column 0 is all zeros |
88 // (rather than something with a step in it that is harder to | 88 // (rather than something with a step in it that is harder to |
89 // reason about the FFT of) and the results for subsequent columns | 89 // reason about the FFT of) and the results for subsequent columns |
90 // are those of our expected signal. | 90 // are those of our expected signal. |
91 | 91 |
92 void dc_simple_rect() { | 92 void dc_simple_rect() { |
93 MockWaveModel mwm({ DC }, 16, 4); | 93 MockWaveModel mwm({ DC }, 16, 4); |
94 test(&mwm, RectangularWindow, 8, 8, 8, 0, | 94 test(&mwm, RectangularWindow, 8, 8, 8, 0, |
95 { { {}, {}, {}, {}, {} } }, 4); | 95 { { {}, {}, {}, {}, {} } }, 4); |
96 test(&mwm, RectangularWindow, 8, 8, 8, 1, | 96 test(&mwm, RectangularWindow, 8, 8, 8, 1, |
97 { { { 4.f, 0.f }, {}, {}, {}, {} } }, 4); | 97 { { { 4.f, 0.f }, {}, {}, {}, {} } }, 4); |
98 test(&mwm, RectangularWindow, 8, 8, 8, 2, | 98 test(&mwm, RectangularWindow, 8, 8, 8, 2, |
99 { { { 4.f, 0.f }, {}, {}, {}, {} } }, 4); | 99 { { { 4.f, 0.f }, {}, {}, {}, {} } }, 4); |
100 test(&mwm, RectangularWindow, 8, 8, 8, 3, | 100 test(&mwm, RectangularWindow, 8, 8, 8, 3, |
101 { { { }, {}, {}, {}, {} } }, 4); | 101 { { {}, {}, {}, {}, {} } }, 4); |
102 } | 102 } |
103 | 103 |
104 void dc_simple_hann() { | 104 void dc_simple_hann() { |
105 // The Hann window function is a simple sinusoid with period | 105 // The Hann window function is a simple sinusoid with period |
106 // equal to twice the window size, and it halves the DC energy | 106 // equal to twice the window size, and it halves the DC energy |
110 test(&mwm, HanningWindow, 8, 8, 8, 1, | 110 test(&mwm, HanningWindow, 8, 8, 8, 1, |
111 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); | 111 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); |
112 test(&mwm, HanningWindow, 8, 8, 8, 2, | 112 test(&mwm, HanningWindow, 8, 8, 8, 2, |
113 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); | 113 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); |
114 test(&mwm, HanningWindow, 8, 8, 8, 3, | 114 test(&mwm, HanningWindow, 8, 8, 8, 3, |
115 { { { }, {}, {}, {}, {} } }, 4); | 115 { { {}, {}, {}, {}, {} } }, 4); |
116 } | 116 } |
117 | 117 |
118 void sine_simple_rect() { | |
119 MockWaveModel mwm({ Sine }, 16, 4); | |
120 test(&mwm, RectangularWindow, 8, 8, 8, 0, | |
121 { { {}, {}, {}, {}, {} } }, 4); | |
122 test(&mwm, RectangularWindow, 8, 8, 8, 1, | |
123 { { {}, { 0.f, 2.f }, {}, {}, {} } }, 4); | |
124 test(&mwm, RectangularWindow, 8, 8, 8, 2, | |
125 { { {}, { 0.f, 2.f }, {}, {}, {} } }, 4); | |
126 test(&mwm, RectangularWindow, 8, 8, 8, 3, | |
127 { { {}, {}, {}, {}, {} } }, 4); | |
128 } | |
129 | |
130 void cosine_simple_rect() { | |
131 MockWaveModel mwm({ Cosine }, 16, 4); | |
132 test(&mwm, RectangularWindow, 8, 8, 8, 0, | |
133 { { {}, {}, {}, {}, {} } }, 4); | |
134 test(&mwm, RectangularWindow, 8, 8, 8, 1, | |
135 { { {}, { 2.f, 0.f }, {}, {}, {} } }, 4); | |
136 test(&mwm, RectangularWindow, 8, 8, 8, 2, | |
137 { { {}, { 2.f, 0.f }, {}, {}, {} } }, 4); | |
138 test(&mwm, RectangularWindow, 8, 8, 8, 3, | |
139 { { {}, {}, {}, {}, {} } }, 4); | |
140 } | |
141 | |
142 void nyquist_simple_rect() { | |
143 MockWaveModel mwm({ Nyquist }, 16, 4); | |
144 test(&mwm, RectangularWindow, 8, 8, 8, 0, | |
145 { { {}, {}, {}, {}, {} } }, 4); | |
146 test(&mwm, RectangularWindow, 8, 8, 8, 1, | |
147 { { {}, {}, {}, {}, { 2.f, 0.f } } }, 4); | |
148 test(&mwm, RectangularWindow, 8, 8, 8, 2, | |
149 { { {}, {}, {}, {}, { 2.f, 0.f } } }, 4); | |
150 test(&mwm, RectangularWindow, 8, 8, 8, 3, | |
151 { { {}, {}, {}, {}, {} } }, 4); | |
152 } | |
153 | |
154 void dirac_simple_rect() { | |
155 MockWaveModel mwm({ Dirac }, 16, 4); | |
156 test(&mwm, RectangularWindow, 8, 8, 8, 0, | |
157 { { {}, {}, {}, {}, {} } }, 4); | |
158 test(&mwm, RectangularWindow, 8, 8, 8, 1, | |
159 { { { 1.f, 0.f }, { 1.f, 0.f }, { 1.f, 0.f }, { 1.f, 0.f }, { 1.f, 0.f } } }, 4); | |
160 test(&mwm, RectangularWindow, 8, 8, 8, 2, | |
161 { { { 1.f, 0.f }, { 1.f, 0.f }, { 1.f, 0.f }, { 1.f, 0.f }, { 1.f, 0.f } } }, 4); | |
162 test(&mwm, RectangularWindow, 8, 8, 8, 3, | |
163 { { {}, {}, {}, {}, {} } }, 4); | |
164 } | |
165 | |
118 }; | 166 }; |
119 | 167 |
120 #endif | 168 #endif |