mirror of https://github.com/pvnis/srsRAN_4G.git
Started implementing PUCCH
parent
4cdbd9bd83
commit
6d8540441a
@ -0,0 +1,109 @@
|
||||
/**
|
||||
*
|
||||
* \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/.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PUCCH_
|
||||
#define PUCCH_
|
||||
|
||||
#include "liblte/config.h"
|
||||
#include "liblte/phy/common/phy_common.h"
|
||||
#include "liblte/phy/mimo/precoding.h"
|
||||
#include "liblte/phy/mimo/layermap.h"
|
||||
#include "liblte/phy/modem/mod.h"
|
||||
#include "liblte/phy/modem/demod_soft.h"
|
||||
#include "liblte/phy/scrambling/scrambling.h"
|
||||
#include "liblte/phy/phch/regs.h"
|
||||
#include "liblte/phy/phch/sch.h"
|
||||
#include "liblte/phy/phch/harq.h"
|
||||
#include "liblte/phy/filter/dft_precoding.h"
|
||||
|
||||
#define TDEC_MAX_ITERATIONS 5
|
||||
|
||||
typedef _Complex float cf_t;
|
||||
|
||||
#define PUCCH_N_SEQ 12 // Only Format 1, 1a and 1b supported
|
||||
#define PUCCH_MAX_BITS 2
|
||||
#define PUCCH_N_SF_MAX 4
|
||||
|
||||
typedef enum LIBLTE_API {
|
||||
PUCCH_FORMAT_1 = 0,
|
||||
PUCCH_FORMAT_1A,
|
||||
PUCCH_FORMAT_1B,
|
||||
PUCCH_FORMAT_2,
|
||||
PUCCH_FORMAT_2A,
|
||||
PUCCH_FORMAT_2B,
|
||||
} pucch_format_t;
|
||||
|
||||
typedef struct LIBLTE_API {
|
||||
pucch_format_t format;
|
||||
float beta_pucch;
|
||||
uint32_t delta_pucch_shift;
|
||||
uint32_t n_pucch;
|
||||
uint32_t N_cs;
|
||||
} pucch_cfg_t;
|
||||
|
||||
/* PUSCH object */
|
||||
typedef struct LIBLTE_API {
|
||||
lte_cell_t cell;
|
||||
pucch_cfg_t pucch_cfg;
|
||||
|
||||
uint32_t n_cs_cell[NSLOTS_X_FRAME][CPNORM_NSYMB];
|
||||
float tmp_arg[PUCCH_N_SF_MAX*PUCCH_N_SEQ];
|
||||
float y[PUCCH_N_SEQ];
|
||||
}pucch_t;
|
||||
|
||||
|
||||
LIBLTE_API int pucch_init(pucch_t *q,
|
||||
lte_cell_t cell);
|
||||
|
||||
LIBLTE_API void pucch_free(pucch_t *q);
|
||||
|
||||
LIBLTE_API void pucch_set_cfg(pucch_t *q,
|
||||
pucch_cfg_t *cfg);
|
||||
|
||||
LIBLTE_API int pucch_set_rnti(pucch_t *q,
|
||||
uint16_t rnti);
|
||||
|
||||
LIBLTE_API int pucch_encode(pucch_t *q,
|
||||
pucch_cfg_t *cfg,
|
||||
uint8_t bits[PUCCH_MAX_BITS],
|
||||
cf_t *sf_symbols);
|
||||
|
||||
LIBLTE_API float pucch_get_alpha(uint32_t n_cs_cell[NSLOTS_X_FRAME][CPNORM_NSYMB],
|
||||
pucch_cfg_t *cfg,
|
||||
lte_cp_t cp,
|
||||
bool is_drms,
|
||||
uint32_t ns,
|
||||
uint32_t l,
|
||||
uint32_t *n_oc);
|
||||
|
||||
LIBLTE_API int generate_n_cs_cell(lte_cell_t cell,
|
||||
uint32_t n_cs_cell[NSLOTS_X_FRAME][CPNORM_NSYMB]);
|
||||
|
||||
LIBLTE_API bool pucch_cfg_isvalid(pucch_cfg_t *cfg);
|
||||
|
||||
#endif
|
@ -0,0 +1,206 @@
|
||||
/**
|
||||
*
|
||||
* \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 "liblte/phy/phch/pucch.h"
|
||||
#include "liblte/phy/phch/uci.h"
|
||||
#include "liblte/phy/common/phy_common.h"
|
||||
#include "liblte/phy/utils/bit.h"
|
||||
#include "liblte/phy/utils/debug.h"
|
||||
#include "liblte/phy/utils/vector.h"
|
||||
#include "liblte/phy/filter/dft_precoding.h"
|
||||
|
||||
#define MAX_PUSCH_RE(cp) (2 * CP_NSYMB(cp) * 12)
|
||||
|
||||
bool pucch_cfg_isvalid(pucch_cfg_t *cfg) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* Generates n_cs_cell according to Sec 5.4 of 36.211 */
|
||||
int generate_n_cs_cell(lte_cell_t cell, uint32_t n_cs_cell[NSLOTS_X_FRAME][CPNORM_NSYMB])
|
||||
{
|
||||
sequence_t seq;
|
||||
bzero(&seq, sizeof(sequence_t));
|
||||
|
||||
sequence_LTE_pr(&seq, 8*CP_NSYMB(cell.cp)*NSLOTS_X_FRAME, cell.id);
|
||||
|
||||
for (uint32_t ns=0;ns<NSLOTS_X_FRAME;ns++) {
|
||||
for (uint32_t l=0;l<CP_NSYMB(cell.cp);l++) {
|
||||
n_cs_cell[ns][l] = 0;
|
||||
for (uint32_t i=0;i<8;i++) {
|
||||
n_cs_cell[ns][l] += seq.c[8*CP_NSYMB(cell.cp)*ns+8*l+i]<<i;
|
||||
}
|
||||
}
|
||||
}
|
||||
sequence_free(&seq);
|
||||
return LIBLTE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/* Calculates alpha according to 5.5.2.2.2 of 36.211 */
|
||||
float pucch_get_alpha(uint32_t n_cs_cell[NSLOTS_X_FRAME][CPNORM_NSYMB],
|
||||
pucch_cfg_t *cfg,
|
||||
lte_cp_t cp, bool is_drms,
|
||||
uint32_t ns, uint32_t l,
|
||||
uint32_t *n_oc_ptr)
|
||||
{
|
||||
uint32_t c = CP_ISNORM(cp)?3:2;
|
||||
uint32_t N_prime = (cfg->n_pucch < c*cfg->N_cs/cfg->delta_pucch_shift)?cfg->N_cs:12;
|
||||
|
||||
uint32_t n_prime = cfg->n_pucch;
|
||||
if (cfg->n_pucch >= c*cfg->N_cs/cfg->delta_pucch_shift) {
|
||||
n_prime = (cfg->n_pucch-c*cfg->N_cs/cfg->delta_pucch_shift)%(cfg->N_cs/cfg->delta_pucch_shift);
|
||||
}
|
||||
|
||||
uint32_t n_oc_div = (!is_drms && CP_ISEXT(cp))?2:1;
|
||||
|
||||
uint32_t n_oc = n_prime*cfg->delta_pucch_shift/N_prime;
|
||||
if (!is_drms && CP_ISEXT(cp)) {
|
||||
n_oc *= 2;
|
||||
}
|
||||
if (n_oc_ptr) {
|
||||
*n_oc_ptr = n_oc;
|
||||
}
|
||||
uint32_t n_cs = 0;
|
||||
if (CP_ISNORM(cp)) {
|
||||
n_cs = (n_cs_cell[ns][l]+(n_prime*cfg->delta_pucch_shift+(n_oc%cfg->delta_pucch_shift))%N_prime)%12;
|
||||
} else {
|
||||
n_cs = (n_cs_cell[ns][l]+(n_prime*cfg->delta_pucch_shift+n_oc/n_oc_div)%N_prime)%12;
|
||||
}
|
||||
|
||||
return 2 * M_PI * (n_cs) / 12;
|
||||
}
|
||||
|
||||
int pucch_cp(pucch_t *q, harq_t *harq, cf_t *input, cf_t *output, bool advance_input)
|
||||
{
|
||||
return LIBLTE_ERROR;
|
||||
}
|
||||
|
||||
int pucch_put(pucch_t *q, harq_t *harq, cf_t *input, cf_t *output) {
|
||||
return pucch_cp(q, harq, input, output, true);
|
||||
}
|
||||
|
||||
int pucch_get(pucch_t *q, harq_t *harq, cf_t *input, cf_t *output) {
|
||||
return pucch_cp(q, harq, input, output, false);
|
||||
}
|
||||
|
||||
|
||||
/** Initializes the PDCCH transmitter and receiver */
|
||||
int pucch_init(pucch_t *q, lte_cell_t cell) {
|
||||
int ret = LIBLTE_ERROR_INVALID_INPUTS;
|
||||
if (q != NULL && lte_cell_isvalid(&cell)) {
|
||||
ret = LIBLTE_ERROR;
|
||||
bzero(q, sizeof(pucch_t));
|
||||
|
||||
q->cell = cell;
|
||||
|
||||
if (generate_n_cs_cell(q->cell, q->n_cs_cell)) {
|
||||
return LIBLTE_ERROR;
|
||||
}
|
||||
|
||||
ret = LIBLTE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void pucch_free(pucch_t *q) {
|
||||
bzero(q, sizeof(pucch_t));
|
||||
}
|
||||
|
||||
/** Decodes the PUSCH from the received symbols
|
||||
*/
|
||||
int pucch_decode(pucch_t *q, harq_t *harq, cf_t *sf_symbols, cf_t *ce, float noise_estimate, uint8_t *data)
|
||||
{
|
||||
return LIBLTE_ERROR_INVALID_INPUTS;
|
||||
}
|
||||
|
||||
static cf_t uci_encode_format1() {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
static cf_t uci_encode_format1a(uint8_t bit) {
|
||||
return bit?1.0:-1.0;
|
||||
}
|
||||
|
||||
static cf_t uci_encode_format1b(uint8_t bits[2]) {
|
||||
if (bits[0] == 0) {
|
||||
if (bits[1] == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return -I;
|
||||
}
|
||||
} else {
|
||||
if (bits[1] == 0) {
|
||||
return I;
|
||||
} else {
|
||||
return -1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void uci_mod_bits(pucch_t *q, pucch_cfg_t *cfg, uint8_t bits[PUCCH_MAX_BITS])
|
||||
{
|
||||
cf_t d_0 = 0;
|
||||
uint8_t tmp[2];
|
||||
switch(cfg->format) {
|
||||
case PUCCH_FORMAT_1:
|
||||
d_0 = uci_encode_format1();
|
||||
break;
|
||||
case PUCCH_FORMAT_1A:
|
||||
d_0 = uci_encode_format1a(bits[0]);
|
||||
break;
|
||||
case PUCCH_FORMAT_1B:
|
||||
tmp[0] = bits[0];
|
||||
tmp[1] = bits[1];
|
||||
d_0 = uci_encode_format1b(tmp);
|
||||
default:
|
||||
fprintf(stderr, "PUCCH format 2 not supported\n");
|
||||
return;
|
||||
}
|
||||
/*
|
||||
for (uint32_t n=0;n<PUCCH_N_SEQ;n++) {
|
||||
q->y[n] = d_0+
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
int pucch_encode(pucch_t *q, pucch_cfg_t *cfg, uint8_t bits[PUCCH_MAX_BITS], cf_t *sf_symbols)
|
||||
{
|
||||
uci_mod_bits(q, cfg, bits);
|
||||
return LIBLTE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
clear
|
||||
enbConfig=struct('NCellID',0,'DuplexMode','TDD','CyclicPrefix','Normal','CellRefP',1,'CFI',2,'NDLRB',25,'NSubframe',4,'CyclicPrefixUL','Normal','NTxAnts',1);
|
||||
pdschConfig=struct('NLayers',1,'TxScheme','Port0','OrthCover','Off','PRBSet',0,'RNTI',82,'Modulation','QPSK','RV',0,'Shortened',0);
|
||||
|
||||
addpath('../../debug/lte/phy/lib/phch/test')
|
||||
|
||||
NDLRB=[6 15 25 50 100];
|
||||
|
||||
Peak=[];
|
||||
k=1;
|
||||
for r=1:length(NDLRB)
|
||||
fprintf('NDLRB: %d\n',NDLRB(r));
|
||||
for l=1:NDLRB(r)
|
||||
trblkin=randi(2,l*5,1)-1;
|
||||
|
||||
enbConfig.NDLRB=NDLRB(r);
|
||||
pdschConfig.PRBSet=(0:(l-1))';
|
||||
|
||||
idx=ltePDSCHIndices(enbConfig,pdschConfig,pdschConfig.PRBSet);
|
||||
[cw, info]=lteDLSCH(enbConfig,pdschConfig,2*length(idx),trblkin);
|
||||
cw_mat=ltePDSCH(enbConfig,pdschConfig,cw);
|
||||
subframe_mat = lteDLResourceGrid(enbConfig);
|
||||
subframe_mat(idx)=cw_mat;
|
||||
waveform = lteOFDMModulate(enbConfig,subframe_mat,0);
|
||||
waveform = waveform*sqrt(512)/sqrt(l)*NDLRB(r)/15;
|
||||
Peak(k)=max(max(abs(real(waveform))),max(abs(imag(waveform))));
|
||||
k=k+1;
|
||||
end
|
||||
end
|
||||
|
||||
plot(Peak(:)')
|
||||
|
Loading…
Reference in New Issue