added some diagnostics for plotting states of cohpsk_demod, still a few glicthes...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 30 May 2015 00:01:56 +0000 (00:01 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 30 May 2015 00:01:56 +0000 (00:01 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2166 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/cohpsk_demod_plot.m [new file with mode: 0644]
codec2-dev/src/CMakeLists.txt
codec2-dev/src/cohpsk_demod.c
codec2-dev/src/cohpsk_put_test_bits.c
codec2-dev/src/freedv_rx.c

diff --git a/codec2-dev/octave/cohpsk_demod_plot.m b/codec2-dev/octave/cohpsk_demod_plot.m
new file mode 100644 (file)
index 0000000..fe0c78a
--- /dev/null
@@ -0,0 +1,49 @@
+% cohpsk_demod.m
+% David Rowe May 2015
+%
+% Plot Octave outputs from cohpsk_demod_plot
+
+Nc=7; Nd=2;
+
+load ../build_linux/src/cohpsk_demod.txt
+load ../build_linux/src/cohpsk_put_test_bits.txt
+  
+figure(1)
+clf;
+
+% plot combined signals to show diversity gains
+
+combined = rx_symb_log_c(:,1:Nc);
+for d=2:Nd
+  combined += rx_symb_log_c(:, (d-1)*Nc+1:d*Nc);
+end
+plot(combined*exp(j*pi/4)/sqrt(Nd),'+')
+title('Scatter');
+axis([-2 2 -2 2])
+
+figure(2)
+clf;
+subplot(211)
+plot(rx_phi_log_c)
+title('phase')
+subplot(212)
+plot(rx_amp_log_c)
+title('amplitide')
+
+figure(3)
+subplot(211)
+plot(rx_timing_log_c)
+title('rx timing');
+subplot(212)
+stem(ratio_log_c)
+title('Sync ratio');
+
+figure(4);
+clf;
+plot(nerr_log_c);
+title('Bit Errors');
+
+figure(5);
+clf;
+plot(error_positions_hist_c);
+title('Error Position Histogram');
index 05ce4675b352ab417e177ce917ccc8ad5a2717bb..981c4116a74aa496593385af4562793a1ec70bd7 100644 (file)
@@ -284,7 +284,7 @@ target_link_libraries(cohpsk_demod ${CMAKE_REQUIRED_LIBRARIES} codec2)
 add_executable(cohpsk_get_test_bits cohpsk_get_test_bits.c)
 target_link_libraries(cohpsk_get_test_bits ${CMAKE_REQUIRED_LIBRARIES} codec2)
 
-add_executable(cohpsk_put_test_bits cohpsk_put_test_bits.c)
+add_executable(cohpsk_put_test_bits cohpsk_put_test_bits.c octave.c)
 target_link_libraries(cohpsk_put_test_bits ${CMAKE_REQUIRED_LIBRARIES} codec2)
 
 add_executable(cohpsk_ch cohpsk_ch.c)
index 507d06acb15fb383a11d2ee80e5be9fe7f86345c..47fc42f1ba90f82b4e58daf413636caf3ae06bee 100644 (file)
@@ -40,6 +40,7 @@
 #include "octave.h"
 
 #define LOG_FRAMES 100
+#define SYNC_FRAMES 12                    /* sync state uses up extra log storage as we reprocess several times */
 
 int main(int argc, char *argv[])
 {
@@ -52,6 +53,7 @@ int main(int argc, char *argv[])
     float        *rx_amp_log;
     float        *rx_phi_log;
     COMP         *rx_symb_log;
+    float         f_est_log[LOG_FRAMES], ratio_log[LOG_FRAMES];
     int           i, r, c, log_data_r, oct, logframes;
 
     if (argc < 3) {
@@ -94,6 +96,8 @@ int main(int argc, char *argv[])
         assert(rx_phi_log != NULL);
         rx_symb_log = (COMP *)malloc(sizeof(COMP)*logframes*NSYMROW*COHPSK_NC*ND);
         assert(rx_symb_log != NULL);
+        cohpsk->rx_timing_log = (float*)malloc(sizeof(float)*SYNC_FRAMES*logframes*NSYMROWPILOT);
+        assert(cohpsk->rx_timing_log != NULL);
     }
 
     log_data_r = 0;
@@ -123,6 +127,10 @@ int main(int argc, char *argv[])
                         rx_symb_log[log_data_r*COHPSK_NC*ND+c] = cohpsk->rx_symb[r][c]; 
                     }
                 }
+
+                f_est_log[frames-1] = cohpsk->f_est;
+                ratio_log[frames-1] = cohpsk->ratio;
+
                 //printf("frames: %d log_data_r: %d\n", frames, log_data_r);
                 if (frames == logframes)
                     oct = 0;
@@ -145,6 +153,9 @@ int main(int argc, char *argv[])
         octave_save_float(foct, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND);  
         octave_save_float(foct, "rx_phi_log_c", (float*)rx_phi_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND);  
         octave_save_complex(foct, "rx_symb_log_c", (COMP*)rx_symb_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND);  
+        octave_save_float(foct, "rx_timing_log_c", (float*)cohpsk->rx_timing_log, 1, cohpsk->rx_timing_log_index, cohpsk->rx_timing_log_index);  
+        octave_save_float(foct, "f_est_log_c", f_est_log, 1, logframes, logframes);  
+        octave_save_float(foct, "ratio_log_c", ratio_log, 1, logframes, logframes);  
         fclose(foct);
     }
 
index 3a2d85e0e658340f19356d591b5723209ef73f04..086c85cf61353f45f9468d67a7f584e8e3eba6bf 100644 (file)
 
 #include "codec2_cohpsk.h"
 #include "test_bits_coh.h"
+#include "octave.h"
+
+#define LOG_FRAMES 100
 
 int main(int argc, char *argv[])
 {
-    FILE         *fin;
+    FILE         *fin, *foct;
     int           rx_bits[COHPSK_BITS_PER_FRAME];
-    int           *ptest_bits_coh, *ptest_bits_coh_end;
+    int          *ptest_bits_coh, *ptest_bits_coh_end;
     int           state, next_state, i, nbits, errors, nerrors;
-    int           error_positions_hist[COHPSK_BITS_PER_FRAME];
+    int           error_positions_hist[COHPSK_BITS_PER_FRAME], logframes;
+    int           nerr_log[LOG_FRAMES];
 
     for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
         error_positions_hist[i] = 0;
 
     if (argc < 2) {
-       printf("usage: %s InputOneBitPerIntFile\n", argv[0]);
+       fprintf(stderr, "usage: %s InputOneBitPerIntFile [OctaveLogFile]\n", argv[0]);
        exit(1);
     }
 
@@ -60,19 +64,34 @@ int main(int argc, char *argv[])
        exit(1);
     }
 
+    foct = NULL;
+    logframes = 0;
+    if (argc == 3) {
+        if ( (foct = fopen(argv[2],"wt")) == NULL ) {
+            fprintf(stderr, "Error opening output Octave file: %s: %s.\n",
+                    argv[2], strerror(errno));            
+       exit(1);
+        }
+    }
+
+    for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
+        error_positions_hist[i] = 0;
+
     ptest_bits_coh = (int*)test_bits_coh;
     ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int);
 
+    state = 0; nbits = 0; nerrors = 0;
     while (fread(rx_bits, sizeof(int), COHPSK_BITS_PER_FRAME, fin) ==  COHPSK_BITS_PER_FRAME) {
 
         errors = 0;
         for(i=0; i<COHPSK_BITS_PER_FRAME; i++) {
             errors += (rx_bits[i] & 0x1) ^ ptest_bits_coh[i];
             if (state == 1) {
-                if ((rx_bits[i] & 0x1) ^ ptest_bits_coh[i])
+                if ((state == 1 ) && (rx_bits[i] & 0x1) ^ ptest_bits_coh[i])
                     error_positions_hist[i]++;
             }
         }
+        //printf("state: %d errors: %d nerrors: %d\n", state, errors, nerrors);
 
         /* state logic */
 
@@ -84,6 +103,8 @@ int main(int argc, char *argv[])
                 ptest_bits_coh += COHPSK_BITS_PER_FRAME;
                 nerrors = errors;
                 nbits = COHPSK_BITS_PER_FRAME;
+                if (logframes < LOG_FRAMES)
+                    nerr_log[logframes++] = errors;
             }
         }
 
@@ -94,6 +115,8 @@ int main(int argc, char *argv[])
             if (ptest_bits_coh >= ptest_bits_coh_end) {
                 ptest_bits_coh = (int*)test_bits_coh;
             }
+            if (logframes < LOG_FRAMES)
+                nerr_log[logframes++] = errors;
         }
 
         state = next_state;
@@ -101,8 +124,14 @@ int main(int argc, char *argv[])
         if (fin == stdin) fflush(stdin);
     }
 
+    if (foct != NULL) {
+        octave_save_int(foct, "nerr_log_c", nerr_log, 1, logframes);  
+        octave_save_int(foct, "error_positions_hist_c", error_positions_hist, 1, logframes);  
+        fclose(foct);
+    }
+
     fclose(fin);
-    printf("BER: %4.3f Nbits: %d Nerrors: %d\n", (float)nerrors/nbits, nbits, nerrors);
+    fprintf(stderr, "BER: %4.3f Nbits: %d Nerrors: %d\n", (float)nerrors/nbits, nbits, nerrors);
 
     return 0;
 }
index 1215b7a39d43e1662afa10a7eacc2e4a0b61df29..94744a96528b4a50a660590a11aa88e932142c45 100644 (file)
@@ -90,6 +90,8 @@ int main(int argc, char *argv[]) {
     freedv->callback_state = (void*)&my_cb_state;
     freedv->freedv_put_next_rx_char = &my_put_next_rx_char;
 
+    freedv->snr_thresh = -100.0;
+
     /* Note we need to work out how many samples demod needs on each
        call (nin).  This is used to adjust for differences in the tx and rx
        sample clock frequencies.  Note also the number of output