From: baobrien Date: Wed, 3 Jan 2018 00:40:33 +0000 (+0000) Subject: Started kickoff work; Started refactoring to make OFDM configurable; started work... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=afb72cc130853fd4228226f21876af1291f29df8;p=freetel-svn-tracking.git Started kickoff work; Started refactoring to make OFDM configurable; started work on OFDM freq est git-svn-id: https://svn.code.sf.net/p/freetel/code@3387 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/codec2_ofdm.h b/codec2-dev/src/codec2_ofdm.h index 9abd1a3a..b335df88 100644 --- a/codec2-dev/src/codec2_ofdm.h +++ b/codec2-dev/src/codec2_ofdm.h @@ -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 *); diff --git a/codec2-dev/src/ofdm.c b/codec2-dev/src/ofdm.c index e0908923..52079af4 100644 --- a/codec2-dev/src/ofdm.c +++ b/codec2-dev/src/ofdm.c @@ -37,6 +37,14 @@ #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++) { diff --git a/codec2-dev/src/ofdm_internal.h b/codec2-dev/src/ofdm_internal.h index 3ba9b69b..1a1c576f 100644 --- a/codec2-dev/src/ofdm_internal.h +++ b/codec2-dev/src/ofdm_internal.h @@ -35,25 +35,27 @@ extern "C" { #include #include +#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; diff --git a/codec2-dev/src/tdma.c b/codec2-dev/src/tdma.c index 59dae394..8be2a8a2 100644 --- a/codec2-dev/src/tdma.c +++ b/codec2-dev/src/tdma.c @@ -35,7 +35,7 @@ #include /* 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); diff --git a/codec2-dev/src/tdma.h b/codec2-dev/src/tdma.h index 4cefdbcd..4b3fe832 100644 --- a/codec2-dev/src/tdma.h +++ b/codec2-dev/src/tdma.h @@ -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); diff --git a/codec2-dev/unittest/CMakeLists.txt b/codec2-dev/unittest/CMakeLists.txt index 45fa5fb7..1c5719a4 100644 --- a/codec2-dev/unittest/CMakeLists.txt +++ b/codec2-dev/unittest/CMakeLists.txt @@ -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) diff --git a/codec2-dev/unittest/tofdm.c b/codec2-dev/unittest/tofdm.c index 115a86e3..2ffff9a2 100644 --- a/codec2-dev/unittest/tofdm.c +++ b/codec2-dev/unittest/tofdm.c @@ -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 ---------------------------------------------------------------------*/