|
|
@ -34,7 +34,11 @@
|
|
|
|
#include "srslte/phy/utils/vector.h"
|
|
|
|
#include "srslte/phy/utils/vector.h"
|
|
|
|
#include "srslte/phy/utils/debug.h"
|
|
|
|
#include "srslte/phy/utils/debug.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Set next macro to 1 for using table generated CFO compensation */
|
|
|
|
|
|
|
|
#define SRSLTE_CFO_USE_EXP_TABLE 0
|
|
|
|
|
|
|
|
|
|
|
|
int srslte_cfo_init(srslte_cfo_t *h, uint32_t nsamples) {
|
|
|
|
int srslte_cfo_init(srslte_cfo_t *h, uint32_t nsamples) {
|
|
|
|
|
|
|
|
#if SRSLTE_CFO_USE_EXP_TABLE
|
|
|
|
int ret = SRSLTE_ERROR;
|
|
|
|
int ret = SRSLTE_ERROR;
|
|
|
|
bzero(h, sizeof(srslte_cfo_t));
|
|
|
|
bzero(h, sizeof(srslte_cfo_t));
|
|
|
|
|
|
|
|
|
|
|
@ -57,13 +61,19 @@ clean:
|
|
|
|
srslte_cfo_free(h);
|
|
|
|
srslte_cfo_free(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
#else /* SRSLTE_CFO_USE_EXP_TABLE */
|
|
|
|
|
|
|
|
h->nsamples = nsamples;
|
|
|
|
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
|
|
|
|
#endif /* SRSLTE_CFO_USE_EXP_TABLE */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_cfo_free(srslte_cfo_t *h) {
|
|
|
|
void srslte_cfo_free(srslte_cfo_t *h) {
|
|
|
|
|
|
|
|
#if SRSLTE_CFO_USE_EXP_TABLE
|
|
|
|
srslte_cexptab_free(&h->tab);
|
|
|
|
srslte_cexptab_free(&h->tab);
|
|
|
|
if (h->cur_cexp) {
|
|
|
|
if (h->cur_cexp) {
|
|
|
|
free(h->cur_cexp);
|
|
|
|
free(h->cur_cexp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SRSLTE_CFO_USE_EXP_TABLE */
|
|
|
|
bzero(h, sizeof(srslte_cfo_t));
|
|
|
|
bzero(h, sizeof(srslte_cfo_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -72,6 +82,7 @@ void srslte_cfo_set_tol(srslte_cfo_t *h, float tol) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int srslte_cfo_resize(srslte_cfo_t *h, uint32_t samples) {
|
|
|
|
int srslte_cfo_resize(srslte_cfo_t *h, uint32_t samples) {
|
|
|
|
|
|
|
|
#if SRSLTE_CFO_USE_EXP_TABLE
|
|
|
|
if (samples <= h->max_samples) {
|
|
|
|
if (samples <= h->max_samples) {
|
|
|
|
srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, samples);
|
|
|
|
srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, samples);
|
|
|
|
h->nsamples = samples;
|
|
|
|
h->nsamples = samples;
|
|
|
@ -79,15 +90,19 @@ int srslte_cfo_resize(srslte_cfo_t *h, uint32_t samples) {
|
|
|
|
fprintf(stderr, "Error in cfo_resize(): nof_samples must be lower than initialized\n");
|
|
|
|
fprintf(stderr, "Error in cfo_resize(): nof_samples must be lower than initialized\n");
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SRSLTE_CFO_USE_EXP_TABLE */
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_cfo_correct(srslte_cfo_t *h, const cf_t *input, cf_t *output, float freq) {
|
|
|
|
void srslte_cfo_correct(srslte_cfo_t *h, const cf_t *input, cf_t *output, float freq) {
|
|
|
|
|
|
|
|
#if SRSLTE_CFO_USE_EXP_TABLE
|
|
|
|
if (fabs(h->last_freq - freq) > h->tol) {
|
|
|
|
if (fabs(h->last_freq - freq) > h->tol) {
|
|
|
|
h->last_freq = freq;
|
|
|
|
h->last_freq = freq;
|
|
|
|
srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, h->nsamples);
|
|
|
|
srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, h->nsamples);
|
|
|
|
DEBUG("CFO generating new table for frequency %.4fe-6\n", freq*1e6);
|
|
|
|
DEBUG("CFO generating new table for frequency %.4fe-6\n", freq*1e6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srslte_vec_prod_ccc(h->cur_cexp, input, output, h->nsamples);
|
|
|
|
srslte_vec_prod_ccc(h->cur_cexp, input, output, h->nsamples);
|
|
|
|
|
|
|
|
#else /* SRSLTE_CFO_USE_EXP_TABLE */
|
|
|
|
|
|
|
|
srslte_vec_apply_cfo(input, freq, output, h->nsamples);
|
|
|
|
|
|
|
|
#endif /* SRSLTE_CFO_USE_EXP_TABLE */
|
|
|
|
}
|
|
|
|
}
|
|
|
|