root/experimental/components/Demodulator/atsrc/Demodulator_testsuite.h @ 3998

Revision 3998, 9.9 KB (checked in by jgaeddert, 6 years ago)

Adding more demod functions, writing test scripts

  • Property svn:eol-style set to native
Line 
1#ifndef __DEMODULATORDSPTEST_H__
2#define __DEMODULATORDSPTEST_H__
3
4#include <cxxtest/TestSuite.h>
5#include "src/DemodulatorDSP.h"
6//
7// A simple test suite: Just inherit CxxTest::TestSuite and write tests!
8//
9
10// NOTE: " : public CxxTest::TestSuite" must be on the same line as the class
11//       definition, otherwise the python script does not recognize it
12//       as a test class
13class Demodulator_TestMiscellaneousFunctions : public CxxTest::TestSuite,
14    public DemodulatorDSP
15{
16public:
17    void test_ScaleSignalAmplitude_01() {
18        // Generate 4-PAM signal
19        short I[4] = {-15, -5, 5, 15};
20        short Q[4] = {0, 0, 0, 0};
21        ScaleSignalAmplitude(I, Q, 4, 10000);
22
23        TS_ASSERT_DELTA( I[0], -13416, 1 );
24        TS_ASSERT_DELTA( I[1],  -4472, 1 );
25        TS_ASSERT_DELTA( I[2],   4472, 1 );
26        TS_ASSERT_DELTA( I[3],  13416, 1 );
27
28        TS_ASSERT_DELTA( Q[0], 0, 1 );
29        TS_ASSERT_DELTA( Q[1], 0, 1 );
30        TS_ASSERT_DELTA( Q[2], 0, 1 );
31        TS_ASSERT_DELTA( Q[3], 0, 1 );
32    }
33
34    // Generate 16-QAM signal
35    void test_ScaleSignalAmplitude_02() {
36        short I[16] = {
37            -15, -15, -15, -15,
38             -5,  -5,  -5,  -5,
39              5,   5,   5,   5,
40             15,  15,  15,  15};
41        short Q[16] = {
42             -15, -5, 5, 15,
43             -15, -5, 5, 15,
44             -15, -5, 5, 15,
45             -15, -5, 5, 15};
46        ScaleSignalAmplitude(I, Q, 16, 10000);
47
48        TS_ASSERT_DELTA( I[0],  -9487, 1 );
49        TS_ASSERT_DELTA( I[1],  -9487, 1 );
50        TS_ASSERT_DELTA( I[2],  -9487, 1 );
51        TS_ASSERT_DELTA( I[3],  -9487, 1 );
52        TS_ASSERT_DELTA( I[4],  -3162, 1 );
53        TS_ASSERT_DELTA( I[5],  -3162, 1 );
54        TS_ASSERT_DELTA( I[6],  -3162, 1 );
55        TS_ASSERT_DELTA( I[7],  -3162, 1 );
56        TS_ASSERT_DELTA( I[8],   3162, 1 );
57        TS_ASSERT_DELTA( I[9],   3162, 1 );
58        TS_ASSERT_DELTA( I[10],  3162, 1 );
59        TS_ASSERT_DELTA( I[11],  3162, 1 );
60        TS_ASSERT_DELTA( I[12],  9487, 1 );
61        TS_ASSERT_DELTA( I[13],  9487, 1 );
62        TS_ASSERT_DELTA( I[14],  9487, 1 );
63        TS_ASSERT_DELTA( I[15],  9487, 1 );
64
65        TS_ASSERT_DELTA( Q[0],  -9487, 1 );
66        TS_ASSERT_DELTA( Q[1],  -3162, 1 );
67        TS_ASSERT_DELTA( Q[2],   3162, 1 );
68        TS_ASSERT_DELTA( Q[3],   9487, 1 );
69        TS_ASSERT_DELTA( Q[4],  -9487, 1 );
70        TS_ASSERT_DELTA( Q[5],  -3162, 1 );
71        TS_ASSERT_DELTA( Q[6],   3162, 1 );
72        TS_ASSERT_DELTA( Q[7],   9487, 1 );
73        TS_ASSERT_DELTA( Q[8],  -9487, 1 );
74        TS_ASSERT_DELTA( Q[9],  -3162, 1 );
75        TS_ASSERT_DELTA( Q[10],  3162, 1 );
76        TS_ASSERT_DELTA( Q[11],  9487, 1 );
77        TS_ASSERT_DELTA( Q[12], -9487, 1 );
78        TS_ASSERT_DELTA( Q[13], -3162, 1 );
79        TS_ASSERT_DELTA( Q[14],  3162, 1 );
80        TS_ASSERT_DELTA( Q[15],  9487, 1 );
81
82    }
83};
84
85// NOTE: " : public CxxTest::TestSuite" must be on the same line as the class
86//       definition, otherwise the python script does not recognize it
87//       as a test class
88class Demodulator_TestDemodulation : public CxxTest::TestSuite,
89    public DemodulatorDSP
90{
91public:
92
93    void test_DemodulateBPSK() {
94        short I[7] = {SHRT_MIN, -10000, -1, 0, 1, 10000, SHRT_MAX};
95        short Q[7] = {0, 0, 0, 0, 0, 0, 0};
96        char * bits_out = new char[7];
97
98        SetModulationScheme( MOD_BPSK );
99        DemodulateSequence(I, Q, 7, bits_out);
100
101        TS_ASSERT_EQUALS( bits_out[0], BIT0 );
102        TS_ASSERT_EQUALS( bits_out[1], BIT0 );
103        TS_ASSERT_EQUALS( bits_out[2], BIT0 );
104        TS_ASSERT_EQUALS( bits_out[3], BIT0 );
105        TS_ASSERT_EQUALS( bits_out[4], BIT1 );
106        TS_ASSERT_EQUALS( bits_out[5], BIT1 );
107        TS_ASSERT_EQUALS( bits_out[6], BIT1 );
108
109        delete [] bits_out;
110    }
111
112    void test_DemodulateQPSK() {
113        short I[4] = {-10, -10,  10,  10};
114        short Q[4] = {-10,  10, -10,  10};
115        char * bits_out = new char[8];
116
117        SetModulationScheme( MOD_QPSK );
118        DemodulateSequence(I, Q, 4, bits_out);
119
120        TS_ASSERT_EQUALS( bits_out[0], BIT0 );
121        TS_ASSERT_EQUALS( bits_out[1], BIT0 );
122        TS_ASSERT_EQUALS( bits_out[2], BIT0 );
123        TS_ASSERT_EQUALS( bits_out[3], BIT1 );
124        TS_ASSERT_EQUALS( bits_out[4], BIT1 );
125        TS_ASSERT_EQUALS( bits_out[5], BIT0 );
126        TS_ASSERT_EQUALS( bits_out[6], BIT1 );
127        TS_ASSERT_EQUALS( bits_out[7], BIT1 );
128
129        delete [] bits_out;
130    }
131
132    void test_Demodulate8PSK() {
133        short I[8] = { 100,  71,   0, -71, -100, -71,    0,  71};
134        short Q[8] = {   0,  71, 100,  71,    0, -71, -100, -71};
135        char * bits_out = new char[24];
136
137        SetModulationScheme( MOD_8PSK );
138        DemodulateSequence(I, Q, 8, bits_out);
139
140        TS_ASSERT_EQUALS( bits_out[0],  BIT0 );
141        TS_ASSERT_EQUALS( bits_out[1],  BIT0 );
142        TS_ASSERT_EQUALS( bits_out[2],  BIT0 );
143
144        TS_ASSERT_EQUALS( bits_out[3],  BIT0 );
145        TS_ASSERT_EQUALS( bits_out[4],  BIT0 );
146        TS_ASSERT_EQUALS( bits_out[5],  BIT1 );
147
148        TS_ASSERT_EQUALS( bits_out[6],  BIT1 );
149        TS_ASSERT_EQUALS( bits_out[7],  BIT0 );
150        TS_ASSERT_EQUALS( bits_out[8],  BIT1 );
151
152        TS_ASSERT_EQUALS( bits_out[9],  BIT1 );
153        TS_ASSERT_EQUALS( bits_out[10], BIT0 );
154        TS_ASSERT_EQUALS( bits_out[11], BIT0 );
155
156        TS_ASSERT_EQUALS( bits_out[12], BIT1 );
157        TS_ASSERT_EQUALS( bits_out[13], BIT1 );
158        TS_ASSERT_EQUALS( bits_out[14], BIT0 );
159
160        TS_ASSERT_EQUALS( bits_out[15], BIT1 );
161        TS_ASSERT_EQUALS( bits_out[16], BIT1 );
162        TS_ASSERT_EQUALS( bits_out[17], BIT1 );
163
164        TS_ASSERT_EQUALS( bits_out[18], BIT0 );
165        TS_ASSERT_EQUALS( bits_out[19], BIT1 );
166        TS_ASSERT_EQUALS( bits_out[20], BIT1 );
167
168        TS_ASSERT_EQUALS( bits_out[21], BIT0 );
169        TS_ASSERT_EQUALS( bits_out[22], BIT1 );
170        TS_ASSERT_EQUALS( bits_out[23], BIT0 );
171
172        delete [] bits_out;
173    }
174
175    void xtest_Demodulate16QAM() {
176        short I[16] = {
177            -15, -15, -15, -15,
178             -5,  -5,  -5,  -5,
179              5,   5,   5,   5,
180             15,  15,  15,  15};
181        short Q[16] = {
182             -15, -5, 5, 15,
183             -15, -5, 5, 15,
184             -15, -5, 5, 15,
185             -15, -5, 5, 15};
186        char * bits_out = new char[64];
187
188        SetModulationScheme( MOD_8PSK );
189        DemodulateSequence(I, Q, 16, bits_out);
190
191        TS_ASSERT_EQUALS( bits_out[0],  BIT0 );
192        TS_ASSERT_EQUALS( bits_out[1],  BIT0 );
193        TS_ASSERT_EQUALS( bits_out[2],  BIT0 );
194        TS_ASSERT_EQUALS( bits_out[3],  BIT0 );
195
196        TS_ASSERT_EQUALS( bits_out[4],  BIT0 );
197        TS_ASSERT_EQUALS( bits_out[5],  BIT1 );
198        TS_ASSERT_EQUALS( bits_out[6],  BIT1 );
199        TS_ASSERT_EQUALS( bits_out[7],  BIT0 );
200
201        TS_ASSERT_EQUALS( bits_out[8],  BIT1 );
202        TS_ASSERT_EQUALS( bits_out[9],  BIT1 );
203        TS_ASSERT_EQUALS( bits_out[10], BIT0 );
204        TS_ASSERT_EQUALS( bits_out[11], BIT0 );
205
206        TS_ASSERT_EQUALS( bits_out[12], BIT1 );
207        TS_ASSERT_EQUALS( bits_out[13], BIT1 );
208        TS_ASSERT_EQUALS( bits_out[14], BIT0 );
209        TS_ASSERT_EQUALS( bits_out[15], BIT1 );
210
211        TS_ASSERT_EQUALS( bits_out[16], BIT1 );
212        TS_ASSERT_EQUALS( bits_out[17], BIT1 );
213        TS_ASSERT_EQUALS( bits_out[18], BIT0 );
214        TS_ASSERT_EQUALS( bits_out[19], BIT1 );
215
216        TS_ASSERT_EQUALS( bits_out[20], BIT1 );
217        TS_ASSERT_EQUALS( bits_out[21], BIT0 );
218        TS_ASSERT_EQUALS( bits_out[22], BIT1 );
219        TS_ASSERT_EQUALS( bits_out[23], BIT0 );
220
221        TS_ASSERT_EQUALS( bits_out[24], BIT0 );
222        TS_ASSERT_EQUALS( bits_out[25], BIT0 );
223        TS_ASSERT_EQUALS( bits_out[26], BIT0 );
224        TS_ASSERT_EQUALS( bits_out[27], BIT0 );
225
226        TS_ASSERT_EQUALS( bits_out[28], BIT0 );
227        TS_ASSERT_EQUALS( bits_out[29], BIT0 );
228        TS_ASSERT_EQUALS( bits_out[30], BIT0 );
229        TS_ASSERT_EQUALS( bits_out[31], BIT0 );
230
231        TS_ASSERT_EQUALS( bits_out[32], BIT0 );
232        TS_ASSERT_EQUALS( bits_out[33], BIT0 );
233        TS_ASSERT_EQUALS( bits_out[34], BIT0 );
234        TS_ASSERT_EQUALS( bits_out[35], BIT0 );
235
236        TS_ASSERT_EQUALS( bits_out[36], BIT0 );
237        TS_ASSERT_EQUALS( bits_out[37], BIT1 );
238        TS_ASSERT_EQUALS( bits_out[38], BIT1 );
239        TS_ASSERT_EQUALS( bits_out[39], BIT0 );
240
241        TS_ASSERT_EQUALS( bits_out[40], BIT1 );
242        TS_ASSERT_EQUALS( bits_out[41], BIT1 );
243        TS_ASSERT_EQUALS( bits_out[42], BIT0 );
244        TS_ASSERT_EQUALS( bits_out[43], BIT0 );
245
246        TS_ASSERT_EQUALS( bits_out[44], BIT1 );
247        TS_ASSERT_EQUALS( bits_out[45], BIT1 );
248        TS_ASSERT_EQUALS( bits_out[46], BIT0 );
249        TS_ASSERT_EQUALS( bits_out[47], BIT1 );
250
251        TS_ASSERT_EQUALS( bits_out[48], BIT1 );
252        TS_ASSERT_EQUALS( bits_out[49], BIT1 );
253        TS_ASSERT_EQUALS( bits_out[50], BIT0 );
254        TS_ASSERT_EQUALS( bits_out[51], BIT1 );
255
256        TS_ASSERT_EQUALS( bits_out[52], BIT1 );
257        TS_ASSERT_EQUALS( bits_out[53], BIT0 );
258        TS_ASSERT_EQUALS( bits_out[54], BIT1 );
259        TS_ASSERT_EQUALS( bits_out[55], BIT0 );
260
261        TS_ASSERT_EQUALS( bits_out[56], BIT0 );
262        TS_ASSERT_EQUALS( bits_out[57], BIT0 );
263        TS_ASSERT_EQUALS( bits_out[58], BIT0 );
264        TS_ASSERT_EQUALS( bits_out[59], BIT0 );
265
266        TS_ASSERT_EQUALS( bits_out[60], BIT0 );
267        TS_ASSERT_EQUALS( bits_out[61], BIT0 );
268        TS_ASSERT_EQUALS( bits_out[62], BIT0 );
269        TS_ASSERT_EQUALS( bits_out[63], BIT0 );
270
271        delete [] bits_out;
272    }
273
274    void test_Demodulate4PAM() {
275        short I[4] = {-15, -10, 10, 15};
276        short Q[4] = {0, 0, 0, 0};
277        char * bits_out = new char[8];
278
279        SetModulationScheme( MOD_4PAM );
280        DemodulateSequence(I, Q, 4, bits_out);
281
282        TS_ASSERT_EQUALS( bits_out[0],  BIT1 );
283        TS_ASSERT_EQUALS( bits_out[1],  BIT0 );
284
285        TS_ASSERT_EQUALS( bits_out[2],  BIT1 );
286        TS_ASSERT_EQUALS( bits_out[3],  BIT1 );
287
288        TS_ASSERT_EQUALS( bits_out[4],  BIT0 );
289        TS_ASSERT_EQUALS( bits_out[5],  BIT1 );
290
291        TS_ASSERT_EQUALS( bits_out[6],  BIT0 );
292        TS_ASSERT_EQUALS( bits_out[7],  BIT0 );
293
294        delete [] bits_out;
295    }
296
297};
298
299#endif
300
Note: See TracBrowser for help on using the browser.