added state transition to lose sync on 3 bad frames. That'll do for a start, we...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 8 Apr 2015 01:02:36 +0000 (01:02 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 8 Apr 2015 01:02:36 +0000 (01:02 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2107 01035d8c-6547-0410-b346-abe4f91aad63

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

index 2f94c5319e326775e1c2c154f913e268437a7cc6..28b2f5245d54268f299d1a0e65fb70ae3d01e848 100644 (file)
@@ -44,7 +44,7 @@ void qpsk_symbols_to_bits(struct COHPSK *coh, int rx_bits[], COMP ct_symb_buf[][
 void coarse_freq_offset_est(struct COHPSK *coh, struct FDMDV *fdmdv, COMP ch_fdm_frame[], int sync, int *next_sync);
 void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][COHPSK_NC], int sync, int *next_sync);
 void fine_freq_correct(struct COHPSK *coh, int sync, int next_sync);
-int sync_state_machine(int sync, int next_sync);
+int sync_state_machine(struct COHPSK *coh, int sync, int next_sync);
 
 void cohpsk_mod(struct COHPSK *cohpsk, COMP tx_fdm[], int tx_bits[]);
 void cohpsk_demod(struct COHPSK *cohpsk, int rx_bits[], int *reliable_sync_bit, COMP rx_fdm[]);
index 758aca8a51de7f0e3688c7bb59c2ff55acf76b79..87dd80e0922388449b3b63b6b09c7cd0c165f1af 100644 (file)
@@ -65,7 +65,9 @@ static COMP qpsk_mod[] = {
     {-1.0, 0.0}
 };
     
-void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int sampling_points[], int t, float f_fine);
+static int sampling_points[] = {0, 1, 6, 7};
+
+void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int t, float f_fine);
 
 /*---------------------------------------------------------------------------*\
                                                                              
@@ -238,7 +240,6 @@ void qpsk_symbols_to_bits(struct COHPSK *coh, int rx_bits[], COMP ct_symb_buf[][
     int   p, r, c, i;
     COMP  corr, rot, pi_on_4, phi_rect;
     float mag, phi_, amp_;
-    short sampling_points[] = {0, 1, 6, 7};
 
     pi_on_4.real = cosf(M_PI/4); pi_on_4.imag = sinf(M_PI/4);
    
@@ -338,7 +339,7 @@ void coarse_freq_offset_est(struct COHPSK *coh, struct FDMDV *fdmdv, COMP ch_fdm
 }
 
 
-void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int sampling_points[], int t, float f_fine) 
+void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int t, float f_fine) 
 {
     COMP  corr, f_fine_rect, f_corr;
     float mag;
@@ -377,7 +378,6 @@ void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int sa
 
 void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int sync, int *next_sync)
 {
-    int   sampling_points[] = {0, 1, 6, 7};
     int   r,c,i,t;
     float f_fine, mag, max_corr, max_mag;
     COMP  corr;
@@ -406,7 +406,7 @@ void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int
         max_corr = 0;
         for (f_fine=-20; f_fine<=20; f_fine+=1.0) {
             for (t=0; t<NSYMROWPILOT; t++) {
-                corr_with_pilots(&corr, &mag, coh, sampling_points, t, f_fine);
+                corr_with_pilots(&corr, &mag, coh, t, f_fine);
                 //printf("  f: %f  t: %d corr: %f %f\n", f_fine, t, corr.real, corr.imag);
                 if (cabsolute(corr) > max_corr) {
                     max_corr = cabsolute(corr);
@@ -425,6 +425,7 @@ void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int
         if (max_corr/max_mag > 0.9) {
             fprintf(stderr, "in sync!\n");
             *next_sync = 4;
+            coh->sync_timer = 0;
         }
         else {
             *next_sync = 0;
@@ -489,6 +490,7 @@ void fine_freq_correct(struct COHPSK *coh, int sync, int next_sync) {
                   coh->ct_symb_ff_buf[r][c] = cmult(coh->ct_symb_ff_buf[r][c], coh->ff_phase);
               }
           }
+
       }
 
       mag = cabsolute(coh->ff_phase);
@@ -498,10 +500,29 @@ void fine_freq_correct(struct COHPSK *coh, int sync, int next_sync) {
 }
 
 
-int sync_state_machine(int sync, int next_sync)
+int sync_state_machine(struct COHPSK *coh, int sync, int next_sync)
 {
+    COMP  corr;
+    float mag;
+
     if (sync == 1)
         next_sync = 2;
+
+    if (sync == 4) {
+
+        /* check that sync is still good */
+
+        corr_with_pilots(&corr, &mag, coh, coh->ct, coh->f_fine_est);
+
+        if (cabsolute(corr)/mag < 0.9) 
+            coh->sync_timer++;
+
+        if (coh->sync_timer == 3) {
+            fprintf(stderr,"  lost sync ....\n");
+            next_sync = 0;
+        }
+    }
+              
     sync = next_sync;
 
     return sync;
@@ -602,7 +623,7 @@ void cohpsk_demod(struct COHPSK *coh, int rx_bits[], int *reliable_sync_bit, COM
         *reliable_sync_bit = 1;
     }
 
-    sync = sync_state_machine(sync, next_sync);        
+    sync = sync_state_machine(coh, sync, next_sync);        
 
     coh->sync = sync;
 }
index 8925f43cdaa98ac47a1fcc15b3ffb9f135bfe2d3..fc72326b3fbb66a6798c393aeab72a0456d9e6f7 100644 (file)
@@ -49,7 +49,8 @@ struct COHPSK {
     COMP         ff_phase;
     COMP         ct_symb_ff_buf[NSYMROWPILOT+2][PILOTS_NC];
     int          sync;
-    
+    int          sync_timer;
+
     struct FDMDV *fdmdv;
 };
 
index 4d9f050b24509b9f2a067037a83829a790583c48..9f3762cc51c8edd4a871c156d803d6618e8ea793 100644 (file)
@@ -59,7 +59,6 @@ int main(int argc, char *argv[])
     COMP           ch_fdm_frame[M*NSYMROWPILOT];
     COMP           rx_fdm_frame_bb[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];
@@ -77,7 +76,6 @@ int main(int argc, char *argv[])
     FILE          *fout;
     int            f, r, c, log_r, log_data_r, noise_r, i;
     int           *ptest_bits_coh, *ptest_bits_coh_end;
-    float          freq_hz;
     COMP           phase_ch;
 
     struct FDMDV  *fdmdv;
@@ -87,7 +85,6 @@ int main(int argc, char *argv[])
     COMP           rx_filt_log[PILOTS_NC][(P+1)*NSYMROWPILOT*FRAMES];
     int            rx_filt_log_col_index = 0;
     float          env[NT*P];
-    COMP           rx_filter_memory[PILOTS_NC][NFILTER];
     float          rx_timing;
     COMP           tx_onesym[PILOTS_NC];
     COMP           rx_onesym[PILOTS_NC];
@@ -189,7 +186,7 @@ int main(int argc, char *argv[])
         }
 
         //printf("f: %d sync: %d next_sync: %d\n", f, sync, next_sync);
-        sync = sync_state_machine(sync, next_sync);
+        sync = sync_state_machine(coh, sync, next_sync);
         
        /* --------------------------------------------------------*\
                               Log each vector