Started kickoff work; Started refactoring to make OFDM configurable; started work...
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 3 Jan 2018 00:40:33 +0000 (00:40 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 3 Jan 2018 00:40:33 +0000 (00:40 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3387 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/codec2_ofdm.h
codec2-dev/src/ofdm.c
codec2-dev/src/ofdm_internal.h
codec2-dev/src/tdma.c
codec2-dev/src/tdma.h
codec2-dev/unittest/CMakeLists.txt
codec2-dev/unittest/tofdm.c

index 9abd1a3a8e86b712de9f6b1b83d37d86fe291fc6..b335df88f27cd9241b714c8f33d37a1b174b20a3 100644 (file)
@@ -43,9 +43,14 @@ extern "C" {
 
 struct OFDM;
 
+/* Constant declarations */
+
+/* Default configuration for '700D' mode */
+const struct OFDM_CONFIG * OFDM_CONFIG_700D;
+
 /* Prototypes */
 
-struct OFDM *ofdm_create(void);
+struct OFDM *ofdm_create(const struct OFDM_CONFIG * config);
 void ofdm_destroy(struct OFDM *);
 void ofdm_mod(struct OFDM *, COMP *, const int *);
 void ofdm_demod(struct OFDM *, int *, COMP *);
index e09089237e3f140a3857e2932a27104954d8104e..52079af44edd8e9bab464bfd30c86b41a7b9ef0f 100644 (file)
 #include "comp.h"
 #include "ofdm_internal.h"
 #include "codec2_ofdm.h"
+#include "kiss_fft.h"
+
+/* Concrete definition of 700D parameters */
+const struct OFDM_CONFIG OFDM_CONFIG_700D_C = 
+{.a = 0};
+
+/* Pointer to 700D config */ 
+const struct OFDM_CONFIG  * OFDM_CONFIG_700D = &OFDM_CONFIG_700D_C;
 
 /* Static Prototypes */
 
@@ -143,6 +151,8 @@ static complex float vector_sum(complex float *a, int num_elements) {
 static int coarse_sync(struct OFDM *ofdm, complex float *rx, int length) {
     complex float csam;
     int Ncorr = length - (OFDM_SAMPLESPERFRAME + (OFDM_M + OFDM_NCP));
+    int Fs = OFDM_FS;
+    int SFrame = OFDM_SAMPLESPERFRAME;
     float corr[Ncorr];
     int i, j;
 
@@ -152,7 +162,7 @@ static int coarse_sync(struct OFDM *ofdm, complex float *rx, int length) {
         for (j = 0; j < (OFDM_M + OFDM_NCP); j++) {
             csam = conjf(ofdm->pilot_samples[j]);
             temp = temp + (rx[i + j] * csam);
-            temp = temp + (rx[i + j + OFDM_SAMPLESPERFRAME] * csam);
+            temp = temp + (rx[i + j + SFrame] * csam);
         }
 
         corr[i] = cabsf(temp);
@@ -170,6 +180,14 @@ static int coarse_sync(struct OFDM *ofdm, complex float *rx, int length) {
         }
     }
 
+    /* Coarse frequency estimation */
+    /* TODO: Move FFT config to ofdm init and ofdm struct */
+    kiss_fft_cfg fftcfg = kiss_fft_alloc(Fs,0,NULL,NULL);
+    complex float fft_in[Fs];
+    complex float fft_out[Fs];
+    
+    
+
     return t_est;
 }
 
@@ -246,7 +264,7 @@ static void ofdm_txframe(struct OFDM *ofdm, complex float tx[OFDM_SAMPLESPERFRAM
  * Return NULL on fail
  */
 
-struct OFDM *ofdm_create() {
+struct OFDM *ofdm_create(const struct OFDM_CONFIG * config) {
     struct OFDM *ofdm;
     int i, j;
 
@@ -254,6 +272,9 @@ struct OFDM *ofdm_create() {
         return NULL;
     }
 
+    /* Copy config structure */
+    memcpy((void*)&ofdm->config,(void*)config,sizeof(struct OFDM_CONFIG));
+
     /* store complex BPSK pilot symbols */
 
     for (i = 0; i < (OFDM_NC + 2); i++) {
index 3ba9b69b27024268a83c533bf3cf7741ca2889a2..1a1c576f2f8548453cf5ccf014cd3d636917daf7 100644 (file)
@@ -35,25 +35,27 @@ extern "C" {
 #include <complex.h>
 #include <stdbool.h>
 
+#include "codec2_ofdm.h"
+
 #ifndef M_PI
 #define M_PI        3.14159265358979323846f  /* math constant */
 #endif
 
 #define TAU         (2.0f * M_PI)            /* mathematical constant */
 
-#define OFDM_NC     16
-#define OFDM_TS     0.018f
-#define OFDM_RS     (1.0f / OFDM_TS)
-#define OFDM_FS     8000.0f
-#define OFDM_BPS    2
-#define OFDM_TCP    0.002f
-#define OFDM_NS     8
-#define OFDM_CENTRE 1500.0f
+#define OFDM_NC     16                       /* N Carriers */
+#define OFDM_TS     0.018f                   /* Symbol time */
+#define OFDM_RS     (1.0f / OFDM_TS)         /* Symbol rate */
+#define OFDM_FS     8000.0f                  /* Sample rate */
+#define OFDM_BPS    2                        /* Bits per symbol */
+#define OFDM_TCP    0.002f                   /* ? */
+#define OFDM_NS     8                        /*  */
+#define OFDM_CENTRE 1500.0f                  /* Center frequency */
 
 /* To prevent C99 warning */
 
-#define OFDM_M      144
-#define OFDM_NCP    16
+#define OFDM_M      144                      /* Samples per bare symbol (?) */
+#define OFDM_NCP    16                       /* Samples per cyclic prefix */
 
 #ifdef OLD_STYLE
 /* This will produce a warning in C99 as (int) makes these variable */
@@ -62,14 +64,27 @@ extern "C" {
 #define OFDM_NCP    ((int)(OFDM_TCP * OFDM_FS))
 #endif
 
+/* ? */
 #define OFDM_FTWINDOWWIDTH       11
+/* Bits per frame (duh) */
 #define OFDM_BITSPERFRAME        ((OFDM_NS - 1) * (OFDM_NC * OFDM_BPS))
+/* Rows per frame */
 #define OFDM_ROWSPERFRAME        (OFDM_BITSPERFRAME / (OFDM_NC * OFDM_BPS))
+/* Samps per frame */
 #define OFDM_SAMPLESPERFRAME     (OFDM_NS * (OFDM_M + OFDM_NCP))
+
 #define OFDM_MAX_SAMPLESPERFRAME (OFDM_SAMPLESPERFRAME + (OFDM_M + OFDM_NCP)/4)
 #define OFDM_RXBUF               (3 * OFDM_SAMPLESPERFRAME + 3 * (OFDM_M + OFDM_NCP))
 
+
+/* Dummy struct for now, will contain constant configuration for OFDM modem */
+struct OFDM_CONFIG{
+  int a;
+};
+
+
 struct OFDM {
+    struct OFDM_CONFIG config;
     float foff_est_gain;
     float foff_est_hz;
 
index 59dae3940ac4094057c9c3bca3c556fd217c27ba..8be2a8a251161623d5064a971b283ed39d5d84a8 100644 (file)
@@ -35,7 +35,7 @@
 #include <stdbool.h>
 
 /* Easy handle to enable/disable a whole slew of debug printouts */
-#define VERY_DEBUG 1
+//#define VERY_DEBUG 1
 
 static const uint8_t TDMA_UW_V[] =    {0,1,1,0,0,1,1,1,
                                        1,0,1,0,1,1,0,1};
@@ -246,6 +246,7 @@ void tdma_do_tx_frame(tdma_t * tdma, int slot_idx){
     COMP mod_samps[(slot_size+1)*Ts];
     u8 frame_bits[frame_size_bits];
     u8 mod_bits[nbits];
+    u8 uw_type = 0;
     if(slot == NULL) return;
 
     /* Clear bit buffer */
@@ -253,18 +254,22 @@ void tdma_do_tx_frame(tdma_t * tdma, int slot_idx){
 
     /* Get a frame, or leave blank if call not setup */
     if(tdma->tx_callback != NULL){
-        int ret = tdma->tx_callback(frame_bits,slot_idx,slot,tdma,tdma->tx_cb_data);
+        int ret = tdma->tx_callback(frame_bits,slot_idx,slot,tdma,&uw_type,tdma->tx_cb_data);
         if(!ret){
             slot->state = rx_no_sync;
+            return;
         }
+        if(uw_type > 1)
+            uw_type = 0;
     }
 
     /* Copy frame bits to front of mod bit buffer */
     memcpy(&mod_bits[0],&frame_bits[0],frame_size_bits*sizeof(u8));
 
+    const u8 * uw = &(TDMA_UW_LIST_A[uw_type][0]);
     /* Copy UW into frame */
     size_t uw_offset = (frame_size_bits-mode.uw_len)/2;
-    memcpy(&mod_bits[uw_offset],&TDMA_UW_V[0],mode.uw_len*sizeof(u8));
+    memcpy(&mod_bits[uw_offset],uw,mode.uw_len*sizeof(u8));
 
     /* Modulate frame */
     fsk_mod_c(slot->fsk,mod_samps,mod_bits);
index 4cefdbcdb45f1690422e1ea1875e631940d2a0e3..4b3fe832a592ccfceacd024f7179a79589bc8387 100644 (file)
@@ -112,7 +112,7 @@ struct TDMA_MODE_SETTINGS {
 /* Declaration of basic 4800bps freedv tdma mode, defined in tdma.h */
 //struct TDMA_MODE_SETTINGS FREEDV_4800T;
 
-#define FREEDV_4800T {2400,4,48000,48,44,2,TDMA_FRAME_AT,16,2,2,2,2,6,3,5};
+#define FREEDV_4800T {2400,4,48000,48,44,2,TDMA_FRAME_A,16,2,2,2,2,6,3,5};
 
 /* Callback typedef that just returns the bits of the frame */
 /* TODO: write this a bit better */
@@ -121,7 +121,7 @@ typedef void (*tdma_cb_rx_frame)(u8* frame_bits,u32 slot_i, slot_t * slot, tdma_
 /* Callback typedef when TDMA is ready to schedule a new frame */
 /* Returns 1 if a frame is supplied, 0 if not */
 /* If no frame supplied, slot is changed out of TX mode */
-typedef int (*tdma_cb_tx_frame)(u8* frame_bits,u32 slot_i, slot_t * slot, tdma_t * tdma, void * cb_data);
+typedef int (*tdma_cb_tx_frame)(u8* frame_bits,u32 slot_i, slot_t * slot, tdma_t * tdma,u8 * uw_type, void * cb_data);
 
 /* Callback to the radio front end to schedule a burst of TX samples */
 typedef int (*tdma_cb_tx_burst)(tdma_t * tdma,COMP* samples, size_t n_samples,i64 timestamp,void * cb_data);
index 45fa5fb72f1214a291e260fa1c683b3922a90cf3..1c5719a455d77d2712aa68cbcd84fb2bed202853 100644 (file)
@@ -51,7 +51,7 @@ target_link_libraries(tfmfsk m)
 add_executable(tdeframer tdeframer.c)
 target_link_libraries(tdeframer m codec2)
 
-add_executable(tofdm tofdm.c ../src/ofdm.c ../src/octave.c)
+add_executable(tofdm tofdm.c ../src/ofdm.c ../src/octave.c ../src/kiss_fft.c)
 target_link_libraries(tofdm m)
 
 add_executable(tfreedv_data_channel tfreedv_data_channel.c)
index 115a86e3a96e708fd507a91c6e052f0b723173e0..2ffff9a2a04d719ffaee78038917acec7c98c408 100644 (file)
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
     FILE          *fout;
     int            f,i,j;
 
-    ofdm = ofdm_create();
+    ofdm = ofdm_create(OFDM_CONFIG_700D);
     assert(ofdm != NULL);
 
     /* Main Loop ---------------------------------------------------------------------*/