Example #1
0
u16 get_TBS(u8 mcs,u16 nb_rb) {

  u16 TBS;

  if ((nb_rb > 0) && (mcs < 28)) {
#ifdef TBS_FIX
    TBS = 3*dlsch_tbs25[get_I_TBS(mcs)][nb_rb-1]/4;
    TBS = TBS>>3;
#else
    TBS = dlsch_tbs25[get_I_TBS(mcs)][nb_rb-1];
    TBS = TBS>>3;
#endif
    return(TBS);
  }
Example #2
0
uint32_t get_TBS_DL(uint8_t mcs, uint16_t nb_rb)
{

  uint32_t TBS;

  if ((nb_rb > 0) && (mcs < 29)) {
#ifdef TBS_FIX
    TBS = 3*TBStable[get_I_TBS(mcs)][nb_rb-1]/4;
    TBS = TBS>>3;
#else
    TBS = TBStable[get_I_TBS(mcs)][nb_rb-1];
    TBS = TBS>>3;
#endif
    return(TBS);
  } else {
Example #3
0
void fill_UE_dlsch_MCH(PHY_VARS_UE *phy_vars_ue,int mcs,int ndi,int rvidx,int eNB_id) {

    LTE_UE_DLSCH_t *dlsch = phy_vars_ue->dlsch_ue_MCH[eNB_id];
    LTE_DL_FRAME_PARMS *frame_parms=&phy_vars_ue->lte_frame_parms;

    //  dlsch->rnti   = M_RNTI;
    dlsch->harq_processes[0]->mcs   = mcs;
    dlsch->harq_processes[0]->rvidx = rvidx;
    //  dlsch->harq_processes[0]->Ndi   = ndi;
    dlsch->harq_processes[0]->Nl    = 1;
    dlsch->harq_processes[0]->TBS = TBStable[get_I_TBS(dlsch->harq_processes[0]->mcs)][frame_parms->N_RB_DL-1];
    dlsch->current_harq_pid = 0;
    dlsch->harq_processes[0]->nb_rb = frame_parms->N_RB_DL;

    switch(frame_parms->N_RB_DL) {
    case 6:
        dlsch->harq_processes[0]->rb_alloc[0] = 0x3f;
        break;
    case 25:
        dlsch->harq_processes[0]->rb_alloc[0] = 0x1ffffff;
        break;
    case 50:
        dlsch->harq_processes[0]->rb_alloc[0] = 0xffffffff;
        dlsch->harq_processes[0]->rb_alloc[1] = 0x3ffff;
        break;
    case 100:
        dlsch->harq_processes[0]->rb_alloc[0] = 0xffffffff;
        dlsch->harq_processes[0]->rb_alloc[1] = 0xffffffff;
        dlsch->harq_processes[0]->rb_alloc[2] = 0xffffffff;
        dlsch->harq_processes[0]->rb_alloc[3] = 0xf;
        break;
    }
}
Example #4
0
void fill_eNB_dlsch_MCH(PHY_VARS_eNB *phy_vars_eNB,int mcs,int ndi,int rvidx, int abstraction_flag)
{

  LTE_eNB_DLSCH_t *dlsch = phy_vars_eNB->dlsch_eNB_MCH;
  LTE_DL_FRAME_PARMS *frame_parms=&phy_vars_eNB->lte_frame_parms;

  //  dlsch->rnti   = M_RNTI;
  dlsch->harq_processes[0]->mcs   = mcs;
  //  dlsch->harq_processes[0]->Ndi   = ndi;
  dlsch->harq_processes[0]->rvidx = rvidx;
  dlsch->harq_processes[0]->Nl    = 1;
  dlsch->harq_processes[0]->TBS   = TBStable[get_I_TBS(dlsch->harq_processes[0]->mcs)][frame_parms->N_RB_DL-1];
  dlsch->current_harq_pid = 0;
  dlsch->harq_processes[0]->nb_rb = frame_parms->N_RB_DL;

  switch(frame_parms->N_RB_DL) {
  case 6:
    dlsch->harq_processes[0]->rb_alloc[0] = 0x3f;
    break;

  case 25:
    dlsch->harq_processes[0]->rb_alloc[0] = 0x1ffffff;
    break;

  case 50:
    dlsch->harq_processes[0]->rb_alloc[0] = 0xffffffff;
    dlsch->harq_processes[0]->rb_alloc[1] = 0x3ffff;
    break;

  case 100:
    dlsch->harq_processes[0]->rb_alloc[0] = 0xffffffff;
    dlsch->harq_processes[0]->rb_alloc[1] = 0xffffffff;
    dlsch->harq_processes[0]->rb_alloc[2] = 0xffffffff;
    dlsch->harq_processes[0]->rb_alloc[3] = 0xf;
    break;
  }

  if (abstraction_flag) {
    eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].cntl.pmch_flag=1;
    eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_pmch=1; // assumption: there is always one pmch in each SF
    eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_common_dci=0;
    eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_ue_spec_dci=0;
    eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dlsch_type[0]=5;// put at the reserved position for PMCH
    eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[0]=0;
    eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].ue_id[0]=255;//broadcast
    eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[0]=dlsch->harq_processes[0]->TBS>>3;
  }

}
Example #5
0
int main(int argc, char *argv[])
{

  int ret,ret2;
  unsigned int errors,uerrors,errors2,crc_misses,iterations,trials,trials2,block_length,errors3,trials3;
  double SNR,sigma,rate=.5;
  unsigned char qbits,mcs;

  char done0=0;
  char done1=1;
  char done2=1;

  unsigned int coded_bits;
  unsigned char NB_RB=25;

  int num_pdcch_symbols = 1;
  int subframe = 6;

  randominit(0);
  logInit();
  lte_param_init(1,1,1,0,0,3);

  PHY_vars_eNB->dlsch_eNB[0][0] = new_eNB_dlsch(1,8,NB_RB,0);
  PHY_vars_UE->dlsch_ue[0][0]  = new_ue_dlsch(1,8,4,NB_RB,0);
  PHY_vars_eNB->dlsch_eNB[0][1] = new_eNB_dlsch(1,8,NB_RB,0);
  PHY_vars_UE->dlsch_ue[0][1]  = new_ue_dlsch(1,8,4,NB_RB,0);

  if (argc>1)
    mcs = atoi(argv[1]);
  else
    mcs = 0;

  printf("NB_RB %d\n",NB_RB);
  DLSCH_alloc_pdu.rah              = 0;
  DLSCH_alloc_pdu.rballoc          = DLSCH_RB_ALLOC;
  DLSCH_alloc_pdu.TPC              = 0;
  DLSCH_alloc_pdu.dai              = 0;
  DLSCH_alloc_pdu.harq_pid         = 0;
  //DLSCH_alloc_pdu2.tb_swap          = 0;
  DLSCH_alloc_pdu.mcs             = mcs;
  DLSCH_alloc_pdu.ndi             = 1;
  DLSCH_alloc_pdu.rv              = 0;

  if (argc>2)
    qbits = atoi(argv[2]);
  else
    qbits = 4;

  printf("Quantization bits %d\n",qbits);

  generate_eNB_dlsch_params_from_dci(subframe,
                                     &DLSCH_alloc_pdu,
                                     0x1234,
                                     format1,
                                     PHY_vars_eNB->dlsch_eNB[0],
                                     &PHY_vars_eNB->lte_frame_parms,
                                     PHY_vars_eNB->pdsch_config_dedicated,
                                     SI_RNTI,
                                     0,
                                     P_RNTI,
                                     0); //change this later
  generate_ue_dlsch_params_from_dci(subframe,
                                    &DLSCH_alloc_pdu,
                                    C_RNTI,
                                    format1,
                                    PHY_vars_UE->dlsch_ue[0],
                                    &PHY_vars_UE->lte_frame_parms,
                                    PHY_vars_UE->pdsch_config_dedicated,
                                    SI_RNTI,
                                    0,
                                    P_RNTI);

  coded_bits =  get_G(&PHY_vars_eNB->lte_frame_parms,
                      PHY_vars_eNB->dlsch_eNB[0][0]->harq_processes[0]->nb_rb,
                      PHY_vars_eNB->dlsch_eNB[0][0]->harq_processes[0]->rb_alloc,
                      get_Qm(mcs),
                      1,
                      num_pdcch_symbols,
                      0,
                      subframe);

  printf("Coded_bits (G) = %d\n",coded_bits);

  block_length =  dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1]>>3;
  printf("Block_length = %d bytes (%d bits, rate %f), mcs %d, I_TBS %d, F %d, NB_RB %d\n",block_length,
         dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1],(double)dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1]/coded_bits,
         mcs,get_I_TBS(mcs),PHY_vars_eNB->dlsch_eNB[0][0]->harq_processes[0]->F,NB_RB);

  for (SNR=-5; SNR<15; SNR+=.1) {




    sigma = pow(10.0,-.05*SNR);
    printf("\n\nSNR %f dB => sigma %f\n",SNR,sigma);

    errors=0;
    crc_misses=0;
    errors2=0;
    errors3=0;

    iterations=0;

    if (done0 == 0) {



      ret = test_logmap8(PHY_vars_eNB->dlsch_eNB[0][0],
                         PHY_vars_UE->dlsch_ue[0][0],
                         coded_bits,
                         NB_RB,
                         sigma,   // noise standard deviation
                         qbits,
                         block_length,   // block length bytes
                         NTRIALS,
                         &errors,
                         &trials,
                         &uerrors,
                         &crc_misses,
                         &iterations,
                         num_pdcch_symbols,
                         subframe);

      if (ret>=0)
        printf("%f,%f,%f,%f\n",SNR,(double)errors/trials,(double)crc_misses/trials,(double)iterations/trials);

      if (((double)errors/trials) < 1e-2)
        done0=1;
    }

    if ((done0==1) && (done1==1) && (done2==1)) {
      printf("done\n");
      break;
    }
  }

  return(0);
}
Example #6
0
File: gd_rx.c Project: gkchai/garud
void configure(int argc, char **argv, int trials, short* iqr, short* iqi, int mmcs, int nrx, int num_bss){

    mcs = mmcs;
    /**************************************************************************/
    char c;
    int i, j,u;
    double snr0=-2.0,snr1,rate;
    double input_snr_step=.2,snr_int=30;
    double forgetting_factor=0.0; //in [0,1] 0 means a new channel every time, 1 means keep the same channel
    uint8_t extended_prefix_flag=0;
    int eNB_id = 0;
    int chMod = 0 ;
    int UE_id = 0;
    unsigned char l;
    int **txdata;
    unsigned char awgn_flag = 0 ;
    SCM_t channel_model=Rice1;
    unsigned int coded_bits_per_codeword,nsymb;
    uint8_t transmission_mode=1,n_tx=1;
    n_rx = nrx;
    FILE *input_fdUL=NULL;
    short input_val_str, input_val_str2;
    int n_frames=1000;
    int n_ch_rlz = 1;
    int abstx = 0;
    channel_desc_t *UE2eNB;
    int delay = 0;
    double maxDoppler = 0.0;
    uint8_t srs_flag = 0;
    uint8_t N_RB_DL=50,osf=1;
    uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2;
    uint8_t tdd_config=3,frame_type=FDD;
    uint8_t N0=30;
    double tx_gain=1.0;
    double cpu_freq_GHz;
    int s;
    int dump_perf=0;
    int test_perf=0;
    int dump_table =0;
    double effective_rate=0.0;
    char channel_model_input[10];
    uint8_t max_turbo_iterations=4;
    int nb_rb_set = 0;
    int sf;
  /***************************************************************************/

  logInit();

  while ((c = getopt (argc, argv, "hapZbm:n:Y:X:x:s:w:e:q:d:D:O:c:r:i:f:y:c:oA:C:R:g:N:l:S:T:QB:PI:L")) != -1) {
    switch (c) {
    case 'a':
      channel_model = AWGN;
      chMod = 1;
      break;

    case 'b':
      bundling_flag = 0;
      break;

    case 'd':
      delay = atoi(optarg);
      break;

    case 'D':
      maxDoppler = atoi(optarg);
      break;

    case 'm':
      mcs = atoi(optarg);
      break;

    case 'n':
      n_frames = atoi(optarg);
      break;

    case 'Y':
      n_ch_rlz = atoi(optarg);
      break;

    case 'X':
      abstx= atoi(optarg);
      break;

    case 'g':
      sprintf(channel_model_input,optarg,10);

      switch((char)*optarg) {
      case 'A':
        channel_model=SCM_A;
        chMod = 2;
        break;

      case 'B':
        channel_model=SCM_B;
        chMod = 3;
        break;

      case 'C':
        channel_model=SCM_C;
        chMod = 4;
        break;

      case 'D':
        channel_model=SCM_D;
        chMod = 5;
        break;

      case 'E':
        channel_model=EPA;
        chMod = 6;
        break;

      case 'F':
        channel_model=EVA;
        chMod = 7;
        break;

      case 'G':
        channel_model=ETU;
        chMod = 8;
        break;

      case 'H':
        channel_model=Rayleigh8;
        chMod = 9;
        break;

      case 'I':
        channel_model=Rayleigh1;
        chMod = 10;
        break;

      case 'J':
        channel_model=Rayleigh1_corr;
        chMod = 11;
        break;

      case 'K':
        channel_model=Rayleigh1_anticorr;
        chMod = 12;
        break;

      case 'L':
        channel_model=Rice8;
        chMod = 13;
        break;

      case 'M':
        channel_model=Rice1;
        chMod = 14;
        break;

      case 'N':
        channel_model=AWGN;
        chMod = 1;
        break;

      default:
        msg("Unsupported channel model!\n");
        exit(-1);
        break;
      }

      break;

    case 's':
      snr0 = atof(optarg);
      break;

    case 'w':
      snr_int = atof(optarg);
      break;

    case 'e':
      input_snr_step= atof(optarg);
      break;

    case 'x':
      transmission_mode=atoi(optarg);

      if ((transmission_mode!=1) &&
          (transmission_mode!=2)) {
        msg("Unsupported transmission mode %d\n",transmission_mode);
        exit(-1);
      }

      if (transmission_mode>1) {
        n_tx = 1;
      }

      break;

    case 'y':
      n_rx = atoi(optarg);
      break;

    case 'S':
      subframe = atoi(optarg);
      break;

    case 'T':
      tdd_config=atoi(optarg);
      frame_type=TDD;
      break;

    case 'p':
      extended_prefix_flag=1;
      break;

    case 'r':
      nb_rb = atoi(optarg);
      nb_rb_set = 1;
      break;

    case 'f':
      first_rb = atoi(optarg);
      break;

    case 'c':
      cyclic_shift = atoi(optarg);
      break;

    case 'N':
      N0 = atoi(optarg);
      break;

    case 'o':
      srs_flag = 1;
      break;

    case 'i':
      input_fdUL = fopen(optarg,"r");
      printf("Reading in %s (%p)\n",optarg,input_fdUL);

      if (input_fdUL == (FILE*)NULL) {
        printf("Unknown file %s\n",optarg);
        exit(-1);
      }

      //      input_file=1;
      break;

    case 'A':
      beta_ACK = atoi(optarg);

      if (beta_ACK>15) {
        printf("beta_ack must be in (0..15)\n");
        exit(-1);
      }

      break;

    case 'C':
      beta_CQI = atoi(optarg);

      if ((beta_CQI>15)||(beta_CQI<2)) {
        printf("beta_cqi must be in (2..15)\n");
        exit(-1);
      }

      break;

    case 'R':
      beta_RI = atoi(optarg);

      if ((beta_RI>15)||(beta_RI<2)) {
        printf("beta_ri must be in (0..13)\n");
        exit(-1);
      }

      break;

    case 'Q':
      cqi_flag=1;
      break;

    case 'B':
      N_RB_DL=atoi(optarg);
      break;

    case 'P':
      dump_perf=1;
      opp_enabled=1;
      break;

    case 'O':
      test_perf=atoi(optarg);
      //print_perf =1;
      break;

    case 'L':
      llr8_flag=1;
      break;

    case 'I':
      max_turbo_iterations=atoi(optarg);
      break;

    case 'Z':
      dump_table = 1;
      break;

    case 'h':
    default:
      printf("%s -h(elp) -a(wgn on) -m mcs -n n_frames -s snr0 -t delay_spread -p (extended prefix on) -r nb_rb -f first_rb -c cyclic_shift -o (srs on) -g channel_model [A:M] Use 3GPP 25.814 SCM-A/B/C/D('A','B','C','D') or 36-101 EPA('E'), EVA ('F'),ETU('G') models (ignores delay spread and Ricean factor), Rayghleigh8 ('H'), Rayleigh1('I'), Rayleigh1_corr('J'), Rayleigh1_anticorr ('K'), Rice8('L'), Rice1('M'), -d Channel delay, -D maximum Doppler shift \n",
             argv[0]);
      exit(1);
      break;
    }
  }

  lte_param_init(1,n_rx,1,extended_prefix_flag,N_RB_DL,frame_type,tdd_config,osf, num_bss);

  int loop = 0;

  for (loop = 0; loop < num_bss; loop++){




                  if (nb_rb_set == 0){
                    nb_rb = PHY_vars_eNB[loop]->lte_frame_parms.N_RB_UL;
                    }


                  // frame_parms = &PHY_vars_eNB[loop]->lte_frame_parms;
                  txdata = PHY_vars_UE[loop]->lte_ue_common_vars.txdata;

                  nsymb = (PHY_vars_eNB[loop]->lte_frame_parms.Ncp == 0) ? 14 : 12;
                  coded_bits_per_codeword = nb_rb * (12 * get_Qm(mcs)) * nsymb;
                  rate = (double)2*dlsch_tbs25[get_I_TBS(mcs)][25-1]/(coded_bits_per_codeword);

                  PHY_vars_UE[loop]->lte_ue_pdcch_vars[0]->crnti = 14;

                  PHY_vars_UE[loop]->lte_frame_parms.soundingrs_ul_config_common.srs_BandwidthConfig = 2;
                  PHY_vars_UE[loop]->lte_frame_parms.soundingrs_ul_config_common.srs_SubframeConfig = 7;
                  PHY_vars_UE[loop]->soundingrs_ul_config_dedicated[eNB_id].srs_Bandwidth = 0;
                  PHY_vars_UE[loop]->soundingrs_ul_config_dedicated[eNB_id].transmissionComb = 0;
                  PHY_vars_UE[loop]->soundingrs_ul_config_dedicated[eNB_id].freqDomainPosition = 0;

                  PHY_vars_eNB[loop]->lte_frame_parms.soundingrs_ul_config_common.srs_BandwidthConfig = 2;
                  PHY_vars_eNB[loop]->lte_frame_parms.soundingrs_ul_config_common.srs_SubframeConfig = 7;

                  PHY_vars_eNB[loop]->soundingrs_ul_config_dedicated[UE_id].srs_ConfigIndex = 1;
                  PHY_vars_eNB[loop]->soundingrs_ul_config_dedicated[UE_id].srs_Bandwidth = 0;
                  PHY_vars_eNB[loop]->soundingrs_ul_config_dedicated[UE_id].transmissionComb = 0;
                  PHY_vars_eNB[loop]->soundingrs_ul_config_dedicated[UE_id].freqDomainPosition = 0;
                  PHY_vars_eNB[loop]->cooperation_flag = cooperation_flag;
                  //  PHY_vars_eNB[loop]->eNB_UE_stats[0].SRS_parameters = PHY_vars_UE[loop]->SRS_parameters;

                  PHY_vars_eNB[loop]->pusch_config_dedicated[UE_id].betaOffset_ACK_Index = beta_ACK;
                  PHY_vars_eNB[loop]->pusch_config_dedicated[UE_id].betaOffset_RI_Index  = beta_RI;
                  PHY_vars_eNB[loop]->pusch_config_dedicated[UE_id].betaOffset_CQI_Index = beta_CQI;
                  PHY_vars_UE[loop]->pusch_config_dedicated[eNB_id].betaOffset_ACK_Index = beta_ACK;
                  PHY_vars_UE[loop]->pusch_config_dedicated[eNB_id].betaOffset_RI_Index  = beta_RI;
                  PHY_vars_UE[loop]->pusch_config_dedicated[eNB_id].betaOffset_CQI_Index = beta_CQI;

                  PHY_vars_UE[loop]->ul_power_control_dedicated[eNB_id].deltaMCS_Enabled = 1;


                  UE2eNB = new_channel_desc_scm(PHY_vars_eNB[loop]->lte_frame_parms.nb_antennas_tx,
                                                PHY_vars_UE[loop]->lte_frame_parms.nb_antennas_rx,
                                                channel_model,
                                                BW,
                                                forgetting_factor,
                                                delay,
                                                0);
                  // set Doppler
                  UE2eNB->max_Doppler = maxDoppler;

                  // NN: N_RB_UL has to be defined in ulsim
                  PHY_vars_eNB[loop]->ulsch_eNB[0] = new_eNB_ulsch(8,max_turbo_iterations,N_RB_DL,0);
                  PHY_vars_UE[loop]->ulsch_ue[0]   = new_ue_ulsch(8,N_RB_DL,0);

                  // Create transport channel structures for 2 transport blocks (MIMO)
                  for (i=0; i<2; i++) {
                    PHY_vars_eNB[loop]->dlsch_eNB[0][i] = new_eNB_dlsch(1,8,N_RB_DL,0);
                    PHY_vars_UE[loop]->dlsch_ue[0][i]  = new_ue_dlsch(1,8,MAX_TURBO_ITERATIONS,N_RB_DL,0);

                    if (!PHY_vars_eNB[loop]->dlsch_eNB[0][i]) {
                      printf("Can't get eNB dlsch structures\n");
                      exit(-1);
                    }

                    if (!PHY_vars_UE[loop]->dlsch_ue[0][i]) {
                      printf("Can't get ue dlsch structures\n");
                      exit(-1);
                    }

                    PHY_vars_eNB[loop]->dlsch_eNB[0][i]->rnti = 14;
                    PHY_vars_UE[loop]->dlsch_ue[0][i]->rnti   = 14;

                  }


                  switch (PHY_vars_eNB[loop]->lte_frame_parms.N_RB_UL) {
                  case 6:
                    break;

                  case 50:
                    if (PHY_vars_eNB[loop]->lte_frame_parms.frame_type == TDD) {
                      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->type    = 0;
                      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->rballoc = computeRIV(PHY_vars_eNB[loop]->lte_frame_parms.N_RB_UL,first_rb,nb_rb);// 12 RBs from position 8
                      printf("nb_rb %d/%d, rballoc %d (dci %x)\n",nb_rb,PHY_vars_eNB[loop]->lte_frame_parms.N_RB_UL,((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->rballoc,*(uint32_t *)&UL_alloc_pdu);
                      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->mcs     = mcs;
                      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->ndi     = 1;
                      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->TPC     = 0;
                      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->cqi_req = cqi_flag&1;
                      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->cshift  = 0;
                      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu)->dai     = 1;
                    } else {
                      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu)->type    = 0;
                      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu)->rballoc = computeRIV(PHY_vars_eNB[loop]->lte_frame_parms.N_RB_UL,first_rb,nb_rb);// 12 RBs from position 8
                      printf("nb_rb %d/%d, rballoc %d (dci %x)\n",nb_rb,PHY_vars_eNB[loop]->lte_frame_parms.N_RB_UL,((DCI0_10MHz_FDD_t*)&UL_alloc_pdu)->rballoc,*(uint32_t *)&UL_alloc_pdu);
                      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu)->mcs     = mcs;
                      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu)->ndi     = 1;
                      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu)->TPC     = 0;
                      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu)->cqi_req = cqi_flag&1;
                      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu)->cshift  = 0;
                    }

                    break;


                  default:
                    break;
                  }


                  PHY_vars_UE[loop]->PHY_measurements.rank[0] = 0;
                  PHY_vars_UE[loop]->transmission_mode[0] = 2;
                  PHY_vars_UE[loop]->pucch_config_dedicated[0].tdd_AckNackFeedbackMode = bundling_flag == 1 ? bundling : multiplexing;
                  PHY_vars_eNB[loop]->transmission_mode[0] = 2;
                  PHY_vars_eNB[loop]->pucch_config_dedicated[0].tdd_AckNackFeedbackMode = bundling_flag == 1 ? bundling : multiplexing;
                  PHY_vars_UE[loop]->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1;
                  PHY_vars_eNB[loop]->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1;
                  PHY_vars_UE[loop]->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0;
                  PHY_vars_eNB[loop]->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0;
                  PHY_vars_UE[loop]->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
                  PHY_vars_eNB[loop]->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
                  PHY_vars_UE[loop]->frame_tx=1;

                  for (sf=0; sf<10; sf++) {
                    PHY_vars_eNB[loop]->proc[sf].frame_tx=1;
                    PHY_vars_eNB[loop]->proc[sf].subframe_tx=sf;
                    PHY_vars_eNB[loop]->proc[sf].frame_rx=1;
                    PHY_vars_eNB[loop]->proc[sf].subframe_rx=sf;
                  }

                  msg("Init UL hopping UE\n");
                  init_ul_hopping(&PHY_vars_UE[loop]->lte_frame_parms);
                  msg("Init UL hopping eNB\n");
                  init_ul_hopping(&PHY_vars_eNB[loop]->lte_frame_parms);

                  PHY_vars_eNB[loop]->proc[subframe].frame_rx = PHY_vars_UE[loop]->frame_tx;

                  if (ul_subframe2pdcch_alloc_subframe(&PHY_vars_eNB[loop]->lte_frame_parms,subframe) > subframe) // allocation was in previous frame
                    PHY_vars_eNB[loop]->proc[ul_subframe2pdcch_alloc_subframe(&PHY_vars_eNB[loop]->lte_frame_parms,subframe)].frame_tx = (PHY_vars_UE[loop]->frame_tx-1)&1023;

                  PHY_vars_UE[loop]->dlsch_ue[0][0]->harq_ack[ul_subframe2pdcch_alloc_subframe(&PHY_vars_eNB[loop]->lte_frame_parms,subframe)].send_harq_status = 1;

                  PHY_vars_UE[loop]->frame_tx = (PHY_vars_UE[loop]->frame_tx-1)&1023;
                  printf("**********************here=1**************************\n");
                  generate_ue_ulsch_params_from_dci((void *)&UL_alloc_pdu,
                                                    14,
                                                    ul_subframe2pdcch_alloc_subframe(&PHY_vars_UE[loop]->lte_frame_parms,subframe),
                                                    format0,
                                                    PHY_vars_UE[loop],
                                                    SI_RNTI,
                                                    0,
                                                    P_RNTI,
                                                    CBA_RNTI,
                                                    0,
                                                    srs_flag);

                 if (PHY_vars_eNB[loop]->ulsch_eNB[0] != NULL)
                  generate_eNB_ulsch_params_from_dci((void *)&UL_alloc_pdu,
                                                     14,
                                                     ul_subframe2pdcch_alloc_subframe(&PHY_vars_eNB[loop]->lte_frame_parms,subframe),
                                                     format0,
                                                     0,
                                                     PHY_vars_eNB[loop],
                                                     SI_RNTI,
                                                     0,
                                                     P_RNTI,
                                                     CBA_RNTI,
                                                     srs_flag);

                  PHY_vars_UE[loop]->frame_tx = (PHY_vars_UE[loop]->frame_tx+1)&1023;
                  printf("**********************here=2**************************\n");

                    int round = 0;

                    harq_pid = subframe2harq_pid(&PHY_vars_UE[loop]->lte_frame_parms,PHY_vars_UE[loop]->frame_tx,subframe);
                    // fflush(stdout);

                    PHY_vars_eNB[loop]->ulsch_eNB[0]->harq_processes[harq_pid]->round=round;
                    PHY_vars_UE[loop]->ulsch_ue[0]->harq_processes[harq_pid]->round=round;
                    PHY_vars_eNB[loop]->ulsch_eNB[0]->harq_processes[harq_pid]->rvidx = round>>1;
                    PHY_vars_UE[loop]->ulsch_ue[0]->harq_processes[harq_pid]->rvidx = round>>1;


                    /////////////////////
                    int aa = 0; int ii=0;
                    for(ii=0; ii< PHY_vars_eNB[loop]->lte_frame_parms.samples_per_tti; ii++){

                        for (aa=0; aa < n_rx; aa++){

                        ((short*) &PHY_vars_eNB[loop]->lte_eNB_common_vars.rxdata[0][aa][PHY_vars_eNB[loop]->lte_frame_parms.samples_per_tti*subframe])[2*ii] = iqr[ii];
                        ((short*) &PHY_vars_eNB[loop]->lte_eNB_common_vars.rxdata[0][aa][PHY_vars_eNB[loop]->lte_frame_parms.samples_per_tti*subframe])[2*ii +1] = iqi[ii];
                        }
                    }

                        printf("Loaded %d IQ samples\n", PHY_vars_eNB[loop]->lte_frame_parms.samples_per_tti);

                      lte_eNB_I0_measurements(PHY_vars_eNB[loop], 0, 1);
                      PHY_vars_eNB[loop]->ulsch_eNB[0]->cyclicShift = cyclic_shift;// cyclic shift for DMRS

                      remove_7_5_kHz(PHY_vars_eNB[loop],subframe<<1);
                      remove_7_5_kHz(PHY_vars_eNB[loop],1+(subframe<<1));


        }


}
Example #7
0
int main(int argc, char *argv[]) {

  int ret,ret2;
  unsigned int errors,uerrors,errors2,crc_misses,iterations,trials,trials2,block_length,errors3,trials3;
  double SNR,sigma,rate=.5;
  unsigned char qbits,mcs;
  
  char done0=0;
  char done1=1;
  char done2=1;

  unsigned short iind;
  unsigned int coded_bits;
  unsigned char NB_RB=25;

  int num_pdcch_symbols = 3;
  int subframe = 6;

  randominit(0);
  logInit();
  lte_param_init(1,1,1,0,0,3);

  PHY_vars_eNB->dlsch_eNB[0][0] = new_eNB_dlsch(1,8,0);
  PHY_vars_UE->dlsch_ue[0][0]  = new_ue_dlsch(1,8,0);
  PHY_vars_eNB->dlsch_eNB[0][1] = new_eNB_dlsch(1,8,0);
  PHY_vars_UE->dlsch_ue[0][1]  = new_ue_dlsch(1,8,0);

  if (argc>1)
    mcs = atoi(argv[1]);
  else
    mcs = 0;

  printf("NB_RB %d\n",NB_RB);
  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;

  if (argc>2)
    qbits = atoi(argv[2]);
  else
    qbits = 4;

  printf("Quantization bits %d\n",qbits);

  generate_eNB_dlsch_params_from_dci(subframe,
                                     &DLSCH_alloc_pdu2,
				     0x1234,
				     format2_2A_M10PRB,
				     PHY_vars_eNB->dlsch_eNB[0],
				     &PHY_vars_eNB->lte_frame_parms,
				     SI_RNTI,
				     0,
				     P_RNTI,
				     0); //change this later
  generate_ue_dlsch_params_from_dci(subframe,
				    &DLSCH_alloc_pdu2,
				    C_RNTI,
				    format2_2A_M10PRB,
				    PHY_vars_UE->dlsch_ue[0],
				    &PHY_vars_UE->lte_frame_parms,
				    SI_RNTI,
				    0,
				    P_RNTI);
  
  coded_bits = 	get_G(&PHY_vars_eNB->lte_frame_parms,NB_RB,PHY_vars_eNB->dlsch_eNB[0][0]->rb_alloc,
		      get_Qm(mcs),num_pdcch_symbols,subframe);

  printf("Coded_bits (G) = %d\n",coded_bits);

  block_length =  dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1]>>3;
  printf("Block_length = %d bytes (%d bits, rate %f), mcs %d, I_TBS %d, NB_RB %d\n",block_length,
	 dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1],(double)dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1]/coded_bits,
	 mcs,get_I_TBS(mcs),NB_RB);

  // Test Openair0 3GPP encoder
/*
  test_encoder(block_length,
	       f1f2mat[(block_length-5)*2],   // f1 (see 36121-820, page 14)
	       f1f2mat[((block_length-5)*2)+1],  // f2 (see 36121-820, page 14)
	       3);
 */ //  exit(0);



  for (SNR=-6;SNR<16;SNR+=.5) {


    //    printf("\n\nSNR %f dB\n",SNR);

    sigma = pow(10.0,-.05*SNR);

    errors=0;
    crc_misses=0;
    errors2=0;
    errors3=0;

    iterations=0;

    if (done0 == 0) {    
    

    
    ret = test_logmap8(PHY_vars_eNB->dlsch_eNB[0][0],
		       PHY_vars_UE->dlsch_ue[0][0],
		       coded_bits,
		       NB_RB,
		       sigma,   // noise standard deviation
		       qbits,
		       block_length,   // block length bytes
		       NTRIALS,
		       &errors,
		       &trials,
		       &uerrors,
		       &crc_misses,
		       &iterations,
		       num_pdcch_symbols,
		       subframe);

    if (ret>=0)
      //      printf("ref: Errors %d (%f), Uerrors %d (%f), CRC Misses %d (%f), Avg iterations %f\n",errors,(double)errors/trials,uerrors,(double)uerrors/trials,crc_misses,(double)crc_misses/trials,(double)iterations/trials);
      printf("%f,%f,%f,%f\n",SNR,(double)errors/trials,(double)crc_misses/trials,(double)iterations/trials);
    if (((double)errors/trials) < 1e-2)
      done0=1;
    } 
    /*    
    if (done1 == 0) { 

      printf("exmimo\n");
      ret = test_logmapexmimo(rate,    // code rate
			      sigma,   // noise standard deviation
			      qbits,
			      block_length,   // block length bytes
			      f1f2mat[iind*2],   // f1 (see 36121-820, page 14)
			      f1f2mat[(iind*2)+1],  // f2 (see 36121-820, page 14)
			      3,
			      NTRIALS,
			      &errors3,
			      &trials3);

      if (ret>=0)
	printf("exmimo : Errors %d (%f)\n",errors3,(double)errors3/trials3);
      if (((double)errors3/trials3) < 1e-3)
	done1=1;
    }
    

    if (done2 == 0) {  
    
      printf("Viterbi ...\n");
      ret2 = test_viterbi(sigma,
			  8*block_length,
			  NTRIALS,
			  &errors2,
			  &trials2,
			  rate);
      
      if (ret2>=0)
	printf("viterbi : Errors %d (%f)\n",errors2,(double)errors2/trials2);
      if (((double)errors2/trials2) < 1e-3)
	done2=1;
    } 
    */
    if ((done0==1) && (done1==1) && (done2==1)) {
      printf("done\n");
      break;
    }
  }
  return(0);
}
Example #8
0
File: dlsim.c Project: a4a881d4/oai
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]);
  }
void mexFunction( int mlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[]
                )
{
    
    /* Declare */
	short *dlsch_llr;
	unsigned char mcs;	
	unsigned int *ret;
	unsigned char mod_order;
	unsigned char num_pdcch_symbols;
	unsigned char harq_pid;
	unsigned char subframe;
	unsigned char Kmimo;
	unsigned char Mdlharq;
	unsigned char abstraction_flag;
	LTE_UE_DLSCH_t* dlsch;
	LTE_DL_FRAME_PARMS *frame_parms;
	PHY_VARS_UE *phy_vars_ue;   
	extern int *pi2tab16[188],*pi5tab16[188],*pi4tab16[188],*pi6tab16[188];
	unsigned long *ptr_td; //Specific Modification for 64bit
    int *tmp[1];
    
	/* Allocate input */
	dlsch_llr = (short*) mxGetData(prhs[0]);
	
	/* Create new dlsch */
	Kmimo = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"Kmimo"));
	Mdlharq = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"Mdlharq"));
	abstraction_flag = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"abstraction_flag"));
	mcs = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"mcs"));
	
    #ifdef DEBUG_DLSCH_DECODING
    mexPrintf("Kmimo %d\n",Kmimo);
    mexPrintf("Mdlharq %d\n",Mdlharq);
    mexPrintf("abstraction_flag %d\n",abstraction_flag);
    mexPrintf("mcs %d\n",mcs);
    #endif
    
	/* Create new dlsch */
	dlsch = new_ue_dlsch(Kmimo,Mdlharq,8,25,abstraction_flag);
    
    // Init CRC tables
  	crcTableInit();	
// 	init_td();    
 	    
    // copy the pointers to memory allocated in dlsch_decoding_init
    ptr_td = (unsigned int*) mxGetData(mxGetField(prhs[1],0,"ptr_td"));
    #ifdef DEBUG_DLSCH_DECODING
    mexPrintf("ptr_td0 %p\n",ptr_td[0]);
    mexPrintf("ptr_td1 %p\n",ptr_td[1]);
    mexPrintf("ptr_td2 %p\n",ptr_td[2]);
    mexPrintf("ptr_td3 %p\n",ptr_td[3]);
    #endif
    
    memcpy(&tmp[0], &ptr_td[0], sizeof(ptr_td[0]));    
    memcpy(&pi2tab16[0], tmp[0], 188*sizeof(pi2tab16[0]));
    
    memcpy(&tmp[0], &ptr_td[1], sizeof(ptr_td[1]));    
    memcpy(&pi4tab16[0], tmp[0], 188*sizeof(pi4tab16[0]));
    
    memcpy(&tmp[0], &ptr_td[2], sizeof(ptr_td[2]));
    memcpy(&pi5tab16[0], tmp[0], 188*sizeof(pi5tab16[0]));
    
    memcpy(&tmp[0], &ptr_td[3], sizeof(ptr_td[3]));
    memcpy(&pi6tab16[0], tmp[0], 188*sizeof(pi6tab16[0]));  
    
	harq_pid = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"harq_pid"));
	dlsch->current_harq_pid = harq_pid;
	dlsch->harq_processes[harq_pid]->rvidx = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"rvidx"));
	dlsch->harq_processes[harq_pid]->Nl = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"Nl"));
	//dlsch->harq_processes[harq_pid]->Ndi = (unsigned char) mxGetScalar(mxGetField(prhs[2],0,"Ndi"));
	dlsch->harq_processes[harq_pid]->mcs = mcs;
	dlsch->harq_processes[harq_pid]->rb_alloc[0] = (unsigned int) mxGetScalar(mxGetField(prhs[1],0,"rb_alloc"));
	dlsch->harq_processes[harq_pid]->nb_rb = (unsigned short) mxGetScalar(mxGetField(prhs[1],0,"nb_rb"));
				
	dlsch->harq_processes[harq_pid]->TBS = dlsch_tbs25[get_I_TBS(mcs)][dlsch->harq_processes[harq_pid]->nb_rb-1];
				
	
	num_pdcch_symbols = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"num_pdcch_symbols"));
	subframe = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"subframe"));
	
	phy_vars_ue = calloc(1,sizeof(PHY_VARS_UE));	
	
	// Create a LTE_DL_FRAME_PARMS structure and assign required params
	frame_parms = calloc(1,sizeof(LTE_DL_FRAME_PARMS));	
	frame_parms->N_RB_DL = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"nb_rb"));
	frame_parms->frame_type = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"frame_type"));
	frame_parms->mode1_flag = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"mode1_flag"));
	frame_parms->Ncp = (unsigned char) mxGetScalar(mxGetField(prhs[1],0,"Ncp"));
	
    
 	mod_order = get_Qm(dlsch->harq_processes[harq_pid]->mcs);
	dlsch->harq_processes[harq_pid]->G = get_G(frame_parms,dlsch->harq_processes[harq_pid]->nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,0,subframe);

    #ifdef DEBUG_DLSCH_DECODING
    mexPrintf("TBS %d\n",dlsch->harq_processes[harq_pid]->TBS);
    mexPrintf("nb_rb %d\n",dlsch->harq_processes[harq_pid]->nb_rb);
    mexPrintf("ncs %d\n",dlsch->harq_processes[harq_pid]->mcs);
    mexPrintf("num_pdcch_symbols %d\n",num_pdcch_symbols);
    mexPrintf("subframe %d\n",subframe);
    mexPrintf("G %d\n",dlsch->harq_processes[harq_pid]->G);
    #endif

	if (dlsch->harq_processes[harq_pid]->G != mxGetM(prhs[0])) {
		free_ue_dlsch(dlsch);
		free(frame_parms);
        free(phy_vars_ue);
		mexErrMsgTxt("Length of the LLR vector is incorrect.");		
	}
	
	/* Allocate Output */	
	plhs[0] = mxCreateNumericMatrix(1, 1, mxUINT32_CLASS, mxREAL);
	ret = (unsigned int*) mxGetPr(plhs[0]);         	
	
    /* Algo */	
	*ret = dlsch_decoding(phy_vars_ue, dlsch_llr, frame_parms, dlsch, dlsch->harq_processes[harq_pid], subframe, dlsch->current_harq_pid, 1,0);
					
	/* free dlsch */
	free_ue_dlsch(dlsch);
	free(frame_parms);
	free(phy_vars_ue);
//     free_td();    
}