int test_logmap8(LTE_eNB_DLSCH_t *dlsch_eNB, LTE_UE_DLSCH_t *dlsch_ue, unsigned int coded_bits, unsigned char NB_RB, double sigma, unsigned char qbits, unsigned int block_length, unsigned int ntrials, unsigned int *errors, unsigned int *trials, unsigned int *uerrors, unsigned int *crc_misses, unsigned int *iterations, unsigned int num_pdcch_symbols, unsigned int subframe) { unsigned char test_input[block_length+1]; //_declspec(align(16)) char channel_output[512]; //_declspec(align(16)) unsigned char output[512],decoded_output[16], *inPtr, *outPtr; short *channel_output; unsigned char decoded_output[block_length]; unsigned int i,trial=0; unsigned int crc=0; unsigned char ret; unsigned char uerr; unsigned char crc_type; channel_output = (short *)malloc(coded_bits*sizeof(short)); *iterations=0; *errors=0; *crc_misses=0; *uerrors=0; // printf("dlsch_eNB->TBS= %d\n",dlsch_eNB->harq_processes[0]->TBS); while (trial++ < ntrials) { // printf("encoding\n"); for (i=0;i<block_length;i++) { test_input[i] = (unsigned char)(taus()&0xff); } dlsch_encoding(test_input, &PHY_vars_eNB->lte_frame_parms, num_pdcch_symbols, PHY_vars_eNB->dlsch_eNB[0][0], subframe); uerr=0; for (i = 0; i < coded_bits; i++){ channel_output[i] = (short)quantize(sigma/4.0,(2.0*PHY_vars_eNB->dlsch_eNB[0][0]->e[i]) - 1.0 + sigma*gaussdouble(0.0,1.0),qbits); } // memset(decoded_output,0,16); // printf("decoding\n"); ret = dlsch_decoding(channel_output, &PHY_vars_UE->lte_frame_parms, PHY_vars_UE->dlsch_ue[0][0], subframe, num_pdcch_symbols); /* int diffs = 0,puncts=0; for (i=0;i<dlsch_ue->harq_processes[0]->Kplus*3;i++) { if (dlsch_ue->harq_processes[0]->d[0][96+i] == 0) { printf("%d punct (%d,%d)\n",i,dlsch_ue->harq_processes[0]->d[0][96+i],dlsch_eNb->harq_processes[0]->d[0][96+i]); puncts++; } else if (sgn(dlsch_ue->harq_processes[0]->d[0][96+i]) != dlsch_eNb->harq_processes[0]->d[0][96+i]) { printf("%d differs (%d,%d)\n",i,dlsch_ue->harq_processes[0]->d[0][96+i],dlsch_eNb->harq_processes[0]->d[0][96+i]); diffs++; } else printf("%d same (%d,%d)\n",i,dlsch_ue->harq_processes[0]->d[0][96+i],dlsch_eNb->harq_processes[0]->d[0][96+i]); } printf("diffs %d puncts %d(%d,%d,%d,%d,%d)\n",diffs,puncts,dlsch_ue->harq_processes[0]->F,coded_bits,3*(block_length<<3),3*dlsch_ue->harq_processes[0]->Kplus,3*dlsch_ue->harq_processes[0]->F+3*(block_length<<3)-coded_bits); */ // printf("ret %d\n",ret); // printf("trial %d : i %d/%d : Input %x, Output %x (%x, F %d)\n",trial,0,block_length,test_input[0], // dlsch_ue->harq_processes[0]->b[0], // dlsch_ue->harq_processes[0]->c[0][0], // (dlsch_ue->harq_processes[0]->F>>3)); if (ret < MAX_TURBO_ITERATIONS+1) *iterations = (*iterations) + ret; else *iterations = (*iterations) + (ret-1); if (uerr==1) *uerrors = (*uerrors) + 1; for (i=0;i<block_length;i++) { if (dlsch_ue->harq_processes[0]->b[i] != test_input[i]) { // printf("i %d/%d : Input %x, Output %x (%x, F %d)\n",i,block_length,test_input[i], // dlsch_ue->harq_processes[0]->b[i], // dlsch_ue->harq_processes[0]->c[0][i], // (dlsch_ue->harq_processes[0]->F>>3)); *errors = (*errors) + 1; // printf("*%d\n",*errors); if (ret < MAX_TURBO_ITERATIONS+1) *crc_misses = (*crc_misses)+1; break; } } if (*errors == 100) { //printf("\n"); break; } } *trials = trial; // printf("lte: trials %d, errors %d\n",trial,*errors); return(0); }
int test_logmap8(LTE_eNB_DLSCH_t *dlsch_eNB, LTE_UE_DLSCH_t *dlsch_ue, unsigned int coded_bits, unsigned char NB_RB, double sigma, unsigned char qbits, unsigned int block_length, unsigned int ntrials, unsigned int *errors, unsigned int *trials, unsigned int *uerrors, unsigned int *crc_misses, unsigned int *iterations, unsigned int num_pdcch_symbols, unsigned int subframe) { unsigned char test_input[block_length+1]; short *channel_output; unsigned char decoded_output[block_length]; unsigned int i,trial=0; unsigned int crc=0; unsigned char ret; unsigned char uerr; unsigned char crc_type; channel_output = (short *)malloc(coded_bits*sizeof(short)); *iterations=0; *errors=0; *crc_misses=0; *uerrors=0; // printf("dlsch_eNB->TBS= %d, block_length %d\n",dlsch_eNB->harq_processes[0]->TBS,block_length); while (trial++ < ntrials) { // printf("encoding\n"); // test_input[0] = 0x80; for (i=0; i<block_length; i++) { test_input[i] = i&0xff;//(unsigned char)(taus()&0xff); } dlsch_encoding(test_input, &PHY_vars_eNB->lte_frame_parms, num_pdcch_symbols, PHY_vars_eNB->dlsch_eNB[0][0], 0, subframe, &PHY_vars_eNB->dlsch_rate_matching_stats, &PHY_vars_eNB->dlsch_turbo_encoding_stats, &PHY_vars_eNB->dlsch_interleaving_stats); uerr=0; for (i = 0; i < coded_bits; i++) { #ifdef DEBUG_CODER if ((i&0xf)==0) printf("\ne %d..%d: ",i,i+15); printf("%d.",PHY_vars_eNB->dlsch_eNB[0][0]->harq_processes[0]->e[i]); #endif channel_output[i] = (short)quantize(sigma/4.0,(2.0*PHY_vars_eNB->dlsch_eNB[0][0]->harq_processes[0]->e[i]) - 1.0 + sigma*gaussdouble(0.0,1.0),qbits); // printf("input %d, output %f\n",(2*PHY_vars_eNB->dlsch_eNB[0][0]->e[i]) - 1, // (2.0*PHY_vars_eNB->dlsch_eNB[0][0]->e[i]) - 1.0 + sigma*gaussdouble(0.0,1.0)); } #ifdef DEBUG_CODER printf("\n"); exit(-1); #endif PHY_vars_UE->dlsch_ue[0][0]->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid]->G = coded_bits; ret = dlsch_decoding(PHY_vars_UE, channel_output, &PHY_vars_UE->lte_frame_parms, PHY_vars_UE->dlsch_ue[0][0], PHY_vars_UE->dlsch_ue[0][0]->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid], subframe, PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid, num_pdcch_symbols,1); /* int diffs = 0,puncts=0; for (i=0;i<dlsch_ue->harq_processes[0]->Kplus*3;i++) { if (dlsch_ue->harq_processes[0]->d[0][96+i] == 0) { printf("%d punct (%d,%d)\n",i,dlsch_ue->harq_processes[0]->d[0][96+i],dlsch_eNb->harq_processes[0]->d[0][96+i]); puncts++; } else if (sgn(dlsch_ue->harq_processes[0]->d[0][96+i]) != dlsch_eNb->harq_processes[0]->d[0][96+i]) { printf("%d differs (%d,%d)\n",i,dlsch_ue->harq_processes[0]->d[0][96+i],dlsch_eNb->harq_processes[0]->d[0][96+i]); diffs++; } else printf("%d same (%d,%d)\n",i,dlsch_ue->harq_processes[0]->d[0][96+i],dlsch_eNb->harq_processes[0]->d[0][96+i]); } printf("diffs %d puncts %d(%d,%d,%d,%d,%d)\n",diffs,puncts,dlsch_ue->harq_processes[0]->F,coded_bits,3*(block_length<<3),3*dlsch_ue->harq_processes[0]->Kplus,3*dlsch_ue->harq_processes[0]->F+3*(block_length<<3)-coded_bits); printf("ret %d (max %d)\n",ret,dlsch_ue->max_turbo_iterations); printf("trial %d : i %d/%d : Input %x, Output %x (%x, F %d)\n",trial,0,block_length,test_input[0], dlsch_ue->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid]->b[0], dlsch_ue->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid]->c[0][0], (dlsch_ue->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid]->F>>3)); */ if (ret < dlsch_ue->max_turbo_iterations+1) { *iterations = (*iterations) + ret; // if (ret>1) // printf("ret %d\n",ret); } else *iterations = (*iterations) + (ret-1); if (uerr==1) *uerrors = (*uerrors) + 1; for (i=0; i<block_length; i++) { if (dlsch_ue->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid]->c[0][i] != test_input[i]) { /* printf("i %d/%d : Input %x, Output %x (%x, F %d)\n",i,block_length,test_input[i], dlsch_ue->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid]->b[i], dlsch_ue->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid]->c[0][i], (dlsch_ue->harq_processes[PHY_vars_UE->dlsch_ue[0][0]->current_harq_pid]->F>>3)); */ *errors = (*errors) + 1; // printf("*%d, ret %d\n",*errors,ret); if (ret < dlsch_ue->max_turbo_iterations+1) *crc_misses = (*crc_misses)+1; break; } } if (ret == dlsch_ue->max_turbo_iterations+1) { // exit(-1); } /* else { for (i=0;i<block_length;i++) { if (dlsch_ue->harq_processes[0]->b[i] != test_input[i]) { printf("i %d/%d : Input %x, Output %x (%x, F %d)\n",i,block_length,test_input[i], dlsch_ue->harq_processes[0]->b[i], dlsch_ue->harq_processes[0]->c[0][i], (dlsch_ue->harq_processes[0]->F>>3)); } } }*/ if (*errors == 100) { printf("trials %d\n",trial); break; } } *trials = trial; // printf("lte: trials %d, errors %d\n",trial,*errors); return(0); }
int main(int argc, char **argv) { char c; int i,aa,s,ind,Kr,Kr_bytes;; double sigma2, sigma2_dB=10,SNR,snr0=-2.0,snr1,SNRmeas; //int **txdataF, **txdata; int **txdata; #ifdef IFFT_FPGA int **txdataF2; #endif //LTE_DL_FRAME_PARMS *frame_parms = (LTE_DL_FRAME_PARMS *)malloc(sizeof(LTE_DL_FRAME_PARMS)); //LTE_UE_COMMON *lte_ue_common_vars = (LTE_UE_COMMON *)malloc(sizeof(LTE_UE_COMMON)); double **s_re,**s_im,**r_re,**r_im; double amps[8] = {0.3868472 , 0.3094778 , 0.1547389 , 0.0773694 , 0.0386847 , 0.0193424 , 0.0096712 , 0.0038685}; double aoa=.03,ricean_factor=1; //0.0000005; int channel_length; struct complex **ch; int eNb_id = 0, eNb_id_i = 1; unsigned char mcs,dual_stream_UE = 0; unsigned short NB_RB=conv_nprb(0,DLSCH_RB_ALLOC); unsigned char Ns,l,m; unsigned char *input_data,*decoded_output; unsigned char *input_buffer; unsigned short input_buffer_length; unsigned int ret; unsigned int coded_bits_per_codeword,nsymb,dci_cnt; unsigned int tx_lev,tx_lev_dB,trials,errs=0,dci_errors=0,dlsch_active=0,num_layers; int re_allocated; FILE *bler_fd; FILE *csv_fd; char bler_fname[20]; char csv_fname[20]; unsigned char pbch_pdu[6]; DCI_ALLOC_t dci_alloc[8],dci_alloc_rx[8]; FILE *rx_frame_file; int result; int n_frames; int cnt=0; int rx_lev_data_sym; int rx_lev_null_sym; int rx_snr_dB; void *data; int ii; int bler; double blerr; int ch_realization; channel_length = (int) 11+2*BW*Td; lte_param_init(1,1,1); num_layers = 1; //int cont=0; // default parameters //for (cont =0;cont<29;cont++){ mcs = 0; n_frames = 1000; snr0 = 2; //if(snr0>0) // snr0 = 0; while ((c = getopt (argc, argv, "hm:n:s:")) != -1) { switch (c) { case 'h': printf("%s -h(elp) -m mcs -n n_frames -s snr0\n",argv[0]); exit(1); case 'm': mcs = atoi(optarg); break; case 'n': n_frames = atoi(optarg); break; case 's': snr0 = atoi(optarg); break; default: printf("%s -h(elp) -m mcs -n n_frames -s snr0\n",argv[0]); exit (-1); break; } } printf("Setting mcs = %d\n",mcs); printf("NPRB = %d\n",NB_RB); printf("n_frames = %d\n",n_frames); /* snr0 = -7 + mcs; if(snr0>0) snr0 = ; */ snr1 = snr0+20; printf("SNR0 %f, SNR1 %f\n",snr0,snr1); /* txdataF = (int **)malloc16(2*sizeof(int*)); txdataF[0] = (int *)malloc16(FRAME_LENGTH_BYTES); txdataF[1] = (int *)malloc16(FRAME_LENGTH_BYTES); txdata = (int **)malloc16(2*sizeof(int*)); txdata[0] = (int *)malloc16(FRAME_LENGTH_BYTES); txdata[1] = (int *)malloc16(FRAME_LENGTH_BYTES); */ #ifdef IFFT_FPGA txdata = (int **)malloc16(2*sizeof(int*)); txdata[0] = (int *)malloc16(FRAME_LENGTH_BYTES); txdata[1] = (int *)malloc16(FRAME_LENGTH_BYTES); bzero(txdata[0],FRAME_LENGTH_BYTES); bzero(txdata[1],FRAME_LENGTH_BYTES); txdataF2 = (int **)malloc16(2*sizeof(int*)); txdataF2[0] = (int *)malloc16(FRAME_LENGTH_BYTES_NO_PREFIX); txdataF2[1] = (int *)malloc16(FRAME_LENGTH_BYTES_NO_PREFIX); bzero(txdataF2[0],FRAME_LENGTH_BYTES_NO_PREFIX); bzero(txdataF2[1],FRAME_LENGTH_BYTES_NO_PREFIX); #else txdata = PHY_vars_eNb->lte_eNB_common_vars.txdata[eNb_id]; #endif s_re = malloc(2*sizeof(double*)); s_im = malloc(2*sizeof(double*)); r_re = malloc(2*sizeof(double*)); r_im = malloc(2*sizeof(double*)); nsymb = (lte_frame_parms->Ncp == 0) ? 14 : 12; coded_bits_per_codeword = NB_RB * (12 * get_Qm(mcs)) * (lte_frame_parms->num_dlsch_symbols); printf("Rate = %f (mod %d)\n",(((double)dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1])*3/4)/coded_bits_per_codeword, get_Qm(mcs)); sprintf(bler_fname,"bler_%d.m",mcs); bler_fd = fopen(bler_fname,"w"); fprintf(bler_fd,"bler = ["); // CSV file sprintf(csv_fname,"data_out%d.m",mcs); csv_fd = fopen(csv_fname,"w"); fprintf(csv_fd,"data_all=["); for (i=0;i<2;i++) { s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); } PHY_vars_UE->lte_ue_pdcch_vars[0]->crnti = 0x1234; // Fill in UL_alloc UL_alloc_pdu.type = 0; UL_alloc_pdu.hopping = 0; UL_alloc_pdu.rballoc = UL_RB_ALLOC; UL_alloc_pdu.mcs = 1; UL_alloc_pdu.ndi = 1; UL_alloc_pdu.TPC = 0; UL_alloc_pdu.cqi_req = 1; CCCH_alloc_pdu.type = 0; CCCH_alloc_pdu.vrb_type = 0; CCCH_alloc_pdu.rballoc = CCCH_RB_ALLOC; CCCH_alloc_pdu.ndi = 1; CCCH_alloc_pdu.mcs = 1; CCCH_alloc_pdu.harq_pid = 0; DLSCH_alloc_pdu2.rah = 0; DLSCH_alloc_pdu2.rballoc = DLSCH_RB_ALLOC; DLSCH_alloc_pdu2.TPC = 0; DLSCH_alloc_pdu2.dai = 0; DLSCH_alloc_pdu2.harq_pid = 0; DLSCH_alloc_pdu2.tb_swap = 0; DLSCH_alloc_pdu2.mcs1 = mcs; DLSCH_alloc_pdu2.ndi1 = 1; DLSCH_alloc_pdu2.rv1 = 0; // Forget second codeword DLSCH_alloc_pdu2.tpmi = 5 ; // precoding // Create transport channel structures for SI pdus PHY_vars_eNb->dlsch_eNb_cntl = new_eNb_dlsch(1,1); PHY_vars_UE->dlsch_ue_cntl = new_ue_dlsch(1,1); // Create transport channel structures for 2 transport blocks (MIMO) PHY_vars_eNb->dlsch_eNb = (LTE_eNb_DLSCH_t**) malloc16(2*sizeof(LTE_eNb_DLSCH_t*)); PHY_vars_UE->dlsch_ue = (LTE_UE_DLSCH_t**) malloc16(2*sizeof(LTE_UE_DLSCH_t*)); for (i=0;i<2;i++) { PHY_vars_eNb->dlsch_eNb[i] = new_eNb_dlsch(1,8); PHY_vars_UE->dlsch_ue[i] = new_ue_dlsch(1,8); if (!PHY_vars_eNb->dlsch_eNb[i]) { printf("Can't get eNb dlsch structures\n"); exit(-1); } if (!PHY_vars_UE->dlsch_ue[i]) { printf("Can't get ue dlsch structures\n"); exit(-1); } } if (DLSCH_alloc_pdu2.tpmi == 5) { PHY_vars_eNb->dlsch_eNb[0]->pmi_alloc = (unsigned short)(taus()&0xffff); PHY_vars_UE->dlsch_ue[0]->pmi_alloc = PHY_vars_eNb->dlsch_eNb[0]->pmi_alloc; PHY_vars_eNb->eNB_UE_stats[0].DL_pmi_single[0] = PHY_vars_eNb->dlsch_eNb[0]->pmi_alloc; } generate_eNb_dlsch_params_from_dci(0, &DLSCH_alloc_pdu2, 0x1234, format2_2A_M10PRB, PHY_vars_eNb->dlsch_eNb, lte_frame_parms, SI_RNTI, RA_RNTI, P_RNTI, 0); //change this later /* generate_eNb_dlsch_params_from_dci(0, &CCCH_alloc_pdu, SI_RNTI, format1A, &dlsch_eNb_cntl, lte_frame_parms, SI_RNTI, RA_RNTI, P_RNTI); */ // input_data = (unsigned char*) malloc(block_length/8); // decoded_output = (unsigned char*) malloc(block_length/8); // DCI memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2,sizeof(DCI2_5MHz_2A_M10PRB_TDD_t)); dci_alloc[0].dci_length = sizeof_DCI2_5MHz_2A_M10PRB_TDD_t; dci_alloc[0].L = 3; dci_alloc[0].rnti = 0x1234; /* memcpy(&dci_alloc[0].dci_pdu[0],&CCCH_alloc_pdu,sizeof(DCI1A_5MHz_TDD_1_6_t)); dci_alloc[0].dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t; dci_alloc[0].L = 3; dci_alloc[0].rnti = SI_RNTI; */ memcpy(&dci_alloc[1].dci_pdu[0],&UL_alloc_pdu,sizeof(DCI0_5MHz_TDD0_t)); dci_alloc[1].dci_length = sizeof_DCI0_5MHz_TDD_0_t; dci_alloc[1].L = 3; dci_alloc[1].rnti = 0x1234; // DLSCH if (1) { input_buffer_length = PHY_vars_eNb->dlsch_eNb[0]->harq_processes[0]->TBS/8; printf("dlsch0: TBS %d\n",PHY_vars_eNb->dlsch_eNb[0]->harq_processes[0]->TBS); printf("Input buffer size %d bytes\n",input_buffer_length); input_buffer = (unsigned char *)malloc(input_buffer_length+4); for (i=0;i<input_buffer_length;i++) input_buffer[i]= (unsigned char)(taus()&0xff); dlsch_encoding(input_buffer, lte_frame_parms, PHY_vars_eNb->dlsch_eNb[0]); #ifdef OUTPUT_DEBUG for (s=0;s<PHY_vars_eNb->dlsch_eNb[0]->harq_processes[0]->C;s++) { if (s<PHY_vars_eNb->dlsch_eNb[0]->harq_processes[0]->Cminus) Kr = PHY_vars_eNb->dlsch_eNb[0]->harq_processes[0]->Kminus; else Kr = PHY_vars_eNb->dlsch_eNb[0]->harq_processes[0]->Kplus; Kr_bytes = Kr>>3; for (i=0;i<Kr_bytes;i++) printf("%d : (%x)\n",i,PHY_vars_eNb->dlsch_eNb[0]->harq_processes[0]->c[s][i]); } #endif re_allocated = dlsch_modulation(PHY_vars_eNb->lte_eNB_common_vars.txdataF[eNb_id], 1024, 0, &PHY_vars_eNb->lte_frame_parms, PHY_vars_eNb->dlsch_eNb[0]); printf("RB count %d (%d,%d)\n",re_allocated,re_allocated/lte_frame_parms->num_dlsch_symbols/12,lte_frame_parms->num_dlsch_symbols); if (num_layers>1) re_allocated = dlsch_modulation(PHY_vars_eNb->lte_eNB_common_vars.txdataF[eNb_id], 1024, 0, &PHY_vars_eNb->lte_frame_parms, PHY_vars_eNb->dlsch_eNb[1]); }