Commit 25dde24d authored by Bartosz Podrygajlo's avatar Bartosz Podrygajlo

Fix formatting in nr_ul_channel_estimation.c

parent f54ca571
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
#include <string.h> #include <string.h>
#include "nr_ul_estimation.h" #include "nr_ul_estimation.h"
...@@ -35,13 +34,12 @@ ...@@ -35,13 +34,12 @@
#include "executables/softmodem-common.h" #include "executables/softmodem-common.h"
#include "nr_phy_common.h" #include "nr_phy_common.h"
//#define DEBUG_CH //#define DEBUG_CH
//#define DEBUG_PUSCH //#define DEBUG_PUSCH
//#define SRS_DEBUG //#define SRS_DEBUG
#define NO_INTERP 1 #define NO_INTERP 1
#define dBc(x,y) (dB_fixed(((int32_t)(x))*(x) + ((int32_t)(y))*(y))) #define dBc(x, y) (dB_fixed(((int32_t)(x)) * (x) + ((int32_t)(y)) * (y)))
__attribute__((always_inline)) inline c16_t c32x16cumulVectVectWithSteps(c16_t *in1, __attribute__((always_inline)) inline c16_t c32x16cumulVectVectWithSteps(c16_t *in1,
int *offset1, int *offset1,
...@@ -50,18 +48,18 @@ __attribute__((always_inline)) inline c16_t c32x16cumulVectVectWithSteps(c16_t * ...@@ -50,18 +48,18 @@ __attribute__((always_inline)) inline c16_t c32x16cumulVectVectWithSteps(c16_t *
int *offset2, int *offset2,
const int step2, const int step2,
const int modulo2, const int modulo2,
const int N) { const int N)
{
int localOffset1=*offset1; int localOffset1 = *offset1;
int localOffset2=*offset2; int localOffset2 = *offset2;
c32_t cumul={0}; c32_t cumul = {0};
for (int i=0; i<N; i++) { for (int i = 0; i < N; i++) {
cumul=c32x16maddShift(in1[localOffset1], in2[localOffset2], cumul, 15); cumul = c32x16maddShift(in1[localOffset1], in2[localOffset2], cumul, 15);
localOffset1+=step1; localOffset1 += step1;
localOffset2= (localOffset2 + step2) % modulo2; localOffset2 = (localOffset2 + step2) % modulo2;
} }
*offset1=localOffset1; *offset1 = localOffset1;
*offset2=localOffset2; *offset2 = localOffset2;
return c16x32div(cumul, N); return c16x32div(cumul, N);
} }
...@@ -82,7 +80,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -82,7 +80,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
#ifdef DEBUG_CH #ifdef DEBUG_CH
FILE *debug_ch_est; FILE *debug_ch_est;
debug_ch_est = fopen("debug_ch_est.txt","w"); debug_ch_est = fopen("debug_ch_est.txt", "w");
#endif #endif
NR_gNB_PUSCH *pusch_vars = &gNB->pusch_vars[ul_id]; NR_gNB_PUSCH *pusch_vars = &gNB->pusch_vars[ul_id];
c16_t **ul_ch_estimates = (c16_t **)pusch_vars->ul_ch_estimates; c16_t **ul_ch_estimates = (c16_t **)pusch_vars->ul_ch_estimates;
...@@ -93,7 +91,8 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -93,7 +91,8 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
const int k0 = bwp_start_subcarrier; const int k0 = bwp_start_subcarrier;
const int nb_rb_pusch = pusch_pdu->rb_size; const int nb_rb_pusch = pusch_pdu->rb_size;
LOG_D(PHY, "symbol_offset %d, slot_offset %d, OFDM size %d, Ns = %d, k0 = %d, symbol %d\n", LOG_D(PHY,
"symbol_offset %d, slot_offset %d, OFDM size %d, Ns = %d, k0 = %d, symbol %d\n",
symbol_offset, symbol_offset,
slot_offset, slot_offset,
symbolSize, symbolSize,
...@@ -127,13 +126,15 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -127,13 +126,15 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
const uint8_t u = pusch_pdu->dfts_ofdm.low_papr_group_number; const uint8_t u = pusch_pdu->dfts_ofdm.low_papr_group_number;
const uint8_t v = pusch_pdu->dfts_ofdm.low_papr_sequence_number; const uint8_t v = pusch_pdu->dfts_ofdm.low_papr_sequence_number;
c16_t *dmrs_seq = gNB_dmrs_lowpaprtype1_sequence[u][v][index]; c16_t *dmrs_seq = gNB_dmrs_lowpaprtype1_sequence[u][v][index];
LOG_D(PHY,"Transform Precoding params. u: %d, v: %d, index for dmrsseq: %d\n", u, v, index); LOG_D(PHY, "Transform Precoding params. u: %d, v: %d, index for dmrsseq: %d\n", u, v, index);
AssertFatal(index >= 0, "Num RBs not configured according to 3GPP 38.211 section 6.3.1.4. For PUSCH with transform precoding, num RBs cannot be multiple of any other primenumber other than 2,3,5\n"); AssertFatal(index >= 0,
"Num RBs not configured according to 3GPP 38.211 section 6.3.1.4. For PUSCH with transform precoding, num RBs "
"cannot be multiple of any other primenumber other than 2,3,5\n");
AssertFatal(dmrs_seq != NULL, "DMRS low PAPR seq not found, check if DMRS sequences are generated"); AssertFatal(dmrs_seq != NULL, "DMRS low PAPR seq not found, check if DMRS sequences are generated");
nr_pusch_lowpaprtype1_dmrs_rx(gNB, Ns, dmrs_seq, pilot, 1000, 0, nb_rb_pusch, 0, pusch_pdu->dmrs_config_type); nr_pusch_lowpaprtype1_dmrs_rx(gNB, Ns, dmrs_seq, pilot, 1000, 0, nb_rb_pusch, 0, pusch_pdu->dmrs_config_type);
#ifdef DEBUG_PUSCH #ifdef DEBUG_PUSCH
printf ("NR_UL_CHANNEL_EST: index %d, u %d,v %d\n", index, u, v); printf("NR_UL_CHANNEL_EST: index %d, u %d,v %d\n", index, u, v);
LOG_M("gNb_DMRS_SEQ.m","gNb_DMRS_SEQ", dmrs_seq,6*nb_rb_pusch,1,1); LOG_M("gNb_DMRS_SEQ.m", "gNb_DMRS_SEQ", dmrs_seq, 6 * nb_rb_pusch, 1, 1);
#endif #endif
} }
//------------------------------------------------// //------------------------------------------------//
...@@ -141,7 +142,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -141,7 +142,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
#ifdef DEBUG_PUSCH #ifdef DEBUG_PUSCH
for (int i = 0; i < (6 * nb_rb_pusch); i++) { for (int i = 0; i < (6 * nb_rb_pusch); i++) {
LOG_I(PHY, "In %s: %d + j*(%d)\n", __FUNCTION__, pilot[i].r,pilot[i].i); LOG_I(PHY, "In %s: %d + j*(%d)\n", __FUNCTION__, pilot[i].r, pilot[i].i);
} }
#endif #endif
...@@ -153,7 +154,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -153,7 +154,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
delay_t *delay = &gNB->ulsch[ul_id].delay; delay_t *delay = &gNB->ulsch[ul_id].delay;
memset(delay, 0, sizeof(*delay)); memset(delay, 0, sizeof(*delay));
for (int aarx=0; aarx<gNB->frame_parms.nb_antennas_rx; aarx++) { for (int aarx = 0; aarx < gNB->frame_parms.nb_antennas_rx; aarx++) {
c16_t *rxdataF = (c16_t *)&gNB->common_vars.rxdataF[beam_nb][aarx][symbol_offset + slot_offset]; c16_t *rxdataF = (c16_t *)&gNB->common_vars.rxdataF[beam_nb][aarx][symbol_offset + slot_offset];
c16_t *ul_ch = &ul_ch_estimates[nl * gNB->frame_parms.nb_antennas_rx + aarx][symbol_offset]; c16_t *ul_ch = &ul_ch_estimates[nl * gNB->frame_parms.nb_antennas_rx + aarx][symbol_offset];
...@@ -171,9 +172,9 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -171,9 +172,9 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
#endif #endif
if (pusch_pdu->dmrs_config_type == pusch_dmrs_type1 && chest_freq == 0) { if (pusch_pdu->dmrs_config_type == pusch_dmrs_type1 && chest_freq == 0) {
c16_t *pil = pilot; c16_t *pil = pilot;
int re_offset = k0; int re_offset = k0;
LOG_D(PHY,"PUSCH estimation DMRS type 1, Freq-domain interpolation"); LOG_D(PHY, "PUSCH estimation DMRS type 1, Freq-domain interpolation");
int pilot_cnt = 0; int pilot_cnt = 0;
for (int n = 0; n < 3 * nb_rb_pusch; n++) { for (int n = 0; n < 3 * nb_rb_pusch; n++) {
...@@ -203,11 +204,9 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -203,11 +204,9 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
#endif #endif
pilot_cnt = 0; pilot_cnt = 0;
for (int n = 0; n < 3*nb_rb_pusch; n++) { for (int n = 0; n < 3 * nb_rb_pusch; n++) {
// Channel interpolation // Channel interpolation
for (int k_line = 0; k_line <= 1; k_line++) { for (int k_line = 0; k_line <= 1; k_line++) {
// Apply delay // Apply delay
int k = pilot_cnt << 1; int k = pilot_cnt << 1;
c16_t ch16 = c16mulShift(ul_ls_est[k], ul_delay_table[k], 8); c16_t ch16 = c16mulShift(ul_ls_est[k], ul_delay_table[k], 8);
...@@ -216,7 +215,13 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -216,7 +215,13 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
re_offset = (k0 + (n << 2) + (k_line << 1)) % symbolSize; re_offset = (k0 + (n << 2) + (k_line << 1)) % symbolSize;
c16_t *rxF = &rxdataF[re_offset]; c16_t *rxF = &rxdataF[re_offset];
printf("pilot %4d: pil -> (%6d,%6d), rxF -> (%4d,%4d), ch -> (%4d,%4d)\n", printf("pilot %4d: pil -> (%6d,%6d), rxF -> (%4d,%4d), ch -> (%4d,%4d)\n",
pilot_cnt, pil->r, pil->i, rxF->r, rxF->i, ch16.r, ch16.i); pilot_cnt,
pil->r,
pil->i,
rxF->r,
rxF->i,
ch16.r,
ch16.i);
#endif #endif
if (pilot_cnt == 0) { if (pilot_cnt == 0) {
...@@ -258,7 +263,8 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -258,7 +263,8 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
} }
} }
} else if (pusch_pdu->dmrs_config_type == pusch_dmrs_type2 && chest_freq == 0) { // pusch_dmrs_type2 |p_r,p_l,d,d,d,d,p_r,p_l,d,d,d,d| } else if (pusch_pdu->dmrs_config_type == pusch_dmrs_type2
&& chest_freq == 0) { // pusch_dmrs_type2 |p_r,p_l,d,d,d,d,p_r,p_l,d,d,d,d|
LOG_D(PHY, "PUSCH estimation DMRS type 2, Freq-domain interpolation\n"); LOG_D(PHY, "PUSCH estimation DMRS type 2, Freq-domain interpolation\n");
c16_t *pil = pilot; c16_t *pil = pilot;
c16_t *rx = &rxdataF[delta]; c16_t *rx = &rxdataF[delta];
...@@ -285,9 +291,10 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -285,9 +291,10 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
} }
} }
// this is case without frequency-domain linear interpolation, just take average of LS channel estimates of 6 DMRS REs and use a common value for the whole PRB // this is case without frequency-domain linear interpolation, just take average of LS channel estimates of 6 DMRS REs and use a
// common value for the whole PRB
else if (pusch_pdu->dmrs_config_type == pusch_dmrs_type1) { else if (pusch_pdu->dmrs_config_type == pusch_dmrs_type1) {
LOG_D(PHY,"PUSCH estimation DMRS type 1, no Freq-domain interpolation\n"); LOG_D(PHY, "PUSCH estimation DMRS type 1, no Freq-domain interpolation\n");
c16_t *rxF = &rxdataF[delta]; c16_t *rxF = &rxdataF[delta];
int pil_offset = 0; int pil_offset = 0;
int re_offset = k0; int re_offset = k0;
...@@ -297,8 +304,8 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -297,8 +304,8 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
ch = c32x16cumulVectVectWithSteps(pilot, &pil_offset, 1, rxF, &re_offset, 2, symbolSize, 6); ch = c32x16cumulVectVectWithSteps(pilot, &pil_offset, 1, rxF, &re_offset, 2, symbolSize, 6);
#if NO_INTERP #if NO_INTERP
for (c16_t *end=ul_ch+12; ul_ch<end; ul_ch++) for (c16_t *end = ul_ch + 12; ul_ch < end; ul_ch++)
*ul_ch=ch; *ul_ch = ch;
#else #else
c16multaddVectRealComplex(filt8_avlip0, &ch, ul_ch, 8); c16multaddVectRealComplex(filt8_avlip0, &ch, ul_ch, 8);
ul_ch += 8; ul_ch += 8;
...@@ -308,16 +315,16 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -308,16 +315,16 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
ul_ch -= 12; ul_ch -= 12;
#endif #endif
for (int pilot_cnt=6; pilot_cnt<6*(nb_rb_pusch-1); pilot_cnt += 6) { for (int pilot_cnt = 6; pilot_cnt < 6 * (nb_rb_pusch - 1); pilot_cnt += 6) {
ch = c32x16cumulVectVectWithSteps(pilot, &pil_offset, 1, rxF, &re_offset, 2, symbolSize, 6); ch = c32x16cumulVectVectWithSteps(pilot, &pil_offset, 1, rxF, &re_offset, 2, symbolSize, 6);
*max_ch = max(*max_ch, max(abs(ch.r), abs(ch.i))); *max_ch = max(*max_ch, max(abs(ch.r), abs(ch.i)));
#if NO_INTERP #if NO_INTERP
for (c16_t *end=ul_ch+12; ul_ch<end; ul_ch++) for (c16_t *end = ul_ch + 12; ul_ch < end; ul_ch++)
*ul_ch=ch; *ul_ch = ch;
#else #else
ul_ch[3].r += (ch.r * 1365)>>15; // 1/12*16384 ul_ch[3].r += (ch.r * 1365) >> 15; // 1/12*16384
ul_ch[3].i += (ch.i * 1365)>>15; // 1/12*16384 ul_ch[3].i += (ch.i * 1365) >> 15; // 1/12*16384
ul_ch += 4; ul_ch += 4;
c16multaddVectRealComplex(filt8_avlip3, &ch, ul_ch, 8); c16multaddVectRealComplex(filt8_avlip3, &ch, ul_ch, 8);
...@@ -329,26 +336,27 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -329,26 +336,27 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
#endif #endif
} }
// Last PRB // Last PRB
ch=c32x16cumulVectVectWithSteps(pilot, &pil_offset, 1, rxF, &re_offset, 2, symbolSize, 6); ch = c32x16cumulVectVectWithSteps(pilot, &pil_offset, 1, rxF, &re_offset, 2, symbolSize, 6);
#if NO_INTERP #if NO_INTERP
for (c16_t *end=ul_ch+12; ul_ch<end; ul_ch++) for (c16_t *end = ul_ch + 12; ul_ch < end; ul_ch++)
*ul_ch=ch; *ul_ch = ch;
#else #else
ul_ch[3].r += (ch.r * 1365)>>15; // 1/12*16384 ul_ch[3].r += (ch.r * 1365) >> 15; // 1/12*16384
ul_ch[3].i += (ch.i * 1365)>>15; // 1/12*16384 ul_ch[3].i += (ch.i * 1365) >> 15; // 1/12*16384
ul_ch += 4; ul_ch += 4;
c16multaddVectRealComplex(filt8_avlip3, &ch, ul_ch, 8); c16multaddVectRealComplex(filt8_avlip3, &ch, ul_ch, 8);
ul_ch += 8; ul_ch += 8;
c16multaddVectRealComplex(filt8_avlip6, &ch, ul_ch, 8); c16multaddVectRealComplex(filt8_avlip6, &ch, ul_ch, 8);
#endif #endif
} else { // this is case without frequency-domain linear interpolation, just take average of LS channel estimates of 4 DMRS REs and use a common value for the whole PRB } else { // this is case without frequency-domain linear interpolation, just take average of LS channel estimates of 4 DMRS REs
LOG_D(PHY,"PUSCH estimation DMRS type 2, no Freq-domain interpolation"); // and use a common value for the whole PRB
LOG_D(PHY, "PUSCH estimation DMRS type 2, no Freq-domain interpolation");
c16_t *pil = pilot; c16_t *pil = pilot;
int re_offset = (k0 + delta) % symbolSize; int re_offset = (k0 + delta) % symbolSize;
c32_t ch0 = {0}; c32_t ch0 = {0};
//First PRB // First PRB
ch0 = c32x16mulShift(*pil, rxdataF[re_offset], 15); ch0 = c32x16mulShift(*pil, rxdataF[re_offset], 15);
pil++; pil++;
re_offset = (re_offset + 1) % symbolSize; re_offset = (re_offset + 1) % symbolSize;
...@@ -361,10 +369,10 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -361,10 +369,10 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
pil++; pil++;
re_offset = (re_offset + 5) % symbolSize; re_offset = (re_offset + 5) % symbolSize;
c16_t ch=c16x32div(ch0, 4); c16_t ch = c16x32div(ch0, 4);
#if NO_INTERP #if NO_INTERP
for (c16_t *end=ul_ch+12; ul_ch<end; ul_ch++) for (c16_t *end = ul_ch + 12; ul_ch < end; ul_ch++)
*ul_ch=ch; *ul_ch = ch;
#else #else
c16multaddVectRealComplex(filt8_avlip0, &ch, ul_ch, 8); c16multaddVectRealComplex(filt8_avlip0, &ch, ul_ch, 8);
ul_ch += 8; ul_ch += 8;
...@@ -374,7 +382,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -374,7 +382,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
ul_ch -= 12; ul_ch -= 12;
#endif #endif
for (int pilot_cnt=4; pilot_cnt<4*(nb_rb_pusch-1); pilot_cnt += 4) { for (int pilot_cnt = 4; pilot_cnt < 4 * (nb_rb_pusch - 1); pilot_cnt += 4) {
c32_t ch0; c32_t ch0;
ch0 = c32x16mulShift(*pil, rxdataF[re_offset], 15); ch0 = c32x16mulShift(*pil, rxdataF[re_offset], 15);
pil++; pil++;
...@@ -390,14 +398,14 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -390,14 +398,14 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
ch0 = c32x16maddShift(*pil, rxdataF[re_offset], ch0, 15); ch0 = c32x16maddShift(*pil, rxdataF[re_offset], ch0, 15);
pil++; pil++;
re_offset = (re_offset+5) % symbolSize; re_offset = (re_offset + 5) % symbolSize;
ch=c16x32div(ch0, 4); ch = c16x32div(ch0, 4);
*max_ch = max(*max_ch, max(abs(ch.r), abs(ch.i))); *max_ch = max(*max_ch, max(abs(ch.r), abs(ch.i)));
#if NO_INTERP #if NO_INTERP
for (c16_t *end=ul_ch+12; ul_ch<end; ul_ch++) for (c16_t *end = ul_ch + 12; ul_ch < end; ul_ch++)
*ul_ch=ch; *ul_ch = ch;
#else #else
ul_ch[3] = c16maddShift(ch, (c16_t){1365, 1365}, (c16_t){0, 0}, 15); // 1365 = 1/12*16384 (full range is +/- 32768) ul_ch[3] = c16maddShift(ch, (c16_t){1365, 1365}, (c16_t){0, 0}, 15); // 1365 = 1/12*16384 (full range is +/- 32768)
ul_ch += 4; ul_ch += 4;
...@@ -427,10 +435,10 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -427,10 +435,10 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
pil++; pil++;
re_offset = (re_offset + 5) % symbolSize; re_offset = (re_offset + 5) % symbolSize;
ch=c16x32div(ch0, 4); ch = c16x32div(ch0, 4);
#if NO_INTERP #if NO_INTERP
for (c16_t *end=ul_ch+12; ul_ch<end; ul_ch++) for (c16_t *end = ul_ch + 12; ul_ch < end; ul_ch++)
*ul_ch=ch; *ul_ch = ch;
#else #else
ul_ch[3] = c16maddShift(ch, (c16_t){1365, 1365}, (c16_t){0, 0}, 15); // 1365 = 1/12*16384 (full range is +/- 32768) ul_ch[3] = c16maddShift(ch, (c16_t){1365, 1365}, (c16_t){0, 0}, 15); // 1365 = 1/12*16384 (full range is +/- 32768)
ul_ch += 4; ul_ch += 4;
...@@ -444,12 +452,11 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -444,12 +452,11 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
ul_ch = &ul_ch_estimates[nl * gNB->frame_parms.nb_antennas_rx + aarx][symbol_offset]; ul_ch = &ul_ch_estimates[nl * gNB->frame_parms.nb_antennas_rx + aarx][symbol_offset];
for (int idxP = 0; idxP < ceil((float)nb_rb_pusch * 12 / 8); idxP++) { for (int idxP = 0; idxP < ceil((float)nb_rb_pusch * 12 / 8); idxP++) {
for (int idxI = 0; idxI < 8; idxI++) { for (int idxI = 0; idxI < 8; idxI++) {
printf("%d\t%d\t", ul_ch[idxP * 8 + idxI].r, ul_ch[idxP * 8 + idxI].i); printf("%d\t%d\t", ul_ch[idxP * 8 + idxI].r, ul_ch[idxP * 8 + idxI].i);
} }
printf("%d\n", idxP); printf("%d\n", idxP);
} }
#endif #endif
} }
#ifdef DEBUG_CH #ifdef DEBUG_CH
...@@ -463,7 +470,6 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB, ...@@ -463,7 +470,6 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
return 0; return 0;
} }
/******************************************************************* /*******************************************************************
* *
* NAME : nr_pusch_ptrs_processing * NAME : nr_pusch_ptrs_processing
...@@ -495,51 +501,46 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB, ...@@ -495,51 +501,46 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB,
uint32_t nb_re_pusch) uint32_t nb_re_pusch)
{ {
NR_gNB_PUSCH *pusch_vars = &gNB->pusch_vars[ulsch_id]; NR_gNB_PUSCH *pusch_vars = &gNB->pusch_vars[ulsch_id];
int32_t *ptrs_re_symbol = NULL; int32_t *ptrs_re_symbol = NULL;
int8_t ret = 0; int8_t ret = 0;
uint8_t symbInSlot = rel15_ul->start_symbol_index + rel15_ul->nr_of_symbols; uint8_t symbInSlot = rel15_ul->start_symbol_index + rel15_ul->nr_of_symbols;
uint8_t *startSymbIndex = &rel15_ul->start_symbol_index; uint8_t *startSymbIndex = &rel15_ul->start_symbol_index;
uint8_t *nbSymb = &rel15_ul->nr_of_symbols; uint8_t *nbSymb = &rel15_ul->nr_of_symbols;
uint8_t *L_ptrs = &rel15_ul->pusch_ptrs.ptrs_time_density; uint8_t *L_ptrs = &rel15_ul->pusch_ptrs.ptrs_time_density;
uint8_t *K_ptrs = &rel15_ul->pusch_ptrs.ptrs_freq_density; uint8_t *K_ptrs = &rel15_ul->pusch_ptrs.ptrs_freq_density;
uint16_t *dmrsSymbPos = &rel15_ul->ul_dmrs_symb_pos; uint16_t *dmrsSymbPos = &rel15_ul->ul_dmrs_symb_pos;
uint16_t *ptrsSymbPos = &pusch_vars->ptrs_symbols; uint16_t *ptrsSymbPos = &pusch_vars->ptrs_symbols;
uint8_t *ptrsSymbIdx = &pusch_vars->ptrs_symbol_index; uint8_t *ptrsSymbIdx = &pusch_vars->ptrs_symbol_index;
uint16_t *nb_rb = &rel15_ul->rb_size; uint16_t *nb_rb = &rel15_ul->rb_size;
uint8_t *ptrsReOffset = &rel15_ul->pusch_ptrs.ptrs_ports_list[0].ptrs_re_offset; uint8_t *ptrsReOffset = &rel15_ul->pusch_ptrs.ptrs_ports_list[0].ptrs_re_offset;
/* loop over antennas */ /* loop over antennas */
for (int aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { for (int aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++) {
c16_t *phase_per_symbol = (c16_t *)pusch_vars->ptrs_phase_per_slot[aarx]; c16_t *phase_per_symbol = (c16_t *)pusch_vars->ptrs_phase_per_slot[aarx];
ptrs_re_symbol = &pusch_vars->ptrs_re_per_slot; ptrs_re_symbol = &pusch_vars->ptrs_re_per_slot;
*ptrs_re_symbol = 0; *ptrs_re_symbol = 0;
phase_per_symbol[symbol].i = 0; phase_per_symbol[symbol].i = 0;
/* set DMRS estimates to 0 angle with magnitude 1 */ /* set DMRS estimates to 0 angle with magnitude 1 */
if(is_dmrs_symbol(symbol,*dmrsSymbPos)) { if (is_dmrs_symbol(symbol, *dmrsSymbPos)) {
/* set DMRS real estimation to 32767 */ /* set DMRS real estimation to 32767 */
phase_per_symbol[symbol].r=INT16_MAX; // 32767 phase_per_symbol[symbol].r = INT16_MAX; // 32767
#ifdef DEBUG_UL_PTRS #ifdef DEBUG_UL_PTRS
printf("[PHY][PTRS]: DMRS Symbol %d -> %4d + j*%4d\n", symbol, phase_per_symbol[symbol].r,phase_per_symbol[symbol].i); printf("[PHY][PTRS]: DMRS Symbol %d -> %4d + j*%4d\n", symbol, phase_per_symbol[symbol].r, phase_per_symbol[symbol].i);
#endif #endif
} } else { // real ptrs value is set to 0
else {// real ptrs value is set to 0 phase_per_symbol[symbol].r = 0;
phase_per_symbol[symbol].r = 0;
} }
if(symbol == *startSymbIndex) { if (symbol == *startSymbIndex) {
*ptrsSymbPos = 0; *ptrsSymbPos = 0;
set_ptrs_symb_idx(ptrsSymbPos, set_ptrs_symb_idx(ptrsSymbPos, *nbSymb, *startSymbIndex, 1 << *L_ptrs, *dmrsSymbPos);
*nbSymb,
*startSymbIndex,
1<< *L_ptrs,
*dmrsSymbPos);
} }
/* if not PTRS symbol set current ptrs symbol index to zero*/ /* if not PTRS symbol set current ptrs symbol index to zero*/
*ptrsSymbIdx = 0; *ptrsSymbIdx = 0;
/* Check if current symbol contains PTRS */ /* Check if current symbol contains PTRS */
if(is_ptrs_symbol(symbol, *ptrsSymbPos)) { if (is_ptrs_symbol(symbol, *ptrsSymbPos)) {
*ptrsSymbIdx = symbol; *ptrsSymbIdx = symbol;
/*------------------------------------------------------------------------------------------------------- */ /*------------------------------------------------------------------------------------------------------- */
/* 1) Estimate common phase error per PTRS symbol */ /* 1) Estimate common phase error per PTRS symbol */
...@@ -564,27 +565,27 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB, ...@@ -564,27 +565,27 @@ void nr_pusch_ptrs_processing(PHY_VARS_gNB *gNB,
} }
/* For last OFDM symbol at each antenna perform interpolation and compensation for the slot*/ /* For last OFDM symbol at each antenna perform interpolation and compensation for the slot*/
if(symbol == (symbInSlot -1)) { if (symbol == (symbInSlot - 1)) {
/*------------------------------------------------------------------------------------------------------- */ /*------------------------------------------------------------------------------------------------------- */
/* 2) Interpolate PTRS estimated value in TD */ /* 2) Interpolate PTRS estimated value in TD */
/*------------------------------------------------------------------------------------------------------- */ /*------------------------------------------------------------------------------------------------------- */
/* If L-PTRS is > 0 then we need interpolation */ /* If L-PTRS is > 0 then we need interpolation */
if(*L_ptrs > 0) { if (*L_ptrs > 0) {
ret = nr_ptrs_process_slot(*dmrsSymbPos, *ptrsSymbPos, (int16_t*)phase_per_symbol, *startSymbIndex, *nbSymb); ret = nr_ptrs_process_slot(*dmrsSymbPos, *ptrsSymbPos, (int16_t *)phase_per_symbol, *startSymbIndex, *nbSymb);
if(ret != 0) { if (ret != 0) {
LOG_W(PHY,"[PTRS] Compensation is skipped due to error in PTRS slot processing !!\n"); LOG_W(PHY, "[PTRS] Compensation is skipped due to error in PTRS slot processing !!\n");
} }
} }
/*------------------------------------------------------------------------------------------------------- */ /*------------------------------------------------------------------------------------------------------- */
/* 3) Compensated DMRS based estimated signal with PTRS estimation */ /* 3) Compensated DMRS based estimated signal with PTRS estimation */
/*--------------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------------*/
for(uint8_t i = *startSymbIndex; i < symbInSlot; i++) { for (uint8_t i = *startSymbIndex; i < symbInSlot; i++) {
/* DMRS Symbol has 0 phase so no need to rotate the respective symbol */ /* DMRS Symbol has 0 phase so no need to rotate the respective symbol */
/* Skip rotation if the slot processing is wrong */ /* Skip rotation if the slot processing is wrong */
if((!is_dmrs_symbol(i,*dmrsSymbPos)) && (ret == 0)) { if ((!is_dmrs_symbol(i, *dmrsSymbPos)) && (ret == 0)) {
#ifdef DEBUG_UL_PTRS #ifdef DEBUG_UL_PTRS
printf("[PHY][UL][PTRS]: Rotate Symbol %2d with %d + j* %d\n", i, phase_per_symbol[i].r,phase_per_symbol[i].i); printf("[PHY][UL][PTRS]: Rotate Symbol %2d with %d + j* %d\n", i, phase_per_symbol[i].r, phase_per_symbol[i].i);
#endif #endif
rotate_cpx_vector((c16_t *)&pusch_vars->rxdataF_comp[aarx][i * nb_re_pusch], rotate_cpx_vector((c16_t *)&pusch_vars->rxdataF_comp[aarx][i * nb_re_pusch],
&phase_per_symbol[i], &phase_per_symbol[i],
...@@ -613,22 +614,22 @@ int nr_srs_channel_estimation( ...@@ -613,22 +614,22 @@ int nr_srs_channel_estimation(
int8_t *snr) int8_t *snr)
{ {
#ifdef SRS_DEBUG #ifdef SRS_DEBUG
LOG_I(NR_PHY,"Calling %s function\n", __FUNCTION__); LOG_I(NR_PHY, "Calling %s function\n", __FUNCTION__);
#endif #endif
const NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms; const NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms;
const uint64_t subcarrier_offset = frame_parms->first_carrier_offset + srs_pdu->bwp_start*NR_NB_SC_PER_RB; const uint64_t subcarrier_offset = frame_parms->first_carrier_offset + srs_pdu->bwp_start * NR_NB_SC_PER_RB;
const uint8_t N_ap = 1<<srs_pdu->num_ant_ports; const uint8_t N_ap = 1 << srs_pdu->num_ant_ports;
const uint8_t K_TC = 2<<srs_pdu->comb_size; const uint8_t K_TC = 2 << srs_pdu->comb_size;
const uint16_t m_SRS_b = get_m_srs(srs_pdu->config_index, srs_pdu->bandwidth_index); const uint16_t m_SRS_b = get_m_srs(srs_pdu->config_index, srs_pdu->bandwidth_index);
const uint16_t M_sc_b_SRS = m_SRS_b * NR_NB_SC_PER_RB/K_TC; const uint16_t M_sc_b_SRS = m_SRS_b * NR_NB_SC_PER_RB / K_TC;
uint8_t fd_cdm = N_ap; uint8_t fd_cdm = N_ap;
if (N_ap == 4 && ((K_TC == 2 && srs_pdu->cyclic_shift >= 4) || (K_TC == 4 && srs_pdu->cyclic_shift >= 6))) { if (N_ap == 4 && ((K_TC == 2 && srs_pdu->cyclic_shift >= 4) || (K_TC == 4 && srs_pdu->cyclic_shift >= 6))) {
fd_cdm = 2; fd_cdm = 2;
} }
c16_t srs_ls_estimated_channel[frame_parms->ofdm_symbol_size*(1<<srs_pdu->num_symbols)]; c16_t srs_ls_estimated_channel[frame_parms->ofdm_symbol_size * (1 << srs_pdu->num_symbols)];
uint32_t noise_power_per_rb[srs_pdu->bwp_size]; uint32_t noise_power_per_rb[srs_pdu->bwp_size];
const uint32_t arr_len = frame_parms->nb_antennas_rx * N_ap * M_sc_b_SRS; const uint32_t arr_len = frame_parms->nb_antennas_rx * N_ap * M_sc_b_SRS;
...@@ -639,7 +640,8 @@ int nr_srs_channel_estimation( ...@@ -639,7 +640,8 @@ int nr_srs_channel_estimation(
c16_t noise[arr_len]; c16_t noise[arr_len];
memset(noise, 0, arr_len * sizeof(c16_t)); memset(noise, 0, arr_len * sizeof(c16_t));
uint8_t mem_offset = ((16 - ((long)&srs_estimated_channel_freq[0][0][subcarrier_offset + nr_srs_info->k_0_p[0][0]])) & 0xF) >> 2; // >> 2 <=> /sizeof(int32_t) uint8_t mem_offset = ((16 - ((long)&srs_estimated_channel_freq[0][0][subcarrier_offset + nr_srs_info->k_0_p[0][0]])) & 0xF)
>> 2; // >> 2 <=> /sizeof(int32_t)
// filt16_end is {4096,8192,8192,8192,12288,16384,16384,16384,0,0,0,0,0,0,0,0} // filt16_end is {4096,8192,8192,8192,12288,16384,16384,16384,0,0,0,0,0,0,0,0}
// The End of OFDM symbol corresponds to the position of last 16384 in the filter // The End of OFDM symbol corresponds to the position of last 16384 in the filter
...@@ -649,26 +651,23 @@ int nr_srs_channel_estimation( ...@@ -649,26 +651,23 @@ int nr_srs_channel_estimation(
c16_t ls_estimated = {0}; c16_t ls_estimated = {0};
for (int ant = 0; ant < frame_parms->nb_antennas_rx; ant++) { for (int ant = 0; ant < frame_parms->nb_antennas_rx; ant++) {
for (int p_index = 0; p_index < N_ap; p_index++) { for (int p_index = 0; p_index < N_ap; p_index++) {
memset(srs_ls_estimated_channel, 0, frame_parms->ofdm_symbol_size * (1 << srs_pdu->num_symbols) * sizeof(c16_t));
memset(srs_ls_estimated_channel, 0, frame_parms->ofdm_symbol_size*(1<<srs_pdu->num_symbols)*sizeof(c16_t)); memset(srs_est, 0, (frame_parms->ofdm_symbol_size * (1 << srs_pdu->num_symbols) + mem_offset) * sizeof(int32_t));
memset(srs_est, 0, (frame_parms->ofdm_symbol_size*(1<<srs_pdu->num_symbols) + mem_offset)*sizeof(int32_t));
#ifdef SRS_DEBUG #ifdef SRS_DEBUG
LOG_I(NR_PHY,"====================== UE port %d --> gNB Rx antenna %i ======================\n", p_index, ant); LOG_I(NR_PHY, "====================== UE port %d --> gNB Rx antenna %i ======================\n", p_index, ant);
#endif #endif
uint16_t subcarrier = subcarrier_offset + nr_srs_info->k_0_p[p_index][0]; uint16_t subcarrier = subcarrier_offset + nr_srs_info->k_0_p[p_index][0];
if (subcarrier>frame_parms->ofdm_symbol_size) { if (subcarrier > frame_parms->ofdm_symbol_size) {
subcarrier -= frame_parms->ofdm_symbol_size; subcarrier -= frame_parms->ofdm_symbol_size;
} }
c16_t *srs_estimated_channel16 = (c16_t *)&srs_est[subcarrier + mem_offset]; c16_t *srs_estimated_channel16 = (c16_t *)&srs_est[subcarrier + mem_offset];
for (int k = 0; k < M_sc_b_SRS; k++) { for (int k = 0; k < M_sc_b_SRS; k++) {
if (k % fd_cdm == 0) {
if (k%fd_cdm==0) {
ls_estimated = (c16_t){0, 0}; ls_estimated = (c16_t){0, 0};
uint16_t subcarrier_cdm = subcarrier; uint16_t subcarrier_cdm = subcarrier;
...@@ -676,18 +675,21 @@ int nr_srs_channel_estimation( ...@@ -676,18 +675,21 @@ int nr_srs_channel_estimation(
int16_t generated_real = srs_generated_signal[p_index][subcarrier_cdm].r; int16_t generated_real = srs_generated_signal[p_index][subcarrier_cdm].r;
int16_t generated_imag = srs_generated_signal[p_index][subcarrier_cdm].i; int16_t generated_imag = srs_generated_signal[p_index][subcarrier_cdm].i;
int16_t received_real = ((c16_t*)srs_received_signal[ant])[subcarrier_cdm].r; int16_t received_real = ((c16_t *)srs_received_signal[ant])[subcarrier_cdm].r;
int16_t received_imag = ((c16_t*)srs_received_signal[ant])[subcarrier_cdm].i; int16_t received_imag = ((c16_t *)srs_received_signal[ant])[subcarrier_cdm].i;
// We know that nr_srs_info->srs_generated_signal_bits bits are enough to represent the generated_real and generated_imag. // We know that nr_srs_info->srs_generated_signal_bits bits are enough to represent the generated_real and
// So we only need a nr_srs_info->srs_generated_signal_bits shift to ensure that the result fits into 16 bits. // generated_imag. So we only need a nr_srs_info->srs_generated_signal_bits shift to ensure that the result fits into 16
ls_estimated.r += (int16_t)(((int32_t)generated_real*received_real + (int32_t)generated_imag*received_imag)>>nr_srs_info->srs_generated_signal_bits); // bits.
ls_estimated.i += (int16_t)(((int32_t)generated_real*received_imag - (int32_t)generated_imag*received_real)>>nr_srs_info->srs_generated_signal_bits); ls_estimated.r += (int16_t)(((int32_t)generated_real * received_real + (int32_t)generated_imag * received_imag)
>> nr_srs_info->srs_generated_signal_bits);
ls_estimated.i += (int16_t)(((int32_t)generated_real * received_imag - (int32_t)generated_imag * received_real)
>> nr_srs_info->srs_generated_signal_bits);
// Subcarrier increment // Subcarrier increment
subcarrier_cdm += K_TC; subcarrier_cdm += K_TC;
if (subcarrier_cdm >= frame_parms->ofdm_symbol_size) { if (subcarrier_cdm >= frame_parms->ofdm_symbol_size) {
subcarrier_cdm=subcarrier_cdm-frame_parms->ofdm_symbol_size; subcarrier_cdm = subcarrier_cdm - frame_parms->ofdm_symbol_size;
} }
} }
} }
...@@ -695,19 +697,23 @@ int nr_srs_channel_estimation( ...@@ -695,19 +697,23 @@ int nr_srs_channel_estimation(
srs_ls_estimated_channel[subcarrier] = ls_estimated; srs_ls_estimated_channel[subcarrier] = ls_estimated;
#ifdef SRS_DEBUG #ifdef SRS_DEBUG
int subcarrier_log = subcarrier-subcarrier_offset; int subcarrier_log = subcarrier - subcarrier_offset;
if(subcarrier_log < 0) { if (subcarrier_log < 0) {
subcarrier_log = subcarrier_log + frame_parms->ofdm_symbol_size; subcarrier_log = subcarrier_log + frame_parms->ofdm_symbol_size;
} }
if(subcarrier_log%12 == 0) { if (subcarrier_log % 12 == 0) {
LOG_I(NR_PHY,"------------------------------------ %d ------------------------------------\n", subcarrier_log/12); LOG_I(NR_PHY, "------------------------------------ %d ------------------------------------\n", subcarrier_log / 12);
LOG_I(NR_PHY,"\t __genRe________genIm__|____rxRe_________rxIm__|____lsRe________lsIm_\n"); LOG_I(NR_PHY, "\t __genRe________genIm__|____rxRe_________rxIm__|____lsRe________lsIm_\n");
} }
LOG_I(NR_PHY,"(%4i) %6i\t%6i | %6i\t%6i | %6i\t%6i\n", LOG_I(NR_PHY,
"(%4i) %6i\t%6i | %6i\t%6i | %6i\t%6i\n",
subcarrier_log, subcarrier_log,
((c16_t*)srs_generated_signal[p_index])[subcarrier].r, ((c16_t*)srs_generated_signal[p_index])[subcarrier].i, ((c16_t *)srs_generated_signal[p_index])[subcarrier].r,
((c16_t*)srs_received_signal[ant])[subcarrier].r, ((c16_t*)srs_received_signal[ant])[subcarrier].i, ((c16_t *)srs_generated_signal[p_index])[subcarrier].i,
ls_estimated.r, ls_estimated.i); ((c16_t *)srs_received_signal[ant])[subcarrier].r,
((c16_t *)srs_received_signal[ant])[subcarrier].i,
ls_estimated.r,
ls_estimated.i);
#endif #endif
const uint16_t sc_offset = subcarrier + mem_offset; const uint16_t sc_offset = subcarrier + mem_offset;
...@@ -722,7 +728,8 @@ int nr_srs_channel_estimation( ...@@ -722,7 +728,8 @@ int nr_srs_channel_estimation(
srs_estimated_channel16 = (c16_t *)&srs_est[subcarrier]; srs_estimated_channel16 = (c16_t *)&srs_est[subcarrier];
const short *filter = mem_offset == 0 ? filt8_start : filt8_start_shift2; const short *filter = mem_offset == 0 ? filt8_start : filt8_start_shift2;
c16multaddVectRealComplex(filter, &ls_estimated, srs_estimated_channel16, 8); c16multaddVectRealComplex(filter, &ls_estimated, srs_estimated_channel16, 8);
} else if ((subcarrier + K_TC) >= frame_parms->ofdm_symbol_size || k == (M_sc_b_SRS - 1)) { // End of OFDM symbol or last subcarrier cases } else if ((subcarrier + K_TC) >= frame_parms->ofdm_symbol_size
|| k == (M_sc_b_SRS - 1)) { // End of OFDM symbol or last subcarrier cases
// filt8_end is {4096,8192,12288,16384,0,0,0,0} // filt8_end is {4096,8192,12288,16384,0,0,0,0}
const short *filter = mem_offset == 0 || k == (M_sc_b_SRS - 1) ? filt8_end : filt8_end_shift2; const short *filter = mem_offset == 0 || k == (M_sc_b_SRS - 1) ? filt8_end : filt8_end_shift2;
c16multaddVectRealComplex(filter, &ls_estimated, srs_estimated_channel16, 8); c16multaddVectRealComplex(filter, &ls_estimated, srs_estimated_channel16, 8);
...@@ -742,7 +749,8 @@ int nr_srs_channel_estimation( ...@@ -742,7 +749,8 @@ int nr_srs_channel_estimation(
srs_estimated_channel16 = (c16_t *)&srs_est[sc_offset]; srs_estimated_channel16 = (c16_t *)&srs_est[sc_offset];
// filt16_start is {12288,8192,8192,8192,4096,0,0,0,0,0,0,0,0,0,0,0} // filt16_start is {12288,8192,8192,8192,4096,0,0,0,0,0,0,0,0,0,0,0}
c16multaddVectRealComplex(filt16_start, &ls_estimated, srs_estimated_channel16, 16); c16multaddVectRealComplex(filt16_start, &ls_estimated, srs_estimated_channel16, 16);
} else if ((subcarrier + K_TC) >= frame_parms->ofdm_symbol_size || k == (M_sc_b_SRS - 1)) { // End of OFDM symbol or last subcarrier cases } else if ((subcarrier + K_TC) >= frame_parms->ofdm_symbol_size
|| k == (M_sc_b_SRS - 1)) { // End of OFDM symbol or last subcarrier cases
// filt16_end is {4096,8192,8192,8192,12288,16384,16384,16384,0,0,0,0,0,0,0,0} // filt16_end is {4096,8192,8192,8192,12288,16384,16384,16384,0,0,0,0,0,0,0,0}
c16multaddVectRealComplex(filt16_end, &ls_estimated, srs_estimated_channel16, 16); c16multaddVectRealComplex(filt16_end, &ls_estimated, srs_estimated_channel16, 16);
} else { // Middle case } else { // Middle case
...@@ -755,18 +763,18 @@ int nr_srs_channel_estimation( ...@@ -755,18 +763,18 @@ int nr_srs_channel_estimation(
// Subcarrier increment // Subcarrier increment
subcarrier += K_TC; subcarrier += K_TC;
if (subcarrier >= frame_parms->ofdm_symbol_size) { if (subcarrier >= frame_parms->ofdm_symbol_size) {
subcarrier=subcarrier-frame_parms->ofdm_symbol_size; subcarrier = subcarrier - frame_parms->ofdm_symbol_size;
} }
} // for (int k = 0; k < M_sc_b_SRS; k++) } // for (int k = 0; k < M_sc_b_SRS; k++)
memcpy(&srs_estimated_channel_freq[ant][p_index][0], memcpy(&srs_estimated_channel_freq[ant][p_index][0],
&srs_est[mem_offset], &srs_est[mem_offset],
(frame_parms->ofdm_symbol_size*(1<<srs_pdu->num_symbols))*sizeof(int32_t)); (frame_parms->ofdm_symbol_size * (1 << srs_pdu->num_symbols)) * sizeof(int32_t));
// Compute noise // Compute noise
subcarrier = subcarrier_offset + nr_srs_info->k_0_p[p_index][0]; subcarrier = subcarrier_offset + nr_srs_info->k_0_p[p_index][0];
if (subcarrier>frame_parms->ofdm_symbol_size) { if (subcarrier > frame_parms->ofdm_symbol_size) {
subcarrier -= frame_parms->ofdm_symbol_size; subcarrier -= frame_parms->ofdm_symbol_size;
} }
uint16_t base_idx = ant * N_ap * M_sc_b_SRS + p_index * M_sc_b_SRS; uint16_t base_idx = ant * N_ap * M_sc_b_SRS + p_index * M_sc_b_SRS;
...@@ -782,23 +790,23 @@ int nr_srs_channel_estimation( ...@@ -782,23 +790,23 @@ int nr_srs_channel_estimation(
#ifdef SRS_DEBUG #ifdef SRS_DEBUG
subcarrier = subcarrier_offset + nr_srs_info->k_0_p[p_index][0]; subcarrier = subcarrier_offset + nr_srs_info->k_0_p[p_index][0];
if (subcarrier>frame_parms->ofdm_symbol_size) { if (subcarrier > frame_parms->ofdm_symbol_size) {
subcarrier -= frame_parms->ofdm_symbol_size; subcarrier -= frame_parms->ofdm_symbol_size;
} }
for (int k = 0; k < K_TC*M_sc_b_SRS; k++) { for (int k = 0; k < K_TC * M_sc_b_SRS; k++) {
int subcarrier_log = subcarrier - subcarrier_offset;
int subcarrier_log = subcarrier-subcarrier_offset; if (subcarrier_log < 0) {
if(subcarrier_log < 0) {
subcarrier_log = subcarrier_log + frame_parms->ofdm_symbol_size; subcarrier_log = subcarrier_log + frame_parms->ofdm_symbol_size;
} }
if(subcarrier_log%12 == 0) { if (subcarrier_log % 12 == 0) {
LOG_I(NR_PHY,"------------------------------------- %d -------------------------------------\n", subcarrier_log/12); LOG_I(NR_PHY, "------------------------------------- %d -------------------------------------\n", subcarrier_log / 12);
LOG_I(NR_PHY,"\t __lsRe__________lsIm__|____intRe_______intIm__|____noiRe_______noiIm__\n"); LOG_I(NR_PHY, "\t __lsRe__________lsIm__|____intRe_______intIm__|____noiRe_______noiIm__\n");
} }
LOG_I(NR_PHY,"(%4i) %6i\t%6i | %6i\t%6i | %6i\t%6i\n", LOG_I(NR_PHY,
"(%4i) %6i\t%6i | %6i\t%6i | %6i\t%6i\n",
subcarrier_log, subcarrier_log,
srs_ls_estimated_channel[subcarrier].r, srs_ls_estimated_channel[subcarrier].r,
srs_ls_estimated_channel[subcarrier].i, srs_ls_estimated_channel[subcarrier].i,
...@@ -810,23 +818,23 @@ int nr_srs_channel_estimation( ...@@ -810,23 +818,23 @@ int nr_srs_channel_estimation(
// Subcarrier increment // Subcarrier increment
subcarrier++; subcarrier++;
if (subcarrier >= frame_parms->ofdm_symbol_size) { if (subcarrier >= frame_parms->ofdm_symbol_size) {
subcarrier=subcarrier-frame_parms->ofdm_symbol_size; subcarrier = subcarrier - frame_parms->ofdm_symbol_size;
} }
} }
#endif #endif
// Convert to time domain // Convert to time domain
freq2time(gNB->frame_parms.ofdm_symbol_size, freq2time(gNB->frame_parms.ofdm_symbol_size,
(int16_t*) srs_estimated_channel_freq[ant][p_index], (int16_t *)srs_estimated_channel_freq[ant][p_index],
(int16_t*) srs_estimated_channel_time[ant][p_index]); (int16_t *)srs_estimated_channel_time[ant][p_index]);
memcpy(&srs_estimated_channel_time_shifted[ant][p_index][0], memcpy(&srs_estimated_channel_time_shifted[ant][p_index][0],
&srs_estimated_channel_time[ant][p_index][gNB->frame_parms.ofdm_symbol_size>>1], &srs_estimated_channel_time[ant][p_index][gNB->frame_parms.ofdm_symbol_size >> 1],
(gNB->frame_parms.ofdm_symbol_size>>1)*sizeof(int32_t)); (gNB->frame_parms.ofdm_symbol_size >> 1) * sizeof(int32_t));
memcpy(&srs_estimated_channel_time_shifted[ant][p_index][gNB->frame_parms.ofdm_symbol_size>>1], memcpy(&srs_estimated_channel_time_shifted[ant][p_index][gNB->frame_parms.ofdm_symbol_size >> 1],
&srs_estimated_channel_time[ant][p_index][0], &srs_estimated_channel_time[ant][p_index][0],
(gNB->frame_parms.ofdm_symbol_size>>1)*sizeof(int32_t)); (gNB->frame_parms.ofdm_symbol_size >> 1) * sizeof(int32_t));
} // for (int p_index = 0; p_index < N_ap; p_index++) } // for (int p_index = 0; p_index < N_ap; p_index++)
} // for (int ant = 0; ant < frame_parms->nb_antennas_rx; ant++) } // for (int ant = 0; ant < frame_parms->nb_antennas_rx; ant++)
...@@ -835,7 +843,7 @@ int nr_srs_channel_estimation( ...@@ -835,7 +843,7 @@ int nr_srs_channel_estimation(
uint32_t signal_power = max(signal_energy_nodc(ch, arr_len), 1); uint32_t signal_power = max(signal_energy_nodc(ch, arr_len), 1);
#ifdef SRS_DEBUG #ifdef SRS_DEBUG
LOG_I(NR_PHY,"signal_power = %u\n", signal_power); LOG_I(NR_PHY, "signal_power = %u\n", signal_power);
#endif #endif
if (signal_power == 0) { if (signal_power == 0) {
...@@ -845,14 +853,13 @@ int nr_srs_channel_estimation( ...@@ -845,14 +853,13 @@ int nr_srs_channel_estimation(
// Compute noise power // Compute noise power
const uint8_t srs_symbols_per_rb = srs_pdu->comb_size == 0 ? 6 : 3; const uint8_t srs_symbols_per_rb = srs_pdu->comb_size == 0 ? 6 : 3;
const uint8_t n_noise_est = frame_parms->nb_antennas_rx*N_ap*srs_symbols_per_rb; const uint8_t n_noise_est = frame_parms->nb_antennas_rx * N_ap * srs_symbols_per_rb;
uint64_t sum_re = 0; uint64_t sum_re = 0;
uint64_t sum_re2 = 0; uint64_t sum_re2 = 0;
uint64_t sum_im = 0; uint64_t sum_im = 0;
uint64_t sum_im2 = 0; uint64_t sum_im2 = 0;
for (int rb = 0; rb < m_SRS_b; rb++) { for (int rb = 0; rb < m_SRS_b; rb++) {
sum_re = 0; sum_re = 0;
sum_re2 = 0; sum_re2 = 0;
sum_im = 0; sum_im = 0;
...@@ -870,12 +877,13 @@ int nr_srs_channel_estimation( ...@@ -870,12 +877,13 @@ int nr_srs_channel_estimation(
} // for (int p_index = 0; p_index < N_ap; p_index++) } // for (int p_index = 0; p_index < N_ap; p_index++)
} // for (int ant = 0; ant < frame_parms->nb_antennas_rx; ant++) } // for (int ant = 0; ant < frame_parms->nb_antennas_rx; ant++)
noise_power_per_rb[rb] = max(sum_re2 / n_noise_est - (sum_re / n_noise_est) * (sum_re / n_noise_est) + noise_power_per_rb[rb] = max(sum_re2 / n_noise_est - (sum_re / n_noise_est) * (sum_re / n_noise_est) + sum_im2 / n_noise_est
sum_im2 / n_noise_est - (sum_im / n_noise_est) * (sum_im / n_noise_est), 1); - (sum_im / n_noise_est) * (sum_im / n_noise_est),
1);
snr_per_rb[rb] = dB_fixed(signal_power) - dB_fixed(noise_power_per_rb[rb]); snr_per_rb[rb] = dB_fixed(signal_power) - dB_fixed(noise_power_per_rb[rb]);
#ifdef SRS_DEBUG #ifdef SRS_DEBUG
LOG_I(NR_PHY,"noise_power_per_rb[%i] = %i, snr_per_rb[%i] = %i dB\n", rb, noise_power_per_rb[rb], rb, snr_per_rb[rb]); LOG_I(NR_PHY, "noise_power_per_rb[%i] = %i, snr_per_rb[%i] = %i dB\n", rb, noise_power_per_rb[rb], rb, snr_per_rb[rb]);
#endif #endif
} // for (int rb = 0; rb < m_SRS_b; rb++) } // for (int rb = 0; rb < m_SRS_b; rb++)
...@@ -885,7 +893,7 @@ int nr_srs_channel_estimation( ...@@ -885,7 +893,7 @@ int nr_srs_channel_estimation(
*snr = dB_fixed(signal_power) - dB_fixed(noise_power); *snr = dB_fixed(signal_power) - dB_fixed(noise_power);
#ifdef SRS_DEBUG #ifdef SRS_DEBUG
LOG_I(NR_PHY,"noise_power = %u, SNR = %i dB\n", noise_power, *snr); LOG_I(NR_PHY, "noise_power = %u, SNR = %i dB\n", noise_power, *snr);
#endif #endif
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment