Mercurial > hg > svcore
comparison data/model/test/TestFFTModel.h @ 1429:48e9f538e6e9
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | 87ae75da6527 |
children | c170b8d0433c |
comparison
equal
deleted
inserted
replaced
1428:87ae75da6527 | 1429:48e9f538e6e9 |
---|---|
99 // (rather than something with a step in it that is harder to | 99 // (rather than something with a step in it that is harder to |
100 // reason about the FFT of) and the results for subsequent columns | 100 // reason about the FFT of) and the results for subsequent columns |
101 // are those of our expected signal. | 101 // are those of our expected signal. |
102 | 102 |
103 void dc_simple_rect() { | 103 void dc_simple_rect() { |
104 MockWaveModel mwm({ DC }, 16, 4); | 104 MockWaveModel mwm({ DC }, 16, 4); |
105 test(&mwm, RectangularWindow, 8, 8, 8, 0, | 105 test(&mwm, RectangularWindow, 8, 8, 8, 0, |
106 { { {}, {}, {}, {}, {} } }, 4); | 106 { { {}, {}, {}, {}, {} } }, 4); |
107 test(&mwm, RectangularWindow, 8, 8, 8, 1, | 107 test(&mwm, RectangularWindow, 8, 8, 8, 1, |
108 { { { 4.f, 0.f }, {}, {}, {}, {} } }, 4); | 108 { { { 4.f, 0.f }, {}, {}, {}, {} } }, 4); |
109 test(&mwm, RectangularWindow, 8, 8, 8, 2, | 109 test(&mwm, RectangularWindow, 8, 8, 8, 2, |
113 } | 113 } |
114 | 114 |
115 void dc_simple_hann() { | 115 void dc_simple_hann() { |
116 // The Hann window function is a simple sinusoid with period | 116 // The Hann window function is a simple sinusoid with period |
117 // equal to twice the window size, and it halves the DC energy | 117 // equal to twice the window size, and it halves the DC energy |
118 MockWaveModel mwm({ DC }, 16, 4); | 118 MockWaveModel mwm({ DC }, 16, 4); |
119 test(&mwm, HanningWindow, 8, 8, 8, 0, | 119 test(&mwm, HanningWindow, 8, 8, 8, 0, |
120 { { {}, {}, {}, {}, {} } }, 4); | 120 { { {}, {}, {}, {}, {} } }, 4); |
121 test(&mwm, HanningWindow, 8, 8, 8, 1, | 121 test(&mwm, HanningWindow, 8, 8, 8, 1, |
122 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); | 122 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 4); |
123 test(&mwm, HanningWindow, 8, 8, 8, 2, | 123 test(&mwm, HanningWindow, 8, 8, 8, 2, |
125 test(&mwm, HanningWindow, 8, 8, 8, 3, | 125 test(&mwm, HanningWindow, 8, 8, 8, 3, |
126 { { {}, {}, {}, {}, {} } }, 4); | 126 { { {}, {}, {}, {}, {} } }, 4); |
127 } | 127 } |
128 | 128 |
129 void dc_simple_hann_halfoverlap() { | 129 void dc_simple_hann_halfoverlap() { |
130 MockWaveModel mwm({ DC }, 16, 4); | 130 MockWaveModel mwm({ DC }, 16, 4); |
131 test(&mwm, HanningWindow, 8, 4, 8, 0, | 131 test(&mwm, HanningWindow, 8, 4, 8, 0, |
132 { { {}, {}, {}, {}, {} } }, 7); | 132 { { {}, {}, {}, {}, {} } }, 7); |
133 test(&mwm, HanningWindow, 8, 4, 8, 2, | 133 test(&mwm, HanningWindow, 8, 4, 8, 2, |
134 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 7); | 134 { { { 4.f, 0.f }, { 2.f, 0.f }, {}, {}, {} } }, 7); |
135 test(&mwm, HanningWindow, 8, 4, 8, 3, | 135 test(&mwm, HanningWindow, 8, 4, 8, 3, |
137 test(&mwm, HanningWindow, 8, 4, 8, 6, | 137 test(&mwm, HanningWindow, 8, 4, 8, 6, |
138 { { {}, {}, {}, {}, {} } }, 7); | 138 { { {}, {}, {}, {}, {} } }, 7); |
139 } | 139 } |
140 | 140 |
141 void sine_simple_rect() { | 141 void sine_simple_rect() { |
142 MockWaveModel mwm({ Sine }, 16, 4); | 142 MockWaveModel mwm({ Sine }, 16, 4); |
143 // Sine: output is purely imaginary. Note the sign is flipped | 143 // Sine: output is purely imaginary. Note the sign is flipped |
144 // (normally the first half of the output would have negative | 144 // (normally the first half of the output would have negative |
145 // 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 |
146 // FFT shift to centre the phase | 146 // FFT shift to centre the phase |
147 test(&mwm, RectangularWindow, 8, 8, 8, 0, | 147 test(&mwm, RectangularWindow, 8, 8, 8, 0, |
153 test(&mwm, RectangularWindow, 8, 8, 8, 3, | 153 test(&mwm, RectangularWindow, 8, 8, 8, 3, |
154 { { {}, {}, {}, {}, {} } }, 4); | 154 { { {}, {}, {}, {}, {} } }, 4); |
155 } | 155 } |
156 | 156 |
157 void cosine_simple_rect() { | 157 void cosine_simple_rect() { |
158 MockWaveModel mwm({ Cosine }, 16, 4); | 158 MockWaveModel mwm({ Cosine }, 16, 4); |
159 // Cosine: output is purely real. Note the sign is flipped | 159 // Cosine: output is purely real. Note the sign is flipped |
160 // because the model does an FFT shift to centre the phase | 160 // because the model does an FFT shift to centre the phase |
161 test(&mwm, RectangularWindow, 8, 8, 8, 0, | 161 test(&mwm, RectangularWindow, 8, 8, 8, 0, |
162 { { {}, {}, {}, {}, {} } }, 4); | 162 { { {}, {}, {}, {}, {} } }, 4); |
163 test(&mwm, RectangularWindow, 8, 8, 8, 1, | 163 test(&mwm, RectangularWindow, 8, 8, 8, 1, |
167 test(&mwm, RectangularWindow, 8, 8, 8, 3, | 167 test(&mwm, RectangularWindow, 8, 8, 8, 3, |
168 { { {}, {}, {}, {}, {} } }, 4); | 168 { { {}, {}, {}, {}, {} } }, 4); |
169 } | 169 } |
170 | 170 |
171 void twochan_simple_rect() { | 171 void twochan_simple_rect() { |
172 MockWaveModel mwm({ Sine, Cosine }, 16, 4); | 172 MockWaveModel mwm({ Sine, Cosine }, 16, 4); |
173 // Test that the two channels are read and converted separately | 173 // Test that the two channels are read and converted separately |
174 test(&mwm, RectangularWindow, 8, 8, 8, 0, | 174 test(&mwm, RectangularWindow, 8, 8, 8, 0, |
175 { | 175 { |
176 { {}, {}, {}, {}, {} }, | 176 { {}, {}, {}, {}, {} }, |
177 { {}, {}, {}, {}, {} } | 177 { {}, {}, {}, {}, {} } |
192 { {}, {}, {}, {}, {} } | 192 { {}, {}, {}, {}, {} } |
193 }, 4); | 193 }, 4); |
194 } | 194 } |
195 | 195 |
196 void nyquist_simple_rect() { | 196 void nyquist_simple_rect() { |
197 MockWaveModel mwm({ Nyquist }, 16, 4); | 197 MockWaveModel mwm({ Nyquist }, 16, 4); |
198 // Again, the sign is flipped. This has the same amount of | 198 // Again, the sign is flipped. This has the same amount of |
199 // energy as the DC example | 199 // energy as the DC example |
200 test(&mwm, RectangularWindow, 8, 8, 8, 0, | 200 test(&mwm, RectangularWindow, 8, 8, 8, 0, |
201 { { {}, {}, {}, {}, {} } }, 4); | 201 { { {}, {}, {}, {}, {} } }, 4); |
202 test(&mwm, RectangularWindow, 8, 8, 8, 1, | 202 test(&mwm, RectangularWindow, 8, 8, 8, 1, |
206 test(&mwm, RectangularWindow, 8, 8, 8, 3, | 206 test(&mwm, RectangularWindow, 8, 8, 8, 3, |
207 { { {}, {}, {}, {}, {} } }, 4); | 207 { { {}, {}, {}, {}, {} } }, 4); |
208 } | 208 } |
209 | 209 |
210 void dirac_simple_rect() { | 210 void dirac_simple_rect() { |
211 MockWaveModel mwm({ Dirac }, 16, 4); | 211 MockWaveModel mwm({ Dirac }, 16, 4); |
212 // The window scales by 0.5 and some signs are flipped. Only | 212 // The window scales by 0.5 and some signs are flipped. Only |
213 // column 1 has any data (the single impulse). | 213 // column 1 has any data (the single impulse). |
214 test(&mwm, RectangularWindow, 8, 8, 8, 0, | 214 test(&mwm, RectangularWindow, 8, 8, 8, 0, |
215 { { {}, {}, {}, {}, {} } }, 4); | 215 { { {}, {}, {}, {}, {} } }, 4); |
216 test(&mwm, RectangularWindow, 8, 8, 8, 1, | 216 test(&mwm, RectangularWindow, 8, 8, 8, 1, |
220 test(&mwm, RectangularWindow, 8, 8, 8, 3, | 220 test(&mwm, RectangularWindow, 8, 8, 8, 3, |
221 { { {}, {}, {}, {}, {} } }, 4); | 221 { { {}, {}, {}, {}, {} } }, 4); |
222 } | 222 } |
223 | 223 |
224 void dirac_simple_rect_2() { | 224 void dirac_simple_rect_2() { |
225 MockWaveModel mwm({ Dirac }, 16, 8); | 225 MockWaveModel mwm({ Dirac }, 16, 8); |
226 // With 8 samples padding, the FFT shift places the first | 226 // With 8 samples padding, the FFT shift places the first |
227 // Dirac impulse at the start of column 1, thus giving all | 227 // Dirac impulse at the start of column 1, thus giving all |
228 // positive values | 228 // positive values |
229 test(&mwm, RectangularWindow, 8, 8, 8, 0, | 229 test(&mwm, RectangularWindow, 8, 8, 8, 0, |
230 { { {}, {}, {}, {}, {} } }, 5); | 230 { { {}, {}, {}, {}, {} } }, 5); |
237 test(&mwm, RectangularWindow, 8, 8, 8, 4, | 237 test(&mwm, RectangularWindow, 8, 8, 8, 4, |
238 { { {}, {}, {}, {}, {} } }, 5); | 238 { { {}, {}, {}, {}, {} } }, 5); |
239 } | 239 } |
240 | 240 |
241 void dirac_simple_rect_halfoverlap() { | 241 void dirac_simple_rect_halfoverlap() { |
242 MockWaveModel mwm({ Dirac }, 16, 4); | 242 MockWaveModel mwm({ Dirac }, 16, 4); |
243 test(&mwm, RectangularWindow, 8, 4, 8, 0, | 243 test(&mwm, RectangularWindow, 8, 4, 8, 0, |
244 { { {}, {}, {}, {}, {} } }, 7); | 244 { { {}, {}, {}, {}, {} } }, 7); |
245 test(&mwm, RectangularWindow, 8, 4, 8, 1, | 245 test(&mwm, RectangularWindow, 8, 4, 8, 1, |
246 { { { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f } } }, 7); | 246 { { { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f }, { 0.5f, 0.f } } }, 7); |
247 test(&mwm, RectangularWindow, 8, 4, 8, 2, | 247 test(&mwm, RectangularWindow, 8, 4, 8, 2, |