mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.4 KiB
C
92 lines
2.4 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
11 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
11 years ago
|
*
|
||
10 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
10 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
11 years ago
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
10 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
11 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
10 years ago
|
* GNU Affero General Public License for more details.
|
||
11 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
11 years ago
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <strings.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <math.h>
|
||
|
|
||
10 years ago
|
#include "srslte/utils/cexptab.h"
|
||
|
#include "srslte/sync/cfo.h"
|
||
|
#include "srslte/utils/vector.h"
|
||
|
#include "srslte/utils/debug.h"
|
||
11 years ago
|
|
||
10 years ago
|
int srslte_cfo_init(srslte_cfo_t *h, uint32_t nsamples) {
|
||
10 years ago
|
int ret = SRSLTE_ERROR;
|
||
10 years ago
|
bzero(h, sizeof(srslte_cfo_t));
|
||
11 years ago
|
|
||
10 years ago
|
if (srslte_cexptab_init(&h->tab, SRSLTE_CFO_CEXPTAB_SIZE)) {
|
||
11 years ago
|
goto clean;
|
||
|
}
|
||
10 years ago
|
h->cur_cexp = srslte_vec_malloc(sizeof(cf_t) * nsamples);
|
||
11 years ago
|
if (!h->cur_cexp) {
|
||
|
goto clean;
|
||
|
}
|
||
10 years ago
|
h->tol = SRSLTE_CFO_TOLERANCE;
|
||
11 years ago
|
h->last_freq = 0;
|
||
|
h->nsamples = nsamples;
|
||
10 years ago
|
srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, h->nsamples);
|
||
11 years ago
|
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
11 years ago
|
clean:
|
||
10 years ago
|
if (ret == SRSLTE_ERROR) {
|
||
10 years ago
|
srslte_cfo_free(h);
|
||
11 years ago
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_cfo_free(srslte_cfo_t *h) {
|
||
|
srslte_cexptab_free(&h->tab);
|
||
11 years ago
|
if (h->cur_cexp) {
|
||
|
free(h->cur_cexp);
|
||
|
}
|
||
|
bzero(h, sizeof(cf_t));
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_cfo_set_tol(srslte_cfo_t *h, float tol) {
|
||
11 years ago
|
h->tol = tol;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_cfo_realloc(srslte_cfo_t *h, uint32_t samples) {
|
||
11 years ago
|
h->cur_cexp = realloc(h->cur_cexp, sizeof(cf_t) * samples);
|
||
|
if (!h->cur_cexp) {
|
||
|
perror("realloc");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, samples);
|
||
11 years ago
|
h->nsamples = samples;
|
||
|
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_cfo_correct(srslte_cfo_t *h, cf_t *input, cf_t *output, float freq) {
|
||
11 years ago
|
if (fabs(h->last_freq - freq) > h->tol) {
|
||
|
h->last_freq = freq;
|
||
10 years ago
|
srslte_cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, h->nsamples);
|
||
9 years ago
|
DEBUG("CFO generating new table for frequency %.4fe-6\n", freq*1e6);
|
||
11 years ago
|
}
|
||
10 years ago
|
srslte_vec_prod_ccc(h->cur_cexp, input, output, h->nsamples);
|
||
11 years ago
|
}
|