From f68d124dcc9ffeac95921f26cabc232347f19ef1 Mon Sep 17 00:00:00 2001 From: hongzhi wang Date: Wed, 4 Jul 2018 17:01:41 +0200 Subject: [PATCH 1/4] ue changing pbch dmrs modulation --- openair1/PHY/NR_REFSIG/nr_dmrs_rx.c | 19 ++++++++++++------- openair1/PHY/NR_REFSIG/nr_mod_table.h | 2 +- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 6 +++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c b/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c index f9b4afeb34..26d883eb17 100644 --- a/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c +++ b/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c @@ -41,6 +41,7 @@ #include "refsig_defs_ue.h" #include "PHY/defs_nr_UE.h" +#include "nr_mod_table.h" #include "log.h" /*Table 7.4.1.1.2-1/2 from 38.211 */ @@ -50,7 +51,7 @@ int wf2[12][2] = {{1,1},{1,-1},{1,1},{1,-1},{1,1},{1,-1},{1,1},{1,1},{1,1},{1,-1 int wt2[12][2] = {{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1}}; //short nr_mod_table[14] = {0,0,-23170,-23170,23170,23170,-23170,-23170,-23170,23170,23170,-23170,23170,23170}; - short nr_mod_table[14] = {0,0,23170,-23170,-23170,23170,23170,-23170,23170,23170,-23170,-23170,-23170,23170}; + short nr_rx_mod_table[NR_MOD_TABLE_SIZE_SHORT] = {0,0,23170,-23170,-23170,23170,23170,-23170,23170,23170,-23170,-23170,-23170,23170}; //short nr_mod_table[14] = {0,0,23170,23170,-23170,-23170,23170,23170,23170,-23170,-23170,23170,-23170,-23170}; //extern short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT]; @@ -143,16 +144,20 @@ int nr_pdsch_dmrs_rx(PHY_VARS_NR_UE *ue, int nr_pbch_dmrs_rx(unsigned int *nr_gold_pbch, int32_t *output ) { - int m; + int m; + uint8_t idx=0; + + /// QPSK modulation + for (m=0; m>1; m++) { + idx = ((((nr_gold_pbch[(m<<1)>>5])>>((m<<1)&0x1f))&1)<<1) ^ (((nr_gold_pbch[((m<<1)+1)>>5])>>(((m<<1)+1)&0x1f))&1); + ((int16_t*)output)[m<<1] = nr_rx_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1]; + ((int16_t*)output)[(m<<1)+1] = nr_rx_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1]; - /// BPSK modulation - for (m=0; m>5]&(1<<(m&0x1f)))>>(m&0x1f)))<<1)]; - ((int16_t*)output)[(m<<1)+1] = nr_mod_table[((1 + ((nr_gold_pbch[m>>5]&(1<<(m&0x1f)))>>(m&0x1f)))<<1) + 1]; #ifdef DEBUG_PBCH - //printf("nr_gold_pbch[m>>5] %x\n",nr_gold_pbch[m>>5]); if (m<16) + {printf("nr_gold_pbch[(m<<1)>>5] %x\n",nr_gold_pbch[(m<<1)>>5]); printf("m %d output %d %d addr %p\n", m, ((int16_t*)output)[m<<1], ((int16_t*)output)[(m<<1)+1],&output[0]); + } #endif } diff --git a/openair1/PHY/NR_REFSIG/nr_mod_table.h b/openair1/PHY/NR_REFSIG/nr_mod_table.h index 75d8262147..3c0c808d1d 100644 --- a/openair1/PHY/NR_REFSIG/nr_mod_table.h +++ b/openair1/PHY/NR_REFSIG/nr_mod_table.h @@ -1,4 +1,4 @@ #define NR_MOD_TABLE_SIZE_SHORT 14 #define NR_MOD_TABLE_BPSK_OFFSET 1 #define NR_MOD_TABLE_QPSK_OFFSET 3 -short nr_mod_table[MOD_TABLE_SIZE_SHORT] = {0,0,23170,23170,-23170,-23170,23170,23170,23170,-23170,-23170,23170,-23170,-23170}; +short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT] = {0,0,23170,23170,-23170,-23170,23170,23170,23170,-23170,-23170,23170,-23170,-23170}; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index 3c062dbfa7..a3180beee8 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -496,7 +496,7 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output; //uint16_t crc; //short nr_demod_table[8] = {0,0,0,1,1,0,1,1}; - double nr_demod_table[8] = {0.707,0.707,0.707,-0.707,-0.707,0.707,-0.707,-0.707}; + double nr_demod_table[8] = {0.707,0.707,-0.707,0.707,0.707,-0.707,-0.707,-0.707}; double *demod_pbch_e = malloc (sizeof(double) * 864); unsigned short idx_demod =0; int8_t decoderState=0; @@ -607,8 +607,8 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, //polar decoding de-rate matching decoderState = polar_decoder(demod_pbch_e, pbch_a, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr); - //for (i=0; i Date: Fri, 13 Jul 2018 15:20:51 +0200 Subject: [PATCH 2/4] ue adding 2nd decrambling and deinterleaving --- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 98 ++++++++++++++++++++------ openair1/PHY/defs_nr_UE.h | 7 +- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index a3180beee8..8e52a89893 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -386,31 +386,53 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms, #endif } -void nr_pbch_unscrambling(NR_DL_FRAME_PARMS *frame_parms, - uint8_t* pbch_a, - uint32_t length) +void nr_pbch_unscrambling(NR_UE_PBCH *pbch, + uint16_t Nid, + uint8_t nushift, + uint16_t M, + uint16_t length, + uint8_t bitwise) { int i; - uint8_t reset; + uint8_t reset, offset; uint32_t x1, x2, s=0; + uint8_t *pbch_e = pbch->pbch_e; + uint32_t *pbch_a_prime = (uint32_t*)pbch->pbch_a_prime; + uint32_t *pbch_a_interleaved = (uint32_t*)pbch->pbch_a_interleaved; + uint32_t unscrambling_mask = 0x100006D; //printf("unscramb nid_cell %d\n",frame_parms->Nid_cell); reset = 1; // x1 is set in first call to lte_gold_generic - x2 = frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.6.1 + x2 = Nid; //this is c_init - for (i=0; i>(i%32))&1) ); - if (((s>>(i%32))&1)==1) - pbch_a[i] = 1-pbch_a[i]; + // The Gold sequence is shifted by nushift* M, so we skip (nushift*M /32) double words + for (int i=0; i<(uint16_t)ceil((nushift*M)/32); i++) { + s = lte_gold_generic(&x1, &x2, reset); + reset = 0; } + // Scrambling is now done with offset (nushift*M)%32 + offset = (nushift*M)&0x1f; + + for (int i=0; i>i)&1)? (((*pbch_a_prime)>>i)&1)<>i)&1) ^ ((s>>((i+offset)&0x1f))&1))<>((i+offset)&0x1f))&1)==1) + pbch_e[i] = -pbch_e[i]; + } + } + } void nr_pbch_alamouti(NR_DL_FRAME_PARMS *frame_parms, @@ -473,6 +495,8 @@ unsigned char sign(int8_t x) { return (unsigned char)x >> 7; } +uint8_t pbch_deinterleaving_pattern[32] = {28,0,31,30,1,29,25,27,22,2,24,3,4,5,6,7,18,21,20,8,9,10,11,19,26,12,13,14,15,16,23,17}; + uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, NR_UE_PBCH *nr_ue_pbch_vars, @@ -490,10 +514,14 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, int symbol,i; //uint8_t pbch_a[64]; - uint8_t *pbch_a = malloc(sizeof(uint8_t) * 32); ; - + uint8_t *pbch_a = malloc(sizeof(uint8_t) * 32); + uint8_t *pbch_a_prime; int8_t *pbch_e_rx; uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output; + uint8_t nushift; + uint16_t M; + uint8_t Lmax=8; //to update + uint8_t ssb_index=0; //uint16_t crc; //short nr_demod_table[8] = {0,0,0,1,1,0,1,1}; double nr_demod_table[8] = {0.707,0.707,-0.707,0.707,0.707,-0.707,-0.707,-0.707}; @@ -582,6 +610,9 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, } pbch_e_rx = nr_ue_pbch_vars->llr; + demod_pbch_e = nr_ue_pbch_vars->demod_pbch_e; + pbch_a = nr_ue_pbch_vars->pbch_a; + pbch_a_prime = nr_ue_pbch_vars->pbch_a_prime; #ifdef DEBUG_PBCH //pbch_e_rx = &nr_ue_pbch_vars->llr[0]; @@ -603,19 +634,40 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, #endif } + //un-scrambling + M = NR_POLAR_PBCH_E; + nushift = (Lmax==4)? ssb_index&3 : ssb_index&7; + nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_E,0); //polar decoding de-rate matching - decoderState = polar_decoder(demod_pbch_e, pbch_a, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr); + decoderState = polar_decoder(demod_pbch_e, pbch_a_prime, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr); for (i=0; i>6)&1)<<1) ^ ((pbch_a_prime[3])&1); + nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_PAYLOAD_BITS,1); + + //payload deinterleaving + uint32_t in=0, out=0; + for (int i=0; i>3; i++) + in |= (uint32_t)(nr_ue_pbch_vars->pbch_a_interleaved[i]<<((3-i)<<3)); + + for (int i=0; i<32; i++) { + out |= ((in>>i)&1)<<(pbch_deinterleaving_pattern[i]); +#ifdef DEBUG_PBCH + printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) 0x%08x\n", i, in, out, pbch_deinterleaver_pattern[i], (in>>i)&1); +#endif + } + + for (int i=0; i>3; i++) + nr_ue_pbch_vars->pbch_a[i] = (uint8_t)((out>>(i<<3))&0xff); // Fix byte endian - for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS); i++) - decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS)-i-1] = pbch_a[i]; + for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++) + decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_a[i]; //#ifdef DEBUG_PBCH for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS); i++) diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 4a25e62c77..ab9953308e 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -149,8 +149,6 @@ #include "targets/ARCH/COMMON/common_lib.h" - - /// Context data structure for RX/TX portion of subframe processing typedef struct { /// index of the current UE RX/TX proc @@ -850,6 +848,11 @@ typedef struct { /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..287] (hard coded) int32_t **dl_ch_estimates_ext; + uint8_t pbch_a[NR_POLAR_PBCH_PAYLOAD_BITS>>3]; + uint8_t pbch_a_interleaved[NR_POLAR_PBCH_PAYLOAD_BITS>>3]; + uint8_t pbch_a_prime[NR_POLAR_PBCH_PAYLOAD_BITS>>3]; + uint8_t pbch_e[NR_POLAR_PBCH_E]; + double demod_pbch_e[NR_POLAR_PBCH_E]; /// \brief Pointer to PBCH llrs. /// - first index: ? [0..1919] (hard coded) int8_t *llr; From bdf0d29c2026f5c9a83436d969d95aa4ae564a54 Mon Sep 17 00:00:00 2001 From: Hongzhi Wang Date: Fri, 13 Jul 2018 15:29:32 +0200 Subject: [PATCH 3/4] adding pbch logs --- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index 8e52a89893..6b4541f864 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -630,7 +630,7 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, if (i<16){ printf("idx[%d]= %d\n", i , idx_demod); printf("sign[%d]= %d sign[%d]= %d\n", i<<1 , sign(pbch_e_rx[i<<1]), (i<<1)+1 , sign(pbch_e_rx[(i<<1)+1])); - printf("demod_pbch_e2[%d] r = %2.3f i = %2.3f\n", i<<1 , demod_pbch_e[i<<1], demod_pbch_e[(i<<1)+1]);} + printf("demod_pbch_e[%d] r = %2.3f i = %2.3f\n", i<<1 , demod_pbch_e[i<<1], demod_pbch_e[(i<<1)+1]);} #endif } @@ -638,6 +638,11 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, M = NR_POLAR_PBCH_E; nushift = (Lmax==4)? ssb_index&3 : ssb_index&7; nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_E,0); + +#ifdef DEBUG_PBCH + if (i<16){ + printf("unscrambling demod_pbch_e[%d] r = %2.3f i = %2.3f\n", i<<1 , demod_pbch_e[i<<1], demod_pbch_e[(i<<1)+1]);} +#endif //polar decoding de-rate matching decoderState = polar_decoder(demod_pbch_e, pbch_a_prime, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr); From a49a0d627ff2286c8c98690d8d871d955ac80df3 Mon Sep 17 00:00:00 2001 From: hongzhi wang Date: Thu, 19 Jul 2018 15:11:48 +0200 Subject: [PATCH 4/4] ue bug fix 2nd unscrambling --- .../nr_dl_channel_estimation.c | 5 +-- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 37 +++++++++++++------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c index ad3f74452c..87361f5e9e 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -46,12 +46,11 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1]; - uint8_t nushift, Lmax, ssb_index=0, n_hf=0; + uint8_t nushift, ssb_index=0, n_hf=0; int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset]; int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF; - Lmax = 8; //to be updated - nushift = (Lmax < 8)? ssb_index&3 : ssb_index&7; + nushift = ue->frame_parms.Nid_cell%4; ue->frame_parms.nushift = nushift; if (ue->high_speed_flag == 0) // use second channel estimate position for temporary storage diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index 6b4541f864..5c2f949341 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -396,7 +396,7 @@ void nr_pbch_unscrambling(NR_UE_PBCH *pbch, int i; uint8_t reset, offset; uint32_t x1, x2, s=0; - uint8_t *pbch_e = pbch->pbch_e; + double *demod_pbch_e = pbch->demod_pbch_e; uint32_t *pbch_a_prime = (uint32_t*)pbch->pbch_a_prime; uint32_t *pbch_a_interleaved = (uint32_t*)pbch->pbch_a_interleaved; uint32_t unscrambling_mask = 0x100006D; @@ -421,6 +421,7 @@ void nr_pbch_unscrambling(NR_UE_PBCH *pbch, reset = 0; } #ifdef DEBUG_PBCH_ENCODING + if (i<8) printf("s: %04x\t", s); #endif if (bitwise) { @@ -429,7 +430,7 @@ void nr_pbch_unscrambling(NR_UE_PBCH *pbch, else { if (((s>>((i+offset)&0x1f))&1)==1) - pbch_e[i] = -pbch_e[i]; + demod_pbch_e[i] = -demod_pbch_e[i]; } } @@ -516,6 +517,7 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, //uint8_t pbch_a[64]; uint8_t *pbch_a = malloc(sizeof(uint8_t) * 32); uint8_t *pbch_a_prime; + uint8_t *pbch_a_b = malloc(sizeof(uint8_t) *NR_POLAR_PBCH_PAYLOAD_BITS); int8_t *pbch_e_rx; uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output; uint8_t nushift; @@ -645,40 +647,51 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, #endif //polar decoding de-rate matching - decoderState = polar_decoder(demod_pbch_e, pbch_a_prime, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr); + decoderState = polar_decoder(demod_pbch_e, pbch_a_b, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr); + memset(&pbch_a_prime[0], 0, sizeof(uint8_t) * NR_POLAR_PBCH_PAYLOAD_BITS>>3); for (i=0; i>3; i++) + printf("pbch_a_prime[%d] = 0x%02x\n", i,pbch_a_prime[i]); +#endif //payload un-scrambling + memset(nr_ue_pbch_vars->pbch_a_interleaved, 0, sizeof(uint8_t) * NR_POLAR_PBCH_PAYLOAD_BITS>>3); M = (Lmax == 64)? (NR_POLAR_PBCH_PAYLOAD_BITS - 6) : (NR_POLAR_PBCH_PAYLOAD_BITS - 3); - nushift = (((pbch_a_prime[0]>>6)&1)<<1) ^ ((pbch_a_prime[3])&1); + nushift = ((pbch_a_prime[0]>>6)&1) ^ (((pbch_a_prime[3])&1)<<1); + //printf("payload unscrambling nushift %d sfn3 %d sfn2 %d M %d\n",nushift, ((pbch_a_prime[0]>>6)&1),((pbch_a_prime[3])&1),M); nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_PAYLOAD_BITS,1); //payload deinterleaving uint32_t in=0, out=0; for (int i=0; i>3; i++) - in |= (uint32_t)(nr_ue_pbch_vars->pbch_a_interleaved[i]<<((3-i)<<3)); + in |= (uint32_t)(nr_ue_pbch_vars->pbch_a_interleaved[i]<<(i<<3)); for (int i=0; i<32; i++) { out |= ((in>>i)&1)<<(pbch_deinterleaving_pattern[i]); #ifdef DEBUG_PBCH - printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) 0x%08x\n", i, in, out, pbch_deinterleaver_pattern[i], (in>>i)&1); + printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) 0x%08x\n", i, in, out, pbch_deinterleaving_pattern[i], (in>>i)&1); #endif } for (int i=0; i>3; i++) - nr_ue_pbch_vars->pbch_a[i] = (uint8_t)((out>>(i<<3))&0xff); + pbch_a[i] = (uint8_t)((out>>(i<<3))&0xff); // Fix byte endian for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++) decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_a[i]; //#ifdef DEBUG_PBCH - for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS); i++) - printf("unscrambling pbch_a[%d] = %d \n", i,pbch_a[i]); - //for (i=0; i>3); i++){ + printf("unscrambling pbch_a[%d] = %x \n", i,pbch_a[i]); + printf("[PBCH] decoder_output[%d] = %x\n",i,decoded_output[i]); + } //#endif }