adjusted ofdm levels to be the same as fdmdv - C
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 24 Apr 2018 07:02:49 +0000 (07:02 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 24 Apr 2018 07:02:49 +0000 (07:02 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3524 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/codec2_ofdm.h
codec2-dev/src/freedv_api.c
codec2-dev/src/ofdm_demod.c
codec2-dev/src/ofdm_mod.c

index d2a4b5a448e49bbfbc48cf098a712542845c4759..3fc69833e7d21f0f5583a54da7291bffcb30767a 100644 (file)
@@ -41,6 +41,8 @@ extern "C" {
 
 /* Defines */
 
+#define OFDM_AMP_SCALE (2E5*1.1491/1.06)   /* use to scale to 16 bit short */
+    
 struct OFDM;
 
 /* Default configuration for '700D' mode */
index eb21a47f4f5f1ef62af61cdac70f5efe0de537c7..2333abc2657a68ad4143216dd3504e87e73a3fe2 100644 (file)
  *              Changed all input and output sample rates to 8000 sps.  Rates for FREEDV_MODE_700 and 700B were 7500.
  */
 
-#define NORM_PWR_COHPSK  1.74   /* experimentally derived fudge factor to normalise power for cohpsk modes */
-#define NORM_PWR_FSK     0.193  /* experimentally derived fudge factor to normalise power for fsk modes    */
-#define NORM_PWR_OFDM    10.00  /* todo: experimentally derived fudge factor to normalise power for OFDM modes */
+/* experimentally derived fudge factors to normalise power across modes */
+
+#define NORM_PWR_COHPSK  1.74   
+#define NORM_PWR_FSK     0.193 
+#define NORM_PWR_OFDM    1.00
 
 /* OFDM payload data test frame for 700D */
 
@@ -927,7 +929,7 @@ static void freedv_comptx_700d(struct freedv *f, COMP mod_out[]) {
     for(i=0; i<f->n_nat_modem_samples; i++) {
         asam.real = crealf(tx_sams[i]);
         asam.imag = cimagf(tx_sams[i]);
-        mod_out[i] = fcmult(FDMDV_SCALE*NORM_PWR_OFDM, asam);
+        mod_out[i] = fcmult(OFDM_AMP_SCALE*NORM_PWR_OFDM, asam);
     }
 
     assert(f->clip == 0); /* todo: support clipping, requires some simulations and testing */
@@ -1110,10 +1112,16 @@ int freedv_rx(struct freedv *f, short speech_out[], short demod_in[]) {
     
     if ( (f->mode == FREEDV_MODE_1600) || (f->mode == FREEDV_MODE_700) || (f->mode == FREEDV_MODE_700B) ||
         (f->mode == FREEDV_MODE_700C) || (f->mode == FREEDV_MODE_700D)) {
+
+        float gain = 1.0;
+        if (f->mode == FREEDV_MODE_700D) {
+            gain = 2.0; /* keep levels the same as Octave simulations and C unit tests for real signals */
+        }
+        
         /* FDM RX happens with complex samps, so do that */
         COMP rx_fdm[f->n_max_modem_samples];
         for(i=0; i<nin; i++) {
-            rx_fdm[i].real = (float)demod_in[i];
+            rx_fdm[i].real = gain*(float)demod_in[i];
             rx_fdm[i].imag = 0.0;
         }
         return freedv_comprx(f, speech_out, rx_fdm);
@@ -1556,16 +1564,14 @@ static int freedv_comprx_700(struct freedv *f, COMP demod_in_8kHz[], int *valid)
   TODO: 
     [X] in testframe mode count coded and uncoded errors
     [X] freedv getter for modem and interleaver sync
+    [X] rms level the same as fdmdv
     [ ] way to stay in sync and not resync automatically 
     [ ] SNR est, maybe from pilots, cohpsk have an example?
     [ ] error pattern support?
     [ ] work out how to handle return of multiple interleaved frames over time
     [ ] deal with out of sync returning nin samples, listening to analog audio when out of sync
-    [ ] level issues
 */
 
-#define ASCALE   (2E5*1.1491/2.0)  /* scale from shorts back to floats       */
-
 static int freedv_comprx_700d(struct freedv *f, COMP demod_in_8kHz[], int *valid) {
     int   bits_per_codec_frame, bytes_per_codec_frame;
     int   i, j, bit, byte, nout, k;
@@ -1597,8 +1603,8 @@ static int freedv_comprx_700d(struct freedv *f, COMP demod_in_8kHz[], int *valid
     COMP rxbuf_in[f->nin];
 
     for(i=0; i<f->nin; i++) {
-        rxbuf_in[i].real = demod_in_8kHz[i].real/ASCALE;
-        rxbuf_in[i].imag = demod_in_8kHz[i].imag/ASCALE;
+        rxbuf_in[i].real = demod_in_8kHz[i].real/OFDM_AMP_SCALE;
+        rxbuf_in[i].imag = demod_in_8kHz[i].imag/OFDM_AMP_SCALE;
     }
     
     /* echo samples back out as default (say if sync not found) */
@@ -1607,7 +1613,7 @@ static int freedv_comprx_700d(struct freedv *f, COMP demod_in_8kHz[], int *valid
 
     /* TODO estimate this properly from signal */
     
-    float EsNo = 10.0;
+    float EsNo = 3.0;
     
     /* looking for modem sync */
     
@@ -1621,7 +1627,7 @@ static int freedv_comprx_700d(struct freedv *f, COMP demod_in_8kHz[], int *valid
         ofdm_demod(ofdm, rx_bits, rxbuf_in);
           
         assert((OFDM_NUWBITS+OFDM_NTXTBITS+coded_bits_per_frame) == OFDM_BITSPERFRAME);
-
+t
         /* now we need to buffer for de-interleaving -------------------------------------*/
                 
         /* shift interleaved symbol buffers to make room for new symbols */
index 3c00cad046aa5357c4e7aeeb57ed2badb93f7096..199e6f71dbd5fea1d753495e29d323b6a4ef10f4 100644 (file)
@@ -46,7 +46,6 @@
 #include "gp_interleaver.h"
 #include "interldpc.h"
 
-#define ASCALE   (2E5*1.1491/2.0)  /* scale from shorts back to floats       */
 #define NFRAMES  100               /* just log the first 100 frames          */
 #define NDISCARD 20                /* BER2measure disctrds first 20 frames   */
 
@@ -198,7 +197,7 @@ int main(int argc, char *argv[])
        /* scale and demod */
 
        for(i=0; i<nin_frame; i++) {
-           rxbuf_in[i].real = (float)rx_scaled[i]/ASCALE;
+           rxbuf_in[i].real = (float)rx_scaled[i]/(OFDM_AMP_SCALE/2);
             rxbuf_in[i].imag = 0.0;
         }
 
index 504c7fcaf1e9310db475f0760a5a4340e93b9932..582a406acd0bbc6a752733e6c33bbc4064a3f577 100644 (file)
@@ -39,8 +39,6 @@
 #include "interldpc.h"
 #include "gp_interleaver.h"
 
-#define ASCALE (2E5*1.1491)
-
 extern int payload_data_bits[];
 extern int test_bits_ofdm[];
 
@@ -161,7 +159,7 @@ int main(int argc, char *argv[])
 
             for (j=0; j<interleave_frames; j++) {            
                 for(i=0; i<Nsamperframe; i++) {
-                    tx_scaled[i] = ASCALE * crealf(tx_sams[j*Nsamperframe+i]);
+                    tx_scaled[i] = OFDM_AMP_SCALE * crealf(tx_sams[j*Nsamperframe+i]);
                 }
                 fwrite(tx_scaled, sizeof(short), Nsamperframe, fout);
                 frames++;
@@ -185,7 +183,7 @@ int main(int argc, char *argv[])
             /* scale and save to disk as shorts */
 
             for(i=0; i<Nsamperframe; i++)
-                tx_scaled[i] = ASCALE * tx_sams[i].real;
+                tx_scaled[i] = OFDM_AMP_SCALE * tx_sams[i].real;
 
             fwrite(tx_scaled, sizeof(short), Nsamperframe, fout);
             frames++;