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 *);
#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 */
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;
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);
}
}
+ /* 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;
}
* Return NULL on fail
*/
-struct OFDM *ofdm_create() {
+struct OFDM *ofdm_create(const struct OFDM_CONFIG * config) {
struct OFDM *ofdm;
int i, j;
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++) {
#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 */
#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;
#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};
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 */
/* 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);
/* 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 */
/* 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);
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)
FILE *fout;
int f,i,j;
- ofdm = ofdm_create();
+ ofdm = ofdm_create(OFDM_CONFIG_700D);
assert(ofdm != NULL);
/* Main Loop ---------------------------------------------------------------------*/