2014-03-03 11:09:26 -08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
|
|
|
* Copyright 2013-2014 The libLTE Developers. See the
|
|
|
|
* COPYRIGHT file at the top-level directory of this distribution.
|
|
|
|
*
|
|
|
|
* \section LICENSE
|
|
|
|
*
|
|
|
|
* This file is part of the libLTE library.
|
|
|
|
*
|
|
|
|
* libLTE is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* libLTE is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* A copy of the GNU Lesser General Public License can be found in
|
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-01-28 03:41:17 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2014-06-17 06:20:00 -07:00
|
|
|
#include "liblte/phy/phy.h"
|
2014-01-28 03:41:17 -08:00
|
|
|
|
|
|
|
char *input_file_name = NULL;
|
2014-03-27 09:31:25 -07:00
|
|
|
char *matlab_file_name = NULL;
|
2014-01-31 06:35:43 -08:00
|
|
|
|
2014-03-27 09:31:25 -07:00
|
|
|
FILE *fmatlab = NULL;
|
2014-01-31 06:35:43 -08:00
|
|
|
|
2014-06-29 10:51:25 -07:00
|
|
|
lte_cell_t cell = {
|
|
|
|
6, // nof_prb
|
|
|
|
2, // nof_ports
|
|
|
|
150, // cell_id
|
|
|
|
CPNORM // cyclic prefix
|
|
|
|
};
|
|
|
|
|
2014-06-17 02:11:41 -07:00
|
|
|
#define FLEN 9600
|
2014-01-28 03:41:17 -08:00
|
|
|
|
|
|
|
filesource_t fsrc;
|
2014-06-27 09:36:25 -07:00
|
|
|
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS];
|
2014-01-28 03:41:17 -08:00
|
|
|
pbch_t pbch;
|
2014-01-31 06:35:43 -08:00
|
|
|
lte_fft_t fft;
|
2014-01-28 03:41:17 -08:00
|
|
|
chest_t chest;
|
|
|
|
|
|
|
|
void usage(char *prog) {
|
2014-06-17 02:11:41 -07:00
|
|
|
printf("Usage: %s [vcoe] -i input_file\n", prog);
|
|
|
|
printf("\t-o output matlab file name [Default Disabled]\n");
|
2014-06-29 10:51:25 -07:00
|
|
|
printf("\t-c cell_id [Default %d]\n", cell.id);
|
|
|
|
printf("\t-n nof_prb [Default %d]\n", cell.nof_prb);
|
2014-06-17 02:11:41 -07:00
|
|
|
printf("\t-e Set extended prefix [Default Normal]\n");
|
|
|
|
printf("\t-v [set verbose to debug, default none]\n");
|
2014-01-28 03:41:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void parse_args(int argc, char **argv) {
|
2014-06-17 02:11:41 -07:00
|
|
|
int opt;
|
2014-06-29 10:51:25 -07:00
|
|
|
|
2014-06-17 02:11:41 -07:00
|
|
|
while ((opt = getopt(argc, argv, "iovce")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'i':
|
|
|
|
input_file_name = argv[optind];
|
|
|
|
break;
|
|
|
|
case 'c':
|
2014-06-29 10:51:25 -07:00
|
|
|
cell.id = atoi(argv[optind]);
|
2014-06-17 02:11:41 -07:00
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
matlab_file_name = argv[optind];
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
case 'e':
|
2014-06-29 10:51:25 -07:00
|
|
|
cell.cp = CPEXT;
|
2014-06-17 02:11:41 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!input_file_name) {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2014-01-28 03:41:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int base_init() {
|
2014-06-17 02:11:41 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (filesource_init(&fsrc, input_file_name, COMPLEX_FLOAT_BIN)) {
|
|
|
|
fprintf(stderr, "Error opening file %s\n", input_file_name);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matlab_file_name) {
|
|
|
|
fmatlab = fopen(matlab_file_name, "w");
|
|
|
|
if (!fmatlab) {
|
|
|
|
perror("fopen");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmatlab = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_buffer = malloc(FLEN * sizeof(cf_t));
|
|
|
|
if (!input_buffer) {
|
|
|
|
perror("malloc");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2014-08-01 14:26:28 -07:00
|
|
|
fft_buffer = malloc(SLOT_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
|
2014-06-17 02:11:41 -07:00
|
|
|
if (!fft_buffer) {
|
|
|
|
perror("malloc");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-29 15:44:39 -07:00
|
|
|
for (i=0;i<cell.nof_ports;i++) {
|
2014-08-01 14:26:28 -07:00
|
|
|
ce[i] = malloc(SLOT_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
|
2014-06-17 02:11:41 -07:00
|
|
|
if (!ce[i]) {
|
|
|
|
perror("malloc");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2014-06-29 10:51:25 -07:00
|
|
|
|
|
|
|
if (!lte_cell_isvalid(&cell)) {
|
|
|
|
fprintf(stderr, "Invalid cell properties\n");
|
2014-06-17 02:11:41 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-07-21 07:19:17 -07:00
|
|
|
if (chest_init_LTEDL(&chest, cell)) {
|
2014-06-29 10:51:25 -07:00
|
|
|
fprintf(stderr, "Error initializing equalizer\n");
|
2014-06-17 02:11:41 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-29 10:51:25 -07:00
|
|
|
if (lte_fft_init(&fft, cell.cp, cell.nof_prb)) {
|
2014-06-17 02:11:41 -07:00
|
|
|
fprintf(stderr, "Error initializing FFT\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-29 15:44:39 -07:00
|
|
|
if (pbch_init(&pbch, cell)) {
|
2014-06-17 02:11:41 -07:00
|
|
|
fprintf(stderr, "Error initiating PBCH\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG("Memory init OK\n",0);
|
|
|
|
return 0;
|
2014-01-28 03:41:17 -08:00
|
|
|
}
|
|
|
|
|
2014-03-14 18:04:21 -07:00
|
|
|
void base_free() {
|
2014-06-17 02:11:41 -07:00
|
|
|
int i;
|
2014-03-03 11:09:26 -08:00
|
|
|
|
2014-06-17 02:11:41 -07:00
|
|
|
filesource_free(&fsrc);
|
|
|
|
if (fmatlab) {
|
|
|
|
fclose(fmatlab);
|
|
|
|
}
|
2014-03-03 11:09:26 -08:00
|
|
|
|
2014-06-17 02:11:41 -07:00
|
|
|
free(input_buffer);
|
|
|
|
free(fft_buffer);
|
2014-03-03 11:09:26 -08:00
|
|
|
|
2014-06-17 02:11:41 -07:00
|
|
|
filesource_free(&fsrc);
|
2014-06-29 15:44:39 -07:00
|
|
|
for (i=0;i<cell.nof_ports;i++) {
|
2014-06-17 02:11:41 -07:00
|
|
|
free(ce[i]);
|
|
|
|
}
|
|
|
|
chest_free(&chest);
|
|
|
|
lte_fft_free(&fft);
|
2014-03-03 11:09:26 -08:00
|
|
|
|
2014-06-17 02:11:41 -07:00
|
|
|
pbch_free(&pbch);
|
2014-01-28 03:41:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2014-06-17 02:11:41 -07:00
|
|
|
pbch_mib_t mib;
|
2014-06-29 15:44:39 -07:00
|
|
|
int n;
|
2014-06-17 02:11:41 -07:00
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_args(argc,argv);
|
|
|
|
|
|
|
|
if (base_init()) {
|
2014-06-29 10:51:25 -07:00
|
|
|
fprintf(stderr, "Error initializing receiver\n");
|
2014-06-17 02:11:41 -07:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
n = filesource_read(&fsrc, input_buffer, FLEN);
|
|
|
|
|
2014-08-01 14:26:28 -07:00
|
|
|
lte_fft_run_slot(&fft, &input_buffer[960], fft_buffer);
|
2014-06-17 02:11:41 -07:00
|
|
|
|
|
|
|
if (fmatlab) {
|
|
|
|
fprintf(fmatlab, "outfft=");
|
2014-06-29 10:51:25 -07:00
|
|
|
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);
|
2014-06-17 02:11:41 -07:00
|
|
|
fprintf(fmatlab, ";\n");
|
2014-06-29 10:51:25 -07:00
|
|
|
vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB);
|
2014-06-17 02:11:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get channel estimates for each port */
|
2014-08-01 14:26:28 -07:00
|
|
|
chest_ce_slot(&chest, fft_buffer, ce, 1);
|
2014-06-17 02:11:41 -07:00
|
|
|
|
|
|
|
INFO("Decoding PBCH\n", 0);
|
|
|
|
|
2014-06-27 09:36:25 -07:00
|
|
|
n = pbch_decode(&pbch, fft_buffer, ce, &mib);
|
2014-06-17 02:11:41 -07:00
|
|
|
|
|
|
|
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) {
|
2014-07-22 07:56:56 -07:00
|
|
|
pbch_mib_fprint(stdout, &mib, cell.id);
|
2014-06-17 02:11:41 -07:00
|
|
|
printf("This is the signal.1.92M.dat file\n");
|
|
|
|
exit(0);
|
|
|
|
} else {
|
2014-07-22 07:56:56 -07:00
|
|
|
pbch_mib_fprint(stdout, &mib, cell.id);
|
2014-06-17 02:11:41 -07:00
|
|
|
printf("This is an unknown file\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
2014-01-28 03:41:17 -08:00
|
|
|
}
|