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.
81 lines
2.0 KiB
C
81 lines
2.0 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>
|
||
|
|
||
11 years ago
|
#include "liblte/phy/utils/cexptab.h"
|
||
|
#include "liblte/phy/sync/cfo.h"
|
||
|
#include "liblte/phy/utils/vector.h"
|
||
|
#include "liblte/phy/utils/debug.h"
|
||
11 years ago
|
|
||
|
int cfo_init(cfo_t *h, int nsamples) {
|
||
11 years ago
|
int ret = -1;
|
||
|
bzero(h, sizeof(cfo_t));
|
||
11 years ago
|
|
||
11 years ago
|
if (cexptab_init(&h->tab, CFO_CEXPTAB_SIZE)) {
|
||
|
goto clean;
|
||
|
}
|
||
|
h->cur_cexp = malloc(sizeof(cf_t) * nsamples);
|
||
|
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
|
|
||
11 years ago
|
ret = 0;
|
||
11 years ago
|
clean:
|
||
11 years ago
|
if (ret == -1) {
|
||
|
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
|
}
|
||
|
|
||
|
void cfo_correct(cfo_t *h, cf_t *x, 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);
|
||
|
INFO("CFO generating new table for frequency %.4f\n", freq);
|
||
|
}
|
||
|
vec_prod_ccc(h->cur_cexp, x, x, h->nsamples);
|
||
11 years ago
|
}
|