void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,u16 Nid_cell,u8 N_RB_DL,u8 osf) { LTE_DL_FRAME_PARMS *lte_frame_parms; printf("Start lte_param_init\n"); PHY_vars_eNB = (PHY_VARS_eNB *)malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE = (PHY_VARS_UE *)malloc(sizeof(PHY_VARS_UE)); //PHY_config = malloc(sizeof(PHY_CONFIG)); // mac_xface = malloc(sizeof(MAC_xface)); randominit(0); set_taus_seed(0); lte_frame_parms = &(PHY_vars_eNB->lte_frame_parms); lte_frame_parms->N_RB_DL = N_RB_DL; //50 for 10MHz and 25 for 5 MHz lte_frame_parms->N_RB_UL = N_RB_DL; lte_frame_parms->Ncp = extended_prefix_flag; lte_frame_parms->Nid_cell = Nid_cell; lte_frame_parms->nushift = 0; lte_frame_parms->nb_antennas_tx = N_tx; lte_frame_parms->nb_antennas_rx = N_rx; // lte_frame_parms->Csrs = 2; // lte_frame_parms->Bsrs = 0; // lte_frame_parms->kTC = 0; // lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = (transmission_mode == 1)? 1 : 0; lte_frame_parms->tdd_config = 1; lte_frame_parms->frame_type = 1; init_frame_parms(lte_frame_parms,osf); //copy_lte_parms_to_phy_framing(lte_frame_parms, &(PHY_config->PHY_framing)); phy_init_top(lte_frame_parms); //allocation lte_frame_parms->twiddle_fft = twiddle_fft; lte_frame_parms->twiddle_ifft = twiddle_ifft; lte_frame_parms->rev = rev; PHY_vars_UE->lte_frame_parms = *lte_frame_parms; phy_init_lte_top(lte_frame_parms); phy_init_lte_ue(PHY_vars_UE,0); phy_init_lte_eNB(PHY_vars_eNB,0,0,0); printf("Done lte_param_init\n"); }
void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,uint16_t Nid_cell,uint8_t tdd_config) { unsigned int ind; LTE_DL_FRAME_PARMS *lte_frame_parms; printf("Start lte_param_init (Nid_cell %d, extended_prefix %d, transmission_mode %d, N_tx %d, N_rx %d)\n", Nid_cell, extended_prefix_flag,transmission_mode,N_tx,N_rx); PHY_vars_eNB = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE = malloc(sizeof(PHY_VARS_UE)); mac_xface = malloc(sizeof(MAC_xface)); randominit(0); set_taus_seed(0); lte_frame_parms = &(PHY_vars_eNB->lte_frame_parms); lte_frame_parms->N_RB_DL = 25; //50 for 10MHz and 25 for 5 MHz lte_frame_parms->N_RB_UL = 25; lte_frame_parms->Ncp = extended_prefix_flag; lte_frame_parms->Nid_cell = Nid_cell; lte_frame_parms->nushift = 0; lte_frame_parms->nb_antennas_tx = N_tx; lte_frame_parms->nb_antennas_rx = N_rx; lte_frame_parms->tdd_config = tdd_config; // lte_frame_parms->Csrs = 2; // lte_frame_parms->Bsrs = 0; // lte_frame_parms->kTC = 0; // lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = (transmission_mode == 1)? 1 : 0; init_frame_parms(lte_frame_parms,1); //copy_lte_parms_to_phy_framing(lte_frame_parms, &(PHY_config->PHY_framing)); phy_init_top(lte_frame_parms); //allocation lte_frame_parms->twiddle_fft = twiddle_fft; lte_frame_parms->twiddle_ifft = twiddle_ifft; lte_frame_parms->rev = rev; memcpy(&PHY_vars_UE->lte_frame_parms,lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); phy_init_lte_top(lte_frame_parms); phy_init_lte_ue(PHY_vars_UE,1,0); phy_init_lte_eNB(PHY_vars_eNB,0,0,0); printf("Done lte_param_init\n"); }
void main(int argc,char **argv) { unsigned int *gauss_LUT_ptr,i; unsigned int hist[(1<<Nhistbits)]; int gvar,maxg=0,ming=9999999,maxnum=0,L,Ntrials,Nbits; double meang=0.0,varg=0.0; if (argc < 4) { printf("Not enough arguments: %s Nbits L Ntrials\n",argv[0]); exit(-1); } Nbits = atoi(argv[1]); L = atoi(argv[2]); Ntrials = atoi(argv[3]); set_taus_seed(); // Generate Gaussian LUT 12-bit quantization over 5 standard deviations gauss_LUT_ptr = generate_gauss_LUT(Nbits,L); for (i=0; i<(1<<Nhistbits); i++) hist[i] = 0; for (i=0; i<Ntrials; i++) { gvar = gauss(gauss_LUT_ptr,Nbits); if (gvar == ((1<<(Nbits-1))-1)) maxnum++; maxg = gvar > maxg ? gvar : maxg; ming = gvar < ming ? gvar : ming; meang += (double)gvar/Ntrials; varg += (double)gvar*gvar/Ntrials; gvar += (1<<(Nbits-1))-1; hist[(gvar/(1<<(Nbits-Nhistbits)))]++; // printf("%d\n",gauss(gauss_LUT_ptr,Nbits)); } printf("Tail probability = %e(%x)\n",2*erfc((double)L*gauss_LUT_ptr[(1<<(Nbits-1))-1]/(unsigned int)(1<<31)),gauss_LUT_ptr[(1<<(Nbits-1))-1]); printf("max %d, min %d, mean %f, stddev %f, Pr(maxnum)=%e(%d)\n",maxg,ming,meang,sqrt(varg),(double)maxnum/Ntrials,maxnum); // for (i=0;i<(1<<Nhistbits);i++) // printf("%d : %u\n",i,hist[i]); free(gauss_LUT_ptr); }
void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,uint8_t extended_prefix_flag,uint8_t N_RB_DL,uint8_t frame_type,uint8_t tdd_config,uint8_t osf, int num_bss) { LTE_DL_FRAME_PARMS *lte_frame_parms[num_bss]; PHY_vars_eNB = malloc(num_bss*sizeof(PHY_VARS_eNB*)); PHY_vars_UE = malloc(num_bss*sizeof(PHY_VARS_UE*)); var = malloc(num_bss*sizeof(uint8_t)); randominit(0); set_taus_seed(0); mac_xface = malloc(sizeof(MAC_xface)); int i = 0; for (i = 0; i < num_bss; i++){ PHY_vars_eNB[i] = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE[i] = malloc(sizeof(PHY_VARS_UE)); lte_frame_parms[i] = &(PHY_vars_eNB[i]->lte_frame_parms); lte_frame_parms[i]->frame_type = frame_type; lte_frame_parms[i]->tdd_config = tdd_config; lte_frame_parms[i]->N_RB_DL = N_RB_DL; //50 for 10MHz and 25 for 5 MHz lte_frame_parms[i]->N_RB_UL = N_RB_DL; lte_frame_parms[i]->Ncp = extended_prefix_flag; lte_frame_parms[i]->Ncp_UL = extended_prefix_flag; lte_frame_parms[i]->Nid_cell = 10; lte_frame_parms[i]->nushift = 0; lte_frame_parms[i]->nb_antennas_tx = N_tx; lte_frame_parms[i]->nb_antennas_rx = N_rx; lte_frame_parms[i]->mode1_flag = (transmission_mode == 1)? 1 : 0; lte_frame_parms[i]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 0;//n_DMRS1 set to 0 init_frame_parms(lte_frame_parms[i],osf); PHY_vars_UE[i]->lte_frame_parms = *lte_frame_parms[i]; phy_init_lte_top(lte_frame_parms[i]); phy_init_lte_ue(PHY_vars_UE[i],1,0); phy_init_lte_eNB(PHY_vars_eNB[i],0,0,0); } }
int main(int argc, char* argv[]) { // Fill input vector with complex sinusoid int nb_antennas = 1; int length = 100000; int i,j,n; double input_amp = pow(10.0,(.05*INPUT_dBm))/sqrt(2); double nf[2] = {3.0,3.0}; double ip =0.0; double path_loss_dB = -90, rx_gain_dB = 125; double tx_pwr, rx_pwr; uint32_t **input = malloc(nb_antennas*sizeof(uint32_t*)); uint32_t **output = malloc(nb_antennas*sizeof(uint32_t*)); double **s_re = malloc(nb_antennas*sizeof (double *)); double **s_im = malloc(nb_antennas*sizeof (double *)); double **r_re = malloc(nb_antennas*sizeof (double *)); double **r_im = malloc(nb_antennas*sizeof (double *)); channel_desc_t *channel; srand(0); randominit(0); set_taus_seed(0); channel = new_channel_desc_scm(nb_antennas, nb_antennas, AWGN, 7.68e6, 0, 0, path_loss_dB); for (i=0; i<nb_antennas; i++) { s_re[i] = (double *)malloc(length * sizeof (double )); s_im[i] = (double *)malloc(length * sizeof (double )); r_re[i] = (double *)malloc(length * sizeof (double )); r_im[i] = (double *)malloc(length * sizeof (double )); input[i] = (uint32_t*)malloc(length * sizeof(uint32_t)); output[i] = (uint32_t*)malloc(length * sizeof(uint32_t)); } for (i=0; i<nb_antennas; i++) { // generate a random QPSK signal for (j=0; j<length/2; j++) { input[i][j] = QPSK[taus()&3]; } } tx_pwr = dac_fixed_gain(s_re, s_im, input, 0, nb_antennas, length, 0, 512, 14, 15.0); multipath_channel(channel,s_re,s_im,r_re,r_im, length,0); rf_rx_simple(r_re, r_im, nb_antennas, length, 1.0/7.68e6 * 1e9,// sampling time (ns) rx_gain_dB - 66.227); /* rf_rx(r_re, r_im, nb_antennas, length, 1.0/6.5e6 * 1e9,// sampling time (ns) 1000.0 , //freq offset (Hz) 0.0, //drift (Hz) NOT YET IMPLEMENTED nf, //noise_figure NOT YET IMPLEMENTED -INPUT_dBm, //rx_gain (dB) 200, // IP3_dBm (dBm) &ip, // initial phase 30.0e3, // pn_cutoff (kHz) -500.0, // pn_amp (dBc) -0.0, // IQ imbalance (dB), 0.0); // IQ phase imbalance (rad) */ adc(r_re, r_im, 0, 0, output, nb_antennas, length, 12); write_output("s_im.m","s_im",s_im[0],length,1,7); write_output("s_re.m","s_re",s_re[0],length,1,7); write_output("r_im.m","r_im",r_im[0],length,1,7); write_output("r_re.m","r_re",r_re[0],length,1,7); write_output("input.m","rfin",input[0],length,1,1); write_output("output.m","rfout",output[0],length,1,1); }
int main(int argc, char **argv) { char c; int i,aa,aarx; double sigma2, sigma2_dB=0,SNR,snr0=10.0,snr1=10.2; int snr1set=0; uint32_t *txdata,*rxdata[2]; double *s_re[2],*s_im[2],*r_re[2],*r_im[2]; double iqim=0.0; int trial, ntrials=1; int n_rx=1; int awgn_flag=0; int n_frames=1; channel_desc_t *ch; uint32_t tx_lev,tx_lev_dB; int interf1=-19,interf2=-19; SCM_t channel_model=AWGN; uint32_t sdu_length_samples; TX_VECTOR_t tx_vector; int errors=0,misdetected_errors=0,signal_errors=0; int symbols=0; int tx_offset = 0,rx_offset; RX_VECTOR_t *rxv; uint8_t *data_ind,*data_ind_rx; int no_detection=1; int missed_packets=0; uint8_t rxp; int off,off2; double txg,txg_dB; int log2_maxh; double snr_array[100]; int errors_array[100]; int trials_array[100]; int misdetected_errors_array[100]; int signal_errors_array[100]; int missed_packets_array[100]; int cnt=0; char fname[100],vname[100]; int stop=0; data_ind = (uint8_t*)malloc(4095+2+1); data_ind_rx = (uint8_t*)malloc(4095+2+1); tx_vector.rate=1; tx_vector.sdu_length=256; tx_vector.service=0; logInit(); randominit(0); set_taus_seed(0); // Basic initializations init_fft(64,6,rev64); init_interleavers(); ccodedot11_init(); ccodedot11_init_inv(); phy_generate_viterbi_tables(); init_crc32(); data_ind[0] = 0; data_ind[1] = 0; tx_offset = taus()%(FRAME_LENGTH_SAMPLES_MAX/2); while ((c = getopt (argc, argv, "hag:n:s:S:z:r:p:d:")) != -1) { switch (c) { case 'a': printf("Running AWGN simulation\n"); awgn_flag = 1; ntrials=1; break; case 'g': switch((char)*optarg) { case 'A': channel_model=SCM_A; break; case 'B': channel_model=SCM_B; break; case 'C': channel_model=SCM_C; break; case 'D': channel_model=SCM_D; break; case 'E': channel_model=EPA; break; case 'F': channel_model=EVA; break; case 'G': channel_model=ETU; break; case 'H': channel_model=Rayleigh8; case 'I': channel_model=Rayleigh1; case 'J': channel_model=Rayleigh1_corr; case 'K': channel_model=Rayleigh1_anticorr; case 'L': channel_model=Rice8; case 'M': channel_model=Rice1; break; default: printf("Unsupported channel model!\n"); exit(-1); } break; case 'd': tx_offset = atoi(optarg); break; case 'p': tx_vector.sdu_length = atoi(optarg); if (atoi(optarg)>4095) { printf("Illegal sdu_length %d\n",tx_vector.sdu_length); exit(-1); } break; case 'r': tx_vector.rate = atoi(optarg); if (atoi(optarg)>7) { printf("Illegal rate %d\n",tx_vector.rate); exit(-1); } break; case 'n': n_frames = atoi(optarg); break; case 's': snr0 = atof(optarg); printf("Setting SNR0 to %f\n",snr0); break; case 'S': snr1 = atof(optarg); snr1set=1; printf("Setting SNR1 to %f\n",snr1); break; case 'z': n_rx=atoi(optarg); if ((n_rx==0) || (n_rx>2)) { printf("Unsupported number of rx antennas %d\n",n_rx); exit(-1); } break; default: case 'h': printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -r Ricean_FactordB -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",argv[0]); printf("-h This message\n"); printf("-a Use AWGN channel and not multipath\n"); printf("-n Number of frames to simulate\n"); printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); printf("-S Ending SNR, runs from SNR0 to SNR1\n"); printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); printf("-z Number of RX antennas used\n"); printf("-F Input filename (.txt format) for RX conformance testing\n"); exit (-1); break; } } if (n_frames==1) snr1 = snr0+.2; else snr1 = snr0+5; for (i=0; i<tx_vector.sdu_length; i++) data_ind[i+2] = i;//taus(); // randomize packet data_ind[tx_vector.sdu_length+2+4]=0; // Tail byte // compute number of OFDM symbols in DATA period symbols = ((4+2+1+tx_vector.sdu_length)<<1) / nibbles_per_symbol[tx_vector.rate]; if ((((4+2+1+tx_vector.sdu_length)<<1) % nibbles_per_symbol[tx_vector.rate]) > 0) symbols++; sdu_length_samples = (symbols + 5) * 80; printf("Number of symbols for sdu : %d, samples %d\n",symbols,sdu_length_samples); txdata = (uint32_t*)memalign(16,sdu_length_samples*sizeof(uint32_t)); for (i=0; i<n_rx; i++) { rxdata[i] = (uint32_t*)memalign(16,(FRAME_LENGTH_SAMPLES_MAX+1280)*sizeof(uint32_t)); bzero(rxdata[i],(FRAME_LENGTH_SAMPLES_MAX+1280)*sizeof(uint32_t)); } s_re[0] = (double *)malloc(sdu_length_samples*sizeof(double)); bzero(s_re[0],sdu_length_samples*sizeof(double)); s_im[0] = (double *)malloc(sdu_length_samples*sizeof(double)); bzero(s_im[0],sdu_length_samples*sizeof(double)); for (i=0; i<n_rx; i++) { r_re[i] = (double *)malloc((sdu_length_samples+100)*sizeof(double)); bzero(r_re[i],(sdu_length_samples+100)*sizeof(double)); r_im[i] = (double *)malloc((sdu_length_samples+100)*sizeof(double)); bzero(r_im[i],(sdu_length_samples+100)*sizeof(double)); } ch = new_channel_desc_scm(1, n_rx, channel_model, BW, 0.0, 0, 0); if (ch==NULL) { printf("Problem generating channel model. Exiting.\n"); exit(-1); } phy_tx_start(&tx_vector,txdata,0,FRAME_LENGTH_SAMPLES_MAX,data_ind); tx_lev = signal_energy((int32_t*)txdata,320); tx_lev_dB = (unsigned int) dB_fixed(tx_lev); write_output("txsig0.m","txs", txdata,sdu_length_samples,1,1); // multipath channel for (i=0; i<sdu_length_samples; i++) { s_re[0][i] = (double)(((short *)txdata)[(i<<1)]); s_im[0][i] = (double)(((short *)txdata)[(i<<1)+1]); } for (SNR=snr0; SNR<snr1; SNR+=.2) { printf("n_frames %d SNR %f sdu_length %d rate %d\n",n_frames,SNR,tx_vector.sdu_length,tx_vector.rate); errors=0; misdetected_errors=0; signal_errors=0; missed_packets=0; stop=0; for (trial=0; trial<n_frames; trial++) { // printf("Trial %d (errors %d), sdu_length_samples %d\n",trial,errors,sdu_length_samples); sigma2_dB = 25; //10*log10((double)tx_lev) - SNR; txg_dB = 10*log10((double)tx_lev) - (SNR + sigma2_dB); txg = pow(10.0,-.05*txg_dB); if (n_frames==1) printf("sigma2_dB %f (SNR %f dB) tx_lev_dB %f, txg %f\n",sigma2_dB,SNR,10*log10((double)tx_lev)-txg_dB,txg_dB); //AWGN sigma2 = pow(10,sigma2_dB/10); // printf("Sigma2 %f (sigma2_dB %f)\n",sigma2,sigma2_dB); // sigma2 = 0; multipath_channel(ch,s_re,s_im,r_re,r_im, sdu_length_samples,0); if (n_frames==1) { printf("rx_level data symbol %f, tx_lev %f\n", 10*log10(signal_energy_fp(r_re,r_im,1,80,0)), 10*log10(tx_lev)); } for (aa=0; aa<n_rx; aa++) { for (i=0; i<(sdu_length_samples+100); i++) { ((short*)&rxdata[aa][tx_offset])[(i<<1)] = (short) (((txg*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); ((short*)&rxdata[aa][tx_offset])[1+(i<<1)] = (short) (((txg*r_im[aa][i]) + (iqim*r_re[aa][i]*txg) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); // if (i<128) // printf("i%d : rxdata %d, txdata %d\n",i,((short *)rxdata[aa])[rx_offset+(i<<1)],((short *)txdata)[i<<1]); } for (i=0; i<tx_offset; i++) { ((short*) rxdata[aa])[(i<<1)] = (short) (sqrt(sigma2/2)*gaussdouble(0.0,1.0)); ((short*) rxdata[aa])[1+(i<<1)] = (short) (sqrt(sigma2/2)*gaussdouble(0.0,1.0)); } for (i=(tx_offset+sdu_length_samples+100); i<FRAME_LENGTH_SAMPLES_MAX; i++) { ((short*) rxdata[aa])[(i<<1)] = (short) (sqrt(sigma2/2)*gaussdouble(0.0,1.0)); ((short*) rxdata[aa])[1+(i<<1)] = (short) (sqrt(sigma2/2)*gaussdouble(0.0,1.0)); } } if (n_frames==1) { write_output("rxsig0.m","rxs", &rxdata[0][0],FRAME_LENGTH_SAMPLES_MAX,1,1); } no_detection=1; off = 0; while(off<FRAME_LENGTH_SAMPLES_MAX) { rxp = dB_fixed(signal_energy(rxdata[0]+off,512)); if (n_frames==1) printf("off %d: rxp %d (%d)\n",off,rxp,signal_energy(rxdata[0]+off,104)); if (rxp>RX_THRES_dB) { if (off<105) off2 = FRAME_LENGTH_SAMPLES_MAX-105; else off2=off; if ((initial_sync(&rxv,&rx_offset,&log2_maxh,(uint32_t*)rxdata[0],FRAME_LENGTH_SAMPLES_MAX,off2,1) == BUSY)) { if (n_frames==1) printf("Channel is busy, rxv %p, offset %d\n",(void*)rxv,rx_offset); no_detection=0; if (rxv) { if (n_frames==1) printf("Rate %d, SDU_LENGTH %d\n",rxv->rate,rxv->sdu_length); if ( (rxv->rate != tx_vector.rate)||(rxv->sdu_length != tx_vector.sdu_length)) { signal_errors++; if ((signal_errors > (n_frames/10)) && (trial>=100)) { stop=1; } if (n_frames == 1) printf("SIGNAL error: rx_offset %d, tx_offset %d (off2 %d)\n",rx_offset,tx_offset,off2); break; } else { memset(data_ind_rx,0,rxv->sdu_length+4+2+1); if (data_detection(rxv,data_ind_rx,(uint32_t*)rxdata[0],FRAME_LENGTH_SAMPLES_MAX,rx_offset,log2_maxh,NULL)) { for (i=0; i<rxv->sdu_length+6; i++) { if (data_ind[i]!=data_ind_rx[i]) { //printf("error position %d : %x,%x\n",i,data_ind[i],data_ind_rx[i]); misdetected_errors++; errors++; } } if ((errors > (n_frames/10)) && (trial>100)) { stop=1; break; } } // initial_synch returns IDLE else { errors++; if (n_frames == 1) { printf("Running data_detection fails\n"); for (i=0; i<rxv->sdu_length+6; i++) { if (data_ind[i]!=data_ind_rx[i]) { printf("error position %d : %x,%x\n",i,data_ind[i],data_ind_rx[i]); } } } if ((errors > (n_frames/10)) && (trial>=100)) { stop=1; break; } } break; } } } } off+=105; } if (no_detection==1) missed_packets++; if (stop==1) break; } printf("\nSNR %f dB: errors %d/%d, misdetected errors %d/%d,signal_errors %d/%d, missed_packets %d/%d\n",SNR,errors,trial-signal_errors,misdetected_errors,trial-signal_errors,signal_errors,trial,missed_packets,trial); snr_array[cnt] = SNR; errors_array[cnt] = errors; trials_array[cnt] = trial; misdetected_errors_array[cnt] = misdetected_errors; signal_errors_array[cnt] = signal_errors; missed_packets_array[cnt] = missed_packets; cnt++; if (cnt>99) { printf("too many SNR points, exiting ...\n"); break; } if (errors == 0) break; #ifdef EXECTIME print_is_stats(); print_dd_stats(); #endif } sprintf(fname,"SNR_%d_%d.m",tx_vector.rate,tx_vector.sdu_length); sprintf(vname,"SNR_%d_%d_v",tx_vector.rate,tx_vector.sdu_length); write_output(fname,vname,snr_array,cnt,1,7); sprintf(fname,"errors_%d_%d.m",tx_vector.rate,tx_vector.sdu_length); sprintf(vname,"errors_%d_%d_v",tx_vector.rate,tx_vector.sdu_length); write_output(fname,vname,errors_array,cnt,1,2); sprintf(fname,"trials_%d_%d.m",tx_vector.rate,tx_vector.sdu_length); sprintf(vname,"trials_%d_%d_v",tx_vector.rate,tx_vector.sdu_length); write_output(fname,vname,trials_array,cnt,1,2); sprintf(fname,"signal_errors_%d_%d.m",tx_vector.rate,tx_vector.sdu_length); sprintf(vname,"signal_errors_%d_%d_v",tx_vector.rate,tx_vector.sdu_length); write_output(fname,vname,signal_errors_array,cnt,1,2); free(data_ind); free(data_ind_rx); // free_channel_desc_scm(ch); free(txdata); for (i=0; i<n_rx; i++) { free(rxdata[i]); } free(s_re[0]); free(s_im[0]); for (i=0; i<n_rx; i++) { free(r_re[i]); free(r_im[i]); } return(0); }
int main (int argc, char **argv) { Interface_init(); s_t* st2=(s_t*)(Instance[1].gm->mem_ref.pointer); st2->port=38800; char c; s32 i, j; int new_omg_model; // goto ocg in oai_emulation.info. // pointers signal buffers (s = transmit, r,r0 = receive) double **s_re[NINST], **s_im[NINST], **r_re[NINST], **r_im[NINST], **r_re0, **r_im0; double **r_re0_d[8][3], **r_im0_d[8][3], **r_re0_u[3][8],**r_im0_u[3][8]; // double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0; double forgetting_factor=0; int map1,map2; double **ShaF= NULL; // Framing variables s32 slot, last_slot, next_slot; // variables/flags which are set by user on command-line double snr_dB, sinr_dB; u8 set_snr=0,set_sinr=0; u8 cooperation_flag; // for cooperative communication u8 target_dl_mcs = 4; u8 target_ul_mcs = 2; u8 rate_adaptation_flag; u8 abstraction_flag = 0, ethernet_flag = 0; u16 Nid_cell = 0; s32 UE_id, eNB_id, ret; // time calibration for soft realtime mode struct timespec time_spec; unsigned long time_last, time_now; int td, td_avg, sleep_time_us; char *g_log_level = "trace"; // by default global log level is set to trace lte_subframe_t direction; #ifdef XFORMS FD_phy_procedures_sim *form[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX]; char title[255]; #endif LTE_DL_FRAME_PARMS *frame_parms; FILE *UE_stats[NUMBER_OF_UE_MAX], *eNB_stats; char UE_stats_filename[255]; int len; #ifdef ICIC remove ("dci.txt"); #endif //time_t t0,t1; clock_t start, stop; // Added for PHY abstraction Node_list ue_node_list = NULL; Node_list enb_node_list = NULL; //default parameters target_dl_mcs = 0; rate_adaptation_flag = 0; oai_emulation.info.n_frames = 0xffff;//1024; //100; oai_emulation.info.n_frames_flag = 0;//fixme snr_dB = 30; cooperation_flag = 0; // default value 0 for no cooperation, 1 for Delay diversity, 2 for Distributed Alamouti init_oai_emulation(); // to initialize everything !!! // get command-line options while ((c = getopt (argc, argv, "haePToFt:C:N:k:x:m:rn:s:S:f:z:u:b:c:M:p:g:l:d:U:B:R:E:")) != -1) { switch (c) { case 'F': // set FDD oai_emulation.info.frame_type = 0; break; case 'C': oai_emulation.info.tdd_config = atoi (optarg); if (oai_emulation.info.tdd_config > 6) { msg ("Illegal tdd_config %d (should be 0-6)\n", oai_emulation.info.tdd_config); exit (-1); } break; case 'R': oai_emulation.info.N_RB_DL = atoi (optarg); if ((oai_emulation.info.N_RB_DL != 6) && (oai_emulation.info.N_RB_DL != 15) && (oai_emulation.info.N_RB_DL != 25) && (oai_emulation.info.N_RB_DL != 50) && (oai_emulation.info.N_RB_DL != 75) && (oai_emulation.info.N_RB_DL != 100)) { msg ("Illegal N_RB_DL %d (should be one of 6,15,25,50,75,100)\n", oai_emulation.info.N_RB_DL); exit (-1); } case 'N': Nid_cell = atoi (optarg); if (Nid_cell > 503) { msg ("Illegal Nid_cell %d (should be 0 ... 503)\n", Nid_cell); exit(-1); } break; case 'h': help (); exit (1); case 'x': oai_emulation.info.transmission_mode = atoi (optarg); if ((oai_emulation.info.transmission_mode != 1) && (oai_emulation.info.transmission_mode != 2) && (oai_emulation.info.transmission_mode != 5) && (oai_emulation.info.transmission_mode != 6)) { msg("Unsupported transmission mode %d\n",oai_emulation.info.transmission_mode); exit(-1); } break; case 'm': target_dl_mcs = atoi (optarg); break; case 'r': rate_adaptation_flag = 1; break; case 'n': oai_emulation.info.n_frames = atoi (optarg); //n_frames = (n_frames >1024) ? 1024: n_frames; // adjust the n_frames if higher that 1024 oai_emulation.info.n_frames_flag = 1; break; case 's': snr_dB = atoi (optarg); set_snr = 1; oai_emulation.info.ocm_enabled=0; break; case 'S': sinr_dB = atoi (optarg); set_sinr = 1; oai_emulation.info.ocm_enabled=0; break; case 'k': //ricean_factor = atof (optarg); printf("[SIM] Option k is no longer supported on the command line. Please specify your channel model in the xml template\n"); exit(-1); break; case 't': //Td = atof (optarg); printf("[SIM] Option t is no longer supported on the command line. Please specify your channel model in the xml template\n"); exit(-1); break; case 'f': forgetting_factor = atof (optarg); break; case 'z': cooperation_flag = atoi (optarg); break; case 'u': oai_emulation.info.nb_ue_local = atoi (optarg); break; case 'b': oai_emulation.info.nb_enb_local = atoi (optarg); break; case 'a': abstraction_flag = 1; break; case 'p': oai_emulation.info.nb_master = atoi (optarg); break; case 'M': abstraction_flag = 1; ethernet_flag = 1; oai_emulation.info.ethernet_id = atoi (optarg); oai_emulation.info.master_id = oai_emulation.info.ethernet_id; oai_emulation.info.ethernet_flag = 1; break; case 'e': oai_emulation.info.extended_prefix_flag = 1; break; case 'l': g_log_level = optarg; break; case 'c': strcpy(oai_emulation.info.local_server, optarg); oai_emulation.info.ocg_enabled=1; break; case 'g': oai_emulation.info.multicast_group = atoi (optarg); break; case 'B': oai_emulation.info.omg_model_enb = atoi (optarg); break; case 'U': oai_emulation.info.omg_model_ue = atoi (optarg); break; case 'T': oai_emulation.info.otg_enabled = 1; break; case 'P': oai_emulation.info.opt_enabled = 1; break; case 'E': oai_emulation.info.seed = atoi (optarg); break; default: help (); exit (-1); break; } } // configure oaisim with OCG oaisim_config(g_log_level); // config OMG and OCG, OPT, OTG, OLG if (oai_emulation.info.nb_ue_local > NUMBER_OF_UE_MAX ) { printf ("Enter fewer than %d UEs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_UE_MAX); exit (-1); } if (oai_emulation.info.nb_enb_local > NUMBER_OF_eNB_MAX) { printf ("Enter fewer than %d eNBs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_eNB_MAX); exit (-1); } // fix ethernet and abstraction with RRC_CELLULAR Flag #ifdef RRC_CELLULAR abstraction_flag = 1; ethernet_flag = 0; #endif if (set_sinr == 0) sinr_dB = snr_dB - 20; // setup ntedevice interface (netlink socket) #ifndef CYGWIN ret = netlink_init (); #endif if (ethernet_flag == 1) { oai_emulation.info.master[oai_emulation.info.master_id].nb_ue = oai_emulation.info.nb_ue_local; oai_emulation.info.master[oai_emulation.info.master_id].nb_enb = oai_emulation.info.nb_enb_local; if (!oai_emulation.info.master_id) oai_emulation.info.is_primary_master = 1; j = 1; for (i = 0; i < oai_emulation.info.nb_master; i++) { if (i != oai_emulation.info.master_id) oai_emulation.info.master_list = oai_emulation.info.master_list + j; LOG_I (EMU, "Index of master id i=%d MASTER_LIST %d\n", i, oai_emulation.info.master_list); j *= 2; } LOG_I (EMU, " Total number of master %d my master id %d\n", oai_emulation.info.nb_master, oai_emulation.info.master_id); #ifdef LINUX init_bypass (); #endif while (emu_tx_status != SYNCED_TRANSPORT) { LOG_I (EMU, " Waiting for EMU Transport to be synced\n"); emu_transport_sync (); //emulation_tx_rx(); } } // ethernet flag NB_UE_INST = oai_emulation.info.nb_ue_local + oai_emulation.info.nb_ue_remote; NB_eNB_INST = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_enb_remote; #ifndef NAS_NETLINK for (UE_id=0;UE_id<NB_UE_INST;UE_id++) { sprintf(UE_stats_filename,"UE_stats%d.txt",UE_id); UE_stats[UE_id] = fopen (UE_stats_filename, "w"); } eNB_stats = fopen ("eNB_stats.txt", "w"); printf ("UE_stats=%p, eNB_stats=%p\n", UE_stats, eNB_stats); #endif LOG_I(EMU, "total number of UE %d (local %d, remote %d) \n", NB_UE_INST,oai_emulation.info.nb_ue_local,oai_emulation.info.nb_ue_remote); LOG_I(EMU, "Total number of eNB %d (local %d, remote %d) \n", NB_eNB_INST,oai_emulation.info.nb_enb_local,oai_emulation.info.nb_enb_remote); printf("Running with frame_type %d, Nid_cell %d, N_RB_DL %d, EP %d, mode %d, target dl_mcs %d, rate adaptation %d, nframes %d, abstraction %d\n", 1+oai_emulation.info.frame_type, Nid_cell, oai_emulation.info.N_RB_DL, oai_emulation.info.extended_prefix_flag, oai_emulation.info.transmission_mode,target_dl_mcs,rate_adaptation_flag,oai_emulation.info.n_frames,abstraction_flag); // init_lte_vars (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag); init_frame_params (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag); printf ("Nid_cell %d\n", frame_parms->Nid_cell); /* Added for PHY abstraction */ if (abstraction_flag) get_beta_map(); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { enb_data[eNB_id] = (node_desc_t *)malloc(sizeof(node_desc_t)); init_enb(enb_data[eNB_id],oai_emulation.environment_system_config.antenna.eNB_antenna); } for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { ue_data[UE_id] = (node_desc_t *)malloc(sizeof(node_desc_t)); init_ue(ue_data[UE_id],oai_emulation.environment_system_config.antenna.UE_antenna); } // init SF map here!!! map1 =(int)oai_emulation.topology_config.area.x_km; map2 =(int)oai_emulation.topology_config.area.y_km; //ShaF = createMat(map1,map2); -> memory is allocated within init_SF ShaF = init_SF(map1,map2,DECOR_DIST,SF_VAR); // size of area to generate shadow fading map printf("Simulation area x=%f, y=%f\n", oai_emulation.topology_config.area.x_km, oai_emulation.topology_config.area.y_km); if (abstraction_flag == 0){ int ci; int ji=0; for(ci=0;ci<NB_eNB_INST;ci++) { init_channel_mmap_channel(10+ji,frame_parms, &(s_re[ci]), &(s_im[ci]), &(r_re[ci]), &(r_im[ci]), &(r_re0), &(r_im0)); ji++; //printf("ci %d\n",ci); } ji=0; for(ci=NB_eNB_INST;ci<(NB_eNB_INST+NB_UE_INST);ci++) { init_channel_mmap_channel(20+ji,frame_parms, &(s_re[ci]), &(s_im[ci]), &(r_re[ci]), &(r_im[ci]), &(r_re0), &(r_im0)); ji++; //printf("ci %d\n",ci); } } for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { init_rre(frame_parms,&(r_re0_u[eNB_id][UE_id]),&(r_im0_u[eNB_id][UE_id])); init_rre(frame_parms,&(r_re0_d[UE_id][eNB_id]),&(r_im0_d[UE_id][eNB_id])); } } // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); // // r_im0_u[0][0][0][0]=100; // // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); // // // clean_param((r_re0_u[0][0]),(r_im0_u[0][0]),frame_parms); // // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { #ifdef DEBUG_SIM printf ("[SIM] Initializing channel from eNB %d to UE %d\n", eNB_id, UE_id); #endif eNB2UE[eNB_id][UE_id] = new_channel_desc_scm(2, 2, map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option), oai_emulation.environment_system_config.system_bandwidth_MB, forgetting_factor, 0, 0); UE2eNB[UE_id][eNB_id] = new_channel_desc_scm(2, 2, map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option), oai_emulation.environment_system_config.system_bandwidth_MB, forgetting_factor, 0, 0); } } randominit (0); set_taus_seed (0); number_of_cards = 1; openair_daq_vars.rx_rf_mode = 1; openair_daq_vars.tdd = 1; openair_daq_vars.rx_gain_mode = DAQ_AGC_ON; openair_daq_vars.dlsch_transmission_mode = oai_emulation.info.transmission_mode; openair_daq_vars.target_ue_dl_mcs = target_dl_mcs; openair_daq_vars.target_ue_ul_mcs = target_ul_mcs; openair_daq_vars.dlsch_rate_adaptation = rate_adaptation_flag; openair_daq_vars.ue_ul_nb_rb = 2; #ifdef XFORMS fl_initialize (&argc, argv, NULL, 0, 0); for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { form[eNB_id][UE_id] = create_form_phy_procedures_sim (); sprintf (title, "LTE SIM UE %d eNB %d", UE_id, eNB_id); fl_show_form (form[eNB_id][UE_id]->phy_procedures_sim, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); } #endif // time calibration for OAI clock_gettime (CLOCK_REALTIME, &time_spec); time_now = (unsigned long) time_spec.tv_nsec; td_avg = 0; sleep_time_us = SLEEP_STEP_US; td_avg = TARGET_SF_TIME_NS; // s_t* st2=(s_t*)(Instance[1].gm->mem_ref.pointer); st2->Exec_FLAG=0; int count; IntInitAll(); Soc_t* this = (Soc_t*)(obj_inst[0].ptr->mem_ref.pointer); fd_set read_ibits; fd_set write_ibits; int n; struct timeval tvp ; tvp.tv_sec=10; tvp.tv_usec=0; FD_ZERO(&read_ibits); FD_SET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); ch_thread *e2u_t[NB_eNB_INST][NB_UE_INST]; ch_thread *u2e_t[NB_UE_INST][NB_eNB_INST]; for(eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++){ for(UE_id=0;UE_id<NB_UE_INST;UE_id++){ e2u_t[eNB_id][UE_id]=(ch_thread*)calloc(1,sizeof(ch_thread)); }} for(UE_id=0;UE_id<NB_UE_INST;UE_id++){ for(eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++){ u2e_t[UE_id][eNB_id]=(ch_thread*)calloc(1,sizeof(ch_thread)); }} pthread_t thread,thread2; pthread_t cthr_u[NB_eNB_INST][NB_UE_INST]; pthread_t cthr_d[NB_UE_INST][NB_eNB_INST]; for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { u2e_t[UE_id][eNB_id]->eNB_id=eNB_id; u2e_t[UE_id][eNB_id]->UE_id=UE_id; u2e_t[UE_id][eNB_id]->r_re0=r_re0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_im0=r_im0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_re=r_re[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->r_im=r_im[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->s_im=s_im[eNB_id]; u2e_t[UE_id][eNB_id]->s_re=s_re[eNB_id]; u2e_t[UE_id][eNB_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; u2e_t[UE_id][eNB_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->enb_data=enb_data[eNB_id]; u2e_t[UE_id][eNB_id]->ue_data=ue_data[UE_id]; u2e_t[UE_id][eNB_id]->next_slot=&next_slot; u2e_t[UE_id][eNB_id]->abstraction_flag=&abstraction_flag; u2e_t[UE_id][eNB_id]->frame_parms=frame_parms; pthread_create (&cthr_d[UE_id][eNB_id], NULL, do_DL_sig_channel_T,(void*)(u2e_t[UE_id][eNB_id])); } } int sock; int port=(35000+(10+eNB_id)+(20+UE_id)); port=35010; sock = openairInetCreateSocket(SOCK_DGRAM,IPPROTO_UDP,"127.0.0.1",port); // int n; // fd_set read_ibits; // fd_set write_ibits; // struct timeval tvp = { 0, 0 }; FD_ZERO(&read_ibits); FD_SET(sock,&read_ibits); n = openairSelect(sock+1, &read_ibits, NULL, NULL, NULL); printf("Waiting is over\n"); FD_ISSET(sock, &read_ibits); for (mac_xface->frame=0; mac_xface->frame<oai_emulation.info.n_frames; mac_xface->frame++) { int dir_flag=0; printf("=============== Frame Number %d ============= \n ",mac_xface->frame); /* // Handling the cooperation Flag if (cooperation_flag == 2) { if ((PHY_vars_eNB_g[0]->eNB_UE_stats[0].mode == PUSCH) && (PHY_vars_eNB_g[0]->eNB_UE_stats[1].mode == PUSCH)) PHY_vars_eNB_g[0]->cooperation_flag = 2; } */ // for dubugging the frame counter update_nodes(oai_emulation.info.time); enb_node_list = get_current_positions(oai_emulation.info.omg_model_enb, eNB, oai_emulation.info.time); ue_node_list = get_current_positions(oai_emulation.info.omg_model_ue, UE, oai_emulation.info.time); // update the position of all the nodes (eNB/CH, and UE/MR) every frame if (((int)oai_emulation.info.time % 10) == 0 ) { display_node_list(enb_node_list); display_node_list(ue_node_list); if (oai_emulation.info.omg_model_ue >= MAX_NUM_MOB_TYPES){ // mix mobility model for(UE_id=oai_emulation.info.first_ue_local; UE_id<(oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local);UE_id++){ new_omg_model = randomGen(STATIC, MAX_NUM_MOB_TYPES); LOG_D(OMG, "[UE] Node of ID %d is changing mobility generator ->%d \n", UE_id, new_omg_model); // reset the mobility model for a specific node set_new_mob_type (UE_id, UE, new_omg_model, oai_emulation.info.time); } } if (oai_emulation.info.omg_model_enb >= MAX_NUM_MOB_TYPES) { // mix mobility model for (eNB_id = oai_emulation.info.first_enb_local; eNB_id < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local); eNB_id++) { new_omg_model = randomGen (STATIC, MAX_NUM_MOB_TYPES); LOG_D (OMG, "[eNB] Node of ID %d is changing mobility generator ->%d \n", UE_id, new_omg_model); // reset the mobility model for a specific node set_new_mob_type (eNB_id, eNB, new_omg_model, oai_emulation.info.time); } } } #ifdef DEBUG_OMG if ((((int) oai_emulation.info.time) % 100) == 0) { for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) { get_node_position (UE, UE_id); } } #endif if (oai_emulation.info.n_frames_flag == 0){ // if n_frames not set by the user then let the emulation run to infinity mac_xface->frame %=(oai_emulation.info.n_frames-1); // set the emulation time based on 1ms subframe number oai_emulation.info.time += 0.01; // emu time in s } else { // user set the number of frames for the emulation // let the time go faster to see the effect of mobility oai_emulation.info.time += 0.1; } /* check if the openair channel model is activated used for PHY abstraction */ /* if ((oai_emulation.info.ocm_enabled == 1)&& (ethernet_flag == 0 )) { extract_position(enb_node_list, enb_data, NB_eNB_INST); extract_position(ue_node_list, ue_data, NB_UE_INST); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { calc_path_loss (enb_data[eNB_id], ue_data[UE_id], eNB2UE[eNB_id][UE_id], oai_emulation.environment_system_config,ShaF[(int)ue_data[UE_id]->x][(int)ue_data[UE_id]->y]); UE2eNB[UE_id][eNB_id]->path_loss_dB = eNB2UE[eNB_id][UE_id]->path_loss_dB; printf("[CHANNEL_SIM] Pathloss bw enB %d at (%f,%f) and UE%d at (%f,%f) is %f (ShaF %f)\n", eNB_id,enb_data[eNB_id]->x,enb_data[eNB_id]->y,UE_id,ue_data[UE_id]->x,ue_data[UE_id]->y, eNB2UE[eNB_id][UE_id]->path_loss_dB, ShaF[(int)ue_data[UE_id]->x][(int)ue_data[UE_id]->y]); } } } */ // else { for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { eNB2UE[eNB_id][UE_id]->path_loss_dB = -105 + snr_dB; //UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + snr_dB; if (eNB_id == (UE_id % NB_eNB_INST)) UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + snr_dB - 10; else UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + sinr_dB - 10; #ifdef DEBUG_SIM printf("[SIM] Path loss from eNB %d to UE %d => %f dB\n",eNB_id,UE_id,eNB2UE[eNB_id][UE_id]->path_loss_dB); printf("[SIM] Path loss from UE %d to eNB %d => %f dB\n",UE_id,eNB_id,UE2eNB[UE_id][eNB_id]->path_loss_dB); #endif } } // } else st2->EResp_FLAG=0; for (slot=0 ; slot<20 ; slot++) { printf("=============== Frame Number %d , Slot %d ============= \n ",mac_xface->frame,slot); last_slot = (slot - 1)%20; if (last_slot <0) last_slot+=20; next_slot = (slot + 1)%20; direction = subframe_select(frame_parms,next_slot>>1); if (direction == SF_DL) { dir_flag=1; } else if (direction == SF_UL) { dir_flag=2; } else {//it must be a special subframe if (next_slot%2==0) {//DL part dir_flag=1; } else {// UL part dir_flag=2; } } int count=0; if(dir_flag==1) { st2->EResp_FLAG=0; count=0; for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38810+eNB_id); printf("Waiting for Exec Msg Complete \n"); // n = openairIoSyncCreateThread_2(&this->m_io_sync); } // for loop while(count<NB_eNB_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { //trigger message send_exec_msg(0,0,0,0,0,0,(35000+(10+eNB_id)+(20+UE_id))); } } usleep(5); // while(st2->EResp_FLAG<NB_eNB_INST) // { /* for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { u2e_t[UE_id][eNB_id]->eNB_id=eNB_id; u2e_t[UE_id][eNB_id]->UE_id=UE_id; u2e_t[UE_id][eNB_id]->r_re0=r_re0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_im0=r_im0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_re=r_re[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->r_im=r_im[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->s_im=s_im[eNB_id]; u2e_t[UE_id][eNB_id]->s_re=s_re[eNB_id]; u2e_t[UE_id][eNB_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; u2e_t[UE_id][eNB_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->enb_data=enb_data[eNB_id]; u2e_t[UE_id][eNB_id]->ue_data=ue_data[UE_id]; u2e_t[UE_id][eNB_id]->next_slot=&next_slot; u2e_t[UE_id][eNB_id]->abstraction_flag=&abstraction_flag; u2e_t[UE_id][eNB_id]->frame_parms=frame_parms; // pthread_create (&thread[eNB_id][UE_id], NULL, do_DL_sig_channel_T,(void*)cthread); pthread_create (&cthr_d[UE_id][eNB_id], NULL, do_DL_sig_channel_T,(void*)(u2e_t[UE_id][eNB_id])); // pthread_join(cthr_d[UE_id][eNB_id], NULL); // pthread_join(cthr_d[UE_id][eNB_id], NULL); // pthread_join(thread[eNB_id][UE_id], NULL); // do_DL_sig_channel(eNB_id,UE_id,r_re0,r_im0,r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],s_re[eNB_id],s_im[eNB_id],eNB2UE,enb_data, ue_data,next_slot,abstraction_flag,frame_parms); // do_DL_sig_channel(eNB_id,UE_id,r_re0_d[UE_id][eNB_id],r_im0_d[UE_id][eNB_id],r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],s_re[eNB_id],s_im[eNB_id],eNB2UE,enb_data, ue_data,next_slot,abstraction_flag,frame_parms); } } */ // //for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ //for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { //pthread_join(cthr_d[UE_id][eNB_id], NULL); //} //} for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ clean_param(r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],frame_parms); for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { channel_add(r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],r_re0_d[UE_id][eNB_id],r_im0_d[UE_id][eNB_id],frame_parms); } } // if(UE_id==NB_UE_INST) // pthread_join(thread, NULL); //} for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { // pthread_join(thread, NULL); //pthread_join(thread[eNB_id][UE_id], NULL); } } // } st2->EResp_FLAG=0; count=0; for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) if (mac_xface->frame >= (UE_id * 10)) { // activate UE only after 10*UE_id frames so that different UEs turn on separately send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38820+UE_id); printf("Waiting for Exec Msg Complete \n"); //n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); } else{ st2->EResp_FLAG=st2->EResp_FLAG+1; count++; } while(count<NB_UE_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } //while(st2->EResp_FLAG<NB_UE_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // printf(".."); // } } else if(dir_flag==2) { st2->EResp_FLAG=0; count=0; for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) if (mac_xface->frame >= (UE_id * 10)) { // activate UE only after 10*UE_id frames so that different UEs turn on separately send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38820+UE_id); // printf("Waiting for Exec Msg Complete \n"); // n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); } else{ st2->EResp_FLAG=st2->EResp_FLAG+1; count++; } while(count<NB_UE_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } //while(st2->EResp_FLAG<NB_UE_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // printf(".."); // } // do_UL_sig_channel2(1,0,r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,next_slot,abstraction_flag,frame_parms); // do_UL_sig_channel(r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,next_slot,abstraction_flag,frame_parms); for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ e2u_t[eNB_id][UE_id]->eNB_id=eNB_id; e2u_t[eNB_id][UE_id]->UE_id=UE_id; e2u_t[eNB_id][UE_id]->r_re=r_re[eNB_id]; e2u_t[eNB_id][UE_id]->r_im=r_im[eNB_id]; e2u_t[eNB_id][UE_id]->r_re0=r_re0_u[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->r_im0=r_im0_u[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->s_im=s_im[NB_eNB_INST+UE_id]; e2u_t[eNB_id][UE_id]->s_re=s_re[NB_eNB_INST+UE_id]; e2u_t[eNB_id][UE_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; e2u_t[eNB_id][UE_id]->enb_data=enb_data[eNB_id]; e2u_t[eNB_id][UE_id]->ue_data=ue_data[UE_id]; e2u_t[eNB_id][UE_id]->next_slot=&next_slot; e2u_t[eNB_id][UE_id]->abstraction_flag=&abstraction_flag; e2u_t[eNB_id][UE_id]->frame_parms=frame_parms; pthread_create (&cthr_u[eNB_id][UE_id], NULL, do_UL_sig_channel_T,(void*)e2u_t[eNB_id][UE_id]); // pthread_create (&thread[eNB_id][UE_id], NULL, do_UL_sig_channel_T,(void*)cthread); // do_UL_sig_channel(eNB_id,UE_id,r_re0,r_im0,r_re[eNB_id],r_im[eNB_id],s_re[NB_eNB_INST+UE_id],s_im[NB_eNB_INST+UE_id],UE2eNB,next_slot,abstraction_flag,frame_parms); // do_UL_sig_channel(eNB_id,UE_id,r_re0_u[eNB_id][UE_id],r_im0_u[eNB_id][UE_id],r_re[eNB_id],r_im[eNB_id],s_re[NB_eNB_INST+UE_id],s_im[NB_eNB_INST+UE_id],UE2eNB,next_slot,abstraction_flag,frame_parms); } } for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ // pthread_join(thread[eNB_id][UE_id], NULL); pthread_join(cthr_u[eNB_id][UE_id], NULL); } } for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { clean_param(r_re[eNB_id],r_im[eNB_id],frame_parms); for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ channel_add(r_re[eNB_id],r_im[eNB_id],r_re0_u[eNB_id][UE_id],r_im0_u[eNB_id][UE_id],frame_parms); } } // } st2->EResp_FLAG=0; count=0; for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38810+eNB_id); // n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); // printf("Waiting for Exec Msg Complete \n"); } // for loop while(count<NB_eNB_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } // while(st2->EResp_FLAG<NB_eNB_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // // printf(".."); // } } if ((last_slot == 1) && (mac_xface->frame == 0) && (abstraction_flag == 0) && (oai_emulation.info.n_frames == 1)) { // write_output ("dlchan0.m", "dlch0", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("dlchan1.m", "dlch1", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[1][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("dlchan2.m", "dlch2", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[2][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("pbch_rxF_comp0.m", "pbch_comp0", // PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0], 6 * 12 * 4, 1, 1); // write_output ("pbch_rxF_llr.m", "pbch_llr", // PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr, (frame_parms->Ncp == 0) ? 1920 : 1728, 1, 4); } /* if ((last_slot==1) && (mac_xface->frame==1)) { write_output("dlsch_rxF_comp0.m","dlsch0_rxF_comp0",PHY_vars_UE->lte_ue_dlsch_vars[eNB_id]->rxdataF_comp[0],300*(-(PHY_vars_UE->lte_frame_parms.Ncp*2)+14),1,1); write_output("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",PHY_vars_UE->lte_ue_pdcch_vars[eNB_id]->rxdataF_comp[0],4*300,1,1); } */ if (next_slot %2 == 0){ clock_gettime (CLOCK_REALTIME, &time_spec); time_last = time_now; time_now = (unsigned long) time_spec.tv_nsec; td = (int) (time_now - time_last); if (td>0) { td_avg = (int)(((K*(long)td) + (((1<<3)-K)*((long)td_avg)))>>3); // in us LOG_I(EMU,"sleep frame %d, average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n", mac_xface->frame, td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000); } if (td_avg<(TARGET_SF_TIME_NS - SF_DEVIATION_OFFSET_NS)){ sleep_time_us += SLEEP_STEP_US; } else if (td_avg > (TARGET_SF_TIME_NS + SF_DEVIATION_OFFSET_NS)) { sleep_time_us-= SLEEP_STEP_US; } }// end if next_slot%2 } //end of slot
int main (int argc, char **argv) { args_t args; LTE_DL_FRAME_PARMS frame_parms0; LTE_DL_FRAME_PARMS *frame_parms=&frame_parms; char sdu0[16],sdu1[64],sdu2[1024],sdu3[1024],sdu4[1024]; unsigned short sdu_len0,sdu_len1,sdu_len2,sdu_len3,sdu_len4; char ulsch_buffer[1024],dlsch_buffer[1024]; u8 lcid; u8 payload_offset; int i,comp; logInit(); NB_UE_INST = 1; NB_eNB_INST = 1; NB_INST=2; // Parse arguments if(parse_args(argc, argv, &args) > 0) { print_usage(argv[0]); exit(1); } set_taus_seed(0); logInit(); set_glog(LOG_TRACE, 1); for (comp = PHY; comp < MAX_LOG_COMPONENTS ; comp++) set_comp_log(comp, LOG_TRACE, LOG_NONE, 1); /* set_log(OMG, LOG_INFO, 20); set_log(EMU, LOG_INFO, 10); set_log(OCG, LOG_INFO, 1); set_log(MAC, LOG_TRACE, 1); set_log(RLC, LOG_TRACE, 1); set_log(PHY, LOG_DEBUG, 1); set_log(PDCP, LOG_TRACE, 1); set_log(RRC, LOG_TRACE, 1); */ mac_xface = (MAC_xface *)malloc(sizeof(MAC_xface)); init_lte_vars (&frame_parms, 0, 1, 0, 0, 25, 0, 0, 1, 1); l2_init(frame_parms); // Generate eNB SI if (args.input_sib == 0) { openair_rrc_lite_eNB_init(0); } else { printf("Got SI from files (%d,%d,%d,%d,%d)\n",args.input_sib,args.input1_sdu_flag,args.input2_sdu_flag); } openair_rrc_on(0,0); openair_rrc_lite_ue_init(0,0); switch (args.SDUsource) { case eNB_RRC: if (args.RRCmessage == RRCSIB1) { if (args.input1_sdu_flag == 1) { for (i=0; i<args.input1_sdu_len; i++) printf("%02x",args.input1_sdu[i]); printf("\n"); ue_decode_si(0,142,0,args.input1_sdu,args.input1_sdu_len); } else { printf("\n\nSIB1\n\n"); for (i=0; i<eNB_rrc_inst[0].sizeof_SIB1; i++) printf("%02x",eNB_rrc_inst[0].SIB1[i]); printf("\n"); } } else if (args.RRCmessage == RRCSIB2_3) { if (args.input1_sdu_flag == 1) { for (i=0; i<args.input2_sdu_len; i++) printf("%02x",args.input2_sdu[i]); printf("\n"); ue_decode_si(0,149,0,args.input1_sdu,args.input1_sdu_len); } else { printf("\n\nSIB2_3\n\n"); for (i=0; i<eNB_rrc_inst[0].sizeof_SIB23; i++) printf("%02x",eNB_rrc_inst[0].SIB23[i]); printf("\n"); } } else if ((args.input1_sdu_flag == 1)&& ((args.RRCmessage == RRCConnectionSetup) || (args.RRCmessage == RRCConnectionReconfiguration))) { sdu_len0 = attach_ue0(sdu0); ue_send_sdu(0,143,args.input1_sdu,args.input1_sdu_len,0); if (args.RRCmessage == RRCConnectionReconfiguration) ue_send_sdu(0,144,args.input2_sdu,args.input2_sdu_len,0); } else { switch (args.RRCmessage) { case RRCConnectionSetup: printf("Doing eNB RRCConnectionSetup\n"); sdu_len0 = attach_ue0(sdu0); sdu_len1 = attach_ue1(sdu1); lcid = 0; payload_offset = generate_dlsch_header(dlsch_buffer, 1, //num_sdus &sdu_len1, // &lcid, // sdu_lcid 255, // no drx 0, // no timing advance sdu0, // contention res id 0,0); memcpy(&dlsch_buffer[payload_offset],sdu1,sdu_len1); printf("\nRRCConnectionSetup (DLSCH input / MAC output)\n\n"); for (i=0; i<sdu_len1+payload_offset; i++) printf("%02x ",(unsigned char)sdu1[i]); printf("\n"); break; case RRCConnectionReconfiguration: printf("Doing eNB RRCConnectionReconfiguration\n"); sdu_len0 = attach_ue0(sdu0); sdu_len1 = attach_ue1(sdu1); sdu_len2 = attach_ue2(sdu1,sdu_len1,sdu2); sdu_len3 = attach_ue3(sdu2,sdu_len2,sdu3); lcid=1; payload_offset = generate_dlsch_header(dlsch_buffer, // offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[0].DLSCH_pdu[0][0].payload[0], 1, //num_sdus &sdu_len3, // &lcid, 255, // no drx 1, // timing advance NULL, // contention res idk 0,0); memcpy(&dlsch_buffer[payload_offset],sdu3,sdu_len3); printf("\nRRCConnectionReconfiguration (DLSCH input / MAC output)\n\n"); for (i=0; i<sdu_len3+payload_offset; i++) printf("%02x ",(unsigned char)dlsch_buffer[i]); printf("\n"); break; default: printf("Unknown eNB_RRC SDU (%d), exiting\n",args.RRCmessage); break; } break; } break; case eNB_MAC: sdu_len0 = attach_ue0(sdu0); ue_send_sdu(0,143,args.input1_sdu,args.input1_sdu_len,0); break; case UE_RRC: switch (args.RRCmessage) { case RRCConnectionRequest: sdu_len0 = attach_ue0(sdu0); printf("\n\nRRCConnectionRequest\n\n"); for (i=0; i<sdu_len0; i++) printf("%02x ",(unsigned char)sdu0[i]); printf("\n"); break; case RRCConnectionSetupComplete: sdu_len0=attach_ue0(sdu0); sdu_len1 = attach_ue1(sdu1); sdu_len2 = attach_ue2(sdu1,sdu_len1,sdu2); lcid=1; printf("Got sdu of length %d\n",sdu_len2); payload_offset = generate_ulsch_header((u8*)ulsch_buffer, // mac header 1, // num sdus 0, // short pading &sdu_len2, // sdu length &lcid, // sdu lcid NULL, // power headroom NULL, // crnti NULL, // truncated bsr NULL, // short bsr NULL, // long_bsr 0); printf("Got MAC header of length %d\n",payload_offset); memcpy(&ulsch_buffer[payload_offset],sdu2,sdu_len2); printf("\n\nRRCConnectionSetupComplete (ULSCH input / MAC output)\n\n"); for (i=0; i<sdu_len2+payload_offset; i++) printf("%02x ",(unsigned char)ulsch_buffer[i]); printf("\n"); break; case RRCConnectionReconfigurationComplete: sdu_len0=attach_ue0(sdu0); sdu_len1=attach_ue1(sdu1); sdu_len2 = attach_ue2(sdu1,sdu_len1,sdu2); sdu_len3 = attach_ue3(sdu2,sdu_len2,sdu3); sdu_len4 = attach_ue4(sdu3,sdu_len3,sdu4); lcid=1; printf("Got sdu of length %d\n",sdu_len4); payload_offset = generate_ulsch_header((u8*)ulsch_buffer, // mac header 1, // num sdus 0, // short pading &sdu_len4, // sdu length &lcid, // sdu lcid NULL, // power headroom NULL, // crnti NULL, // truncated bsr NULL, // short bsr NULL, // long_bsr 0); printf("Got MAC header of length %d\n",payload_offset); memcpy(&ulsch_buffer[payload_offset],sdu4,sdu_len4); printf("\n\nRRCConnectionReconfigurationComplete (ULSCH input / MAC output)\n\n"); for (i=0; i<sdu_len4+payload_offset; i++) printf("%02x ",(unsigned char)ulsch_buffer[i]); printf("\n"); break; default: printf("Unknown UE_RRC SDU (%d), exiting\n",args.RRCmessage); break; } break; } free(mac_xface); return(0); }
int main(int argc, char **argv) { int i,l,aa,sector; double sigma2, sigma2_dB=0; mod_sym_t **txdataF; #ifdef IFFT_FPGA int **txdataF2; #endif int **txdata,**rxdata; 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,Td=1.0; int channel_length; int amp; unsigned char pbch_pdu[6]; int sync_pos, sync_pos_slot; FILE *rx_frame_file; int result; int freq_offset; int subframe_offset; char fname[40], vname[40]; int trial, n_errors=0; unsigned int nb_rb = 25; unsigned int first_rb = 0; unsigned int eNb_id = 0; unsigned int slot_offset = 0; unsigned int sample_offset = 0; unsigned int channel_offset = 0; int n_frames; int slot=0,last_slot=0,next_slot=0; double nf[2] = {3.0,3.0}; //currently unused double ip =0.0; double N0W, path_loss, path_loss_dB, tx_pwr, rx_pwr; double rx_gain; int rx_pwr2, target_rx_pwr_dB; struct complex **ch; unsigned char first_call = 1; LTE_DL_FRAME_PARMS frame_parms; LTE_DL_FRAME_PARMS *lte_frame_parms = &frame_parms; if (argc==2) amp = atoi(argv[1]); else amp = 1024; // we normalize the tx power to 0dBm, assuming the amplitude of the signal is 1024 // the SNR is this given by the difference of the path loss and the thermal noise (~-105dBm) // the rx_gain is adjusted automatically to achieve the target_rx_pwr_dB path_loss_dB = -90; path_loss = pow(10,path_loss_dB/10); target_rx_pwr_dB = 60; lte_frame_parms->N_RB_DL = 25; lte_frame_parms->N_RB_UL = 25; lte_frame_parms->Ng_times6 = 1; lte_frame_parms->Ncp = 1; lte_frame_parms->Nid_cell = 0; lte_frame_parms->nushift = 0; lte_frame_parms->nb_antennas_tx = 2; lte_frame_parms->nb_antennas_rx = 2; lte_frame_parms->first_dlsch_symbol = 4; lte_frame_parms->num_dlsch_symbols = 6; lte_frame_parms->Csrs = 2; lte_frame_parms->Bsrs = 0; lte_frame_parms->kTC = 0; lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = 1; lte_frame_parms->ofdm_symbol_size = 512; lte_frame_parms->log2_symbol_size = 9; lte_frame_parms->samples_per_tti = 7680; lte_frame_parms->first_carrier_offset = 362; lte_frame_parms->nb_prefix_samples>>=2; #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); rxdata = (int **)malloc16(2*sizeof(int*)); rxdata[0] = (int *)malloc16(2*FRAME_LENGTH_BYTES); rxdata[1] = (int *)malloc16(2*FRAME_LENGTH_BYTES); bzero(rxdata[0],2*FRAME_LENGTH_BYTES); bzero(rxdata[1],2*FRAME_LENGTH_BYTES); txdataF2 = (int **)malloc16(2*sizeof(int*)); txdataF2[0] = (int *)malloc16(FRAME_LENGTH_BYTES); txdataF2[1] = (int *)malloc16(FRAME_LENGTH_BYTES); bzero(txdataF2[0],FRAME_LENGTH_BYTES); bzero(txdataF2[1],FRAME_LENGTH_BYTES); #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*)); for (i=0; i<2; i++) { s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_im[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(r_im[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); } for (i=0; i<2; i++) { for (l=0; l<FRAME_LENGTH_COMPLEX_SAMPLES; l++) { ((short*) txdata[i])[2*l] = amp * cos(M_PI/2*l); ((short*) txdata[i])[2*l+1] = amp * sin(M_PI/2*l); } } tx_pwr = signal_energy(txdata[0],lte_frame_parms->samples_per_tti>>1); printf("tx_pwr (DAC in) %d dB for slot %d (subframe %d)\n",dB_fixed(tx_pwr),next_slot,next_slot>>1); channel_length = (int) 11+2*BW*Td; ch = (struct complex**) malloc(4 * sizeof(struct complex*)); for (i = 0; i<4; i++) ch[i] = (struct complex*) malloc(channel_length * sizeof(struct complex)); randominit(0); set_taus_seed(0); #ifdef RF tx_pwr = dac_fixed_gain(s_re, s_im, txdata, lte_frame_parms->nb_antennas_tx, lte_frame_parms->samples_per_tti>>1, 14, 18); //this should give 0dBm output level for input with amplitude 1024 printf("tx_pwr (DAC out) %f dB for slot %d (subframe %d)\n",10*log10(tx_pwr),next_slot,next_slot>>1); #else for (i=0; i<(lte_frame_parms->samples_per_tti>>1); i++) { for (aa=0; aa<lte_frame_parms->nb_antennas_tx; aa++) { s_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); s_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); } } #endif // printf("channel for slot %d (subframe %d)\n",next_slot,next_slot>>1); multipath_channel(ch,s_re,s_im,r_re,r_im, amps,Td,BW,ricean_factor,aoa, lte_frame_parms->nb_antennas_tx, lte_frame_parms->nb_antennas_rx, lte_frame_parms->samples_per_tti>>1, channel_length, 0, .9, (first_call == 1) ? 1 : 0); if (first_call == 1) first_call = 0; #ifdef RF //path_loss_dB = 0; //path_loss = 1; for (i=0; i<(lte_frame_parms->samples_per_tti>>1); i++) { for (aa=0; aa<lte_frame_parms->nb_antennas_rx; aa++) { r_re[aa][i]=r_re[aa][i]*sqrt(path_loss); r_im[aa][i]=r_im[aa][i]*sqrt(path_loss); } } rx_pwr = signal_energy_fp(r_re,r_im,lte_frame_parms->nb_antennas_rx,lte_frame_parms->samples_per_tti>>1,0); printf("rx_pwr (RF in) %f dB for slot %d (subframe %d)\n",10*log10(rx_pwr),next_slot,next_slot>>1); rx_gain = target_rx_pwr_dB - 10*log10(rx_pwr); // RF model rf_rx(r_re, r_im, NULL, NULL, 0, lte_frame_parms->nb_antennas_rx, lte_frame_parms->samples_per_tti>>1, 1.0/7.68e6 * 1e9, // sampling time (ns) 0.0, // freq offset (Hz) (-20kHz..20kHz) 0.0, // drift (Hz) NOT YET IMPLEMENTED nf, // noise_figure NOT YET IMPLEMENTED rx_gain-66.227, // rx gain (66.227 = 20*log10(pow2(11)) = gain from the adc that will be applied later) 200, // IP3_dBm (dBm) &ip, // initial phase 30.0e3, // pn_cutoff (kHz) -500.0, // pn_amp (dBc) default: 50 0.0, // IQ imbalance (dB), 0.0); // IQ phase imbalance (rad) rx_pwr = signal_energy_fp(r_re,r_im,lte_frame_parms->nb_antennas_rx,lte_frame_parms->samples_per_tti>>1,0); printf("rx_pwr (ADC in) %f dB for slot %d (subframe %d)\n",10*log10(rx_pwr),next_slot,next_slot>>1); #endif #ifdef RF adc(r_re, r_im, 0, slot_offset, rxdata, lte_frame_parms->nb_antennas_rx, lte_frame_parms->samples_per_tti>>1, 12); rx_pwr2 = signal_energy(rxdata[0]+slot_offset,lte_frame_parms->samples_per_tti>>1); printf("rx_pwr (ADC out) %f dB (%d) for slot %d (subframe %d)\n",10*log10((double)rx_pwr2),rx_pwr2,next_slot,next_slot>>1); #else for (i=0; i<(lte_frame_parms->samples_per_tti>>1); i++) { for (aa=0; aa<lte_frame_parms->nb_antennas_rx; aa++) { ((short*) rxdata[aa])[2*slot_offset + (2*i)] = (short) ((r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); ((short*) rxdata[aa])[2*slot_offset + (2*i)+1] = (short) ((r_im[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); } } #endif write_output("rxsig0.m","rxs0",rxdata[0],lte_frame_parms->samples_per_tti>>1,1,1); write_output("rxsig1.m","rxs1",rxdata[1],lte_frame_parms->samples_per_tti>>1,1,1); #ifdef IFFT_FPGA free(txdataF2[0]); free(txdataF2[1]); free(txdataF2); free(txdata[0]); free(txdata[1]); free(txdata); free(rxdata[0]); free(rxdata[1]); free(rxdata); #endif for (i=0; i<2; i++) { free(s_re[i]); free(s_im[i]); free(r_re[i]); free(r_im[i]); } free(s_re); free(s_im); free(r_re); free(r_im); return(0); }
void fft_test(char *dma_buffer_local, char log2N, char test, int openair_fd) { int N=pow(2,log2N), radix=4; //,test=0; int i; char maxscale[7],MAXSHIFT; char *scale; //scale[7] double maxSNR,input_dB; struct complex *data; struct complex_fixed *data_fixed; set_taus_seed(); if ((data=malloc(sizeof(struct complex)*(size_t)N))==NULL) { fprintf(stderr, "Out of memory!\n"); exit(1); } // data_fixed = &((struct complex_fixed *)dma_buffer_local)[2]; scale = &((char *)dma_buffer_local)[0]; if ((data_fixed=malloc(sizeof(struct complex_fixed)*(size_t)N))==NULL) { fprintf(stderr, "Out of memory!\n"); exit(1); } /** Set up power of two arrays */ pow_2[0]=1; for (i=1; i<MAXPOW; i++) pow_2[i]=pow_2[i-1]*2; pow_4[0]=1; for (i=1; i<MAXPOW; i++) pow_4[i]=pow_4[i-1]*4; #ifdef OPEN_OUTPUT_FILE if ((fid = fopen("res_output.m","w")) == NULL) { printf("[FFT_TEST] Cannot open res_output.m data file\n"); exit(0); } fprintf(fid,"res16_%d = [ \n",N); #endif printf("res16_%d = [ \n",N); for (input_dB=-50;input_dB<0;input_dB++) { // input_dB = -40; switch (N) { case 64: // scale = SCALE64; MAXSHIFT=3; break; case 256: // scale = SCALE256; MAXSHIFT=4; break; case 1024: // scale = SCALE1024; MAXSHIFT=5; break; case 4096: // scale = SCALE4096; MAXSHIFT=6; break; } for (i=0;i<7;i++) scale[i] = 0; maxSNR = -1000; switch (N) { case 4096: for (scale[0]=0;scale[0]<=MAXSHIFT;scale[0]++) for (scale[1]=0;scale[1]<=MAXSHIFT-scale[0];scale[1]++) for (scale[2]=0;scale[2]<=MAXSHIFT-scale[0]-scale[1];scale[2]++) for (scale[3]=0;scale[3]<=MAXSHIFT-scale[0]-scale[1]-scale[2];scale[3]++) for (scale[4]=0;scale[4]<=MAXSHIFT-scale[0]-scale[1]-scale[2]-scale[3];scale[4]++) for (scale[5]=0;scale[5]<=MAXSHIFT-scale[0]-scale[1]-scale[2]-scale[3]-scale[4];scale[5]++){ scale[6]=MAXSHIFT-scale[0]-scale[1]-scale[2]-scale[3]-scale[4]-scale[5]; fft_distortion_test(N,test,input_dB,scale,&maxSNR,maxscale,data,data_fixed,openair_fd); } printf("%f, %f, %% Optimum Scaling : %d %d %d %d %d %d %d\n",input_dB,maxSNR,maxscale[0],maxscale[1],maxscale[2],maxscale[3],maxscale[4],maxscale[5],maxscale[6]); break; case 1024: for (scale[0]=0;scale[0]<=MAXSHIFT;scale[0]++) for (scale[1]=0;scale[1]<=MAXSHIFT-scale[0];scale[1]++) for (scale[2]=0;scale[2]<=MAXSHIFT-scale[0]-scale[1];scale[2]++) for (scale[3]=0;scale[3]<=MAXSHIFT-scale[0]-scale[1]-scale[2];scale[3]++) for (scale[4]=0;scale[4]<=MAXSHIFT-scale[0]-scale[1]-scale[2]-scale[3];scale[4]++){ scale[6]=MAXSHIFT-scale[0]-scale[1]-scale[2]-scale[3]-scale[4]; fft_distortion_test(N,test,input_dB,scale,&maxSNR,maxscale,data,data_fixed,openair_fd); } printf("%f, %f, %% Optimum Scaling : %d %d %d %d %d %d %d\n",input_dB,maxSNR,maxscale[0],maxscale[1],maxscale[2],maxscale[3],maxscale[4],maxscale[5],maxscale[6]); break; case 256: for (scale[0]=0;scale[0]<=MAXSHIFT;scale[0]++) for (scale[1]=0;scale[1]<=MAXSHIFT-scale[0];scale[1]++) for (scale[2]=0;scale[2]<=MAXSHIFT-scale[0]-scale[1];scale[2]++) for (scale[3]=0;scale[3]<=MAXSHIFT-scale[0]-scale[1]-scale[2];scale[3]++) { scale[6]=MAXSHIFT-scale[0]-scale[1]-scale[2]-scale[3]; // scale[0] = 2; // scale[1] = 1; // scale[2] = 1; fft_distortion_test(N,test,input_dB,scale,&maxSNR,maxscale,data,&((struct complex_fixed *)dma_buffer_local)[2],openair_fd); } printf("%f, %f, %% Optimum Scaling : %d %d %d %d %d %d %d\n",input_dB,maxSNR,maxscale[0],maxscale[1],maxscale[2],maxscale[3],maxscale[4],maxscale[5],maxscale[6]); #ifdef OPEN_OUTPUT_FILE fprintf(fid,"%f, %f, %% Optimum Scaling : %d %d %d %d %d %d %d\n",input_dB,maxSNR,maxscale[0],maxscale[1],maxscale[2],maxscale[3],maxscale[4],maxscale[5],maxscale[6]); #endif break; case 64: for (scale[0]=0;scale[0]<=MAXSHIFT;scale[0]++) for (scale[1]=0;scale[1]<=MAXSHIFT-scale[0];scale[1]++) for (scale[2]=0;scale[2]<=MAXSHIFT-scale[0]-scale[1];scale[2]++) { scale[6]=MAXSHIFT-scale[0]-scale[1]-scale[2]; fft_distortion_test(N,test,input_dB,scale,&maxSNR,maxscale,data,data_fixed,openair_fd); } printf("%f, %f, %% Optimum Scaling : %d %d %d %d %d %d %d\n",input_dB,maxSNR,maxscale[0],maxscale[1],maxscale[2],maxscale[3],maxscale[4],maxscale[5],maxscale[6]); break; } /* for (i=0;i<N;i++) { printf("%d + sqrt(-1)*(%d)\n",(short)(32767*data[i].r),(short)(32767*data[i].i)); } printf("];\n"); printf("out_fixed = [ \n"); for (i=0;i<N;i++) printf("%d + sqrt(-1)*(%d)\n",(short)(data_fixed[i].r),(short)(data_fixed[i].i)); printf("];\n"); */ } #ifdef OPEN_OUTPUT_FILE fprintf(fid,"];\n"); #endif printf("];\n"); }
void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode) { unsigned int ind; printf("Start lte_param_init\n"); PHY_vars_eNb = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE = malloc(sizeof(PHY_VARS_UE)); PHY_config = malloc(sizeof(PHY_CONFIG)); mac_xface = malloc(sizeof(MAC_xface)); randominit(0); set_taus_seed(0); lte_frame_parms = &(PHY_vars_eNb->lte_frame_parms); lte_frame_parms->N_RB_DL = 25; //50 for 10MHz and 25 for 5 MHz lte_frame_parms->N_RB_UL = 25; lte_frame_parms->Ncp = 1; lte_frame_parms->Nid_cell = 0; lte_frame_parms->nushift = 0; lte_frame_parms->nb_antennas_tx = N_tx; lte_frame_parms->nb_antennas_rx = N_rx; lte_frame_parms->first_dlsch_symbol = 4; lte_frame_parms->num_dlsch_symbols = 6; lte_frame_parms->Csrs = 2; lte_frame_parms->Bsrs = 0; lte_frame_parms->kTC = 0; lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = (transmission_mode == 1)? 1 : 0; init_frame_parms(lte_frame_parms); copy_lte_parms_to_phy_framing(lte_frame_parms, &(PHY_config->PHY_framing)); phy_init_top(N_tx); //allocation lte_frame_parms->twiddle_fft = twiddle_fft; lte_frame_parms->twiddle_ifft = twiddle_ifft; lte_frame_parms->rev = rev; PHY_vars_UE->lte_frame_parms = *lte_frame_parms; lte_gold(lte_frame_parms); generate_ul_ref_sigs(); generate_ul_ref_sigs_rx(); generate_64qam_table(); generate_16qam_table(); generate_RIV_tables(); generate_pcfich_reg_mapping(lte_frame_parms); generate_phich_reg_mapping_ext(lte_frame_parms); phy_init_lte_ue(&PHY_vars_UE->lte_frame_parms, &PHY_vars_UE->lte_ue_common_vars, PHY_vars_UE->lte_ue_dlsch_vars, PHY_vars_UE->lte_ue_dlsch_vars_cntl, PHY_vars_UE->lte_ue_dlsch_vars_ra, PHY_vars_UE->lte_ue_dlsch_vars_1A, PHY_vars_UE->lte_ue_pbch_vars, PHY_vars_UE->lte_ue_pdcch_vars, PHY_vars_UE); phy_init_lte_eNB(&PHY_vars_eNb->lte_frame_parms, &PHY_vars_eNb->lte_eNB_common_vars, PHY_vars_eNb->lte_eNB_ulsch_vars, 0, PHY_vars_eNb); printf("Done lte_param_init\n"); }
void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,unsigned char frame_type, uint16_t Nid_cell,uint8_t N_RB_DL,uint8_t osf) { // unsigned int ind; LTE_DL_FRAME_PARMS *lte_frame_parms; int i; printf("Start lte_param_init\n"); PHY_vars_eNb = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_eNb1 = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_eNb2 = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE = malloc(sizeof(PHY_VARS_UE)); //PHY_config = malloc(sizeof(PHY_CONFIG)); mac_xface = malloc(sizeof(MAC_xface)); randominit(0); set_taus_seed(0); lte_frame_parms = &(PHY_vars_eNb->lte_frame_parms); lte_frame_parms->N_RB_DL = N_RB_DL; //50 for 10MHz and 25 for 5 MHz lte_frame_parms->N_RB_UL = N_RB_DL; lte_frame_parms->Ncp = extended_prefix_flag; lte_frame_parms->Nid_cell = Nid_cell; lte_frame_parms->nushift = Nid_cell%6; lte_frame_parms->nb_antennas_tx = N_tx; lte_frame_parms->nb_antennas_tx_eNB = N_tx; lte_frame_parms->nb_antennas_rx = N_rx; // lte_frame_parms->Csrs = 2; // lte_frame_parms->Bsrs = 0; // lte_frame_parms->kTC = 0; // lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = (transmission_mode == 1)? 1 : 0; lte_frame_parms->tdd_config = 3; lte_frame_parms->frame_type = frame_type; init_frame_parms(lte_frame_parms,osf); //copy_lte_parms_to_phy_framing(lte_frame_parms, &(PHY_config->PHY_framing)); PHY_vars_UE->lte_frame_parms = *lte_frame_parms; phy_init_lte_top(lte_frame_parms); PHY_vars_UE->PHY_measurements.n_adj_cells=2; PHY_vars_UE->PHY_measurements.adj_cell_id[0] = Nid_cell+1; PHY_vars_UE->PHY_measurements.adj_cell_id[1] = Nid_cell+2; for (i=0; i<3; i++) lte_gold(lte_frame_parms,PHY_vars_UE->lte_gold_table[i],Nid_cell+i); phy_init_lte_ue(PHY_vars_UE,1,0); phy_init_lte_eNB(PHY_vars_eNb,0,0,0); for (i=0; i<10; i++) { PHY_vars_UE->scan_info[0].amp[0][i] = 0; PHY_vars_UE->scan_info[0].amp[1][i] = 0; PHY_vars_UE->scan_info[0].amp[2][i] = 0; } memcpy((void*)&PHY_vars_eNb1->lte_frame_parms,(void*)&PHY_vars_eNb->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); PHY_vars_eNb1->lte_frame_parms.Nid_cell=Nid_cell+1; PHY_vars_eNb1->lte_frame_parms.nushift=(Nid_cell+1)%6; PHY_vars_eNb1->Mod_id=1; memcpy((void*)&PHY_vars_eNb2->lte_frame_parms,(void*)&PHY_vars_eNb->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); PHY_vars_eNb2->lte_frame_parms.Nid_cell=Nid_cell+2; PHY_vars_eNb2->lte_frame_parms.nushift=(Nid_cell+2)%6; PHY_vars_eNb2->Mod_id=2; phy_init_lte_eNB(PHY_vars_eNb1,0,0,0); phy_init_lte_eNB(PHY_vars_eNb2,0,0,0); phy_init_lte_top(lte_frame_parms); printf("Done lte_param_init\n"); }