Update carrier table generation
authorokcsampson <okcsampson@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 31 Mar 2018 17:44:56 +0000 (17:44 +0000)
committerokcsampson <okcsampson@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 31 Mar 2018 17:44:56 +0000 (17:44 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3443 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/ofdm.c
codec2-dev/src/ofdm_internal.h

index 3631f982eb3a53db5c7cf80756ebde226ca91531..e47b18ed2b7e5896cc462e402e42a486b3bd6472 100644 (file)
@@ -307,15 +307,20 @@ static void ofdm_txframe(struct OFDM *ofdm, complex float tx[OFDM_SAMPLESPERFRAM
  * Return NULL on fail
  */
 
-struct OFDM *ofdm_create(const struct OFDM_CONFIG * config) {
+struct OFDM *ofdm_create(const struct OFDM_CONFIG *config) {
     struct OFDM *ofdm;
-    int i, j;
+    int i, j, n;
 
     if ((ofdm = (struct OFDM *) malloc(sizeof (struct OFDM))) == NULL) {
         return NULL;
     }
 
     /* Copy config structure */
+
+    if (config == NULL) { /* prevent segmentation error */
+        return NULL;
+    }
+
     memcpy((void*)&ofdm->config,(void*)config,sizeof(struct OFDM_CONFIG));
 
     /* store complex BPSK pilot symbols */
@@ -326,20 +331,14 @@ struct OFDM *ofdm_create(const struct OFDM_CONFIG * config) {
 
     /* carrier tables for up and down conversion */
 
-    int Nlower = floorf((OFDM_CENTRE - OFDM_RS * (OFDM_NC / 2)) / OFDM_RS);
+    float lower = OFDM_CENTRE - OFDM_RS * (OFDM_NC / 2);
+    int Nlower = floorf(lower / OFDM_RS);
 
-    for (i = 0, j = Nlower; i < (OFDM_NC + 2); i++, j++) {
-        /*
-         * 2 * pi * j/144  j=19..36
-         * j = 1 kHz to 2 kHz (1.5 kHz center)
-         */
-
-        ofdm->w[i] = TAU * (float) j / (OFDM_FS / OFDM_RS);
-    }
+    for (i = 0, n = Nlower; i < (OFDM_NC + 2); i++, n++) {
+        float w = (TAU * (float) n) / (OFDM_FS / OFDM_RS);
 
-    for (i = 0; i < (OFDM_NC + 2); i++) {
         for (j = 0; j < OFDM_M; j++) {
-            ofdm->W[i][j] = cexpf(I * ofdm->w[i] * j);
+            ofdm->W[i][j] = cexpf(I * w * j);
         }
     }
 
index 162cf334911a2b8a3f5e5dce07eb737c9326f1fd..5d37a322ec1003e5abc78442964d4de80873de2b 100644 (file)
@@ -106,7 +106,6 @@ struct OFDM {
     complex float W[OFDM_NC + 2][OFDM_M];
     complex float rxbuf[OFDM_RXBUF];
     complex float pilots[OFDM_NC + 2];
-    float w[OFDM_NC + 2];
     
     /* Demodulator data */