int main(int argc, char **argv) { chest_t eq; cf_t *input = NULL, *ce = NULL, *h = NULL; refsignal_t refs; int i, j, n_port, n_slot, cid, num_re; int ret = -1; int max_cid; FILE *fmatlab = NULL; float mse_mag, mse_phase; parse_args(argc,argv); if (output_matlab) { fmatlab=fopen(output_matlab, "w"); if (!fmatlab) { perror("fopen"); goto do_exit; } } num_re = nof_prb * RE_X_RB * CP_NSYMB(cp); input = malloc(num_re * sizeof(cf_t)); if (!input) { perror("malloc"); goto do_exit; } h = malloc(num_re * sizeof(cf_t)); if (!h) { perror("malloc"); goto do_exit; } ce = malloc(num_re * sizeof(cf_t)); if (!ce) { perror("malloc"); goto do_exit; } if (cell_id == -1) { cid = 0; max_cid = 504; } else { cid = cell_id; max_cid = cell_id; } while(cid <= max_cid) { if (chest_init(&eq, LINEAR, cp, nof_prb, MAX_PORTS)) { fprintf(stderr, "Error initializing equalizer\n"); goto do_exit; } if (chest_ref_LTEDL(&eq, cid)) { fprintf(stderr, "Error initializing reference signal\n"); goto do_exit; } for (n_slot=0;n_slot<NSLOTS_X_FRAME;n_slot++) { for (n_port=0;n_port<MAX_PORTS;n_port++) { if (refsignal_init_LTEDL(&refs, n_port, n_slot, cid, cp, nof_prb)) { fprintf(stderr, "Error initiating CRS slot=%d\n", i); return -1; } bzero(input, sizeof(cf_t) * num_re); for (i=0;i<num_re;i++) { input[i] = 0.5-rand()/RAND_MAX+I*(0.5-rand()/RAND_MAX); } bzero(ce, sizeof(cf_t) * num_re); bzero(h, sizeof(cf_t) * num_re); refsignal_put(&refs, input); refsignal_free(&refs); for (i=0;i<CP_NSYMB(cp);i++) { for (j=0;j<nof_prb * RE_X_RB;j++) { float x = -1+(float) i/CP_NSYMB(cp) + cosf(2 * M_PI * (float) j/nof_prb/RE_X_RB); h[i*nof_prb * RE_X_RB+j] = (3+x) * cexpf(I * x); input[i*nof_prb * RE_X_RB+j] *= h[i*nof_prb * RE_X_RB+j]; } } chest_ce_slot_port(&eq, input, ce, n_slot, n_port); mse_mag = mse_phase = 0; for (i=0;i<num_re;i++) { mse_mag += (cabsf(h[i]) - cabsf(ce[i])) * (cabsf(h[i]) - cabsf(ce[i])) / num_re; mse_phase += (cargf(h[i]) - cargf(ce[i])) * (cargf(h[i]) - cargf(ce[i])) / num_re; } if (check_mse(mse_mag, mse_phase, n_port)) { goto do_exit; } if (fmatlab) { fprintf(fmatlab, "input="); vec_fprint_c(fmatlab, input, num_re); fprintf(fmatlab, ";\n"); fprintf(fmatlab, "h="); vec_fprint_c(fmatlab, h, num_re); fprintf(fmatlab, ";\n"); fprintf(fmatlab, "ce="); vec_fprint_c(fmatlab, ce, num_re); fprintf(fmatlab, ";\n"); chest_fprint(&eq, fmatlab, n_slot, n_port); } } } chest_free(&eq); cid+=10; INFO("cid=%d\n", cid); } ret = 0; do_exit: if (ce) { free(ce); } if (input) { free(input); } if (h) { free(h); } if (!ret) { printf("OK\n"); } else { printf("Error at cid=%d, slot=%d, port=%d\n",cid, n_slot, n_port); } exit(ret); }
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); }
int main(int argc, char **argv) { int distance; int i, n; int ngroup, nseq, max_nseq; char ack_rx; if (argc < 3) { usage(argv[0]); exit(-1); } parse_args(argc,argv); max_nseq = CP_ISNORM(cp)?PHICH_NORM_NSEQUENCES:PHICH_EXT_NSEQUENCES; if (base_init()) { fprintf(stderr, "Error initializing memory\n"); exit(-1); } n = filesource_read(&fsrc, input_buffer, flen); lte_fft_run(&fft, input_buffer, fft_buffer); if (fmatlab) { fprintf(fmatlab, "infft="); vec_fprint_c(fmatlab, input_buffer, flen); fprintf(fmatlab, ";\n"); fprintf(fmatlab, "outfft="); vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB); fprintf(fmatlab, ";\n"); } /* Get channel estimates for each port */ for (i=0;i<nof_ports;i++) { chest_ce_slot_port(&chest, fft_buffer, ce[i], 0, i); if (fmatlab) { chest_fprint(&chest, fmatlab, 0, i); } } INFO("Decoding PHICH\n", 0); /* Receive all PHICH groups and sequence numbers */ for (ngroup=0;ngroup<phich_ngroups(&phich);ngroup++) { for (nseq=0;nseq<max_nseq;nseq++) { if (phich_decode(&phich, fft_buffer, ce, ngroup, nseq, numsubframe, &ack_rx, &distance)<0) { printf("Error decoding ACK\n"); exit(-1); } INFO("%d/%d, ack_rx: %d, ns: %d, distance: %d\n", ngroup, nseq, ack_rx, numsubframe, distance); } } base_free(); fftwf_cleanup(); if (n < 0) { fprintf(stderr, "Error decoding phich\n"); exit(-1); } else if (n == 0) { printf("Could not decode phich\n"); exit(-1); } else { exit(0); } }