From 35d28f0dea9a5bd6f12dd12ac5751880ab1ac059 Mon Sep 17 00:00:00 2001 From: baobrien Date: Sun, 4 Dec 2016 04:24:43 +0000 Subject: [PATCH] Added hann table compile option to fsk git-svn-id: https://svn.code.sf.net/p/freetel/code@2917 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/fsk.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ codec2-dev/src/fsk.h | 7 +++-- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/codec2-dev/src/fsk.c b/codec2-dev/src/fsk.c index 89017e8c..700437bf 100644 --- a/codec2-dev/src/fsk.c +++ b/codec2-dev/src/fsk.c @@ -41,6 +41,27 @@ /* This is a flag to make the mod/demod allocate their memory on the stack instead of the heap */ /* At large sample rates, there's not enough stack space to run the demod */ #define DEMOD_ALLOC_STACK + +/* This is a flag for the freq. estimator to use a precomputed/rt computed hann window table + On platforms with slow cosf, this will produce a substantial speedup at the cost of a small + amount of memory +*/ +#define USE_HANN_TABLE + +/* This flag turns on run-time hann table generation. If USE_HANN_TABLE is unset, + this flag has no effect. If USE_HANN_TABLE is set and this flag is set, the + hann table will be allocated and generated when fsk_init or fsk_init_hbr is + called. If this flag is not set, a hann function table of size fsk->Ndft MUST + be provided. On small platforms, this can be used with a precomputed table to + save memory at the cost of flash space. +*/ +#define GENERATE_HANN_TABLE_RUNTIME + +/* Turn off table generation if on cortex M4 to save memory */ +#ifdef CORTEX_M4 +#undef USE_HANN_TABLE +#endif + /*---------------------------------------------------------------------------*\ INCLUDES @@ -112,6 +133,19 @@ static inline COMP comp_normalize(COMP a){ return b; } +#ifdef USE_HANN_TABLE +/* + This is used by fsk_create and fsk_create_hbr to generate a hann function + table +*/ +static void fsk_generate_hann_table(struct FSK* fsk){ + int Ndft = fsk->Ndft; + for(size_t i=0; ihann_table[i] = hann; + } +} +#endif /*---------------------------------------------------------------------------*\ @@ -212,6 +246,22 @@ struct FSK * fsk_create_hbr(int Fs, int Rs,int P,int M, int tx_f1, int tx_fs) return NULL; } + #ifdef USE_HANN_TABLE + #ifdef GENERATE_HANN_TABLE_RUNTIME + fsk->hann_table = (float*)malloc(sizeof(float)*fsk->Ndft); + if(fsk->hann_table == NULL){ + free(fsk->fft_est); + free(fsk->samp_old); + free(fsk->fft_cfg); + free(fsk); + return NULL; + } + fsk_generate_hann_table(fsk); + #else + fsk->hann_table = NULL; + #endif + #endif + for(i=0;iNdft/2;i++)fsk->fft_est[i] = 0; fsk->norm_rx_timing = 0; @@ -323,6 +373,22 @@ struct FSK * fsk_create(int Fs, int Rs,int M, int tx_f1, int tx_fs) return NULL; } + #ifdef USE_HANN_TABLE + #ifdef GENERATE_HANN_TABLE_RUNTIME + fsk->hann_table = (float*)malloc(sizeof(float)*fsk->Ndft); + if(fsk->hann_table == NULL){ + free(fsk->fft_est); + free(fsk->samp_old); + free(fsk->fft_cfg); + free(fsk); + return NULL; + } + fsk_generate_hann_table(fsk); + #else + fsk->hann_table = NULL; + #endif + #endif + for(i=0;ifft_est[i] = 0; fsk->norm_rx_timing = 0; @@ -456,7 +522,11 @@ void fsk_demod_freq_est(struct FSK *fsk, COMP fsk_in[],float *freqs,int M){ for(j=0; jhann_table[i]; + #else hann = 1-cosf((2*M_PI*(float)(i))/((float)fft_samps-1)); + #endif fftin[i].r = 0.5*hann*fsk_in[i+Ndft*j].real; fftin[i].i = 0.5*hann*fsk_in[i+Ndft*j].imag; } diff --git a/codec2-dev/src/fsk.h b/codec2-dev/src/fsk.h index 1ca53ee7..c156138f 100644 --- a/codec2-dev/src/fsk.h +++ b/codec2-dev/src/fsk.h @@ -57,17 +57,18 @@ struct FSK { int est_min; /* Minimum frequency for freq. estimator */ int est_max; /* Maximum frequency for freq. estimaotr */ int est_space; /* Minimum frequency spacing for freq. estimator */ + float* hann_table; /* Precomputed or runtime computed hann window table */ /* Parameters used by demod */ COMP phi_c[MODE_M_MAX]; - kiss_fft_cfg fft_cfg; /* Config for KISS FFT, used in freq est */ + kiss_fft_cfg fft_cfg; /* Config for KISS FFT, used in freq est */ float norm_rx_timing; /* Normalized RX timing */ - COMP *samp_old; /* Tail end of last batch of samples */ + COMP* samp_old; /* Tail end of last batch of samples */ int nstash; /* How many elements are in there */ - float *fft_est; /* Freq est FFT magnitude */ + float* fft_est; /* Freq est FFT magnitude */ /* Memory used by demod but not important between demod frames */ -- 2.25.1