Exemplo n.º 1
0
int main(int argc, char **argv) {
  uint32_t cfi;
  float cfi_corr; 
  int n;

  if (argc < 3) {
    usage(argv[0]);
    exit(-1);
  }

  parse_args(argc,argv);

  if (base_init()) {
    fprintf(stderr, "Error initializing receiver\n");
    exit(-1);
  }

  n = filesource_read(&fsrc, input_buffer, flen);

  lte_fft_run_sf(&fft, input_buffer, fft_buffer);

  if (fmatlab) {
    fprintf(fmatlab, "infft=");
    vec_fprint_c(fmatlab, input_buffer, flen);
    fprintf(fmatlab, ";\n");

    fprintf(fmatlab, "outfft=");
    vec_sc_prod_cfc(fft_buffer, 1000.0, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
    vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
    fprintf(fmatlab, ";\n");
    vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer,   CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
  }

  /* Get channel estimates for each port */
  chest_dl_estimate(&chest, fft_buffer, ce, 0);

  INFO("Decoding PCFICH\n", 0);

  
  n = pcfich_decode(&pcfich, fft_buffer, ce, chest_dl_get_noise_estimate(&chest),  0, &cfi, &cfi_corr);
  printf("cfi: %d, distance: %f\n", cfi, cfi_corr);

  base_free();

  if (n < 0) {
    fprintf(stderr, "Error decoding PCFICH\n");
    exit(-1);
  } else if (n == 0) {
    printf("Could not decode PCFICH\n");
    exit(-1);
  } else {
    if (cfi_corr > 2.8 && cfi == 1) {
      exit(0);
    } else {
      exit(-1);
    }
  }
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
  pbch_mib_t mib;
  int n;

  if (argc < 3) {
    usage(argv[0]);
    exit(-1);
  }

  parse_args(argc,argv);

  if (base_init()) {
    fprintf(stderr, "Error initializing receiver\n");
    exit(-1);
  }

  n = filesource_read(&fsrc, input_buffer, FLEN);

  lte_fft_run_sf(&fft, input_buffer, fft_buffer);

  if (fmatlab) {
    fprintf(fmatlab, "outfft=");
    vec_sc_prod_cfc(fft_buffer, 1000.0, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
    vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
    fprintf(fmatlab, ";\n");
    vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer,   CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
  }

  /* Get channel estimates for each port */
  chest_ce_sf(&chest, fft_buffer, ce, 0);

  INFO("Decoding PBCH\n", 0);

  n = pbch_decode(&pbch, fft_buffer, ce, &mib);

  base_free();

  if (n < 0) {
    fprintf(stderr, "Error decoding PBCH\n");
    exit(-1);
  } else if (n == 0) {
    printf("Could not decode PBCH\n");
    exit(-1);
  } else {
    if (mib.nof_ports == 2 && mib.nof_prb == 50 && mib.phich_length == PHICH_NORM
        && mib.phich_resources == R_1 && mib.sfn == 28) {
      pbch_mib_fprint(stdout, &mib, cell.id);
      printf("This is the signal.1.92M.dat file\n");
      exit(0);
    } else {
      pbch_mib_fprint(stdout, &mib, cell.id);
      printf("This is an unknown file\n");
      exit(-1);
    }
  }
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
  ra_pdsch_t ra_dl;
  int i;
  int frame_cnt;
  int ret;
  dci_location_t locations[MAX_CANDIDATES];
  uint32_t nof_locations;
  dci_msg_t dci_msg; 

  if (argc < 3) {
    usage(argv[0]);
    exit(-1);
  }

  parse_args(argc,argv);

  if (base_init()) {
    fprintf(stderr, "Error initializing memory\n");
    exit(-1);
  }

  ret = -1;
  frame_cnt = 0;
  do {
    filesource_read(&fsrc, input_buffer, flen);

    INFO("Reading %d samples sub-frame %d\n", flen, frame_cnt);

    lte_fft_run_sf(&fft, input_buffer, fft_buffer);

    /* Get channel estimates for each port */
    chest_dl_estimate(&chest, fft_buffer, ce, frame_cnt %10);
    
    uint16_t crc_rem = 0;
    if (pdcch_extract_llr(&pdcch, fft_buffer, 
                          ce, chest_dl_get_noise_estimate(&chest), 
                          frame_cnt %10, cfi)) {
      fprintf(stderr, "Error extracting LLRs\n");
      return -1;
    }
    if (rnti == SIRNTI) {
      INFO("Initializing common search space for SI-RNTI\n",0);
      nof_locations = pdcch_common_locations(&pdcch, locations, MAX_CANDIDATES, cfi);
    } else {
      INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti);
      nof_locations = pdcch_ue_locations(&pdcch, locations, MAX_CANDIDATES, frame_cnt %10, cfi, rnti); 
    }

    for (i=0;i<nof_locations && crc_rem != rnti;i++) {
      if (pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], dci_format, &crc_rem)) {
        fprintf(stderr, "Error decoding DCI msg\n");
        return -1;
      }
    }
    
    if (crc_rem == rnti) {
      dci_msg_type_t type;
      if (dci_msg_get_type(&dci_msg, &type, cell.nof_prb, rnti, 1234)) {
        fprintf(stderr, "Can't get DCI message type\n");
        exit(-1);
      }
      printf("MSG %d: ",i);
      dci_msg_type_fprint(stdout, type);
      switch(type.type) {
      case PDSCH_SCHED:
        bzero(&ra_dl, sizeof(ra_pdsch_t));
        if (dci_msg_unpack_pdsch(&dci_msg, &ra_dl, cell.nof_prb, rnti != SIRNTI)) {
          fprintf(stderr, "Can't unpack PDSCH message\n");
        } else {
          ra_pdsch_fprint(stdout, &ra_dl, cell.nof_prb);
          if (ra_dl.alloc_type == alloc_type2 && ra_dl.type2_alloc.mode == t2_loc
              && ra_dl.type2_alloc.riv == 11 && ra_dl.rv_idx == 0
              && ra_dl.harq_process == 0 && ra_dl.mcs_idx == 2) {
            printf("This is the file signal.1.92M.amar.dat\n");
            ret = 0;
          }
        }
        break;
      default:
        fprintf(stderr, "Unsupported message type\n");
        break;
      }

    }

    frame_cnt++;
  } while (frame_cnt <= max_frames);

  base_free();
  exit(ret);
}
Exemplo n.º 4
0
int main(int argc, char **argv) {
  ra_pdsch_t ra_dl;
  int i;
  int nof_frames;
  int ret;
  char *data;
  dci_location_t locations[10];
  uint32_t nof_locations;
  dci_msg_t dci_msg; 
  
  data = malloc(10000);

  if (argc < 3) {
    usage(argv[0]);
    exit(-1);
  }

  parse_args(argc,argv);

  if (base_init()) {
    fprintf(stderr, "Error initializing memory\n");
    exit(-1);
  }

  if (rnti == SIRNTI) {
    INFO("Initializing common search space for SI-RNTI\n",0);
    nof_locations = pdcch_common_locations(&pdcch, locations, 10, cfi);
  } else {
    // For ue-specific, generate locations for subframe 5
    INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti);
    nof_locations = pdcch_ue_locations(&pdcch, locations, 10, 5, cfi, rnti); 
  }
  
  ret = -1;
  nof_frames = 0;
  do {
    filesource_read(&fsrc, input_buffer, flen);
    if (nof_frames == 5) {
      INFO("Reading %d samples sub-frame %d\n", flen, nof_frames);

      lte_fft_run_sf(&fft, input_buffer, fft_buffer);

      if (fmatlab) {
        fprintf(fmatlab, "infft%d=", nof_frames);
        vec_fprint_c(fmatlab, input_buffer, flen);
        fprintf(fmatlab, ";\n");

        fprintf(fmatlab, "outfft%d=", nof_frames);
        vec_sc_prod_cfc(fft_buffer, 1000.0, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
        vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
        fprintf(fmatlab, ";\n");
        vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer,  CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
      }

      /* Get channel estimates for each port */
      for (i=0;i<cell.nof_ports;i++) {
        chest_ce_slot_port(&chest, fft_buffer, ce[i], 2*nof_frames, i);
        chest_ce_slot_port(&chest, &fft_buffer[CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB],
            &ce[i][CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB], 2*nof_frames+1, i);
        if (fmatlab) {
          chest_fprint(&chest, fmatlab, 2*nof_frames+1, i);
        }
      }
      
      
      uint16_t crc_rem = 0;
      for (i=0;i<nof_locations && crc_rem != rnti;i++) {
        if (pdcch_extract_llr(&pdcch, fft_buffer, ce, locations[i], nof_frames, cfi)) {
          fprintf(stderr, "Error extracting LLRs\n");
          return -1;
        }
        if (pdcch_decode_msg(&pdcch, &dci_msg, Format1A, &crc_rem)) {
          fprintf(stderr, "Error decoding DCI msg\n");
          return -1;
        }
      }
      
      if (crc_rem == rnti) {
        if (dci_msg_to_ra_dl(&dci_msg, rnti, 1234, cell, cfi, &ra_dl)) {
          fprintf(stderr, "Error unpacking PDSCH scheduling DCI message\n");
          goto goout;
        }
        if (pdsch_harq_setup(&harq_process, ra_dl.mcs, &ra_dl.prb_alloc)) {
          fprintf(stderr, "Error configuring HARQ process\n");
          goto goout;
        }
        if (pdsch_decode(&pdsch, fft_buffer, ce, data, nof_frames%10, &harq_process, ra_dl.rv_idx)) {
          fprintf(stderr, "Error decoding PDSCH\n");
          goto goout;
        } else {
          printf("PDSCH Decoded OK!\n");
        }
      }
    }

    nof_frames++;
  } while (nof_frames <= max_frames);

  ret = 0;

goout:
  base_free();
  exit(ret);
}
Exemplo n.º 5
0
/* the gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  int i; 
  lte_cell_t cell; 
  pcfich_t pcfich;
  chest_dl_t chest; 
  lte_fft_t fft; 
  regs_t regs;
  uint32_t sf_idx; 
  cf_t *input_fft, *input_signal;
  
  if (nrhs != NOF_INPUTS) {
    help();
    return;
  }
    
  if (mexutils_read_cell(ENBCFG, &cell)) {
    help();
    return;
  }
  
  if (mexutils_read_uint32_struct(ENBCFG, "NSubframe", &sf_idx)) {
    help();
    return;
  }

  if (chest_dl_init(&chest, cell)) {
    mexErrMsgTxt("Error initializing equalizer\n");
    return;
  }

  if (lte_fft_init(&fft, cell.cp, cell.nof_prb)) {
    mexErrMsgTxt("Error initializing FFT\n");
    return;
  }
  
  if (regs_init(&regs, cell)) {
    mexErrMsgTxt("Error initiating regs\n");
    return;
  }
  
  if (pcfich_init(&pcfich, &regs, cell)) {
    mexErrMsgTxt("Error creating PBCH object\n");
    return;
  }
      
  /** Allocate input buffers */
  if (mexutils_read_cf(INPUT, &input_signal) < 0) {
    mexErrMsgTxt("Error reading input signal\n");
    return; 
  }
  input_fft = vec_malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
  
  // Set Channel estimates to 1.0 (ignore fading) 
  cf_t *ce[MAX_PORTS];
  for (i=0;i<cell.nof_ports;i++) {
    ce[i] = vec_malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
  }
  
  lte_fft_run_sf(&fft, input_signal, input_fft);

  if (nrhs > NOF_INPUTS) {
    cf_t *cearray; 
    mexutils_read_cf(prhs[NOF_INPUTS], &cearray);
    for (i=0;i<cell.nof_ports;i++) {
      for (int j=0;j<SF_LEN_RE(cell.nof_prb, cell.cp);j++) {
        ce[i][j] = *cearray;
        cearray++;
      }
    }
  } else {
    chest_dl_estimate(&chest, input_fft, ce, sf_idx);    
  }
  float noise_power;
  if (nrhs > NOF_INPUTS + 1) {
    noise_power = mxGetScalar(prhs[NOF_INPUTS+1]);
  } else {
    noise_power = chest_dl_get_noise_estimate(&chest);
  }
    
    
  uint32_t cfi;
  float corr_res; 
  int n = pcfich_decode(&pcfich, input_fft, ce, noise_power,  sf_idx, &cfi, &corr_res);

  if (nlhs >= 1) { 
    if (n < 0) {      
      plhs[0] = mxCreateDoubleScalar(-1);
    } else {
      plhs[0] = mxCreateDoubleScalar(cfi);      
    }
  }
  if (nlhs >= 2) {
    mexutils_write_cf(pcfich.pcfich_d, &plhs[1], 16, 1);  
  }
  if (nlhs >= 3) {
    mexutils_write_cf(pcfich.pcfich_symbols[0], &plhs[2], 16, 1);  
  }
  
  chest_dl_free(&chest);
  lte_fft_free(&fft);
  pcfich_free(&pcfich);
  regs_free(&regs);
  
  for (i=0;i<cell.nof_ports;i++) {
    free(ce[i]);
  }
  free(input_signal);
  free(input_fft);
  
  return;
}