| 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 | class SymbolSyncPoly_symboltestsuite: public CxxTest::TestSuite |
|---|
| 83 | { |
|---|
| 84 | public: |
|---|
| 85 | |
|---|
| 86 | void testBasicSynchronization() { |
|---|
| 87 | SymbolSyncPolyDSP symbolSync; |
|---|
| 88 | //The following input buffers and expected results are defined in header files |
|---|
| 89 | // float nominal_test_vector_I, nominal_test_vector_Q; |
|---|
| 90 | // short nominal_expected_results_I, nominal_expected_results_Q; |
|---|
| 91 | |
|---|
| 92 | //float to short conversion |
|---|
| 93 | float max_float_value = 3; //double check this value later if signal is noisy |
|---|
| 94 | short max_short_value = 10000;//32767; |
|---|
| 95 | float tmp_float; |
|---|
| 96 | unsigned int N_in = 512; //This number must match with the lenght of the input buffer |
|---|
| 97 | short* nominal_test_vector_I_short = new short[N_in]; |
|---|
| 98 | short* nominal_test_vector_Q_short = new short[N_in]; |
|---|
| 99 | for(unsigned int i =0 ; i < N_in; i++){ |
|---|
| 100 | tmp_float = nominal_test_vector_I[i];// / max_float_value; //gives a value between 0 and 1 |
|---|
| 101 | nominal_test_vector_I_short[i] = (short) (tmp_float * max_short_value); |
|---|
| 102 | |
|---|
| 103 | tmp_float = nominal_test_vector_Q[i];// / max_float_value; //gives a value between 0 and 1 |
|---|
| 104 | nominal_test_vector_Q_short[i] = (short) (tmp_float * max_short_value); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | //init variables |
|---|
| 108 | char type[] = "rrcos"; |
|---|
| 109 | unsigned int k = 4; //samples per symbol |
|---|
| 110 | unsigned int m = 4; //symbol delay |
|---|
| 111 | float beta = .25; //rolloff factor |
|---|
| 112 | unsigned int Npfb = 32; //polyphse filter bank size |
|---|
| 113 | |
|---|
| 114 | unsigned int N_out = N_in/k + 2; //Need some buffer for mismatched samples per symbol |
|---|
| 115 | short* systemOutputI = new short[N_out]; |
|---|
| 116 | short* systemOutputQ = new short[N_out]; |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | symbolSync.ConfigureFilterBank(type, k, m, beta, Npfb); |
|---|
| 120 | //debug printing |
|---|
| 121 | std::cout<<std::endl; |
|---|
| 122 | for(int i = 0; i<10; i++){ |
|---|
| 123 | std::cout<<nominal_test_vector_I[i]<<" "; |
|---|
| 124 | } |
|---|
| 125 | std::cout<<std::endl; |
|---|
| 126 | |
|---|
| 127 | //send test data |
|---|
| 128 | symbolSync.SynchronizeAndDecimate(nominal_test_vector_I_short, nominal_test_vector_Q_short, N_in, systemOutputI, systemOutputQ, N_out); |
|---|
| 129 | std::cout << "N_out = "<< N_out<<std::endl; |
|---|
| 130 | |
|---|
| 131 | for(unsigned int i=0; i<N_out; i++) { |
|---|
| 132 | std::cout << systemOutputI[i] << " " << systemOutputQ[i] << std::endl; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | //hard decision to see if we recovered the message |
|---|
| 136 | for(unsigned int i = 0; i<N_out; i++){ |
|---|
| 137 | if (systemOutputI[i] < 0){ |
|---|
| 138 | systemOutputI[i] = 1; |
|---|
| 139 | }else{ |
|---|
| 140 | systemOutputI[i] = -1; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | if (systemOutputQ[i] < 0){ |
|---|
| 144 | systemOutputQ[i] = 1; |
|---|
| 145 | }else{ |
|---|
| 146 | systemOutputQ[i] = -1; |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | //verify |
|---|
| 151 | TS_ASSERT_SAME_DATA(&systemOutputI[m], nominal_expected_results_I,20*sizeof(short));// N_out*sizeof(short)); |
|---|
| 152 | // TS_ASSERT_SAME_DATA(&systemOutputQ[m], &nominal_expected_results_Q, 20*sizeof(short)); |
|---|
| 153 | |
|---|
| 154 | TS_WARN("Test not fully implemented"); |
|---|
| 155 | delete [] systemOutputI; |
|---|
| 156 | delete [] systemOutputQ; |
|---|
| 157 | delete [] nominal_test_vector_I_short; |
|---|
| 158 | delete [] nominal_test_vector_Q_short; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | }; |
|---|
| 162 | |
|---|
| 163 | #endif |
|---|
| 164 | |
|---|