coarse frame sync in C working, C and Octace matching
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Mar 2015 21:59:38 +0000 (21:59 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Mar 2015 21:59:38 +0000 (21:59 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2085 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/autotest.m
codec2-dev/octave/tcohpsk.m
codec2-dev/unittest/tcohpsk.c

index 38e99903ff0c776b58e73f2c16a0c80253da56d1..0a772e40488f497372a65040b51b5319934bbecf 100644 (file)
@@ -64,7 +64,7 @@ function check(a, b, test_name, tol)
     printf("OK\n");
     passes++;
   else
-    printf("FAIL\n");
+    printf("FAIL (%f)\n",e);
     fails++;
   end
 endfunction
index bc76eee65030dae4429fcbfe2a12c447b2904f45..35af735e1e47b6af928401fe408a84fcb70dd466 100644 (file)
@@ -245,15 +245,15 @@ check(rx_fdm_log, rx_fdm_log_c, 'rx_fdm');
 check(rx_baseband_log, rx_baseband_log_c, 'rx_baseband',0.01);
 check(rx_filt_log, rx_filt_log_c, 'rx_filt');
 check(ch_symb_log, ch_symb_log_c, 'ch_symb',0.01);
-check(rx_amp_log, rx_amp_log_c, 'rx_amp_log');
+check(rx_amp_log, rx_amp_log_c, 'rx_amp_log',0.01);
 check(rx_phi_log, rx_phi_log_c, 'rx_phi_log');
-check(rx_symb_log, rx_symb_log_c, 'rx_symb');
+check(rx_symb_log, rx_symb_log_c, 'rx_symb',0.01);
 check(rx_bits_log, rx_bits_log_c, 'rx_bits');
 
 % Determine bit error rate
 
 sz = length(tx_bits_log_c);
-Nerrs_c = sum(xor(tx_bits_log_c(framesize+1:sz-framesize), rx_bits_log_c(2*framesize+1:sz)));
+Nerrs_c = sum(xor(tx_bits_log_c(framesize+1:sz-2*framesize), rx_bits_log_c(3*framesize+1:sz)));
 Tbits_c = sz - 2*framesize;
 ber_c = Nerrs_c/Tbits_c;
 ber = Nerrs/Tbits;
index 024f80f0013ca78913c9ae48a9cb179f9096e895..d32847f2156d18e4c8049b526589df7a6c8d4b68 100644 (file)
@@ -48,6 +48,8 @@
 #define RS     50
 #define FOFF   1
 
+extern float pilots_coh[][PILOTS_NC];
+
 int main(int argc, char *argv[])
 {
     struct COHPSK *coh;
@@ -56,6 +58,7 @@ int main(int argc, char *argv[])
     COMP           tx_fdm[M*NSYMROWPILOT];
     COMP           rx_fdm[M*NSYMROWPILOT];
     COMP           ch_symb[NSYMROWPILOT][PILOTS_NC];
+    COMP           ct_symb_buf[2*NSYMROWPILOT][COHPSK_NC];
     int            rx_bits[COHPSK_BITS_PER_FRAME];
     
     int            tx_bits_log[COHPSK_BITS_PER_FRAME*FRAMES];
@@ -88,6 +91,10 @@ int main(int argc, char *argv[])
     COMP           rx_onesym[PILOTS_NC];
     int            rx_baseband_log_col_index = 0;
     COMP           rx_baseband_log[PILOTS_NC][(M+M/P)*NSYMROWPILOT*FRAMES];
+    
+    int            t,ct,p;
+    float          max_corr;
+    COMP           corr;
 
     coh = cohpsk_create();
     assert(coh != NULL);
@@ -177,8 +184,6 @@ int main(int argc, char *argv[])
          }
          rx_baseband_log_col_index += nin;        
 
-         //if (f == 3)
-          //    exit(0);
          for(c=0; c<PILOTS_NC; c++) {       
             for(i=0; i<P; i++) {
               rx_filt_log[c][rx_filt_log_col_index + i] = rx_filt[c][i]; 
@@ -187,8 +192,36 @@ int main(int argc, char *argv[])
          rx_filt_log_col_index += P;        
 
         }
-        qpsk_symbols_to_bits(coh, rx_bits, ch_symb);
 
+        /* coarse frame sync */
+
+        for(r=0; r<NSYMROWPILOT; r++)
+            for(c=0; c<PILOTS_NC; c++) {
+                ct_symb_buf[r][c] = ct_symb_buf[r+NSYMROWPILOT][c];
+                ct_symb_buf[r+NSYMROWPILOT][c] = ch_symb[r][c];
+            }
+        
+        max_corr = 0;
+        for(t=0; t<NSYMROWPILOT; t++) {
+            
+            corr.real = corr.imag = 0.0;
+            for(p=0; p<NPILOTSFRAME; p++) {
+                for(c=0; c<PILOTS_NC; c++) {
+                    corr = cadd(corr,fcmult(pilots_coh[p][c], ct_symb_buf[t+p*(NS+1)][c]));
+                }
+            }
+        
+            if (cabsolute(corr) > max_corr) {
+                max_corr = cabsolute(corr);
+                ct = t;
+            }
+        }
+        //printf("max_corr: %f ct: %d\n", max_corr, ct);
+
+        /* Coherent phase estimation and correction */
+
+        qpsk_symbols_to_bits(coh, rx_bits, ct_symb_buf + ct);
+        
        /* --------------------------------------------------------*\
                               Log each vector 
        \*---------------------------------------------------------*/