Fixed PDSCH not working with odd number of PRB. Fixed PBCH resource allocation for PRB greater than 6. Other minor issues

master
ismagom 11 years ago
parent 8f08380d46
commit a08cdaecfc

@ -57,20 +57,34 @@ target_link_libraries(pbch_ue lte_phy)
add_executable(pbch_enodeb pbch_enodeb.c)
target_link_libraries(pbch_enodeb lte_phy)
add_executable(pdsch_ue pdsch_ue.c)
target_link_libraries(pdsch_ue lte_phy)
add_executable(pdsch_enodeb pdsch_enodeb.c)
target_link_libraries(pdsch_enodeb lte_phy)
IF(${CUHD_FIND} EQUAL -1)
SET_TARGET_PROPERTIES(pbch_ue PROPERTIES COMPILE_DEFINITIONS "DISABLE_UHD")
SET_TARGET_PROPERTIES(pbch_enodeb PROPERTIES COMPILE_DEFINITIONS "DISABLE_UHD")
SET_TARGET_PROPERTIES(pbch_ue PROPERTIES COMPILE_DEFINITIONS "DISABLE_UHD")
SET_TARGET_PROPERTIES(pbch_enodeb PROPERTIES COMPILE_DEFINITIONS "DISABLE_UHD")
SET_TARGET_PROPERTIES(pdsch_ue PROPERTIES COMPILE_DEFINITIONS "DISABLE_UHD")
SET_TARGET_PROPERTIES(pdsch_enodeb PROPERTIES COMPILE_DEFINITIONS "DISABLE_UHD")
ELSE(${CUHD_FIND} EQUAL -1)
target_link_libraries(pbch_ue cuhd)
target_link_libraries(pbch_enodeb cuhd)
target_link_libraries(pbch_ue cuhd)
target_link_libraries(pbch_enodeb cuhd)
target_link_libraries(pdsch_ue cuhd)
target_link_libraries(pdsch_enodeb cuhd)
ENDIF(${CUHD_FIND} EQUAL -1)
IF(${GRAPHICS_FIND} EQUAL -1)
SET_TARGET_PROPERTIES(pbch_ue PROPERTIES COMPILE_DEFINITIONS "DISABLE_GRAPHICS")
SET_TARGET_PROPERTIES(pbch_enodeb PROPERTIES COMPILE_DEFINITIONS "DISABLE_GRAPHICS")
SET_TARGET_PROPERTIES(pbch_ue PROPERTIES COMPILE_DEFINITIONS "DISABLE_GRAPHICS")
SET_TARGET_PROPERTIES(pbch_enodeb PROPERTIES COMPILE_DEFINITIONS "DISABLE_GRAPHICS")
SET_TARGET_PROPERTIES(pdsch_ue PROPERTIES COMPILE_DEFINITIONS "DISABLE_GRAPHICS")
SET_TARGET_PROPERTIES(pdsch_enodeb PROPERTIES COMPILE_DEFINITIONS "DISABLE_GRAPHICS")
ELSE(${GRAPHICS_FIND} EQUAL -1)
target_link_libraries(pbch_ue graphics)
target_link_libraries(pbch_enodeb graphics)
target_link_libraries(pbch_ue graphics)
target_link_libraries(pbch_enodeb graphics)
target_link_libraries(pdsch_ue graphics)
target_link_libraries(pdsch_enodeb graphics)
ENDIF(${GRAPHICS_FIND} EQUAL -1)
@ -81,17 +95,17 @@ ENDIF(${GRAPHICS_FIND} EQUAL -1)
IF(${CUHD_FIND} GREATER -1)
add_executable(scan_rssi scan_rssi.c)
target_link_libraries(scan_rssi lte_phy cuhd )
add_executable(scan_rssi scan_rssi.c)
target_link_libraries(scan_rssi lte_phy cuhd )
add_executable(scan_pss scan_pss.c)
target_link_libraries(scan_pss lte_phy cuhd )
add_executable(scan_pss scan_pss.c)
target_link_libraries(scan_pss lte_phy cuhd )
add_executable(scan_mib scan_mib.c)
target_link_libraries(scan_mib lte_phy cuhd )
add_executable(scan_mib scan_mib.c)
target_link_libraries(scan_mib lte_phy cuhd )
MESSAGE(STATUS " UHD examples will be installed.")
MESSAGE(STATUS " UHD examples will be installed.")
ELSE(${CUHD_FIND} GREATER -1)
MESSAGE(STATUS " UHD examples NOT INSTALLED: CUHD library not compiled.")
MESSAGE(STATUS " UHD examples NOT INSTALLED: CUHD library not compiled.")
ENDIF(${CUHD_FIND} GREATER -1)

@ -50,7 +50,7 @@ filesink_t fsink;
lte_fft_t ifft;
pbch_t pbch;
cf_t *slot_buffer = NULL, *output_buffer = NULL;
cf_t *sf_buffer = NULL, *output_buffer = NULL;
int slot_n_re, slot_n_samples;
#define UHD_SAMP_FREQ 1920000
@ -118,8 +118,8 @@ void parse_args(int argc, char **argv) {
void base_init() {
/* init memory */
slot_buffer = malloc(sizeof(cf_t) * slot_n_re);
if (!slot_buffer) {
sf_buffer = malloc(sizeof(cf_t) * slot_n_re);
if (!sf_buffer) {
perror("malloc");
exit(-1);
}
@ -164,8 +164,8 @@ void base_free() {
lte_ifft_free(&ifft);
if (slot_buffer) {
free(slot_buffer);
if (sf_buffer) {
free(sf_buffer);
}
if (output_buffer) {
free(output_buffer);
@ -187,7 +187,7 @@ int main(int argc, char **argv) {
pbch_mib_t mib;
refsignal_t refs[NSLOTS_X_FRAME];
int i;
cf_t *slot1_symbols[MAX_PORTS_CTRL];
cf_t *slot1_symbols[MAX_PORTS];
#ifdef DISABLE_UHD
@ -224,8 +224,8 @@ int main(int argc, char **argv) {
mib.phich_resources = R_1;
mib.sfn = 0;
for (i=0;i<MAX_PORTS_CTRL;i++) { // now there's only 1 port
slot1_symbols[i] = slot_buffer;
for (i=0;i<MAX_PORTS;i++) { // now there's only 1 port
slot1_symbols[i] = sf_buffer;
}
#ifndef DISABLE_UHD
@ -240,13 +240,13 @@ int main(int argc, char **argv) {
while(nf<nof_frames || nof_frames == -1) {
for (ns=0;ns<NSLOTS_X_FRAME;ns++) {
bzero(slot_buffer, sizeof(cf_t) * slot_n_re);
bzero(sf_buffer, sizeof(cf_t) * slot_n_re);
switch(ns) {
case 0: // tx pss/sss
case 10: // tx pss/sss
pss_put_slot(pss_signal, slot_buffer, nof_prb, CPNORM);
sss_put_slot(ns?sss_signal5:sss_signal0, slot_buffer, nof_prb, CPNORM);
pss_put_slot(pss_signal, sf_buffer, nof_prb, CPNORM);
sss_put_slot(ns?sss_signal5:sss_signal0, sf_buffer, nof_prb, CPNORM);
break;
case 1: // tx pbch
pbch_encode(&pbch, &mib, slot1_symbols, 1);
@ -255,10 +255,10 @@ int main(int argc, char **argv) {
break;
}
refsignal_put(&refs[ns], slot_buffer);
refsignal_put(&refs[ns], sf_buffer);
/* Transform to OFDM symbols */
lte_ifft_run(&ifft, slot_buffer, output_buffer);
lte_ifft_run_slot(&ifft, sf_buffer, output_buffer);
/* send to file or usrp */
if (output_file_name) {

@ -39,15 +39,15 @@
#include "liblte/phy/phy.h"
#ifndef DISABLE_UHD
#include "liblte/cuhd/cuhd.h"
void *uhd;
#include "liblte/cuhd/cuhd.h"
void *uhd;
#endif
#ifndef DISABLE_GRAPHICS
#include "liblte/graphics/plot.h"
plot_real_t poutfft;
plot_complex_t pce;
plot_scatter_t pscatrecv, pscatequal;
#include "liblte/graphics/plot.h"
plot_real_t poutfft;
plot_complex_t pce;
plot_scatter_t pscatrecv, pscatequal;
#endif
#define MHZ 1000000
@ -57,27 +57,28 @@
#define NOF_PORTS 2
float find_threshold = 20.0, track_threshold = 10.0;
float find_threshold = 20.0;
int max_track_lost = 20, nof_frames = -1;
int track_len=300;
int track_len = 300;
char *input_file_name = NULL;
int disable_plots = 0;
int go_exit=0;
int go_exit = 0;
float uhd_freq = 2600000000.0, uhd_gain = 20.0;
char *uhd_args = "";
filesource_t fsrc;
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS_CTRL];
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS];
pbch_t pbch;
lte_fft_t fft;
chest_t chest;
sync_t sfind, strack;
sync_t ssync;
cfo_t cfocorr;
enum sync_state {FIND, TRACK};
enum sync_state {
FIND, TRACK
};
void usage(char *prog) {
printf("Usage: %s [iagfndvp]\n", prog);
@ -85,7 +86,7 @@ void usage(char *prog) {
#ifndef DISABLE_UHD
printf("\t-a UHD args [Default %s]\n", uhd_args);
printf("\t-g UHD RX gain [Default %.2f dB]\n", uhd_gain);
printf("\t-f UHD RX frequency [Default %.1f MHz]\n", uhd_freq/1000000);
printf("\t-f UHD RX frequency [Default %.1f MHz]\n", uhd_freq / 1000000);
#else
printf("\t UHD is disabled. CUHD library not available\n");
#endif
@ -102,7 +103,7 @@ void usage(char *prog) {
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "iagfndvp")) != -1) {
switch(opt) {
switch (opt) {
case 'i':
input_file_name = argv[optind];
break;
@ -181,16 +182,16 @@ int base_init(int frame_length) {
}
} else {
/* open UHD device */
#ifndef DISABLE_UHD
#ifndef DISABLE_UHD
printf("Opening UHD device...\n");
if (cuhd_open(uhd_args,&uhd)) {
if (cuhd_open(uhd_args, &uhd)) {
fprintf(stderr, "Error opening uhd\n");
return -1;
}
#else
#else
printf("Error UHD not available. Select an input file\n");
return -1;
#endif
#endif
}
input_buffer = (cf_t*) malloc(frame_length * sizeof(cf_t));
@ -204,19 +205,14 @@ int base_init(int frame_length) {
perror("malloc");
return -1;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i = 0; i < MAX_PORTS; i++) {
ce[i] = (cf_t*) malloc(CPNORM_NSYMB * 72 * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
return -1;
}
}
if (sync_init(&sfind, FLEN)) {
fprintf(stderr, "Error initiating PSS/SSS\n");
return -1;
}
if (sync_init(&strack, track_len)) {
if (sync_init(&ssync, FLEN)) {
fprintf(stderr, "Error initiating PSS/SSS\n");
return -1;
}
@ -229,7 +225,6 @@ int base_init(int frame_length) {
fprintf(stderr, "Error initiating CFO\n");
return -1;
}
if (lte_fft_init(&fft, CPNORM, 6)) {
fprintf(stderr, "Error initializing FFT\n");
return -1;
@ -244,29 +239,27 @@ void base_free() {
if (input_file_name) {
filesource_free(&fsrc);
} else {
#ifndef DISABLE_UHD
#ifndef DISABLE_UHD
cuhd_close(uhd);
#endif
#endif
}
#ifndef DISABLE_GRAPHICS
plot_exit();
#endif
sync_free(&sfind);
sync_free(&strack);
sync_free(&ssync);
lte_fft_free(&fft);
chest_free(&chest);
cfo_free(&cfocorr);
free(input_buffer);
free(fft_buffer);
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i = 0; i < MAX_PORTS; i++) {
free(ce[i]);
}
}
int mib_decoder_init(int cell_id) {
if (chest_ref_LTEDL(&chest, cell_id)) {
@ -284,25 +277,28 @@ int mib_decoder_init(int cell_id) {
int mib_decoder_run(cf_t *input, pbch_mib_t *mib) {
int i, n;
lte_fft_run(&fft, input, fft_buffer);
lte_fft_run_slot(&fft, input, fft_buffer);
/* Get channel estimates for each port */
for (i=0;i<NOF_PORTS;i++) {
for (i = 0; i < NOF_PORTS; i++) {
chest_ce_slot_port(&chest, fft_buffer, ce[i], 1, i);
}
DEBUG("Decoding PBCH\n", 0);
n = pbch_decode(&pbch, fft_buffer, ce, 1, mib);
n = pbch_decode(&pbch, fft_buffer, ce, mib);
#ifndef DISABLE_GRAPHICS
float tmp[72*7];
float tmp[72 * 7];
if (!disable_plots) {
for (i=0;i<72*7;i++) {
tmp[i] = 10*log10f(cabsf(fft_buffer[i]));
for (i = 0; i < 72 * 7; i++) {
tmp[i] = 10 * log10f(cabsf(fft_buffer[i]));
if (isinf(tmp[i])) {
tmp[i] = -80;
}
}
plot_real_setNewData(&poutfft, tmp, 72*7);
plot_complex_setNewData(&pce, ce[0], 72*7);
plot_real_setNewData(&poutfft, tmp, 72 * 7);
plot_complex_setNewData(&pce, ce[0], 72 * 7);
plot_scatter_setNewData(&pscatrecv, pbch.pbch_symbols[0], pbch.nof_symbols);
if (n) {
plot_scatter_setNewData(&pscatequal, pbch.pbch_d, pbch.nof_symbols);
@ -313,9 +309,8 @@ int mib_decoder_run(cf_t *input, pbch_mib_t *mib) {
return n;
}
void sigintHandler(int sig_num)
{
go_exit=1;
void sigintHandler(int sig_num) {
go_exit = 1;
}
int main(int argc, char **argv) {
@ -337,29 +332,28 @@ int main(int argc, char **argv) {
}
#endif
parse_args(argc,argv);
parse_args(argc, argv);
if (base_init(FLEN)) {
fprintf(stderr, "Error initializing memory\n");
exit(-1);
}
sync_pss_det_peak_to_avg(&sfind);
sync_pss_det_peak_to_avg(&strack);
sync_pss_det_peak_to_avg(&ssync);
if (!input_file_name) {
#ifndef DISABLE_UHD
#ifndef DISABLE_UHD
INFO("Setting sampling frequency %.2f MHz\n", (float) SAMP_FREQ/MHZ);
cuhd_set_rx_srate(uhd, SAMP_FREQ);
cuhd_set_rx_gain(uhd, uhd_gain);
/* set uhd_freq */
cuhd_set_rx_freq(uhd, (double) uhd_freq);
cuhd_rx_wait_lo_locked(uhd);
DEBUG("Set uhd_freq to %.3f MHz\n", (double) uhd_freq);
DEBUG("Set uhd_freq to %.3f MHz\n", (double ) uhd_freq);
DEBUG("Starting receiver...\n",0);
DEBUG("Starting receiver...\n", 0);
cuhd_start_rx_stream(uhd);
#endif
#endif
}
printf("\n --- Press Ctrl+C to exit --- \n");
@ -372,10 +366,9 @@ int main(int argc, char **argv) {
mib.sfn = -1;
frame_cnt = 0;
last_found = 0;
sync_set_threshold(&sfind, find_threshold);
sync_force_N_id_2(&sfind, -1);
sync_set_threshold(&ssync, find_threshold);
while(!go_exit && (frame_cnt < nof_frames || nof_frames==-1)) {
while (!go_exit && (frame_cnt < nof_frames || nof_frames == -1)) {
INFO(" ----- RECEIVING %d SAMPLES ---- \n", FLEN);
if (input_file_name) {
n = filesource_read(&fsrc, input_buffer, FLEN);
@ -387,29 +380,26 @@ int main(int argc, char **argv) {
filesource_read(&fsrc, input_buffer, FLEN);
}
} else {
#ifndef DISABLE_UHD
#ifndef DISABLE_UHD
cuhd_recv(uhd, input_buffer, FLEN, 1);
#endif
#endif
}
switch(state) {
switch (state) {
case FIND:
/* find peak in all frame */
find_idx = sync_run(&sfind, input_buffer);
INFO("FIND %3d:\tPAR=%.2f\n", frame_cnt, sync_get_peak_to_avg(&sfind));
find_idx = sync_find(&ssync, input_buffer);
INFO("FIND %3d:\tPAR=%.2f\n", frame_cnt, sync_get_peak_to_avg(&ssync));
if (find_idx != -1) {
/* if found peak, go to track and set track threshold */
cell_id = sync_get_cell_id(&sfind);
cell_id = sync_get_cell_id(&ssync);
if (cell_id != -1) {
frame_cnt = -1;
last_found = 0;
sync_set_threshold(&strack, track_threshold);
sync_force_N_id_2(&strack, sync_get_N_id_2(&sfind));
sync_force_cp(&strack, sync_get_cp(&sfind));
mib_decoder_init(cell_id);
nof_found_mib = 0;
nslot = sync_get_slot_id(&sfind);
nslot=(nslot+10)%20;
nslot = sync_get_slot_id(&ssync);
nslot = (nslot + 10) % 20;
cfo = 0;
timeoffset = 0;
printf("\n");
@ -419,31 +409,26 @@ int main(int argc, char **argv) {
}
}
if (verbose == VERBOSE_NONE) {
printf("Finding PSS... PAR=%.2f\r", sync_get_peak_to_avg(&sfind));
printf("Finding PSS... PAR=%.2f\r", sync_get_peak_to_avg(&ssync));
}
break;
case TRACK:
/* Find peak around known position find_idx */
INFO("TRACK %3d: PSS find_idx %d offset %d\n", frame_cnt, find_idx, find_idx - track_len);
track_idx = sync_run(&strack, &input_buffer[find_idx - track_len]);
INFO("TRACK %3d: PSS find_idx %d offset %d\n", frame_cnt, find_idx,
find_idx - track_len);
track_idx = sync_track(&ssync, &input_buffer[find_idx - track_len]);
if (track_idx != -1) {
/* compute cumulative moving average CFO */
cfo = (sync_get_cfo(&strack) + frame_cnt * cfo) / (frame_cnt + 1);
cfo = (sync_get_cfo(&ssync) + frame_cnt * cfo) / (frame_cnt + 1);
/* compute cumulative moving average time offset */
timeoffset = (float) (track_idx-track_len + timeoffset * frame_cnt) / (frame_cnt + 1);
timeoffset = (float) (track_idx - track_len + timeoffset * frame_cnt)
/ (frame_cnt + 1);
last_found = frame_cnt;
find_idx = (find_idx + track_idx - track_len)%FLEN;
if (nslot != sync_get_slot_id(&strack)) {
INFO("Expected slot %d but got %d\n", nslot, sync_get_slot_id(&strack));
printf("\r\n");
fflush(stdout);
printf("\r\n");
state = FIND;
}
find_idx = (find_idx + track_idx - track_len) % FLEN;
} else {
/* if sync not found, adjust time offset with the averaged value */
find_idx = (find_idx + (int) timeoffset)%FLEN;
find_idx = (find_idx + (int) timeoffset) % FLEN;
}
/* if we missed too many PSS go back to FIND */
@ -458,7 +443,7 @@ int main(int argc, char **argv) {
// Correct CFO
INFO("Correcting CFO=%.4f\n", cfo);
cfo_correct(&cfocorr, input_buffer, -cfo/128);
cfo_correct(&cfocorr, input_buffer, -cfo / 128);
if (nslot == 0 && find_idx + 960 < FLEN) {
INFO("Finding MIB at idx %d\n", find_idx);
@ -475,19 +460,21 @@ int main(int argc, char **argv) {
}
nof_found_mib++;
} else {
INFO("MIB not found attempt %d\n",frame_cnt);
INFO("MIB not found attempt %d\n", frame_cnt);
}
if (frame_cnt) {
printf("SFN: %4d, CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Errors: %4d/%4d, ErrorRate: %.1e\r", mib.sfn,
cfo*15, timeoffset/5, find_idx, frame_cnt-2*(nof_found_mib-1), frame_cnt,
(float) (frame_cnt-2*(nof_found_mib-1))/frame_cnt);
printf(
"SFN: %4d, CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Errors: %4d/%4d, ErrorRate: %.1e\r",
mib.sfn, cfo * 15, timeoffset / 5, find_idx,
frame_cnt - 2 * (nof_found_mib - 1), frame_cnt,
(float) (frame_cnt - 2 * (nof_found_mib - 1)) / frame_cnt);
fflush(stdout);
}
}
if (input_file_name) {
usleep(5000);
}
nslot = (nslot+10)%20;
nslot = (nslot + 10) % 20;
break;
}
frame_cnt++;

@ -0,0 +1,367 @@
/**
*
* \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/.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "liblte/phy/phy.h"
#ifndef DISABLE_UHD
#include "liblte/cuhd/cuhd.h"
void *uhd;
#endif
char *output_file_name = NULL;
int nof_frames = -1;
int cell_id = 1;
int nof_prb = 6;
char *uhd_args = "";
int cfi=1;
float uhd_amp = 0.25, uhd_gain = 10.0, uhd_freq = 2400000000;
filesink_t fsink;
lte_fft_t ifft;
pbch_t pbch;
pcfich_t pcfich;
pdcch_t pdcch;
pdsch_t pdsch;
regs_t regs;
cf_t *sf_buffer = NULL, *output_buffer = NULL;
int sf_n_re, sf_n_samples;
void usage(char *prog) {
printf("Usage: %s [agmfoncvp]\n", prog);
#ifndef DISABLE_UHD
printf("\t-a UHD args [Default %s]\n", uhd_args);
printf("\t-g UHD TX gain [Default %.2f dB]\n", uhd_gain);
printf("\t-m UHD signal amplitude [Default %.2f]\n", uhd_amp);
printf("\t-f UHD TX frequency [Default %.1f MHz]\n", uhd_freq / 1000000);
#else
printf("\t UHD is disabled. CUHD library not available\n");
#endif
printf("\t-o output_file [Default USRP]\n");
printf("\t-n number of frames [Default %d]\n", nof_frames);
printf("\t-c cell id [Default %d]\n", cell_id);
printf("\t-p nof_prb [Default %d]\n", nof_prb);
printf("\t-v [set verbose to debug, default none]\n");
}
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "agfmoncpv")) != -1) {
switch (opt) {
case 'a':
uhd_args = argv[optind];
break;
case 'g':
uhd_gain = atof(argv[optind]);
break;
case 'm':
uhd_amp = atof(argv[optind]);
break;
case 'f':
uhd_freq = atof(argv[optind]);
break;
case 'o':
output_file_name = argv[optind];
break;
case 'n':
nof_frames = atoi(argv[optind]);
break;
case 'p':
nof_prb = atoi(argv[optind]);
break;
case 'c':
cell_id = atoi(argv[optind]);
break;
case 'v':
verbose++;
break;
default:
usage(argv[0]);
exit(-1);
}
}
#ifdef DISABLE_UHD
if (!output_file_name) {
usage(argv[0]);
exit(-1);
}
#endif
}
void base_init() {
/* init memory */
sf_buffer = malloc(sizeof(cf_t) * sf_n_re);
if (!sf_buffer) {
perror("malloc");
exit(-1);
}
output_buffer = malloc(sizeof(cf_t) * sf_n_samples);
if (!output_buffer) {
perror("malloc");
exit(-1);
}
/* open file or USRP */
if (output_file_name) {
if (filesink_init(&fsink, output_file_name, COMPLEX_FLOAT_BIN)) {
fprintf(stderr, "Error opening file %s\n", output_file_name);
exit(-1);
}
} else {
#ifndef DISABLE_UHD
printf("Opening UHD device...\n");
if (cuhd_open(uhd_args, &uhd)) {
fprintf(stderr, "Error opening uhd\n");
exit(-1);
}
#else
printf("Error UHD not available. Select an output file\n");
exit(-1);
#endif
}
/* create ifft object */
if (lte_ifft_init(&ifft, CPNORM, nof_prb)) {
fprintf(stderr, "Error creating iFFT object\n");
exit(-1);
}
if (pbch_init(&pbch, nof_prb, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PBCH object\n");
exit(-1);
}
if (regs_init(&regs, cell_id, nof_prb, 1, R_1, PHICH_NORM, CPNORM)) {
fprintf(stderr, "Error initiating regs\n");
exit(-1);
}
if (pcfich_init(&pcfich, &regs, cell_id, nof_prb, 1, CPNORM)) {
fprintf(stderr, "Error creating PBCH object\n");
exit(-1);
}
if (regs_set_cfi(&regs, cfi)) {
fprintf(stderr, "Error setting CFI\n");
exit(-1);
}
if (pdcch_init(&pdcch, &regs, nof_prb, 1, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
if (pdsch_init(&pdsch, 1234, nof_prb, 1, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PDSCH object\n");
exit(-1);
}
}
void base_free() {
pdsch_free(&pdsch);
pdcch_free(&pdcch);
regs_free(&regs);
pbch_free(&pbch);
lte_ifft_free(&ifft);
if (sf_buffer) {
free(sf_buffer);
}
if (output_buffer) {
free(output_buffer);
}
if (output_file_name) {
filesink_free(&fsink);
} else {
#ifndef DISABLE_UHD
cuhd_close(&uhd);
#endif
}
}
int main(int argc, char **argv) {
int nf, sf_idx, N_id_2;
cf_t pss_signal[PSS_LEN];
float sss_signal0[SSS_LEN]; // for subframe 0
float sss_signal5[SSS_LEN]; // for subframe 5
pbch_mib_t mib;
ra_pdsch_t ra_dl;
ra_prb_t prb_alloc;
refsignal_t refs[NSLOTS_X_FRAME];
int i, n;
char *data;
cf_t *sf_symbols[MAX_PORTS];
cf_t *slot1_symbols[MAX_PORTS];
dci_t dci_tx;
#ifdef DISABLE_UHD
if (argc < 3) {
usage(argv[0]);
exit(-1);
}
#endif
parse_args(argc, argv);
N_id_2 = cell_id % 3;
sf_n_re = 2 * CPNORM_NSYMB * nof_prb * RE_X_RB;
sf_n_samples = 2 * SLOT_LEN_CPNORM(lte_symbol_sz(nof_prb));
/* this *must* be called after setting slot_len_* */
base_init();
/* Generate PSS/SSS signals */
pss_generate(pss_signal, N_id_2);
sss_generate(sss_signal0, sss_signal5, cell_id);
/* Generate CRS signals */
for (i = 0; i < NSLOTS_X_FRAME; i++) {
if (refsignal_init_LTEDL(&refs[i], 0, i, cell_id, CPNORM, nof_prb)) {
fprintf(stderr, "Error initiating CRS slot=%d\n", i);
return -1;
}
}
mib.nof_ports = 1;
mib.nof_prb = nof_prb;
mib.phich_length = PHICH_NORM;
mib.phich_resources = R_1;
mib.sfn = 0;
for (i = 0; i < MAX_PORTS; i++) { // now there's only 1 port
sf_symbols[i] = sf_buffer;
slot1_symbols[i] = &sf_buffer[sf_n_re/2];
}
#ifndef DISABLE_UHD
if (!output_file_name) {
printf("Set TX rate: %.2f MHz\n",
cuhd_set_tx_srate(uhd, lte_sampling_freq_hz(nof_prb)) / 1000000);
printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain));
printf("Set TX freq: %.2f MHz\n",
cuhd_set_tx_freq(uhd, uhd_freq) / 1000000);
}
#endif
dci_init(&dci_tx, 1);
bzero(&ra_dl, sizeof(ra_pdsch_t));
ra_dl.harq_process = 0;
ra_pdsch_set_mcs(&ra_dl, QPSK, 5);
ra_dl.ndi = 0;
ra_dl.rv_idx = 0;
ra_dl.alloc_type = alloc_type0;
ra_dl.type0_alloc.rbg_bitmask = 0xffffffff;
dci_msg_pack_pdsch(&ra_dl, &dci_tx.msg[0], Format1, nof_prb, false);
dci_tx.nof_dcis++;
if (pdcch_set_cfi(&pdcch, cfi)) {
fprintf(stderr, "Error setting CFI\n");
return -1;
}
pdcch_init_search_ue(&pdcch, 1234);
ra_prb_get_dl(&prb_alloc, &ra_dl, nof_prb);
ra_prb_get_re(&prb_alloc, nof_prb, 1, nof_prb<10?(cfi+1):cfi, CPNORM);
ra_dl.mcs.tbs = ra_tbs_from_idx(ra_dl.mcs.tbs_idx, nof_prb);
ra_pdsch_fprint(stdout, &ra_dl, nof_prb);
data = malloc(sizeof(char) * ra_dl.mcs.tbs);
if (!data) {
perror("malloc");
exit(-1);
}
nf = 0;
while (nf < nof_frames || nof_frames == -1) {
for (sf_idx = 0; sf_idx < NSUBFRAMES_X_FRAME; sf_idx++) {
bzero(sf_buffer, sizeof(cf_t) * sf_n_re);
if (sf_idx == 0 || sf_idx == 5) {
pss_put_slot(pss_signal, sf_buffer, nof_prb, CPNORM);
sss_put_slot(sf_idx ? sss_signal5 : sss_signal0, sf_buffer, nof_prb,
CPNORM);
}
if (sf_idx == 0) {
pbch_encode(&pbch, &mib, slot1_symbols, 1);
}
for (n=0;n<2;n++) {
refsignal_put(&refs[2*sf_idx+n], &sf_buffer[n*sf_n_re/2]);
}
pcfich_encode(&pcfich, cfi, sf_symbols, sf_idx);
INFO("SF: %d, Generating %d random bits\n", sf_idx, ra_dl.mcs.tbs);
for (i=0;i<ra_dl.mcs.tbs;i++) {
data[i] = rand()%2;
}
dci_msg_candidate_set(&dci_tx.msg[0], pdcch.search_mode[2].candidates[0][sf_idx].L,
pdcch.search_mode[2].candidates[0][sf_idx].ncce, 1234);
INFO("Setting DCI candidate L: %d nCCE: %d\n", pdcch.search_mode[2].candidates[0][sf_idx].L,
pdcch.search_mode[2].candidates[0][sf_idx].ncce);
pdcch_encode(&pdcch, &dci_tx, sf_symbols, sf_idx);
pdsch_encode(&pdsch, data, sf_symbols, sf_idx, ra_dl.mcs, &prb_alloc);
/* Transform to OFDM symbols */
lte_ifft_run_sf(&ifft, sf_buffer, output_buffer);
/* send to file or usrp */
if (output_file_name) {
filesink_write(&fsink, output_buffer, sf_n_samples);
usleep(5000);
} else {
#ifndef DISABLE_UHD
vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, sf_n_samples);
cuhd_send(uhd, output_buffer, sf_n_samples, 1);
#endif
}
}
mib.sfn = (mib.sfn + 1) % 1024;
printf("SFN: %4d\r", mib.sfn);
fflush(stdout);
nf++;
}
base_free();
printf("Done\n");
exit(0);
}

@ -0,0 +1,643 @@
/**
*
* \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/.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <math.h>
#include <sys/time.h>
#include <unistd.h>
#include <assert.h>
#include <signal.h>
#include "liblte/phy/phy.h"
#ifndef DISABLE_UHD
#include "liblte/cuhd/cuhd.h"
void *uhd;
#endif
#ifndef DISABLE_GRAPHICS
#include "liblte/graphics/plot.h"
plot_real_t poutfft;
plot_complex_t pce;
plot_scatter_t pscatrecv, pscatequal;
#endif
#define MHZ 1000000
#define SAMP_FREQ 1920000
#define NOF_PORTS 2
float find_threshold = 10.0;
int nof_frames = -1;
int pdsch_errors = 0, pdsch_total = 0;
int frame_cnt;
char *input_file_name = NULL;
int disable_plots = 0;
/* These are the number of PRBs used during the SYNC procedure */
int sampling_nof_prb = 6;
/* Number of samples in a subframe */
int sf_n_samples;
int cell_id_initated = 0, mib_initiated = 0;
int go_exit = 0;
float uhd_freq = 2600000000.0, uhd_gain = 20.0;
char *uhd_args = "";
filesource_t fsrc;
cf_t *input_buffer, *sf_buffer, *fft_buffer, *input_decim_buffer, *ce[MAX_PORTS];
float *tmp_plot;
pbch_t pbch;
pbch_mib_t mib;
pcfich_t pcfich;
pdcch_t pdcch;
dci_t dci_set;
pdsch_t pdsch;
regs_t regs;
lte_fft_t fft;
chest_t chest;
sync_frame_t sframe;
#define CLRSTDOUT printf("\r\n"); fflush(stdout); printf("\r\n")
#define DOWNSAMPLE_FACTOR(x, y) lte_symbol_sz(x) / lte_symbol_sz(y)
void usage(char *prog) {
printf("Usage: %s [iagfndvtp]\n", prog);
printf("\t-i input_file [Default use USRP]\n");
#ifndef DISABLE_UHD
printf("\t-a UHD args [Default %s]\n", uhd_args);
printf("\t-g UHD RX gain [Default %.2f dB]\n", uhd_gain);
printf("\t-f UHD RX frequency [Default %.1f MHz]\n", uhd_freq / 1000000);
#else
printf("\t UHD is disabled. CUHD library not available\n");
#endif
printf("\t-p sampling_nof_prb [Default %d]\n", sampling_nof_prb);
printf("\t-n nof_frames [Default %d]\n", nof_frames);
printf("\t-t PSS threshold [Default %f]\n", find_threshold);
#ifndef DISABLE_GRAPHICS
printf("\t-d disable plots [Default enabled]\n");
#else
printf("\t plots are disabled. Graphics library not available\n");
#endif
printf("\t-v [set verbose to debug, default none]\n");
}
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "iagfndvtp")) != -1) {
switch (opt) {
case 'i':
input_file_name = argv[optind];
break;
case 'a':
uhd_args = argv[optind];
break;
case 'g':
uhd_gain = atof(argv[optind]);
break;
case 'f':
uhd_freq = atof(argv[optind]);
break;
case 't':
find_threshold = atof(argv[optind]);
break;
case 'p':
sampling_nof_prb = atof(argv[optind]);
break;
case 'n':
nof_frames = atoi(argv[optind]);
break;
case 'd':
disable_plots = 1;
break;
case 'v':
verbose++;
break;
default:
usage(argv[0]);
exit(-1);
}
}
}
#ifndef DISABLE_GRAPHICS
void init_plots() {
plot_init();
plot_real_init(&poutfft);
plot_real_setTitle(&poutfft, "Output FFT - Magnitude");
plot_real_setLabels(&poutfft, "Index", "dB");
plot_real_setYAxisScale(&poutfft, -60, 0);
plot_real_setXAxisScale(&poutfft, 1, 504);
plot_complex_init(&pce);
plot_complex_setTitle(&pce, "Channel Estimates");
plot_complex_setYAxisScale(&pce, Ip, -0.01, 0.01);
plot_complex_setYAxisScale(&pce, Q, -0.01, 0.01);
plot_complex_setYAxisScale(&pce, Magnitude, 0, 0.01);
plot_complex_setYAxisScale(&pce, Phase, -M_PI, M_PI);
plot_scatter_init(&pscatrecv);
plot_scatter_setTitle(&pscatrecv, "Received Symbols");
plot_scatter_setXAxisScale(&pscatrecv, -0.01, 0.01);
plot_scatter_setYAxisScale(&pscatrecv, -0.01, 0.01);
plot_scatter_init(&pscatequal);
plot_scatter_setTitle(&pscatequal, "Equalized Symbols");
plot_scatter_setXAxisScale(&pscatequal, -1, 1);
plot_scatter_setYAxisScale(&pscatequal, -1, 1);
}
#endif
/* This function initializes the objects defined as global variables */
int base_init(int nof_prb) {
int i;
int sf_n_re = 2 * CPNORM_NSYMB * nof_prb * RE_X_RB;
int sf_n_samples = 2 * SLOT_LEN_CPNORM(lte_symbol_sz(nof_prb));
#ifndef DISABLE_GRAPHICS
if (!disable_plots) {
tmp_plot = malloc(sizeof(cf_t) * sf_n_re);
if (!tmp_plot) {
perror("malloc");
return -1;
}
init_plots();
}
#else
printf("-- PLOTS are disabled. Graphics library not available --\n\n");
#endif
if (input_file_name) {
if (filesource_init(&fsrc, input_file_name, COMPLEX_FLOAT_BIN)) {
return -1;
}
} else {
/* open UHD device */
#ifndef DISABLE_UHD
printf("Opening UHD device...\n");
if (cuhd_open(uhd_args, &uhd)) {
fprintf(stderr, "Error opening uhd\n");
return -1;
}
#else
printf("Error UHD not available. Select an input file\n");
return -1;
#endif
}
/* For the input buffer, we allocate space for 1 ms of samples */
input_buffer = (cf_t*) malloc(sf_n_samples * sizeof(cf_t));
if (!input_buffer) {
perror("malloc");
return -1;
}
input_decim_buffer = (cf_t*) malloc(sf_n_samples * sizeof(cf_t));
if (!input_decim_buffer) {
perror("malloc");
return -1;
}
/* This buffer is the aligned version of input_buffer */
sf_buffer = (cf_t*) malloc(sf_n_samples * sizeof(cf_t));
if (!sf_buffer) {
perror("malloc");
return -1;
}
/* For the rest of the buffers, we allocate for the number of RE in one subframe */
fft_buffer = (cf_t*) malloc(sf_n_re * sizeof(cf_t));
if (!fft_buffer) {
perror("malloc");
return -1;
}
for (i = 0; i < MAX_PORTS; i++) {
ce[i] = (cf_t*) malloc(sf_n_re * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
return -1;
}
}
bzero(&mib, sizeof(pbch_mib_t));
if (sync_frame_init(&sframe, DOWNSAMPLE_FACTOR(nof_prb,6))) {
fprintf(stderr, "Error initiating PSS/SSS\n");
return -1;
}
if (chest_init(&chest, LINEAR, CPNORM, nof_prb, NOF_PORTS)) {
fprintf(stderr, "Error initializing equalizer\n");
return -1;
}
if (lte_fft_init(&fft, CPNORM, nof_prb)) {
fprintf(stderr, "Error initializing FFT\n");
return -1;
}
dci_init(&dci_set, 10);
return 0;
}
void base_free() {
int i;
if (input_file_name) {
filesource_free(&fsrc);
} else {
#ifndef DISABLE_UHD
cuhd_close(uhd);
#endif
}
#ifndef DISABLE_GRAPHICS
if (!disable_plots) {
if (tmp_plot) {
free(tmp_plot);
}
plot_exit();
}
#endif
pbch_free(&pbch);
pdsch_free(&pdsch);
pdcch_free(&pdcch);
regs_free(&regs);
sync_frame_free(&sframe);
lte_fft_free(&fft);
chest_free(&chest);
free(input_buffer);
free(input_decim_buffer);
free(fft_buffer);
for (i = 0; i < MAX_PORTS; i++) {
free(ce[i]);
}
}
int mib_init(int cell_id) {
if (mib.nof_prb > sampling_nof_prb) {
fprintf(stderr, "Error sampling frequency is %.2f Mhz but captured signal has %d PRB\n",
(float) lte_sampling_freq_hz(sampling_nof_prb)/MHZ, mib.nof_prb);
return -1;
}
if (regs_init(&regs, cell_id, mib.nof_prb, mib.nof_ports,
mib.phich_resources, mib.phich_length, CPNORM)) {
fprintf(stderr, "Error initiating regs\n");
return -1;
}
if (pcfich_init(&pcfich, &regs, cell_id, mib.nof_prb, mib.nof_ports, CPNORM)) {
fprintf(stderr, "Error creating PCFICH object\n");
return -1;
}
if (pdcch_init(&pdcch, &regs, mib.nof_prb, mib.nof_ports, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PDCCH object\n");
return -1;
}
if (pdsch_init(&pdsch, 1234, mib.nof_prb, mib.nof_ports, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PDSCH object\n");
return -1;
}
chest_set_nof_ports(&chest, mib.nof_ports);
mib_initiated = 1;
DEBUG("Receiver initiated cell_id=%d nof_prb=%d\n", cell_id, mib.nof_prb);
return 0;
}
int cell_id_init(int nof_prb, int cell_id) {
if (chest_ref_LTEDL(&chest, cell_id)) {
fprintf(stderr, "Error initializing reference signal\n");
return -1;
}
if (pbch_init(&pbch, nof_prb, cell_id, CPNORM)) {
fprintf(stderr, "Error initiating PBCH\n");
return -1;
}
cell_id_initated = 1;
DEBUG("PBCH initiated cell_id=%d\n", cell_id);
return 0;
}
char data[10000];
int rx_run(cf_t *input, int sf_idx) {
int cfi, i, cfi_distance, nof_dcis;
cf_t *input_decim;
ra_pdsch_t ra_dl;
ra_prb_t prb_alloc;
/* Downsample if the signal bandwith is shorter */
if (sampling_nof_prb > mib.nof_prb) {
decim_c(input, input_decim_buffer, sf_n_samples, DOWNSAMPLE_FACTOR(sampling_nof_prb, mib.nof_prb));
input_decim = input_decim_buffer;
} else {
input_decim = input;
}
lte_fft_run_sf(&fft, input_decim, fft_buffer);
/* Get channel estimates for each port */
chest_ce_sf(&chest, fft_buffer, ce, sf_idx);
/* First decode PCFICH and obtain CFI */
if (pcfich_decode(&pcfich, fft_buffer, ce, sf_idx, &cfi, &cfi_distance)<0) {
return -1;
}
INFO("Decoded CFI=%d with distance %d\n", cfi, cfi_distance);
if (regs_set_cfi(&regs, cfi)) {
fprintf(stderr, "Error setting CFI\n");
return -1;
}
if (pdcch_set_cfi(&pdcch, cfi)) {
fprintf(stderr, "Error setting CFI\n");
return -1;
}
pdcch_init_search_ue(&pdcch, 1234);
dci_set.nof_dcis = 0;
nof_dcis = pdcch_decode(&pdcch, fft_buffer, ce, &dci_set, sf_idx);
INFO("Received %d DCIs\n", nof_dcis);
for (i=0;i<nof_dcis;i++) {
dci_msg_type_t type;
if (dci_msg_get_type(&dci_set.msg[i], &type, mib.nof_prb, 1234)) {
fprintf(stderr, "Can't get DCI message type\n");
} else {
INFO("MSG %d: L: %d nCCE: %d Nbits: %d. ",i,dci_set.msg[i].location.L,
dci_set.msg[i].location.ncce, dci_set.msg[i].location.nof_bits);
if (VERBOSE_ISINFO()) {
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_set.msg[i], &ra_dl, mib.nof_prb,
false)) {
fprintf(stderr, "Can't unpack PDSCH message\n");
break;
}
if (VERBOSE_ISINFO() || !pdsch_total) {
printf("\n");
ra_pdsch_fprint(stdout, &ra_dl, mib.nof_prb);
printf("\n");
}
if (ra_prb_get_dl(&prb_alloc, &ra_dl, mib.nof_prb)) {
fprintf(stderr, "Error computing resource allocation\n");
break;
}
ra_prb_get_re(&prb_alloc, mib.nof_prb, mib.nof_ports,
mib.nof_prb<10?(cfi+1):cfi, CPNORM);
if (pdsch_decode(&pdsch, fft_buffer, ce, data, sf_idx, ra_dl.mcs, &prb_alloc)) {
pdsch_errors++;
}
pdsch_total++;
break;
default:
fprintf(stderr, "Unsupported message type\n");
break;
}
}
}
#ifndef DISABLE_GRAPHICS
if (!disable_plots && nof_dcis > 0) {
int n_re = 2 * RE_X_RB * CPNORM_NSYMB * mib.nof_prb;
for (i = 0; i < n_re; i++) {
tmp_plot[i] = 10 * log10f(cabsf(fft_buffer[i]));
if (isinf(tmp_plot[i])) {
tmp_plot[i] = -80;
}
}
plot_real_setNewData(&poutfft, tmp_plot, n_re);
plot_complex_setNewData(&pce, ce[0], n_re);
plot_scatter_setNewData(&pscatrecv, pdsch.pdsch_symbols[0], prb_alloc.re_sf[sf_idx]);
plot_scatter_setNewData(&pscatequal, pdsch.pdsch_d, prb_alloc.re_sf[sf_idx]);
}
#endif
return 0;
}
int mib_decoder_run(cf_t *input) {
int i, n;
lte_fft_run_slot(&fft, input, fft_buffer);
/* Get channel estimates for each port */
for (i = 0; i < NOF_PORTS; i++) {
chest_ce_slot_port(&chest, fft_buffer, ce[i], 1, i);
}
DEBUG("Decoding PBCH\n", 0);
n = pbch_decode(&pbch, fft_buffer, ce, &mib);
return n;
}
int run_receiver(cf_t *input, int cell_id, int sf_idx) {
if (!cell_id_initated) {
cell_id_init(sampling_nof_prb, cell_id);
}
if (!mib.nof_prb) {
if (!sf_idx) {
if (mib_decoder_run(&input[sf_n_samples/2])) {
INFO("MIB decoded!\n", 0);
if (!mib_initiated) {
if (mib_init(cell_id)) {
return -1;
}
}
if (VERBOSE_ISINFO() || !frame_cnt) {
CLRSTDOUT;
printf(" - Phy. CellId:\t %d\n", cell_id);
pbch_mib_fprint(stdout, &mib);
}
}
}
}
if (mib.nof_prb) {
if (rx_run(input, sf_idx)) {
return -1;
}
}
return 0;
}
void sigintHandler(int sig_num) {
go_exit = 1;
}
void setup_uhd() {
double samp_freq;
#ifndef DISABLE_UHD
/* Get the sampling rate from the number of PRB */
samp_freq = lte_sampling_freq_hz(sampling_nof_prb);
INFO("Setting sampling frequency %.2f MHz\n", (float) samp_freq/MHZ);
cuhd_set_rx_srate(uhd, samp_freq);
cuhd_set_rx_gain(uhd, uhd_gain);
/* set uhd_freq */
cuhd_set_rx_freq(uhd, (double) uhd_freq);
cuhd_rx_wait_lo_locked(uhd);
DEBUG("Set uhd_freq to %.3f MHz\n", (double ) uhd_freq);
DEBUG("Starting receiver...\n", 0);
cuhd_start_rx_stream(uhd);
#endif
}
void read_io(cf_t *buffer, int nsamples) {
int n;
DEBUG(" ----- RECEIVING %d SAMPLES ---- \n", nsamples);
if (input_file_name) {
n = filesource_read(&fsrc, buffer, nsamples);
if (n == -1) {
fprintf(stderr, "Error reading file\n");
exit(-1);
/* wrap file if arrive to end */
} else if (n < nsamples) {
DEBUG("Read %d from file. Seeking to 0\n",n);
filesource_seek(&fsrc, 0);
filesource_read(&fsrc, buffer, nsamples);
}
} else {
#ifndef DISABLE_UHD
cuhd_recv(uhd, buffer, nsamples, 1);
#endif
}
}
int main(int argc, char **argv) {
#ifdef DISABLE_UHD
if (argc < 3) {
usage(argv[0]);
exit(-1);
}
#endif
parse_args(argc, argv);
if (base_init(sampling_nof_prb)) {
fprintf(stderr, "Error initializing memory\n");
exit(-1);
}
/* If input_file_name is NULL, we read from the USRP */
if (!input_file_name) {
setup_uhd();
}
printf("\n --- Press Ctrl+C to exit --- \n");
signal(SIGINT, sigintHandler);
/* Initialize variables */
mib.sfn = -1;
frame_cnt = 0;
/* The number of samples read from the USRP or file corresponds to 1 ms (subframe) */
sf_n_samples = 1920 * lte_symbol_sz(sampling_nof_prb)/128;
sync_frame_set_threshold(&sframe, find_threshold);
while (!go_exit && (frame_cnt < nof_frames || nof_frames == -1)) {
read_io(input_buffer, sf_n_samples);
switch(sync_frame_push(&sframe, input_buffer, sf_buffer)) {
case 0:
/* not yet synched */
break;
case 1:
if (!(frame_cnt%10)) {
mib.sfn++;
}
/* synch'd and tracking */
if (run_receiver(sf_buffer, sync_frame_cell_id(&sframe), sync_frame_sfidx(&sframe))) {
exit(-1);
}
if (!(frame_cnt % 10)) {
printf(
"SFN: %4d, CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Errors: %4d/%4d, BLER: %.1e\r",
mib.sfn, sframe.cur_cfo * 15, sframe.timeoffset / 5, sframe.peak_idx,
pdsch_errors, pdsch_total,
(float) pdsch_errors / pdsch_total);
fflush(stdout);
}
break;
default:
fprintf(stderr, "Error running automatic synchronization\n");
exit(-1);
}
frame_cnt++;
if (input_file_name) {
usleep(5000);
}
}
base_free();
printf("\nBye\n");
exit(0);
}

@ -53,7 +53,7 @@
#define IS_SIGNAL(i) (10*log10f(rssi[i]) + 30 > rssi_threshold)
int band, earfcn=-1;
float find_threshold = 10.0, track_threshold = 8.0;
float find_threshold = 10.0;
int earfcn_start=-1, earfcn_end = -1;
float rssi_threshold = -45.0;
int max_track_lost=9;
@ -64,7 +64,7 @@ cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS];
pbch_t pbch;
lte_fft_t fft;
chest_t chest;
sync_t sfind, strack;
sync_t ssync;
cfo_t cfocorr;
float *cfo_v;
@ -86,7 +86,7 @@ enum sync_state {INIT, FIND, TRACK, MIB, DONE};
void usage(char *prog) {
printf("Usage: %s [seRrFfTtgv] -b band\n", prog);
printf("Usage: %s [seRrFfTgv] -b band\n", prog);
printf("\t-s earfcn_start [Default All]\n");
printf("\t-e earfcn_end [Default All]\n");
printf("\t-R rssi_nof_samples [Default %d]\n", nof_samples_rssi);
@ -94,7 +94,6 @@ void usage(char *prog) {
printf("\t-F pss_find_nof_frames [Default %d]\n", nof_frames_find);
printf("\t-f pss_find_threshold [Default %.2f]\n", find_threshold);
printf("\t-T pss_track_nof_frames [Default %d]\n", nof_frames_track);
printf("\t-t pss_track_threshold [Default %.2f]\n", track_threshold);
printf("\t-l pss_track_len [Default %d]\n", track_len);
printf("\t-g gain [Default %.2f dB]\n", uhd_gain);
printf("\t-v [set verbose to debug, default none]\n");
@ -102,7 +101,7 @@ void usage(char *prog) {
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "bseRrFfTtgv")) != -1) {
while ((opt = getopt(argc, argv, "bseRrFfTgv")) != -1) {
switch(opt) {
case 'b':
band = atoi(argv[optind]);
@ -128,9 +127,6 @@ void parse_args(int argc, char **argv) {
case 'T':
nof_frames_track = atoi(argv[optind]);
break;
case 't':
track_threshold = atof(argv[optind]);
break;
case 'g':
uhd_gain = atof(argv[optind]);
break;
@ -166,11 +162,7 @@ int base_init(int frame_length) {
return -1;
}
}
if (sync_init(&sfind, FLEN)) {
fprintf(stderr, "Error initiating PSS/SSS\n");
return -1;
}
if (sync_init(&strack, track_len)) {
if (sync_init(&ssync, FLEN)) {
fprintf(stderr, "Error initiating PSS/SSS\n");
return -1;
}
@ -235,8 +227,7 @@ void base_free() {
cuhd_close(uhd);
#endif
sync_free(&sfind);
sync_free(&strack);
sync_free(&ssync);
lte_fft_free(&fft);
chest_free(&chest);
cfo_free(&cfocorr);
@ -335,7 +326,7 @@ int mib_decoder_init(int cell_id) {
int mib_decoder_run(cf_t *input, pbch_mib_t *mib) {
int i;
lte_fft_run(&fft, input, fft_buffer);
lte_fft_run_slot(&fft, input, fft_buffer);
/* Get channel estimates for each port */
for (i=0;i<MAX_PORTS;i++) {
@ -343,7 +334,7 @@ int mib_decoder_run(cf_t *input, pbch_mib_t *mib) {
}
DEBUG("Decoding PBCH\n", 0);
return pbch_decode(&pbch, fft_buffer, ce, 1, mib);
return pbch_decode(&pbch, fft_buffer, ce, mib);
}
int main(int argc, char **argv) {
@ -371,8 +362,7 @@ int main(int argc, char **argv) {
exit(-1);
}
sync_pss_det_peak_to_avg(&sfind);
sync_pss_det_peak_to_avg(&strack);
sync_pss_det_peak_to_avg(&ssync);
nof_bands = lte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN);
printf("RSSI scan: %d freqs in band %d, RSSI threshold %.2f dBm\n", nof_bands, band, rssi_threshold);
@ -438,27 +428,24 @@ int main(int argc, char **argv) {
cuhd_recv(uhd, input_buffer, FLEN, 1);
#endif
/* set find_threshold and go to FIND state */
sync_set_threshold(&sfind, find_threshold);
sync_force_N_id_2(&sfind, -1);
sync_set_threshold(&ssync, find_threshold);
state = FIND;
break;
case FIND:
/* find peak in all frame */
find_idx = sync_run(&sfind, &input_buffer[FLEN]);
DEBUG("[%3d/%d]: PAR=%.2f\n", freq, nof_bands, sync_get_peak_to_avg(&sfind));
find_idx = sync_find(&ssync, &input_buffer[FLEN]);
DEBUG("[%3d/%d]: PAR=%.2f\n", freq, nof_bands, sync_get_peak_to_avg(&ssync));
if (find_idx != -1) {
/* if found peak, go to track and set lower threshold */
frame_cnt = -1;
last_found = 0;
max_peak_to_avg = -1;
sync_set_threshold(&strack, track_threshold);
sync_force_N_id_2(&strack, sync_get_N_id_2(&sfind));
cell_id = sync_get_cell_id(&sfind);
cell_id = sync_get_cell_id(&ssync);
state = TRACK;
INFO("[%3d/%d]: EARFCN %d Freq. %.2f MHz PSS found PAR %.2f dB\n", freq, nof_bands,
channels[freq].id, channels[freq].fd,
10*log10f(sync_get_peak_to_avg(&sfind)));
10*log10f(sync_get_peak_to_avg(&ssync)));
} else {
if (frame_cnt >= nof_frames_find) {
state = INIT;
@ -469,20 +456,20 @@ int main(int argc, char **argv) {
case TRACK:
INFO("Tracking PSS find_idx %d offset %d\n", find_idx, find_idx - track_len);
track_idx = sync_run(&strack, &input_buffer[FLEN + find_idx - track_len]);
p2a_v[frame_cnt] = sync_get_peak_to_avg(&strack);
track_idx = sync_track(&ssync, &input_buffer[FLEN + find_idx - track_len]);
p2a_v[frame_cnt] = sync_get_peak_to_avg(&ssync);
/* save cell id for the best peak-to-avg */
if (p2a_v[frame_cnt] > max_peak_to_avg) {
max_peak_to_avg = p2a_v[frame_cnt];
cell_id = sync_get_cell_id(&strack);
cell_id = sync_get_cell_id(&ssync);
}
if (track_idx != -1) {
cfo_v[frame_cnt] = sync_get_cfo(&strack);
cfo_v[frame_cnt] = sync_get_cfo(&ssync);
last_found = frame_cnt;
find_idx += track_idx - track_len;
idx_v[frame_cnt] = find_idx;
nslot = sync_get_slot_id(&strack);
nslot = sync_get_slot_id(&ssync);
} else {
idx_v[frame_cnt] = -1;
cfo_v[frame_cnt] = 0.0;

@ -348,19 +348,17 @@ int main(int argc, char **argv) {
/* set find_threshold and go to FIND state */
sync_set_threshold(&sfind, find_threshold);
sync_force_N_id_2(&sfind, -1);
state = FIND;
break;
case FIND:
/* find peak in all frame */
find_idx = sync_run(&sfind, &input_buffer[FLEN]);
find_idx = sync_find(&sfind, &input_buffer[FLEN]);
DEBUG("[%3d/%d]: PAR=%.2f\n", freq, nof_bands, sync_get_peak_to_avg(&sfind));
if (find_idx != -1) {
/* if found peak, go to track and set lower threshold */
frame_cnt = -1;
last_found = 0;
sync_set_threshold(&strack, track_threshold);
sync_force_N_id_2(&strack, sync_get_N_id_2(&sfind));
state = TRACK;
INFO("[%3d/%d]: EARFCN %d Freq. %.2f MHz PSS found PAR %.2f dB\n", freq, nof_bands,
channels[freq].id, channels[freq].fd,
@ -382,7 +380,7 @@ int main(int argc, char **argv) {
filesink_write(&fs, &input_buffer[FLEN+find_idx+track_len], track_len);
track_idx = sync_run(&strack, &input_buffer[FLEN + find_idx - track_len]);
track_idx = sync_find(&strack, &input_buffer[FLEN + find_idx - track_len]);
p2a_v[frame_cnt] = sync_get_peak_to_avg(&strack);
/* save cell id for the best peak-to-avg */

@ -61,6 +61,7 @@ typedef struct LIBLTE_API{
LIBLTE_API int chest_init(chest_t *q, chest_interp_t interp, lte_cp_t cp, int nof_prb, int nof_ports);
LIBLTE_API void chest_free(chest_t *q);
LIBLTE_API void chest_set_nof_ports(chest_t *q, int nof_ports);
LIBLTE_API int chest_ref_LTEDL_slot_port(chest_t *q, int port, int nslot, int cell_id);
LIBLTE_API int chest_ref_LTEDL_slot(chest_t *q, int nslot, int cell_id);
@ -68,7 +69,9 @@ LIBLTE_API int chest_ref_LTEDL(chest_t *q, int cell_id);
LIBLTE_API void chest_ce_ref(chest_t *q, cf_t *input, int nslot, int port_id, int nref);
LIBLTE_API void chest_ce_slot_port(chest_t *q, cf_t *input, cf_t *ce, int nslot, int port_id);
LIBLTE_API void chest_ce_slot(chest_t *q, cf_t *input, cf_t **ce, int nslot);
LIBLTE_API void chest_ce_sf_port(chest_t *q, cf_t *input, cf_t *ce, int sf_idx, int port_id);
LIBLTE_API void chest_ce_slot(chest_t *q, cf_t *input, cf_t *ce[MAX_PORTS], int nslot);
LIBLTE_API void chest_ce_sf(chest_t *q, cf_t *input, cf_t *ce[MAX_PORTS], int sf_idx);
LIBLTE_API void chest_fprint(chest_t *q, FILE *stream, int nslot, int port_id);
LIBLTE_API void chest_ref_fprint(chest_t *q, FILE *stream, int nslot, int port_id);

@ -41,7 +41,6 @@
#define LTE_NIL_SYMBOL 2
#define MAX_PORTS 4
#define MAX_PORTS_CTRL 4
#define MAX_LAYERS 8
#define MAX_CODEWORDS 2
@ -82,7 +81,7 @@ typedef enum {CPNORM, CPEXT} lte_cp_t;
#define SF_LEN_CPNORM(symbol_sz) 2*SLOT_LEN_CPNORM(symbol_sz)
#define SF_LEN_CPEXT(symbol_sz) 2*SLOT_LEN_CPEXT(symbol_sz)
#define SF_LEN(symbol_sz, cp) 2*SLOT_LEN(cp, symbol_sz)
#define SF_LEN(symbol_sz, cp) (2*SLOT_LEN(symbol_sz, cp))
#define SLOT_IDX_CPNORM(idx, symbol_sz) (idx==0?(CP(symbol_sz, CPNORM_0_LEN)):(CP(symbol_sz, CPNORM_0_LEN)+idx*(symbol_sz+CP(symbol_sz, CPNORM_LEN))))
#define SLOT_IDX_CPEXT(idx, symbol_sz) (idx*(symbol_sz+CP(symbol_sz, CPEXT_LEN)))
@ -96,8 +95,13 @@ typedef enum {CPNORM, CPEXT} lte_cp_t;
#define GUARD_RE(nof_prb) ((lte_symbol_sz(nof_prb)-nof_prb*RE_X_RB)/2)
#define SYMBOL_HAS_REF(l, cp, nof_ports) ((l == 1 && nof_ports == 4) \
|| l == 0 \
|| l == CP_NSYMB(cp) - 3)
LIBLTE_API const int lte_symbol_sz(int nof_prb);
LIBLTE_API const int lte_sampling_freq_hz(int nof_prb);
LIBLTE_API int lte_re_x_prb(int ns, int symbol, int nof_ports, int nof_symbols);
LIBLTE_API int lte_voffset(int symbol_id, int cell_id, int nof_ports);
@ -105,6 +109,13 @@ LIBLTE_API int lte_voffset(int symbol_id, int cell_id, int nof_ports);
#define NOF_TC_CB_SIZES 188
typedef struct LIBLTE_API {
int nof_prb;
int nof_ports;
int cell_id;
lte_cp_t cp;
}lte_cell_t;
typedef enum LIBLTE_API {
SINGLE_ANTENNA,TX_DIVERSITY, SPATIAL_MULTIPLEX

@ -46,16 +46,19 @@ typedef struct LIBLTE_API{
int symbol_sz;
int nof_guards;
int nof_re;
lte_cp_t cp_type;
int slot_sz;
lte_cp_t cp;
cf_t *tmp; // for removing zero padding
}lte_fft_t;
LIBLTE_API int lte_fft_init(lte_fft_t *q, lte_cp_t cp_type, int nof_prb);
LIBLTE_API void lte_fft_free(lte_fft_t *q);
LIBLTE_API void lte_fft_run(lte_fft_t *q, cf_t *input, cf_t *output);
LIBLTE_API void lte_fft_run_slot(lte_fft_t *q, cf_t *input, cf_t *output);
LIBLTE_API void lte_fft_run_sf(lte_fft_t *q, cf_t *input, cf_t *output);
LIBLTE_API int lte_ifft_init(lte_fft_t *q, lte_cp_t cp_type, int nof_prb);
LIBLTE_API void lte_ifft_free(lte_fft_t *q);
LIBLTE_API void lte_ifft_run(lte_fft_t *q, cf_t *input, cf_t *output);
LIBLTE_API void lte_ifft_run_slot(lte_fft_t *q, cf_t *input, cf_t *output);
LIBLTE_API void lte_ifft_run_sf(lte_fft_t *q, cf_t *input, cf_t *output);
#endif

@ -62,9 +62,9 @@ typedef struct LIBLTE_API {
int nof_symbols;
/* buffers */
cf_t *ce[MAX_PORTS_CTRL];
cf_t *pbch_symbols[MAX_PORTS_CTRL];
cf_t *pbch_x[MAX_PORTS_CTRL];
cf_t *ce[MAX_PORTS];
cf_t *pbch_symbols[MAX_PORTS];
cf_t *pbch_x[MAX_PORTS];
cf_t *pbch_d;
float *pbch_llr;
float *temp;
@ -87,13 +87,10 @@ typedef struct LIBLTE_API {
LIBLTE_API int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp);
LIBLTE_API void pbch_free(pbch_t *q);
LIBLTE_API int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float ebno, pbch_mib_t *mib);
LIBLTE_API void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL], int nof_ports);
LIBLTE_API int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS], pbch_mib_t *mib);
LIBLTE_API void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS], int nof_ports);
LIBLTE_API void pbch_decode_reset(pbch_t *q);
LIBLTE_API void pbch_mib_fprint(FILE *stream, pbch_mib_t *mib);
LIBLTE_API bool pbch_exists(int nframe, int nslot);
LIBLTE_API int pbch_put(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp, int cell_id);
LIBLTE_API int pbch_get(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp, int cell_id);
#endif // PBCH_

@ -55,9 +55,9 @@ typedef struct LIBLTE_API {
regs_t *regs;
/* buffers */
cf_t ce[MAX_PORTS_CTRL][PCFICH_RE];
cf_t pcfich_symbols[MAX_PORTS_CTRL][PCFICH_RE];
cf_t pcfich_x[MAX_PORTS_CTRL][PCFICH_RE];
cf_t ce[MAX_PORTS][PCFICH_RE];
cf_t pcfich_symbols[MAX_PORTS][PCFICH_RE];
cf_t pcfich_x[MAX_PORTS][PCFICH_RE];
cf_t pcfich_d[PCFICH_RE];
/* bit message */
@ -73,9 +73,9 @@ typedef struct LIBLTE_API {
LIBLTE_API int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb,
int nof_tx_ports, lte_cp_t cp);
LIBLTE_API void pcfich_free(pcfich_t *q);
LIBLTE_API int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
LIBLTE_API int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS],
int nsubframe, int *cfi, int *distance);
LIBLTE_API int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL],
LIBLTE_API int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS],
int nsubframe);
LIBLTE_API bool pcfich_exists(int nframe, int nslot);

@ -44,7 +44,8 @@
typedef _Complex float cf_t;
#define PDCCH_NOF_SEARCH_MODES 3
#define PDCCH_NOF_SEARCH_MODES 3
#define MAX_CANDIDATES 32
typedef enum LIBLTE_API {
SEARCH_NONE = 3, SEARCH_SI = 0, SEARCH_RA = 1, SEARCH_UE = 2
@ -56,7 +57,7 @@ typedef enum LIBLTE_API {
*/
typedef struct LIBLTE_API {
int nof_candidates;
dci_candidate_t *candidates[NSUBFRAMES_X_FRAME];
dci_candidate_t candidates[NSUBFRAMES_X_FRAME][MAX_CANDIDATES];
} pdcch_search_t;
/* PDCCH object */
@ -76,9 +77,9 @@ typedef struct LIBLTE_API {
regs_t *regs;
/* buffers */
cf_t *ce[MAX_PORTS_CTRL];
cf_t *pdcch_symbols[MAX_PORTS_CTRL];
cf_t *pdcch_x[MAX_PORTS_CTRL];
cf_t *ce[MAX_PORTS];
cf_t *pdcch_symbols[MAX_PORTS];
cf_t *pdcch_x[MAX_PORTS];
cf_t *pdcch_d;
char *pdcch_e;
float *pdcch_llr;
@ -95,8 +96,10 @@ LIBLTE_API int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
int cell_id, lte_cp_t cp);
LIBLTE_API void pdcch_free(pdcch_t *q);
LIBLTE_API int pdcch_set_cfi(pdcch_t *q, int cfi);
/* Encoding functions */
LIBLTE_API int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS_CTRL],
LIBLTE_API int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS],
int nsubframe);
/* Decoding functions */
@ -106,10 +109,10 @@ LIBLTE_API int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS
* b) call pdcch_extract_llr() and then call pdcch_decode_si/ue/ra
*/
LIBLTE_API int pdcch_decode(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
dci_t *dci, int nsubframe, float ebno);
LIBLTE_API int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
float *llr, int nsubframe, float ebno);
LIBLTE_API int pdcch_decode(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS],
dci_t *dci, int nsubframe);
LIBLTE_API int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS],
float *llr, int nsubframe);
LIBLTE_API void pdcch_init_search_si(pdcch_t *q);
LIBLTE_API void pdcch_set_search_si(pdcch_t *q);

@ -49,43 +49,46 @@ typedef _Complex float cf_t;
/* PDSCH object */
typedef struct LIBLTE_API {
int cell_id;
lte_cp_t cp;
int nof_prb;
int nof_ports;
int max_symbols;
unsigned short rnti;
int cell_id;
lte_cp_t cp;
int nof_prb;
int nof_ports;
int max_symbols;
unsigned short rnti;
/* buffers */
cf_t *ce[MAX_PORTS];
cf_t *pdsch_symbols[MAX_PORTS];
cf_t *pdsch_x[MAX_PORTS];
cf_t *pdsch_d;
char *pdsch_e_bits;
char *cb_in_b;
char *cb_out_b;
float *pdsch_llr;
float *pdsch_rm_f;
/* buffers */
cf_t *ce[MAX_PORTS];
cf_t *pdsch_symbols[MAX_PORTS];
cf_t *pdsch_x[MAX_PORTS];
cf_t *pdsch_d;
char *pdsch_e_bits;
char *cb_in_b;
char *cb_out_b;
float *pdsch_llr;
float *pdsch_rm_f;
/* tx & rx objects */
modem_table_t mod[4];
demod_soft_t demod;
sequence_t seq_pdsch[NSUBFRAMES_X_FRAME];
tcod_t encoder;
tdec_t decoder;
rm_turbo_t rm_turbo;
crc_t crc_tb;
crc_t crc_cb;
/* tx & rx objects */
modem_table_t mod[4];
demod_soft_t demod;
sequence_t seq_pdsch[NSUBFRAMES_X_FRAME];
tcod_t encoder;
tdec_t decoder;
rm_turbo_t rm_turbo;
crc_t crc_tb;
crc_t crc_cb;
}pdsch_t;
LIBLTE_API int pdsch_init(pdsch_t *q, unsigned short user_rnti, int nof_prb,
int nof_ports, int cell_id, lte_cp_t cp);
int nof_ports, int cell_id, lte_cp_t cp);
LIBLTE_API void pdsch_free(pdsch_t *q);
LIBLTE_API int pdsch_encode(pdsch_t *q, char *data, cf_t *sf_symbols[MAX_PORTS],
int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc);
int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc);
LIBLTE_API int pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS],
char *data, int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc);
char *data, int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc);
LIBLTE_API int pdsch_get(pdsch_t *q, cf_t *sf_symbols, cf_t *pdsch_symbols,
ra_prb_t *prb_alloc, int nsubframe);
LIBLTE_API int pdsch_put(pdsch_t *q, cf_t *pdsch_symbols, cf_t *sf_symbols,
ra_prb_t *prb_alloc, int nsubframe);
#endif

@ -63,9 +63,9 @@ typedef struct LIBLTE_API {
regs_t *regs;
/* buffers */
cf_t ce[MAX_PORTS_CTRL][PHICH_MAX_NSYMB];
cf_t phich_symbols[MAX_PORTS_CTRL][PHICH_MAX_NSYMB];
cf_t phich_x[MAX_PORTS_CTRL][PHICH_MAX_NSYMB];
cf_t ce[MAX_PORTS][PHICH_MAX_NSYMB];
cf_t phich_symbols[MAX_PORTS][PHICH_MAX_NSYMB];
cf_t phich_x[MAX_PORTS][PHICH_MAX_NSYMB];
cf_t phich_d[PHICH_MAX_NSYMB];
cf_t phich_d0[PHICH_MAX_NSYMB];
cf_t phich_z[PHICH_NBITS];
@ -82,13 +82,13 @@ typedef struct LIBLTE_API {
LIBLTE_API int phich_init(phich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_tx_ports, lte_cp_t cp);
LIBLTE_API void phich_free(phich_t *q);
LIBLTE_API int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
LIBLTE_API int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS],
int ngroup, int nseq, int nsubframe, char *ack, int *distance);
LIBLTE_API int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
cf_t *slot_symbols[MAX_PORTS_CTRL]);
cf_t *slot_symbols[MAX_PORTS]);
LIBLTE_API void phich_reset(phich_t *q, cf_t *slot_symbols[MAX_PORTS_CTRL]);
LIBLTE_API void phich_reset(phich_t *q, cf_t *slot_symbols[MAX_PORTS]);
LIBLTE_API int phich_ngroups(phich_t *q);
LIBLTE_API bool phich_exists(int nframe, int nslot);
LIBLTE_API int phich_put(regs_t *h, cf_t *phich, cf_t *slot_data);

@ -94,7 +94,7 @@ LIBLTE_API int regs_phich_get(regs_t *h, cf_t *slot_symbols, cf_t phich_symbols[
LIBLTE_API int regs_phich_ngroups(regs_t *h);
LIBLTE_API int regs_phich_reset(regs_t *h, cf_t *slot_symbols);
LIBLTE_API int regs_pdcch_nregs(regs_t *h);
LIBLTE_API int regs_pdcch_nregs(regs_t *h, int cfi);
LIBLTE_API int regs_pdcch_put(regs_t *h, cf_t *pdcch_symbols, cf_t *slot_symbols);
LIBLTE_API int regs_pdcch_get(regs_t *h, cf_t *slot_symbols, cf_t *pdcch_symbols);

@ -93,11 +93,14 @@
#include "liblte/phy/scrambling/scrambling.h"
#include "liblte/phy/resampling/interp.h"
#include "liblte/phy/resampling/decim.h"
#include "liblte/phy/resampling/resample_arb.h"
#include "liblte/phy/sync/pss.h"
#include "liblte/phy/sync/sfo.h"
#include "liblte/phy/sync/sss.h"
#include "liblte/phy/sync/sync.h"
#include "liblte/phy/sync/sync_frame.h"
#include "liblte/phy/sync/cfo.h"
#ifdef __cplusplus

@ -0,0 +1,39 @@
/**
*
* \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/.
*
*/
#ifndef DECIM_H
#define DECIM_H_
#include "liblte/config.h"
typedef _Complex float cf_t;
LIBLTE_API void decim_c(cf_t *input, cf_t *output, int M, int len);
LIBLTE_API void decim_f(float *input, float *output, int M, int len);
#endif // DECIM_H

@ -34,7 +34,7 @@ typedef _Complex float cf_t;
LIBLTE_API void interp_linear_offset(cf_t *input, cf_t *output, int M, int len, int off_st, int off_end);
LIBLTE_API void interp_linear(cf_t *input, cf_t *output, int M, int len);
LIBLTE_API void interp_linear_c(cf_t *input, cf_t *output, int M, int len);
LIBLTE_API void interp_linear_f(float *input, float *output, int M, int len);
#endif // INTERP_H

@ -32,6 +32,7 @@
#include <complex.h>
#include "liblte/config.h"
#include "liblte/phy/utils/cexptab.h"
typedef _Complex float cf_t;

@ -69,20 +69,25 @@ typedef struct LIBLTE_API {
int frame_size;
int N_id_2;
float current_cfo;
bool cfo_auto; // default true
int nof_nosync_frames;
int nosync_timeout_frames; // default 5
float correlation_threshold; // default 10000
int frame_start_idx;
int fb_wp;
cf_t *pss_signal_freq;
cf_t *pss_signal_freq[3]; // One sequence for each N_id_2
cf_t *tmp_input;
float *conv_abs;
cf_t *frame_buffer;
cf_t *conv_output;
#ifdef ENABLE_HL
cf_t *frame_buffer;
cf_t *tmp_nco;
float current_cfo;
bool cfo_auto;
int nof_nosync_frames;
int nosync_timeout_frames;
float correlation_threshold;
int frame_start_idx;
int fb_wp;
#endif
}pss_synch_t;
typedef enum { PSS_TX, PSS_RX } pss_direction_t;

@ -53,7 +53,6 @@ struct sss_tables{
int z1[N_SSS][N_SSS];
int c[2][N_SSS];
int s[N_SSS][N_SSS];
int N_id_2;
};
/* Allocate 32 complex to make it multiple of 32-byte AVX instructions alignment requirement.
@ -74,9 +73,10 @@ typedef struct LIBLTE_API {
float corr_peak_threshold;
int symbol_sz;
int subframe_sz;
int N_id_2;
int N_id_1_table[30][30];
struct fc_tables fc_tables;
struct fc_tables fc_tables[3]; // one for each N_id_2
}sss_synch_t;

@ -32,13 +32,13 @@
#include <stdbool.h>
#include "liblte/config.h"
#include "pss.h"
#include "sss.h"
#include "sfo.h"
#include "liblte/phy/sync/pss.h"
#include "liblte/phy/sync/sss.h"
/**
*
* This object performs time and frequency synchronization using the PSS and SSS signals.
*
* The object is designed to work with signals sampled at 1.92 Mhz centered at the carrier frequency.
* Thus, downsampling is required if the signal is sampled at higher frequencies.
*
@ -49,28 +49,36 @@
enum sync_pss_det { ABSOLUTE, PEAK_MEAN};
#define TRACK_THRESHOLD 10.0
#define TRACK_LEN 300
typedef struct LIBLTE_API {
pss_synch_t pss[3]; // One for each N_id_2
sss_synch_t sss[3]; // One for each N_id_2
pss_synch_t pss;
pss_synch_t pss_track;
sss_synch_t sss;
enum sync_pss_det pss_mode;
float threshold;
float peak_to_avg;
int force_N_id_2;
int N_id_2;
int N_id_1;
int slot_id;
float cfo;
lte_cp_t cp;
bool detect_cp;
bool sss_en;
lte_cp_t cp;
}sync_t;
LIBLTE_API int sync_init(sync_t *q, int frame_size);
LIBLTE_API void sync_free(sync_t *q);
/* Runs the synchronization algorithm. input signal must be sampled at 1.92 MHz and should be frame_size long at least */
LIBLTE_API int sync_run(sync_t *q, cf_t *input);
/* Finds a correlation peak in the input signal. The signal must be sampled at 1.92 MHz and should be
subframe_size long at least */
LIBLTE_API int sync_find(sync_t *q, cf_t *input);
/* Tracks the correlation peak in the input signal. The signal must be sampled at 1.92 MHz and should be
TRACK_LEN long at least */
LIBLTE_API int sync_track(sync_t *q, cf_t *input);
/* Sets the threshold for peak comparison */
LIBLTE_API void sync_set_threshold(sync_t *q, float threshold);
@ -79,14 +87,6 @@ LIBLTE_API void sync_pss_det_absolute(sync_t *q);
/* Set peak comparison to relative to the mean */
LIBLTE_API void sync_pss_det_peak_to_avg(sync_t *q);
/* Forces the synchronizer to check one N_id_2 PSS sequence only (useful for tracking mode) */
LIBLTE_API void sync_force_N_id_2(sync_t *q, int force_N_id_2);
/* Forces the synchronizer to skip CP detection (useful for tracking mode) */
LIBLTE_API void sync_force_cp(sync_t *q, lte_cp_t cp);
/* Enables/Disables SSS detection (useful for tracking mode) */
LIBLTE_API void sync_sss_en(sync_t *q, bool enabled);
/* Gets the slot id (0 or 10) */
LIBLTE_API int sync_get_slot_id(sync_t *q);
/* Gets the last peak-to-average ratio */
@ -101,6 +101,10 @@ LIBLTE_API int sync_get_cell_id(sync_t *q);
LIBLTE_API float sync_get_cfo(sync_t *q);
/* Gets the CP length estimation from the last call to synch_run() */
LIBLTE_API lte_cp_t sync_get_cp(sync_t *q);
/* Enables/Disables SSS detection */
LIBLTE_API void sync_sss_en(sync_t *q, bool enabled);
/* Enables/Disables CP detection */
LIBLTE_API void sync_cp_en(sync_t *q, bool enabled);
#endif // SYNC_

@ -0,0 +1,106 @@
/**
*
* \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/.
*
*/
#ifndef SYNC_FRAME_
#define SYNC_FRAME_
#include <stdbool.h>
#include "liblte/config.h"
#include "liblte/phy/sync/sync.h"
#include "liblte/phy/sync/cfo.h"
/**
*
* Uses sync object to automatically manage the FIND and TRACKING states.
* It is suposed to work on a subframe basis. The input signal must be sampled at
* a frequency integer multiple of 1.92 MHz. The signal is internally downsampled
* and fed to the sync object.
*
* This object also deals with frame alignment and CFO correction, returning an
* output signal aligned both in time and frequency.
*/
enum sync_frame_state { SF_FIND, SF_TRACK };
#define SYNC_SF_LEN 1920 // 1ms at 1.92 MHz
#define TRACK_MAX_LOST 10
typedef struct LIBLTE_API {
sync_t s;
enum sync_frame_state state;
int downsampling;
unsigned long frame_cnt;
bool fb_wp;
int frame_size;
cf_t *input_buffer;
cf_t *input_downsampled;
cfo_t cfocorr;
float cur_cfo;
int peak_idx;
int cell_id;
float timeoffset;
int last_found;
int sf_idx;
}sync_frame_t;
/* Initializes the automatic tracker, setting the downsampling ratio for the input signal.
* upsampled is the ratio of the provided signal sampling frequency to 1.92 Mhz. E.g. if input is sampled at 3.84 Mhz,
* upsampled should be 2.
*/
LIBLTE_API int sync_frame_init(sync_frame_t *q, int upsampled);
LIBLTE_API void sync_frame_free(sync_frame_t *q);
LIBLTE_API void sync_frame_set_threshold(sync_frame_t *q, float threshold);
LIBLTE_API int sync_frame_cell_id(sync_frame_t *q);
LIBLTE_API int sync_frame_sfidx(sync_frame_t *q);
/* Automatically time/freq synchronizes the input signal. Returns 1 if the signal is synched and locked,
* and fills the output buffer with the time and frequency aligned version of the signal.
* If 0 is returned, the PSS was not found. -1 is returned in case of error.
*
* The provided signal can be sampled at an integer multiple of 1.92 Mhz.
* The sampling ratio is provided when calling the sync_auto_reset() function.
*
* The buffer input must have subframe_size samples (used in sync_init)
*/
LIBLTE_API int sync_frame_push(sync_frame_t *q, cf_t *input, cf_t *output);
/* Resets the automatic tracker */
LIBLTE_API void sync_frame_reset(sync_frame_t *q);
#endif // SYNC_FRAME_

@ -44,6 +44,7 @@ LIBLTE_API extern int verbose;
#define VERBOSE_ISINFO() (verbose>=VERBOSE_INFO)
#define VERBOSE_ISDEBUG() (verbose>=VERBOSE_DEBUG)
#define VERBOSE_ISNONE() (verbose==VERBOSE_NONE)
#define PRINT_DEBUG verbose=VERBOSE_DEBUG
#define PRINT_INFO verbose=VERBOSE_INFO

@ -46,6 +46,15 @@ void chest_fprint(chest_t *q, FILE *stream, int nslot, int port_id) {
chest_ce_fprint(q, stream, nslot, port_id);
}
/* Sets the number of ports to estimate. nof_ports must be smaler than nof_ports
* used during the call to chest_init().
*/
void chest_set_nof_ports(chest_t *q, int nof_ports) {
if (nof_ports < q->nof_ports && nof_ports > 0) {
q->nof_ports = nof_ports;
}
}
void chest_ref_fprint(chest_t *q, FILE *stream, int nslot, int port_id) {
int i;
fprintf(stream, "refs%d=[",port_id);
@ -149,8 +158,18 @@ void chest_ce_slot_port(chest_t *q, cf_t *input, cf_t *ce, int nslot, int port_i
}
}
/* Computes channel estimates for each reference in a slot.
* Saves the result for the p-th port to the pointer ce[p]
/* Computes channel estimates for each reference in a subframe and port id.
*/
void chest_ce_sf_port(chest_t *q, cf_t *input, cf_t *ce, int sf_idx, int port_id) {
int n, slotsz;
slotsz = CP_NSYMB(q->cp)*q->nof_prb*RE_X_RB;
for (n=0;n<2;n++) {
chest_ce_slot_port(q, &input[n*slotsz], &ce[n*slotsz], 2*sf_idx+n, port_id);
}
}
/* Computes channel estimates for each reference in a slot for all ports.
*/
void chest_ce_slot(chest_t *q, cf_t *input, cf_t **ce, int nslot) {
int p;
@ -159,6 +178,17 @@ void chest_ce_slot(chest_t *q, cf_t *input, cf_t **ce, int nslot) {
}
}
/* Computes channel estimates for each reference in a subframe for all ports.
*/
void chest_ce_sf(chest_t *q, cf_t *input, cf_t *ce[MAX_PORTS], int sf_idx) {
int p, n, slotsz;
slotsz = CP_NSYMB(q->cp)*q->nof_prb*RE_X_RB;
for (p=0;p<q->nof_ports;p++) {
for (n=0;n<2;n++) {
chest_ce_slot_port(q, &input[n*slotsz], &ce[p][n*slotsz], 2*sf_idx+n, p);
}
}
}
int chest_init(chest_t *q, chest_interp_t interp, lte_cp_t cp, int nof_prb, int nof_ports) {
if (nof_ports > MAX_PORTS) {

@ -35,7 +35,7 @@
#include "liblte/phy/utils/debug.h"
#include "liblte/phy/utils/vector.h"
int lte_fft_init_(lte_fft_t *q, lte_cp_t cp_type, int nof_prb, dft_dir_t dir) {
int lte_fft_init_(lte_fft_t *q, lte_cp_t cp, int nof_prb, dft_dir_t dir) {
int symbol_sz = lte_symbol_sz(nof_prb);
if (symbol_sz == -1) {
@ -57,13 +57,15 @@ int lte_fft_init_(lte_fft_t *q, lte_cp_t cp_type, int nof_prb, dft_dir_t dir) {
dft_plan_set_dc(&q->fft_plan, true);
q->symbol_sz = symbol_sz;
q->nof_symbols = CP_NSYMB(cp_type);
q->cp_type = cp_type;
q->nof_symbols = CP_NSYMB(cp);
q->cp = cp;
q->nof_re = nof_prb * RE_X_RB;
q->nof_guards = ((symbol_sz - q->nof_re) / 2);
DEBUG("Init %s symbol_sz=%d, nof_symbols=%d, cp_type=%s, nof_re=%d, nof_guards=%d\n",
q->slot_sz = SLOT_LEN(symbol_sz, cp);
DEBUG("Init %s symbol_sz=%d, nof_symbols=%d, cp=%s, nof_re=%d, nof_guards=%d\n",
dir==FORWARD?"FFT":"iFFT", q->symbol_sz, q->nof_symbols,
q->cp_type==CPNORM?"Normal":"Extended", q->nof_re, q->nof_guards);
q->cp==CPNORM?"Normal":"Extended", q->nof_re, q->nof_guards);
return 0;
}
@ -75,17 +77,17 @@ void lte_fft_free_(lte_fft_t *q) {
bzero(q, sizeof(lte_fft_t));
}
int lte_fft_init(lte_fft_t *q, lte_cp_t cp_type, int nof_prb) {
return lte_fft_init_(q, cp_type, nof_prb, FORWARD);
int lte_fft_init(lte_fft_t *q, lte_cp_t cp, int nof_prb) {
return lte_fft_init_(q, cp, nof_prb, FORWARD);
}
void lte_fft_free(lte_fft_t *q) {
lte_fft_free_(q);
}
int lte_ifft_init(lte_fft_t *q, lte_cp_t cp_type, int nof_prb) {
int lte_ifft_init(lte_fft_t *q, lte_cp_t cp, int nof_prb) {
int i;
if (lte_fft_init_(q, cp_type, nof_prb, BACKWARD)) {
if (lte_fft_init_(q, cp, nof_prb, BACKWARD)) {
return -1;
}
/* set now zeros at CP */
@ -103,10 +105,10 @@ void lte_ifft_free(lte_fft_t *q) {
/* Transforms input samples into output OFDM symbols.
* Performs FFT on a each symbol and removes CP.
*/
void lte_fft_run(lte_fft_t *q, cf_t *input, cf_t *output) {
void lte_fft_run_slot(lte_fft_t *q, cf_t *input, cf_t *output) {
int i;
for (i=0;i<q->nof_symbols;i++) {
input += CP_ISNORM(q->cp_type)?CP_NORM(i, q->symbol_sz):CP_EXT(q->symbol_sz);
input += CP_ISNORM(q->cp)?CP_NORM(i, q->symbol_sz):CP_EXT(q->symbol_sz);
dft_run_c(&q->fft_plan, input, q->tmp);
memcpy(output, &q->tmp[q->nof_guards], q->nof_re * sizeof(cf_t));
input += q->symbol_sz;
@ -114,13 +116,20 @@ void lte_fft_run(lte_fft_t *q, cf_t *input, cf_t *output) {
}
}
void lte_fft_run_sf(lte_fft_t *q, cf_t *input, cf_t *output) {
int n;
for (n=0;n<2;n++) {
lte_fft_run_slot(q, &input[n*q->slot_sz], &output[n*q->nof_re*q->nof_symbols]);
}
}
/* Transforms input OFDM symbols into output samples.
* Performs FFT on a each symbol and adds CP.
*/
void lte_ifft_run(lte_fft_t *q, cf_t *input, cf_t *output) {
void lte_ifft_run_slot(lte_fft_t *q, cf_t *input, cf_t *output) {
int i, cp_len;
for (i=0;i<q->nof_symbols;i++) {
cp_len = CP_ISNORM(q->cp_type)?CP_NORM(i, q->symbol_sz):CP_EXT(q->symbol_sz);
cp_len = CP_ISNORM(q->cp)?CP_NORM(i, q->symbol_sz):CP_EXT(q->symbol_sz);
memcpy(&q->tmp[q->nof_guards], input, q->nof_re * sizeof(cf_t));
dft_run_c(&q->fft_plan, q->tmp, &output[cp_len]);
input += q->nof_re;
@ -130,3 +139,9 @@ void lte_ifft_run(lte_fft_t *q, cf_t *input, cf_t *output) {
}
}
void lte_ifft_run_sf(lte_fft_t *q, cf_t *input, cf_t *output) {
int n;
for (n=0;n<2;n++) {
lte_ifft_run_slot(q, &input[n*q->nof_re*q->nof_symbols], &output[n*q->slot_sz]);
}
}

@ -77,6 +77,9 @@ int lte_find_cb_index(int long_cb) {
}
}
const int lte_sampling_freq_hz(int nof_prb) {
return 15000 * lte_symbol_sz(nof_prb);
}
const int lte_symbol_sz(int nof_prb) {
if (nof_prb<=0) {
return -1;

@ -111,8 +111,8 @@ int main(int argc, char **argv) {
input[i] = 100 * ((float) rand()/RAND_MAX + (float) I*rand()/RAND_MAX);
}
lte_ifft_run(&ifft, input, outfft);
lte_fft_run(&fft, outfft, outifft);
lte_ifft_run_slot(&ifft, input, outfft);
lte_fft_run_slot(&fft, outfft, outifft);
/* compute MSE */

@ -185,7 +185,9 @@ int viterbi_init(viterbi_t *q, viterbi_type_t type, int poly[3],
}
void viterbi_free(viterbi_t *q) {
q->free(q);
if (q->free) {
q->free(q);
}
}
/* symbols are real-valued */

@ -364,6 +364,7 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
ra_nprb_dl(data, nof_prb));
}
mcs = ra_mcs_to_table_idx(&data->mcs);
data->mcs.mcs_idx = mcs;
}
bit_pack(mcs, &y, 5);
@ -425,7 +426,7 @@ int dci_format1_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
return -1;
}
/* pack MCS according to 7.1.7 of 36.213 */
/* unpack MCS according to 7.1.7 of 36.213 */
uint32_t mcs = bit_unpack(&y, 5);
data->mcs.mcs_idx = mcs;
ra_mcs_from_idx_dl(mcs, &data->mcs);

@ -55,6 +55,7 @@ int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id,
int i;
cf_t *ptr;
assert(cell_id >= 0);
if (put) {
ptr = input;
output += nof_prb * RE_X_RB / 2 - 36;
@ -65,16 +66,31 @@ int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id,
/* symbol 0 & 1 */
for (i = 0; i < 2; i++) {
prb_cp_ref(&input, &output, cell_id % 3, 4, 6, put);
prb_cp_ref(&input, &output, cell_id % 3, 4, 4*6, put);
if (put) {
output += nof_prb * RE_X_RB - 2*36;
} else {
input += nof_prb * RE_X_RB - 2*36;
}
}
/* symbols 2 & 3 */
if (CP_ISNORM(cp)) {
for (i = 0; i < 2; i++) {
prb_cp(&input, &output, 6);
if (put) {
output += nof_prb * RE_X_RB - 2*36;
} else {
input += nof_prb * RE_X_RB - 2*36;
}
}
} else {
prb_cp(&input, &output, 6);
prb_cp_ref(&input, &output, cell_id % 3, 4, 6, put);
if (put) {
output += nof_prb * RE_X_RB - 2*36;
} else {
input += nof_prb * RE_X_RB - 2*36;
}
prb_cp_ref(&input, &output, cell_id % 3, 4, 4*6, put);
}
if (put) {
return input - ptr;
@ -147,7 +163,7 @@ int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp) {
goto clean;
}
int i;
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
q->ce[i] = malloc(sizeof(cf_t) * q->nof_symbols);
if (!q->ce[i]) {
goto clean;
@ -198,7 +214,7 @@ void pbch_free(pbch_t *q) {
free(q->pbch_d);
}
int i;
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
if (q->ce[i]) {
free(q->ce[i]);
}
@ -422,8 +438,7 @@ int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n,
*
* Returns 1 if successfully decoded MIB, 0 if not and -1 on error
*/
int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
float ebno, pbch_mib_t *mib) {
int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS], pbch_mib_t *mib) {
int src, dst, res, nb;
int nant_[3] = { 1, 2, 4 };
int na, nant;
@ -434,10 +449,10 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
cf_t *x[MAX_LAYERS];
/* number of layers equals number of ports */
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
x[i] = q->pbch_x[i];
}
memset(&x[MAX_PORTS_CTRL], 0, sizeof(cf_t*) * (MAX_LAYERS - MAX_PORTS_CTRL));
memset(&x[MAX_PORTS], 0, sizeof(cf_t*) * (MAX_LAYERS - MAX_PORTS));
/* extract symbols */
if (q->nof_symbols
@ -448,7 +463,7 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
}
/* extract channel estimates */
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
if (q->nof_symbols
!= pbch_get(ce[i], q->ce[i], q->nof_prb, q->cp, q->cell_id)) {
fprintf(stderr, "There was an error getting the PBCH symbols\n");
@ -477,7 +492,7 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
}
/* demodulate symbols */
demod_soft_sigma_set(&q->demod, ebno);
demod_soft_sigma_set(&q->demod, 1.0);
demod_soft_demodulate(&q->demod, q->pbch_d,
&q->pbch_llr[nof_bits * (q->frame_idx - 1)], q->nof_symbols);
@ -510,11 +525,11 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
/** Converts the MIB message to symbols mapped to SLOT #1 ready for transmission
*/
void pbch_encode(pbch_t *q, pbch_mib_t *mib,
cf_t *slot1_symbols[MAX_PORTS_CTRL], int nof_ports) {
cf_t *slot1_symbols[MAX_PORTS], int nof_ports) {
int i;
int nof_bits = 2 * q->nof_symbols;
assert(nof_ports <= MAX_PORTS_CTRL);
assert(nof_ports <= MAX_PORTS);
/* Set pointers for layermapping & precoding */
cf_t *x[MAX_LAYERS];

@ -139,7 +139,7 @@ int pcfich_cfi_encode(int cfi, char bits[PCFICH_CFI_LEN]) {
*
* Returns 1 if successfully decoded the CFI, 0 if not and -1 on error
*/
int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS],
int nsubframe, int *cfi, int *distance) {
int dist;
@ -154,7 +154,7 @@ int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
}
/* number of layers equals number of ports */
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
x[i] = q->pcfich_x[i];
}
for (i = 0; i < MAX_PORTS; i++) {
@ -208,7 +208,7 @@ int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
/** Encodes CFI and maps symbols to the slot
*/
int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL],
int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS],
int nsubframe) {
int i;
@ -229,7 +229,7 @@ int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL],
symbols_precoding[i] = q->pcfich_symbols[i];
}
/* pack MIB */
/* pack CFI */
pcfich_cfi_encode(cfi, q->data);
/* scramble for slot sequence nslot */

@ -89,8 +89,6 @@ int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits,
if (!subframe) {
INFO("UE-specific candidates for RNTI: 0x%x, NofBits: %d, NofCCE: %d\n",
rnti, nof_bits, nof_cce);
if (VERBOSE_ISINFO())
printf("[INFO]: ");
}
for (l = 3; l >= 0; l--) {
L = (1 << l);
@ -103,39 +101,31 @@ int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits,
Yk = (39827 * Yk) % 65537;
}
c[k].ncce = L * ((Yk + i) % (nof_cce / L));
if (!subframe) {
if (VERBOSE_ISINFO()) {
printf("(%d, %d), ", c[k].ncce, c[k].L);
}
if (VERBOSE_ISDEBUG()) {
printf("sf %d - (%d, %d), ", subframe, c[k].ncce, c[k].L);
}
k++;
}
}
if (!subframe) {
if (VERBOSE_ISINFO())
printf("\n");
if (VERBOSE_ISDEBUG()) {
printf("\n");
}
return k;
}
void pdcch_init_common(pdcch_t *q, pdcch_search_t *s, unsigned short rnti) {
int k, i;
s->nof_candidates = NOF_COMMON_FORMATS
* (MIN(q->nof_cce,16) / 4 + MIN(q->nof_cce,16) / 8);
if (s->nof_candidates) {
s->candidates[0] = malloc(sizeof(dci_candidate_t) * s->nof_candidates);
dci_candidate_t *c = s->candidates[0];
s->nof_candidates = 0;
if (c) {
// Format 1A and 1C L=4 and L=8, 4 and 2 candidates, only if nof_cce > 16
k = 0;
for (i = 0; i < NOF_COMMON_FORMATS; i++) {
k += gen_common_search(&c[k], q->nof_cce,
dci_format_sizeof(common_formats[i], q->nof_prb), SIRNTI);
s->nof_candidates++;
}
}
dci_candidate_t *c = s->candidates[0];
s->nof_candidates = 0;
// Format 1A and 1C L=4 and L=8, 4 and 2 candidates, only if nof_cce > 16
k = 0;
for (i = 0; i < NOF_COMMON_FORMATS && k < MAX_CANDIDATES; i++) {
k += gen_common_search(&c[k], q->nof_cce,
dci_format_sizeof(common_formats[i], q->nof_prb), SIRNTI);
}
s->nof_candidates=k;
INFO("Initiated %d candidate(s) in the Common search space for RNTI: 0x%x\n",
s->nof_candidates, rnti);
}
/** 36.213 v9.3 Table 7.1-1: System Information DCI messages
@ -151,30 +141,23 @@ void pdcch_init_search_si(pdcch_t *q) {
* DCI Format 1A and 1 + PUSCH scheduling format 0
*/
void pdcch_init_search_ue(pdcch_t *q, unsigned short c_rnti) {
int l, n, k, i;
int n, k, i;
pdcch_search_t *s = &q->search_mode[SEARCH_UE];
s->nof_candidates = 0;
for (l = 0; l < 3; l++) {
s->nof_candidates += NOF_UE_FORMATS * (MIN(q->nof_cce,16) / (1 << l));
}
INFO(
"Initiating %d candidate(s) in the UE-specific search space for C-RNTI: 0x%x\n",
s->nof_candidates, c_rnti);
if (s->nof_candidates) {
for (n = 0; n < NSUBFRAMES_X_FRAME; n++) {
s->candidates[n] = malloc(sizeof(dci_candidate_t) * s->nof_candidates);
dci_candidate_t *c = s->candidates[n];
if (c) {
// Expect Formats 1, 1A, 0
k = 0;
for (i = 0; i < NOF_UE_FORMATS; i++) {
k += gen_ue_search(&c[k], q->nof_cce,
dci_format_sizeof(ue_formats[i], q->nof_prb), c_rnti, n);
}
}
for (n = 0; n < NSUBFRAMES_X_FRAME; n++) {
dci_candidate_t *c = s->candidates[n];
if (!n) s->nof_candidates = 0;
// Expect Formats 1, 1A, 0
k = 0;
for (i = 0; i < NOF_UE_FORMATS && k < MAX_CANDIDATES; i++) {
k += gen_ue_search(&c[k], q->nof_cce,
dci_format_sizeof(ue_formats[i], q->nof_prb), c_rnti, n);
}
s->nof_candidates = k;
}
INFO("Initiated %d candidate(s) in the UE-specific search space for C-RNTI: 0x%x\n",
s->nof_candidates, c_rnti);
q->current_search_mode = SEARCH_UE;
}
@ -196,6 +179,24 @@ void pdcch_set_search_ra(pdcch_t *q) {
q->current_search_mode = SEARCH_RA;
}
int pdcch_set_cfi(pdcch_t *q, int cfi) {
if (cfi == -1) {
q->nof_bits = -1;
q->nof_symbols = -1;
q->nof_cce = -1;
q->nof_regs = -1;
return 0;
} else if (cfi < 4 && cfi > 0) {
q->nof_regs = (regs_pdcch_nregs(q->regs, cfi) / 9) * 9;
q->nof_cce = q->nof_regs / 9;
q->nof_symbols = 4 * q->nof_regs;
q->nof_bits = 2 * q->nof_symbols;
return 0;
} else {
return -1;
}
}
/** Initializes the PDCCH transmitter and receiver */
int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
int cell_id, lte_cp_t cp) {
@ -205,7 +206,7 @@ int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
if (cell_id < 0) {
return -1;
}
if (nof_ports > MAX_PORTS_CTRL) {
if (nof_ports > MAX_PORTS) {
fprintf(stderr, "Invalid number of ports %d\n", nof_ports);
return -1;
}
@ -217,10 +218,10 @@ int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
q->nof_prb = nof_prb;
q->current_search_mode = SEARCH_NONE;
q->nof_regs = (regs_pdcch_nregs(q->regs) / 9) * 9;
q->nof_cce = q->nof_regs / 9;
q->nof_symbols = 4 * q->nof_regs;
q->nof_bits = 2 * q->nof_symbols;
/* Now allocate memory for the maximum number of REGs (CFI=2), then can
* be changed at runtime
*/
pdcch_set_cfi(q, 3);
INFO("Init PDCCH: %d CCEs (%d REGs), %d bits, %d symbols, %d ports\n",
q->nof_cce, q->nof_regs, q->nof_bits, q->nof_symbols, q->nof_ports);
@ -262,7 +263,7 @@ int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
goto clean;
}
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
q->ce[i] = malloc(sizeof(cf_t) * q->nof_symbols);
if (!q->ce[i]) {
goto clean;
@ -276,6 +277,10 @@ int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
goto clean;
}
}
/* Reset CFI to make sure we return error if new CFI is not set */
pdcch_set_cfi(q, -1);
ret = 0;
clean: if (ret == -1) {
pdcch_free(q);
@ -284,15 +289,8 @@ int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
}
void pdcch_free(pdcch_t *q) {
int i, j;
int i;
for (i = 0; i < PDCCH_NOF_SEARCH_MODES; i++) {
for (j = 0; j < NSUBFRAMES_X_FRAME; j++) {
if (q->search_mode[i].candidates[j]) {
free(q->search_mode[i].candidates[j]);
}
}
}
if (q->pdcch_e) {
free(q->pdcch_e);
}
@ -302,7 +300,7 @@ void pdcch_free(pdcch_t *q) {
if (q->pdcch_d) {
free(q->pdcch_d);
}
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
if (q->ce[i]) {
free(q->ce[i]);
}
@ -362,7 +360,7 @@ unsigned short dci_decode(pdcch_t *q, float *e, char *data, int E, int nof_bits)
int pdcch_decode_candidate(pdcch_t *q, float *llr, dci_candidate_t *c,
dci_msg_t *msg) {
unsigned short crc_res;
DEBUG("Trying Candidate: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n",
INFO("Trying Candidate: Nbits: %d, E: %3d, nCCE: %d, L: %d, RNTI: 0x%x\n",
c->nof_bits, PDCCH_FORMAT_NOF_BITS(c->L), c->ncce, c->L, c->rnti);
crc_res = dci_decode(q, &llr[72 * c->ncce], msg->data,
PDCCH_FORMAT_NOF_BITS(c->L), c->nof_bits);
@ -376,20 +374,20 @@ int pdcch_decode_candidate(pdcch_t *q, float *llr, dci_candidate_t *c,
return 0;
}
int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
float *llr, int nsubframe, float ebno) {
int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS],
float *llr, int nsubframe) {
/* Set pointers for layermapping & precoding */
int i;
cf_t *x[MAX_LAYERS];
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
fprintf(stderr, "Invalid subframe %d\n", nsubframe);
if (q->nof_bits == -1 || q->nof_cce == -1 || q->nof_regs == -1) {
fprintf(stderr, "Must call pdcch_set_cfi() first to set the CFI\n");
return -1;
}
if (ebno == 0.0) {
fprintf(stderr, "EbNo is Zero\n");
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
fprintf(stderr, "Invalid subframe %d\n", nsubframe);
return -1;
}
@ -435,7 +433,7 @@ int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
}
/* demodulate symbols */
demod_soft_sigma_set(&q->demod, ebno);
demod_soft_sigma_set(&q->demod, 1.0);
demod_soft_demodulate(&q->demod, q->pdcch_d, q->pdcch_llr, q->nof_symbols);
DEBUG("llr: ", 0);
@ -489,10 +487,15 @@ int pdcch_decode_ue(pdcch_t *q, float *llr, dci_t *dci, int nsubframe) {
*
* Returns number of messages stored in dci
*/
int pdcch_decode(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
dci_t *dci, int nsubframe, float ebno) {
int pdcch_decode(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS],
dci_t *dci, int nsubframe) {
if (q->nof_bits == -1 || q->nof_cce == -1 || q->nof_regs == -1) {
fprintf(stderr, "Must call pdcch_set_cfi() first to set the CFI\n");
return -1;
}
if (pdcch_extract_llr(q, slot_symbols, ce, q->pdcch_llr, nsubframe, ebno)) {
if (pdcch_extract_llr(q, slot_symbols, ce, q->pdcch_llr, nsubframe)) {
return -1;
}
@ -547,12 +550,16 @@ void dci_encode(pdcch_t *q, char *data, char *e, int nof_bits, int E,
/** Converts the set of DCI messages to symbols mapped to the slot ready for transmission
*/
int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS_CTRL],
int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS],
int nsubframe) {
int i;
/* Set pointers for layermapping & precoding */
cf_t *x[MAX_LAYERS];
if (q->nof_bits == -1 || q->nof_cce == -1 || q->nof_regs == -1) {
fprintf(stderr, "Must call pdcch_set_cfi() first to set the CFI\n");
return -1;
}
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
fprintf(stderr, "Invalid subframe %d\n", nsubframe);
return -1;

@ -44,10 +44,7 @@
const enum modem_std modulations[4] =
{ LTE_BPSK, LTE_QPSK, LTE_QAM16, LTE_QAM64 };
#define MAX_PDSCH_RE(cp) (2 * (CP_NSYMB(cp) - 1) * 12 - 6)
#define HAS_REF(l, cp, nof_ports) ((l == 1 && nof_ports == 4) \
|| l == 0 \
|| l == CP_NSYMB(cp) - 3)
#define MAX_PDSCH_RE(cp) (2 * CP_NSYMB(cp) * 12)
int pdsch_cp(pdsch_t *q, cf_t *input, cf_t *output, ra_prb_t *prb_alloc,
int nsubframe, bool put) {
@ -56,9 +53,9 @@ int pdsch_cp(pdsch_t *q, cf_t *input, cf_t *output, ra_prb_t *prb_alloc,
cf_t *in_ptr = input, *out_ptr = output;
int offset;
assert(q->cell_id >= 0);
assert(q->cell_id >= 0);
INFO("%s %d RE from %d PRB\n", put ? "Putting" : "Getting",
INFO("%s %d RE from %d PRB\n", put ? "Putting" : "Getting",
prb_alloc->re_sf[nsubframe], prb_alloc->slot[0].nof_prb);
if (q->nof_ports == 1) {
@ -68,14 +65,14 @@ assert(q->cell_id >= 0);
}
for (s = 0; s < 2; s++) {
if (s == 0) {
lstart = prb_alloc->lstart;
} else {
lstart = 0;
}
for (l = lstart; l < CP_NSYMB(q->cp); l++) {
for (l = 0; l < CP_NSYMB(q->cp); l++) {
for (n = 0; n < prb_alloc->slot[s].nof_prb; n++) {
if (s == 0) {
lstart = prb_alloc->lstart;
} else {
lstart = 0;
}
lend = CP_NSYMB(q->cp);
is_pbch = is_sss = false;
@ -103,31 +100,36 @@ assert(q->cell_id >= 0);
in_ptr = &input[(lp * q->nof_prb + prb_alloc->slot[s].prb_idx[n])
* RE_X_RB];
}
if (is_pbch && (q->nof_prb % 2)
&& (prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 - 3
&& prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 + 3)) {
if (l < lstart) {
prb_cp_half(&in_ptr, &out_ptr, 1);
}
}
if (l >= lstart && l < lend) {
if (HAS_REF(l, q->cp, q->nof_ports)) {
if (SYMBOL_HAS_REF(l, q->cp, q->nof_ports)) {
if (nof_refs == 2 && l != 0) {
offset = q->cell_id % 3 + 3;
} else {
offset = q->cell_id % 3;
}
prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, 1, put);
prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs, put);
} else {
prb_cp(&in_ptr, &out_ptr, 1);
}
}
if (is_sss && (q->nof_prb % 2)
&& (prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 - 3
&& prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 + 3)) {
if (l >= lend) {
prb_cp_half(&in_ptr, &out_ptr, 1);
if ((q->nof_prb % 2) && ((is_pbch && l < lstart) || (is_sss && l >= lend))) {
if (prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 - 3) {
if (SYMBOL_HAS_REF(l, q->cp, q->nof_ports)) {
prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs/2, put);
} else {
prb_cp_half(&in_ptr, &out_ptr, 1);
}
} else if (prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 + 3) {
if (put) {
out_ptr += 6;
} else {
in_ptr += 6;
}
if (SYMBOL_HAS_REF(l, q->cp, q->nof_ports)) {
prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs/2, put);
} else {
prb_cp_half(&in_ptr, &out_ptr, 1);
}
}
}
}
@ -135,9 +137,9 @@ assert(q->cell_id >= 0);
}
if (put) {
return (int) (input - in_ptr);
return abs((int) (input - in_ptr));
} else {
return (int) (output - out_ptr);
return abs((int) (output - out_ptr));
}
}
@ -421,11 +423,6 @@ int pdsch_decode_tb(pdsch_t *q, char *data, int tbs, int nb_e, int rv_idx) {
//crc_attach(&q->crc_cb, q->pdsch_b[wp], cb_len);
}
if (VERBOSE_ISDEBUG()) {
DEBUG("CB#%d Len=%d: ", i, cb_len);
vec_fprint_b(stdout, q->cb_in_b, cb_len);
}
/* Copy data to another buffer, removing the Codeblock CRC */
if (i < cbs.C - 1) {
memcpy(&data[wp], &q->cb_in_b[F], (rlen - F) * sizeof(char));
@ -450,13 +447,6 @@ int pdsch_decode_tb(pdsch_t *q, char *data, int tbs, int nb_e, int rv_idx) {
// check parity bits
par_tx = bit_unpack(&p_parity, 24);
if (VERBOSE_ISDEBUG()) {
DEBUG("DATA: ", 0);
vec_fprint_b(stdout, data, tbs);
DEBUG("PARITY: ", 0);
vec_fprint_b(stdout, parity, 24);
}
if (!par_rx) {
printf("\n\tCAUTION!! Received all-zero transport block\n\n");
}
@ -470,7 +460,7 @@ int pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS], char *data,
int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc) {
/* Set pointers for layermapping & precoding */
int i;
int i, n;
cf_t *x[MAX_LAYERS];
int nof_symbols, nof_bits, nof_bits_e;
@ -490,8 +480,7 @@ int pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS], char *data,
return -1;
}
INFO(
"Decoding PDSCH SF: %d, Mod %d, NofBits: %d, NofSymbols: %d, NofBitsE: %d\n",
INFO("Decoding PDSCH SF: %d, Mod %d, NofBits: %d, NofSymbols: %d, NofBitsE: %d\n",
nsubframe, mcs.mod, nof_bits, nof_symbols, nof_bits_e);
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
@ -506,11 +495,19 @@ int pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS], char *data,
memset(&x[q->nof_ports], 0, sizeof(cf_t*) * (MAX_LAYERS - q->nof_ports));
/* extract symbols */
pdsch_get(q, sf_symbols, q->pdsch_symbols[0], prb_alloc, nsubframe);
n = pdsch_get(q, sf_symbols, q->pdsch_symbols[0], prb_alloc, nsubframe);
if (n != nof_symbols) {
fprintf(stderr, "Error expecting %d symbols but got %d\n", nof_symbols, n);
return -1;
}
/* extract channel estimates */
for (i = 0; i < q->nof_ports; i++) {
pdsch_get(q, ce[i], q->ce[i], prb_alloc, nsubframe);
n = pdsch_get(q, ce[i], q->ce[i], prb_alloc, nsubframe);
if (n != nof_symbols) {
fprintf(stderr, "Error expecting %d symbols but got %d\n", nof_symbols, n);
return -1;
}
}
/* TODO: only diversity is supported */

@ -57,9 +57,9 @@ int phich_ngroups(phich_t *q) {
return regs_phich_ngroups(q->regs);
}
void phich_reset(phich_t *q, cf_t *slot_symbols[MAX_PORTS_CTRL]) {
void phich_reset(phich_t *q, cf_t *slot_symbols[MAX_PORTS]) {
int i;
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
regs_phich_reset(q->regs, slot_symbols[i]);
}
}
@ -136,7 +136,7 @@ void phich_ack_encode(char ack, char bits[PHICH_NBITS]) {
*
* Returns 1 if successfully decoded the CFI, 0 if not and -1 on error
*/
int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS],
int ngroup, int nseq, int nsubframe, char *ack, int *distance) {
/* Set pointers for layermapping & precoding */
@ -168,7 +168,7 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
}
/* number of layers equals number of ports */
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
x[i] = q->phich_x[i];
}
for (i = 0; i < MAX_PORTS; i++) {
@ -264,7 +264,7 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
* The parameter ack is an array of phich_ngroups() pointers to buffers of nof_sequences chars
*/
int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
cf_t *slot_symbols[MAX_PORTS_CTRL]) {
cf_t *slot_symbols[MAX_PORTS]) {
int i;
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {

@ -33,14 +33,14 @@
#include "liblte/phy/common/base.h"
void prb_cp_ref(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb, bool advance_output) {
int nof_intervals, bool advance_output) {
int i;
int ref_interval = ((RE_X_RB / nof_refs) - 1);
memcpy(*output, *input, offset * sizeof(cf_t));
*input += offset;
*output += offset;
for (i = 0; i < nof_refs * nof_prb - 1; i++) {
for (i = 0; i < nof_intervals - 1; i++) {
if (advance_output) {
(*output)++;
} else {
@ -70,18 +70,18 @@ void prb_cp(cf_t **input, cf_t **output, int nof_prb) {
void prb_cp_half(cf_t **input, cf_t **output, int nof_prb) {
memcpy(*output, *input, sizeof(cf_t) * RE_X_RB * nof_prb / 2);
*input += nof_prb * RE_X_RB / 2;
*output += nof_prb * RE_X_RB / 2;
memcpy(*output, *input, sizeof(cf_t) * RE_X_RB * nof_prb / 2);
*input += nof_prb * RE_X_RB / 2;
*output += nof_prb * RE_X_RB / 2;
}
void prb_put_ref_(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb) {
prb_cp_ref(input, output, offset, nof_refs, nof_prb, false);
int nof_intervals) {
prb_cp_ref(input, output, offset, nof_refs, nof_intervals, false);
}
void prb_get_ref_(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb) {
prb_cp_ref(input, output, offset, nof_refs, nof_prb, true);
int nof_intervals) {
prb_cp_ref(input, output, offset, nof_refs, nof_intervals, true);
}

@ -29,10 +29,10 @@
typedef _Complex float cf_t;
void prb_cp_ref(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb, bool advance_input);
int nof_intervals, bool advance_input);
void prb_cp(cf_t **input, cf_t **output, int nof_prb);
void prb_cp_half(cf_t **input, cf_t **output, int nof_prb);
void prb_put_ref_(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb);
int nof_intervals);
void phch_get_prb_ref(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb);
int nof_intervals);

@ -117,6 +117,7 @@ void ra_prb_get_re(ra_prb_t *prb_dist, int nof_prb, int nof_ports,
prb_dist->lstart = nof_ctrl_symbols;
// Compute number of RE per subframe
for (i = 0; i < NSUBFRAMES_X_FRAME; i++) {
prb_dist->re_sf[i] = 0;
for (s = 0; s < 2; s++) {
for (j = 0; j < prb_dist->slot[s].nof_prb; j++) {
prb_dist->re_sf[i] += ra_re_x_prb(i, s, prb_dist->slot[s].prb_idx[j],
@ -166,8 +167,10 @@ int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
for (i = 0; i < nb; i++) {
if (bitmask & (1 << (nb - i - 1))) {
for (j = 0; j < P; j++) {
prb_dist->slot[0].prb_idx[prb_dist->slot[0].nof_prb] = i * P + j;
prb_dist->slot[0].nof_prb++;
if (i*P+j < nof_prb) {
prb_dist->slot[0].prb_idx[prb_dist->slot[0].nof_prb] = i * P + j;
prb_dist->slot[0].nof_prb++;
}
}
}
}
@ -278,9 +281,7 @@ int ra_nprb_dl(ra_pdsch_t *ra, int nof_prb) {
nof_rbg = bit_count(ra->type0_alloc.rbg_bitmask & 0xFFFFFFFE);
P = ra_type0_P(nof_prb);
if (nof_rbg > (int) ceilf((float) nof_prb / P)) {
fprintf(stderr, "Number of RGB (%d) can not exceed %d\n", nof_prb,
(int) ceilf((float) nof_prb / P));
return -1;
nof_rbg = (int) ceilf((float) nof_prb / P) - 1;
}
nprb = nof_rbg * P;
@ -547,6 +548,7 @@ void ra_pdsch_set_mcs_index(ra_pdsch_t *ra, uint8_t mcs_idx) {
void ra_pdsch_set_mcs(ra_pdsch_t *ra, ra_mod_t mod, uint8_t tbs_idx) {
ra->mcs.mod = mod;
ra->mcs.tbs_idx = tbs_idx;
ra->mcs.tbs = 0;
}
void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) {

@ -122,12 +122,6 @@ int regs_pdcch_init(regs_t *h) {
h->pdcch[cfi].nof_regs = (h->pdcch[cfi].nof_regs/9)*9;
free(tmp);
tmp = NULL;
if (VERBOSE_ISINFO() && cfi == 1) {
for (i=0;i<h->pdcch[cfi].nof_regs;i++) {
INFO("Logical PDCCH REG#%d:%d (%d,%d)\n", i%9,i/9,
h->pdcch[cfi].regs[i]->k0, h->pdcch[cfi].regs[i]->l);
}
}
}
ret = 0;
@ -141,12 +135,12 @@ clean_and_exit:
return ret;
}
int regs_pdcch_nregs(regs_t *h) {
if (h->cfi == -1) {
fprintf(stderr, "Must call regs_set_cfi() first\n");
int regs_pdcch_nregs(regs_t *h, int cfi) {
if (cfi < 1 || cfi > 3) {
fprintf(stderr, "Invalid CFI=%d\n", cfi);
return -1;
} else {
return h->pdcch[h->cfi].nof_regs;
return h->pdcch[cfi-1].nof_regs;
}
}
@ -671,8 +665,9 @@ int regs_init(regs_t *h, int cell_id, int nof_prb, int nof_ports,
fprintf(stderr, "Error initializing REGs\n");
goto clean_and_exit;
}
DEBUG("Available REG #%3d: l=%d, prb=%d, nreg=%d (k0=%d)\n", k, i, prb, j[i],
/*DEBUG("Available REG #%3d: l=%d, prb=%d, nreg=%d (k0=%d)\n", k, i, prb, j[i],
h->regs[k].k0);
*/
j[i]++;
k++;
}
@ -718,7 +713,6 @@ clean_and_exit:
int regs_put_reg(regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, int nof_prb) {
int i;
for (i = 0; i < REGS_RE_X_REG; i++) {
DEBUG("PUT REG: i=%d, (k=%d,l=%d)\n", i, REG_IDX(reg, i, nof_prb),reg->l);
slot_symbols[REG_IDX(reg, i, nof_prb)] = reg_data[i];
}
return REGS_RE_X_REG;
@ -732,9 +726,6 @@ int regs_add_reg(regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, int nof_pr
int i;
for (i = 0; i < REGS_RE_X_REG; i++) {
slot_symbols[REG_IDX(reg, i, nof_prb)] += reg_data[i];
DEBUG("ADD REG: i=%d, (k=%d,l=%d): %.1f+%.1fi\n", i, REG_IDX(reg, i, nof_prb),reg->l,
__real__ slot_symbols[REG_IDX(reg, i, nof_prb)],
__imag__ slot_symbols[REG_IDX(reg, i, nof_prb)]);
}
return REGS_RE_X_REG;
}
@ -746,7 +737,6 @@ int regs_add_reg(regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, int nof_pr
int regs_reset_reg(regs_reg_t *reg, cf_t *slot_symbols, int nof_prb) {
int i;
for (i = 0; i < REGS_RE_X_REG; i++) {
DEBUG("RESET REG: i=%d, (k=%d,l=%d)\n", i, REG_IDX(reg, i, nof_prb),reg->l);
slot_symbols[REG_IDX(reg, i, nof_prb)] = 0;
}
return REGS_RE_X_REG;
@ -759,8 +749,6 @@ int regs_get_reg(regs_reg_t *reg, cf_t *slot_symbols, cf_t *reg_data, int nof_pr
int i;
for (i = 0; i < REGS_RE_X_REG; i++) {
reg_data[i] = slot_symbols[REG_IDX(reg, i, nof_prb)];
//DEBUG("GET REG: i=%d, (k=%d,l=%d): %.1f+%.1fi\n", i, REG_IDX(reg, i, nof_prb),reg->l,
// __real__ reg_data[i], __imag__ reg_data[i]);
}
return REGS_RE_X_REG;
}

@ -45,7 +45,7 @@ FILE *fmatlab = NULL;
#define FLEN 9600
filesource_t fsrc;
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS_CTRL];
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS];
pbch_t pbch;
lte_fft_t fft;
chest_t chest;
@ -118,7 +118,7 @@ int base_init() {
return -1;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
ce[i] = malloc(CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
@ -162,7 +162,7 @@ void base_free() {
free(fft_buffer);
filesource_free(&fsrc);
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
free(ce[i]);
}
chest_free(&chest);
@ -189,7 +189,7 @@ int main(int argc, char **argv) {
n = filesource_read(&fsrc, input_buffer, FLEN);
lte_fft_run(&fft, &input_buffer[960], fft_buffer);
lte_fft_run_slot(&fft, &input_buffer[960], fft_buffer);
if (fmatlab) {
fprintf(fmatlab, "outfft=");
@ -209,7 +209,7 @@ int main(int argc, char **argv) {
INFO("Decoding PBCH\n", 0);
n = pbch_decode(&pbch, fft_buffer, ce, 1, &mib);
n = pbch_decode(&pbch, fft_buffer, ce, &mib);
base_free();

@ -74,16 +74,16 @@ int main(int argc, char **argv) {
pbch_t pbch;
pbch_mib_t mib_tx, mib_rx;
int i, j;
cf_t *ce[MAX_PORTS_CTRL];
cf_t *ce[MAX_PORTS];
int nof_re;
cf_t *slot1_symbols[MAX_PORTS_CTRL];
cf_t *slot1_symbols[MAX_PORTS];
parse_args(argc,argv);
nof_re = CPNORM_NSYMB * nof_prb * RE_X_RB;
/* init memory */
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
@ -120,14 +120,14 @@ int main(int argc, char **argv) {
}
pbch_decode_reset(&pbch);
if (1 != pbch_decode(&pbch, slot1_symbols[0], ce, 1, &mib_rx)) {
if (1 != pbch_decode(&pbch, slot1_symbols[0], ce, &mib_rx)) {
printf("Error decoding\n");
exit(-1);
}
pbch_free(&pbch);
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
free(ce[i]);
free(slot1_symbols[i]);
}

@ -44,7 +44,7 @@ int flen;
FILE *fmatlab = NULL;
filesource_t fsrc;
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS_CTRL];
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS];
pcfich_t pcfich;
regs_t regs;
lte_fft_t fft;
@ -128,7 +128,7 @@ int base_init() {
return -1;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
ce[i] = malloc(CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
@ -177,7 +177,7 @@ void base_free() {
free(fft_buffer);
filesource_free(&fsrc);
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
free(ce[i]);
}
chest_free(&chest);
@ -205,7 +205,7 @@ int main(int argc, char **argv) {
n = filesource_read(&fsrc, input_buffer, flen);
lte_fft_run(&fft, input_buffer, fft_buffer);
lte_fft_run_slot(&fft, input_buffer, fft_buffer);
if (fmatlab) {
fprintf(fmatlab, "infft=");

@ -73,9 +73,9 @@ int main(int argc, char **argv) {
pcfich_t pcfich;
regs_t regs;
int i, j;
cf_t *ce[MAX_PORTS_CTRL];
cf_t *ce[MAX_PORTS];
int nof_re;
cf_t *slot_symbols[MAX_PORTS_CTRL];
cf_t *slot_symbols[MAX_PORTS];
int cfi, cfi_rx, nsf, distance;
int cid, max_cid;
@ -84,7 +84,7 @@ int main(int argc, char **argv) {
nof_re = CPNORM_NSYMB * nof_prb * RE_X_RB;
/* init memory */
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
@ -148,7 +148,7 @@ int main(int argc, char **argv) {
cid++;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
free(ce[i]);
free(slot_symbols[i]);
}

@ -47,7 +47,7 @@ FILE *fmatlab = NULL;
filesource_t fsrc;
pdcch_t pdcch;
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS_CTRL];
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS];
regs_t regs;
lte_fft_t fft;
chest_t chest;
@ -143,7 +143,7 @@ int base_init() {
return -1;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
ce[i] = malloc(CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
@ -175,11 +175,15 @@ int base_init() {
fprintf(stderr, "Error setting CFI %d\n", cfi);
return -1;
}
if (pdcch_init(&pdcch, &regs, nof_prb, nof_ports, cell_id, cp)) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
if (pdcch_set_cfi(&pdcch, cfi)) {
fprintf(stderr, "Error setting CFI %d\n", cfi);
return -1;
}
dci_init(&dci_rx, 10);
DEBUG("Memory init OK\n",0);
@ -198,7 +202,7 @@ void base_free() {
free(fft_buffer);
filesource_free(&fsrc);
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
free(ce[i]);
}
chest_free(&chest);
@ -242,7 +246,7 @@ int main(int argc, char **argv) {
if (nof_frames == 5) {
INFO("Reading %d samples sub-frame %d\n", flen, nof_frames);
lte_fft_run(&fft, input_buffer, fft_buffer);
lte_fft_run_slot(&fft, input_buffer, fft_buffer);
if (fmatlab) {
fprintf(fmatlab, "infft%d=", nof_frames);
@ -264,7 +268,7 @@ int main(int argc, char **argv) {
}
}
nof_dcis = pdcch_decode(&pdcch, fft_buffer, ce, &dci_rx, nof_frames%10, 1);
nof_dcis = pdcch_decode(&pdcch, fft_buffer, ce, &dci_rx, nof_frames%10);
INFO("Received %d DCI messages\n", nof_dcis);

@ -105,9 +105,9 @@ int main(int argc, char **argv) {
ra_pdsch_t ra_dl;
regs_t regs;
int i, j;
cf_t *ce[MAX_PORTS_CTRL];
cf_t *ce[MAX_PORTS];
int nof_re;
cf_t *slot_symbols[MAX_PORTS_CTRL];
cf_t *slot_symbols[MAX_PORTS];
int nof_dcis;
int ret = -1;
@ -120,7 +120,7 @@ int main(int argc, char **argv) {
}
/* init memory */
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
@ -150,6 +150,11 @@ int main(int argc, char **argv) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
if (pdcch_set_cfi(&pdcch, cfi)) {
fprintf(stderr, "Error setting CFI %d\n", cfi);
return -1;
}
dci_init(&dci_tx, 2);
bzero(&ra_dl, sizeof(ra_pdsch_t));
@ -182,7 +187,7 @@ int main(int argc, char **argv) {
pdcch_init_search_ue(&pdcch, 1234);
dci_init(&dci_rx, 2);
nof_dcis = pdcch_decode(&pdcch, slot_symbols[0], ce, &dci_rx, 0, 1);
nof_dcis = pdcch_decode(&pdcch, slot_symbols[0], ce, &dci_rx, 0);
if (nof_dcis < 0) {
printf("Error decoding\n");
} else if (nof_dcis == dci_tx.nof_dcis) {
@ -213,7 +218,7 @@ int main(int argc, char **argv) {
dci_free(&dci_tx);
dci_free(&dci_rx);
for (i = 0; i < MAX_PORTS_CTRL; i++) {
for (i = 0; i < MAX_PORTS; i++) {
free(ce[i]);
free(slot_symbols[i]);
}

@ -48,286 +48,291 @@ FILE *fmatlab = NULL;
filesource_t fsrc;
pdcch_t pdcch;
pdsch_t pdsch;
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS_CTRL];
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS];
regs_t regs;
lte_fft_t fft;
chest_t chest;
dci_t dci_rx;
void usage(char *prog) {
printf("Usage: %s [vcfoe] -i input_file\n", prog);
printf("\t-o output matlab file name [Default Disabled]\n");
printf("\t-c cell_id [Default %d]\n", cell_id);
printf("\t-f cfi [Default %d]\n", cfi);
printf("\t-r rnti [Default SI-RNTI]\n");
printf("\t-p nof_ports [Default %d]\n", nof_ports);
printf("\t-n nof_prb [Default %d]\n", nof_prb);
printf("\t-m max_frames [Default %d]\n", max_frames);
printf("\t-e Set extended prefix [Default Normal]\n");
printf("\t-v [set verbose to debug, default none]\n");
printf("Usage: %s [vcfoe] -i input_file\n", prog);
printf("\t-o output matlab file name [Default Disabled]\n");
printf("\t-c cell_id [Default %d]\n", cell_id);
printf("\t-f cfi [Default %d]\n", cfi);
printf("\t-r rnti [Default SI-RNTI]\n");
printf("\t-p nof_ports [Default %d]\n", nof_ports);
printf("\t-n nof_prb [Default %d]\n", nof_prb);
printf("\t-m max_frames [Default %d]\n", max_frames);
printf("\t-e Set extended prefix [Default Normal]\n");
printf("\t-v [set verbose to debug, default none]\n");
}
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "irovfcenmp")) != -1) {
switch(opt) {
case 'i':
input_file_name = argv[optind];
break;
case 'c':
cell_id = atoi(argv[optind]);
break;
case 'r':
rnti = strtoul(argv[optind], NULL, 0);
break;
case 'm':
max_frames = strtoul(argv[optind], NULL, 0);
break;
case 'f':
cfi = atoi(argv[optind]);
break;
case 'n':
nof_prb = atoi(argv[optind]);
break;
case 'p':
nof_ports = atoi(argv[optind]);
break;
case 'o':
matlab_file_name = argv[optind];
break;
case 'v':
verbose++;
break;
case 'e':
cp = CPEXT;
break;
default:
usage(argv[0]);
exit(-1);
}
}
if (!input_file_name) {
usage(argv[0]);
exit(-1);
}
int opt;
while ((opt = getopt(argc, argv, "irovfcenmp")) != -1) {
switch(opt) {
case 'i':
input_file_name = argv[optind];
break;
case 'c':
cell_id = atoi(argv[optind]);
break;
case 'r':
rnti = strtoul(argv[optind], NULL, 0);
break;
case 'm':
max_frames = strtoul(argv[optind], NULL, 0);
break;
case 'f':
cfi = atoi(argv[optind]);
break;
case 'n':
nof_prb = atoi(argv[optind]);
break;
case 'p':
nof_ports = atoi(argv[optind]);
break;
case 'o':
matlab_file_name = argv[optind];
break;
case 'v':
verbose++;
break;
case 'e':
cp = CPEXT;
break;
default:
usage(argv[0]);
exit(-1);
}
}
if (!input_file_name) {
usage(argv[0]);
exit(-1);
}
}
int base_init() {
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;
}
flen = 2 * (SLOT_LEN(lte_symbol_sz(nof_prb), cp));
input_buffer = malloc(flen * sizeof(cf_t));
if (!input_buffer) {
perror("malloc");
exit(-1);
}
fft_buffer = malloc(2 * CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!fft_buffer) {
perror("malloc");
return -1;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
ce[i] = malloc(2 * CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
return -1;
}
}
if (chest_init(&chest, LINEAR, cp, nof_prb, nof_ports)) {
fprintf(stderr, "Error initializing equalizer\n");
return -1;
}
if (chest_ref_LTEDL(&chest, cell_id)) {
fprintf(stderr, "Error initializing reference signal\n");
return -1;
}
if (lte_fft_init(&fft, cp, nof_prb)) {
fprintf(stderr, "Error initializing FFT\n");
return -1;
}
if (regs_init(&regs, cell_id, nof_prb, nof_ports, R_1, PHICH_NORM, cp)) {
fprintf(stderr, "Error initiating regs\n");
return -1;
}
if (regs_set_cfi(&regs, cfi)) {
fprintf(stderr, "Error setting CFI %d\n", cfi);
return -1;
}
if (pdcch_init(&pdcch, &regs, nof_prb, nof_ports, cell_id, cp)) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
dci_init(&dci_rx, 10);
if (pdsch_init(&pdsch, rnti, nof_prb, nof_ports, cell_id, cp)) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
DEBUG("Memory init OK\n",0);
return 0;
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;
}
flen = 2 * (SLOT_LEN(lte_symbol_sz(nof_prb), cp));
input_buffer = malloc(flen * sizeof(cf_t));
if (!input_buffer) {
perror("malloc");
exit(-1);
}
fft_buffer = malloc(2 * CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!fft_buffer) {
perror("malloc");
return -1;
}
for (i=0;i<MAX_PORTS;i++) {
ce[i] = malloc(2 * CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
return -1;
}
}
if (chest_init(&chest, LINEAR, cp, nof_prb, nof_ports)) {
fprintf(stderr, "Error initializing equalizer\n");
return -1;
}
if (chest_ref_LTEDL(&chest, cell_id)) {
fprintf(stderr, "Error initializing reference signal\n");
return -1;
}
if (lte_fft_init(&fft, cp, nof_prb)) {
fprintf(stderr, "Error initializing FFT\n");
return -1;
}
if (regs_init(&regs, cell_id, nof_prb, nof_ports, R_1, PHICH_NORM, cp)) {
fprintf(stderr, "Error initiating regs\n");
return -1;
}
if (regs_set_cfi(&regs, cfi)) {
fprintf(stderr, "Error setting CFI %d\n", cfi);
return -1;
}
if (pdcch_init(&pdcch, &regs, nof_prb, nof_ports, cell_id, cp)) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
if (pdcch_set_cfi(&pdcch, cfi)) {
fprintf(stderr, "Error setting CFI %d\n", cfi);
return -1;
}
dci_init(&dci_rx, 10);
if (pdsch_init(&pdsch, rnti, nof_prb, nof_ports, cell_id, cp)) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
DEBUG("Memory init OK\n",0);
return 0;
}
void base_free() {
int i;
filesource_free(&fsrc);
if (fmatlab) {
fclose(fmatlab);
}
free(input_buffer);
free(fft_buffer);
filesource_free(&fsrc);
for (i=0;i<MAX_PORTS_CTRL;i++) {
free(ce[i]);
}
chest_free(&chest);
lte_fft_free(&fft);
dci_free(&dci_rx);
pdcch_free(&pdcch);
pdsch_free(&pdsch);
regs_free(&regs);
int i;
filesource_free(&fsrc);
if (fmatlab) {
fclose(fmatlab);
}
free(input_buffer);
free(fft_buffer);
filesource_free(&fsrc);
for (i=0;i<MAX_PORTS;i++) {
free(ce[i]);
}
chest_free(&chest);
lte_fft_free(&fft);
dci_free(&dci_rx);
pdcch_free(&pdcch);
pdsch_free(&pdsch);
regs_free(&regs);
}
int main(int argc, char **argv) {
ra_pdsch_t ra_dl;
ra_prb_t prb_alloc;
int i;
int nof_dcis;
int nof_frames;
int ret;
char *data;
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);
pdcch_init_search_si(&pdcch);
} else {
INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti);
pdcch_init_search_ue(&pdcch, 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(&fft, input_buffer, fft_buffer);
lte_fft_run(&fft, &input_buffer[flen/2], &fft_buffer[CP_NSYMB(cp) * nof_prb * RE_X_RB]);
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(cp) * nof_prb * RE_X_RB);
vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB);
fprintf(fmatlab, ";\n");
vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB);
}
/* Get channel estimates for each port */
for (i=0;i<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(cp) * nof_prb * RE_X_RB],
&ce[i][CP_NSYMB(cp) * nof_prb * RE_X_RB], 2*nof_frames+1, i);
if (fmatlab) {
chest_fprint(&chest, fmatlab, 2*nof_frames+1, i);
}
}
nof_dcis = pdcch_decode(&pdcch, fft_buffer, ce, &dci_rx, nof_frames%10, 1);
INFO("Received %d DCI messages\n", nof_dcis);
for (i=0;i<nof_dcis;i++) {
dci_msg_type_t type;
if (dci_msg_get_type(&dci_rx.msg[i], &type, nof_prb, 1234)) {
fprintf(stderr, "Can't get DCI message type\n");
goto goout;
}
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_rx.msg[i], &ra_dl, nof_prb, rnti != SIRNTI)) {
fprintf(stderr, "Can't unpack PDSCH message\n");
} else {
ra_pdsch_fprint(stdout, &ra_dl, 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.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;
}
if (ra_prb_get_dl(&prb_alloc, &ra_dl, nof_prb)) {
fprintf(stderr, "Error computing resource allocation\n");
goto goout;
}
ra_prb_get_re(&prb_alloc, nof_prb, nof_ports, nof_prb<10?(cfi+1):cfi, cp);
if (pdsch_decode(&pdsch, fft_buffer, ce, data, nof_frames%10, ra_dl.mcs, &prb_alloc)) {
fprintf(stderr, "Error decoding PDSCH\n");
goto goout;
} else {
printf("PDSCH Decoded OK!\n");
}
}
}
nof_frames++;
} while (nof_frames <= max_frames);
ra_pdsch_t ra_dl;
ra_prb_t prb_alloc;
int i;
int nof_dcis;
int nof_frames;
int ret;
char *data;
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);
pdcch_init_search_si(&pdcch);
} else {
INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti);
pdcch_init_search_ue(&pdcch, 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_slot(&fft, input_buffer, fft_buffer);
lte_fft_run_slot(&fft, &input_buffer[flen/2], &fft_buffer[CP_NSYMB(cp) * nof_prb * RE_X_RB]);
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(cp) * nof_prb * RE_X_RB);
vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB);
fprintf(fmatlab, ";\n");
vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB);
}
/* Get channel estimates for each port */
for (i=0;i<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(cp) * nof_prb * RE_X_RB],
&ce[i][CP_NSYMB(cp) * nof_prb * RE_X_RB], 2*nof_frames+1, i);
if (fmatlab) {
chest_fprint(&chest, fmatlab, 2*nof_frames+1, i);
}
}
nof_dcis = pdcch_decode(&pdcch, fft_buffer, ce, &dci_rx, nof_frames%10);
INFO("Received %d DCI messages\n", nof_dcis);
for (i=0;i<nof_dcis;i++) {
dci_msg_type_t type;
if (dci_msg_get_type(&dci_rx.msg[i], &type, nof_prb, 1234)) {
fprintf(stderr, "Can't get DCI message type\n");
goto goout;
}
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_rx.msg[i], &ra_dl, nof_prb, rnti != SIRNTI)) {
fprintf(stderr, "Can't unpack PDSCH message\n");
} else {
ra_pdsch_fprint(stdout, &ra_dl, 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.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;
}
if (ra_prb_get_dl(&prb_alloc, &ra_dl, nof_prb)) {
fprintf(stderr, "Error computing resource allocation\n");
goto goout;
}
ra_prb_get_re(&prb_alloc, nof_prb, nof_ports, nof_prb<10?(cfi+1):cfi, cp);
if (pdsch_decode(&pdsch, fft_buffer, ce, data, nof_frames%10, ra_dl.mcs, &prb_alloc)) {
fprintf(stderr, "Error decoding PDSCH\n");
goto goout;
} else {
printf("PDSCH Decoded OK!\n");
}
}
}
nof_frames++;
} while (nof_frames <= max_frames);
goout:
base_free();
exit(ret);
exit(ret);
}

@ -41,63 +41,75 @@ const int test_re_ports[N_TESTS] = {1, 1, 1, 2, 4, 4, 1, 4, 1, 4};
const int test_re_csymb[N_TESTS] = {2, 1, 3, 3, 1, 3, 2, 2, 1, 2};
const int test_re_prb[N_TESTS] = {6, 15, 15, 15, 15, 15, 6, 6, 15, 15};
const int test_re_num[N_TESTS][3] = {
{408, 684, 828 }, // sf 0, 5 and the rest
{1830, 2106, 2250},
{1470, 1746, 1890},
{1392, 1656, 1800},
{1656, 1896, 2040},
{1356, 1596, 1740},
{276, 540, 684},
{264, 480, 624},
{1482, 1746, 1890},
{1200, 1416, 1560}
{408, 684, 828 }, // sf 0, 5 and the rest
{1830, 2106, 2250},
{1470, 1746, 1890},
{1392, 1656, 1800},
{1656, 1896, 2040},
{1356, 1596, 1740},
{276, 540, 684},
{264, 480, 624},
{1482, 1746, 1890},
{1200, 1416, 1560}
};
cf_t in[200000], out[200000];
int main(int argc, char **argv) {
int i, n, np;
ra_prb_t prb_alloc;
int ret = -1;
int i, n, np, r;
ra_prb_t prb_alloc;
int ret = -1;
pdsch_t pdsch;
while (getopt(argc, argv, "v") == 'v') {
verbose++;
}
for (i=0;i<110;i++) {
prb_alloc.slot[0].prb_idx[i] = i;
prb_alloc.slot[1].prb_idx[i] = i;
}
for (i=0;i<N_TESTS;i++) {
while (getopt(argc, argv, "v") == 'v') {
verbose++;
}
pdsch_init(&pdsch, 0, test_re_prb[i], test_re_ports[i], 0, test_re_cp[i]);
for (i=0;i<110;i++) {
prb_alloc.slot[0].prb_idx[i] = i;
prb_alloc.slot[1].prb_idx[i] = i;
}
memset(prb_alloc.re_sf, 0, sizeof(int) * 10);
prb_alloc.slot[0].nof_prb = test_re_prb[i];
prb_alloc.slot[1].nof_prb = test_re_prb[i];
ra_prb_get_re(&prb_alloc, test_re_prb[i], test_re_ports[i], test_re_csymb[i], test_re_cp[i]);
for (n=0;n<10;n++) {
switch(n) {
case 0:
np = 0;
break;
case 5:
np = 1;
break;
default:
np = 2;
break;
}
r = pdsch_get(&pdsch, in, out, &prb_alloc, n);
for (i=0;i<N_TESTS;i++) {
memset(prb_alloc.re_sf, 0, sizeof(int) * 10);
prb_alloc.slot[0].nof_prb = test_re_prb[i];
prb_alloc.slot[1].nof_prb = test_re_prb[i];
ra_prb_get_re(&prb_alloc, test_re_prb[i], test_re_ports[i], test_re_csymb[i], test_re_cp[i]);
for (n=0;n<10;n++) {
switch(n) {
case 0:
np = 0;
break;
case 5:
np = 1;
break;
default:
np = 2;
break;
}
if (prb_alloc.re_sf[n] != test_re_num[i][np]) {
goto go_out;
}
}
}
ret = 0;
if (prb_alloc.re_sf[n] != test_re_num[i][np]) {
goto go_out;
}
if (r != prb_alloc.re_sf[n]) {
goto go_out;
}
}
pdsch_free(&pdsch);
}
ret = 0;
go_out:
if (ret) {
printf("Error in SF %d test %d. %d PRB, %d ports, RE is %d and should be %d\n",
n, i, test_re_prb[i], test_re_ports[i], prb_alloc.re_sf[n], test_re_num[i][np]);
} else {
printf("Ok\n");
}
exit(ret);
if (ret) {
printf("Error in SF %d test %d. %d PRB, %d ports, RE is %d, get %d and should be %d\n",
n, i, test_re_prb[i], test_re_ports[i], prb_alloc.re_sf[n], r, test_re_num[i][np]);
} else {
printf("Ok\n");
}
exit(ret);
}

@ -43,165 +43,168 @@ int subframe = 1;
ra_mod_t modulation = BPSK;
void usage(char *prog) {
printf("Usage: %s [cpnfvmt] -l TBS \n", prog);
printf("\t-m modulation (1: BPSK, 2: QPSK, 3: QAM16, 4: QAM64) [Default BPSK]\n");
printf("\t-c cell id [Default %d]\n", cell_id);
printf("\t-s subframe [Default %d]\n", subframe);
printf("\t-f cfi [Default %d]\n", cfi);
printf("\t-p nof_ports [Default %d]\n", nof_ports);
printf("\t-n nof_prb [Default %d]\n", nof_prb);
printf("\t-v [set verbose to debug, default none]\n");
printf("Usage: %s [cpnfvmt] -l TBS \n", prog);
printf("\t-m modulation (1: BPSK, 2: QPSK, 3: QAM16, 4: QAM64) [Default BPSK]\n");
printf("\t-c cell id [Default %d]\n", cell_id);
printf("\t-s subframe [Default %d]\n", subframe);
printf("\t-f cfi [Default %d]\n", cfi);
printf("\t-p nof_ports [Default %d]\n", nof_ports);
printf("\t-n nof_prb [Default %d]\n", nof_prb);
printf("\t-v [set verbose to debug, default none]\n");
}
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "lcpnfvmt")) != -1) {
switch(opt) {
case 'm':
switch(atoi(argv[optind])) {
case 1:
modulation = BPSK;
break;
case 2:
modulation = QPSK;
break;
case 4:
modulation = QAM16;
break;
case 6:
modulation = QAM64;
break;
default:
fprintf(stderr, "Invalid modulation %d. Possible values: "
"(1: BPSK, 2: QPSK, 3: QAM16, 4: QAM64)\n", atoi(argv[optind]));
break;
}
break;
case 'l':
tbs = atoi(argv[optind]);
break;
case 'p':
nof_ports = atoi(argv[optind]);
break;
case 'n':
nof_prb = atoi(argv[optind]);
break;
case 'c':
cell_id = atoi(argv[optind]);
break;
case 'v':
verbose++;
break;
default:
usage(argv[0]);
exit(-1);
}
}
if (tbs == -1) {
usage(argv[0]);
exit(-1);
}
int opt;
while ((opt = getopt(argc, argv, "lcpnfvmts")) != -1) {
switch(opt) {
case 'm':
switch(atoi(argv[optind])) {
case 1:
modulation = BPSK;
break;
case 2:
modulation = QPSK;
break;
case 4:
modulation = QAM16;
break;
case 6:
modulation = QAM64;
break;
default:
fprintf(stderr, "Invalid modulation %d. Possible values: "
"(1: BPSK, 2: QPSK, 3: QAM16, 4: QAM64)\n", atoi(argv[optind]));
break;
}
break;
case 's':
subframe = atoi(argv[optind]);
break;
case 'l':
tbs = atoi(argv[optind]);
break;
case 'p':
nof_ports = atoi(argv[optind]);
break;
case 'n':
nof_prb = atoi(argv[optind]);
break;
case 'c':
cell_id = atoi(argv[optind]);
break;
case 'v':
verbose++;
break;
default:
usage(argv[0]);
exit(-1);
}
}
if (tbs == -1) {
usage(argv[0]);
exit(-1);
}
}
int main(int argc, char **argv) {
pdsch_t pdsch;
int i, j;
char *data = NULL;
cf_t *ce[MAX_PORTS_CTRL];
int nof_re;
cf_t *slot_symbols[MAX_PORTS_CTRL];
int ret = -1;
struct timeval t[3];
ra_mcs_t mcs;
ra_prb_t prb_alloc;
parse_args(argc,argv);
nof_re = 2 * CPNORM_NSYMB * nof_prb * RE_X_RB;
mcs.tbs = tbs;
mcs.mod = modulation;
prb_alloc.slot[0].nof_prb = nof_prb;
for (i=0;i<prb_alloc.slot[0].nof_prb;i++) {
prb_alloc.slot[0].prb_idx[i] = i;
}
memcpy(&prb_alloc.slot[1], &prb_alloc.slot[0], sizeof(ra_prb_slot_t));
ra_prb_get_re(&prb_alloc, nof_prb, nof_ports, 2, CPNORM);
/* init memory */
for (i=0;i<nof_ports;i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
goto quit;
}
for (j=0;j<nof_re;j++) {
ce[i][j] = 1;
}
slot_symbols[i] = malloc(sizeof(cf_t) * nof_re);
if (!slot_symbols[i]) {
perror("malloc");
goto quit;
}
}
data = malloc(sizeof(char) * mcs.tbs);
if (!data) {
perror("malloc");
goto quit;
}
if (pdsch_init(&pdsch, 1234, nof_prb, nof_ports, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PDSCH object\n");
goto quit;
}
for (i=0;i<mcs.tbs;i++) {
data[i] = rand()%2;
}
pdsch_encode(&pdsch, data, slot_symbols, subframe, mcs, &prb_alloc);
/* combine outputs */
for (i=0;i<nof_ports;i++) {
for (j=0;j<nof_re;j++) {
if (i > 0) {
slot_symbols[0][j] += slot_symbols[i][j];
}
ce[i][j] = 1;
}
}
gettimeofday(&t[1], NULL);
int r = pdsch_decode(&pdsch, slot_symbols[0], ce, data, subframe, mcs, &prb_alloc);
gettimeofday(&t[2], NULL);
get_time_interval(t);
if (r) {
printf("Error decoding\n");
ret = -1;
} else {
printf("DECODED OK in %d:%d (%.2f Mbps)\n", (int) t[0].tv_sec, (int) t[0].tv_usec, (float) mcs.tbs/t[0].tv_usec);
}
ret = 0;
pdsch_t pdsch;
int i, j;
char *data = NULL;
cf_t *ce[MAX_PORTS];
int nof_re;
cf_t *slot_symbols[MAX_PORTS];
int ret = -1;
struct timeval t[3];
ra_mcs_t mcs;
ra_prb_t prb_alloc;
parse_args(argc,argv);
nof_re = 2 * CPNORM_NSYMB * nof_prb * RE_X_RB;
mcs.tbs = tbs;
mcs.mod = modulation;
prb_alloc.slot[0].nof_prb = nof_prb;
for (i=0;i<prb_alloc.slot[0].nof_prb;i++) {
prb_alloc.slot[0].prb_idx[i] = i;
}
memcpy(&prb_alloc.slot[1], &prb_alloc.slot[0], sizeof(ra_prb_slot_t));
ra_prb_get_re(&prb_alloc, nof_prb, nof_ports, 2, CPNORM);
/* init memory */
for (i=0;i<nof_ports;i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
goto quit;
}
for (j=0;j<nof_re;j++) {
ce[i][j] = 1;
}
slot_symbols[i] = calloc(sizeof(cf_t) , nof_re);
if (!slot_symbols[i]) {
perror("malloc");
goto quit;
}
}
data = malloc(sizeof(char) * mcs.tbs);
if (!data) {
perror("malloc");
goto quit;
}
if (pdsch_init(&pdsch, 1234, nof_prb, nof_ports, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PDSCH object\n");
goto quit;
}
for (i=0;i<mcs.tbs;i++) {
data[i] = rand()%2;
}
pdsch_encode(&pdsch, data, slot_symbols, subframe, mcs, &prb_alloc);
/* combine outputs */
for (i=0;i<nof_ports;i++) {
for (j=0;j<nof_re;j++) {
if (i > 0) {
slot_symbols[0][j] += slot_symbols[i][j];
}
ce[i][j] = 1;
}
}
gettimeofday(&t[1], NULL);
int r = pdsch_decode(&pdsch, slot_symbols[0], ce, data, subframe, mcs, &prb_alloc);
gettimeofday(&t[2], NULL);
get_time_interval(t);
if (r) {
printf("Error decoding\n");
ret = -1;
} else {
printf("DECODED OK in %d:%d (%.2f Mbps)\n", (int) t[0].tv_sec, (int) t[0].tv_usec, (float) mcs.tbs/t[0].tv_usec);
}
ret = 0;
quit:
pdsch_free(&pdsch);
for (i=0;i<nof_ports;i++) {
if (ce[i]) {
free(ce[i]);
}
if (slot_symbols[i]) {
free(slot_symbols[i]);
}
}
if (data) {
free(data);
}
if (ret) {
printf("Error\n");
} else {
printf("Ok\n");
}
exit(ret);
pdsch_free(&pdsch);
for (i=0;i<nof_ports;i++) {
if (ce[i]) {
free(ce[i]);
}
if (slot_symbols[i]) {
free(slot_symbols[i]);
}
}
if (data) {
free(data);
}
if (ret) {
printf("Error\n");
} else {
printf("Ok\n");
}
exit(ret);
}

@ -48,7 +48,7 @@ int numsubframe = 0;
FILE *fmatlab = NULL;
filesource_t fsrc;
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS_CTRL];
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS];
phich_t phich;
regs_t regs;
lte_fft_t fft;
@ -154,7 +154,7 @@ int base_init() {
return -1;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
ce[i] = malloc(CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
@ -203,7 +203,7 @@ void base_free() {
free(fft_buffer);
filesource_free(&fsrc);
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
free(ce[i]);
}
chest_free(&chest);
@ -235,7 +235,7 @@ int main(int argc, char **argv) {
n = filesource_read(&fsrc, input_buffer, flen);
lte_fft_run(&fft, input_buffer, fft_buffer);
lte_fft_run_slot(&fft, input_buffer, fft_buffer);
if (fmatlab) {
fprintf(fmatlab, "infft=");

@ -98,9 +98,9 @@ int main(int argc, char **argv) {
phich_t phich;
regs_t regs;
int i, j;
cf_t *ce[MAX_PORTS_CTRL];
cf_t *ce[MAX_PORTS];
int nof_re;
cf_t *slot_symbols[MAX_PORTS_CTRL];
cf_t *slot_symbols[MAX_PORTS];
char ack[50][PHICH_NORM_NSEQUENCES], ack_rx;
int nsf, distance;
int cid, max_cid;
@ -113,7 +113,7 @@ int main(int argc, char **argv) {
nof_re = CPNORM_NSYMB * nof_prb * RE_X_RB;
/* init memory */
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
@ -196,7 +196,7 @@ int main(int argc, char **argv) {
cid++;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i=0;i<MAX_PORTS;i++) {
free(ce[i]);
free(slot_symbols[i]);
}

@ -0,0 +1,49 @@
/**
*
* \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/.
*
*/
#include <complex.h>
#include <math.h>
#include "liblte/phy/resampling/decim.h"
#include "liblte/phy/utils/debug.h"
/* Performs integer linear decimation by a factor of M */
void decim_c(cf_t *input, cf_t *output, int M, int len) {
int i;
for (i=0;i<len/M;i++) {
output[i] = input[i*M];
}
}
/* Performs integer linear decimation by a factor of M */
void decim_f(float *input, float *output, int M, int len) {
int i;
for (i=0;i<len/M;i++) {
output[i] = input[i*M];
}
}

@ -63,7 +63,7 @@ void interp_linear_offset(cf_t *input, cf_t *output, int M, int len, int off_st,
}
/* Performs 1st order linear interpolation */
void interp_linear(cf_t *input, cf_t *output, int M, int len) {
void interp_linear_c(cf_t *input, cf_t *output, int M, int len) {
interp_linear_offset(input, output, M, len, 0, 0);
}

@ -76,25 +76,25 @@ void sss_synch_m0m1(sss_synch_t *q, cf_t *input, int *m0, float *m0_value,
y[1][i] = input_fft[SSS_POS_SYMBOL + 2 * i + 1];
}
vec_prod_ccc(y[0], q->fc_tables.c[0], z, N_SSS);
vec_prod_ccc(y[0], q->fc_tables[q->N_id_2].c[0], z, N_SSS);
memcpy(zdelay, &z[1], (N_SSS - 1) * sizeof(cf_t));
vec_conj_cc(z, zconj, N_SSS - 1);
vec_prod_ccc(zdelay, zconj, zprod, N_SSS - 1);
corr_all_zs(zprod, q->fc_tables.s, tmp);
corr_all_zs(zprod, q->fc_tables[q->N_id_2].s, tmp);
vec_abs_cf(tmp, tmp_real, N_SSS);
*m0 = vec_max_fi(tmp_real, N_SSS);
if (m0_value) {
*m0_value = tmp_real[*m0];
}
vec_prod_ccc(y[1], q->fc_tables.c[1], tmp, N_SSS);
vec_prod_ccc(tmp, q->fc_tables.z1[*m0], z, N_SSS);
vec_prod_ccc(y[1], q->fc_tables[q->N_id_2].c[1], tmp, N_SSS);
vec_prod_ccc(tmp, q->fc_tables[q->N_id_2].z1[*m0], z, N_SSS);
memcpy(zdelay, &z[1], (N_SSS - 1) * sizeof(cf_t));
vec_conj_cc(z, zconj, N_SSS - 1);
vec_prod_ccc(zdelay, zconj, zprod, N_SSS - 1);
corr_all_zs(zprod, q->fc_tables.s, tmp);
corr_all_zs(zprod, q->fc_tables[q->N_id_2].s, tmp);
vec_abs_cf(tmp, tmp_real, N_SSS);
*m1 = vec_max_fi(tmp_real, N_SSS);
if (m1_value) {

@ -123,7 +123,6 @@ void generate_sss_all_tables(struct sss_tables *tables, int N_id_2) {
for (i = 0; i < 2; i++) {
generate_c(tables->c[i], c_t, N_id_2, i);
}
tables->N_id_2 = N_id_2;
}
void sss_generate(float *signal0, float *signal5, int cell_id) {

@ -39,18 +39,50 @@
#define NOT_SYNC 0xF0F0F0F0
int pss_synch_init_N_id_2(pss_synch_t *q, int N_id_2) {
q->N_id_2 = N_id_2;
dft_plan_t plan;
cf_t pss_signal_pad[PSS_LEN_FREQ];
cf_t pss_signal_time[PSS_LEN];
if (N_id_2 < 0 || N_id_2 > 2) {
fprintf(stderr, "Invalid N_id_2 %d\n", N_id_2);
return -1;
}
pss_generate(pss_signal_time, N_id_2);
memset(pss_signal_pad, 0, PSS_LEN_FREQ * sizeof(cf_t));
memset(q->pss_signal_freq[N_id_2], 0, PSS_LEN_FREQ * sizeof(cf_t));
memcpy(&pss_signal_pad[33], pss_signal_time, PSS_LEN * sizeof(cf_t));
if (dft_plan(&plan, PSS_LEN_FREQ - 1, BACKWARD, COMPLEX)) {
return -1;
}
dft_plan_set_mirror(&plan, true);
dft_plan_set_dc(&plan, true);
dft_run_c(&plan, pss_signal_pad, q->pss_signal_freq[q->N_id_2]);
vec_sc_prod_cfc(q->pss_signal_freq[q->N_id_2], (float) 1 / (PSS_LEN_FREQ - 1),
pss_signal_pad, PSS_LEN_FREQ);
vec_conj_cc(pss_signal_pad, q->pss_signal_freq[q->N_id_2], PSS_LEN_FREQ);
dft_plan_free(&plan);
return 0;
}
/* Initializes the object. subframe_size is the size, in samples, of the 1ms subframe
*
*/
int pss_synch_init(pss_synch_t *q, int frame_size) {
int ret = -1;
int N_id_2;
bzero(q, sizeof(pss_synch_t));
q->pss_signal_freq = vec_malloc((PSS_LEN_FREQ + frame_size) * sizeof(cf_t));
if (!q->pss_signal_freq) {
fprintf(stderr, "Error allocating memory\n");
goto clean_and_exit;
}
q->conv_abs = vec_malloc((PSS_LEN_FREQ + frame_size) * sizeof(float));
if (!q->conv_abs) {
fprintf(stderr, "Error allocating memory\n");
@ -61,16 +93,35 @@ int pss_synch_init(pss_synch_t *q, int frame_size) {
fprintf(stderr, "Error allocating memory\n");
goto clean_and_exit;
}
q->frame_buffer = vec_malloc(4 * frame_size * sizeof(cf_t));
if (!q->frame_buffer) {
q->conv_output = vec_malloc((PSS_LEN_FREQ + frame_size) * sizeof(cf_t));
if (!q->conv_output) {
fprintf(stderr, "Error allocating memory\n");
goto clean_and_exit;
}
q->conv_output = vec_malloc((PSS_LEN_FREQ + frame_size) * sizeof(cf_t));
if (!q->conv_output) {
for (N_id_2=0;N_id_2<3;N_id_2++) {
q->pss_signal_freq[N_id_2] = vec_malloc((PSS_LEN_FREQ + frame_size) * sizeof(cf_t));
if (!q->pss_signal_freq[N_id_2]) {
fprintf(stderr, "Error allocating memory\n");
goto clean_and_exit;
}
if (pss_synch_init_N_id_2(q, N_id_2)) {
fprintf(stderr, "Error initiating PSS detector for N_id_2=%d\n", N_id_2);
goto clean_and_exit;
}
}
#ifdef ENABLE_SF
q->frame_buffer = vec_malloc(4 * frame_size * sizeof(cf_t));
if (!q->frame_buffer) {
fprintf(stderr, "Error allocating memory\n");
goto clean_and_exit;
}
q->correlation_threshold = DEFAULT_CORRELATION_TH;
q->nosync_timeout_frames = DEFAULT_NOSYNC_TIMEOUT;
q->cfo_auto = true;
q->frame_start_idx = NOT_SYNC;
q->fb_wp = 0;
#endif
#ifdef CONVOLUTION_FFT
if (conv_fft_cc_init(&q->conv_fft, frame_size, PSS_LEN_FREQ)) {
@ -79,13 +130,8 @@ int pss_synch_init(pss_synch_t *q, int frame_size) {
}
#endif
q->correlation_threshold = DEFAULT_CORRELATION_TH;
q->nosync_timeout_frames = DEFAULT_NOSYNC_TIMEOUT;
q->cfo_auto = true;
q->N_id_2 = -1;
q->frame_size = frame_size;
q->frame_start_idx = NOT_SYNC;
q->fb_wp = 0;
ret = 0;
clean_and_exit: if (ret == -1) {
@ -95,8 +141,11 @@ int pss_synch_init(pss_synch_t *q, int frame_size) {
}
void pss_synch_free(pss_synch_t *q) {
if (q->pss_signal_freq) {
free(q->pss_signal_freq);
int i;
for (i=0;i<3;i++) {
if (q->pss_signal_freq[i]) {
free(q->pss_signal_freq[i]);
}
}
if (q->conv_abs) {
free(q->conv_abs);
@ -104,13 +153,16 @@ void pss_synch_free(pss_synch_t *q) {
if (q->tmp_input) {
free(q->tmp_input);
}
if (q->frame_buffer) {
free(q->frame_buffer);
}
if (q->conv_output) {
free(q->conv_output);
}
#ifdef ENABLE_SF
if (q->frame_buffer) {
free(q->frame_buffer);
}
#endif
#ifdef CONVOLUTION_FFT
conv_fft_cc_free(&q->conv_fft);
#endif
@ -162,47 +214,20 @@ void pss_put_slot(cf_t *pss_signal, cf_t *slot, int nof_prb, lte_cp_t cp) {
memset(&slot[k + PSS_LEN], 0, 5 * sizeof(cf_t));
}
/** Sets the current N_id_2 value. Initializes the object for this PSS sequence
* Returns -1 on error, 0 otherwise
/** Sets the current N_id_2 value. Returns -1 on error, 0 otherwise
*/
int pss_synch_set_N_id_2(pss_synch_t *q, int N_id_2) {
q->N_id_2 = N_id_2;
dft_plan_t plan;
cf_t pss_signal_pad[PSS_LEN_FREQ];
cf_t pss_signal_time[PSS_LEN];
if (N_id_2 < 0 || N_id_2 > 2) {
if (N_id_2 < 0 || N_id_2 > 2) {
fprintf(stderr, "Invalid N_id_2 %d\n", N_id_2);
return -1;
} else {
q->N_id_2 = N_id_2;
return 0;
}
pss_generate(pss_signal_time, N_id_2);
memset(pss_signal_pad, 0, PSS_LEN_FREQ * sizeof(cf_t));
memset(q->pss_signal_freq, 0, PSS_LEN_FREQ * sizeof(cf_t));
memcpy(&pss_signal_pad[33], pss_signal_time, PSS_LEN * sizeof(cf_t));
if (dft_plan(&plan, PSS_LEN_FREQ - 1, BACKWARD, COMPLEX)) {
return -1;
}
dft_plan_set_mirror(&plan, true);
dft_plan_set_dc(&plan, true);
dft_run_c(&plan, pss_signal_pad, q->pss_signal_freq);
vec_sc_prod_cfc(q->pss_signal_freq, (float) 1 / (PSS_LEN_FREQ - 1),
pss_signal_pad, PSS_LEN_FREQ);
vec_conj_cc(pss_signal_pad, q->pss_signal_freq, PSS_LEN_FREQ);
q->N_id_2 = N_id_2;
dft_plan_free(&plan);
return 0;
}
/** Returns the index of the PSS correlation peak in a subframe.
* The frame starts at corr_peak_pos-subframe_size/2.
* The value of the correlation is stored in corr_peak_value.
@ -214,15 +239,15 @@ int pss_synch_find_pss(pss_synch_t *q, cf_t *input, float *corr_peak_value,
int corr_peak_pos;
int conv_output_len;
memset(&q->pss_signal_freq[PSS_LEN_FREQ], 0, q->frame_size * sizeof(cf_t));
memset(&q->pss_signal_freq[q->N_id_2][PSS_LEN_FREQ], 0, q->frame_size * sizeof(cf_t));
memcpy(q->tmp_input, input, q->frame_size * sizeof(cf_t));
memset(&q->tmp_input[q->frame_size], 0, PSS_LEN_FREQ * sizeof(cf_t));
#ifdef CONVOLUTION_FFT
conv_output_len = conv_fft_cc_run(&q->conv_fft, q->tmp_input,
q->pss_signal_freq, q->conv_output);
q->pss_signal_freq[q->N_id_2], q->conv_output);
#else
conv_output_len = conv_cc(input, q->pss_signal_freq, q->conv_output, q->frame_size, PSS_LEN_FREQ);
conv_output_len = conv_cc(input, q->pss_signal_freq[q->N_id_2], q->conv_output, q->frame_size, PSS_LEN_FREQ);
#endif
vec_abs_cf(q->conv_output, q->conv_abs, conv_output_len);
@ -247,7 +272,7 @@ float pss_synch_cfo_compute(pss_synch_t* q, cf_t *pss_recv) {
cf_t y0, y1, yr;
cf_t y[PSS_LEN_FREQ - 1];
vec_prod_ccc_unalign(q->pss_signal_freq, pss_recv, y, PSS_LEN_FREQ - 1);
vec_prod_ccc_unalign(q->pss_signal_freq[q->N_id_2], pss_recv, y, PSS_LEN_FREQ - 1);
y0 = vec_acc_cc(y, (PSS_LEN_FREQ - 1) / 2);
y1 = vec_acc_cc(&y[(PSS_LEN_FREQ - 1) / 2], (PSS_LEN_FREQ - 1) / 2);
@ -256,6 +281,28 @@ float pss_synch_cfo_compute(pss_synch_t* q, cf_t *pss_recv) {
return atan2f(__imag__ yr, __real__ yr) / M_PI;
}
#ifdef ENABLE_SF
void pss_synch_set_timeout(pss_synch_t *q, int nof_frames) {
q->nosync_timeout_frames = nof_frames;
}
void pss_synch_set_threshold(pss_synch_t *q, float threshold) {
q->correlation_threshold = threshold;
}
void pss_synch_set_cfo_mode(pss_synch_t *q, bool cfo_auto) {
q->cfo_auto = cfo_auto;
}
float pss_synch_get_cfo(pss_synch_t *q) {
return q->current_cfo;
}
int pss_synch_get_frame_start_idx(pss_synch_t *q) {
return q->frame_start_idx;
}
/** This function is designed to be called periodically on a subframe basis.
* The function finds the PSS correlation peak and computes (does not adjust) CFO automatically as defined by
* pss_synch_set_cfo_mode().
@ -338,26 +385,6 @@ int pss_synch_frame(pss_synch_t *q, cf_t *input, cf_t *output, int nsamples) {
return retval;
}
void pss_synch_set_timeout(pss_synch_t *q, int nof_frames) {
q->nosync_timeout_frames = nof_frames;
}
void pss_synch_set_threshold(pss_synch_t *q, float threshold) {
q->correlation_threshold = threshold;
}
void pss_synch_set_cfo_mode(pss_synch_t *q, bool cfo_auto) {
q->cfo_auto = cfo_auto;
}
float pss_synch_get_cfo(pss_synch_t *q) {
return q->current_cfo;
}
int pss_synch_get_frame_start_idx(pss_synch_t *q) {
return q->frame_start_idx;
}
/** High-level API */
int pss_synch_initialize(pss_synch_hl* h) {
@ -397,3 +424,5 @@ int pss_synch_stop(pss_synch_hl* hl) {
return 0;
}
#endif

@ -41,6 +41,9 @@ void convert_tables(struct fc_tables *fc_tables, struct sss_tables *in);
void generate_N_id_1_table(int table[30][30]);
int sss_synch_init(sss_synch_t *q) {
int N_id_2;
struct sss_tables sss_tables;
bzero(q, sizeof(sss_synch_t));
if (dft_plan(&q->dftp_input, SSS_DFT_LEN, FORWARD, COMPLEX)) {
@ -49,6 +52,11 @@ int sss_synch_init(sss_synch_t *q) {
generate_N_id_1_table(q->N_id_1_table);
dft_plan_set_mirror(&q->dftp_input, true);
dft_plan_set_dc(&q->dftp_input, true);
for (N_id_2=0;N_id_2<3;N_id_2++) {
generate_sss_all_tables(&sss_tables, N_id_2);
convert_tables(&q->fc_tables[N_id_2], &sss_tables);
}
q->N_id_2 = 0;
return 0;
}
@ -57,18 +65,15 @@ void sss_synch_free(sss_synch_t *q) {
bzero(q, sizeof(sss_synch_t));
}
/** Initializes the SSS sequences for the given N_id_2 */
/** Sets the N_id_2 to search for */
int sss_synch_set_N_id_2(sss_synch_t *q, int N_id_2) {
if (N_id_2 < 0 || N_id_2 > 2) {
fprintf(stderr, "Invalid N_id_2 %d\n", N_id_2);
return -1;
} else {
q->N_id_2 = N_id_2;
return 0;
}
struct sss_tables sss_tables;
generate_sss_all_tables(&sss_tables, N_id_2);
convert_tables(&q->fc_tables, &sss_tables);
return 0;
}
/** 36.211 10.3 section 6.11.2.2

@ -34,45 +34,34 @@
#include "liblte/phy/sync/sync.h"
int sync_init(sync_t *q, int frame_size) {
int N_id_2;
bzero(q, sizeof(sync_t));
q->force_N_id_2 = -1;
q->threshold = 1.5;
q->pss_mode = PEAK_MEAN;
q->detect_cp = true;
q->sss_en = true;
for (N_id_2=0;N_id_2<3;N_id_2++) {
if (pss_synch_init(&q->pss[N_id_2], frame_size)) {
fprintf(stderr, "Error initializing PSS object\n");
return -1;
}
if (pss_synch_set_N_id_2(&q->pss[N_id_2], N_id_2)) {
fprintf(stderr, "Error initializing N_id_2\n");
return -1;
}
if (sss_synch_init(&q->sss[N_id_2])) {
fprintf(stderr, "Error initializing SSS object\n");
return -1;
}
if (sss_synch_set_N_id_2(&q->sss[N_id_2], N_id_2)) {
fprintf(stderr, "Error initializing N_id_2\n");
return -1;
}
DEBUG("PSS and SSS initiated N_id_2=%d\n", N_id_2);
if (pss_synch_init(&q->pss, frame_size)) {
fprintf(stderr, "Error initializing PSS object\n");
return -1;
}
if (pss_synch_init(&q->pss_track, TRACK_LEN)) {
fprintf(stderr, "Error initializing PSS track object\n");
return -1;
}
if (sss_synch_init(&q->sss)) {
fprintf(stderr, "Error initializing SSS object\n");
return -1;
}
DEBUG("PSS and SSS initiated\n",0);
return 0;
}
void sync_free(sync_t *q) {
int N_id_2;
for (N_id_2=0;N_id_2<3;N_id_2++) {
pss_synch_free(&q->pss[N_id_2]);
sss_synch_free(&q->sss[N_id_2]);
}
pss_synch_free(&q->pss);
pss_synch_free(&q->pss_track);
sss_synch_free(&q->sss);
}
void sync_pss_det_absolute(sync_t *q) {
@ -86,15 +75,6 @@ void sync_set_threshold(sync_t *q, float threshold) {
q->threshold = threshold;
}
void sync_force_N_id_2(sync_t *q, int force_N_id_2) {
q->force_N_id_2 = force_N_id_2;
}
void sync_force_cp(sync_t *q, lte_cp_t cp) {
q->cp = cp;
q->detect_cp = false;
}
void sync_sss_en(sync_t *q, bool enabled) {
q->sss_en = enabled;
}
@ -127,36 +107,129 @@ float sync_get_peak_to_avg(sync_t *q) {
return q->peak_to_avg;
}
void sync_cp_en(sync_t *q, bool enabled) {
q->detect_cp = enabled;
}
lte_cp_t sync_get_cp(sync_t *q) {
return q->cp;
}
int sync_run(sync_t *q, cf_t *input) {
int N_id_2, peak_pos[3], sss_idx_n, sss_idx_e;
int m0, m1;
int sync_sss(sync_t *q, cf_t *input, int N_id_2, int peak_pos, bool en_cp) {
int m0, m1, sss_idx_n, sss_idx_e;
float m0_value_e, m1_value_e,m0_value_n, m1_value_n;
int slot_id_e, N_id_1_e, slot_id_n, N_id_1_n;
sss_synch_set_N_id_2(&q->sss, N_id_2);
/* Make sure we have enough room to find SSS sequence */
sss_idx_n = peak_pos-2*(128+CP(128,CPNORM_LEN));
sss_idx_e = peak_pos-2*(128+CP(128,CPEXT_LEN));
if (en_cp) {
if (sss_idx_n < 0 || sss_idx_e < 0) {
INFO("Not enough room to decode SSS (%d, %d)\n", sss_idx_n, sss_idx_e);
return -1;
}
} else {
if (CP_ISNORM(q->cp)) {
if (sss_idx_n < 0) {
INFO("Not enough room to decode SSS (%d)\n", sss_idx_n);
return -1;
}
} else {
if (sss_idx_e < 0) {
INFO("Not enough room to decode SSS (%d)\n", sss_idx_e);
return -1;
}
}
}
N_id_1_e = -1;
N_id_1_n = -1;
slot_id_e = -1;
slot_id_n = -1;
/* try Normal CP length */
if (en_cp || CP_ISNORM(q->cp)) {
sss_synch_m0m1(&q->sss, &input[sss_idx_n],
&m0, &m0_value_n, &m1, &m1_value_n);
slot_id_n = 2 * sss_synch_subframe(m0, m1);
N_id_1_n = sss_synch_N_id_1(&q->sss, m0, m1);
}
if (en_cp || CP_ISEXT(q->cp)) {
/* Now try Extended CP length */
sss_synch_m0m1(&q->sss, &input[sss_idx_e],
&m0, &m0_value_e, &m1, &m1_value_e);
slot_id_e = 2 * sss_synch_subframe(m0, m1);
N_id_1_e = sss_synch_N_id_1(&q->sss, m0, m1);
}
/* Correlation with extended CP hypoteshis is greater than with normal? */
if ((en_cp && m0_value_e * m1_value_e > m0_value_n * m1_value_n)
|| CP_ISEXT(q->cp)) {
q->cp = CPEXT;
q->slot_id = slot_id_e;
q->N_id_1 = N_id_1_e;
/* then is normal CP */
} else {
q->cp = CPNORM;
q->slot_id = slot_id_n;
q->N_id_1 = N_id_1_n;
}
INFO("SSS detected N_id_1=%d, slot_idx=%d, %s CP\n",
q->N_id_1, q->slot_id, CP_ISNORM(q->cp)?"Normal":"Extended");
return 0;
}
int sync_track(sync_t *q, cf_t *input) {
float peak_value, mean_value;
int peak_detected = 0;
pss_synch_set_N_id_2(&q->pss_track, q->N_id_2);
int peak_pos = pss_synch_find_pss(&q->pss, input, &peak_value, &mean_value);
if (q->peak_to_avg > TRACK_THRESHOLD) {
peak_detected = 1;
}
if (peak_detected) {
q->cfo = pss_synch_cfo_compute(&q->pss, &input[peak_pos-128]);
if (q->sss_en) {
if (sync_sss(q, input, q->N_id_2, peak_pos, false)) {
return -1;
}
}
return peak_pos;
} else {
return -1;
}
}
int sync_find(sync_t *q, cf_t *input) {
int N_id_2, peak_pos[3];
float peak_value[3];
float mean_value[3];
float max=-999;
int i;
int peak_detected;
if (q->force_N_id_2 == -1) {
for (N_id_2=0;N_id_2<3;N_id_2++) {
peak_pos[N_id_2] = pss_synch_find_pss(&q->pss[N_id_2], input,
&peak_value[N_id_2], &mean_value[N_id_2]);
}
for (i=0;i<3;i++) {
if (peak_value[i] > max) {
max = peak_value[i];
N_id_2 = i;
}
for (N_id_2=0;N_id_2<3;N_id_2++) {
pss_synch_set_N_id_2(&q->pss, N_id_2);
peak_pos[N_id_2] = pss_synch_find_pss(&q->pss, input, &peak_value[N_id_2], &mean_value[N_id_2]);
}
for (i=0;i<3;i++) {
if (peak_value[i] > max) {
max = peak_value[i];
N_id_2 = i;
}
} else {
N_id_2 = q->force_N_id_2;
peak_pos[N_id_2] = pss_synch_find_pss(&q->pss[N_id_2], input,
&peak_value[N_id_2], &mean_value[N_id_2]);
}
q->peak_to_avg = peak_value[N_id_2] / mean_value[N_id_2];
@ -178,74 +251,17 @@ int sync_run(sync_t *q, cf_t *input) {
}
}
if (peak_detected) {
q->cfo = pss_synch_cfo_compute(&q->pss[N_id_2], &input[peak_pos[N_id_2]-128]);
q->N_id_2 = N_id_2;
pss_synch_set_N_id_2(&q->pss, q->N_id_2);
q->cfo = pss_synch_cfo_compute(&q->pss, &input[peak_pos[q->N_id_2]-128]);
INFO("PSS peak detected N_id_2=%d, pos=%d peak=%.2f par=%.2f th=%.2f cfo=%.4f\n", N_id_2,
peak_pos[N_id_2], peak_value[N_id_2], q->peak_to_avg, q->threshold, q->cfo);
if (q->sss_en) {
/* Make sure we have enough room to find SSS sequence */
sss_idx_n = peak_pos[N_id_2]-2*(128+CP(128,CPNORM_LEN));
sss_idx_e = peak_pos[N_id_2]-2*(128+CP(128,CPEXT_LEN));
if (q->detect_cp) {
if (sss_idx_n < 0 || sss_idx_e < 0) {
INFO("Not enough room to decode SSS (%d, %d)\n", sss_idx_n, sss_idx_e);
return -1;
}
} else {
if (CP_ISNORM(q->cp)) {
if (sss_idx_n < 0) {
INFO("Not enough room to decode SSS (%d)\n", sss_idx_n);
return -1;
}
} else {
if (sss_idx_e < 0) {
INFO("Not enough room to decode SSS (%d)\n", sss_idx_e);
return -1;
}
}
}
N_id_1_e = -1;
N_id_1_n = -1;
slot_id_e = -1;
slot_id_n = -1;
/* try Normal CP length */
if (q->detect_cp || CP_ISNORM(q->cp)) {
sss_synch_m0m1(&q->sss[N_id_2], &input[sss_idx_n],
&m0, &m0_value_n, &m1, &m1_value_n);
slot_id_n = 2 * sss_synch_subframe(m0, m1);
N_id_1_n = sss_synch_N_id_1(&q->sss[N_id_2], m0, m1);
if (sync_sss(q, input, q->N_id_2, peak_pos[q->N_id_2], q->detect_cp)) {
return -1;
}
if (q->detect_cp || CP_ISEXT(q->cp)) {
/* Now try Extended CP length */
sss_synch_m0m1(&q->sss[N_id_2], &input[sss_idx_e],
&m0, &m0_value_e, &m1, &m1_value_e);
slot_id_e = 2 * sss_synch_subframe(m0, m1);
N_id_1_e = sss_synch_N_id_1(&q->sss[N_id_2], m0, m1);
}
/* Correlation with extended CP hypoteshis is greater than with normal? */
if ((q->detect_cp && m0_value_e * m1_value_e > m0_value_n * m1_value_n)
|| CP_ISEXT(q->cp)) {
q->cp = CPEXT;
q->slot_id = slot_id_e;
q->N_id_1 = N_id_1_e;
/* then is normal CP */
} else {
q->cp = CPNORM;
q->slot_id = slot_id_n;
q->N_id_1 = N_id_1_n;
}
q->N_id_2 = N_id_2;
INFO("SSS detected N_id_1=%d, slot_idx=%d, %s CP\n",
q->N_id_1, q->slot_id, CP_ISNORM(q->cp)?"Normal":"Extended");
}
return peak_pos[N_id_2];

@ -0,0 +1,236 @@
/**
*
* \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/.
*
*/
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "liblte/phy/resampling/decim.h"
#include "liblte/phy/utils/debug.h"
#include "liblte/phy/sync/sync_frame.h"
int sync_frame_init(sync_frame_t *q, int downsampling) {
int ret = -1;
bzero(q, sizeof(sync_frame_t));
if(sync_init(&q->s, SYNC_SF_LEN)) {
goto clean_exit;
}
sync_pss_det_peak_to_avg(&q->s);
if (cfo_init(&q->cfocorr, SYNC_SF_LEN * downsampling)) {
fprintf(stderr, "Error initiating CFO\n");
goto clean_exit;
}
q->input_buffer = malloc(2 * SYNC_SF_LEN * downsampling * sizeof(cf_t));
if (!q->input_buffer) {
perror("malloc");
goto clean_exit;
}
q->input_downsampled = malloc(SYNC_SF_LEN * sizeof(cf_t));
if (!q->input_downsampled) {
perror("malloc");
goto clean_exit;
}
q->downsampling = downsampling;
sync_frame_reset(q);
ret = 0;
clean_exit:
if (ret == -1) {
sync_frame_free(q);
}
return ret;
}
void sync_frame_free(sync_frame_t *q) {
if (q->input_buffer) {
free(q->input_buffer);
}
if (q->input_downsampled) {
free(q->input_downsampled);
}
cfo_free(&q->cfocorr);
sync_free(&q->s);
}
void sync_frame_run(sync_frame_t *q, cf_t *input) {
int track_idx;
switch (q->state) {
case SF_FIND:
q->peak_idx = sync_find(&q->s, input);
q->cell_id = sync_get_cell_id(&q->s);
INFO("FIND %3d:\tPAR=%.2f\n", (int) q->frame_cnt, sync_get_peak_to_avg(&q->s));
if (q->peak_idx != -1 && q->cell_id != -1) {
/* Get the subframe index (0 or 5) */
q->sf_idx = sync_get_slot_id(&q->s)/2;
/* Reset variables */
q->last_found = 0;
q->timeoffset = 0;
q->frame_cnt = 0;
/* Goto Tracking state */
q->state = SF_TRACK;
}
break;
case SF_TRACK:
q->sf_idx = (q->sf_idx + 1) % 10;
/* Every SF idx 0 and 5, find peak around known position q->peak_idx */
if (q->sf_idx != 0 && q->sf_idx != 5) {
break;
}
track_idx = sync_track(&q->s, &input[q->peak_idx - TRACK_LEN]);
INFO("TRACK %3d: SF=%d. Previous idx is %d New Offset is %d\n",
(int) q->frame_cnt, q->sf_idx, q->peak_idx, track_idx - TRACK_LEN);
if (track_idx != -1) {
INFO("Expected SF idx %d but got %d. Going back to FIND\n", q->sf_idx,
sync_get_slot_id(&q->s)/2);
/* Make sure subframe idx is what we expect */
if (q->sf_idx != sync_get_slot_id(&q->s)/2) {
INFO("Expected SF idx %d but got %d. Going back to FIND\n", q->sf_idx,
sync_get_slot_id(&q->s)/2);
q->state = SF_FIND;
}
/* compute cumulative moving average CFO */
q->cur_cfo = (sync_get_cfo(&q->s) + q->frame_cnt * q->cur_cfo) / (q->frame_cnt + 1);
/* compute cumulative moving average time offset */
q->timeoffset = (float) (track_idx - TRACK_LEN + q->timeoffset * q->frame_cnt)
/ (q->frame_cnt + 1);
q->last_found = q->frame_cnt;
q->peak_idx = (q->peak_idx + track_idx - TRACK_LEN) % SYNC_SF_LEN;
if (q->peak_idx < 0) {
INFO("PSS lost (peak_idx=%d). Going back to FIND\n", q->peak_idx);
q->state = SF_FIND;
}
} else {
/* if sync not found, adjust time offset with the averaged value */
q->peak_idx = (q->peak_idx + (int) q->timeoffset) % SYNC_SF_LEN;
/* if we missed too many PSS go back to FIND */
if (q->frame_cnt - q->last_found > TRACK_MAX_LOST) {
INFO("%d frames lost. Going back to FIND", (int) q->frame_cnt - q->last_found);
q->state = SF_FIND;
}
}
q->frame_cnt++;
break;
}
}
void sync_frame_set_threshold(sync_frame_t *q, float threshold) {
sync_set_threshold(&q->s, threshold);
}
int sync_frame_cell_id(sync_frame_t *q) {
return q->cell_id;
}
int sync_frame_sfidx(sync_frame_t *q) {
return q->sf_idx;
}
int sync_frame_push(sync_frame_t *q, cf_t *input, cf_t *output) {
int retval = 0;
int frame_start;
cf_t *input_ds;
int sf_len;
if (q->downsampling == 1) {
input_ds = input;
} else {
decim_c(input, q->input_downsampled, q->downsampling, SYNC_SF_LEN * q->downsampling);
input_ds = q->input_downsampled;
}
sync_frame_run(q, input_ds);
sf_len = q->downsampling * SYNC_SF_LEN;
if (q->state == SF_FIND) {
memcpy(q->input_buffer, input, sf_len * sizeof(cf_t));
} else {
frame_start = q->downsampling * q->peak_idx - sf_len/2;
DEBUG("Peak_idx=%d, frame_start=%d cfo=%.3f\n",q->peak_idx,
frame_start, q->cur_cfo);
if (frame_start > 0) {
if (q->fb_wp) {
memcpy(&q->input_buffer[(sf_len - frame_start)], input, frame_start * sizeof(cf_t));
memcpy(output, q->input_buffer, sf_len * sizeof(cf_t));
retval = 1;
}
memcpy(q->input_buffer, &input[frame_start], (sf_len - frame_start) * sizeof(cf_t));
q->fb_wp = true;
} else {
memcpy(output, &q->input_buffer[sf_len + frame_start], (-frame_start) * sizeof(cf_t));
memcpy(&output[-frame_start], input, (sf_len + frame_start) * sizeof(cf_t));
memcpy(&q->input_buffer[sf_len + frame_start], &input[sf_len + frame_start], (-frame_start) * sizeof(cf_t));
retval = 1;
}
}
/* Frequency Synchronization */
if (retval) {
cfo_correct(&q->cfocorr, output, -q->cur_cfo / 128);
}
if (!retval) {
DEBUG("Frame Buffered\n",0);
}
return retval;
}
void sync_frame_reset(sync_frame_t *q) {
q->state = SF_FIND;
q->frame_cnt = 0;
q->fb_wp = false;
q->cur_cfo = 0;
}

@ -107,7 +107,6 @@ int main(int argc, char **argv) {
}
sync_set_threshold(&sync, 20);
sync_force_N_id_2(&sync, -1);
if (cell_id == -1) {
cid = 0;
@ -130,9 +129,9 @@ int main(int argc, char **argv) {
/* Transform to OFDM symbols */
memset(fft_buffer, 0, sizeof(cf_t) * 2 * FLEN);
lte_ifft_run(&ifft, buffer, &fft_buffer[offset]);
lte_ifft_run_slot(&ifft, buffer, &fft_buffer[offset]);
find_idx = sync_run(&sync, fft_buffer);
find_idx = sync_find(&sync, fft_buffer);
find_ns = sync_get_slot_id(&sync);
printf("cell_id: %d find: %d, offset: %d, ns=%d find_ns=%d\n", cid, find_idx, offset,
ns, find_ns);

Loading…
Cancel
Save