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.
93 lines
2.4 KiB
C
93 lines
2.4 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
|
* Copyright 2013-2014 The libLTE Developers. See the
|
||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
|
* This file is part of the libLTE library.
|
||
|
*
|
||
|
* libLTE is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Lesser General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
|
* libLTE is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Lesser General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Lesser General Public License can be found in
|
||
|
* 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/phy/utils/cexptab.h"
|
||
|
#include "srslte/phy/sync/cfo.h"
|
||
|
#include "srslte/phy/utils/vector.h"
|
||
|
#include "srslte/phy/utils/debug.h"
|
||
11 years ago
|
|
||
10 years ago
|
int cfo_init(cfo_t *h, uint32_t nsamples) {
|
||
|
int ret = LIBLTE_ERROR;
|
||
11 years ago
|
bzero(h, sizeof(cfo_t));
|
||
11 years ago
|
|
||
11 years ago
|
if (cexptab_init(&h->tab, CFO_CEXPTAB_SIZE)) {
|
||
|
goto clean;
|
||
|
}
|
||
10 years ago
|
h->cur_cexp = vec_malloc(sizeof(cf_t) * nsamples);
|
||
11 years ago
|
if (!h->cur_cexp) {
|
||
|
goto clean;
|
||
|
}
|
||
|
h->tol = CFO_TOLERANCE;
|
||
|
h->last_freq = 0;
|
||
|
h->nsamples = nsamples;
|
||
|
cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, h->nsamples);
|
||
11 years ago
|
|
||
10 years ago
|
ret = LIBLTE_SUCCESS;
|
||
11 years ago
|
clean:
|
||
10 years ago
|
if (ret == LIBLTE_ERROR) {
|
||
11 years ago
|
cfo_free(h);
|
||
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
|
|
||
|
void cfo_free(cfo_t *h) {
|
||
11 years ago
|
cexptab_free(&h->tab);
|
||
|
if (h->cur_cexp) {
|
||
|
free(h->cur_cexp);
|
||
|
}
|
||
|
bzero(h, sizeof(cf_t));
|
||
11 years ago
|
}
|
||
|
|
||
|
void cfo_set_tol(cfo_t *h, float tol) {
|
||
11 years ago
|
h->tol = tol;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int cfo_realloc(cfo_t *h, uint32_t samples) {
|
||
|
h->cur_cexp = realloc(h->cur_cexp, sizeof(cf_t) * samples);
|
||
|
if (!h->cur_cexp) {
|
||
|
perror("realloc");
|
||
|
return LIBLTE_ERROR;
|
||
|
}
|
||
|
cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, samples);
|
||
|
h->nsamples = samples;
|
||
|
|
||
|
return LIBLTE_SUCCESS;
|
||
|
}
|
||
|
|
||
|
void cfo_correct(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;
|
||
|
cexptab_gen(&h->tab, h->cur_cexp, h->last_freq, h->nsamples);
|
||
10 years ago
|
DEBUG("CFO generating new table for frequency %.4f\n", freq);
|
||
11 years ago
|
}
|
||
10 years ago
|
vec_prod_ccc(h->cur_cexp, input, output, h->nsamples);
|
||
11 years ago
|
}
|