srsLTE/srslte/lib/filter/src/dft_precoding.c

128 lines
3.8 KiB
C
Raw Normal View History

2015-02-13 02:14:10 -08:00
/**
*
* \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 <stdint.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <math.h>
#include "srslte/common/phy_common.h"
#include "srslte/utils/debug.h"
#include "srslte/utils/vector.h"
#include "srslte/utils/dft.h"
#include "srslte/filter/dft_precoding.h"
2015-02-13 02:14:10 -08:00
/* Create DFT plans for transform precoding */
2015-03-18 08:05:38 -07:00
int srslte_srslte_dft_precoding_init(srslte_srslte_dft_precoding_t *q, uint32_t max_prb)
2015-02-13 02:14:10 -08:00
{
int ret = SRSLTE_ERROR_INVALID_INPUTS;
2015-03-18 08:05:38 -07:00
bzero(q, sizeof(srslte_srslte_dft_precoding_t));
2015-02-13 02:14:10 -08:00
2015-03-18 05:59:29 -07:00
if (max_prb <= SRSLTE_MAX_PRB) {
ret = SRSLTE_ERROR;
2015-02-15 23:55:17 -08:00
for (uint32_t i=1;i<max_prb;i++) {
2015-03-18 08:05:38 -07:00
if(srslte_srslte_dft_precoding_valid_prb(i)) {
DEBUG("Initiating DFT precoding plan for %d PRBs\n", i);
2015-03-18 05:59:29 -07:00
if (dft_plan_c(&q->dft_plan[i], i*SRSLTE_NRE, FORWARD)) {
2015-02-13 02:14:10 -08:00
fprintf(stderr, "Error: Creating DFT plan %d\n",i);
goto clean_exit;
}
dft_plan_set_norm(&q->dft_plan[i], true);
2015-03-18 05:59:29 -07:00
if (dft_plan_c(&q->idft_plan[i], i*SRSLTE_NRE, BACKWARD)) {
2015-02-13 02:14:10 -08:00
fprintf(stderr, "Error: Creating DFT plan %d\n",i);
goto clean_exit;
}
dft_plan_set_norm(&q->idft_plan[i], true);
2015-02-13 02:14:10 -08:00
}
}
q->max_prb = max_prb;
ret = SRSLTE_SUCCESS;
2015-02-13 02:14:10 -08:00
}
clean_exit:
if (ret == SRSLTE_ERROR) {
2015-03-18 08:05:38 -07:00
srslte_srslte_dft_precoding_free(q);
2015-02-13 02:14:10 -08:00
}
return ret;
}
/* Free DFT plans for transform precoding */
2015-03-18 08:05:38 -07:00
void srslte_srslte_dft_precoding_free(srslte_srslte_dft_precoding_t *q)
2015-02-13 02:14:10 -08:00
{
2015-02-15 23:55:17 -08:00
for (uint32_t i=1;i<q->max_prb;i++) {
2015-03-18 08:05:38 -07:00
if(srslte_srslte_dft_precoding_valid_prb(i)) {
DEBUG("Freeing DFT precoding plan for %d PRBs\n", i);
2015-02-13 02:14:10 -08:00
dft_plan_free(&q->dft_plan[i]);
dft_plan_free(&q->idft_plan[i]);
}
}
2015-03-18 08:05:38 -07:00
bzero(q, sizeof(srslte_srslte_dft_precoding_t));
2015-02-13 02:14:10 -08:00
}
2015-03-18 08:05:38 -07:00
bool srslte_srslte_dft_precoding_valid_prb(uint32_t nof_prb) {
2015-02-15 23:55:17 -08:00
if (nof_prb == 1 || (nof_prb%2) == 0 || (nof_prb%3) == 0 || (nof_prb%5) == 0) {
return true;
} else {
return false;
}
}
2015-03-18 08:05:38 -07:00
int srslte_dft_precoding(srslte_srslte_dft_precoding_t *q, cf_t *input, cf_t *output,
2015-02-13 02:14:10 -08:00
uint32_t nof_prb, uint32_t nof_symbols)
{
2015-03-18 08:05:38 -07:00
if (!srslte_srslte_dft_precoding_valid_prb(nof_prb)) {
2015-02-13 02:14:10 -08:00
fprintf(stderr, "Error invalid number of PRB (%d)\n", nof_prb);
return SRSLTE_ERROR;
2015-02-13 02:14:10 -08:00
}
for (uint32_t i=0;i<nof_symbols;i++) {
2015-03-18 05:59:29 -07:00
dft_run_c(&q->dft_plan[nof_prb], &input[i*SRSLTE_NRE*nof_prb], &output[i*SRSLTE_NRE*nof_prb]);
2015-02-13 02:14:10 -08:00
}
return SRSLTE_SUCCESS;
2015-02-13 02:14:10 -08:00
}
2015-03-18 08:05:38 -07:00
int srslte_dft_predecoding(srslte_srslte_dft_precoding_t *q, cf_t *input, cf_t *output,
2015-02-13 02:14:10 -08:00
uint32_t nof_prb, uint32_t nof_symbols)
{
2015-03-18 08:05:38 -07:00
if (!srslte_srslte_dft_precoding_valid_prb(nof_prb)) {
2015-02-13 02:14:10 -08:00
fprintf(stderr, "Error invalid number of PRB (%d)\n", nof_prb);
return SRSLTE_ERROR;
2015-02-13 02:14:10 -08:00
}
for (uint32_t i=0;i<nof_symbols;i++) {
2015-03-18 05:59:29 -07:00
dft_run_c(&q->dft_plan[nof_prb], &input[i*SRSLTE_NRE*nof_prb], &output[i*SRSLTE_NRE*nof_prb]);
2015-02-13 02:14:10 -08:00
}
return SRSLTE_SUCCESS;
2015-02-13 02:14:10 -08:00
}