uncoded BER being counted OK
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 17 Apr 2018 07:34:22 +0000 (07:34 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 17 Apr 2018 07:34:22 +0000 (07:34 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3493 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/ofdm.c
codec2-dev/src/ofdm_demod.c
codec2-dev/src/ofdm_internal.h
codec2-dev/src/test_bits_ofdm.h

index a66351a1bea0789954efa8912981f70196d3694f..c92bc7bf4a0ee20c89f870cf0301bddfedde0d9a 100644 (file)
@@ -231,7 +231,7 @@ static int coarse_sync(struct OFDM *ofdm, complex float *rx, int length, float *
        frequency est.  We combine samples from either end of frame to
        improve estimate.  Small real 1E-12 term to prevent instability
        with 0 inputs. */
-    
+
     *foff_est = Fs1 * cargf(conjf(p1)*p2 + conjf(p3)*p4 + 1E-12f) / TAU;
 
     return timing_est;
@@ -381,7 +381,8 @@ struct OFDM *ofdm_create(const struct OFDM_CONFIG *config) {
     ofdm->timing_valid = 0;
     ofdm->timing_mx = 0.0f;
     ofdm->nin = OFDM_SAMPLESPERFRAME;
-
+    ofdm->foff_running = 0.0 + I*0.0;
+    
     /* sync state machine */
     
     strcpy(ofdm->sync_state,"searching");
@@ -1001,8 +1002,9 @@ void ofdm_sync_state_machine(struct OFDM *ofdm, int *rx_uw) {
            we use a Unique Word to get a really solid indication of sync. */
 
         ofdm->uw_errors = 0;
+        int tx_uw[] = {1,0,0,1,0,1,0,0,1,0};
         for (i=0; i<OFDM_NUWBITS; i++) {
-            ofdm->uw_errors += rx_uw[i]; 
+            ofdm->uw_errors += tx_uw[i] ^ rx_uw[i]; 
         }
 
         /* during trial sync we don't tolerate errors so much, we look
@@ -1021,7 +1023,7 @@ void ofdm_sync_state_machine(struct OFDM *ofdm, int *rx_uw) {
                 strcpy(ofdm->sync_state_interleaver, "searching");                
             }
            
-            if (ofdm->frame_count == 3) {
+            if (ofdm->frame_count == 4) {
                 /* three good frames, sync is OK! */
                 strcpy(next_state, "synced");
             }
@@ -1033,9 +1035,7 @@ void ofdm_sync_state_machine(struct OFDM *ofdm, int *rx_uw) {
             if (ofdm->uw_errors > 2) {
                 ofdm->sync_counter++;
             } else {
-                if (ofdm->sync_counter) {
-                    ofdm->sync_counter--;
-                }
+                ofdm->sync_counter = 0;
             }
                 
             if (ofdm->sync_counter == 6) {
index 2afda390340389420596a10720aaa5243dde3eb9..bb6d32d50892969558957eed45ef1848409eaca3 100644 (file)
@@ -276,7 +276,7 @@ int main(int argc, char *argv[])
                         symbols_to_llrs(llr, codeword_symbols_de, codeword_amps_de, EsNo, CODED_SYMSPERFRAME);               
                         iter = run_ldpc_decoder(&ldpc, out_char, llr, &parityCheckCount);
                         Nerrs = DATA_BITSPERFRAME - parityCheckCount;
-                        fprintf(stderr, "iter: %d pcc: %d Nerrs: %d\n", iter, parityCheckCount, Nerrs);
+                        //fprintf(stderr, "iter: %d pcc: %d Nerrs: %d\n", iter, parityCheckCount, Nerrs);
                         if (Nerrs < 10) {
                             /* sucessful decode! */
                             strcpy(next_sync_state_interleaver, "synced");
@@ -297,20 +297,25 @@ int main(int argc, char *argv[])
                             int rx_bits_raw[CODED_BITSPERFRAME];
                             for (j=0; j<interleave_frames; j++) {
                                 for(i=0; i<CODED_SYMSPERFRAME; i++) {
-                                    complex float s = codeword_symbols_de[j*CODED_SYMSPERFRAME+i].real + I*codeword_symbols_de[j*CODED_SYMSPERFRAME+i].imag;                                  
-                                    qpsk_demod(s, &rx_bits_raw[OFDM_BPS*i]);
+                                    int bits[2];
+                                    complex float s = codeword_symbols_de[j*CODED_SYMSPERFRAME+i].real + I*codeword_symbols_de[j*CODED_SYMSPERFRAME+i].imag;
+                                    qpsk_demod(s, bits);
+                                    rx_bits_raw[OFDM_BPS*i]   = bits[1];
+                                    rx_bits_raw[OFDM_BPS*i+1] = bits[0];
                                 }
                                 Nerrs = 0;
+                                assert(sizeof(test_codeword)/sizeof(int) == CODED_BITSPERFRAME);
                                 for(i=0; i<CODED_BITSPERFRAME; i++) {
-                                    //fprintf(stderr, "%d %d %d\n", i, test_bits_ofdm[i], rx_bits_raw[i]);
-                                    if (test_bits_ofdm[i] != rx_bits_raw[i]) {
+                                    //fprintf(stderr, "%d %d %d\n", i, test_codeword[i], rx_bits_raw[i]);
+                                    if (test_codeword[i] != rx_bits_raw[i]) {
                                         Nerrs++;
                                     }
                                 }
+                                
                                 Nerrs_raw += Nerrs;
                             }
                             Terrs += Nerrs_raw;
-                            Tbits += Nbitsperframe;
+                            Tbits += Nbitsperframe*interleave_frames;
                         }
 
                         for (j=0; j<interleave_frames; j++) {
index 043d6d115c623c9d9cd26385a22705cad235cc55..1958b4e14752d67da5b0a39594573372760745e9 100644 (file)
@@ -105,6 +105,7 @@ struct OFDM {
     int timing_valid;
     float timing_mx;
     float coarse_foff_est_hz;
+    complex float foff_running;
     int nin;
 
     bool timing_en;
index 32dda83564560b60e70738aca93915309706730d..17b55b3891ff20954757f2a23087255d0eadb8ce 100644 (file)
@@ -355,3 +355,230 @@ const int payload_data_bits[]={
   1,
   0
 };
+
+const int test_codeword[]={
+  1,
+  1,
+  0,
+  0,
+  1,
+  1,
+  1,
+  0,
+  1,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  1,
+  1,
+  0,
+  1,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  0,
+  1,
+  1,
+  1,
+  1,
+  1,
+  1,
+  0,
+  1,
+  0,
+  1,
+  0,
+  1,
+  1,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  1,
+  0,
+  1,
+  0,
+  1,
+  0,
+  1,
+  1,
+  1,
+  0,
+  1,
+  0,
+  1,
+  0,
+  1,
+  1,
+  0,
+  1,
+  1,
+  0,
+  1,
+  0,
+  0,
+  1,
+  0,
+  1,
+  0,
+  0,
+  0,
+  1,
+  1,
+  1,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  1,
+  1,
+  1,
+  0,
+  0,
+  1,
+  1,
+  1,
+  0,
+  0,
+  1,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  1,
+  1,
+  1,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  1,
+  1,
+  0,
+  0,
+  1,
+  1,
+  0,
+  1,
+  1,
+  1,
+  0,
+  1,
+  0,
+  1,
+  1,
+  1,
+  1,
+  1,
+  0,
+  1,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  1,
+  1,
+  1,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  1,
+  1,
+  0,
+  0,
+  1,
+  1,
+  0,
+  1,
+  1,
+  0,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  1,
+  0,
+  1,
+  0,
+  0,
+  1,
+  1,
+  1,
+  0,
+  0,
+  1,
+  0,
+  1,
+  1,
+  0,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  1,
+  0,
+  0
+};