Fix bugs in coarse sync in ofdm.c
authorokcsampson <okcsampson@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 19 Jun 2017 04:12:45 +0000 (04:12 +0000)
committerokcsampson <okcsampson@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 19 Jun 2017 04:12:45 +0000 (04:12 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3216 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/ofdm.c

index 5397e4449463d933157c1282a0e98e29eb3f9f81..fcf855995c4ec494ec43c319c7ec74e05f106154 100644 (file)
@@ -154,19 +154,24 @@ static complex float vector_conjugate_sum(complex float *a, int num_elements) {
  */
 
 static int coarse_sync(struct OFDM *ofdm, complex float *rx, int length) {
-    int Npsam = (OFDM_M + OFDM_NCP);
-    int Ncorr = length - (OFDM_SAMPLESPERFRAME + Npsam);
-    int i;
-
-    assert(Ncorr > 0);
-
+    complex float csam;
+    complex float rxa;
+    complex float rxb;
+    int Ncorr = length - (OFDM_SAMPLESPERFRAME + (OFDM_M + OFDM_NCP));
     float corr[Ncorr];
+    int i, j;
 
     for (i = 0; i < Ncorr; i++) {
-        complex float csam = conjf(ofdm->rate_fs_pilot_samples[i]);
+        rxa = 0.0f + 0.0f *I;
+        rxb = 0.0f + 0.0f *I;
 
-        corr[i]  = cabsf(rx[i] * csam);
-        corr[i] += cabsf(rx[i + OFDM_SAMPLESPERFRAME] * csam);
+        for (j = 0; j < (OFDM_M + OFDM_NCP); j++) {
+            csam = conjf(ofdm->rate_fs_pilot_samples[j]);
+            rxa += (rx[i + j] * csam);
+            rxb += (rx[i + j + OFDM_SAMPLESPERFRAME] * csam);
+        }
+
+        corr[i] = cabsf(rxa) + cabsf(rxb);
     }
 
     /* find the max magnitude and its index */
@@ -480,8 +485,11 @@ void ofdm_demod(struct OFDM *ofdm, int *rx_bits, COMP *rxbuf_in) {
     if (ofdm->timing_en == true) {
         /* update timing at start of every frame */
 
-        st = (OFDM_M + OFDM_NCP + OFDM_SAMPLESPERFRAME + 1) - floorf(OFDM_FTWINDOWWIDTH / 2) + ofdm->timing_est;
-        en = st + OFDM_SAMPLESPERFRAME - 1 + OFDM_M + OFDM_NCP + OFDM_FTWINDOWWIDTH - 1;
+        //st = (OFDM_M + OFDM_NCP + OFDM_SAMPLESPERFRAME + 1) - floorf(OFDM_FTWINDOWWIDTH / 2) + ofdm->timing_est;
+        //en = st + OFDM_SAMPLESPERFRAME - 1 + OFDM_M + OFDM_NCP + OFDM_FTWINDOWWIDTH - 1;
+
+        st = (OFDM_M + OFDM_NCP + OFDM_SAMPLESPERFRAME) - floorf(OFDM_FTWINDOWWIDTH / 2) + ofdm->timing_est;
+        en = st + OFDM_SAMPLESPERFRAME - 1 + OFDM_M + OFDM_NCP + OFDM_FTWINDOWWIDTH;
 
         complex float work[(en - st)];