Started implementing PUCCH

master
ismagom 10 years ago
parent 4cdbd9bd83
commit 6d8540441a

@ -590,6 +590,9 @@ int main(int argc, char **argv) {
/* Transform to OFDM symbols */
lte_ifft_run_sf(&ifft, sf_buffer, output_buffer);
float norm_factor = (float) cell.nof_prb/15/sqrtf(ra_dl.prb_alloc.slot[0].nof_prb);
vec_sc_prod_cfc(output_buffer, uhd_amp*norm_factor, output_buffer, SF_LEN_PRB(cell.nof_prb));
/* send to file or usrp */
if (output_file_name) {
if (!null_file_sink) {

@ -80,7 +80,7 @@ void args_default(prog_args_t *args) {
args->nof_subframes = -1;
args->force_N_id_2 = -1; // Pick the best
args->file_nof_prb = 6;
args->beta_prach = 0.02;
args->beta_prach = 0.005;
args->beta_pusch = 2.0;
args->ta_usec = -1.0;
args->preamble_idx = 7;
@ -400,10 +400,10 @@ int main(int argc, char **argv) {
drms_cfg.beta_pusch = 1.0;
drms_cfg.group_hopping_en = false;
drms_cfg.sequence_hopping_en = false;
drms_cfg.common.delta_ss = 0;
drms_cfg.common.cyclic_shift = 0;
drms_cfg.common.cyclic_shift_for_drms = 0;
drms_cfg.common.en_drms_2 = false;
drms_cfg.delta_ss = 0;
drms_cfg.cyclic_shift = 0;
drms_cfg.cyclic_shift_for_drms = 0;
drms_cfg.en_drms_2 = false;
ue_ul_set_pusch_cfg(&ue_ul, &drms_cfg, &hop_cfg);
cf_t *ul_signal = vec_malloc(sizeof(cf_t) * SF_LEN_PRB(cell.nof_prb));
@ -433,7 +433,7 @@ int main(int argc, char **argv) {
uint16_t ra_rnti;
uint32_t conn_setup_trial = 0;
uint32_t ul_sf_idx = 0;
#ifdef kk
// Register Ctrl+C handler
signal(SIGINT, sig_int_handler);
@ -528,10 +528,10 @@ int main(int argc, char **argv) {
} else if (n > 0) {
rar_unpack(data_rx, &rar_msg);
if (rar_msg.RAPID != prog_args.preamble_idx) {
printf("Found RAR for sequence %d\n", rar_msg.RAPID);
} else {
cuhd_stop_rx_stream(uhd);
//if (rar_msg.RAPID != prog_args.preamble_idx) {
// printf("Found RAR for sequence %d\n", rar_msg.RAPID);
//} else {
//cuhd_stop_rx_stream(uhd);
//cuhd_flush_buffer(uhd);
rar_msg_fprint(stdout, &rar_msg);
@ -554,7 +554,7 @@ int main(int argc, char **argv) {
const uint32_t rv[N_TX]={0,2,3,1,0};
for (int i=0; i<N_TX;i++) {
ra_pusch.rv_idx = rv[i];
uint32_t ul_sf_idx = (ue_sync_get_sfidx(&ue_sync)+6+i*8)%10;
ul_sf_idx = (ue_sync_get_sfidx(&ue_sync)+6+i*8)%10;
n = ue_ul_pusch_encode_rnti(&ue_ul, &ra_pusch, data, ul_sf_idx, rar_msg.temp_c_rnti, ul_signal);
if (n < 0) {
@ -575,11 +575,11 @@ int main(int argc, char **argv) {
cuhd_send_timed(uhd, ul_signal, SF_LEN_PRB(cell.nof_prb),
next_tx_time.full_secs, next_tx_time.frac_secs);
cuhd_start_rx_stream(uhd);
//cuhd_start_rx_stream(uhd);
state = RECV_CONNSETUP;
conn_setup_trial = 0;
}
// }
}
}
@ -629,12 +629,18 @@ int main(int argc, char **argv) {
break;
case RECV_CONNSETUP:
printf("Looking for ConnectionSetup in sfn: %d sf_idx: %d\n", sfn, ue_sync_get_sfidx(&ue_sync));
n = ue_dl_decode_rnti(&ue_dl, sf_buffer, data_rx, ue_sync_get_sfidx(&ue_sync), ra_rnti);
if (ue_sync_get_sfidx(&ue_sync) == (ul_sf_idx+4)%10) {
//verbose=VERBOSE_DEBUG;
vec_save_file("connsetup",sf_buffer,SF_LEN_PRB(cell.nof_prb)*sizeof(cf_t));
} else {
//verbose=VERBOSE_NONE;
}
printf("Looking for ConnectionSetup in sfn: %d sf_idx: %d, RNTI: %d\n", sfn, ue_sync_get_sfidx(&ue_sync),rar_msg.temp_c_rnti);
n = ue_dl_decode_rnti(&ue_dl, sf_buffer, data_rx, ue_sync_get_sfidx(&ue_sync), rar_msg.temp_c_rnti);
if (n < 0) {
fprintf(stderr, "Error decoding UE DL\n");fflush(stdout);
} else if (n > 0) {
printf("Received ConnectionSetup len: %d.\n");
printf("Received ConnectionSetup len: %d.\n", n);
vec_fprint_hex(stdout, data_rx, n);
} else {
conn_setup_trial++;

@ -33,6 +33,7 @@
*/
#include "liblte/config.h"
#include "liblte/phy/phch/pucch.h"
#include "liblte/phy/common/phy_common.h"
#define NOF_GROUPS_U 30
@ -47,24 +48,12 @@ typedef struct LIBLTE_API {
uint32_t cyclic_shift_for_drms;
uint32_t delta_ss;
bool en_drms_2;
}refsignal_ul_cfg_t;
typedef struct LIBLTE_API {
refsignal_ul_cfg_t common;
float beta_pusch;
bool group_hopping_en;
bool sequence_hopping_en;
}refsignal_drms_pusch_cfg_t;
typedef struct LIBLTE_API {
refsignal_ul_cfg_t common;
float beta_pucch;
uint32_t nof_prb;
}refsignal_drms_pucch_cfg_t;
typedef struct LIBLTE_API {
refsignal_ul_cfg_t common;
float beta_pucch;
uint32_t nof_prb;
}refsignal_srs_cfg_t;
@ -72,6 +61,7 @@ typedef struct LIBLTE_API {
/** Uplink DeModulation Reference Signal (DMRS) */
typedef struct LIBLTE_API {
lte_cell_t cell;
uint32_t n_cs_cell[NSLOTS_X_FRAME][CPNORM_NSYMB];
float *tmp_arg;
uint32_t n_prs_pusch[NOF_DELTA_SS][NSLOTS_X_FRAME]; // We precompute n_prs needed for cyclic shift alpha at refsignal_dl_init()
uint32_t f_gh[NSLOTS_X_FRAME];
@ -92,25 +82,25 @@ LIBLTE_API bool refsignal_drms_pusch_cfg_isvalid(refsignal_ul_t *q,
LIBLTE_API void refsignal_drms_pusch_put(refsignal_ul_t *q,
refsignal_drms_pusch_cfg_t *cfg,
cf_t *r_pusch,
uint32_t ns_idx,
uint32_t nof_prb,
uint32_t n_prb,
uint32_t n_prb[2],
cf_t *sf_symbols);
LIBLTE_API int refsignal_dmrs_pusch_gen(refsignal_ul_t *q,
refsignal_drms_pusch_cfg_t *cfg,
uint32_t nof_prb,
uint32_t ns,
uint32_t sf_idx,
cf_t *r_pusch);
LIBLTE_API void refsignal_dmrs_pucch_gen(refsignal_ul_t *q,
refsignal_drms_pucch_cfg_t *cfg,
uint32_t ns,
cf_t *r_pucch);
LIBLTE_API int refsignal_dmrs_pucch_gen(refsignal_ul_t *q,
pucch_cfg_t *cfg,
uint32_t sf_idx,
uint32_t n_rb,
cf_t *r_pucch) ;
LIBLTE_API void refsignal_srs_gen(refsignal_ul_t *q,
refsignal_srs_cfg_t *cfg,
uint32_t ns,
uint32_t sf_idx,
cf_t *r_srs);
#endif

@ -98,7 +98,7 @@ typedef enum {CPNORM, CPEXT} lte_cp_t;
#define SLOT_LEN_RE(nof_prb, cp) (nof_prb*RE_X_RB*CP_NSYMB(cp))
#define SF_LEN_RE(nof_prb, cp) (2*SLOT_LEN_RE(nof_prb, cp))
#define TA_OFFSET (8e-6)
#define TA_OFFSET (10e-6)
#define LTE_TS 1.0/(15000.0*2048)

@ -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

@ -45,6 +45,23 @@ uint32_t n_drms_2[8] = { 0, 6, 3, 4, 2, 8, 10, 9 };
// n_drms_1 table 5.5.2.1.1-2 from 36.211
uint32_t n_drms_1[8] = { 0, 2, 3, 4, 6, 8, 9, 10 };
/* Orthogonal sequences for PUCCH formats 1a, 1b and 1c. Table 5.5.2.2.1-2
*/
float w_arg_pucch_format1_cpnorm[3][3] = {{0, 0, 0},
{0, 2*M_PI/3, 4*M_PI/3},
{0, 4*M_PI/3, 2*M_PI/3}};
float w_arg_pucch_format1_cpext[3][2] = {{0, 0},
{0, M_PI},
{0, 0}};
float w_arg_pucch_format2_cpnorm[2] = {0, 0};
float w_arg_pucch_format2_cpext[1] = {0};
uint32_t pucch_symbol_format1_cpnorm[3] = {2, 3, 5};
uint32_t pucch_symbol_format1_cpext[2] = {2, 3};
uint32_t pucch_symbol_format2_cpnorm[2] = {1, 5};
uint32_t pucch_symbol_format2_cpext[1] = {3};
/** Computes n_prs values used to compute alpha as defined in 5.5.2.1.1 of 36.211 */
static int generate_n_prs(refsignal_ul_t * q) {
@ -109,6 +126,7 @@ static int generate_sequence_hopping_v(refsignal_ul_t *q) {
return LIBLTE_SUCCESS;
}
/** Initializes refsignal_ul_t object according to 3GPP 36.211 5.5
*
*/
@ -144,6 +162,10 @@ int refsignal_ul_init(refsignal_ul_t * q, lte_cell_t cell)
goto free_and_exit;
}
if (generate_n_cs_cell(q->cell, q->n_cs_cell)) {
goto free_and_exit;
}
ret = LIBLTE_SUCCESS;
}
free_and_exit:
@ -221,7 +243,7 @@ static void compute_pusch_r_uv_arg(refsignal_ul_t *q, refsignal_drms_pusch_cfg_t
}
/* Calculates alpha according to 5.5.2.1.1 of 36.211 */
static float get_alpha(refsignal_ul_t *q, refsignal_ul_cfg_t *cfg, uint32_t ns) {
static float pusch_get_alpha(refsignal_ul_t *q, refsignal_drms_pusch_cfg_t *cfg, uint32_t ns) {
uint32_t n_drms_2_val = 0;
if (cfg->en_drms_2) {
n_drms_2_val = n_drms_2[cfg->cyclic_shift_for_drms];
@ -233,10 +255,10 @@ static float get_alpha(refsignal_ul_t *q, refsignal_ul_cfg_t *cfg, uint32_t ns)
}
bool refsignal_drms_pusch_cfg_isvalid(refsignal_ul_t *q, refsignal_drms_pusch_cfg_t *cfg, uint32_t nof_prb) {
if (cfg->common.cyclic_shift < NOF_CSHIFT &&
cfg->common.cyclic_shift_for_drms < NOF_CSHIFT &&
cfg->common.delta_ss < NOF_DELTA_SS &&
nof_prb < q->cell.nof_prb) {
if (cfg->cyclic_shift < NOF_CSHIFT &&
cfg->cyclic_shift_for_drms < NOF_CSHIFT &&
cfg->delta_ss < NOF_DELTA_SS &&
nof_prb < q->cell.nof_prb) {
return true;
} else {
return false;
@ -245,65 +267,151 @@ bool refsignal_drms_pusch_cfg_isvalid(refsignal_ul_t *q, refsignal_drms_pusch_cf
void refsignal_drms_pusch_put(refsignal_ul_t *q, refsignal_drms_pusch_cfg_t *cfg,
cf_t *r_pusch,
uint32_t ns_idx,
uint32_t nof_prb,
uint32_t n_prb,
uint32_t n_prb[2],
cf_t *sf_symbols)
{
if (ns_idx < 2) {
DEBUG("Putting DRMS to n_prb: %d, L: %d, ns_idx: %d\n", n_prb, nof_prb, ns_idx);
for (uint32_t ns_idx=0;ns_idx<2;ns_idx++) {
DEBUG("Putting DRMS to n_prb: %d, L: %d, ns_idx: %d\n", n_prb[ns_idx], nof_prb, ns_idx);
uint32_t L = (ns_idx+1)*CP_NSYMB(q->cell.cp)-4;
memcpy(&sf_symbols[RE_IDX(q->cell.nof_prb, L, n_prb*RE_X_RB)], r_pusch, nof_prb*RE_X_RB*sizeof(cf_t));
memcpy(&sf_symbols[RE_IDX(q->cell.nof_prb, L, n_prb[ns_idx]*RE_X_RB)],
&r_pusch[ns_idx*RE_X_RB*nof_prb], nof_prb*RE_X_RB*sizeof(cf_t));
}
}
/* Generate DRMS for PUSCH signal according to 5.5.2.1 of 36.211 */
int refsignal_dmrs_pusch_gen(refsignal_ul_t *q, refsignal_drms_pusch_cfg_t *cfg, uint32_t nof_prb, uint32_t ns, cf_t *r_pusch) {
int refsignal_dmrs_pusch_gen(refsignal_ul_t *q, refsignal_drms_pusch_cfg_t *cfg, uint32_t nof_prb, uint32_t sf_idx, cf_t *r_pusch)
{
int ret = LIBLTE_ERROR_INVALID_INPUTS;
if (refsignal_drms_pusch_cfg_isvalid(q, cfg, nof_prb)) {
ret = LIBLTE_ERROR;
// Get group hopping number u
uint32_t f_gh=0;
if (cfg->group_hopping_en) {
f_gh = q->f_gh[ns];
}
uint32_t u = (f_gh + (q->cell.id%30)+cfg->common.delta_ss)%30;
// Get sequence hopping number v
uint32_t v = 0;
if (nof_prb >= 6 && cfg->sequence_hopping_en) {
v = q->v_pusch[ns][cfg->common.delta_ss];
}
for (uint32_t ns=2*sf_idx;ns<2*(sf_idx+1);ns++) {
// Get group hopping number u
uint32_t f_gh=0;
if (cfg->group_hopping_en) {
f_gh = q->f_gh[ns];
}
uint32_t u = (f_gh + (q->cell.id%30)+cfg->delta_ss)%30;
// Get sequence hopping number v
uint32_t v = 0;
if (nof_prb >= 6 && cfg->sequence_hopping_en) {
v = q->v_pusch[ns][cfg->delta_ss];
}
// Compute signal argument
compute_pusch_r_uv_arg(q, cfg, nof_prb, u, v);
// Compute signal argument
compute_pusch_r_uv_arg(q, cfg, nof_prb, u, v);
// Add cyclic prefix alpha
float alpha = get_alpha(q, &cfg->common, ns);
// Add cyclic prefix alpha
float alpha = pusch_get_alpha(q, cfg, ns);
if (verbose == VERBOSE_DEBUG) {
uint32_t N_sz = largest_prime_lower_than(nof_prb*RE_X_RB);
DEBUG("Generating PUSCH DRMS sequence with parameters:\n",0);
DEBUG("\tbeta: %.1f, nof_prb: %d, u: %d, v: %d, alpha: %f, N_sc: %d, root q: %d, nprs: %d\n",
cfg->beta_pusch, nof_prb, u, v, alpha, N_sz, get_q(u,v,N_sz),q->n_prs_pusch[cfg->common.delta_ss][ns]);
}
if (verbose == VERBOSE_DEBUG) {
uint32_t N_sz = largest_prime_lower_than(nof_prb*RE_X_RB);
DEBUG("Generating PUSCH DRMS sequence with parameters:\n",0);
DEBUG("\tbeta: %.1f, nof_prb: %d, u: %d, v: %d, alpha: %f, N_sc: %d, root q: %d, nprs: %d\n",
cfg->beta_pusch, nof_prb, u, v, alpha, N_sz, get_q(u,v,N_sz),q->n_prs_pusch[cfg->delta_ss][ns]);
}
// Do complex exponential and adjust amplitude
for (int i=0;i<RE_X_RB*nof_prb;i++) {
r_pusch[i] = cfg->beta_pusch * cexpf(I*(q->tmp_arg[i] + alpha*i));
// Do complex exponential and adjust amplitude
for (int i=0;i<RE_X_RB*nof_prb;i++) {
r_pusch[(ns%2)*RE_X_RB*nof_prb+i] = cfg->beta_pusch * cexpf(I*(q->tmp_arg[i] + alpha*i));
}
}
ret = 0;
}
return ret;
}
void refsignal_dmrs_pucch_gen(refsignal_ul_t *q, refsignal_drms_pucch_cfg_t *cfg, uint32_t ns, cf_t *r_pucch) {
int refsignal_dmrs_pucch_gen(refsignal_ul_t *q, pucch_cfg_t *cfg, uint32_t sf_idx, uint32_t n_rb, cf_t *r_pucch)
{
int ret = LIBLTE_ERROR_INVALID_INPUTS;
if (pucch_cfg_isvalid(cfg)) {
ret = LIBLTE_ERROR;
for (uint32_t ns=2*sf_idx;ns<2*(sf_idx+1);ns++) {
uint32_t N_rs=0;
uint32_t *pucch_symbol = NULL;
switch (cfg->format) {
case PUCCH_FORMAT_1:
case PUCCH_FORMAT_1A:
case PUCCH_FORMAT_1B:
if (CP_ISNORM(q->cell.cp)) {
N_rs = 3;
pucch_symbol=pucch_symbol_format1_cpnorm;
} else {
N_rs=2;
pucch_symbol=pucch_symbol_format1_cpext;
}
break;
case PUCCH_FORMAT_2:
if (CP_ISNORM(q->cell.cp)) {
N_rs = 2;
pucch_symbol=pucch_symbol_format2_cpnorm;
} else {
N_rs=1;
pucch_symbol=pucch_symbol_format2_cpext;
}
break;
case PUCCH_FORMAT_2A:
case PUCCH_FORMAT_2B:
N_rs = 2;
pucch_symbol=pucch_symbol_format2_cpnorm;
break;
}
if (pucch_symbol) {
for (uint32_t m=0;m<N_rs;m++) {
uint32_t n_oc=0;
uint32_t l = pucch_symbol[m];
// Add cyclic prefix alpha
float alpha = pucch_get_alpha(q->n_cs_cell, cfg, q->cell.cp, true, ns, l, &n_oc);
// Choose number of symbols and orthogonal sequence from Tables 5.5.2.2.1-1 to -3
float *w=NULL;
switch (cfg->format) {
case PUCCH_FORMAT_1:
case PUCCH_FORMAT_1A:
case PUCCH_FORMAT_1B:
if (CP_ISNORM(q->cell.cp)) {
w=w_arg_pucch_format1_cpnorm[n_oc];
} else {
w=w_arg_pucch_format1_cpext[n_oc];
}
break;
case PUCCH_FORMAT_2:
if (CP_ISNORM(q->cell.cp)) {
w=w_arg_pucch_format2_cpnorm;
} else {
w=w_arg_pucch_format2_cpext;
}
break;
case PUCCH_FORMAT_2A:
case PUCCH_FORMAT_2B:
w=w_arg_pucch_format2_cpnorm;
break;
}
if (w) {
for (uint32_t n=0;n<RE_X_RB*n_rb;n++) {
r_pucch[(ns%2)*RE_X_RB*n_rb*N_rs+m*RE_X_RB*n_rb+n] = cfg->beta_pucch*cexpf(I*(w[m]+q->tmp_arg[n]+alpha*n));
}
} else {
return LIBLTE_ERROR;
}
}
} else {
return LIBLTE_ERROR;
}
}
ret = LIBLTE_SUCCESS;
}
return ret;
}
void refsignal_srs_gen(refsignal_ul_t *q, refsignal_srs_cfg_t *cfg, uint32_t ns, cf_t *r_srs) {
void refsignal_srs_gen(refsignal_ul_t *q, refsignal_srs_cfg_t *cfg, uint32_t ns, cf_t *r_srs)
{
}

@ -89,11 +89,11 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
}
if (mexutils_read_uint32_struct(UECFG, "SeqGroup", &pusch_cfg.common.delta_ss)) {
pusch_cfg.common.delta_ss = 0;
if (mexutils_read_uint32_struct(UECFG, "SeqGroup", &pusch_cfg.delta_ss)) {
pusch_cfg.delta_ss = 0;
}
if (mexutils_read_uint32_struct(UECFG, "CyclicShift", &pusch_cfg.common.cyclic_shift)) {
pusch_cfg.common.cyclic_shift = 0;
if (mexutils_read_uint32_struct(UECFG, "CyclicShift", &pusch_cfg.cyclic_shift)) {
pusch_cfg.cyclic_shift = 0;
}
float *prbset;
mxArray *p;
@ -104,11 +104,11 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
}
uint32_t nof_prb = mexutils_read_f(p, &prbset);
if (mexutils_read_uint32_struct(PUSCHCFG, "DynCyclicShift", &pusch_cfg.common.cyclic_shift_for_drms)) {
pusch_cfg.common.cyclic_shift_for_drms = 0;
pusch_cfg.common.en_drms_2 = false;
if (mexutils_read_uint32_struct(PUSCHCFG, "DynCyclicShift", &pusch_cfg.cyclic_shift_for_drms)) {
pusch_cfg.cyclic_shift_for_drms = 0;
pusch_cfg.en_drms_2 = false;
} else {
pusch_cfg.common.en_drms_2 = true;
pusch_cfg.en_drms_2 = true;
}
pusch_cfg.beta_pusch = 1.0;
@ -119,9 +119,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
}
mexPrintf("nof_prb: %d, ",nof_prb);
mexPrintf("cyclic_shift: %d, ",pusch_cfg.common.cyclic_shift);
mexPrintf("cyclic_shift_for_drms: %d, ",pusch_cfg.common.cyclic_shift_for_drms);
mexPrintf("delta_ss: %d, ",pusch_cfg.common.delta_ss);
mexPrintf("cyclic_shift: %d, ",pusch_cfg.cyclic_shift);
mexPrintf("cyclic_shift_for_drms: %d, ",pusch_cfg.cyclic_shift_for_drms);
mexPrintf("delta_ss: %d, ",pusch_cfg.delta_ss);
cf_t *signal = vec_malloc(2*RE_X_RB*nof_prb*sizeof(cf_t));
if (!signal) {
@ -134,13 +134,12 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
return;
}
bzero(sf_symbols, SF_LEN_RE(cell.nof_prb, cell.cp)*sizeof(cf_t));
for (uint32_t i=0;i<2;i++) {
//mexPrintf("Generating DRMS for ns=%d, nof_prb=%d\n", 2*sf_idx+i,pusch_cfg.nof_prb);
refsignal_dmrs_pusch_gen(&refs, &pusch_cfg, nof_prb, 2*sf_idx+i, &signal[i*RE_X_RB*nof_prb]);
}
for (uint32_t i=0;i<2;i++) {
refsignal_drms_pusch_put(&refs, &pusch_cfg, &signal[i*RE_X_RB*nof_prb], i, nof_prb, prbset[0], sf_symbols);
}
//mexPrintf("Generating DRMS for ns=%d, nof_prb=%d\n", 2*sf_idx+i,pusch_cfg.nof_prb);
refsignal_dmrs_pusch_gen(&refs, &pusch_cfg, nof_prb, sf_idx, signal);
uint32_t n_prb[2];
n_prb[0] = prbset[0];
n_prb[1] = prbset[0];
refsignal_drms_pusch_put(&refs, &pusch_cfg, signal, nof_prb, n_prb, sf_symbols);
if (nlhs >= 1) {
mexutils_write_cf(sf_symbols, &plhs[0], SF_LEN_RE(cell.nof_prb, cell.cp), 1);
}

@ -82,7 +82,7 @@ int main(int argc, char **argv) {
parse_args(argc,argv);
signal = malloc(RE_X_RB * cell.nof_prb * sizeof(cf_t));
signal = malloc(2 * RE_X_RB * cell.nof_prb * sizeof(cf_t));
if (!signal) {
perror("malloc");
goto do_exit;
@ -99,13 +99,13 @@ int main(int argc, char **argv) {
for (int delta_ss=29;delta_ss<NOF_DELTA_SS;delta_ss++) {
for (int cshift=0;cshift<NOF_CSHIFT;cshift++) {
for (int h=0;h<3;h++) {
for (int ns=0;ns<NSLOTS_X_FRAME;ns++) {
for (int sf_idx=0;sf_idx<NSLOTS_X_FRAME;sf_idx++) {
for (int cshift_drms=0;cshift_drms<NOF_CSHIFT;cshift_drms++) {
pusch_cfg.beta_pusch = 1.0;
uint32_t nof_prb = n;
pusch_cfg.common.cyclic_shift = cshift;
pusch_cfg.common.cyclic_shift_for_drms = cshift_drms;
pusch_cfg.common.delta_ss = delta_ss;
pusch_cfg.cyclic_shift = cshift;
pusch_cfg.cyclic_shift_for_drms = cshift_drms;
pusch_cfg.delta_ss = delta_ss;
if (!h) {
pusch_cfg.group_hopping_en = false;
pusch_cfg.sequence_hopping_en = false;
@ -116,14 +116,14 @@ int main(int argc, char **argv) {
pusch_cfg.group_hopping_en = true;
pusch_cfg.sequence_hopping_en = false;
}
pusch_cfg.common.en_drms_2 = true;
pusch_cfg.en_drms_2 = true;
printf("Beta: %f, ",pusch_cfg.beta_pusch);
printf("nof_prb: %d, ",nof_prb);
printf("cyclic_shift: %d, ",pusch_cfg.common.cyclic_shift);
printf("cyclic_shift_for_drms: %d, ",pusch_cfg.common.cyclic_shift_for_drms);
printf("delta_ss: %d, ",pusch_cfg.common.delta_ss);
printf("Slot: %d\n", ns);
refsignal_dmrs_pusch_gen(&refs, &pusch_cfg, nof_prb, ns, signal);
printf("cyclic_shift: %d, ",pusch_cfg.cyclic_shift);
printf("cyclic_shift_for_drms: %d, ",pusch_cfg.cyclic_shift_for_drms);
printf("delta_ss: %d, ",pusch_cfg.delta_ss);
printf("SF_idx: %d\n", sf_idx);
refsignal_dmrs_pusch_gen(&refs, &pusch_cfg, nof_prb, sf_idx, signal);
exit(0);
}
}

@ -865,13 +865,15 @@ int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, uint32_t nof_prb,
type->format = Format1;
return LIBLTE_SUCCESS;
} else if (msg->nof_bits == dci_format_sizeof(Format1A, nof_prb)) {
if (msg_rnti >= CRNTI_START && msg_rnti <= CRNTI_END) {
/* The RNTI is not the only condition. Also some fields in the packet.
* if (msg_rnti >= CRNTI_START && msg_rnti <= CRNTI_END) {
type->type = RA_PROC_PDCCH;
type->format = Format1A;
} else {
*/
type->type = PDSCH_SCHED; // only these 2 types supported
type->format = Format1A;
}
//}
return LIBLTE_SUCCESS;
} else if (msg->nof_bits == dci_format_sizeof(Format1C, nof_prb)) {
if (msg_rnti == MRNTI) {

@ -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;
}

@ -203,7 +203,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
lte_ifft_run_sf(&fft, sf_symbols, scfdma);
// Matlab toolbox expects further normalization
vec_sc_prod_cfc(scfdma, 1.0/sqrtf(512), scfdma, SF_LEN_PRB(cell.nof_prb));
vec_sc_prod_cfc(scfdma, 1.0/sqrtf(lte_symbol_sz(cell.nof_prb)), scfdma, SF_LEN_PRB(cell.nof_prb));
if (nlhs >= 1) {
mexutils_write_cf(scfdma, &plhs[0], SF_LEN_PRB(cell.nof_prb), 1);

@ -85,7 +85,7 @@ int ue_ul_init(ue_ul_t *q,
perror("malloc");
goto clean_exit;
}
q->refsignal = vec_malloc(RE_X_RB * q->cell.nof_prb * sizeof(cf_t));
q->refsignal = vec_malloc(2 * RE_X_RB * q->cell.nof_prb * sizeof(cf_t));
if (!q->refsignal) {
perror("malloc");
goto clean_exit;
@ -200,19 +200,17 @@ int ue_ul_pusch_uci_encode_rnti(ue_ul_t *q, ra_pusch_t *ra_ul, uint8_t *data, uc
return ret;
}
for (uint32_t i=0;i<2;i++) {
// FIXME: Pregenerate for all possible number of prb
if (refsignal_dmrs_pusch_gen(&q->drms, &q->pusch_drms_cfg,
q->harq_process[0].ul_alloc.L_prb, 2*sf_idx+i, q->refsignal))
{
fprintf(stderr, "Error generating PUSCH DRMS signals\n");
return ret;
}
refsignal_drms_pusch_put(&q->drms, &q->pusch_drms_cfg, q->refsignal, i,
q->harq_process[0].ul_alloc.L_prb,
q->harq_process[0].ul_alloc.n_prb_tilde[i],
q->sf_symbols);
// FIXME: Pregenerate for all possible number of prb
if (refsignal_dmrs_pusch_gen(&q->drms, &q->pusch_drms_cfg,
q->harq_process[0].ul_alloc.L_prb, sf_idx, q->refsignal))
{
fprintf(stderr, "Error generating PUSCH DRMS signals\n");
return ret;
}
refsignal_drms_pusch_put(&q->drms, &q->pusch_drms_cfg, q->refsignal,
q->harq_process[0].ul_alloc.L_prb,
q->harq_process[0].ul_alloc.n_prb_tilde,
q->sf_symbols);
lte_ifft_run_sf(&q->fft, q->sf_symbols, output_signal);

@ -1,4 +1,4 @@
ueConfig=struct('CyclicPrefixUL','Normal','NTxAnts',1,'NULRB',25);
ueConfig=struct('CyclicPrefixUL','Normal','NTxAnts',1,'NULRB',6);
puschConfig=struct('NLayers',1,'OrthCover','Off');
addpath('../../debug/lte/phy/lib/ch_estimation/test')
@ -8,7 +8,7 @@ Hopping={'Off','Sequence','Group'};
k=1;
for prb=4
for ncell=1
for ns=4
for ns=8
for h=1
for sg=0
for cs=0
@ -20,7 +20,7 @@ for prb=4
ueConfig.SeqGroup=sg;
ueConfig.CyclicShift=cs;
puschConfig.PRBSet=(19:22)';
puschConfig.PRBSet=(1:4)';
puschConfig.DynCyclicShift=ds;
[mat, info]=ltePUSCHDRS(ueConfig,puschConfig);

@ -1,7 +1,7 @@
ueConfig=struct('NCellID',0,'NULRB',25,'NSubframe',4,'RNTI',109,'CyclicPrefixUL','Normal','NTxAnts',1);
puschConfig=struct('NLayers',1,'OrthCover','Off','PRBSet',(19:22)','Modulation','QPSK','RV',0,'Shortened',0);
ueConfig=struct('NCellID',1,'NULRB',6,'NSubframe',8,'RNTI',81,'CyclicPrefixUL','Normal','NTxAnts',1);
puschConfig=struct('NLayers',1,'OrthCover','Off','PRBSet',(1:4)','Modulation','QPSK','RV',0,'Shortened',0);
subframe_rx=lteSCFDMADemodulate(ueConfig,x.*transpose(exp(-1i*2*pi*0.18*(1:length(x))/512)));
subframe_rx=lteSCFDMADemodulate(ueConfig,x.*transpose(exp(-1i*2*pi*0.26*(1:length(x))/128)));
idx=ltePUSCHIndices(ueConfig,puschConfig);
pusch_rx=subframe_rx(idx);
[hest, noiseest] = lteULChannelEstimate(ueConfig,puschConfig,subframe_rx);
@ -9,4 +9,7 @@ ce=hest(idx);
[cws,symbols] = ltePUSCHDecode(ueConfig,puschConfig,pusch_rx,ce,noiseest);
[trblkout,blkcrc,stateout] = lteULSCHDecode(ueConfig,puschConfig,88,cws);
disp(blkcrc)
scatter(real(symbols),imag(symbols))
subplot(1,2,1)
scatter(real(symbols),imag(symbols))
subplot(1,2,2)
plot(angle(hest))

@ -1,5 +1,5 @@
clear
ueConfig=struct('NCellID',0,'NULRB',6,'NSubframe',5,'RNTI',79,'CyclicPrefixUL','Normal','NTxAnts',1);
ueConfig=struct('NCellID',1,'NULRB',6,'NSubframe',8,'RNTI',68,'CyclicPrefixUL','Normal','NTxAnts',1);
puschConfig=struct('NLayers',1,'OrthCover','Off','PRBSet',[1:4]','Modulation','QPSK','RV',0,'Shortened',0);
addpath('../../debug/lte/phy/lib/phch/test')

@ -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…
Cancel
Save