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.
130 lines
3.8 KiB
C
130 lines
3.8 KiB
C
10 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
10 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
10 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
|
||
10 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,
|
||
10 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.
|
||
10 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
10 years ago
|
* 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>
|
||
|
|
||
10 years ago
|
#include "srslte/common/phy_common.h"
|
||
|
#include "srslte/utils/debug.h"
|
||
|
#include "srslte/utils/vector.h"
|
||
10 years ago
|
#include "srslte/dft/dft.h"
|
||
|
#include "srslte/dft/dft_precoding.h"
|
||
10 years ago
|
|
||
|
/* Create DFT plans for transform precoding */
|
||
10 years ago
|
int srslte_dft_precoding_init(srslte_dft_precoding_t *q, uint32_t max_prb)
|
||
10 years ago
|
{
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
bzero(q, sizeof(srslte_dft_precoding_t));
|
||
10 years ago
|
|
||
10 years ago
|
if (max_prb <= SRSLTE_MAX_PRB) {
|
||
10 years ago
|
ret = SRSLTE_ERROR;
|
||
10 years ago
|
for (uint32_t i=1;i<=max_prb;i++) {
|
||
10 years ago
|
if(srslte_dft_precoding_valid_prb(i)) {
|
||
10 years ago
|
DEBUG("Initiating DFT precoding plan for %d PRBs\n", i);
|
||
10 years ago
|
if (srslte_dft_plan_c(&q->dft_plan[i], i*SRSLTE_NRE, SRSLTE_DFT_FORWARD)) {
|
||
10 years ago
|
fprintf(stderr, "Error: Creating DFT plan %d\n",i);
|
||
|
goto clean_exit;
|
||
|
}
|
||
10 years ago
|
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)) {
|
||
10 years ago
|
fprintf(stderr, "Error: Creating DFT plan %d\n",i);
|
||
|
goto clean_exit;
|
||
10 years ago
|
}
|
||
10 years ago
|
srslte_dft_plan_set_norm(&q->idft_plan[i], true);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
q->max_prb = max_prb;
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
}
|
||
|
|
||
|
clean_exit:
|
||
10 years ago
|
if (ret == SRSLTE_ERROR) {
|
||
10 years ago
|
srslte_dft_precoding_free(q);
|
||
10 years ago
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
/* Free DFT plans for transform precoding */
|
||
10 years ago
|
void srslte_dft_precoding_free(srslte_dft_precoding_t *q)
|
||
10 years ago
|
{
|
||
10 years ago
|
for (uint32_t i=1;i<=q->max_prb;i++) {
|
||
10 years ago
|
if(srslte_dft_precoding_valid_prb(i)) {
|
||
10 years ago
|
DEBUG("Freeing DFT precoding plan for %d PRBs\n", i);
|
||
10 years ago
|
srslte_dft_plan_free(&q->dft_plan[i]);
|
||
|
srslte_dft_plan_free(&q->idft_plan[i]);
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
bzero(q, sizeof(srslte_dft_precoding_t));
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
bool srslte_dft_precoding_valid_prb(uint32_t nof_prb) {
|
||
9 years ago
|
if (nof_prb > 0 &&
|
||
|
(nof_prb == 1 || (nof_prb%2) == 0 || (nof_prb%3) == 0 || (nof_prb%5) == 0))
|
||
|
{
|
||
10 years ago
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
int srslte_dft_precoding(srslte_dft_precoding_t *q, cf_t *input, cf_t *output,
|
||
10 years ago
|
uint32_t nof_prb, uint32_t nof_symbols)
|
||
|
{
|
||
|
|
||
10 years ago
|
if (!srslte_dft_precoding_valid_prb(nof_prb) && nof_prb <= q->max_prb) {
|
||
10 years ago
|
fprintf(stderr, "Error invalid number of PRB (%d)\n", nof_prb);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
|
||
|
for (uint32_t i=0;i<nof_symbols;i++) {
|
||
10 years ago
|
srslte_dft_run_c(&q->dft_plan[nof_prb], &input[i*SRSLTE_NRE*nof_prb], &output[i*SRSLTE_NRE*nof_prb]);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_dft_predecoding(srslte_dft_precoding_t *q, cf_t *input, cf_t *output,
|
||
10 years ago
|
uint32_t nof_prb, uint32_t nof_symbols)
|
||
|
{
|
||
10 years ago
|
if (!srslte_dft_precoding_valid_prb(nof_prb) && nof_prb <= q->max_prb) {
|
||
10 years ago
|
fprintf(stderr, "Error invalid number of PRB (%d)\n", nof_prb);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
|
||
|
for (uint32_t i=0;i<nof_symbols;i++) {
|
||
10 years ago
|
srslte_dft_run_c(&q->dft_plan[nof_prb], &input[i*SRSLTE_NRE*nof_prb], &output[i*SRSLTE_NRE*nof_prb]);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
10 years ago
|
|
||
9 years ago
|
}
|