mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
270 lines
7.5 KiB
C
270 lines
7.5 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
11 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
11 years ago
|
*
|
||
10 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
10 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
11 years ago
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
10 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
11 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
10 years ago
|
* GNU Affero General Public License for more details.
|
||
11 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
11 years ago
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
11 years ago
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <strings.h>
|
||
|
#include <unistd.h>
|
||
|
#include <sys/time.h>
|
||
|
|
||
10 years ago
|
#include "srslte/srslte.h"
|
||
11 years ago
|
|
||
|
char *input_file_name;
|
||
|
char *output_file_name="abs_corr.txt";
|
||
11 years ago
|
int nof_frames=100, frame_length=9600, symbol_sz=128;
|
||
11 years ago
|
float corr_peak_threshold=25.0;
|
||
|
int out_N_id_2 = 0, force_N_id_2=-1;
|
||
|
|
||
11 years ago
|
#define CFO_AUTO -9999.0
|
||
11 years ago
|
float force_cfo = CFO_AUTO;
|
||
|
|
||
|
void usage(char *prog) {
|
||
11 years ago
|
printf("Usage: %s [olntsNfcv] -i input_file\n", prog);
|
||
|
printf("\t-o output_file [Default %s]\n", output_file_name);
|
||
|
printf("\t-l frame_length [Default %d]\n", frame_length);
|
||
|
printf("\t-n number of frames [Default %d]\n", nof_frames);
|
||
|
printf("\t-t correlation threshold [Default %g]\n", corr_peak_threshold);
|
||
|
printf("\t-s symbol_sz [Default %d]\n", symbol_sz);
|
||
|
printf("\t-N out_N_id_2 [Default %d]\n", out_N_id_2);
|
||
|
printf("\t-f force_N_id_2 [Default %d]\n", force_N_id_2);
|
||
|
printf("\t-c force_cfo [Default disabled]\n");
|
||
10 years ago
|
printf("\t-v srslte_verbose\n");
|
||
11 years ago
|
}
|
||
|
|
||
|
void parse_args(int argc, char **argv) {
|
||
11 years ago
|
int opt;
|
||
|
while ((opt = getopt(argc, argv, "ionltsNfcv")) != -1) {
|
||
|
switch(opt) {
|
||
|
case 'i':
|
||
|
input_file_name = argv[optind];
|
||
|
break;
|
||
|
case 'o':
|
||
|
output_file_name = argv[optind];
|
||
|
break;
|
||
|
case 'n':
|
||
|
nof_frames = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 'l':
|
||
|
frame_length = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 't':
|
||
|
corr_peak_threshold = atof(argv[optind]);
|
||
|
break;
|
||
|
case 's':
|
||
|
symbol_sz = atof(argv[optind]);
|
||
|
break;
|
||
|
case 'N':
|
||
|
out_N_id_2 = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 'f':
|
||
|
force_N_id_2 = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 'c':
|
||
|
force_cfo = atof(argv[optind]);
|
||
|
break;
|
||
|
case 'v':
|
||
10 years ago
|
srslte_verbose++;
|
||
11 years ago
|
break;
|
||
|
default:
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
if (!input_file_name) {
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
10 years ago
|
srslte_filesource_t fsrc;
|
||
|
srslte_filesink_t fsink;
|
||
10 years ago
|
srslte_pss_synch_t pss[3]; // One for each N_id_2
|
||
|
srslte_sss_synch_t sss[3]; // One for each N_id_2
|
||
|
srslte_cfo_t cfocorr;
|
||
11 years ago
|
int peak_pos[3];
|
||
|
float *cfo;
|
||
|
float peak_value[3];
|
||
|
int frame_cnt;
|
||
|
cf_t *input;
|
||
10 years ago
|
uint32_t m0, m1;
|
||
11 years ago
|
float m0_value, m1_value;
|
||
10 years ago
|
uint32_t N_id_2;
|
||
|
uint32_t sss_idx;
|
||
11 years ago
|
struct timeval tdata[3];
|
||
|
int *exec_time;
|
||
11 years ago
|
|
||
11 years ago
|
if (argc < 3) {
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
parse_args(argc,argv);
|
||
11 years ago
|
|
||
11 years ago
|
gettimeofday(&tdata[1], NULL);
|
||
|
printf("Initializing...");fflush(stdout);
|
||
11 years ago
|
|
||
10 years ago
|
if (srslte_filesource_init(&fsrc, input_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) {
|
||
11 years ago
|
fprintf(stderr, "Error opening file %s\n", input_file_name);
|
||
|
exit(-1);
|
||
|
}
|
||
10 years ago
|
if (srslte_filesink_init(&fsink, output_file_name, SRSLTE_COMPLEX_FLOAT_BIN)) {
|
||
11 years ago
|
fprintf(stderr, "Error opening file %s\n", output_file_name);
|
||
|
exit(-1);
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
input = malloc(frame_length*sizeof(cf_t));
|
||
|
if (!input) {
|
||
|
perror("malloc");
|
||
|
exit(-1);
|
||
|
}
|
||
|
cfo = malloc(nof_frames*sizeof(float));
|
||
|
if (!cfo) {
|
||
|
perror("malloc");
|
||
|
exit(-1);
|
||
|
}
|
||
|
exec_time = malloc(nof_frames*sizeof(int));
|
||
|
if (!exec_time) {
|
||
|
perror("malloc");
|
||
|
exit(-1);
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
if (srslte_cfo_init(&cfocorr, frame_length)) {
|
||
11 years ago
|
fprintf(stderr, "Error initiating CFO\n");
|
||
|
return -1;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* We have 2 options here:
|
||
|
* a) We create 3 pss objects, each initialized with a different N_id_2
|
||
|
* b) We create 1 pss object which scans for each N_id_2 one after another.
|
||
|
* a) requries more memory but has less latency and is paralellizable.
|
||
|
*/
|
||
|
for (N_id_2=0;N_id_2<3;N_id_2++) {
|
||
10 years ago
|
if (srslte_pss_synch_init(&pss[N_id_2], frame_length)) {
|
||
11 years ago
|
fprintf(stderr, "Error initializing PSS object\n");
|
||
|
exit(-1);
|
||
|
}
|
||
10 years ago
|
if (srslte_pss_synch_set_N_id_2(&pss[N_id_2], N_id_2)) {
|
||
11 years ago
|
fprintf(stderr, "Error initializing N_id_2\n");
|
||
|
exit(-1);
|
||
|
}
|
||
10 years ago
|
if (srslte_sss_synch_init(&sss[N_id_2], 128)) {
|
||
11 years ago
|
fprintf(stderr, "Error initializing SSS object\n");
|
||
|
exit(-1);
|
||
|
}
|
||
10 years ago
|
if (srslte_sss_synch_set_N_id_2(&sss[N_id_2], N_id_2)) {
|
||
11 years ago
|
fprintf(stderr, "Error initializing N_id_2\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
gettimeofday(&tdata[2], NULL);
|
||
|
get_time_interval(tdata);
|
||
8 years ago
|
printf("done in %ld s %ld ms\n", tdata[0].tv_sec, tdata[0].tv_usec/1000);
|
||
11 years ago
|
|
||
11 years ago
|
printf("\n\tFr.Cnt\tN_id_2\tN_id_1\tSubf\tPSS Peak/Avg\tIdx\tm0\tm1\tCFO\n");
|
||
|
printf("\t===============================================================================\n");
|
||
11 years ago
|
|
||
11 years ago
|
/* read all file or nof_frames */
|
||
|
frame_cnt = 0;
|
||
10 years ago
|
while (frame_length == srslte_filesource_read(&fsrc, input, frame_length)
|
||
11 years ago
|
&& frame_cnt < nof_frames) {
|
||
11 years ago
|
|
||
11 years ago
|
gettimeofday(&tdata[1], NULL);
|
||
|
if (force_cfo != CFO_AUTO) {
|
||
10 years ago
|
srslte_cfo_correct(&cfocorr, input, input, force_cfo/128);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
if (force_N_id_2 != -1) {
|
||
|
N_id_2 = force_N_id_2;
|
||
10 years ago
|
peak_pos[N_id_2] = srslte_pss_synch_find_pss(&pss[N_id_2], input, &peak_value[N_id_2]);
|
||
11 years ago
|
} else {
|
||
|
for (N_id_2=0;N_id_2<3;N_id_2++) {
|
||
10 years ago
|
peak_pos[N_id_2] = srslte_pss_synch_find_pss(&pss[N_id_2], input, &peak_value[N_id_2]);
|
||
11 years ago
|
}
|
||
|
float max_value=-99999;
|
||
|
N_id_2=-1;
|
||
|
int i;
|
||
|
for (i=0;i<3;i++) {
|
||
|
if (peak_value[i] > max_value) {
|
||
|
max_value = peak_value[i];
|
||
|
N_id_2 = i;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* If peak detected */
|
||
10 years ago
|
if (peak_value[N_id_2] > corr_peak_threshold) {
|
||
11 years ago
|
|
||
10 years ago
|
sss_idx = peak_pos[N_id_2]-2*(symbol_sz+SRSLTE_CP_LEN(symbol_sz,SRSLTE_CP_NORM_LEN));
|
||
11 years ago
|
if (sss_idx >= 0) {
|
||
10 years ago
|
srslte_sss_synch_m0m1_diff(&sss[N_id_2], &input[sss_idx],
|
||
11 years ago
|
&m0, &m0_value, &m1, &m1_value);
|
||
11 years ago
|
|
||
10 years ago
|
cfo[frame_cnt] = srslte_pss_synch_cfo_compute(&pss[N_id_2], &input[peak_pos[N_id_2]-128]);
|
||
11 years ago
|
printf("\t%d\t%d\t%d\t%d\t%.3f\t\t%3d\t%d\t%d\t%.3f\n",
|
||
10 years ago
|
frame_cnt,N_id_2, srslte_sss_synch_N_id_1(&sss[N_id_2], m0, m1),
|
||
|
srslte_sss_synch_subframe(m0, m1), peak_value[N_id_2],
|
||
11 years ago
|
peak_pos[N_id_2], m0, m1,
|
||
|
cfo[frame_cnt]);
|
||
|
}
|
||
|
}
|
||
|
gettimeofday(&tdata[2], NULL);
|
||
|
get_time_interval(tdata);
|
||
|
exec_time[frame_cnt] = tdata[0].tv_usec;
|
||
|
frame_cnt++;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
int i;
|
||
|
float avg_time=0;
|
||
|
for (i=0;i<frame_cnt;i++) {
|
||
|
avg_time += (float) exec_time[i];
|
||
|
}
|
||
|
avg_time /= frame_cnt;
|
||
|
printf("\n");
|
||
|
printf("Average exec time: %.3f ms / frame. %.3f Msamp/s (%.3f\%% CPU)\n",
|
||
|
avg_time / 1000, frame_length / avg_time, 100 * avg_time / 5000 * (9600 / (float) frame_length ));
|
||
11 years ago
|
|
||
11 years ago
|
float cfo_mean=0;
|
||
|
for (i=0;i<frame_cnt;i++) {
|
||
|
cfo_mean += cfo[i] / frame_cnt * (9600 / frame_length);
|
||
|
}
|
||
|
printf("Average CFO: %.3f\n", cfo_mean);
|
||
11 years ago
|
|
||
11 years ago
|
for (N_id_2=0;N_id_2<3;N_id_2++) {
|
||
10 years ago
|
srslte_pss_synch_free(&pss[N_id_2]);
|
||
|
srslte_sss_synch_free(&sss[N_id_2]);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
10 years ago
|
srslte_filesource_free(&fsrc);
|
||
|
srslte_filesink_free(&fsink);
|
||
11 years ago
|
|
||
11 years ago
|
free(input);
|
||
|
free(cfo);
|
||
11 years ago
|
|
||
11 years ago
|
printf("Done\n");
|
||
|
exit(0);
|
||
11 years ago
|
}
|