mod works with variable Nc, 10,14, 20 tested using Matlab demod. Demod currently...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 28 Feb 2013 04:03:37 +0000 (04:03 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 28 Feb 2013 04:03:37 +0000 (04:03 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1177 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/fdmdv.c
codec2-dev/src/fdmdv_get_test_bits.c
codec2-dev/src/fdmdv_internal.h
codec2-dev/src/test_bits.h

index 8527a32ac6afec7ac018e3832a69de93d44f2cf6..03c3c3d890f66679d7fa05bb4137caf40a6201f2 100644 (file)
@@ -125,9 +125,9 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(int Nc)
     int           c, i, k;
     float         carrier_freq;
 
-    assert(NC == FDMDV_NC);  /* check public and private #defines match */
+    //assert(NC == FDMDV_NC);  /* check public and private #defines match */
     assert(Nc <= NC);
-    assert(FDMDV_BITS_PER_FRAME == NC*NB);
+    //assert(FDMDV_BITS_PER_FRAME == NC*NB);
     assert(FDMDV_NOM_SAMPLES_PER_FRAME == M);
     assert(FDMDV_MAX_SAMPLES_PER_FRAME == (M+M/P));
 
@@ -137,9 +137,13 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(int Nc)
     
     f->Nc = Nc;
 
+    f->ntest_bits = Nc*NB*4;
     f->current_test_bit = 0;
-    for(i=0; i<NTEST_BITS; i++)
+    f->rx_test_bits_mem = (int*)malloc(sizeof(int)*f->ntest_bits);
+    assert(f->rx_test_bits_mem != NULL);
+    for(i=0; i<f->ntest_bits; i++)
        f->rx_test_bits_mem[i] = 0;
+    assert((sizeof(test_bits)/sizeof(int)) >= f->ntest_bits);
 
     f->tx_pilot_bit = 0;
 
@@ -256,6 +260,7 @@ void CODEC2_WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv)
     assert(fdmdv != NULL);
     KISS_FFT_FREE(fdmdv->fft_pilot_cfg);
     KISS_FFT_FREE(fdmdv->fft_cfg);
+    free(fdmdv->rx_test_bits_mem);
     free(fdmdv);
 }
 
@@ -279,11 +284,12 @@ int CODEC2_WIN32SUPPORT fdmdv_bits_per_frame(struct FDMDV *fdmdv)
 void CODEC2_WIN32SUPPORT fdmdv_get_test_bits(struct FDMDV *f, int tx_bits[])
 {
     int i;
+    int bits_per_frame = fdmdv_bits_per_frame(f);
 
-    for(i=0; i<FDMDV_BITS_PER_FRAME; i++) {
+    for(i=0; i<bits_per_frame; i++) {
        tx_bits[i] = test_bits[f->current_test_bit];
        f->current_test_bit++;
-       if (f->current_test_bit > (NTEST_BITS-1))
+       if (f->current_test_bit > (f->ntest_bits-1))
            f->current_test_bit = 0;
     }
  }
@@ -1087,31 +1093,32 @@ void CODEC2_WIN32SUPPORT fdmdv_put_test_bits(struct FDMDV *f, int *sync,
 {
     int   i,j;
     float ber;
+    int   bits_per_frame = fdmdv_bits_per_frame(f);
 
     /* Append to our memory */
 
-    for(i=0,j=FDMDV_BITS_PER_FRAME; i<NTEST_BITS-FDMDV_BITS_PER_FRAME; i++,j++)
+    for(i=0,j=bits_per_frame; i<f->ntest_bits-bits_per_frame; i++,j++)
        f->rx_test_bits_mem[i] = f->rx_test_bits_mem[j];
-    for(i=NTEST_BITS-FDMDV_BITS_PER_FRAME,j=0; i<NTEST_BITS; i++,j++)
+    for(i=f->ntest_bits-bits_per_frame,j=0; i<f->ntest_bits; i++,j++)
        f->rx_test_bits_mem[i] = rx_bits[j];
     
     /* see how many bit errors we get when checked against test sequence */
        
     *bit_errors = 0;
-    for(i=0; i<NTEST_BITS; i++) {
+    for(i=0; i<f->ntest_bits; i++) {
        *bit_errors += test_bits[i] ^ f->rx_test_bits_mem[i];
        //printf("%d %d %d %d\n", i, test_bits[i], f->rx_test_bits_mem[i], test_bits[i] ^ f->rx_test_bits_mem[i]);
     }
 
     /* if less than a thresh we are aligned and in sync with test sequence */
 
-    ber = (float)*bit_errors/NTEST_BITS;
+    ber = (float)*bit_errors/f->ntest_bits;
   
     *sync = 0;
     if (ber < 0.2)
        *sync = 1;
    
-    *ntest_bits = NTEST_BITS;
+    *ntest_bits = f->ntest_bits;
     
 }
 
index 04db3d0b09b6878701a2d8c1ee7c4c05da4eed8d..c45d80f8f05992bd3227b03817f652b3ffe286cf 100644 (file)
@@ -68,6 +68,8 @@ int main(int argc, char *argv[])
     bits_per_codec_frame = 2*fdmdv_bits_per_frame(fdmdv);
     assert((bits_per_codec_frame % 8) == 0); /* make sure integer number of bytes per frame */
     bytes_per_codec_frame = bits_per_codec_frame/8;
+    fprintf(stderr, "bits_per_fdmdv_frame: %d bits_per_codec_frame: %d bytes_per_codec_frame: %d\n",
+            bits_per_fdmdv_frame, bits_per_codec_frame, bytes_per_codec_frame);
 
     packed_bits = (char*)malloc(bytes_per_codec_frame);
     assert(packed_bits != NULL);
index 455cc0137f2a0ea392424f575a55c06a56e6412a..8c308a91bfef2156c815e2cf54a13bf39b2f56ff 100644 (file)
@@ -43,7 +43,7 @@
 #define FS                    8000  /* sample rate in Hz                                                    */
 #define T                 (1.0/FS)  /* sample period in seconds                                             */
 #define RS                      50  /* symbol rate in Hz                                                    */
-#define NC                      14  /* number of data carriers (plus one pilot in the centre)               */
+#define NC                      20  /* max number of data carriers (plus one pilot in the centre)           */
 #define NB                       2  /* Bits/symbol for QPSK modulation                                      */
 #define RB              (NC*RS*NB)  /* bit rate                                                             */
 #define M                  (FS/RS)  /* oversampling factor                                                  */
@@ -56,8 +56,6 @@
 #define P                        4  /* oversample factor used for initial rx symbol filtering               */
 #define NFILTERTIMING (M+NFILTER+M) /* filter memory used for resampling after timing estimation            */
 
-#define NTEST_BITS        (NC*NB*4) /* length of test bit sequence */
-
 #define NPILOT_LUT                 (4*M)    /* number of pilot look up table samples                 */
 #define NPILOTCOEFF                   30    /* number of FIR filter coeffs in LP filter              */
 #define NPILOTBASEBAND (NPILOTCOEFF+M+M/P)  /* number of pilot baseband samples reqd for pilot LPF   */
@@ -86,8 +84,9 @@ struct FDMDV {
 
     /* test data (test frame) states */
 
+    int  ntest_bits;
     int  current_test_bit;
-    int  rx_test_bits_mem[NTEST_BITS];
+    int *rx_test_bits_mem;
 
     /* Modulator */
 
index 19d7a92f62875e3ce3f06477d3e94b5ff3b380c1..d1c01a03b2f7d85a567b83476cec67a0b1cd0aba 100644 (file)
@@ -112,5 +112,53 @@ const int test_bits[]={
   1,
   1,
   1,
-  0
+  0,
+  0,
+  0,
+  0,
+  1,
+  1,
+  1,
+  1,
+  1,
+  0,
+  1,
+  1,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  1,
+  0,
+  0,
+  1,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  1,
+  1,
+  0,
+  1,
+  1,
+  0,
+  0,
+  0,
+  1,
+  0,
+  1,
+  1,
+  1,
+  0,
+  1
 };