Esempio n. 1
0
int sync_init(sync_t *q, uint32_t frame_size, uint32_t fft_size) {

  int ret = LIBLTE_ERROR_INVALID_INPUTS; 
  
  if (q                 != NULL         &&
      frame_size        <= 307200       &&
      fft_size_isvalid(fft_size))
  {
    ret = LIBLTE_ERROR; 
    
    bzero(q, sizeof(sync_t));
    q->detect_cp = true;
    q->cp = CPNORM;
    q->mean_peak_value = 0.0;
    q->sss_en = true;
    q->correct_cfo = true; 
    q->mean_cfo = 0; 
    q->N_id_2 = 1000; 
    q->N_id_1 = 1000;
    q->fft_size = fft_size;
    q->frame_size = frame_size;
    q->sss_alg = SSS_PARTIAL_3; 
    
    if (pss_synch_init_fft(&q->pss, frame_size, fft_size)) {
      fprintf(stderr, "Error initializing PSS object\n");
      goto clean_exit;
    }
    if (sss_synch_init(&q->sss, fft_size)) {
      fprintf(stderr, "Error initializing SSS object\n");
      goto clean_exit;
    }

    if (cfo_init(&q->cfocorr, frame_size)) {
      fprintf(stderr, "Error initiating CFO\n");
      goto clean_exit;
    }

    DEBUG("SYNC init with frame_size=%d and fft_size=%d\n", frame_size, fft_size);
    
    ret = LIBLTE_SUCCESS;
  }  else {
    fprintf(stderr, "Invalid parameters frame_size: %d, fft_size: %d\n", frame_size, fft_size);
  }
  
clean_exit: 
  if (ret == LIBLTE_ERROR) {
    sync_free(q);
  }
  return ret;
}
Esempio n. 2
0
int main(int argc, char **argv) {
  cf_t *input_buffer, *sf_symbols = NULL; 
  int frame_cnt;
  ue_sync_t s; 
  int pos;
  pss_synch_t pss; 
  float peak;
  struct timeval t[3];
  float mean_ce_time=0;
  bool signal_detected; 
  lte_fft_t fft; 
  lte_cell_t cell; 
  
  bzero(&cell, sizeof(lte_cell_t));
  
  parse_args(argc, argv);
    
  #ifndef DISABLE_GRAPHICS
  if (!disable_plots) {
    init_plots();    
  }
  #endif
  
  input_init();
        
  if (ue_sync_init(&s, cuhd_set_rx_srate, cuhd_recv_wrapper, uhd)) {
    fprintf(stderr, "Error initiating UE sync module\n");
    exit(-1);
  }
  
  ue_sync_pbch_enable(&s, true);
  
  signal_detected = true;
  frame_cnt = 0;
  mean_ce_time=0;
  uint32_t valid_frames=0;
  //uint32_t unaligned = 0; 
  while (frame_cnt < nof_frames || nof_frames == -1) {    

    int n = ue_sync_get_buffer(&s, &input_buffer);
    if (n < 0) {
      fprintf(stderr, "Error calling sync work()\n");
      exit(-1);      
    }
    
    if (n == 1 && ue_sync_get_sfidx(&s) == 0) {

      if (signal_detected) {
        cell = ue_sync_get_cell(&s);
        pss_synch_init_fft(&pss, 
                          SF_LEN(lte_symbol_sz(cell.nof_prb), cell.cp), 
                          lte_symbol_sz(cell.nof_prb));
        pss_synch_set_N_id_2(&pss, cell.id%3);
        
        sf_symbols = vec_malloc(SLOT_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
        if (!sf_symbols) {
          perror("malloc");
          exit(-1);
        }
        lte_fft_init(&fft, cell.cp, cell.nof_prb);
        signal_detected = false; 
      }
      
      mean_ce_time = (float) (mean_ce_time + (float) t[0].tv_usec * valid_frames) / (valid_frames+1);
      valid_frames++;
      
      #ifndef DISABLE_GRAPHICS
      if (!disable_plots && !(valid_frames % 5) && sf_symbols) {
        
        /* Run FFT for the second slot */
        lte_fft_run_slot(&fft, input_buffer, sf_symbols);
    
        int i;
        int nof_re = SLOT_LEN_RE(cell.nof_prb, cell.cp);
        for (i = 0; i < nof_re; i++) {
          tmp_plot[i] = 10 * log10f(cabsf(sf_symbols[i]));
          if (isinf(tmp_plot[i])) {
            tmp_plot[i] = -80;
          }
        }
        plot_real_setNewData(&poutfft, tmp_plot, nof_re);        
      }
    #endif
      
      pos = pss_synch_find_pss(&pss, input_buffer, &peak, NULL);      
      /*if (pos > 962 || pos < 958) {
        unaligned++;
      }
      */
      printf("CELL_ID: %3d CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Exec: %3.2f\r",
              cell.id, ue_sync_get_cfo(&s)/1000, ue_sync_get_sfo(&s)/1000, pos, 
             s.mean_exec_time);
          fflush(stdout);
      if (VERBOSE_ISINFO()) {
        printf("\n");
      }
    }
      
    frame_cnt++;
  }

  printf("\nBye\n");
  exit(0);
}
Esempio n. 3
0
/* Initializes the PSS synchronization object with fft_size=128
 */
int pss_synch_init(pss_synch_t *q, uint32_t frame_size) {
  return pss_synch_init_fft(q, frame_size, 128);
}