diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c index f1b72ae897..776cfbbae2 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c @@ -1069,9 +1069,17 @@ int8_t polar_decoder_int16(int16_t *input, nr_polar_deinterleaver(polarParams->nr_polar_CPrime, polarParams->nr_polar_B, polarParams->interleaving_pattern, polarParams->K); //Remove the CRC (รข) - for (int j = 0; j < polarParams->payloadBits; j++) polarParams->nr_polar_A[j]=polarParams->nr_polar_B[j]; + //for (int j = 0; j < polarParams->payloadBits; j++) polarParams->nr_polar_A[j]=polarParams->nr_polar_B[j]; - nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out); - + // Check the CRC + for (int j=0;jcrcParityBits;j++) { + int crcbit=0; + for (int i=0;ipayloadBits;i++) + crcbit = crcbit ^ (polarParams->crc_generator_matrix[i][j] & polarParams->nr_polar_B[i]); + if (crcbit != polarParams->nr_polar_B[polarParams->payloadBits+j]) return(-1); + } + // pack into ceil(payloadBits/32) 32 bit words, lowest index in MSB + // nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out); + nr_byte2bit_uint8_32_t(polarParams->nr_polar_B, polarParams->payloadBits, out); return(0); } diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c index b79739e98d..1967d3934c 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c @@ -443,7 +443,7 @@ void applyGtoright(t_nrPolar_params *pp,decoder_node_t *node) { } else #endif - {// equvalent scalar code to above, activated only on non x86/ARM architectures + {// equvalent scalar code to above, activated only on non x86/ARM architectures or Nv=1,2 for (int i=0;iNv/2;i++) { alpha_r[i] = alpha_v[i+(node->Nv/2)] - (betal[i]*alpha_v[i]); } diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index 396f662289..6d145741b2 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -361,11 +361,13 @@ static inline void nr_polar_interleaver(uint8_t *input, } static inline void nr_polar_deinterleaver(uint8_t *input, - uint8_t *output, - uint16_t *pattern, - uint16_t size) + uint8_t *output, + uint16_t *pattern, + uint16_t size) { - for (int i=0; inr_polar_crc, polarParams->payloadBits, polarParams->crcParityBits); - for (uint8_t i = 0; i < polarParams->crcParityBits; i++) + for (uint8_t i = 0; i < polarParams->crcParityBits; i++) polarParams->nr_polar_crc[i] = (polarParams->nr_polar_crc[i] % 2); //Attach CRC to the Transport Block. (a to b) diff --git a/openair1/PHY/MODULATION/slot_fep_nr.c b/openair1/PHY/MODULATION/slot_fep_nr.c index 6969e4fbe7..f1f2a94b93 100644 --- a/openair1/PHY/MODULATION/slot_fep_nr.c +++ b/openair1/PHY/MODULATION/slot_fep_nr.c @@ -199,9 +199,9 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, switch(channel){ case NR_PBCH_EST: -//#ifdef DEBUG_FEP +#ifdef DEBUG_FEP printf("Channel estimation eNB %d, slot %d, symbol %d\n",eNB_id,Ns,l); -//#endif +#endif #if UE_TIMING_TRACE start_meas(&ue->dlsch_channel_estimation_stats); #endif diff --git a/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c b/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c index bf996c1590..3c4000fa73 100644 --- a/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c +++ b/openair1/PHY/NR_REFSIG/nr_dmrs_rx.c @@ -233,7 +233,7 @@ int nr_pbch_dmrs_rx(int symbol,unsigned int *nr_gold_pbch,int32_t *output ) m0=84; m1=144; } - printf("Generating pilots symbol %d, m0 %d, m1 %d\n",symbol,m0,m1); + // printf("Generating pilots symbol %d, m0 %d, m1 %d\n",symbol,m0,m1); /// QPSK modulation for (m=m0; m>5])>>((m<<1)&0x1f))&1)<<1) ^ (((nr_gold_pbch[((m<<1)+1)>>5])>>(((m<<1)+1)&0x1f))&1); diff --git a/openair1/PHY/NR_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_TRANSPORT/nr_pbch.c index 10416cf8cc..99a243e0ae 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_pbch.c @@ -37,7 +37,7 @@ //#define DEBUG_PBCH //#define DEBUG_PBCH_ENCODING -#define DEBUG_PBCH_DMRS +//#define DEBUG_PBCH_DMRS //extern short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT]; #include "PHY/NR_REFSIG/nr_mod_table.h" @@ -55,7 +55,7 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs, uint8_t idx=0; uint8_t nushift = config->sch_config.physical_cell_id.value &3; - LOG_I(PHY, "PBCH DMRS mapping started at symbol %d shift %d\n", ssb_start_symbol+1, nushift); + LOG_D(PHY, "PBCH DMRS mapping started at symbol %d shift %d\n", ssb_start_symbol+1, nushift); /// QPSK modulation for (int m=0; mofdm_symbol_size); + // printf("pss: writing position k %d / %d\n",k,frame_parms->ofdm_symbol_size); ((int16_t*)txdataF[aa])[2*(l*frame_parms->ofdm_symbol_size + k)] = (a * d_pss[m]) >> 15; k++; 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 6206a95faf..27b11bba7d 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -67,7 +67,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ch_offset = ue->frame_parms.ofdm_symbol_size*symbol; AssertFatal((symbol > 0 && symbol < 4 && ue->is_synchronized == 0) || - (symbol > 0 && symbol < 4 && ue->is_synchronized == 0), + (symbol > 4 && symbol < 8 && ue->is_synchronized == 1), "symbol %d is illegal for PBCH DM-RS (is_synchronized %d)\n", symbol,ue->is_synchronized); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 2390fa8216..52594f9fd2 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -53,7 +53,6 @@ int cnt=0; int nr_pbch_detection(PHY_VARS_NR_UE *ue, runmode_t mode) { - printf("nr pbch detec RB_DL %d\n", ue->frame_parms.N_RB_DL); NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms; int ret =-1; @@ -96,7 +95,6 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, runmode_t mode) //put back nb_prefix_samples0 frame_parms->nb_prefix_samples0 = nb_prefix_samples0; - printf("pbch_detection nid_cell %d\n",frame_parms->Nid_cell); ret = nr_rx_pbch(ue, &ue->proc.proc_rxtx[0], diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index a6ae4ca100..422f1841b1 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -65,22 +65,21 @@ uint16_t nr_pbch_extract(int **rxdataF, unsigned int rx_offset = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier; //and if (rx_offset>= frame_parms->ofdm_symbol_size) rx_offset-=frame_parms->ofdm_symbol_size; - int s_offset; + int s_offset=0; - AssertFatal(((symbol>=1) && (symbol<5) && (is_synchronized==0)) || - ((symbol>=5) && (symbol<8) && (is_synchronized==1)), - "symbol %d illegal for PBCH (is_synchronized %d)\n", - symbol,is_synchronized); + AssertFatal(symbol>=1 && symbol<5, + "symbol %d illegal for PBCH extraction\n", + symbol); - if (is_synchronized==0) s_offset=4; + if (is_synchronized==1) s_offset=4; for (aarx=0; aarxnb_antennas_rx; aarx++) { - rxF = &rxdataF[aarx][symbol*frame_parms->ofdm_symbol_size]; - rxF_ext = &rxdataF_ext[aarx][symbol*(20*12)]; + rxF = &rxdataF[aarx][(symbol+s_offset)*frame_parms->ofdm_symbol_size]; + rxF_ext = &rxdataF_ext[aarx][(symbol+s_offset)*(20*12)]; #ifdef DEBUG_PBCH printf("extract_rbs (nushift %d): rx_offset=%d, symbol %d\n",frame_parms->nushift, - (rx_offset + (symbol*(frame_parms->ofdm_symbol_size))),symbol); + (rx_offset + ((symbol+s_offset)*(frame_parms->ofdm_symbol_size))),symbol); int16_t *p = (int16_t *)rxF; for (int i =0; i<8;i++){ printf("rxF [%d]= %d\n",i,rxF[i]); @@ -92,7 +91,7 @@ uint16_t nr_pbch_extract(int **rxdataF, for (rb=0; rb<20; rb++) { j=0; - if (((s_offset+symbol)==5) || ((s_offset+symbol)==7)) { + if (symbol==1 || symbol==7) { for (i=0; i<12; i++) { if ((i!=nushiftmod4) && (i!=(nushiftmod4+4)) && @@ -138,17 +137,17 @@ uint16_t nr_pbch_extract(int **rxdataF, } if (high_speed_flag == 1) - dl_ch0 = &dl_ch_estimates[aarx][(symbol*(frame_parms->ofdm_symbol_size))]; + dl_ch0 = &dl_ch_estimates[aarx][((symbol+s_offset)*(frame_parms->ofdm_symbol_size))]; else dl_ch0 = &dl_ch_estimates[aarx][0]; //printf("dl_ch0 addr %p\n",dl_ch0); - dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(20*12)]; + dl_ch0_ext = &dl_ch_estimates_ext[aarx][(symbol+s_offset)*(20*12)]; for (rb=0; rb<20; rb++) { j=0; - if ((s_offset+symbol==5) || (s_offset+symbol==7)) { + if (symbol==1 || symbol==7) { for (i=0; i<12; i++) { if ((i!=nushiftmod4) && (i!=(nushiftmod4+4)) && @@ -291,12 +290,16 @@ void nr_pbch_channel_compensation(int **rxdataF_ext, #endif AssertFatal((symbol > 0 && symbol < 4 && is_synchronized == 0) || - (symbol > 0 && symbol < 4 && is_synchronized == 0), + (symbol > 4 && symbol < 8 && is_synchronized == 1), "symbol %d is illegal for PBCH DM-RS (is_synchronized %d)\n", symbol,is_synchronized); + + if (symbol == 2 || symbol == 6) nb_re = 72; + // printf("comp: symbol %d : nb_re %d\n",symbol,nb_re); + for (aarx=0; aarxnb_antennas_rx; aarx++) { #if defined(__x86_64__) || defined(__i386__) @@ -313,7 +316,7 @@ void nr_pbch_channel_compensation(int **rxdataF_ext, #endif for (int re=0; re127) - pbch_llr8[i]=127; - else if (pbch_llr[i]<-128) - pbch_llr8[i]=-128; + if (pbch_llr[i]>31) + pbch_llr8[i]=32; + else if (pbch_llr[i]<-31) + pbch_llr8[i]=-32; else pbch_llr8[i] = (char)(pbch_llr[i]); @@ -548,8 +550,6 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, int subframe_rx = proc->subframe_rx; - printf("ue->current_thread_id[subframe_rx] %d subframe_rx %d\n",ue->current_thread_id[subframe_rx], subframe_rx); - pbch_e_rx = &nr_ue_pbch_vars->llr[0]; // clear LLR buffer @@ -571,7 +571,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].dl_ch_estimates[eNB_id], nr_ue_pbch_vars->rxdataF_ext, nr_ue_pbch_vars->dl_ch_estimates_ext, - symbol, + symbol-first_symbol+1, high_speed_flag, ue->is_synchronized, frame_parms); @@ -664,7 +664,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, decoderState = polar_decoder_int16(pbch_e_rx,&nr_ue_pbch_vars->pbch_a_prime,currentPtr); - printf("polar decoder state %d\n", decoderState); + if(decoderState == -1) return(decoderState); @@ -674,7 +674,6 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, memset(&nr_ue_pbch_vars->pbch_a_interleaved, 0, sizeof(uint32_t) ); M = (Lmax == 64)? (NR_POLAR_PBCH_PAYLOAD_BITS - 6) : (NR_POLAR_PBCH_PAYLOAD_BITS - 3); nushift = ((nr_ue_pbch_vars->pbch_a_prime>>6)&1) ^ (((nr_ue_pbch_vars->pbch_a_prime>>24)&1)<<1); - printf("payload unscrambling nushift %d sfn3 %d sfn2 %d M %d\n",nushift, ((nr_ue_pbch_vars->pbch_a_prime>>6)&1),((nr_ue_pbch_vars->pbch_a_prime>>24)&1),M); nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_PAYLOAD_BITS,1); //payload deinterleaving @@ -684,31 +683,31 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, for (int i=0; i<32; i++) { out |= ((nr_ue_pbch_vars->pbch_a_interleaved>>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, nr_ue_pbch_vars->pbch_a_interleaved, out, pbch_deinterleaving_pattern[i], (in>>i)&1); + printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) 0x%08x\n", i, nr_ue_pbch_vars->pbch_a_interleaved, out, pbch_deinterleaving_pattern[i], (nr_ue_pbch_vars->pbch_a_interleaved>>i)&1); #endif } for (int i=0; i>3; i++) - pbch_a[i] = (uint8_t)((out>>(i<<3))&0xff); + decoded_output[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]; + // 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 +#ifdef DEBUG_PBCH for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++){ - //printf("unscrambling pbch_a[%d] = %x \n", i,pbch_a[i]); + // printf("unscrambling pbch_a[%d] = %x \n", i,pbch_a[i]); printf("[PBCH] decoder payload[%d] = %x\n",i,decoded_output[i]); } - //#endif +#endif ue->dl_indication.rx_ind = &ue->rx_ind; // hang on rx_ind instance //ue->rx_ind.sfn_slot = 0; //should be set by higher-1-layer, i.e. clean_and_set_if_instance() ue->rx_ind.number_pdus = ue->rx_ind.number_pdus + 1; ue->rx_ind.rx_indication_body = (fapi_nr_rx_indication_body_t *)malloc(sizeof(fapi_nr_rx_indication_body_t)); ue->rx_ind.rx_indication_body->pdu_type = FAPI_NR_RX_PDU_TYPE_MIB; - ue->rx_ind.rx_indication_body->mib_pdu.pdu = &decoded_output[1]; - ue->rx_ind.rx_indication_body->mib_pdu.additional_bits = decoded_output[0]; + ue->rx_ind.rx_indication_body->mib_pdu.pdu = &decoded_output[0]; + ue->rx_ind.rx_indication_body->mib_pdu.additional_bits = decoded_output[3]; ue->rx_ind.rx_indication_body->mib_pdu.ssb_index = ssb_index; // confirm with TCL ue->rx_ind.rx_indication_body->mib_pdu.ssb_length = Lmax; // confirm with TCL ue->rx_ind.rx_indication_body->mib_pdu.cell_id = frame_parms->Nid_cell; // confirm with TCL diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 890ebb1013..27b892c425 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -113,7 +113,7 @@ void nr_set_ssb_first_subcarrier(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PAR { int start_rb = cfg->sch_config.n_ssb_crb.value / (1<subframe_config.numerology_index_mu.value); fp->ssb_start_subcarrier = 12 * start_rb + cfg->sch_config.ssb_subcarrier_offset.value; - LOG_I(PHY, "SSB first subcarrier %d (%d,%d)\n", fp->ssb_start_subcarrier,start_rb,cfg->sch_config.ssb_subcarrier_offset.value); + LOG_D(PHY, "SSB first subcarrier %d (%d,%d)\n", fp->ssb_start_subcarrier,start_rb,cfg->sch_config.ssb_subcarrier_offset.value); } void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe) { @@ -135,13 +135,13 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe) { if (subframe == ss_subframe) { // Current implementation is based on SSB in first half frame, first candidate - LOG_I(PHY,"SS TX: frame %d, subframe %d, start_symbol %d\n",frame,subframe, ssb_start_symbol); + LOG_D(PHY,"SS TX: frame %d, subframe %d, start_symbol %d\n",frame,subframe, ssb_start_symbol); nr_generate_pss(gNB->d_pss, txdataF, AMP, ssb_start_symbol, cfg, fp); nr_generate_sss(gNB->d_sss, txdataF, AMP_OVER_2, ssb_start_symbol, cfg, fp); if (!(frame&7)){ - LOG_I(PHY,"%d.%d : pbch_configured %d\n",frame,subframe,gNB->pbch_configured); + LOG_D(PHY,"%d.%d : pbch_configured %d\n",frame,subframe,gNB->pbch_configured); if (gNB->pbch_configured != 1)return; gNB->pbch_configured = 0; } @@ -183,7 +183,7 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, num_dci = gNB->pdcch_vars.num_dci; if (num_dci) { - LOG_I(PHY, "[gNB %d] Frame %d subframe %d \ + LOG_D(PHY, "[gNB %d] Frame %d subframe %d \ Calling nr_generate_dci_top (number of DCI %d)\n", gNB->Mod_id, frame, subframe, num_dci); uint8_t slot_idx = gNB->pdcch_vars.dci_alloc[0].pdcch_params.first_slot; diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 387daeabcb..cf276e8faa 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -118,7 +118,8 @@ int main(int argc, char **argv) nfapi_nr_config_request_t *gNB_config; int ret; - + int run_initial_sync=0; + cpuf = get_cpu_freq_GHz(); if ( load_configmodule(argc,argv) == 0) { @@ -128,7 +129,7 @@ int main(int argc, char **argv) logInit(); randominit(0); - while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:s:S:t:x:y:z:N:F:GR:dP:")) != -1) { + while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:s:S:t:x:y:z:N:F:GR:dP:I")) != -1) { switch (c) { case 'f': write_output_file=1; @@ -280,7 +281,10 @@ int main(int argc, char **argv) printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase); break; - + + case 'I': + run_initial_sync=1; + break; default: case 'h': printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", @@ -400,7 +404,9 @@ int main(int argc, char **argv) UE = malloc(sizeof(PHY_VARS_NR_UE)); memcpy(&UE->frame_parms,frame_parms,sizeof(NR_DL_FRAME_PARMS)); phy_init_nr_top(UE); - UE->is_synchronized = 0; + if (run_initial_sync==1) UE->is_synchronized = 0; + else UE->is_synchronized = 1; + UE->perfect_ce = 0; if (init_nr_ue_signal(UE, 1, 0) != 0) @@ -409,19 +415,19 @@ int main(int argc, char **argv) exit(-1); } - + nr_gold_pbch(UE); // generate signal if (input_fd==NULL) { gNB->pbch_configured = 1; - for (int i=0;i<4;i++) gNB->pbch_pdu[3-i]=i; + for (int i=0;i<4;i++) gNB->pbch_pdu[i]=i+1; nr_common_signal_procedures (gNB,frame,subframe); } - + /* LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); if (gNB->frame_parms.nb_antennas_tx>1) LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1); - + */ //TODO: loop over slots for (aa=0; aaframe_parms.nb_antennas_tx; aa++) { if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) { @@ -438,20 +444,20 @@ int main(int argc, char **argv) frame_parms); } } - + /* LOG_M("txsig0.m","txs0", txdata[0],frame_length_complex_samples,1,1); if (gNB->frame_parms.nb_antennas_tx>1) LOG_M("txsig1.m","txs1", txdata[1],frame_length_complex_samples,1,1); - + */ int txlev = signal_energy(&txdata[0][5*frame_parms->ofdm_symbol_size + 4*frame_parms->nb_prefix_samples + frame_parms->nb_prefix_samples0], frame_parms->ofdm_symbol_size + frame_parms->nb_prefix_samples); - printf("txlev %d\n",txlev); + // printf("txlev %d (%f)\n",txlev,10*log10(txlev)); for (i=0; inb_antennas_tx; aa++) { - r_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)])/sqrt((double)txlev); - r_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1])/sqrt((double)txlev); + r_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); + r_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); } } @@ -467,15 +473,15 @@ int main(int argc, char **argv) //multipath_channel(gNB2UE,s_re,s_im,r_re,r_im,frame_length_complex_samples,0); //AWGN - sigma2_dB = -SNR; + sigma2_dB = 10*log10((double)txlev)-SNR; sigma2 = pow(10,sigma2_dB/10); - printf("sigma2 %f\n",sigma2); + // printf("sigma2 %f (%f dB)\n",sigma2,sigma2_dB); for (i=0; inb_antennas_rx; aa++) { - ((short*) UE->common_vars.rxdata[aa])[2*i] = (short) ((r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))*512); - ((short*) UE->common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))*512); + ((short*) UE->common_vars.rxdata[aa])[2*i] = (short) ((r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short*) UE->common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } } @@ -484,10 +490,49 @@ int main(int argc, char **argv) if (gNB->frame_parms.nb_antennas_tx>1) LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],frame_length_complex_samples,1,1); } + if (UE->is_synchronized == 0) { + ret = nr_initial_sync(UE, normal_txrx); + printf("nr_initial_sync1 returns %d\n",ret); + if (ret<0) n_errors++; + } + else { + UE->rx_offset=0; + //symbol 1 + nr_slot_fep(UE, + 5, + 0, + 0, + 0, + 1, + NR_PBCH_EST); + + //symbol 2 + nr_slot_fep(UE, + 6, + 0, + 0, + 0, + 1, + NR_PBCH_EST); + + //symbol 3 + nr_slot_fep(UE, + 7, + 0, + 0, + 0, + 1, + NR_PBCH_EST); + + ret = nr_rx_pbch(UE, + &UE->proc.proc_rxtx[0], + UE->pbch_vars[0], + frame_parms, + 0, + SISO, + UE->high_speed_flag); - ret = nr_initial_sync(UE, normal_txrx); - printf("nr_initial_sync1 returns %d\n",ret); - + } } //noise trials printf("SNR %f : n_errors = %d/%d\n", SNR,n_errors,n_trials);