C and Octave match over 35 frames on 8db Es/No AWGN channel, yayyyyyy, next step...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 18 May 2015 05:17:59 +0000 (05:17 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 18 May 2015 05:17:59 +0000 (05:17 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2133 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/tcohpsk.m
codec2-dev/src/cohpsk.c
codec2-dev/src/cohpsk_internal.h
codec2-dev/unittest/tcohpsk.c

index 83850f0f2ecedb43e22686e896740ad5b4696ed4..84c8da3a0604c57ebe4806e71b20021197d02f5c 100644 (file)
@@ -29,10 +29,10 @@ randn('state',1);
 test = 'compare to c';
 
 if strcmp(test, 'compare to c')
-  frames = 2;
+  frames = 35;
   foff =  0;
   dfoff = 0;
-  EsNodB = 0;
+  EsNodB = 8;
   fading_en = 0;
   hf_delay_ms = 2;
   compare_with_c = 1;
@@ -323,15 +323,14 @@ for f=1:frames
   % If in sync just do sample rate processing on latest frame
 
   if sync == 1
-    [ch_symb rx_timing rx_filt rx_baseband afdmdv acohpsk.f_est] = rate_Fs_rx_processing(afdmdv, ch_fdm_frame, acohpsk.f_est, acohpsk.Nsymbrowpilot, nin, 1);
-    rx_baseband_log = [rx_baseband_log rx_baseband];
-    rx_filt_log = [rx_filt_log rx_filt];
-    ch_symb_log = [ch_symb_log; ch_symb];
+    [ch_symb rx_timing rx_filt rx_baseband afdmdv acohpsk.f_est] = rate_Fs_rx_processing(afdmdv, ch_fdm_frame, acohpsk.f_est, acohpsk.Nsymbrowpilot, nin, 0);
     [next_sync acohpsk] = frame_sync_fine_freq_est(acohpsk, ch_symb, sync, next_sync);
 
     acohpsk.ct_symb_ff_buf(1:2,:) = acohpsk.ct_symb_ff_buf(acohpsk.Nsymbrowpilot+1:acohpsk.Nsymbrowpilot+2,:);
     acohpsk.ct_symb_ff_buf(3:acohpsk.Nsymbrowpilot+2,:) = acohpsk.ct_symb_buf(acohpsk.ct+3:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:);
 
+    rx_baseband_log = [rx_baseband_log rx_baseband];
+    rx_filt_log = [rx_filt_log rx_filt];
     ch_symb_log = [ch_symb_log; ch_symb];
     rx_timing_log = [rx_timing_log rx_timing];
     fest_log = [fest_log acohpsk.f_est];
@@ -347,6 +346,7 @@ for f=1:frames
     rx_bits_log = [rx_bits_log rx_bits];
     tx_bits_prev_log = [tx_bits_prev_log prev_tx_bits2];
     ratio_log = [ratio_log acohpsk.ratio];
+    ct_symb_ff_log = [ct_symb_ff_log; acohpsk.ct_symb_ff_buf(1:acohpsk.Nsymbrowpilot,:)];
 
     % BER stats
 
@@ -366,7 +366,7 @@ for f=1:frames
   %rx_filt_log = [rx_filt_log rx_filt];
   %rx_timing_log = [rx_timing_log rx_timing];
   %ch_symb_log = [ch_symb_log; ch_symb];
-  % TODO ct_symb_ff_log = [ct_symb_ff_log; acohpsk.ct_symb_ff_buf(1:acohpsk.Nsymbrowpilot,:)];
+  % ct_symb_ff_log = [ct_symb_ff_log; acohpsk.ct_symb_ff_buf(1:acohpsk.Nsymbrowpilot,:)];
 
 
   if sync == 0
@@ -384,10 +384,18 @@ for f=1:frames
 end
 
 ber = Nerrs/Tbits;
-printf("\nEsNodB: %4.1f ber..: %4.3f Nerrs..: %d Tbits..: %d\n", EsNodB, ber, Nerrs, Tbits);
+printf("\nOctave EsNodB: %4.1f ber..: %4.3f Nerrs..: %d Tbits..: %d\n", EsNodB, ber, Nerrs, Tbits);
 
 if compare_with_c
 
+  % Determine bit error rate
+
+  sz = length(tx_bits_log_c);
+  Nerrs_c = sum(xor(tx_bits_prev_log, rx_bits_log_c(framesize+1:length(rx_bits_log_c))));
+  Tbits_c = length(tx_bits_prev_log);
+  ber_c = Nerrs_c/Tbits_c;
+  printf("C EsNodB.....: %4.1f ber_c: %4.3f Nerrs_c: %d Tbits_c: %d\n", EsNodB, ber_c, Nerrs_c, Tbits_c);
+
   % Output vectors from C port ---------------------------------------------------
 
   load ../build_linux/unittest/tcohpsk_out.txt
@@ -404,7 +412,7 @@ if compare_with_c
   stem_sig_and_error(5, 211, real(rx_baseband_log_c(1,:)), real(rx_baseband_log(1,:) - rx_baseband_log_c(1,:)), 'rx baseband re', [1 length(rx_baseband_log) -10 10])
   stem_sig_and_error(5, 212, imag(rx_baseband_log_c(1,:)), imag(rx_baseband_log(1,:) - rx_baseband_log_c(1,:)), 'rx baseband im', [1 length(rx_baseband_log) -10 10])
 
-  [n m] = size(ch_symb_log); n = 40;
+  [n m] = size(ch_symb_log);
   stem_sig_and_error(6, 211, real(ch_symb_log_c), real(ch_symb_log - ch_symb_log_c), 'ch symb re', [1 n -1.5 1.5])
   stem_sig_and_error(6, 212, imag(ch_symb_log_c), imag(ch_symb_log - ch_symb_log_c), 'ch symb im', [1 n -1.5 1.5])
   %stem_sig_and_error(7, 211, real(ct_symb_ff_log_c), real(ct_symb_ff_log - ct_symb_ff_log_c), 'ct symb ff re', [1 n -1.5 1.5])
@@ -428,13 +436,6 @@ if compare_with_c
   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_prev_log, rx_bits_log_c));
-  Tbits_c = length(tx_bits_prev_log);
-  ber_c = Nerrs_c/Tbits_c;
-  printf("EsNodB: %4.1f ber_c: %4.3f Nerrs_c: %d Tbits_c: %d\n", EsNodB, ber_c, Nerrs_c, Tbits_c);
 
 else
 
index e67bd9498acb29c366f8d1b8c420af50fe73a3ce..21967d97d9e77e9e2f6af3384712105fa4013dd3 100644 (file)
@@ -526,7 +526,7 @@ void cohpsk_mod(struct COHPSK *coh, COMP tx_fdm[], int tx_bits[])
 }
 
 
-void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[NSYMROWPILOT][COHPSK_NC*ND], COMP ch_fdm_frame[], float *f_est, int nsymb, int nin, int freq_track)
+void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC*ND], COMP ch_fdm_frame[], float *f_est, int nsymb, int nin, int freq_track)
 {
     struct FDMDV *fdmdv = coh->fdmdv;
     int   r, c, i;
@@ -696,7 +696,17 @@ void cohpsk_demod(struct COHPSK *coh, int rx_bits[], int *reliable_sync_bit, COM
             for (i=0; i<NSW-1; i++) {
                 update_ct_symb_buf(coh->ct_symb_buf, &ch_symb[i*NSYMROWPILOT]);
             }
-            frame_sync_fine_freq_est(coh, &ch_symb[(NSW-1)*NSYMROWPILOT], sync, &next_sync);
+            /*
+              for(i=0; i<NSW*NSYMROWPILOT; i++) {
+                printf("%f %f\n", ch_symb[i][0].real, ch_symb[i][0].imag);
+            }
+            */
+            /*
+            for(i=0; i<NCT_SYMB_BUF; i++) {
+                printf("%f %f\n", coh->ct_symb_buf[i][0].real, coh->ct_symb_buf[i][0].imag);
+            }
+            */
+             frame_sync_fine_freq_est(coh, &ch_symb[(NSW-1)*NSYMROWPILOT], sync, &next_sync);
 
             if (fabs(coh->f_fine_est) > 2.0) {
                 fprintf(stderr, "  [%d] Hmm %f is a bit big :(\n", coh->frame, coh->f_fine_est);
@@ -718,8 +728,8 @@ void cohpsk_demod(struct COHPSK *coh, int rx_bits[], int *reliable_sync_bit, COM
     /* If in sync just do sample rate processing on latest frame */
 
     if (sync == 1) {
-        rate_Fs_rx_processing(coh, ch_symb, rx_fdm, &coh->f_est, NSYMROWPILOT, nin, 1);
-        frame_sync_fine_freq_est(coh, &ch_symb[(NSW-1)*NSYMROWPILOT], sync, &next_sync);
+        rate_Fs_rx_processing(coh, ch_symb, rx_fdm, &coh->f_est, NSYMROWPILOT, nin, 0);
+        frame_sync_fine_freq_est(coh, ch_symb, sync, &next_sync);
  
         for(r=0; r<2; r++)
             for(c=0; c<COHPSK_NC*ND; c++)
index f299359057c29d5759e79a789945903d5bc7e3de..beb5ffafe19562cc8f327084545e1e1734e84881 100644 (file)
@@ -34,8 +34,6 @@
                                                         one copy */
 #define NSW              3                           /* number of sync window frames */
 
-#define LOG_FRAMES       2                           /* todo: re-arrange logging and tcohpsk.c so this can be moved */
-
 #include "fdmdv_internal.h"
 #include "kiss_fft.h"
 
index e3bcdd10f7b5eaedde223c3f78a82590856cc14a..c4990062ad7b35c75f3628d8ad96994bfad314be 100644 (file)
 #include "comp_prim.h"
 #include "noise_samples.h"
 
-#define FRAMES      LOG_FRAMES            /* LOG_FRAMES is #defined in cohpsk_internal.h                        */
+#define FRAMES      35                    /* LOG_FRAMES is #defined in cohpsk_internal.h                        */
 #define SYNC_FRAMES 12                    /* sync state uses up extra log storage as we reprocess several times */
 #define FRAMESL     (SYNC_FRAMES*FRAMES)  /* worst case is every frame is out of sync                           */
 
 #define RS          50
 #define FOFF        0
-#define ESNODB      0
+#define ESNODB      8
 
 extern float pilots_coh[][PILOTS_NC];
 
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
     int            rx_bits_log[COHPSK_BITS_PER_FRAME*FRAMES];
                                           
     FILE          *fout;
-    int            f, r, c, log_r, log_data_r, noise_r;
+    int            f, r, c, log_r, log_data_r, noise_r, ff_log_r;
     int           *ptest_bits_coh, *ptest_bits_coh_end;
     COMP           phase_ch;
 
@@ -114,7 +114,7 @@ int main(int argc, char *argv[])
     
     /* init stuff */
 
-    log_r = log_data_r = noise_r = log_bits = 0;
+    log_r = log_data_r = noise_r = log_bits = ff_log_r = 0;
     ptest_bits_coh = (int*)test_bits_coh;
     ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int);
     memcpy(tx_bits, test_bits_coh, sizeof(int)*COHPSK_BITS_PER_FRAME);
@@ -181,13 +181,18 @@ int main(int argc, char *argv[])
        for(r=0; r<NSYMROWPILOT; r++, log_r++) {
             for(c=0; c<COHPSK_NC*ND; c++) {
                tx_symb_log[log_r][c] = tx_symb[r][c]; 
-               ct_symb_ff_log[log_r][c] = coh->ct_symb_ff_buf[r][c]; 
             }
         }
 
         if (coh->sync == 1) {
 
-           for(r=0; r<NSYMROW; r++, log_data_r++) {
+            for(r=0; r<NSYMROWPILOT; r++, ff_log_r++) {
+                for(c=0; c<COHPSK_NC*ND; c++) {
+                    ct_symb_ff_log[ff_log_r][c] = coh->ct_symb_ff_buf[r][c]; 
+                }
+            }
+
+            for(r=0; r<NSYMROW; r++, log_data_r++) {
                 for(c=0; c<COHPSK_NC*ND; c++) {
                     rx_amp_log[log_data_r][c] = coh->amp_[r][c]; 
                     rx_phi_log[log_data_r][c] = coh->phi_[r][c]; 
@@ -201,7 +206,10 @@ int main(int argc, char *argv[])
        assert(log_r <= NSYMROWPILOT*FRAMES);
        assert(noise_r <= NSYMROWPILOT*M*FRAMES);
        assert(log_data_r <= NSYMROW*FRAMES);
+
+        printf("\r[%d]", f+1);
     }
+    printf("\n");
 
     /*---------------------------------------------------------*\
                Dump logs to Octave file for evaluation