refactoring cohpsk to remove some warnings and support out of sync logic
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 8 Apr 2015 00:42:42 +0000 (00:42 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 8 Apr 2015 00:42:42 +0000 (00:42 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2106 01035d8c-6547-0410-b346-abe4f91aad63

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

index 64b210b0b6b4624de8671a89785e472f19cf0fee..ea2de9311bdaf981190eb820ccc0175b211e3363 100644 (file)
@@ -6,26 +6,6 @@
 % output of the reference versions of the same functions written in
 % Octave.
 %
-% Ideas:
-% [ ] EB/No v BER curves changing Np, freq offset etc
-%     + can do these pretty fast in C, if we have the channel models
-%     [ ] better interpolation between two signals
-%     [ ] feedback to correct out freq offset est
-%     [ ] fading channel
-%     [ ] freq drift
-%     [ ] timing drift
-% [ ] one version to compare Octave to C
-%     [ ] just compare C at some spot points
-%         + drive C simul from command line?
-%         + drive from octave?
-% [ ] one version to unit test against various impairments  
-% [ ] measure/plot BER against impairments and ideal and tune
-%     + 100 errors
-%     [ ] freq offset
-%         + feeback fine freq?  This will cause IL
-%     [ ] fading ch, compared to ideal
-% [ ] smaller freq est block size to min ram req
-% [ ] freq tracking eeback loop 
 
 
 graphics_toolkit ("gnuplot");
index 1ecc0177a3446483ca61a580170761bce9cebeb4..758aca8a51de7f0e3688c7bb59c2ff55acf76b79 100644 (file)
@@ -5,7 +5,20 @@
   DATE CREATED: March 2015
                                                                              
   Functions that implement a coherent PSK FDM modem.
-                                                                       
+                 
+  TODO:
+
+  [ ] Code to plot EB/No v BER curves for
+      [ ] AWGN channel
+      [ ] freq offset
+      [ ] fading channel
+      [ ] freq drift
+      [ ] timing drift
+  [ ] tune and meas impl loss perf for above
+  [ ] out of sync state
+  [ ] freq offset/drift feedback loop 
+  [ ] smaller freq est block size to min ram req
+                                                      
 \*---------------------------------------------------------------------------*/
 
 /*
@@ -52,6 +65,8 @@ 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);
+
 /*---------------------------------------------------------------------------*\
                                                                              
                                FUNCTIONS
@@ -323,6 +338,28 @@ 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) 
+{
+    COMP  corr, f_fine_rect, f_corr;
+    float mag;
+    int   c, p;
+    
+    corr.real = 0.0; corr.imag = 0.0; mag = 0.0;
+    for (c=0; c<PILOTS_NC; c++) {
+        for (p=0; p<NPILOTSFRAME+2; p++) {
+            f_fine_rect.real = cosf(f_fine*2.0*M_PI*(sampling_points[p]+1.0)/RS);
+            f_fine_rect.imag = sinf(f_fine*2.0*M_PI*(sampling_points[p]+1.0)/RS);
+            f_corr = cmult(f_fine_rect, coh->ct_symb_buf[t+sampling_points[p]][c]);
+            corr = cadd(corr, fcmult(coh->pilot2[p][c], f_corr));
+            mag  += cabsolute(f_corr);
+        }
+    }
+
+    *corr_out = corr;
+    *mag_out  = mag;
+}
+
+
 /*---------------------------------------------------------------------------*\
                                                        
   FUNCTION....: frame_sync_fine_timing_est()        
@@ -341,9 +378,9 @@ void coarse_freq_offset_est(struct COHPSK *coh, struct FDMDV *fdmdv, COMP ch_fdm
 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,p,t;
+    int   r,c,i,t;
     float f_fine, mag, max_corr, max_mag;
-    COMP  f_fine_rect, f_corr, corr;
+    COMP  corr;
 
     /* update memory in symbol buffer */
 
@@ -369,16 +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.real = 0.0; corr.imag = 0.0; mag = 0.0;
-                for (c=0; c<PILOTS_NC; c++) {
-                    for (p=0; p<NPILOTSFRAME+2; p++) {
-                        f_fine_rect.real = cosf(f_fine*2.0*M_PI*(sampling_points[p]+1.0)/RS);
-                        f_fine_rect.imag = sinf(f_fine*2.0*M_PI*(sampling_points[p]+1.0)/RS);
-                        f_corr = cmult(f_fine_rect, coh->ct_symb_buf[t+sampling_points[p]][c]);
-                        corr = cadd(corr, fcmult(coh->pilot2[p][c], f_corr));
-                        mag  += cabsolute(f_corr);
-                    }
-                }
+                corr_with_pilots(&corr, &mag, coh, sampling_points, 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);
@@ -540,7 +568,7 @@ void cohpsk_demod(struct COHPSK *coh, int rx_bits[], int *reliable_sync_bit, COM
     COMP  rx_fdm_frame_bb[M*NSYMROWPILOT];
     COMP  rx_baseband[PILOTS_NC][M+M/P];
     COMP  rx_filt[PILOTS_NC][P+1];
-    float env[NT*P], rx_timing;
+    float env[NT*P], __attribute__((unused)) rx_timing;
     COMP  ch_symb[NSYMROWPILOT][PILOTS_NC];
     COMP  rx_onesym[PILOTS_NC];
     int   sync, next_sync, nin, r, c;
index 8d86ac7ec583ec9ee3ff18ec00b5998762a1c33b..41fe81781528abdbe9b3c43cb9f72ad2a8598aef 100644 (file)
@@ -34,7 +34,7 @@
 
 \*---------------------------------------------------------------------------*/
 
-static COMP cneg(COMP a)
+inline static COMP cneg(COMP a)
 {
     COMP res;
 
@@ -44,7 +44,7 @@ static COMP cneg(COMP a)
     return res;
 }
 
-static COMP cconj(COMP a)
+inline static COMP cconj(COMP a)
 {
     COMP res;
 
@@ -54,7 +54,7 @@ static COMP cconj(COMP a)
     return res;
 }
 
-static COMP cmult(COMP a, COMP b)
+inline static COMP cmult(COMP a, COMP b)
 {
     COMP res;
 
@@ -64,7 +64,7 @@ static COMP cmult(COMP a, COMP b)
     return res;
 }
 
-static COMP fcmult(float a, COMP b)
+inline static COMP fcmult(float a, COMP b)
 {
     COMP res;
 
@@ -74,7 +74,7 @@ static COMP fcmult(float a, COMP b)
     return res;
 }
 
-static COMP cadd(COMP a, COMP b)
+inline static COMP cadd(COMP a, COMP b)
 {
     COMP res;
 
@@ -84,7 +84,7 @@ static COMP cadd(COMP a, COMP b)
     return res;
 }
 
-static float cabsolute(COMP a)
+inline static float cabsolute(COMP a)
 {
     return sqrtf(powf(a.real, 2.0) + powf(a.imag, 2.0));
 }
index 089a54f2a0fdfb3597a0c8ca5dd65a3a254a1855..8b850a08624beb53a9537873c327e3771772aa21 100644 (file)
@@ -1,6 +1,6 @@
 /*---------------------------------------------------------------------------*\
                                                                              
-  FILE........: ttest_cohpsk_ch.c
+  FILE........: test_cohpsk_ch.c
   AUTHOR......: David Rowe  
   DATE CREATED: April 2015
                                                                              
@@ -38,7 +38,7 @@
 #include "comp_prim.h"
 #include "noise_samples.h"
 
-#define FRAMES 35
+#define FRAMES 350
 #define FOFFHZ 10.5
 
 int main(int argc, char *argv[])
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
     ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int);
     phase_ch.real = 1.0; phase_ch.imag = 0.0; 
     noise_r = 0; 
-    noise_end = sizeof(noise)/sizeof(int);
+    noise_end = sizeof(noise)/sizeof(COMP);
     
     /* Main Loop ---------------------------------------------------------------------*/