| 1 | #ifndef __SYMBOLSYNCPOLYDSPTEST_H |
|---|
| 2 | #define __SYMBOLSYNCPOLYDSPTEST_H |
|---|
| 3 | |
|---|
| 4 | #include <cxxtest/TestSuite.h> |
|---|
| 5 | #include "../SymbolSyncPolyDSP.h" |
|---|
| 6 | #include "I_in_rrc_qpsk_N512_dT0_dF0_k4_m4_b025_Npfb32.h" |
|---|
| 7 | #include "Q_in_rrc_qpsk_N512_dT0_dF0_k4_m4_b025_Npfb32.h" |
|---|
| 8 | #include "msg_i_rrc_qpsk_N512_dT0_dF0_k4_m4_b025_Npfb32.h" |
|---|
| 9 | #include "msg_q_rrc_qpsk_N512_dT0_dF0_k4_m4_b025_Npfb32.h" |
|---|
| 10 | |
|---|
| 11 | // |
|---|
| 12 | // A simple test suite: Just inherit CxxTest::TestSuite and write tests! |
|---|
| 13 | // |
|---|
| 14 | |
|---|
| 15 | // NOTE: " : public CxxTest::TestSuite" must be on the same line as the class |
|---|
| 16 | // definition, otherwise the python script does not recognize it |
|---|
| 17 | // as a test class |
|---|
| 18 | class SymbolSyncPoly_testsuite1 : public CxxTest::TestSuite, |
|---|
| 19 | public SymbolSyncPolyDSP |
|---|
| 20 | { |
|---|
| 21 | public: |
|---|
| 22 | |
|---|
| 23 | void test1() { |
|---|
| 24 | // initialize variables |
|---|
| 25 | mf_i = -10; |
|---|
| 26 | dmf_i = 10; |
|---|
| 27 | mf_q = 10; |
|---|
| 28 | dmf_q = 10; |
|---|
| 29 | GenerateErrorSignal(); |
|---|
| 30 | TS_ASSERT_DELTA( q, 0.0f/(Ac*Ac), 1e-6f ); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | void test2() { |
|---|
| 34 | // initialize variables |
|---|
| 35 | mf_i = 30; |
|---|
| 36 | dmf_i = 5; |
|---|
| 37 | mf_q = 20; |
|---|
| 38 | dmf_q = 1; |
|---|
| 39 | GenerateErrorSignal(); |
|---|
| 40 | TS_ASSERT_DELTA( q, -85.0f/(Ac*Ac), 1e-12f ); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | class SymbolSyncPoly_testsuite_ComputeFilterBankIndex : public CxxTest::TestSuite, |
|---|
| 47 | public SymbolSyncPolyDSP |
|---|
| 48 | { |
|---|
| 49 | public: |
|---|
| 50 | void testShift() { |
|---|
| 51 | // Normal operation |
|---|
| 52 | Npfb = 32; |
|---|
| 53 | b_soft = 11.0f; |
|---|
| 54 | ComputeFilterBankIndex(); |
|---|
| 55 | TS_ASSERT_EQUALS( b, 11 ); |
|---|
| 56 | TS_ASSERT_DELTA( b_soft, 11.0f, 0.0001f ); |
|---|
| 57 | TS_ASSERT_EQUALS( lc, SHIFT ); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | void testStuff() { |
|---|
| 61 | // Filter bank overflow |
|---|
| 62 | Npfb = 32; |
|---|
| 63 | b_soft = 32.1f; |
|---|
| 64 | ComputeFilterBankIndex(); |
|---|
| 65 | TS_ASSERT_EQUALS( b, 0 ); |
|---|
| 66 | TS_ASSERT_DELTA( b_soft, 0.1f, 0.0001f ); |
|---|
| 67 | TS_ASSERT_EQUALS( lc, STUFF ); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | void testSkip() { |
|---|
| 71 | // Filter bank underflow |
|---|
| 72 | Npfb = 32; |
|---|
| 73 | b_soft = -2.1f; |
|---|
| 74 | ComputeFilterBankIndex(); |
|---|
| 75 | TS_ASSERT_EQUALS( b, 30 ); |
|---|
| 76 | TS_ASSERT_DELTA( b_soft, 29.9f, 0.0001f ); |
|---|
| 77 | TS_ASSERT_EQUALS( lc, SKIP ); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | /** \brief Test suite for SymbolSyncPolyDSP class |
|---|
| 83 | * |
|---|
| 84 | * In here we perform robust testing of the synchonization mechanism |
|---|
| 85 | * using different configurations and input vectors |
|---|
| 86 | */ |
|---|
| 87 | class SymbolSyncPoly_symboltestsuite: public CxxTest::TestSuite |
|---|
| 88 | { |
|---|
| 89 | public: |
|---|
| 90 | |
|---|
| 91 | ///\Basic test case for SynchronizeAndDecimate. No symbol offsets or timing errors |
|---|
| 92 | void testBasicSynchronization() |
|---|
| 93 | { |
|---|
| 94 | SymbolSyncPolyDSP symbolSync; |
|---|
| 95 | ///The following input buffers and expected results are defined in header files |
|---|
| 96 | ///float nominal_test_vector_I, nominal_test_vector_Q; |
|---|
| 97 | ///short nominal_expected_results_I, nominal_expected_results_Q; |
|---|
| 98 | |
|---|
| 99 | //float to short conversion |
|---|
| 100 | //float max_float_value = 3; //double check this value later if signal is noisy |
|---|
| 101 | short max_short_value = 10000;//32767; |
|---|
| 102 | //float tmp_float; |
|---|
| 103 | unsigned int N_in = 512; //This number must match with the lenght of the input buffer |
|---|
| 104 | short* nominal_test_vector_I_short = new short[N_in]; |
|---|
| 105 | short* nominal_test_vector_Q_short = new short[N_in]; |
|---|
| 106 | for(unsigned int i =0 ; i < N_in; i++){ |
|---|
| 107 | //tmp_float = nominal_test_vector_I[i];// / max_float_value; //gives a value between 0 and 1 |
|---|
| 108 | nominal_test_vector_I_short[i] = (short) (nominal_test_vector_I[i] * max_short_value); |
|---|
| 109 | |
|---|
| 110 | //tmp_float = nominal_test_vector_Q[i];// / max_float_value; //gives a value between 0 and 1 |
|---|
| 111 | nominal_test_vector_Q_short[i] = (short) (nominal_test_vector_Q[i] * max_short_value); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | ///Init variables shall match the values used in MATLAB to get the test vectors and |
|---|
| 115 | ///expected result |
|---|
| 116 | char type[] = "rrcos"; ///< filter type |
|---|
| 117 | unsigned int k = 2; ///< samples per symbol |
|---|
| 118 | unsigned int m = 4; ///< symbol delay |
|---|
| 119 | float beta = .25; ///< rolloff factor |
|---|
| 120 | unsigned int Npfb = 32; ///< polyphse filter bank size |
|---|
| 121 | |
|---|
| 122 | unsigned int N_out = N_in/k + 2; //Need some buffer for mismatched samples per symbol |
|---|
| 123 | short* systemOutputI = new short[N_out]; |
|---|
| 124 | short* systemOutputQ = new short[N_out]; |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | symbolSync.ConfigureFilterBank(type, k, m, beta, Npfb); |
|---|
| 128 | |
|---|
| 129 | //send test data |
|---|
| 130 | symbolSync.SynchronizeAndDecimate( nominal_test_vector_I_short, |
|---|
| 131 | nominal_test_vector_Q_short, |
|---|
| 132 | N_in, |
|---|
| 133 | systemOutputI, |
|---|
| 134 | systemOutputQ, |
|---|
| 135 | N_out); |
|---|
| 136 | |
|---|
| 137 | std::cout << std::endl << "testBasicSynchronization:" << std::endl; |
|---|
| 138 | std::cout << N_in << " Input samples and " << N_out << " Output symbols" << std::endl; |
|---|
| 139 | //hard decision to see if we recovered the message correctly |
|---|
| 140 | for(unsigned int i = 0; i<N_out; i++){ |
|---|
| 141 | systemOutputI[i] = (systemOutputI[i] < 0)? -1 : 1; |
|---|
| 142 | systemOutputQ[i] = (systemOutputQ[i] < 0)? -1 : 1; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | //verify |
|---|
| 146 | TS_ASSERT_SAME_DATA(&systemOutputI[m], |
|---|
| 147 | nominal_expected_results_I, |
|---|
| 148 | (N_out - m)*sizeof(short)); |
|---|
| 149 | |
|---|
| 150 | TS_ASSERT_SAME_DATA(&systemOutputQ[m], |
|---|
| 151 | nominal_expected_results_Q, |
|---|
| 152 | (N_out - m)*sizeof(short)); |
|---|
| 153 | |
|---|
| 154 | delete [] systemOutputI; |
|---|
| 155 | delete [] systemOutputQ; |
|---|
| 156 | delete [] nominal_test_vector_I_short; |
|---|
| 157 | delete [] nominal_test_vector_Q_short; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | }; |
|---|
| 161 | |
|---|
| 162 | #endif |
|---|
| 163 | |
|---|