started modifying for variable number of carriers
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 28 Feb 2013 01:06:38 +0000 (01:06 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 28 Feb 2013 01:06:38 +0000 (01:06 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1174 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/codec2_fdmdv.h
codec2-dev/src/fdmdv.c
codec2-dev/src/fdmdv_demod.c
codec2-dev/src/fdmdv_get_test_bits.c
codec2-dev/src/fdmdv_internal.h
codec2-dev/src/fdmdv_mod.c
codec2-dev/src/fdmdv_put_test_bits.c

index 46b3a6a13354c22f86772268de5bd2b17cda54f5..38e971408d29c9d26ac125907a0ce766091b77cb 100644 (file)
@@ -57,6 +57,7 @@ extern "C" {
 
 #include "comp.h"
 
+#define FDMDV_NC                      14  /* default number of data carriers                                */                               
 #define FDMDV_BITS_PER_FRAME          28  /* 20ms frames, 1400 bit/s                                        */
 #define FDMDV_NOM_SAMPLES_PER_FRAME  160  /* modulator output samples/frame and nominal demod samples/frame */
                                           /* at 8000 Hz sample rate                                         */
@@ -88,7 +89,7 @@ struct FDMDV_STATS {
     float  clock_offset;           /* Estimated tx/rx sample clock offset in ppm         */
 };
 
-struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void);
+struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(int Nc);
 void           CODEC2_WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv_state);
     
 void           CODEC2_WIN32SUPPORT fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[], int *sync_bit);
index 9fe7aa385865731faf0b6acf5dc6e966ebcf1d66..1fcd3d598441859d93eb261196dbbba7dc396659 100644 (file)
@@ -119,12 +119,14 @@ static float cabsolute(COMP a)
 
 \*---------------------------------------------------------------------------*/
 
-struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void)
+struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(int Nc)
 {
     struct FDMDV *f;
     int           c, i, k;
     float         carrier_freq;
 
+    assert(NC == FDMDV_NC);  /* check public and private #defines match */
+    assert(Nc <= NC);
     assert(FDMDV_BITS_PER_FRAME == NC*NB);
     assert(FDMDV_NOM_SAMPLES_PER_FRAME == M);
     assert(FDMDV_MAX_SAMPLES_PER_FRAME == (M+M/P));
@@ -133,13 +135,15 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void)
     if (f == NULL)
        return NULL;
     
+    f->Nc = Nc;
+
     f->current_test_bit = 0;
     for(i=0; i<NTEST_BITS; i++)
        f->rx_test_bits_mem[i] = 0;
 
     f->tx_pilot_bit = 0;
 
-    for(c=0; c<NC+1; c++) {
+    for(c=0; c<Nc+1; c++) {
        f->prev_tx_symbols[c].real = 1.0;
        f->prev_tx_symbols[c].imag = 0.0;
        f->prev_rx_symbols[c].real = 1.0;
@@ -159,8 +163,8 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void)
            This helped PAPR for a few dB.  We don't need to adjust rx
            phase as DQPSK takes care of that. */
        
-       f->phase_tx[c].real = cos(2.0*PI*c/(NC+1));
-       f->phase_tx[c].imag = sin(2.0*PI*c/(NC+1));
+       f->phase_tx[c].real = cos(2.0*PI*c/(Nc+1));
+       f->phase_tx[c].imag = sin(2.0*PI*c/(Nc+1));
 
        f->phase_rx[c].real = 1.0;
        f->phase_rx[c].imag = 0.0;
@@ -177,24 +181,24 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void)
     
     /* Set up frequency of each carrier */
 
-    for(c=0; c<NC/2; c++) {
-       carrier_freq = (-NC/2 + c)*FSEP + FDMDV_FCENTRE;
+    for(c=0; c<Nc/2; c++) {
+       carrier_freq = (-Nc/2 + c)*FSEP + FDMDV_FCENTRE;
        f->freq[c].real = cos(2.0*PI*carrier_freq/FS);
        f->freq[c].imag = sin(2.0*PI*carrier_freq/FS);
     }
 
-    for(c=NC/2; c<NC; c++) {
-       carrier_freq = (-NC/2 + c + 1)*FSEP + FDMDV_FCENTRE;
+    for(c=Nc/2; c<Nc; c++) {
+       carrier_freq = (-Nc/2 + c + 1)*FSEP + FDMDV_FCENTRE;
        f->freq[c].real = cos(2.0*PI*carrier_freq/FS);
        f->freq[c].imag = sin(2.0*PI*carrier_freq/FS);
     }
        
-    f->freq[NC].real = cos(2.0*PI*FDMDV_FCENTRE/FS);
-    f->freq[NC].imag = sin(2.0*PI*FDMDV_FCENTRE/FS);
+    f->freq[Nc].real = cos(2.0*PI*FDMDV_FCENTRE/FS);
+    f->freq[Nc].imag = sin(2.0*PI*FDMDV_FCENTRE/FS);
 
     /* Generate DBPSK pilot Look Up Table (LUT) */
 
-    generate_pilot_lut(f->pilot_lut, &f->freq[NC]);
+    generate_pilot_lut(f->pilot_lut, &f->freq[Nc]);
 
     /* freq Offset estimation states */
 
@@ -223,7 +227,7 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void)
     f->coarse_fine = COARSE;
     f->bad_sync = 0;
 
-    for(c=0; c<NC+1; c++) {
+    for(c=0; c<Nc+1; c++) {
        f->sig_est[c] = 0.0;
        f->noise_est[c] = 0.0;
     }
index 391843f17a84f8c54bb12acf973ae84d272ad51a..d8a43b88ce7b3045f535c9509a4f2e1d3252ec8b 100644 (file)
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
     rx_spec_log = (float*)malloc(sizeof(float)*FDMDV_NSPEC*MAX_FRAMES);
     assert(rx_spec_log != NULL);
 
-    fdmdv = fdmdv_create();
+    fdmdv = fdmdv_create(FDMDV_NC);
     f = 0;
     state = 0;
     nin = FDMDV_NOM_SAMPLES_PER_FRAME;
index 3a18b8cae1ded15fb4e95f980a8ac61ea800c064..234dac34fcdb7dcf1533eaddfd47208ec9e2f924 100644 (file)
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
     numBits = atoi(argv[2]);
     nCodecFrames = numBits/BITS_PER_CODEC_FRAME;
 
-    fdmdv = fdmdv_create();
+    fdmdv = fdmdv_create(FDMDV_NC);
 
     for(n=0; n<nCodecFrames; n++) {
 
index b126bb9120c1234c3dc27e1527159ecc3ceba157..21a8732a044c8f277440e94f7a760cbdd7e6b852 100644 (file)
@@ -81,6 +81,9 @@
 \*---------------------------------------------------------------------------*/
 
 struct FDMDV {
+
+    int Nc;           
+
     /* test data (test frame) states */
 
     int  current_test_bit;
index 9339cf092dc36b1daca0961eb47b8c08a24bdc43..e60e7d3ed30bdb9424619c1f56fcc2a2d2db7e02 100644 (file)
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
        exit(1);
     }
 
-    fdmdv = fdmdv_create();
+    fdmdv = fdmdv_create(FDMDV_NC);
     frames = 0;
 
     while(fread(packed_bits, sizeof(char), BYTES_PER_CODEC_FRAME, fin) == BYTES_PER_CODEC_FRAME) {
index 4af6d7acf8d472f931ea3202db96f1c6ab9d3d54..b28bac79bc9539505ae2f6f4f25cc263c137f89d 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
        exit(1);
     }
 
-    fdmdv = fdmdv_create();
+    fdmdv = fdmdv_create(FDMDV_NC);
     total_bit_errors = 0;
     total_bits = 0;