2015-02-13 02:14:10 -08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* Copyright 2013-2015 The srsLTE Developers. See the
|
2015-02-13 02:14:10 -08:00
|
|
|
* COPYRIGHT file at the top-level directory of this distribution.
|
|
|
|
*
|
|
|
|
* \section LICENSE
|
|
|
|
*
|
2015-03-20 05:01:08 -07:00
|
|
|
* This file is part of the srsLTE library.
|
2015-02-13 02:14:10 -08:00
|
|
|
*
|
2015-03-20 05:01:08 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2015-05-08 08:05:40 -07:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2015-02-13 02:14:10 -08:00
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-03-20 05:01:08 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2015-02-13 02:14:10 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-05-08 08:05:40 -07:00
|
|
|
* GNU Affero General Public License for more details.
|
2015-02-13 02:14:10 -08:00
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
2015-02-13 02:14:10 -08:00
|
|
|
* 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>
|
|
|
|
|
2015-03-18 05:31:13 -07:00
|
|
|
#include "srslte/common/phy_common.h"
|
|
|
|
#include "srslte/utils/debug.h"
|
|
|
|
#include "srslte/utils/vector.h"
|
2015-03-18 11:14:24 -07:00
|
|
|
#include "srslte/dft/dft.h"
|
|
|
|
#include "srslte/dft/dft_precoding.h"
|
2015-02-13 02:14:10 -08:00
|
|
|
|
|
|
|
/* Create DFT plans for transform precoding */
|
2015-03-18 11:14:24 -07:00
|
|
|
int srslte_dft_precoding_init(srslte_dft_precoding_t *q, uint32_t max_prb)
|
2015-02-13 02:14:10 -08:00
|
|
|
{
|
2015-03-18 05:31:13 -07:00
|
|
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
2015-03-18 11:14:24 -07:00
|
|
|
bzero(q, sizeof(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) {
|
2015-03-18 05:31:13 -07:00
|
|
|
ret = SRSLTE_ERROR;
|
2015-06-19 04:10:37 -07:00
|
|
|
for (uint32_t i=1;i<=max_prb;i++) {
|
2015-03-18 11:14:24 -07:00
|
|
|
if(srslte_dft_precoding_valid_prb(i)) {
|
2015-02-14 05:20:16 -08:00
|
|
|
DEBUG("Initiating DFT precoding plan for %d PRBs\n", i);
|
2015-03-18 11:14:24 -07:00
|
|
|
if (srslte_dft_plan_c(&q->dft_plan[i], i*SRSLTE_NRE, SRSLTE_DFT_FORWARD)) {
|
2015-02-13 02:14:10 -08:00
|
|
|
fprintf(stderr, "Error: Creating DFT plan %d\n",i);
|
|
|
|
goto clean_exit;
|
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_dft_plan_set_norm(&q->dft_plan[i], true);
|
|
|
|
if (srslte_dft_plan_c(&q->idft_plan[i], i*SRSLTE_NRE, SRSLTE_DFT_BACKWARD)) {
|
2015-02-13 02:14:10 -08:00
|
|
|
fprintf(stderr, "Error: Creating DFT plan %d\n",i);
|
|
|
|
goto clean_exit;
|
2015-02-14 05:20:16 -08:00
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_dft_plan_set_norm(&q->idft_plan[i], true);
|
2015-02-13 02:14:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
q->max_prb = max_prb;
|
2015-03-18 05:31:13 -07:00
|
|
|
ret = SRSLTE_SUCCESS;
|
2015-02-13 02:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
clean_exit:
|
2015-03-18 05:31:13 -07:00
|
|
|
if (ret == SRSLTE_ERROR) {
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_dft_precoding_free(q);
|
2015-02-13 02:14:10 -08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free DFT plans for transform precoding */
|
2015-03-18 11:14:24 -07:00
|
|
|
void srslte_dft_precoding_free(srslte_dft_precoding_t *q)
|
2015-02-13 02:14:10 -08:00
|
|
|
{
|
2015-06-19 04:10:37 -07:00
|
|
|
for (uint32_t i=1;i<=q->max_prb;i++) {
|
2015-03-18 11:14:24 -07:00
|
|
|
if(srslte_dft_precoding_valid_prb(i)) {
|
2015-02-14 05:20:16 -08:00
|
|
|
DEBUG("Freeing DFT precoding plan for %d PRBs\n", i);
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_dft_plan_free(&q->dft_plan[i]);
|
|
|
|
srslte_dft_plan_free(&q->idft_plan[i]);
|
2015-02-13 02:14:10 -08:00
|
|
|
}
|
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
bzero(q, sizeof(srslte_dft_precoding_t));
|
2015-02-13 02:14:10 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
bool srslte_dft_precoding_valid_prb(uint32_t nof_prb) {
|
2015-07-05 03:35:53 -07:00
|
|
|
if (nof_prb > 0 &&
|
|
|
|
(nof_prb == 1 || (nof_prb%2) == 0 || (nof_prb%3) == 0 || (nof_prb%5) == 0))
|
|
|
|
{
|
2015-02-14 05:20:16 -08:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
int srslte_dft_precoding(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-06-19 04:10:37 -07:00
|
|
|
if (!srslte_dft_precoding_valid_prb(nof_prb) && nof_prb <= q->max_prb) {
|
2015-02-13 02:14:10 -08:00
|
|
|
fprintf(stderr, "Error invalid number of PRB (%d)\n", nof_prb);
|
2015-03-18 05:31:13 -07:00
|
|
|
return SRSLTE_ERROR;
|
2015-02-13 02:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i=0;i<nof_symbols;i++) {
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_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
|
|
|
}
|
|
|
|
|
2015-03-18 05:31:13 -07:00
|
|
|
return SRSLTE_SUCCESS;
|
2015-02-13 02:14:10 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
int srslte_dft_predecoding(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-06-19 04:10:37 -07:00
|
|
|
if (!srslte_dft_precoding_valid_prb(nof_prb) && nof_prb <= q->max_prb) {
|
2015-02-13 02:14:10 -08:00
|
|
|
fprintf(stderr, "Error invalid number of PRB (%d)\n", nof_prb);
|
2015-03-18 05:31:13 -07:00
|
|
|
return SRSLTE_ERROR;
|
2015-02-13 02:14:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i=0;i<nof_symbols;i++) {
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_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
|
|
|
}
|
|
|
|
|
2015-03-18 05:31:13 -07:00
|
|
|
return SRSLTE_SUCCESS;
|
2015-02-13 02:14:10 -08:00
|
|
|
|
|
|
|
}
|