have resolved a few differences between C and Octave, bugs in logging code, Nsym...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 18 May 2015 00:21:11 +0000 (00:21 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 18 May 2015 00:21:11 +0000 (00:21 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2132 01035d8c-6547-0410-b346-abe4f91aad63

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

index 6be9c59155aaa36ab18a6fd6e2f7b835b233a235..ba1c9503ca9e72876254ed7bef91684722953bef 100644 (file)
@@ -592,7 +592,10 @@ endfunction
 function [ch_symb rx_timing rx_filt rx_baseband afdmdv f_est] = rate_Fs_rx_processing(afdmdv, ch_fdm_frame, f_est, nsymb, nin, freq_track)
     M = afdmdv.M;
 
-    % figure(10); clf; hold on;
+    rx_baseband = [];
+    rx_filt = [];
+    rx_timing = [];
+
     for r=1:nsymb
       % shift signal to nominal baseband, this will put Nc/2 carriers either side of 0 Hz
 
@@ -600,9 +603,13 @@ function [ch_symb rx_timing rx_filt rx_baseband afdmdv f_est] = rate_Fs_rx_proce
 
       % downconvert each FDM carrier to Nc separate baseband signals
 
-      [rx_baseband afdmdv] = fdm_downconvert(afdmdv, rx_fdm_frame_bb, nin);
-      [rx_filt afdmdv] = rx_filter(afdmdv, rx_baseband, nin);
-      [rx_onesym rx_timing env afdmdv] = rx_est_timing(afdmdv, rx_filt, nin);     
+      [arx_baseband afdmdv] = fdm_downconvert(afdmdv, rx_fdm_frame_bb, nin);
+      [arx_filt afdmdv] = rx_filter(afdmdv, arx_baseband, nin);
+      [rx_onesym arx_timing env afdmdv] = rx_est_timing(afdmdv, arx_filt, nin);     
+
+      rx_baseband = [rx_baseband arx_baseband];
+      rx_filt     = [rx_filt arx_filt];
+      rx_timng    = [rx_timing arx_timing];
 
       ch_symb(r,:) = rx_onesym;
 
index c529ec1aa465e9168462c282dee9e6fd658d9eeb..83850f0f2ecedb43e22686e896740ad5b4696ed4 100644 (file)
@@ -29,10 +29,10 @@ randn('state',1);
 test = 'compare to c';
 
 if strcmp(test, 'compare to c')
-  frames = 10;
+  frames = 2;
   foff =  0;
   dfoff = 0;
-  EsNodB = 12;
+  EsNodB = 0;
   fading_en = 0;
   hf_delay_ms = 2;
   compare_with_c = 1;
@@ -72,7 +72,7 @@ Nd = 2;
 framesize = 32;
 
 Nsw = 3;
-afdmdv.Nsym = 5;
+afdmdv.Nsym = 6;
 afdmdv.Nt = 5;
 
 % FDMDV init ---------------------------------------------------------------
@@ -255,7 +255,7 @@ for f=1:frames
 
   % if out of sync do Initial Freq offset estimation over NSW frames to flush out memories
 
-  if (sync == 0) && (f>1)
+  if (sync == 0)
 
     % we can test +/- 20Hz, so we break this up into 3 tests to cover +/- 60Hz
 
@@ -267,6 +267,11 @@ for f=1:frames
       % we are out of sync so reset f_est and process two frames to clean out memories
 
       [ch_symb rx_timing rx_filt rx_baseband afdmdv acohpsk.f_est] = rate_Fs_rx_processing(afdmdv, ch_fdm_frame_buf, acohpsk.f_est, Nsw*acohpsk.Nsymbrowpilot, nin, 0);
+      rx_baseband_log = [rx_baseband_log rx_baseband];
+      rx_filt_log = [rx_filt_log rx_filt];
+      ch_symb_log = [ch_symb_log; ch_symb];
+
       for i=1:Nsw-1
         acohpsk.ct_symb_buf = update_ct_symb_buf(acohpsk.ct_symb_buf, ch_symb((i-1)*acohpsk.Nsymbrowpilot+1:i*acohpsk.Nsymbrowpilot,:), acohpsk.Nct_sym_buf, acohpsk.Nsymbrowpilot);
       end
@@ -292,6 +297,10 @@ for f=1:frames
       printf("  [%d] trying sync and f_est: %f\n", f, acohpsk.f_est);
 
       [ch_symb rx_timing rx_filt rx_baseband afdmdv f_est] = rate_Fs_rx_processing(afdmdv, ch_fdm_frame_buf, acohpsk.f_est, Nsw*acohpsk.Nsymbrowpilot, nin, 0);
+      rx_baseband_log = [rx_baseband_log rx_baseband];
+      rx_filt_log = [rx_filt_log rx_filt];
+      ch_symb_log = [ch_symb_log; ch_symb];
       for i=1:Nsw-1
         acohpsk.ct_symb_buf = update_ct_symb_buf(acohpsk.ct_symb_buf, ch_symb((i-1)*acohpsk.Nsymbrowpilot+1:i*acohpsk.Nsymbrowpilot,:), acohpsk.Nct_sym_buf, acohpsk.Nsymbrowpilot);
       end
@@ -314,9 +323,10 @@ for f=1:frames
   % If in sync just do sample rate processing on latest frame
 
   if sync == 1
-    %[rx_fdm_frame_bb afdmdv.fbb_phase_rx] = freq_shift(ch_fdm_frame, -acohpsk.f_est, Fs, afdmdv.fbb_phase_rx);
-    %[ch_symb rx_timing rx_filt rx_baseband afdmdv] = rate_Fs_rx_processing(afdmdv, rx_fdm_frame_bb, acohpsk.Nsymbrowpilot, nin);
     [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];
     [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,:);
@@ -382,22 +392,23 @@ if compare_with_c
 
   load ../build_linux/unittest/tcohpsk_out.txt
 
-  stem_sig_and_error(1, 111, tx_bits_log_c(1:n), tx_bits_log(1:n) - tx_bits_log_c(1:n), 'tx bits', [1 n -1.5 1.5])
-  stem_sig_and_error(2, 211, real(tx_symb_log_c(1:n)), real(tx_symb_log(1:n) - tx_symb_log_c(1:n)), 'tx symb re', [1 n -1.5 1.5])
-  stem_sig_and_error(2, 212, imag(tx_symb_log_c(1:n)), imag(tx_symb_log(1:n) - tx_symb_log_c(1:n)), 'tx symb im', [1 n -1.5 1.5])
+  stem_sig_and_error(1, 111, tx_bits_log_c, tx_bits_log - tx_bits_log_c, 'tx bits', [1 length(tx_bits) -1.5 1.5])
+  stem_sig_and_error(2, 211, real(tx_symb_log_c), real(tx_symb_log - tx_symb_log_c), 'tx symb re', [1 length(tx_symb_log_c) -1.5 1.5])
+  stem_sig_and_error(2, 212, imag(tx_symb_log_c), imag(tx_symb_log - tx_symb_log_c), 'tx symb im', [1 length(tx_symb_log_c) -1.5 1.5])
+
+  stem_sig_and_error(3, 211, real(tx_fdm_frame_log_c), real(tx_fdm_frame_log - tx_fdm_frame_log_c), 'tx fdm frame re', [1 length(tx_fdm_frame_log) -10 10])
+  stem_sig_and_error(3, 212, imag(tx_fdm_frame_log_c), imag(tx_fdm_frame_log - tx_fdm_frame_log_c), 'tx fdm frame im', [1 length(tx_fdm_frame_log) -10 10])
+  stem_sig_and_error(4, 211, real(ch_fdm_frame_log_c), real(ch_fdm_frame_log - ch_fdm_frame_log_c), 'ch fdm frame re', [1 length(ch_fdm_frame_log) -10 10])
+  stem_sig_and_error(4, 212, imag(ch_fdm_frame_log_c), imag(ch_fdm_frame_log - ch_fdm_frame_log_c), 'ch fdm frame im', [1 length(ch_fdm_frame_log) -10 10])
 
-  stem_sig_and_error(3, 211, real(tx_fdm_frame_log_c(1:n)), real(tx_fdm_frame_log(1:n) - tx_fdm_frame_log_c(1:n)), 'tx fdm frame re', [1 n -10 10])
-  stem_sig_and_error(3, 212, imag(tx_fdm_frame_log_c(1:n)), imag(tx_fdm_frame_log(1:n) - tx_fdm_frame_log_c(1:n)), 'tx fdm frame im', [1 n -10 10])
-  stem_sig_and_error(4, 211, real(ch_fdm_frame_log_c(1:n)), real(ch_fdm_frame_log(1:n) - ch_fdm_frame_log_c(1:n)), 'ch fdm frame re', [1 n -10 10])
-  stem_sig_and_error(4, 212, imag(ch_fdm_frame_log_c(1:n)), imag(ch_fdm_frame_log(1:n) - ch_fdm_frame_log_c(1:n)), 'ch fdm frame im', [1 n -10 10])
-  stem_sig_and_error(5, 211, real(rx_fdm_frame_bb_log_c(1:n)), real(rx_fdm_frame_bb_log(1:n) - rx_fdm_frame_bb_log_c(1:n)), 'rx fdm frame bb re', [1 n -10 10])
-  stem_sig_and_error(5, 212, imag(rx_fdm_frame_bb_log_c(1:n)), imag(rx_fdm_frame_bb_log(1:n) - rx_fdm_frame_bb_log_c(1:n)), 'rx fdm frame bb im', [1 n -10 10])
+  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 m] = size(ch_symb_log); n = 40;
   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])
-  stem_sig_and_error(7, 212, imag(ct_symb_ff_log_c), imag(ct_symb_ff_log - ct_symb_ff_log_c), 'ct symb ff 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])
+  %stem_sig_and_error(7, 212, imag(ct_symb_ff_log_c), imag(ct_symb_ff_log - ct_symb_ff_log_c), 'ct symb ff im', [1 n -1.5 1.5])
   stem_sig_and_error(8, 211, rx_amp_log_c, rx_amp_log - rx_amp_log_c, 'Amp Est', [1 n -1.5 1.5])
   stem_sig_and_error(8, 212, rx_phi_log_c, rx_phi_log - rx_phi_log_c, 'Phase Est', [1 n -4 4])
   stem_sig_and_error(9, 211, real(rx_symb_log_c), real(rx_symb_log - rx_symb_log_c), 'rx symb re', [1 n -1.5 1.5])
@@ -408,10 +419,10 @@ if compare_with_c
   check(tx_symb_log, tx_symb_log_c, 'tx_symb');
   check(tx_fdm_frame_log, tx_fdm_frame_log_c, 'tx_fdm_frame');
   check(ch_fdm_frame_log, ch_fdm_frame_log_c, 'ch_fdm_frame');
-  check(rx_fdm_frame_bb_log, rx_fdm_frame_bb_log_c, 'rx_fdm_frame_bb', 0.01);
+  %check(rx_fdm_frame_bb_log, rx_fdm_frame_bb_log_c, 'rx_fdm_frame_bb', 0.01);
 
   check(ch_symb_log, ch_symb_log_c, 'ch_symb',0.01);
-  check(ct_symb_ff_log, ct_symb_ff_log_c, 'ct_symb_ff',0.01);
+  %check(ct_symb_ff_log, ct_symb_ff_log_c, 'ct_symb_ff',0.01);
   check(rx_amp_log, rx_amp_log_c, 'rx_amp_log',0.01);
   check(rx_phi_log, rx_phi_log_c, 'rx_phi_log',0.01);
   check(rx_symb_log, rx_symb_log_c, 'rx_symb',0.01);
index d158a0e7dc35ce61be2467512615a60e563d16d3..e67bd9498acb29c366f8d1b8c420af50fe73a3ce 100644 (file)
@@ -589,7 +589,7 @@ void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[NSYMROWPILOT][COHPSK
         if (coh->rx_baseband_log) {
             for(c=0; c<COHPSK_NC*ND; c++) {       
                 for(i=0; i<nin; i++) {
-                    coh->rx_baseband_log[c*(M+M/P)*LOG_FRAMES*NSYMROWPILOT + coh->rx_baseband_log_col_index + i] = rx_baseband[c][i]; 
+                    coh->rx_baseband_log[c*coh->rx_baseband_log_col_sz + coh->rx_baseband_log_col_index + i] = rx_baseband[c][i]; 
                 }
             }
             coh->rx_baseband_log_col_index += nin;
@@ -599,20 +599,20 @@ void rate_Fs_rx_processing(struct COHPSK *coh, COMP ch_symb[NSYMROWPILOT][COHPSK
         if (coh->rx_filt_log) {
          for(c=0; c<COHPSK_NC*ND; c++) {       
             for(i=0; i<P; i++) {
-              coh->rx_filt_log[c*(P+1)*LOG_FRAMES*NSYMROWPILOT + coh->rx_filt_log_col_index + i] = rx_filt[c][i]; 
+              coh->rx_filt_log[c*coh->rx_filt_log_col_sz + coh->rx_filt_log_col_index + i] = rx_filt[c][i]; 
             }
          }
          coh->rx_filt_log_col_index += P;        
         }
-    }
 
-    if (coh->ch_symb_log) {
-       for(r=0; r<NSYMROWPILOT; r++, coh->ch_symb_log_r++) {
+        if (coh->ch_symb_log) {
             for(c=0; c<COHPSK_NC*ND; c++) {
                coh->ch_symb_log[coh->ch_symb_log_r*COHPSK_NC*ND + c] = ch_symb[r][c]; 
             }
+            coh->ch_symb_log_r++;
         }
     }
+
 }
 
 
index ddbb8084bd436808d00b2b8146dbe0f99d6c8189..f299359057c29d5759e79a789945903d5bc7e3de 100644 (file)
@@ -67,10 +67,14 @@ struct COHPSK {
     COMP           *rx_baseband_log;
     int            rx_baseband_log_col_index;
     int            rx_baseband_log_col_sz;
+
     COMP           *rx_filt_log;
     int            rx_filt_log_col_index;
+    int            rx_filt_log_col_sz;
+
     COMP           *ch_symb_log;
     int            ch_symb_log_r;
+    int            ch_symb_log_col_sz;
 };
 
 
index 8afee7556b8183d86c6926269ec257ff1a3b7039..e3bcdd10f7b5eaedde223c3f78a82590856cc14a 100644 (file)
@@ -49,8 +49,8 @@
 #define FRAMESL     (SYNC_FRAMES*FRAMES)  /* worst case is every frame is out of sync                           */
 
 #define RS          50
-#define FOFF        10.5
-#define ESNODB      8.0
+#define FOFF        0
+#define ESNODB      0
 
 extern float pilots_coh[][PILOTS_NC];
 
@@ -101,11 +101,19 @@ int main(int argc, char *argv[])
     fdmdv = coh->fdmdv;
     assert(coh != NULL);
 
-    coh->rx_filt_log = (COMP *)malloc(sizeof(COMP)*COHPSK_NC*ND*(P+1)*NSYMROWPILOT*FRAMESL);
-    coh->rx_baseband_log_col_sz = M*NSYMROWPILOT*FRAMESL;
-    coh->rx_baseband_log = (COMP *)malloc(sizeof(COMP)*COHPSK_NC*ND*(M+M/P)*NSYMROWPILOT*FRAMESL);
-    coh->ch_symb_log = (COMP *)malloc(sizeof(COMP)*NSYMROWPILOT*FRAMESL*COHPSK_NC*ND);
+    /* these puppies are used for logging data in the bowels on the modem */
+
+    coh->rx_baseband_log_col_sz = (M+M/P)*NSYMROWPILOT*FRAMESL;
+    coh->rx_baseband_log = (COMP *)malloc(sizeof(COMP)*COHPSK_NC*ND*coh->rx_baseband_log_col_sz);
+
+    coh->rx_filt_log_col_sz = (P+1)*NSYMROWPILOT*FRAMESL;
+    coh->rx_filt_log = (COMP *)malloc(sizeof(COMP)*COHPSK_NC*ND*coh->rx_filt_log_col_sz);
+
+    coh->ch_symb_log_col_sz = COHPSK_NC*ND;
+    coh->ch_symb_log = (COMP *)malloc(sizeof(COMP)*NSYMROWPILOT*FRAMESL*coh->ch_symb_log_col_sz);
     
+    /* init stuff */
+
     log_r = log_data_r = noise_r = log_bits = 0;
     ptest_bits_coh = (int*)test_bits_coh;
     ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int);
@@ -208,8 +216,8 @@ int main(int argc, char *argv[])
     octave_save_complex(fout, "tx_fdm_frame_log_c", (COMP*)tx_fdm_frame_log, 1, M*NSYMROWPILOT*FRAMES, M*NSYMROWPILOT*FRAMES);  
     octave_save_complex(fout, "ch_fdm_frame_log_c", (COMP*)ch_fdm_frame_log, 1, M*NSYMROWPILOT*FRAMES, M*NSYMROWPILOT*FRAMES);  
     //octave_save_complex(fout, "rx_fdm_frame_bb_log_c", (COMP*)rx_fdm_frame_bb_log, 1, M*NSYMROWPILOT*FRAMES, M*NSYMROWPILOT*FRAMES);  
-    octave_save_complex(fout, "rx_baseband_log_c", (COMP*)coh->rx_baseband_log, COHPSK_NC*ND, coh->rx_baseband_log_col_index, (M+M/P)*FRAMES*NSYMROWPILOT);  
-    octave_save_complex(fout, "rx_filt_log_c", (COMP*)coh->rx_filt_log, COHPSK_NC*ND, coh->rx_filt_log_col_index, (P+1)*FRAMES*NSYMROWPILOT);  
+    octave_save_complex(fout, "rx_baseband_log_c", (COMP*)coh->rx_baseband_log, COHPSK_NC*ND, coh->rx_baseband_log_col_index, coh->rx_baseband_log_col_sz);  
+    octave_save_complex(fout, "rx_filt_log_c", (COMP*)coh->rx_filt_log, COHPSK_NC*ND, coh->rx_filt_log_col_index, coh->rx_filt_log_col_sz);  
     octave_save_complex(fout, "ch_symb_log_c", (COMP*)coh->ch_symb_log, coh->ch_symb_log_r, COHPSK_NC*ND, COHPSK_NC*ND);  
     octave_save_complex(fout, "ct_symb_ff_log_c", (COMP*)ct_symb_ff_log, NSYMROWPILOT*FRAMES, COHPSK_NC*ND, COHPSK_NC*ND);  
     octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND);