Resolved merge conflict with issue #24

master
ismagom 11 years ago
commit 60e5ed1ee1

@ -23,13 +23,11 @@
########################################################################
# Prevent in-tree builds
########################################################################
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "Prevented in-tree build. This is bad practice.")
endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
########################################################################
# Project setup
########################################################################
@ -66,12 +64,23 @@ SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
########################################################################
# Compiler specific setup
########################################################################
macro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE flag have)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(${flag} ${have})
if(${have})
add_definitions(${flag})
endif(${have})
endmacro(ADD_CXX_COMPILER_FLAG_IF_AVAILABLE)
IF(CMAKE_COMPILER_IS_GNUCXX)
# do something
#Any additional flags for CXX
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-format-extra-args -Winline -Wno-unused-result -Wno-format -std=c99 -D_GNU_SOURCE")
IF(NOT WIN32)
ADD_CXX_COMPILER_FLAG_IF_AVAILABLE(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN)
ENDIF(NOT WIN32)
ENDIF(CMAKE_COMPILER_IS_GNUCC)
IF(MSVC)

@ -35,22 +35,25 @@
SET(QWT_FOUND "NO")
FIND_PATH(QWT_INCLUDE_DIR qwt.h
$ENV{QWT_DIR}/include
SET(HINT_INCLUDE_PATHS $ENV{QWT_DIR}/include
$ENV{QWT_DIR}/src
$ENV{QWTDIR}/include
$ENV{QWTDIR}/src
$ENV{QWT_ROOT}/include
$ENV{QWT_ROOT}/src
$ENV{QWTROOT}/include
$ENV{QWTROOT}/src
/usr/local/qwt/include
$ENV{QWTROOT}/src)
SET(POTENTIAL_INCLUDE_PATHS /usr/local/qwt/include
/usr/local/include
/usr/include/qwt
/usr/include/qwt-qt4
/usr/include/qwt5
/usr/include
/opt/local/include/qwt #macports path
/opt/local/include/qwt) #macports path
FIND_PATH(QWT_INCLUDE_DIR qwt.h
HINTS ${HINT_INCLUDE_PATHS}
PATHS ${POTENTIAL_INCLUDE_PATHS}
)
SET(QWT_INCLUDE_DIRS ${QWT_INCLUDE_DIR})
@ -82,20 +85,19 @@ IF( Qwt_FIND_VERSION AND QWT_VERSION_STRING )
ENDIF()
ENDIF()
SET(POTENTIAL_LIBRARY_PATHS
$ENV{QWT_DIR}/lib
SET(QWT_NAMES ${QWT_NAMES} qwt qwt-qt4 qwt5 )
SET(HINT_LIBRARY_PATHS $ENV{QWT_DIR}/lib
$ENV{QWTDIR}/lib
$ENV{QWT_ROOT}/lib
$ENV{QWTROOT}/lib
/usr/local/qwt/lib
/usr/local/lib /usr/lib
/opt/local/lib
$ENV{QWTROOT}/lib)
SET(POTENTIAL_LIBRARY_PATHS /usr/local/qwt/lib
/usr/local/lib
/usr/lib
/opt/local/lib)
)
SET(QWT_NAMES ${QWT_NAMES} qwt qwt-qt4 qwt5 )
FIND_LIBRARY(QWT_LIBRARY
NAMES ${QWT_NAMES}
HINTS ${HINT_LIBRARY_PATHS}
PATHS ${POTENTIAL_LIBRARY_PATHS}
)
MARK_AS_ADVANCED(QWT_LIBRARY)
@ -107,6 +109,7 @@ IF (QWT_LIBRARY)
SET(QWT_NAMES_DEBUG qwtd qwtd-qt4 qwtd5 )
FIND_LIBRARY(QWT_LIBRARY_DEBUG
NAMES ${QWT_NAMES_DEBUG}
HINTS ${HINT_LIBRARY_PATHS}
PATHS ${POTENTIAL_LIBRARY_PATHS}
)
MARK_AS_ADVANCED(QWT_LIBRARY_DEBUG)

@ -22,6 +22,7 @@
########################################################################
# Install headers
########################################################################
ADD_SUBDIRECTORY(include)
INSTALL(DIRECTORY include/ DESTINATION "${INCLUDE_DIR}"
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE

@ -0,0 +1,38 @@
#
# Copyright 2012-2013 The libLTE Developers. See the
# COPYRIGHT file at the top-level directory of this distribution.
#
# 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/.
#
########################################################################
# Add headers to cmake project (useful for IDEs)
########################################################################
SET(HEADERS_ALL "")
FILE(GLOB_RECURSE tmp "*.h")
LIST(APPEND HEADERS_ALL ${tmp})
FILE(GLOB headers *)
FOREACH (_header ${headers})
IF(IS_DIRECTORY ${_header})
FILE(GLOB_RECURSE tmp "${_header}/*.h")
LIST(APPEND HEADERS_ALL ${tmp})
ENDIF(IS_DIRECTORY ${_header})
ENDFOREACH()
ADD_CUSTOM_TARGET (add_cuhd_headers SOURCES ${HEADERS_ALL})

@ -22,6 +22,7 @@
########################################################################
# Install headers
########################################################################
ADD_SUBDIRECTORY(include)
INSTALL(DIRECTORY include/ DESTINATION "${INCLUDE_DIR}"
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE

@ -0,0 +1,38 @@
#
# Copyright 2012-2013 The libLTE Developers. See the
# COPYRIGHT file at the top-level directory of this distribution.
#
# 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/.
#
########################################################################
# Add headers to cmake project (useful for IDEs)
########################################################################
SET(HEADERS_ALL "")
FILE(GLOB_RECURSE tmp "*.h")
LIST(APPEND HEADERS_ALL ${tmp})
FILE(GLOB headers *)
FOREACH (_header ${headers})
IF(IS_DIRECTORY ${_header})
FILE(GLOB_RECURSE tmp "${_header}/*.h")
LIST(APPEND HEADERS_ALL ${tmp})
ENDIF(IS_DIRECTORY ${_header})
ENDFOREACH()
ADD_CUSTOM_TARGET (add_graphics_headers SOURCES ${HEADERS_ALL})

@ -33,13 +33,15 @@
extern "C" {
#endif
#include "lte/config.h"
#include "plot/plot_real.h"
#include "plot/plot_scatter.h"
#include "plot/plot_complex.h"
#include "plot/plot_waterfall.h"
int plot_init();
void plot_exit();
LIBLTE_API int plot_init();
LIBLTE_API void plot_exit();
#ifdef __cplusplus
}

@ -35,6 +35,7 @@ extern "C" {
#endif
#include <stdbool.h>
#include "lte/config.h"
typedef enum {
Ip, Q, Magnitude, Phase
@ -42,15 +43,15 @@ typedef enum {
typedef void* plot_complex_t;
int plot_complex_init(plot_complex_t *h);
void plot_complex_setTitle(plot_complex_t *h, char *title);
void plot_complex_setNewData(plot_complex_t *h, _Complex float *data,
LIBLTE_API int plot_complex_init(plot_complex_t *h);
LIBLTE_API void plot_complex_setTitle(plot_complex_t *h, char *title);
LIBLTE_API void plot_complex_setNewData(plot_complex_t *h, _Complex float *data,
int num_points);
void plot_complex_setXAxisAutoScale(plot_complex_t *h, plot_complex_id_t id, bool on);
void plot_complex_setYAxisAutoScale(plot_complex_t *h, plot_complex_id_t id, bool on);
void plot_complex_setXAxisScale(plot_complex_t *h, plot_complex_id_t id, double xMin, double xMax);
void plot_complex_setYAxisScale(plot_complex_t *h, plot_complex_id_t id, double yMin, double yMax);
void plot_complex_setXAxisRange(plot_complex_t *h, double xMin, double xMax);
LIBLTE_API void plot_complex_setXAxisAutoScale(plot_complex_t *h, plot_complex_id_t id, bool on);
LIBLTE_API void plot_complex_setYAxisAutoScale(plot_complex_t *h, plot_complex_id_t id, bool on);
LIBLTE_API void plot_complex_setXAxisScale(plot_complex_t *h, plot_complex_id_t id, double xMin, double xMax);
LIBLTE_API void plot_complex_setYAxisScale(plot_complex_t *h, plot_complex_id_t id, double yMin, double yMax);
LIBLTE_API void plot_complex_setXAxisRange(plot_complex_t *h, double xMin, double xMax);
#ifdef __cplusplus
}

@ -34,19 +34,20 @@ extern "C" {
#endif
#include <stdbool.h>
#include "lte/config.h"
typedef void* plot_real_t;
int plot_real_init(plot_real_t *h);
void plot_real_setTitle(plot_real_t *h, char *title);
void plot_real_setNewData(plot_real_t *h, float *data,
LIBLTE_API int plot_real_init(plot_real_t *h);
LIBLTE_API void plot_real_setTitle(plot_real_t *h, char *title);
LIBLTE_API void plot_real_setNewData(plot_real_t *h, float *data,
int num_points);
void plot_real_setXAxisAutoScale(plot_real_t *h, bool on);
void plot_real_setYAxisAutoScale(plot_real_t *h, bool on);
void plot_real_setXAxisScale(plot_real_t *h, double xMin, double xMax);
void plot_real_setYAxisScale(plot_real_t *h, double yMin, double yMax);
void plot_real_setXAxisRange(plot_real_t *h, double xMin, double xMax);
void plot_real_setLabels(plot_real_t *h, char *xLabel, char *yLabel);
LIBLTE_API void plot_real_setXAxisAutoScale(plot_real_t *h, bool on);
LIBLTE_API void plot_real_setYAxisAutoScale(plot_real_t *h, bool on);
LIBLTE_API void plot_real_setXAxisScale(plot_real_t *h, double xMin, double xMax);
LIBLTE_API void plot_real_setYAxisScale(plot_real_t *h, double yMin, double yMax);
LIBLTE_API void plot_real_setXAxisRange(plot_real_t *h, double xMin, double xMax);
LIBLTE_API void plot_real_setLabels(plot_real_t *h, char *xLabel, char *yLabel);
#ifdef __cplusplus
}

@ -34,18 +34,19 @@ extern "C" {
#endif
#include <stdbool.h>
#include "lte/config.h"
typedef void* plot_scatter_t;
int plot_scatter_init(plot_scatter_t *h);
void plot_scatter_setTitle(plot_scatter_t *h, char *title);
void plot_scatter_setNewData(plot_scatter_t *h, _Complex float *data,
LIBLTE_API int plot_scatter_init(plot_scatter_t *h);
LIBLTE_API void plot_scatter_setTitle(plot_scatter_t *h, char *title);
LIBLTE_API void plot_scatter_setNewData(plot_scatter_t *h, _Complex float *data,
int num_points);
void plot_scatter_setXAxisAutoScale(plot_scatter_t *h, bool on);
void plot_scatter_setYAxisAutoScale(plot_scatter_t *h, bool on);
void plot_scatter_setXAxisScale(plot_scatter_t *h, double xMin, double xMax);
void plot_scatter_setYAxisScale(plot_scatter_t *h, double yMin, double yMax);
void plot_scatter_setAxisLabels(plot_scatter_t *h, char *xLabel, char *yLabel);
LIBLTE_API void plot_scatter_setXAxisAutoScale(plot_scatter_t *h, bool on);
LIBLTE_API void plot_scatter_setYAxisAutoScale(plot_scatter_t *h, bool on);
LIBLTE_API void plot_scatter_setXAxisScale(plot_scatter_t *h, double xMin, double xMax);
LIBLTE_API void plot_scatter_setYAxisScale(plot_scatter_t *h, double yMin, double yMax);
LIBLTE_API void plot_scatter_setAxisLabels(plot_scatter_t *h, char *xLabel, char *yLabel);
#ifdef __cplusplus
}

@ -34,24 +34,25 @@ extern "C" {
#endif
#include <stdbool.h>
#include "lte/config.h"
typedef void* plot_waterfall_t;
int plot_waterfall_init(plot_waterfall_t *h);
void plot_waterfall_setTitle(plot_waterfall_t *h, char *title);
void plot_waterfall_appendNewData(plot_waterfall_t *h, float *data,
LIBLTE_API int plot_waterfall_init(plot_waterfall_t *h);
LIBLTE_API void plot_waterfall_setTitle(plot_waterfall_t *h, char *title);
LIBLTE_API void plot_waterfall_appendNewData(plot_waterfall_t *h, float *data,
int num_points);
void plot_complex_setPlotXLabel(plot_waterfall_t *h, char *xLabel);
void plot_complex_setPlotYLabel(plot_waterfall_t *h, char *yLabel);
void plot_waterfall_setPlotXAxisRange(plot_waterfall_t *h, double xMin, double xMax);
void plot_waterfall_setPlotXAxisScale(plot_waterfall_t *h, double xMin, double xMax);
void plot_waterfall_setPlotYAxisScale(plot_waterfall_t *h, double yMin, double yMax);
void plot_waterfall_setSpectrogramXLabel(plot_waterfall_t *h, char* xLabel);
void plot_waterfall_setSpectrogramYLabel(plot_waterfall_t *h, char* yLabel);
void plot_waterfall_setSpectrogramXAxisRange(plot_waterfall_t *h, double xMin, double xMax);
void plot_waterfall_setSpectrogramYAxisRange(plot_waterfall_t *h, double yMin, double yMax);
void plot_waterfall_setSpectrogramZAxisScale(plot_waterfall_t *h, double zMin, double zMax);
LIBLTE_API void plot_complex_setPlotXLabel(plot_waterfall_t *h, char *xLabel);
LIBLTE_API void plot_complex_setPlotYLabel(plot_waterfall_t *h, char *yLabel);
LIBLTE_API void plot_waterfall_setPlotXAxisRange(plot_waterfall_t *h, double xMin, double xMax);
LIBLTE_API void plot_waterfall_setPlotXAxisScale(plot_waterfall_t *h, double xMin, double xMax);
LIBLTE_API void plot_waterfall_setPlotYAxisScale(plot_waterfall_t *h, double yMin, double yMax);
LIBLTE_API void plot_waterfall_setSpectrogramXLabel(plot_waterfall_t *h, char* xLabel);
LIBLTE_API void plot_waterfall_setSpectrogramYLabel(plot_waterfall_t *h, char* yLabel);
LIBLTE_API void plot_waterfall_setSpectrogramXAxisRange(plot_waterfall_t *h, double xMin, double xMax);
LIBLTE_API void plot_waterfall_setSpectrogramYAxisRange(plot_waterfall_t *h, double yMin, double yMax);
LIBLTE_API void plot_waterfall_setSpectrogramZAxisScale(plot_waterfall_t *h, double zMin, double zMax);
#ifdef __cplusplus

@ -67,7 +67,7 @@ IF(QT4_FOUND AND QWT_FOUND AND QWT_MAJOR_VERSION EQUAL 6)
INCLUDE_DIRECTORIES(common complexplot realplot scatterplot waterfallplot ${Boost_INCLUDE_DIRS})
ADD_LIBRARY(graphics ${eventwraps} ${lineplotwraps} ${pointplotwraps} ${spectrogramplotwraps} ${complex} ${real} ${scatter} ${waterfall} ${SOURCES_ALL} )
ADD_LIBRARY(graphics SHARED ${eventwraps} ${lineplotwraps} ${pointplotwraps} ${spectrogramplotwraps} ${complex} ${real} ${scatter} ${waterfall} ${SOURCES_ALL} )
TARGET_LINK_LIBRARIES(graphics pthread ${QT_LIBRARIES} ${QWT_LIBRARIES})
INSTALL(TARGETS graphics DESTINATION ${LIBRARY_DIR})
LIBLTE_SET_PIC(graphics)
@ -75,10 +75,10 @@ IF(QT4_FOUND AND QWT_FOUND AND QWT_MAJOR_VERSION EQUAL 6)
APPEND_INTERNAL_LIST(OPTIONAL_LIBS graphics)
ADD_SUBDIRECTORY(complexplot/test)
ADD_SUBDIRECTORY(realplot/test)
ADD_SUBDIRECTORY(scatterplot/test)
ADD_SUBDIRECTORY(waterfallplot/test)
#ADD_SUBDIRECTORY(complexplot/test)
#ADD_SUBDIRECTORY(realplot/test)
#ADD_SUBDIRECTORY(scatterplot/test)
#ADD_SUBDIRECTORY(waterfallplot/test)
MESSAGE(STATUS " GRAPHICS library will be installed.")

@ -33,8 +33,6 @@
#include "Lineplot.h"
#include "qwt_scale_div.h"
#include "qwt_plot_canvas.h"
#include <algorithm>
class MyZoomer: public QwtPlotZoomer
@ -96,8 +94,7 @@ Lineplot::Lineplot(QWidget *parent)
axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Floating,true);
axisScaleEngine(QwtPlot::yRight)->setAttribute(QwtScaleEngine::Floating,true);
QwtPlotCanvas *mycanvas = qobject_cast<QwtPlotCanvas*>(canvas());
zoomer_ = new MyZoomer(mycanvas);
zoomer_ = new MyZoomer(qobject_cast<QwtPlotCanvas*>(canvas()));
zoomer_->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton);
zoomer_->setMousePattern(QwtEventPattern::MouseSelect2, Qt::LeftButton,
Qt::ControlModifier);
@ -163,5 +160,9 @@ void Lineplot::resetZoom()
void Lineplot::linkScales()
{
// setAxisScaleDiv(QwtPlot::yRight, *axisScaleDiv(QwtPlot::yLeft));
#if QWT_VERSION < 0x060100
setAxisScaleDiv(QwtPlot::yRight, *axisScaleDiv(QwtPlot::yLeft));
#else // QWT_VERSION < 0x060100
setAxisScaleDiv(QwtPlot::yRight, axisScaleDiv(QwtPlot::yLeft));
#endif // QWT_VERSION < 0x060100
}

@ -32,7 +32,6 @@
*/
#include "Pointplot.h"
#include "qwt_plot_canvas.h"
#include <algorithm>
using namespace std;
@ -84,8 +83,7 @@ Pointplot::Pointplot(QWidget *parent)
memset(realPoints_, 0x0, numPoints_*sizeof(double));
memset(imagPoints_, 0x0, numPoints_*sizeof(double));
QwtPlotCanvas *mycanvas = qobject_cast<QwtPlotCanvas*>(canvas());
zoomer_ = new MyZoomer(mycanvas);
zoomer_ = new MyZoomer(qobject_cast<QwtPlotCanvas*>(canvas()));
zoomer_->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton);
zoomer_->setMousePattern(QwtEventPattern::MouseSelect2, Qt::LeftButton,
Qt::ControlModifier);

@ -117,8 +117,7 @@ Spectrogramplot::Spectrogramplot(int numDataPoints, int numRows, QWidget *parent
// RightButton: zoom out by 1
// Ctrl+RighButton: zoom out to full size
QwtPlotCanvas *mycanvas = qobject_cast<QwtPlotCanvas*>(canvas());
zoomer_ = new MyZoomer(mycanvas);
zoomer_ = new MyZoomer(qobject_cast<QwtPlotCanvas*>(canvas()));
zoomer_->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::LeftButton);
zoomer_->setMousePattern(QwtEventPattern::MouseSelect2,

@ -61,5 +61,6 @@ void plot_exit() {
if (plot_initiated) {
pthread_cancel(thread);
}
plot_initiated=0;
}

@ -3,10 +3,11 @@
#include <string>
#include <complex>
#include "lte/config.h"
class ScatterplotWrapper;
class Scatterplot
class LIBLTE_API Scatterplot
{
public:
Scatterplot();
@ -28,7 +29,7 @@ private:
};
template<class Iterator>
void Scatterplot::setNewData(Iterator begin, Iterator end)
LIBLTE_API void Scatterplot::setNewData(Iterator begin, Iterator end)
{
int numPoints = end-begin;
std::complex<double>* data = new std::complex<double>[numPoints];

@ -22,15 +22,17 @@
########################################################################
# Add headers to cmake project (useful for IDEs)
########################################################################
FILE(GLOB headers *)
SET(HEADERS_ALL "")
FILE(GLOB_RECURSE tmp "*.h")
LIST(APPEND HEADERS_ALL ${tmp})
FILE(GLOB headers *)
FOREACH (_header ${headers})
IF(IS_DIRECTORY ${_header})
FILE(GLOB_RECURSE tmp "${_header}/*.h")
LIST(APPEND HEADERS_ALL ${tmp})
ENDIF(IS_DIRECTORY ${_header})
ENDFOREACH()
ADD_CUSTOM_TARGET (add_headers SOURCES ${HEADERS_ALL})
ADD_CUSTOM_TARGET (add_lte_headers SOURCES ${HEADERS_ALL})

@ -32,6 +32,12 @@
#ifndef _LTE_
#define _LTE_
#ifdef __cplusplus
extern "C" {
#endif
#include "lte/config.h"
#include "lte/utils/bit.h"
#include "lte/utils/convolution.h"
#include "lte/utils/debug.h"
@ -94,4 +100,8 @@
#include "lte/sync/sync.h"
#include "lte/sync/cfo.h"
#ifdef __cplusplus
}
#endif
#endif

@ -32,6 +32,7 @@
#include <stdio.h>
#include "lte/config.h"
#include "lte/ch_estimation/refsignal.h"
#include "lte/filter/filter2d.h"
#include "lte/common/base.h"
@ -49,7 +50,7 @@ typedef void (*interpolate_fnc_t) (cf_t *input, cf_t *output, int M, int len, in
*/
/* Low-level API */
typedef struct {
typedef struct LIBLTE_API{
int nof_ports;
int nof_symbols;
int nof_prb;
@ -58,28 +59,28 @@ typedef struct {
interpolate_fnc_t interp;
}chest_t;
int chest_init(chest_t *q, chest_interp_t interp, lte_cp_t cp, int nof_prb, int nof_ports);
void chest_free(chest_t *q);
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);
int chest_ref_LTEDL_slot_port(chest_t *q, int port, int nslot, int cell_id);
int chest_ref_LTEDL_slot(chest_t *q, int nslot, int cell_id);
int chest_ref_LTEDL(chest_t *q, int cell_id);
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);
LIBLTE_API int chest_ref_LTEDL(chest_t *q, int cell_id);
void chest_ce_ref(chest_t *q, cf_t *input, int nslot, int port_id, int nref);
void chest_ce_slot_port(chest_t *q, cf_t *input, cf_t *ce, int nslot, int port_id);
void chest_ce_slot(chest_t *q, cf_t *input, cf_t **ce, int nslot);
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);
void chest_fprint(chest_t *q, FILE *stream, int nslot, int port_id);
void chest_ref_fprint(chest_t *q, FILE *stream, int nslot, int port_id);
void chest_recvsig_fprint(chest_t *q, FILE *stream, int nslot, int port_id);
void chest_ce_fprint(chest_t *q, FILE *stream, int nslot, int port_id);
int chest_ref_symbols(chest_t *q, int port_id, int nslot, int l[2]);
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);
LIBLTE_API void chest_recvsig_fprint(chest_t *q, FILE *stream, int nslot, int port_id);
LIBLTE_API void chest_ce_fprint(chest_t *q, FILE *stream, int nslot, int port_id);
LIBLTE_API int chest_ref_symbols(chest_t *q, int port_id, int nslot, int l[2]);
/* High-level API */
/** TODO: The high-level API has N interfaces, one for each port */
typedef struct {
typedef struct LIBLTE_API{
chest_t obj;
struct chest_init {
int nof_symbols; // 7 for normal cp, 6 for extended
@ -99,8 +100,8 @@ typedef struct {
#define DEFAULT_FRAME_SIZE 2048
int chest_initialize(chest_hl* h);
int chest_work(chest_hl* hl);
int chest_stop(chest_hl* hl);
LIBLTE_API int chest_initialize(chest_hl* h);
LIBLTE_API int chest_work(chest_hl* hl);
LIBLTE_API int chest_stop(chest_hl* hl);
#endif

@ -37,18 +37,19 @@
*
*/
#include "lte/config.h"
#include "lte/common/base.h"
typedef _Complex float cf_t;
typedef struct {
typedef struct LIBLTE_API{
int time_idx;
int freq_idx;
cf_t simbol;
cf_t recv_simbol;
}ref_t;
typedef struct {
typedef struct LIBLTE_API{
int nof_refs; // number of reference signals
int *symbols_ref; // symbols with at least one reference
int nsymbols; // number of symbols with at least one reference
@ -58,10 +59,10 @@ typedef struct {
cf_t *ch_est;
} refsignal_t;
int refsignal_init_LTEDL(refsignal_t *q, int port_id, int nslot,
LIBLTE_API int refsignal_init_LTEDL(refsignal_t *q, int port_id, int nslot,
int cell_id, lte_cp_t cp, int nof_prb);
void refsignal_free(refsignal_t *q);
LIBLTE_API void refsignal_free(refsignal_t *q);
void refsignal_put(refsignal_t *q, cf_t *slot_symbols);
LIBLTE_API void refsignal_put(refsignal_t *q, cf_t *slot_symbols);
#endif

@ -27,18 +27,19 @@
#include <complex.h>
#include "lte/config.h"
#ifndef CH_AWGN_
#define CH_AWGN_
typedef _Complex float cf_t;
void ch_awgn_c(const cf_t* input, cf_t* output, float variance, int buff_sz);
void ch_awgn_f(const float* x, float* y, float variance, int buff_sz);
LIBLTE_API void ch_awgn_c(const cf_t* input, cf_t* output, float variance, int buff_sz);
LIBLTE_API void ch_awgn_f(const float* x, float* y, float variance, int buff_sz);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API{
const cf_t* input;
int in_len;
struct ch_awgn_ctrl_in {
@ -49,8 +50,8 @@ typedef struct {
int out_len;
}ch_awgn_hl;
int ch_awgn_initialize(ch_awgn_hl* hl);
int ch_awgn_work(ch_awgn_hl* hl);
int ch_awgn_stop(ch_awgn_hl* hl);
LIBLTE_API int ch_awgn_initialize(ch_awgn_hl* hl);
LIBLTE_API int ch_awgn_work(ch_awgn_hl* hl);
LIBLTE_API int ch_awgn_stop(ch_awgn_hl* hl);
#endif

@ -29,6 +29,8 @@
#ifndef _LTEBASE_
#define _LTEBASE_
#include "lte/config.h"
#define NSUBFRAMES_X_FRAME 10
#define NSLOTS_X_FRAME (2*NSUBFRAMES_X_FRAME)
@ -95,42 +97,42 @@ typedef enum {CPNORM, CPEXT} lte_cp_t;
#define GUARD_RE(nof_prb) ((lte_symbol_sz(nof_prb)-nof_prb*RE_X_RB)/2)
const int lte_symbol_sz(int nof_prb);
int lte_re_x_prb(int ns, int symbol, int nof_ports, int nof_symbols);
int lte_voffset(int symbol_id, int cell_id, int nof_ports);
LIBLTE_API const int lte_symbol_sz(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);
#define NOF_LTE_BANDS 29
#define NOF_TC_CB_SIZES 188
typedef enum {
typedef enum LIBLTE_API {
SINGLE_ANTENNA,TX_DIVERSITY, SPATIAL_MULTIPLEX
} lte_mimo_type_t;
typedef enum { PHICH_NORM, PHICH_EXT} phich_length_t;
typedef enum { R_1_6, R_1_2, R_1, R_2} phich_resources_t;
typedef enum LIBLTE_API { PHICH_NORM, PHICH_EXT} phich_length_t;
typedef enum LIBLTE_API { R_1_6, R_1_2, R_1, R_2} phich_resources_t;
typedef struct {
typedef struct LIBLTE_API {
int id;
float fd;
}lte_earfcn_t;
enum band_geographical_area {
LIBLTE_API enum band_geographical_area {
ALL, NAR, APAC, EMEA, JAPAN, CALA, NA
};
int lte_cb_size(int index);
int lte_find_cb_index(int long_cb);
LIBLTE_API int lte_cb_size(int index);
LIBLTE_API int lte_find_cb_index(int long_cb);
float lte_band_fd(int earfcn);
int lte_band_get_fd_band(int band, lte_earfcn_t *earfcn, int earfcn_start, int earfcn_end, int max_elems);
int lte_band_get_fd_band_all(int band, lte_earfcn_t *earfcn, int max_nelems);
int lte_band_get_fd_region(enum band_geographical_area region, lte_earfcn_t *earfcn, int max_elems);
LIBLTE_API float lte_band_fd(int earfcn);
LIBLTE_API int lte_band_get_fd_band(int band, lte_earfcn_t *earfcn, int earfcn_start, int earfcn_end, int max_elems);
LIBLTE_API int lte_band_get_fd_band_all(int band, lte_earfcn_t *earfcn, int max_nelems);
LIBLTE_API int lte_band_get_fd_region(enum band_geographical_area region, lte_earfcn_t *earfcn, int max_elems);
int lte_str2mimotype(char *mimo_type_str, lte_mimo_type_t *type);
char *lte_mimotype2str(lte_mimo_type_t type);
LIBLTE_API int lte_str2mimotype(char *mimo_type_str, lte_mimo_type_t *type);
LIBLTE_API char *lte_mimotype2str(lte_mimo_type_t type);
#endif

@ -33,13 +33,14 @@
#include <strings.h>
#include <stdlib.h>
#include "lte/config.h"
#include "lte/common/base.h"
#include "lte/utils/dft.h"
typedef _Complex float cf_t; /* this is only a shortcut */
/* This is common for both directions */
typedef struct {
typedef struct LIBLTE_API{
dft_plan_t fft_plan;
int nof_symbols;
int symbol_sz;
@ -49,12 +50,12 @@ typedef struct {
cf_t *tmp; // for removing zero padding
}lte_fft_t;
int lte_fft_init(lte_fft_t *q, lte_cp_t cp_type, int nof_prb);
void lte_fft_free(lte_fft_t *q);
void lte_fft_run(lte_fft_t *q, cf_t *input, cf_t *output);
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);
int lte_ifft_init(lte_fft_t *q, lte_cp_t cp_type, int nof_prb);
void lte_ifft_free(lte_fft_t *q);
void lte_ifft_run(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);
#endif

@ -25,26 +25,26 @@
*
*/
#ifndef LTESEQ_
#define LTESEQ_
#include "lte/common/base.h"
typedef struct {
typedef struct LIBLTE_API {
char *c;
int len;
}sequence_t;
} sequence_t;
int sequence_init(sequence_t *q, int len);
void sequence_free(sequence_t *q);
LIBLTE_API int sequence_init(sequence_t *q, int len);
LIBLTE_API void sequence_free(sequence_t *q);
int sequence_LTEPRS(sequence_t *q, int len, int seed);
LIBLTE_API int sequence_LTEPRS(sequence_t *q, int len, int seed);
int sequence_pbch(sequence_t *seq, lte_cp_t cp, int cell_id);
int sequence_pcfich(sequence_t *seq, int nslot, int cell_id);
int sequence_phich(sequence_t *seq, int nslot, int cell_id);
int sequence_pdcch(sequence_t *seq, int nslot, int cell_id, int len);
int sequence_pdsch(sequence_t *seq, unsigned short rnti, int q, int nslot, int cell_id, int len);
LIBLTE_API int sequence_pbch(sequence_t *seq, lte_cp_t cp, int cell_id);
LIBLTE_API int sequence_pcfich(sequence_t *seq, int nslot, int cell_id);
LIBLTE_API int sequence_phich(sequence_t *seq, int nslot, int cell_id);
LIBLTE_API int sequence_pdcch(sequence_t *seq, int nslot, int cell_id, int len);
LIBLTE_API int sequence_pdsch(sequence_t *seq, unsigned short rnti, int q,
int nslot, int cell_id, int len);
#endif

@ -0,0 +1,55 @@
/**
*
* \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 CONFIG_H
#define CONFIG_H
// Generic helper definitions for shared library support
#if defined _WIN32 || defined __CYGWIN__
#define LIBLTE_IMPORT __declspec(dllimport)
#define LIBLTE_EXPORT __declspec(dllexport)
#define LIBLTE_LOCAL
#else
#if __GNUC__ >= 4
#define LIBLTE_IMPORT __attribute__ ((visibility ("default")))
#define LIBLTE_EXPORT __attribute__ ((visibility ("default")))
#else
#define LIBLTE_IMPORT
#define LIBLTE_EXPORT
#define LIBLTE_LOCAL
#endif
#endif
// Define LIBLTE_API
// LIBLTE_API is used for the public API symbols.
#ifdef LIBLTE_DLL_EXPORTS // defined if we are building the LIBLTE DLL (instead of using it)
#define LIBLTE_API LIBLTE_EXPORT
#else
#define LIBLTE_API LIBLTE_IMPORT
#endif
#endif // CONFIG_H

@ -31,21 +31,20 @@
#define CONVCODER_
#include <stdbool.h>
#include "lte/config.h"
typedef struct {
typedef struct LIBLTE_API {
int R;
int K;
int poly[3];
bool tail_biting;
}convcoder_t;
int convcoder_encode(convcoder_t *q, char *input, char *output, int frame_length);
LIBLTE_API int convcoder_encode(convcoder_t *q, char *input, char *output, int frame_length);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
convcoder_t obj;
struct convcoder_ctrl_in {
int rate;
@ -62,8 +61,8 @@ typedef struct {
int out_len;
}convcoder_hl;
int convcoder_initialize(convcoder_hl* h);
int convcoder_work(convcoder_hl* hl);
int convcoder_stop(convcoder_hl* h);
LIBLTE_API int convcoder_initialize(convcoder_hl* h);
LIBLTE_API int convcoder_work(convcoder_hl* hl);
LIBLTE_API int convcoder_stop(convcoder_hl* h);
#endif

@ -29,7 +29,9 @@
#ifndef CRC_
#define CRC_
typedef struct {
#include "lte/config.h"
typedef struct LIBLTE_API {
unsigned long table[256];
unsigned char byte;
int polynom;
@ -40,9 +42,9 @@ typedef struct {
unsigned int crc_out;
} crc_t;
int crc_init(crc_t *h, unsigned int crc_poly, int crc_order);
int crc_set_init(crc_t *h, unsigned long crc_init_value);
void crc_attach(crc_t *h, char *data, int len);
unsigned int crc_checksum(crc_t *h, char *data, int len);
LIBLTE_API int crc_init(crc_t *h, unsigned int crc_poly, int crc_order);
LIBLTE_API int crc_set_init(crc_t *h, unsigned long crc_init_value);
LIBLTE_API void crc_attach(crc_t *h, char *data, int len);
LIBLTE_API unsigned int crc_checksum(crc_t *h, char *data, int len);
#endif

@ -25,20 +25,20 @@
*
*/
#ifndef RM_CONV_
#define RM_CONV_
#include "lte/config.h"
#define RX_NULL 10000
#define TX_NULL 80
int rm_conv_tx(char *input, int in_len, char *output, int out_len);
int rm_conv_rx(float *input, int in_len, float *output, int out_len);
LIBLTE_API int rm_conv_tx(char *input, int in_len, char *output, int out_len);
LIBLTE_API int rm_conv_rx(float *input, int in_len, float *output, int out_len);
/* High-level API */
typedef struct {
typedef struct
LIBLTE_API {
struct rm_conv_init {
int direction;
} init;
@ -50,10 +50,10 @@ typedef struct {
} ctrl_in;
void *output;
int out_len;
}rm_conv_hl;
} rm_conv_hl;
int rm_conv_initialize(rm_conv_hl* h);
int rm_conv_work(rm_conv_hl* hl);
int rm_conv_stop(rm_conv_hl* hl);
LIBLTE_API int rm_conv_initialize(rm_conv_hl* h);
LIBLTE_API int rm_conv_work(rm_conv_hl* hl);
LIBLTE_API int rm_conv_stop(rm_conv_hl* hl);
#endif

@ -25,7 +25,6 @@
*
*/
#ifndef RM_TURBO_
#define RM_TURBO_
@ -37,19 +36,22 @@
#define TX_NULL 100
#endif
typedef struct {
#include "lte/config.h"
typedef struct LIBLTE_API {
int buffer_len;
char *buffer;
} rm_turbo_t;
int rm_turbo_init(rm_turbo_t *q, int max_codeblock_len);
void rm_turbo_free(rm_turbo_t *q);
int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_len, int rv_idx);
int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_len, int rv_idx);
LIBLTE_API int rm_turbo_init(rm_turbo_t *q, int max_codeblock_len);
LIBLTE_API void rm_turbo_free(rm_turbo_t *q);
LIBLTE_API int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output,
int out_len, int rv_idx);
LIBLTE_API int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len,
float *output, int out_len, int rv_idx);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
rm_turbo_t q;
struct rm_turbo_init {
int direction;
@ -63,10 +65,10 @@ typedef struct {
} ctrl_in;
void *output;
int out_len;
}rm_turbo_hl;
} rm_turbo_hl;
int rm_turbo_initialize(rm_turbo_hl* h);
int rm_turbo_work(rm_turbo_hl* hl);
int rm_turbo_stop(rm_turbo_hl* hl);
LIBLTE_API int rm_turbo_initialize(rm_turbo_hl* h);
LIBLTE_API int rm_turbo_work(rm_turbo_hl* hl);
LIBLTE_API int rm_turbo_stop(rm_turbo_hl* hl);
#endif

@ -28,16 +28,18 @@
#ifndef _TC_INTERL_H
#define _TC_INTERL_H
typedef struct {
#include "lte/config.h"
typedef struct LIBLTE_API {
int *forward;
int *reverse;
int max_long_cb;
}tc_interl_t;
} tc_interl_t;
int tc_interl_LTE_gen(tc_interl_t *h, int long_cb);
int tc_interl_UMTS_gen(tc_interl_t *h, int long_cb);
LIBLTE_API int tc_interl_LTE_gen(tc_interl_t *h, int long_cb);
LIBLTE_API int tc_interl_UMTS_gen(tc_interl_t *h, int long_cb);
int tc_interl_init(tc_interl_t *h, int max_long_cb);
void tc_interl_free(tc_interl_t *h);
LIBLTE_API int tc_interl_init(tc_interl_t *h, int max_long_cb);
LIBLTE_API void tc_interl_free(tc_interl_t *h);
#endif

@ -29,21 +29,21 @@
#define TURBOCODER_
#include "lte/fec/tc_interl.h"
#include "lte/config.h"
#define NUMREGS 3
#define RATE 3
#define TOTALTAIL 12
typedef struct {
typedef struct LIBLTE_API {
int max_long_cb;
tc_interl_t interl;
} tcod_t;
}tcod_t;
int tcod_init(tcod_t *h, int max_long_cb);
void tcod_free(tcod_t *h);
int tcod_encode(tcod_t *h, char *input, char *output, int long_cb);
LIBLTE_API int tcod_init(tcod_t *h, int max_long_cb);
LIBLTE_API void tcod_free(tcod_t *h);
LIBLTE_API int tcod_encode(tcod_t *h, char *input, char *output, int long_cb);
#endif

@ -29,6 +29,7 @@
#define TURBODECODER_
#include "lte/fec/tc_interl.h"
#include "lte/config.h"
#define RATE 3
#define TOTALTAIL 12
@ -48,12 +49,12 @@
typedef float llr_t;
typedef struct {
typedef struct LIBLTE_API {
int max_long_cb;
llr_t *beta;
}map_gen_t;
} map_gen_t;
typedef struct {
typedef struct LIBLTE_API {
int max_long_cb;
map_gen_t dec;
@ -65,14 +66,15 @@ typedef struct {
llr_t *parity;
tc_interl_t interleaver;
}tdec_t;
} tdec_t;
int tdec_init(tdec_t *h, int max_long_cb);
void tdec_free(tdec_t *h);
LIBLTE_API int tdec_init(tdec_t *h, int max_long_cb);
LIBLTE_API void tdec_free(tdec_t *h);
int tdec_reset(tdec_t *h, int long_cb);
void tdec_iteration(tdec_t *h, llr_t *input, int long_cb);
void tdec_decision(tdec_t *h, char *output, int long_cb);
void tdec_run_all(tdec_t *h, llr_t *input, char *output, int nof_iterations, int long_cb);
LIBLTE_API int tdec_reset(tdec_t *h, int long_cb);
LIBLTE_API void tdec_iteration(tdec_t *h, llr_t *input, int long_cb);
LIBLTE_API void tdec_decision(tdec_t *h, char *output, int long_cb);
LIBLTE_API void tdec_run_all(tdec_t *h, llr_t *input, char *output, int nof_iterations,
int long_cb);
#endif

@ -30,12 +30,13 @@
#define VITERBI_
#include <stdbool.h>
#include "lte/config.h"
typedef enum {
viterbi_27, viterbi_29, viterbi_37, viterbi_39
}viterbi_type_t;
typedef struct {
typedef struct LIBLTE_API{
void *ptr;
int R;
int K;
@ -48,14 +49,14 @@ typedef struct {
unsigned char *symbols_uc;
}viterbi_t;
int viterbi_init(viterbi_t *q, viterbi_type_t type, int poly[3], int max_frame_length, bool tail_bitting);
void viterbi_free(viterbi_t *q);
int viterbi_decode_f(viterbi_t *q, float *symbols, char *data, int frame_length);
int viterbi_decode_uc(viterbi_t *q, unsigned char *symbols, char *data, int frame_length);
LIBLTE_API int viterbi_init(viterbi_t *q, viterbi_type_t type, int poly[3], int max_frame_length, bool tail_bitting);
LIBLTE_API void viterbi_free(viterbi_t *q);
LIBLTE_API int viterbi_decode_f(viterbi_t *q, float *symbols, char *data, int frame_length);
LIBLTE_API int viterbi_decode_uc(viterbi_t *q, unsigned char *symbols, char *data, int frame_length);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API{
viterbi_t obj;
struct viterbi_init {
int rate;
@ -72,8 +73,8 @@ typedef struct {
int out_len;
}viterbi_hl;
int viterbi_initialize(viterbi_hl* h);
int viterbi_work(viterbi_hl* hl);
int viterbi_stop(viterbi_hl* h);
LIBLTE_API int viterbi_initialize(viterbi_hl* h);
LIBLTE_API int viterbi_work(viterbi_hl* hl);
LIBLTE_API int viterbi_stop(viterbi_hl* h);
#endif

@ -30,12 +30,14 @@
#ifndef FILTER2D_
#define FILTER2D_
#include "lte/config.h"
/* 2-D real filter of complex input
*
*/
typedef _Complex float cf_t;
typedef struct {
typedef struct LIBLTE_API{
int sztime; // Output signal size in the time domain
int szfreq; // Output signal size in the freq domain
int ntime; // 2-D Filter size in time domain
@ -44,10 +46,10 @@ typedef struct {
cf_t *output; // Output signal
} filter2d_t;
int filter2d_init (filter2d_t* q, float **taps, int ntime, int nfreq, int sztime, int szfreq);
int filter2d_init_default (filter2d_t* q, int ntime, int nfreq, int sztime, int szfreq);
void filter2d_free(filter2d_t *q);
void filter2d_reset(filter2d_t *q);
void filter2d_add(filter2d_t *q, cf_t h, int time_idx, int freq_idx);
LIBLTE_API int filter2d_init (filter2d_t* q, float **taps, int ntime, int nfreq, int sztime, int szfreq);
LIBLTE_API int filter2d_init_default (filter2d_t* q, int ntime, int nfreq, int sztime, int szfreq);
LIBLTE_API void filter2d_free(filter2d_t *q);
LIBLTE_API void filter2d_reset(filter2d_t *q);
LIBLTE_API void filter2d_add(filter2d_t *q, cf_t h, int time_idx, int freq_idx);
#endif
#endif // FILTER2D_

@ -31,9 +31,10 @@
#include <stdint.h>
#include "lte/config.h"
/* Low-level API */
typedef struct {
typedef struct LIBLTE_API{
unsigned int seed;
uint32_t *seq_buff;
int seq_buff_nwords;
@ -41,16 +42,16 @@ typedef struct {
int seq_cache_rp;
}binsource_t;
void binsource_init(binsource_t* q);
void binsource_free(binsource_t* q);
void binsource_seed_set(binsource_t* q, unsigned int seed);
void binsource_seed_time(binsource_t *q);
int binsource_cache_gen(binsource_t* q, int nbits);
void binsource_cache_cpy(binsource_t* q, char *bits, int nbits);
int binsource_generate(binsource_t* q, char *bits, int nbits);
LIBLTE_API void binsource_init(binsource_t* q);
LIBLTE_API void binsource_free(binsource_t* q);
LIBLTE_API void binsource_seed_set(binsource_t* q, unsigned int seed);
LIBLTE_API void binsource_seed_time(binsource_t *q);
LIBLTE_API int binsource_cache_gen(binsource_t* q, int nbits);
LIBLTE_API void binsource_cache_cpy(binsource_t* q, char *bits, int nbits);
LIBLTE_API int binsource_generate(binsource_t* q, char *bits, int nbits);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
binsource_t obj;
struct binsource_init {
int cache_seq_nbits; // If non-zero, generates random bits on init
@ -63,8 +64,8 @@ typedef struct {
int out_len;
}binsource_hl;
int binsource_initialize(binsource_hl* h);
int binsource_work( binsource_hl* hl);
int binsource_stop(binsource_hl* hl);
LIBLTE_API int binsource_initialize(binsource_hl* h);
LIBLTE_API int binsource_work( binsource_hl* hl);
LIBLTE_API int binsource_stop(binsource_hl* hl);
#endif
#endif // BINSOURCE_

@ -32,22 +32,23 @@
#include <stdint.h>
#include <stdlib.h>
#include "lte/config.h"
#include "lte/io/format.h"
/* Low-level API */
typedef struct {
typedef struct LIBLTE_API {
FILE *f;
data_type_t type;
}filesink_t;
int filesink_init(filesink_t *q, char *filename, data_type_t type);
void filesink_free(filesink_t *q);
LIBLTE_API int filesink_init(filesink_t *q, char *filename, data_type_t type);
LIBLTE_API void filesink_free(filesink_t *q);
int filesink_write(filesink_t *q, void *buffer, int nsamples);
LIBLTE_API int filesink_write(filesink_t *q, void *buffer, int nsamples);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
filesink_t obj;
struct filesink_init {
char *file_name;
@ -58,8 +59,8 @@ typedef struct {
int in_len;
}filesink_hl;
int filesink_initialize(filesink_hl* h);
int filesink_work( filesink_hl* hl);
int filesink_stop(filesink_hl* h);
LIBLTE_API int filesink_initialize(filesink_hl* h);
LIBLTE_API int filesink_work( filesink_hl* hl);
LIBLTE_API int filesink_stop(filesink_hl* h);
#endif
#endif // FILESINK_

@ -32,23 +32,24 @@
#include <stdint.h>
#include <stdlib.h>
#include "lte/config.h"
#include "lte/io/format.h"
/* Low-level API */
typedef struct {
typedef struct LIBLTE_API {
FILE *f;
data_type_t type;
}filesource_t;
int filesource_init(filesource_t *q, char *filename, data_type_t type);
void filesource_free(filesource_t *q);
LIBLTE_API int filesource_init(filesource_t *q, char *filename, data_type_t type);
LIBLTE_API void filesource_free(filesource_t *q);
void filesource_seek(filesource_t *q, int pos);
int filesource_read(filesource_t *q, void *buffer, int nsamples);
LIBLTE_API void filesource_seek(filesource_t *q, int pos);
LIBLTE_API int filesource_read(filesource_t *q, void *buffer, int nsamples);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
filesource_t obj;
struct filesource_init {
char *file_name;
@ -62,8 +63,8 @@ typedef struct {
int out_len;
}filesource_hl;
int filesource_initialize(filesource_hl* h);
int filesource_work( filesource_hl* hl);
int filesource_stop(filesource_hl* h);
LIBLTE_API int filesource_initialize(filesource_hl* h);
LIBLTE_API int filesource_work( filesource_hl* hl);
LIBLTE_API int filesource_stop(filesource_hl* h);
#endif
#endif // FILESOURCE_

@ -31,4 +31,4 @@
typedef enum { FLOAT, COMPLEX_FLOAT, COMPLEX_SHORT, FLOAT_BIN, COMPLEX_FLOAT_BIN, COMPLEX_SHORT_BIN} data_type_t;
#endif
#endif // FORMAT_

@ -26,8 +26,8 @@
*/
#ifndef udpsink_
#define udpsink_
#ifndef UDPSINK_
#define UDPSINK_
#include <sys/socket.h>
#include <netinet/in.h>
@ -35,23 +35,24 @@
#include <stdint.h>
#include <stdlib.h>
#include "lte/config.h"
#include "lte/io/format.h"
/* Low-level API */
typedef struct {
typedef struct LIBLTE_API {
int sockfd;
struct sockaddr_in servaddr;
data_type_t type;
}udpsink_t;
int udpsink_init(udpsink_t *q, char *address, int port, data_type_t type);
void udpsink_free(udpsink_t *q);
LIBLTE_API int udpsink_init(udpsink_t *q, char *address, int port, data_type_t type);
LIBLTE_API void udpsink_free(udpsink_t *q);
int udpsink_write(udpsink_t *q, void *buffer, int nsamples);
LIBLTE_API int udpsink_write(udpsink_t *q, void *buffer, int nsamples);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
udpsink_t obj;
struct udpsink_init {
char *address;
@ -63,8 +64,8 @@ typedef struct {
int in_len;
}udpsink_hl;
int udpsink_initialize(udpsink_hl* h);
int udpsink_work( udpsink_hl* hl);
int udpsink_stop(udpsink_hl* h);
LIBLTE_API int udpsink_initialize(udpsink_hl* h);
LIBLTE_API int udpsink_work( udpsink_hl* hl);
LIBLTE_API int udpsink_stop(udpsink_hl* h);
#endif
#endif // UDPSINK_

@ -26,8 +26,8 @@
*/
#ifndef udpsource_
#define udpsource_
#ifndef UDPSOURCE_
#define UDPSOURCE_
#include <sys/socket.h>
@ -36,23 +36,24 @@
#include <stdint.h>
#include <stdlib.h>
#include "lte/config.h"
#include "lte/io/format.h"
/* Low-level API */
typedef struct {
typedef struct LIBLTE_API {
int sockfd;
struct sockaddr_in servaddr;
data_type_t type;
}udpsource_t;
int udpsource_init(udpsource_t *q, char *address, int port, data_type_t type);
void udpsource_free(udpsource_t *q);
LIBLTE_API int udpsource_init(udpsource_t *q, char *address, int port, data_type_t type);
LIBLTE_API void udpsource_free(udpsource_t *q);
int udpsource_read(udpsource_t *q, void *buffer, int nsamples);
LIBLTE_API int udpsource_read(udpsource_t *q, void *buffer, int nsamples);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
udpsource_t obj;
struct udpsource_init {
char *address;
@ -66,8 +67,8 @@ typedef struct {
int out_len;
}udpsource_hl;
int udpsource_initialize(udpsource_hl* h);
int udpsource_work( udpsource_hl* hl);
int udpsource_stop(udpsource_hl* h);
LIBLTE_API int udpsource_initialize(udpsource_hl* h);
LIBLTE_API int udpsource_work( udpsource_hl* hl);
LIBLTE_API int udpsource_stop(udpsource_hl* h);
#endif
#endif // UDPSOURCE_

@ -29,25 +29,27 @@
#ifndef LAYERMAP_H_
#define LAYERMAP_H_
#include "lte/config.h"
typedef _Complex float cf_t;
/* Generates the vector of layer-mapped symbols "x" based on the vector of data symbols "d"
*/
int layermap_single(cf_t *d, cf_t *x, int nof_symbols);
int layermap_diversity(cf_t *d, cf_t *x[MAX_LAYERS], int nof_layers, int nof_symbols);
int layermap_multiplex(cf_t *d[MAX_CODEWORDS], cf_t *x[MAX_LAYERS], int nof_cw, int nof_layers,
LIBLTE_API int layermap_single(cf_t *d, cf_t *x, int nof_symbols);
LIBLTE_API int layermap_diversity(cf_t *d, cf_t *x[MAX_LAYERS], int nof_layers, int nof_symbols);
LIBLTE_API int layermap_multiplex(cf_t *d[MAX_CODEWORDS], cf_t *x[MAX_LAYERS], int nof_cw, int nof_layers,
int nof_symbols[MAX_CODEWORDS]);
int layermap_type(cf_t *d[MAX_CODEWORDS], cf_t *x[MAX_LAYERS], int nof_cw, int nof_layers,
LIBLTE_API int layermap_type(cf_t *d[MAX_CODEWORDS], cf_t *x[MAX_LAYERS], int nof_cw, int nof_layers,
int nof_symbols[MAX_CODEWORDS], lte_mimo_type_t type);
/* Generates the vector of data symbols "d" based on the vector of layer-mapped symbols "x"
*/
int layerdemap_single(cf_t *x, cf_t *d, int nof_symbols);
int layerdemap_diversity(cf_t *x[MAX_LAYERS], cf_t *d, int nof_layers, int nof_layer_symbols);
int layerdemap_multiplex(cf_t *x[MAX_LAYERS], cf_t *d[MAX_CODEWORDS], int nof_layers, int nof_cw,
LIBLTE_API int layerdemap_single(cf_t *x, cf_t *d, int nof_symbols);
LIBLTE_API int layerdemap_diversity(cf_t *x[MAX_LAYERS], cf_t *d, int nof_layers, int nof_layer_symbols);
LIBLTE_API int layerdemap_multiplex(cf_t *x[MAX_LAYERS], cf_t *d[MAX_CODEWORDS], int nof_layers, int nof_cw,
int nof_layer_symbols, int nof_symbols[MAX_CODEWORDS]);
int layerdemap_type(cf_t *x[MAX_LAYERS], cf_t *d[MAX_CODEWORDS], int nof_layers, int nof_cw,
LIBLTE_API int layerdemap_type(cf_t *x[MAX_LAYERS], cf_t *d[MAX_CODEWORDS], int nof_layers, int nof_cw,
int nof_layer_symbols, int nof_symbols[MAX_CODEWORDS], lte_mimo_type_t type);
#endif
#endif // LAYERMAP_H_

@ -25,7 +25,6 @@
*
*/
#ifndef PRECODING_H_
#define PRECODING_H_
@ -38,19 +37,18 @@ typedef _Complex float cf_t;
/* Generates the vector "y" from the input vector "x"
*/
int precoding_single(cf_t *x, cf_t *y, int nof_symbols);
int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports, int nof_symbols);
int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int nof_ports,
int nof_symbols, lte_mimo_type_t type);
LIBLTE_API int precoding_single(cf_t *x, cf_t *y, int nof_symbols);
LIBLTE_API int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports,
int nof_symbols);
LIBLTE_API int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers,
int nof_ports, int nof_symbols, lte_mimo_type_t type);
/* Estimates the vector "x" based on the received signal "y" and the channel estimates "ce"
*/
int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols);
int predecoding_diversity_zf(cf_t *y, cf_t *ce[MAX_PORTS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_symbols);
int predecoding_type(cf_t *y, cf_t *ce[MAX_PORTS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_layers, int nof_symbols,
lte_mimo_type_t type);
LIBLTE_API int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols);
LIBLTE_API int predecoding_diversity_zf(cf_t *y, cf_t *ce[MAX_PORTS], cf_t *x[MAX_LAYERS],
int nof_ports, int nof_symbols);
LIBLTE_API int predecoding_type(cf_t *y, cf_t *ce[MAX_PORTS], cf_t *x[MAX_LAYERS],
int nof_ports, int nof_layers, int nof_symbols, lte_mimo_type_t type);
#endif /* PRECODING_H_ */

@ -32,23 +32,24 @@
#include <complex.h>
#include <stdint.h>
#include "lte/config.h"
#include "modem_table.h"
typedef _Complex float cf_t;
typedef struct {
typedef struct LIBLTE_API {
enum modem_std table; /* In this implementation, mapping table is hard-coded */
}demod_hard_t;
void demod_hard_init(demod_hard_t* q);
void demod_hard_table_set(demod_hard_t* q, enum modem_std table);
int demod_hard_demodulate(demod_hard_t* q, cf_t* symbols, char *bits, int nsymbols);
LIBLTE_API void demod_hard_init(demod_hard_t* q);
LIBLTE_API void demod_hard_table_set(demod_hard_t* q, enum modem_std table);
LIBLTE_API int demod_hard_demodulate(demod_hard_t* q, cf_t* symbols, char *bits, int nsymbols);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
demod_hard_t obj;
struct demod_hard_init {
enum modem_std std; // Symbol mapping standard (see modem_table.h)
@ -61,9 +62,9 @@ typedef struct {
int out_len;
}demod_hard_hl;
int demod_hard_initialize(demod_hard_hl* hl);
int demod_hard_work(demod_hard_hl* hl);
int demod_hard_stop(demod_hard_hl* hl);
LIBLTE_API int demod_hard_initialize(demod_hard_hl* hl);
LIBLTE_API int demod_hard_work(demod_hard_hl* hl);
LIBLTE_API int demod_hard_stop(demod_hard_hl* hl);
#endif
#endif // DEMOD_HARD_

@ -32,29 +32,30 @@
#include <complex.h>
#include <stdint.h>
#include "lte/config.h"
#include "modem_table.h"
enum alg { EXACT, APPROX };
typedef struct {
typedef struct LIBLTE_API {
float sigma; // noise power
enum alg alg_type; // soft demapping algorithm (EXACT or APPROX)
modem_table_t *table; // symbol mapping table (see modem_table.h)
}demod_soft_t;
void demod_soft_init(demod_soft_t *q);
void demod_soft_table_set(demod_soft_t *q, modem_table_t *table);
void demod_soft_alg_set(demod_soft_t *q, enum alg alg_type);
void demod_soft_sigma_set(demod_soft_t *q, float sigma);
int demod_soft_demodulate(demod_soft_t *q, const cf_t* symbols, float* llr, int nsymbols);
LIBLTE_API void demod_soft_init(demod_soft_t *q);
LIBLTE_API void demod_soft_table_set(demod_soft_t *q, modem_table_t *table);
LIBLTE_API void demod_soft_alg_set(demod_soft_t *q, enum alg alg_type);
LIBLTE_API void demod_soft_sigma_set(demod_soft_t *q, float sigma);
LIBLTE_API int demod_soft_demodulate(demod_soft_t *q, const cf_t* symbols, float* llr, int nsymbols);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
demod_soft_t obj;
modem_table_t table;
struct demod_soft_init {
struct demod_soft_init{
enum modem_std std; // symbol mapping standard (see modem_table.h)
} init;
@ -71,9 +72,9 @@ typedef struct {
}demod_soft_hl;
int demod_soft_initialize(demod_soft_hl* hl);
int demod_soft_work(demod_soft_hl* hl);
int demod_soft_stop(demod_soft_hl* hl);
LIBLTE_API int demod_soft_initialize(demod_soft_hl* hl);
LIBLTE_API int demod_soft_work(demod_soft_hl* hl);
LIBLTE_API int demod_soft_stop(demod_soft_hl* hl);
#endif
#endif // DEMOD_SOFT_

@ -32,14 +32,15 @@
#include <complex.h>
#include <stdint.h>
#include "lte/config.h"
#include "modem_table.h"
typedef _Complex float cf_t;
int mod_modulate(modem_table_t* table, const char *bits, cf_t* symbols, int nbits);
LIBLTE_API int mod_modulate(modem_table_t* table, const char *bits, cf_t* symbols, int nbits);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
modem_table_t obj;
struct mod_init {
enum modem_std std; // symbol mapping standard (see modem_table.h)
@ -52,8 +53,8 @@ typedef struct {
int out_len;
}mod_hl;
int mod_initialize(mod_hl* hl);
int mod_work(mod_hl* hl);
int mod_stop(mod_hl* hl);
LIBLTE_API int mod_initialize(mod_hl* hl);
LIBLTE_API int mod_work(mod_hl* hl);
LIBLTE_API int mod_stop(mod_hl* hl);
#endif
#endif // MOD_

@ -34,12 +34,14 @@
#include <complex.h>
#include <stdint.h>
#include "lte/config.h"
typedef _Complex float cf_t;
typedef struct {
typedef struct LIBLTE_API {
int idx[2][6][32];
}soft_table_t;
typedef struct {
typedef struct LIBLTE_API {
cf_t* symbol_table; // bit-to-symbol mapping
soft_table_t soft_table; // symbol-to-bit mapping (used in soft demodulating)
int nsymbols; // number of modulation symbols
@ -52,10 +54,10 @@ enum modem_std {
LTE_BPSK = 1, LTE_QPSK = 2, LTE_QAM16 = 4, LTE_QAM64 = 6
};
void modem_table_init(modem_table_t* q);
void modem_table_free(modem_table_t* q);
void modem_table_reset(modem_table_t* q);
int modem_table_set(modem_table_t* q, cf_t* table, soft_table_t *soft_table, int nsymbols, int nbits_x_symbol);
int modem_table_std(modem_table_t* q, enum modem_std table, bool compute_soft_demod);
LIBLTE_API void modem_table_init(modem_table_t* q);
LIBLTE_API void modem_table_free(modem_table_t* q);
LIBLTE_API void modem_table_reset(modem_table_t* q);
LIBLTE_API int modem_table_set(modem_table_t* q, cf_t* table, soft_table_t *soft_table, int nsymbols, int nbits_x_symbol);
LIBLTE_API int modem_table_std(modem_table_t* q, enum modem_std table, bool compute_soft_demod);
#endif
#endif // MODEM_TABLE_

@ -28,8 +28,10 @@
#ifndef DCI_
#define DCI_
#include "lte/common/base.h"
#include <stdint.h>
#include "lte/config.h"
#include "lte/common/base.h"
#include "lte/phch/ra.h"
typedef _Complex float cf_t;
@ -48,7 +50,7 @@ typedef enum {
} dci_format_t;
// Each type is for a different interface to packing/unpacking functions
typedef struct {
typedef struct LIBLTE_API {
enum {
PUSCH_SCHED, PDSCH_SCHED, MCCH_CHANGE, TPC_COMMAND, RA_PROC_PDCCH
} type;
@ -59,42 +61,42 @@ typedef enum {
DCI_COMMON = 0, DCI_UE = 1
} dci_spec_t;
typedef struct {
typedef struct LIBLTE_API {
unsigned char nof_bits;
unsigned char L; // Aggregation level
unsigned char ncce; // Position of first CCE of the dci
unsigned short rnti;
} dci_candidate_t;
typedef struct {
typedef struct LIBLTE_API {
char data[DCI_MAX_BITS];
dci_candidate_t location;
} dci_msg_t;
typedef struct {
typedef struct LIBLTE_API {
dci_msg_t *msg;
int nof_dcis;
int max_dcis;
} dci_t;
int dci_init(dci_t *q, int max_dci);
void dci_free(dci_t *q);
char* dci_format_string(dci_format_t format);
LIBLTE_API int dci_init(dci_t *q, int max_dci);
LIBLTE_API void dci_free(dci_t *q);
LIBLTE_API char* dci_format_string(dci_format_t format);
int dci_msg_candidate_set(dci_msg_t *msg, int L, int nCCE, unsigned short rnti);
void dci_candidate_fprint(FILE *f, dci_candidate_t *q);
LIBLTE_API int dci_msg_candidate_set(dci_msg_t *msg, int L, int nCCE, unsigned short rnti);
LIBLTE_API void dci_candidate_fprint(FILE *f, dci_candidate_t *q);
int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, int nof_prb, unsigned short crnti);
void dci_msg_type_fprint(FILE *f, dci_msg_type_t type);
LIBLTE_API int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, int nof_prb, unsigned short crnti);
LIBLTE_API void dci_msg_type_fprint(FILE *f, dci_msg_type_t type);
// For dci_msg_type_t = PUSCH_SCHED
int dci_msg_pack_pusch(ra_pusch_t *data, dci_msg_t *msg, int nof_prb);
int dci_msg_unpack_pusch(dci_msg_t *msg, ra_pusch_t *data, int nof_prb);
LIBLTE_API int dci_msg_pack_pusch(ra_pusch_t *data, dci_msg_t *msg, int nof_prb);
LIBLTE_API int dci_msg_unpack_pusch(dci_msg_t *msg, ra_pusch_t *data, int nof_prb);
// For dci_msg_type_t = PDSCH_SCHED
int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format, int nof_prb, bool crc_is_crnti);
int dci_msg_unpack_pdsch(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc_is_crnti);
LIBLTE_API int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format, int nof_prb, bool crc_is_crnti);
LIBLTE_API int dci_msg_unpack_pdsch(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc_is_crnti);
int dci_format_sizeof(dci_format_t format, int nof_prb);
LIBLTE_API int dci_format_sizeof(dci_format_t format, int nof_prb);
#endif
#endif // DCI_

@ -29,6 +29,7 @@
#ifndef PBCH_
#define PBCH_
#include "lte/config.h"
#include "lte/common/base.h"
#include "lte/mimo/precoding.h"
#include "lte/mimo/layermap.h"
@ -45,7 +46,7 @@
typedef _Complex float cf_t;
typedef struct {
typedef struct LIBLTE_API {
int nof_ports;
int nof_prb;
int sfn;
@ -54,7 +55,7 @@ typedef struct {
}pbch_mib_t;
/* PBCH object */
typedef struct {
typedef struct LIBLTE_API {
int cell_id;
lte_cp_t cp;
int nof_prb;
@ -84,15 +85,15 @@ typedef struct {
}pbch_t;
int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp);
void pbch_free(pbch_t *q);
int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float ebno, pbch_mib_t *mib);
void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL], int nof_ports);
void pbch_decode_reset(pbch_t *q);
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 void pbch_decode_reset(pbch_t *q);
void pbch_mib_fprint(FILE *stream, pbch_mib_t *mib);
bool pbch_exists(int nframe, int nslot);
int pbch_put(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp, int cell_id);
int pbch_get(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp, int cell_id);
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
#endif // PBCH_

@ -25,7 +25,6 @@
*
*/
#ifndef PCFICH_
#define PCFICH_
@ -44,7 +43,7 @@
typedef _Complex float cf_t;
/* PCFICH object */
typedef struct {
typedef struct LIBLTE_API {
int cell_id;
lte_cp_t cp;
int nof_symbols;
@ -68,15 +67,18 @@ typedef struct {
demod_hard_t demod;
sequence_t seq_pcfich[NSUBFRAMES_X_FRAME];
}pcfich_t;
} pcfich_t;
int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_tx_ports, lte_cp_t cp);
void pcfich_free(pcfich_t *q);
int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int nsubframe, int *cfi, int *distance);
int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int nsubframe);
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],
int nsubframe, int *cfi, int *distance);
LIBLTE_API int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL],
int nsubframe);
bool pcfich_exists(int nframe, int nslot);
int pcfich_put(regs_t *h, cf_t *pcfich, cf_t *slot_data);
int pcfich_get(regs_t *h, cf_t *pcfich, cf_t *slot_data);
LIBLTE_API bool pcfich_exists(int nframe, int nslot);
LIBLTE_API int pcfich_put(regs_t *h, cf_t *pcfich, cf_t *slot_data);
LIBLTE_API int pcfich_get(regs_t *h, cf_t *pcfich, cf_t *slot_data);
#endif

@ -25,7 +25,6 @@
*
*/
#ifndef PDCCH_
#define PDCCH_
@ -46,21 +45,21 @@ typedef _Complex float cf_t;
#define PDCCH_NOF_SEARCH_MODES 3
typedef enum {
SEARCH_NONE=3, SEARCH_SI=0, SEARCH_RA=1, SEARCH_UE=2
}pdcch_search_mode_t;
typedef enum LIBLTE_API {
SEARCH_NONE = 3, SEARCH_SI = 0, SEARCH_RA = 1, SEARCH_UE = 2
} pdcch_search_mode_t;
/*
* A search mode is indicated by higher layers to look for SI/C/RA-RNTI
* DCI messages as defined in Section 7.1 of 36.213
*/
typedef struct {
typedef struct LIBLTE_API {
int nof_candidates;
dci_candidate_t *candidates[NSUBFRAMES_X_FRAME];
}pdcch_search_t;
} pdcch_search_t;
/* PDCCH object */
typedef struct {
typedef struct LIBLTE_API {
int cell_id;
lte_cp_t cp;
int nof_prb;
@ -89,14 +88,15 @@ typedef struct {
sequence_t seq_pdcch[NSUBFRAMES_X_FRAME];
viterbi_t decoder;
crc_t crc;
}pdcch_t;
} pdcch_t;
int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports, int cell_id, lte_cp_t cp);
void pdcch_free(pdcch_t *q);
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);
/* Encoding functions */
int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS_CTRL], int nsubframe);
LIBLTE_API int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS_CTRL],
int nsubframe);
/* Decoding functions */
@ -105,22 +105,21 @@ int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS_CTRL], int
* b) call pdcch_extract_llr() and then call pdcch_decode_si/ue/ra
*/
int pdcch_decode(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
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);
int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], float *llr,
int nsubframe, float ebno);
void pdcch_init_search_si(pdcch_t *q);
void pdcch_set_search_si(pdcch_t *q);
int pdcch_decode_si(pdcch_t *q, float *llr, dci_t *dci);
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);
void pdcch_init_search_ue(pdcch_t *q, unsigned short c_rnti);
void pdcch_set_search_ue(pdcch_t *q);
int pdcch_decode_ue(pdcch_t *q, float *llr, dci_t *dci, int nsubframe);
LIBLTE_API void pdcch_init_search_si(pdcch_t *q);
LIBLTE_API void pdcch_set_search_si(pdcch_t *q);
LIBLTE_API int pdcch_decode_si(pdcch_t *q, float *llr, dci_t *dci);
void pdcch_init_search_ra(pdcch_t *q, unsigned short ra_rnti);
void pdcch_set_search_ra(pdcch_t *q);
int pdcch_decode_ra(pdcch_t *q, float *llr, dci_t *dci);
LIBLTE_API void pdcch_init_search_ue(pdcch_t *q, unsigned short c_rnti);
LIBLTE_API void pdcch_set_search_ue(pdcch_t *q);
LIBLTE_API int pdcch_decode_ue(pdcch_t *q, float *llr, dci_t *dci, int nsubframe);
LIBLTE_API void pdcch_init_search_ra(pdcch_t *q, unsigned short ra_rnti);
LIBLTE_API void pdcch_set_search_ra(pdcch_t *q);
LIBLTE_API int pdcch_decode_ra(pdcch_t *q, float *llr, dci_t *dci);
#endif

@ -29,6 +29,7 @@
#ifndef PDSCH_
#define PDSCH_
#include "lte/config.h"
#include "lte/common/base.h"
#include "lte/mimo/precoding.h"
#include "lte/mimo/layermap.h"
@ -47,7 +48,7 @@
typedef _Complex float cf_t;
/* PDSCH object */
typedef struct {
typedef struct LIBLTE_API {
int cell_id;
lte_cp_t cp;
int nof_prb;
@ -77,13 +78,13 @@ typedef struct {
crc_t crc_cb;
}pdsch_t;
int pdsch_init(pdsch_t *q, unsigned short user_rnti, int nof_prb,
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);
void pdsch_free(pdsch_t *q);
LIBLTE_API void pdsch_free(pdsch_t *q);
int pdsch_encode(pdsch_t *q, char *data, cf_t *sf_symbols[MAX_PORTS],
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 pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS],
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);

@ -29,6 +29,7 @@
#ifndef PHICH_
#define PHICH_
#include "lte/config.h"
#include "lte/common/base.h"
#include "lte/mimo/precoding.h"
#include "lte/mimo/layermap.h"
@ -53,7 +54,7 @@ typedef _Complex float cf_t;
#define PHICH_EXT_NSF 2
/* phich object */
typedef struct {
typedef struct LIBLTE_API {
lte_cp_t cp;
int nof_prb;
int nof_tx_ports;
@ -79,18 +80,18 @@ typedef struct {
}phich_t;
int phich_init(phich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_tx_ports, lte_cp_t cp);
void phich_free(phich_t *q);
int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
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],
int ngroup, int nseq, int nsubframe, char *ack, int *distance);
int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
LIBLTE_API int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
cf_t *slot_symbols[MAX_PORTS_CTRL]);
void phich_reset(phich_t *q, cf_t *slot_symbols[MAX_PORTS_CTRL]);
int phich_ngroups(phich_t *q);
bool phich_exists(int nframe, int nslot);
int phich_put(regs_t *h, cf_t *phich, cf_t *slot_data);
int phich_get(regs_t *h, cf_t *phich, cf_t *slot_data);
LIBLTE_API void phich_reset(phich_t *q, cf_t *slot_symbols[MAX_PORTS_CTRL]);
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);
LIBLTE_API int phich_get(regs_t *h, cf_t *phich, cf_t *slot_data);
#endif
#endif // PHICH_

@ -35,44 +35,48 @@
* allocation.
*/
typedef enum {
typedef enum LIBLTE_API {
MOD_NULL = 0, BPSK = 1, QPSK = 2, QAM16 = 3, QAM64 = 4
} ra_mod_t;
typedef struct {
typedef struct LIBLTE_API {
ra_mod_t mod; // By default, mod = MOD_NULL and the mcs_idx value is taken by the packing functions
// otherwise mod + tbs values are used to generate the mcs_idx automatically.
uint8_t tbs_idx;
uint8_t mcs_idx;
int tbs; // If tbs<=0, the tbs_idx value is taken by the packing functions to generate the DCI
int tbs;// If tbs<=0, the tbs_idx value is taken by the packing functions to generate the DCI
// message. Otherwise the tbs_idx corresponding to the lower nearest TBS is taken.
}ra_mcs_t;
} ra_mcs_t;
typedef enum {
typedef enum LIBLTE_API {
alloc_type0 = 0, alloc_type1 = 1, alloc_type2 = 2
}ra_type_t;
} ra_type_t;
typedef struct {
typedef struct LIBLTE_API {
uint32_t rbg_bitmask;
}ra_type0_t;
} ra_type0_t;
typedef struct {
typedef struct LIBLTE_API {
uint32_t vrb_bitmask;
uint8_t rbg_subset;
bool shift;
}ra_type1_t;
uint8_t rbg_subset;bool shift;
} ra_type1_t;
typedef struct {
typedef struct LIBLTE_API {
uint32_t riv; // if L_crb==0, DCI message packer will take this value directly
uint16_t L_crb;
uint16_t RB_start;
enum {nprb1a_2 = 0, nprb1a_3 = 1} n_prb1a;
enum {t2_ng1 = 0, t2_ng2 = 1} n_gap;
enum {t2_loc = 0, t2_dist = 1} mode;
}ra_type2_t;
enum {
nprb1a_2 = 0, nprb1a_3 = 1
} n_prb1a;
enum {
t2_ng1 = 0, t2_ng2 = 1
} n_gap;
enum {
t2_loc = 0, t2_dist = 1
} mode;
} ra_type2_t;
typedef struct {
typedef struct LIBLTE_API {
unsigned short rnti;
ra_type_t alloc_type;
union {
@ -82,11 +86,10 @@ typedef struct {
};
ra_mcs_t mcs;
uint8_t harq_process;
uint8_t rv_idx;
bool ndi;
uint8_t rv_idx;bool ndi;
} ra_pdsch_t;
typedef struct {
typedef struct LIBLTE_API {
/* 36.213 Table 8.4-2: hop_half is 0 for < 10 Mhz and 10 for > 10 Mh.
* hop_quart is 00 for > 10 Mhz and hop_quart_neg is 01 for > 10 Mhz.
*/
@ -102,60 +105,60 @@ typedef struct {
ra_mcs_t mcs;
uint8_t rv_idx; // If set to non-zero, a retransmission is requested with the same modulation
// than before (Format0 message, see also 8.6.1 in 36.2313).
bool ndi;
bool cqi_request;
bool ndi;bool cqi_request;
} ra_pusch_t;
typedef struct {
typedef struct LIBLTE_API {
uint8_t prb_idx[110];
int nof_prb;
}ra_prb_slot_t;
} ra_prb_slot_t;
typedef struct {
typedef struct LIBLTE_API {
ra_prb_slot_t slot[2];
int lstart;
int re_sf[NSUBFRAMES_X_FRAME];
}ra_prb_t;
void ra_prb_fprint(FILE *f, ra_prb_slot_t *prb);
} ra_prb_t;
int ra_prb_get_dl(ra_prb_t *prb, ra_pdsch_t *ra, int nof_prb);
int ra_prb_get_ul(ra_prb_slot_t *prb, ra_pusch_t *ra, int nof_prb);
void ra_prb_get_re(ra_prb_t *prb_dist, int nof_prb, int nof_ports, int nof_ctrl_symbols, lte_cp_t cp);
LIBLTE_API void ra_prb_fprint(FILE *f, ra_prb_slot_t *prb);
int ra_nprb_dl(ra_pdsch_t *ra, int nof_prb);
int ra_nprb_ul(ra_pusch_t *ra, int nof_prb);
int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb, int nof_ports,
LIBLTE_API int ra_prb_get_dl(ra_prb_t *prb, ra_pdsch_t *ra, int nof_prb);
LIBLTE_API int ra_prb_get_ul(ra_prb_slot_t *prb, ra_pusch_t *ra, int nof_prb);
LIBLTE_API void ra_prb_get_re(ra_prb_t *prb_dist, int nof_prb, int nof_ports,
int nof_ctrl_symbols, lte_cp_t cp);
uint8_t ra_mcs_to_table_idx(ra_mcs_t *mcs);
int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs);
int ra_mcs_from_idx_ul(uint8_t idx, ra_mcs_t *mcs);
int ra_tbs_from_idx_format1c(uint8_t tbs_idx);
int ra_tbs_to_table_idx_format1c(int tbs);
int ra_tbs_from_idx(uint8_t tbs_idx, int n_prb);
int ra_tbs_to_table_idx(int tbs, int n_prb);
uint8_t ra_mcs_to_table_idx(ra_mcs_t *mcs);
int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs);
int ra_mcs_from_idx_ul(uint8_t idx, ra_mcs_t *mcs);
char *ra_mod_string(ra_mod_t mod);
int ra_type0_P(int nof_prb);
uint32_t ra_type2_to_riv(uint16_t L_crb, uint16_t RB_start, int nof_prb);
void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start, int nof_prb, int nof_vrb);
int ra_type2_n_vrb_dl(int nof_prb, bool ngap_is_1);
int ra_type2_n_rb_step(int nof_prb);
int ra_type2_ngap(int nof_prb, bool ngap_is_1);
int ra_type1_N_rb(int nof_prb);
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);
void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb);
void ra_pusch_fprint(FILE *f, ra_pusch_t *ra, int nof_prb);
LIBLTE_API int ra_nprb_dl(ra_pdsch_t *ra, int nof_prb);
LIBLTE_API int ra_nprb_ul(ra_pusch_t *ra, int nof_prb);
LIBLTE_API int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb,
int nof_ports, int nof_ctrl_symbols, lte_cp_t cp);
LIBLTE_API uint8_t ra_mcs_to_table_idx(ra_mcs_t *mcs);
LIBLTE_API int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs);
LIBLTE_API int ra_mcs_from_idx_ul(uint8_t idx, ra_mcs_t *mcs);
LIBLTE_API int ra_tbs_from_idx_format1c(uint8_t tbs_idx);
LIBLTE_API int ra_tbs_to_table_idx_format1c(int tbs);
LIBLTE_API int ra_tbs_from_idx(uint8_t tbs_idx, int n_prb);
LIBLTE_API int ra_tbs_to_table_idx(int tbs, int n_prb);
LIBLTE_API uint8_t ra_mcs_to_table_idx(ra_mcs_t *mcs);
LIBLTE_API int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs);
LIBLTE_API int ra_mcs_from_idx_ul(uint8_t idx, ra_mcs_t *mcs);
LIBLTE_API char *ra_mod_string(ra_mod_t mod);
LIBLTE_API int ra_type0_P(int nof_prb);
LIBLTE_API uint32_t ra_type2_to_riv(uint16_t L_crb, uint16_t RB_start, int nof_prb);
LIBLTE_API void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start,
int nof_prb, int nof_vrb);
LIBLTE_API int ra_type2_n_vrb_dl(int nof_prb, bool ngap_is_1);
LIBLTE_API int ra_type2_n_rb_step(int nof_prb);
LIBLTE_API int ra_type2_ngap(int nof_prb, bool ngap_is_1);
LIBLTE_API int ra_type1_N_rb(int nof_prb);
LIBLTE_API void ra_pdsch_set_mcs_index(ra_pdsch_t *ra, uint8_t mcs_idx);
LIBLTE_API void ra_pdsch_set_mcs(ra_pdsch_t *ra, ra_mod_t mod, uint8_t tbs_idx);
LIBLTE_API void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb);
LIBLTE_API void ra_pusch_fprint(FILE *f, ra_pusch_t *ra, int nof_prb);
#endif /* RB_ALLOC_H_ */

@ -30,6 +30,7 @@
#define _REGS_H_
#include <stdbool.h>
#include "lte/config.h"
#include "lte/common/base.h"
#define REGS_PHICH_NSYM 12
@ -43,19 +44,19 @@
typedef _Complex float cf_t;
typedef struct {
typedef struct LIBLTE_API {
int k[4];
int k0;
int l;
bool assigned;
}regs_reg_t;
typedef struct {
typedef struct LIBLTE_API {
int nof_regs;
regs_reg_t **regs;
}regs_ch_t;
typedef struct {
typedef struct LIBLTE_API {
int cell_id;
int nof_prb;
int max_ctrl_symbols;
@ -73,28 +74,28 @@ typedef struct {
regs_reg_t *regs;
}regs_t;
int regs_init(regs_t *h, int cell_id, int nof_prb, int nof_ports,
LIBLTE_API int regs_init(regs_t *h, int cell_id, int nof_prb, int nof_ports,
phich_resources_t phich_res, phich_length_t phich_len, lte_cp_t cp);
void regs_free(regs_t *h);
int regs_set_cfi(regs_t *h, int nof_ctrl_symbols);
LIBLTE_API void regs_free(regs_t *h);
LIBLTE_API int regs_set_cfi(regs_t *h, int nof_ctrl_symbols);
int regs_put_reg(regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, int nof_prb);
int regs_add_reg(regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, int nof_prb);
int regs_get_reg(regs_reg_t *reg, cf_t *slot_symbols, cf_t *reg_data, int nof_prb);
int regs_reset_reg(regs_reg_t *reg, cf_t *slot_symbols, int nof_prb);
LIBLTE_API int regs_put_reg(regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, int nof_prb);
LIBLTE_API int regs_add_reg(regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, int nof_prb);
LIBLTE_API int regs_get_reg(regs_reg_t *reg, cf_t *slot_symbols, cf_t *reg_data, int nof_prb);
LIBLTE_API int regs_reset_reg(regs_reg_t *reg, cf_t *slot_symbols, int nof_prb);
int regs_pcfich_nregs(regs_t *h);
int regs_pcfich_put(regs_t *h, cf_t pcfich_symbols[REGS_PCFICH_NSYM], cf_t *slot_symbols);
int regs_pcfich_get(regs_t *h, cf_t *slot_symbols, cf_t pcfich_symbols[REGS_PCFICH_NSYM]);
LIBLTE_API int regs_pcfich_nregs(regs_t *h);
LIBLTE_API int regs_pcfich_put(regs_t *h, cf_t pcfich_symbols[REGS_PCFICH_NSYM], cf_t *slot_symbols);
LIBLTE_API int regs_pcfich_get(regs_t *h, cf_t *slot_symbols, cf_t pcfich_symbols[REGS_PCFICH_NSYM]);
int regs_phich_nregs(regs_t *h);
int regs_phich_add(regs_t *h, cf_t phich_symbols[REGS_PHICH_NSYM], int ngroup, cf_t *slot_symbols);
int regs_phich_get(regs_t *h, cf_t *slot_symbols, cf_t phich_symbols[REGS_PHICH_NSYM], int ngroup);
int regs_phich_ngroups(regs_t *h);
int regs_phich_reset(regs_t *h, cf_t *slot_symbols);
LIBLTE_API int regs_phich_nregs(regs_t *h);
LIBLTE_API int regs_phich_add(regs_t *h, cf_t phich_symbols[REGS_PHICH_NSYM], int ngroup, cf_t *slot_symbols);
LIBLTE_API int regs_phich_get(regs_t *h, cf_t *slot_symbols, cf_t phich_symbols[REGS_PHICH_NSYM], int ngroup);
LIBLTE_API int regs_phich_ngroups(regs_t *h);
LIBLTE_API int regs_phich_reset(regs_t *h, cf_t *slot_symbols);
int regs_pdcch_nregs(regs_t *h);
int regs_pdcch_put(regs_t *h, cf_t *pdcch_symbols, cf_t *slot_symbols);
int regs_pdcch_get(regs_t *h, cf_t *slot_symbols, cf_t *pdcch_symbols);
LIBLTE_API int regs_pdcch_nregs(regs_t *h);
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);
#endif
#endif // REGS_H_

@ -25,10 +25,16 @@
*
*/
#ifndef INTERP_H
#define INTERP_H_
#include "lte/config.h"
typedef _Complex float cf_t;
void interp_linear_offset(cf_t *input, cf_t *output, int M, int len, int off_st, int off_end);
void interp_linear(cf_t *input, cf_t *output, int M, int len);
void interp_linear_f(float *input, float *output, int M, int len);
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_f(float *input, float *output, int M, int len);
#endif // INTERP_H

@ -31,19 +31,21 @@
#include <stdint.h>
#include <complex.h>
#include "lte/config.h"
typedef _Complex float cf_t;
#define RESAMPLE_ARB_N 32 // Polyphase filter rows
#define RESAMPLE_ARB_M 8 // Polyphase filter columns
typedef struct {
typedef struct LIBLTE_API {
float rate; // Resample rate
float step; // Step increment through filter
float acc; // Index into filter
cf_t reg[RESAMPLE_ARB_M]; // Our window of samples
}resample_arb_t;
void resample_arb_init(resample_arb_t *q, float rate);
int resample_arb_compute(resample_arb_t *q, cf_t *input, cf_t *output, int n_in);
LIBLTE_API void resample_arb_init(resample_arb_t *q, float rate);
LIBLTE_API int resample_arb_compute(resample_arb_t *q, cf_t *input, cf_t *output, int n_in);
#endif //RESAMPLE_ARB_

@ -29,20 +29,21 @@
#ifndef SCRAMBLING_
#define SCRAMBLING_
#include "lte/config.h"
#include "lte/common/sequence.h"
#include "lte/common/base.h"
typedef _Complex float cf_t;
/* Scrambling has no state */
void scrambling_b(sequence_t *s, char *data);
void scrambling_b_offset(sequence_t *s, char *data, int offset, int len);
LIBLTE_API void scrambling_b(sequence_t *s, char *data);
LIBLTE_API void scrambling_b_offset(sequence_t *s, char *data, int offset, int len);
void scrambling_f(sequence_t *s, float *data);
void scrambling_f_offset(sequence_t *s, float *data, int offset, int len);
LIBLTE_API void scrambling_f(sequence_t *s, float *data);
LIBLTE_API void scrambling_f_offset(sequence_t *s, float *data, int offset, int len);
void scrambling_c(sequence_t *s, cf_t *data);
void scrambling_c_offset(sequence_t *s, cf_t *data, int offset, int len);
LIBLTE_API void scrambling_c(sequence_t *s, cf_t *data);
LIBLTE_API void scrambling_c_offset(sequence_t *s, cf_t *data, int offset, int len);
/* High-level API */
@ -55,11 +56,11 @@ void scrambling_c_offset(sequence_t *s, cf_t *data, int offset, int len);
#define SCRAMBLING_PMCH 4
#define SCRAMBLING_PUCCH 5
typedef struct {
typedef struct LIBLTE_API {
sequence_t seq[NSUBFRAMES_X_FRAME];
}scrambling_t;
typedef struct {
typedef struct LIBLTE_API {
scrambling_t obj;
struct scrambling_init {
int hard;
@ -79,4 +80,4 @@ typedef struct {
int out_len;
}scrambling_hl;
#endif
#endif // SCRAMBLING_

@ -26,11 +26,13 @@
*/
#ifndef _cfo_
#define _cfo_
#ifndef CFO_
#define CFO_
#include <complex.h>
#include "lte/config.h"
typedef _Complex float cf_t;
/** If the frequency is changed more than the tolerance, a new table is generated */
@ -38,7 +40,7 @@ typedef _Complex float cf_t;
#define CFO_CEXPTAB_SIZE 4096
typedef struct {
typedef struct LIBLTE_API {
float last_freq;
float tol;
int nsamples;
@ -46,10 +48,10 @@ typedef struct {
cf_t *cur_cexp;
}cfo_t;
int cfo_init(cfo_t *h, int nsamples);
void cfo_free(cfo_t *h);
LIBLTE_API int cfo_init(cfo_t *h, int nsamples);
LIBLTE_API void cfo_free(cfo_t *h);
void cfo_set_tol(cfo_t *h, float tol);
void cfo_correct(cfo_t *h, cf_t *x, float freq);
LIBLTE_API void cfo_set_tol(cfo_t *h, float tol);
LIBLTE_API void cfo_correct(cfo_t *h, cf_t *x, float freq);
#endif
#endif // CFO_

@ -32,6 +32,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "lte/config.h"
#include "lte/common/base.h"
#include "lte/utils/convolution.h"
@ -60,7 +61,7 @@ typedef _Complex float cf_t; /* this is only a shortcut */
/* Low-level API */
typedef struct {
typedef struct LIBLTE_API {
#ifdef CONVOLUTION_FFT
conv_fft_cc_t conv_fft;
@ -87,39 +88,29 @@ typedef struct {
typedef enum { PSS_TX, PSS_RX } pss_direction_t;
/* Basic functionality */
LIBLTE_API int pss_synch_init(pss_synch_t *q, int frame_size);
LIBLTE_API void pss_synch_free(pss_synch_t *q);
LIBLTE_API int pss_generate(cf_t *signal, int N_id_2);
LIBLTE_API void pss_put_slot(cf_t *pss_signal, cf_t *slot, int nof_prb, lte_cp_t cp);
int pss_synch_init(pss_synch_t *q, int frame_size);
void pss_synch_free(pss_synch_t *q);
int pss_generate(cf_t *signal, int N_id_2);
void pss_put_slot(cf_t *pss_signal, cf_t *slot, int nof_prb, lte_cp_t cp);
int pss_synch_set_N_id_2(pss_synch_t *q, int N_id_2);
int pss_synch_find_pss(pss_synch_t *q, cf_t *input, float *corr_peak_value, float *corr_mean_value);
float pss_synch_cfo_compute(pss_synch_t* q, cf_t *pss_recv);
LIBLTE_API int pss_synch_set_N_id_2(pss_synch_t *q, int N_id_2);
LIBLTE_API int pss_synch_find_pss(pss_synch_t *q, cf_t *input, float *corr_peak_value, float *corr_mean_value);
LIBLTE_API float pss_synch_cfo_compute(pss_synch_t* q, cf_t *pss_recv);
/* Automatic frame management functions (for periodic calling) */
int pss_synch_periodic(pss_synch_t *q, cf_t *input, cf_t *output, int nsamples);
void pss_synch_set_timeout(pss_synch_t *q, int nof_frames);
void pss_synch_set_threshold(pss_synch_t *q, float threshold);
void pss_synch_set_cfo_mode(pss_synch_t *q, bool cfo_auto);
float pss_synch_get_cfo(pss_synch_t *q);
int pss_synch_get_frame_start_idx(pss_synch_t *q);
LIBLTE_API int pss_synch_periodic(pss_synch_t *q, cf_t *input, cf_t *output, int nsamples);
LIBLTE_API void pss_synch_set_timeout(pss_synch_t *q, int nof_frames);
LIBLTE_API void pss_synch_set_threshold(pss_synch_t *q, float threshold);
LIBLTE_API void pss_synch_set_cfo_mode(pss_synch_t *q, bool cfo_auto);
LIBLTE_API float pss_synch_get_cfo(pss_synch_t *q);
LIBLTE_API int pss_synch_get_frame_start_idx(pss_synch_t *q);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
pss_synch_t obj;
struct pss_synch_init {
int frame_size; // if 0, 2048
@ -139,9 +130,9 @@ typedef struct {
#define DEFAULT_FRAME_SIZE 2048
int pss_synch_initialize(pss_synch_hl* h);
int pss_synch_work(pss_synch_hl* hl);
int pss_synch_stop(pss_synch_hl* hl);
LIBLTE_API int pss_synch_initialize(pss_synch_hl* h);
LIBLTE_API int pss_synch_work(pss_synch_hl* hl);
LIBLTE_API int pss_synch_stop(pss_synch_hl* hl);
#endif
#endif // PSS_

@ -29,7 +29,9 @@
#ifndef SFO_
#define SFO_
float sfo_estimate(int *t0, int len, float period);
float sfo_estimate_period(int *t0, int *t, int len, float period);
#include "lte/config.h"
#endif
LIBLTE_API float sfo_estimate(int *t0, int len, float period);
LIBLTE_API float sfo_estimate_period(int *t0, int *t, int len, float period);
#endif // SFO_

@ -32,6 +32,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "lte/config.h"
#include "lte/common/base.h"
#include "lte/utils/dft.h"
@ -48,7 +49,7 @@ typedef _Complex float cf_t; /* this is only a shortcut */
#define N_SSS 31
#define SSS_LEN 2*N_SSS
struct sss_tables {
struct sss_tables{
int z1[N_SSS][N_SSS];
int c[2][N_SSS];
int s[N_SSS][N_SSS];
@ -58,7 +59,7 @@ struct sss_tables {
/* Allocate 32 complex to make it multiple of 32-byte AVX instructions alignment requirement.
* Should use vect_malloc() to make it platform agnostic.
*/
struct fc_tables {
struct fc_tables{
cf_t z1[N_SSS+1][N_SSS+1];
cf_t c[2][N_SSS+1];
cf_t s[N_SSS+1][N_SSS+1];
@ -66,7 +67,7 @@ struct fc_tables {
/* Low-level API */
typedef struct {
typedef struct LIBLTE_API {
dft_plan_t dftp_input;
@ -81,27 +82,27 @@ typedef struct {
/* Basic functionality */
int sss_synch_init(sss_synch_t *q);
void sss_synch_free(sss_synch_t *q);
void sss_generate(float *signal0, float *signal5, int cell_id);
void sss_put_slot(float *sss, cf_t *symbol, int nof_prb, lte_cp_t cp);
LIBLTE_API int sss_synch_init(sss_synch_t *q);
LIBLTE_API void sss_synch_free(sss_synch_t *q);
LIBLTE_API void sss_generate(float *signal0, float *signal5, int cell_id);
LIBLTE_API void sss_put_slot(float *sss, cf_t *symbol, int nof_prb, lte_cp_t cp);
int sss_synch_set_N_id_2(sss_synch_t *q, int N_id_2);
LIBLTE_API int sss_synch_set_N_id_2(sss_synch_t *q, int N_id_2);
void sss_synch_m0m1(sss_synch_t *q, cf_t *input, int *m0, float *m0_value,
LIBLTE_API void sss_synch_m0m1(sss_synch_t *q, cf_t *input, int *m0, float *m0_value,
int *m1, float *m1_value);
int sss_synch_subframe(int m0, int m1);
int sss_synch_N_id_1(sss_synch_t *q, int m0, int m1);
LIBLTE_API int sss_synch_subframe(int m0, int m1);
LIBLTE_API int sss_synch_N_id_1(sss_synch_t *q, int m0, int m1);
int sss_synch_frame(sss_synch_t *q, cf_t *input, int *subframe_idx, int *N_id_1);
void sss_synch_set_threshold(sss_synch_t *q, float threshold);
void sss_synch_set_symbol_sz(sss_synch_t *q, int symbol_sz);
void sss_synch_set_subframe_sz(sss_synch_t *q, int subframe_sz);
LIBLTE_API int sss_synch_frame(sss_synch_t *q, cf_t *input, int *subframe_idx, int *N_id_1);
LIBLTE_API void sss_synch_set_threshold(sss_synch_t *q, float threshold);
LIBLTE_API void sss_synch_set_symbol_sz(sss_synch_t *q, int symbol_sz);
LIBLTE_API void sss_synch_set_subframe_sz(sss_synch_t *q, int subframe_sz);
/* High-level API */
typedef struct {
typedef struct LIBLTE_API {
sss_synch_t obj;
struct sss_synch_init {
int N_id_2;
@ -121,9 +122,9 @@ typedef struct {
#define DEFAULT_FRAME_SIZE 2048
int sss_synch_initialize(sss_synch_hl* h);
int sss_synch_work(sss_synch_hl* hl);
int sss_synch_stop(sss_synch_hl* hl);
LIBLTE_API int sss_synch_initialize(sss_synch_hl* h);
LIBLTE_API int sss_synch_work(sss_synch_hl* hl);
LIBLTE_API int sss_synch_stop(sss_synch_hl* hl);
#endif
#endif // SSS_

@ -31,6 +31,7 @@
#include <stdbool.h>
#include "lte/config.h"
#include "pss.h"
#include "sss.h"
#include "sfo.h"
@ -48,7 +49,7 @@
enum sync_pss_det { ABSOLUTE, PEAK_MEAN};
typedef struct {
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
enum sync_pss_det pss_mode;
@ -65,41 +66,41 @@ typedef struct {
}sync_t;
int sync_init(sync_t *q, int frame_size);
void sync_free(sync_t *q);
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 */
int sync_run(sync_t *q, cf_t *input);
LIBLTE_API int sync_run(sync_t *q, cf_t *input);
/* Sets the threshold for peak comparison */
void sync_set_threshold(sync_t *q, float threshold);
LIBLTE_API void sync_set_threshold(sync_t *q, float threshold);
/* Set peak comparison to absolute value */
void sync_pss_det_absolute(sync_t *q);
LIBLTE_API void sync_pss_det_absolute(sync_t *q);
/* Set peak comparison to relative to the mean */
void sync_pss_det_peak_to_avg(sync_t *q);
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) */
void sync_force_N_id_2(sync_t *q, int force_N_id_2);
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) */
void sync_force_cp(sync_t *q, lte_cp_t cp);
LIBLTE_API void sync_force_cp(sync_t *q, lte_cp_t cp);
/* Enables/Disables SSS detection (useful for tracking mode) */
void sync_sss_en(sync_t *q, bool enabled);
LIBLTE_API void sync_sss_en(sync_t *q, bool enabled);
/* Gets the slot id (0 or 10) */
int sync_get_slot_id(sync_t *q);
LIBLTE_API int sync_get_slot_id(sync_t *q);
/* Gets the last peak-to-average ratio */
float sync_get_peak_to_avg(sync_t *q);
LIBLTE_API float sync_get_peak_to_avg(sync_t *q);
/* Gets the N_id_2 from the last call to synch_run() */
int sync_get_N_id_2(sync_t *q);
LIBLTE_API int sync_get_N_id_2(sync_t *q);
/* Gets the N_id_1 from the last call to synch_run() */
int sync_get_N_id_1(sync_t *q);
LIBLTE_API int sync_get_N_id_1(sync_t *q);
/* Gets the Physical CellId from the last call to synch_run() */
int sync_get_cell_id(sync_t *q);
LIBLTE_API int sync_get_cell_id(sync_t *q);
/* Gets the CFO estimation from the last call to synch_run() */
float sync_get_cfo(sync_t *q);
LIBLTE_API float sync_get_cfo(sync_t *q);
/* Gets the CP length estimation from the last call to synch_run() */
lte_cp_t sync_get_cp(sync_t *q);
LIBLTE_API lte_cp_t sync_get_cp(sync_t *q);
#endif
#endif // SYNC_

@ -32,11 +32,13 @@
#include <stdint.h>
#include <stdio.h>
uint32_t bit_unpack(char **bits, int nof_bits);
void bit_pack(uint32_t value, char **bits, int nof_bits);
void bit_fprint(FILE *stream, char *bits, int nof_bits);
unsigned int bit_diff(char *x, char *y, int nbits);
int bit_count(unsigned int n);
#include "lte/config.h"
#endif
LIBLTE_API uint32_t bit_unpack(char **bits, int nof_bits);
LIBLTE_API void bit_pack(uint32_t value, char **bits, int nof_bits);
LIBLTE_API void bit_fprint(FILE *stream, char *bits, int nof_bits);
LIBLTE_API unsigned int bit_diff(char *x, char *y, int nbits);
LIBLTE_API int bit_count(unsigned int n);
#endif // BIT_

@ -26,22 +26,23 @@
*/
#ifndef _cexptab_
#define _cexptab_
#ifndef CEXPTAB_
#define CEXPTAB_
#include <complex.h>
#include "lte/config.h"
typedef _Complex float cf_t;
typedef struct {
typedef struct LIBLTE_API {
int size;
cf_t *tab;
}cexptab_t;
int cexptab_init(cexptab_t *nco, int size);
void cexptab_free(cexptab_t *nco);
LIBLTE_API int cexptab_init(cexptab_t *nco, int size);
LIBLTE_API void cexptab_free(cexptab_t *nco);
void cexptab_gen(cexptab_t *nco, cf_t *x, float freq, int len);
void cexptab_gen_direct(cf_t *x, float freq, int len);
LIBLTE_API void cexptab_gen(cexptab_t *nco, cf_t *x, float freq, int len);
LIBLTE_API void cexptab_gen_direct(cf_t *x, float freq, int len);
#endif
#endif // CEXPTAB_

@ -29,9 +29,10 @@
#ifndef CONVOLUTION_H_
#define CONVOLUTION_H_
#include "lte/config.h"
#include "lte/utils/dft.h"
typedef struct {
typedef struct LIBLTE_API {
_Complex float *input_fft;
_Complex float *filter_fft;
_Complex float *output_fft;
@ -44,10 +45,10 @@ typedef struct {
dft_plan_t output_plan;
}conv_fft_cc_t;
int conv_fft_cc_init(conv_fft_cc_t *state, int input_len, int filter_len);
void conv_fft_cc_free(conv_fft_cc_t *state);
int conv_fft_cc_run(conv_fft_cc_t *state, _Complex float *input, _Complex float *filter, _Complex float *output);
LIBLTE_API int conv_fft_cc_init(conv_fft_cc_t *state, int input_len, int filter_len);
LIBLTE_API void conv_fft_cc_free(conv_fft_cc_t *state);
LIBLTE_API int conv_fft_cc_run(conv_fft_cc_t *state, _Complex float *input, _Complex float *filter, _Complex float *output);
int conv_cc(_Complex float *input, _Complex float *filter, _Complex float *output, int input_len, int filter_len);
LIBLTE_API int conv_cc(_Complex float *input, _Complex float *filter, _Complex float *output, int input_len, int filter_len);
#endif
#endif // CONVOLUTION_H_

@ -29,17 +29,18 @@
#define DEBUG_H
#include <stdio.h>
#include "lte/config.h"
#define VERBOSE_DEBUG 2
#define VERBOSE_INFO 1
#define VERBOSE_NONE 0
#include <sys/time.h>
void get_time_interval(struct timeval * tdata);
LIBLTE_API void get_time_interval(struct timeval * tdata);
#ifndef DEBUG_DISABLED
extern int verbose;
LIBLTE_API extern int verbose;
#define VERBOSE_ISINFO() (verbose>=VERBOSE_INFO)
#define VERBOSE_ISDEBUG() (verbose>=VERBOSE_DEBUG)
@ -54,11 +55,11 @@ extern int verbose;
#define INFO(_fmt, ...) if (verbose >= VERBOSE_INFO) \
fprintf(stdout, "[INFO]: " _fmt, __VA_ARGS__)
#else
#else // DEBUG_DISABLED
#define DEBUG
#define INFO
#endif
#endif // DEBUG_DISABLED
#endif
#endif // DEBUG_H

@ -30,12 +30,13 @@
#define DFT_H_
#include <fftw3.h>
#include "lte/config.h"
/* dft is a frontend to the fftw3 library. It facilitates the computation of complex or real DFT,
* power spectral density, normalization, etc.
* It also supports the creation of multiple FFT plans for different FFT sizes or options, selecting
* a different one at runtime.
/* dft is a frontend to the fftw3 library. It facilitates the computation of
* complex or real DFT, power spectral density, normalization, etc.
* It also supports the creation of multiple FFT plans for different FFT sizes
* or options, selecting a different one at runtime.
*/
@ -55,7 +56,7 @@ typedef enum {
#define DFT_NORMALIZE 16
#define DFT_DC_OFFSET 32
typedef struct {
typedef struct LIBLTE_API {
int size;
int sign;
void *in;
@ -71,32 +72,32 @@ typedef float dft_r_t;
/* Create DFT plans */
int dft_plan(const int dft_points, dft_mode_t mode, dft_dir_t dir, dft_plan_t *plan);
int dft_plan_c2c(const int dft_points, dft_dir_t dir, dft_plan_t *plan);
int dft_plan_r2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan);
int dft_plan_c2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan);
void dft_plan_free(dft_plan_t *plan);
LIBLTE_API int dft_plan(dft_plan_t *plan, const int dft_points,
dft_mode_t mode, dft_dir_t dir);
LIBLTE_API int dft_plan_c2c(dft_plan_t *plan, const int dft_points, dft_dir_t dir);
LIBLTE_API int dft_plan_r2r(dft_plan_t *plan, const int dft_points, dft_dir_t dir);
LIBLTE_API int dft_plan_c2r(dft_plan_t *plan, const int dft_points, dft_dir_t dir);
LIBLTE_API void dft_plan_free(dft_plan_t *plan);
/* Create a vector of DFT plans */
int dft_plan_vector(const int *dft_points, dft_mode_t *modes, dft_dir_t *dirs,
int nof_plans, dft_plan_t *plans);
int dft_plan_multi_c2c(const int *dft_points, dft_dir_t dir, int nof_plans,
dft_plan_t *plans);
int dft_plan_multi_c2r(const int *dft_points, dft_dir_t dir, int nof_plans,
dft_plan_t *plans);
int dft_plan_multi_r2r(const int *dft_points, dft_dir_t dir, int nof_plans,
dft_plan_t *plans);
void dft_plan_free_vector(dft_plan_t *plan, int nof_plans);
LIBLTE_API int dft_plan_vector(dft_plan_t *plans, const int *dft_points,
dft_mode_t *modes, dft_dir_t *dirs, int nof_plans);
LIBLTE_API int dft_plan_multi_c2c(dft_plan_t *plans, const int *dft_points,
dft_dir_t dir, int nof_plans);
LIBLTE_API int dft_plan_multi_c2r(dft_plan_t *plans, const int *dft_points,
dft_dir_t dir, int nof_plans);
LIBLTE_API int dft_plan_multi_r2r(dft_plan_t *plans, const int *dft_points,
dft_dir_t dir, int nof_plans);
LIBLTE_API void dft_plan_free_vector(dft_plan_t *plans, int nof_plans);
/* Compute DFT */
void dft_run(dft_plan_t *plan, void *in, void *out);
void dft_run_c2c(dft_plan_t *plan, dft_c_t *in, dft_c_t *out);
void dft_run_r2r(dft_plan_t *plan, dft_r_t *in, dft_r_t *out);
void dft_run_c2r(dft_plan_t *plan, dft_c_t *in, dft_r_t *out);
LIBLTE_API void dft_run(dft_plan_t *plan, void *in, void *out);
LIBLTE_API void dft_run_c2c(dft_plan_t *plan, dft_c_t *in, dft_c_t *out);
LIBLTE_API void dft_run_r2r(dft_plan_t *plan, dft_r_t *in, dft_r_t *out);
LIBLTE_API void dft_run_c2r(dft_plan_t *plan, dft_c_t *in, dft_r_t *out);
#endif
#endif // DFT_H_

@ -25,24 +25,23 @@
*
*/
#include <stdio.h>
#ifndef MATRIX_
#define MATRIX_
typedef _Complex float cf_t;
#include <stdio.h>
#include "lte/config.h"
int matrix_init(void ***m, int sz_x, int sz_y, int elem_sz);
void matrix_free(void **q, int sz_x);
void matrix_bzero(void **q, int sz_x, int sz_y, int elem_sz);
void matrix_fprintf_cf(FILE *f, cf_t **q, int sz_x, int sz_y);
void matrix_fprintf_f(FILE *f, float **q, int sz_x, int sz_y);
void matrix_copy(void **dst, void **src, int sz_x, int sz_y, int elem_sz);
void matrix_dotprod_cf(cf_t **x, cf_t **y, cf_t **out, int sz_x, int sz_y);
void matrix_dotprod_float(float **x, float **y, float **out, int sz_x, int sz_y);
void matrix_dotprod_int(int **x, int **y, int **out, int sz_x, int sz_y);
typedef _Complex float cf_t;
#endif
LIBLTE_API int matrix_init(void ***m, int sz_x, int sz_y, int elem_sz);
LIBLTE_API void matrix_free(void **q, int sz_x);
LIBLTE_API void matrix_bzero(void **q, int sz_x, int sz_y, int elem_sz);
LIBLTE_API void matrix_fprintf_cf(FILE *f, cf_t **q, int sz_x, int sz_y);
LIBLTE_API void matrix_fprintf_f(FILE *f, float **q, int sz_x, int sz_y);
LIBLTE_API void matrix_copy(void **dst, void **src, int sz_x, int sz_y, int elem_sz);
LIBLTE_API void matrix_dotprod_cf(cf_t **x, cf_t **y, cf_t **out, int sz_x, int sz_y);
LIBLTE_API void matrix_dotprod_float(float **x, float **y, float **out, int sz_x, int sz_y);
LIBLTE_API void matrix_dotprod_int(int **x, int **y, int **out, int sz_x, int sz_y);
#endif // MATRIX_

@ -25,16 +25,16 @@
*
*/
#ifndef MUX_
#define MUX_
void mux(void **input, void *output, int *input_lengths, int *input_padding_pre, int nof_inputs,
#include "lte/config.h"
LIBLTE_API void mux(void **input, void *output, int *input_lengths, int *input_padding_pre, int nof_inputs,
int sample_sz);
void demux(void *input, void **output, int *output_lengths,
LIBLTE_API void demux(void *input, void **output, int *output_lengths,
int *output_padding_pre, int *output_padding_post, int nof_outputs,
int sample_sz);
#endif
#endif // MUX_

@ -29,7 +29,9 @@
#ifndef PACK_
#define PACK_
unsigned int unpack_bits(char **bits, int nof_bits);
void pack_bits(unsigned int value, char **bits, int nof_bits);
#include "lte/config.h"
#endif
LIBLTE_API unsigned int unpack_bits(char **bits, int nof_bits);
LIBLTE_API void pack_bits(unsigned int value, char **bits, int nof_bits);
#endif // PACK_

@ -30,50 +30,51 @@
#define VECTOR_
#include <stdio.h>
#include "lte/config.h"
typedef _Complex float cf_t;
/** Return the sum of all the elements */
int vec_acc_ii(int *x, int len);
float vec_acc_ff(float *x, int len);
cf_t vec_acc_cc(cf_t *x, int len);
LIBLTE_API int vec_acc_ii(int *x, int len);
LIBLTE_API float vec_acc_ff(float *x, int len);
LIBLTE_API cf_t vec_acc_cc(cf_t *x, int len);
void *vec_malloc(int size);
LIBLTE_API void *vec_malloc(int size);
/* print vectors */
void vec_fprint_c(FILE *stream, cf_t *x, int len);
void vec_fprint_f(FILE *stream, float *x, int len);
void vec_fprint_b(FILE *stream, char *x, int len);
void vec_fprint_i(FILE *stream, int *x, int len);
LIBLTE_API void vec_fprint_c(FILE *stream, cf_t *x, int len);
LIBLTE_API void vec_fprint_f(FILE *stream, float *x, int len);
LIBLTE_API void vec_fprint_b(FILE *stream, char *x, int len);
LIBLTE_API void vec_fprint_i(FILE *stream, int *x, int len);
/* sum two vectors */
void vec_sum_ch(char *z, char *x, char *y, int len);
void vec_sum_ccc(cf_t *z, cf_t *x, cf_t *y, int len);
LIBLTE_API void vec_sum_ch(char *z, char *x, char *y, int len);
LIBLTE_API void vec_sum_ccc(cf_t *z, cf_t *x, cf_t *y, int len);
/* scalar product */
void vec_sc_prod_cfc(cf_t *x, float h, cf_t *z, int len);
void vec_sc_prod_ccc(cf_t *x, cf_t h, cf_t *z, int len);
LIBLTE_API void vec_sc_prod_cfc(cf_t *x, float h, cf_t *z, int len);
LIBLTE_API void vec_sc_prod_ccc(cf_t *x, cf_t h, cf_t *z, int len);
/* vector product (element-wise) */
void vec_prod_ccc(cf_t *x, cf_t *y, cf_t *z, int len);
void vec_prod_ccc_unalign(cf_t *x, cf_t *y, cf_t *z, int len);
LIBLTE_API void vec_prod_ccc(cf_t *x, cf_t *y, cf_t *z, int len);
LIBLTE_API void vec_prod_ccc_unalign(cf_t *x, cf_t *y, cf_t *z, int len);
/* z=x/y vector division (element-wise) */
void vec_div_ccc(cf_t *x, cf_t *y, cf_t *z, int len);
LIBLTE_API void vec_div_ccc(cf_t *x, cf_t *y, cf_t *z, int len);
/* conjugate */
void vec_conj_cc(cf_t *x, cf_t *y, int len);
LIBLTE_API void vec_conj_cc(cf_t *x, cf_t *y, int len);
/* average vector power */
float vec_avg_power_cf(cf_t *x, int len);
LIBLTE_API float vec_avg_power_cf(cf_t *x, int len);
/* return the index of the maximum value in the vector */
int vec_max_fi(float *x, int len);
LIBLTE_API int vec_max_fi(float *x, int len);
/* quantify vector of floats and convert to unsigned char */
void vec_quant_fuc(float *in, unsigned char *out, float gain, float offset, float clip, int len);
LIBLTE_API void vec_quant_fuc(float *in, unsigned char *out, float gain, float offset, float clip, int len);
/* magnitude of each vector element */
void vec_abs_cf(cf_t *x, float *abs, int len);
LIBLTE_API void vec_abs_cf(cf_t *x, float *abs, int len);
#endif
#endif // VECTOR_

@ -51,7 +51,7 @@ FOREACH (_module ${modules})
ENDIF(IS_DIRECTORY ${_module})
ENDFOREACH()
ADD_LIBRARY(lte ${SOURCES_ALL})
ADD_LIBRARY(lte SHARED ${SOURCES_ALL})
TARGET_LINK_LIBRARIES(lte m ${FFTW3F_LIBRARIES})
INSTALL(TARGETS lte DESTINATION ${LIBRARY_DIR})
LIBLTE_SET_PIC(lte)

@ -42,7 +42,7 @@ int lte_fft_init_(lte_fft_t *q, lte_cp_t cp_type, int nof_prb, dft_dir_t dir) {
fprintf(stderr, "Error: Invalid nof_prb=%d\n", nof_prb);
return -1;
}
if (dft_plan_c2c(symbol_sz, dir, &q->fft_plan)) {
if (dft_plan_c2c(&q->fft_plan, symbol_sz, dir)) {
fprintf(stderr, "Error: Creating DFT plan\n");
return -1;
}

@ -25,7 +25,6 @@
*
*/
#include <string.h>
#include <stdio.h>
#include "lte/fec/rm_conv.h"
@ -33,12 +32,11 @@
#define NCOLS 32
#define NROWS_MAX NCOLS
unsigned char RM_PERM_CC[NCOLS] =
{ 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31, 0, 16, 8,
24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30 };
unsigned char RM_PERM_CC_INV[NCOLS] = { 16, 0, 24, 8, 20, 4, 28, 12, 18, 2, 26,
10, 22, 6, 30, 14, 17, 1, 25, 9, 21, 5, 29, 13, 19, 3, 27, 11, 23, 7,
31, 15 };
unsigned char RM_PERM_CC[NCOLS] = { 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27,
7, 23, 15, 31, 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30 };
unsigned char RM_PERM_CC_INV[NCOLS] =
{ 16, 0, 24, 8, 20, 4, 28, 12, 18, 2, 26, 10, 22, 6, 30, 14, 17, 1, 25, 9,
21, 5, 29, 13, 19, 3, 27, 11, 23, 7, 31, 15 };
int rm_conv_tx(char *input, int in_len, char *output, int out_len) {
@ -59,14 +57,14 @@ int rm_conv_tx(char *input, int in_len, char *output, int out_len) {
ndummy = 0;
}
/* Sub-block interleaver 5.1.4.2.1 */
k=0;
k = 0;
for (s = 0; s < 3; s++) {
for (j = 0; j < NCOLS; j++) {
for (i = 0; i < nrows; i++) {
if (i*NCOLS + RM_PERM_CC[j] < ndummy) {
if (i * NCOLS + RM_PERM_CC[j] < ndummy) {
tmp[k] = TX_NULL;
} else {
tmp[k] = input[(i*NCOLS + RM_PERM_CC[j]-ndummy)*3+s];
tmp[k] = input[(i * NCOLS + RM_PERM_CC[j] - ndummy) * 3 + s];
}
k++;
}
@ -88,7 +86,6 @@ int rm_conv_tx(char *input, int in_len, char *output, int out_len) {
return 0;
}
/* Undoes Convolutional Code Rate Matching.
* 3GPP TS 36.212 v10.1.0 section 5.1.4.2
*/
@ -143,8 +140,7 @@ int rm_conv_rx(float *input, int in_len, float *output, int out_len) {
d_i = (i + ndummy) / NCOLS;
d_j = (i + ndummy) % NCOLS;
for (j = 0; j < 3; j++) {
float o = tmp[K_p * j + RM_PERM_CC_INV[d_j] * nrows
+ d_i];
float o = tmp[K_p * j + RM_PERM_CC_INV[d_j] * nrows + d_i];
if (o != RX_NULL) {
output[i * 3 + j] = o;
} else {

@ -36,9 +36,8 @@
#define NCOLS 32
#define NROWS_MAX NCOLS
unsigned char RM_PERM_TC[NCOLS] =
{ 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30, 1, 17, 9,
25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31 };
unsigned char RM_PERM_TC[NCOLS] = { 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26,
6, 22, 14, 30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31 };
int rm_turbo_init(rm_turbo_t *q, int buffer_len) {
q->buffer_len = buffer_len;
@ -61,7 +60,8 @@ void rm_turbo_free(rm_turbo_t *q) {
*
* TODO: Soft buffer size limitation according to UE category
*/
int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_len, int rv_idx) {
int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output,
int out_len, int rv_idx) {
char *tmp = (char*) q->buffer;
int nrows, ndummy, K_p;
@ -88,9 +88,9 @@ int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_le
for (j = 0; j < NCOLS; j++) {
for (i = 0; i < nrows; i++) {
if (s == 0) {
kidx = k%K_p;
kidx = k % K_p;
} else {
kidx = K_p + 2 * (k%K_p);
kidx = K_p + 2 * (k % K_p);
}
if (i * NCOLS + RM_PERM_TC[j] < ndummy) {
tmp[kidx] = TX_NULL;
@ -115,8 +115,8 @@ int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_le
/* Bit selection and transmission 5.1.4.1.2 */
N_cb = 3 * K_p; // TODO: Soft buffer size limitation
k0 = nrows * (2 * (int) ceilf((float) N_cb / (float) (8 * nrows))
* rv_idx + 2);
k0 = nrows
* (2 * (int) ceilf((float) N_cb / (float) (8 * nrows)) * rv_idx + 2);
k = 0;
j = 0;
@ -133,7 +133,8 @@ int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_le
/* Undoes Turbo Code Rate Matching.
* 3GPP TS 36.212 v10.1.0 section 5.1.4.1
*/
int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_len, int rv_idx) {
int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output,
int out_len, int rv_idx) {
int nrows, ndummy, K_p, k0, N_cb, jp, kidx;
int i, j, k;
@ -162,18 +163,18 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
/* Undo bit collection. Account for dummy bits */
N_cb = 3 * K_p; // TODO: Soft buffer size limitation
k0 = nrows * (2 * (int) ceilf((float) N_cb / (float) (8 * nrows))
* rv_idx + 2);
k0 = nrows
* (2 * (int) ceilf((float) N_cb / (float) (8 * nrows)) * rv_idx + 2);
k = 0;
j = 0;
while (k < in_len) {
jp = (k0 + j) % N_cb;
if (jp < K_p || !(jp%2)) {
if (jp < K_p || !(jp % 2)) {
if (jp >= K_p) {
d_i = ((jp-K_p) / 2) / nrows;
d_j = ((jp-K_p) / 2) % nrows;
d_i = ((jp - K_p) / 2) / nrows;
d_j = ((jp - K_p) / 2) % nrows;
} else {
d_i = jp / nrows;
d_j = jp % nrows;
@ -184,7 +185,7 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
isdummy = true;
}
} else {
int jpp = (jp-K_p-1)/2;
int jpp = (jp - K_p - 1) / 2;
kidx = (RM_PERM_TC[jpp / nrows] + NCOLS * (jpp % nrows) + 1) % K_p;
if ((kidx - ndummy) < 0) {
isdummy = true;
@ -210,13 +211,14 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
d_j = (i + ndummy) % NCOLS;
for (j = 0; j < 3; j++) {
if (j != 2) {
kidx = K_p * j + (j+1)*(RM_PERM_TC[d_j] * nrows + d_i);
kidx = K_p * j + (j + 1) * (RM_PERM_TC[d_j] * nrows + d_i);
} else {
k=(i+ndummy-1)%K_p;
if (k<0) k+=K_p;
k = (i + ndummy - 1) % K_p;
if (k < 0)
k += K_p;
kidx = (k / NCOLS + nrows * RM_PERM_TC[k % NCOLS]) % K_p;
kidx = 2*kidx+K_p+1;
kidx = 2 * kidx + K_p + 1;
}
if (tmp[kidx] != RX_NULL) {
output[i * 3 + j] = tmp[kidx];
@ -228,7 +230,6 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
return 0;
}
/** High-level API */
int rm_turbo_initialize(rm_turbo_hl* h) {
@ -238,10 +239,12 @@ int rm_turbo_initialize(rm_turbo_hl* h) {
/** This function can be called in a subframe (1ms) basis */
int rm_turbo_work(rm_turbo_hl* hl) {
if (hl->init.direction) {
rm_turbo_tx(&hl->q, hl->input, hl->in_len, hl->output, hl->ctrl_in.E, hl->ctrl_in.rv_idx);
rm_turbo_tx(&hl->q, hl->input, hl->in_len, hl->output, hl->ctrl_in.E,
hl->ctrl_in.rv_idx);
hl->out_len = hl->ctrl_in.E;
} else {
rm_turbo_rx(&hl->q, hl->input, hl->in_len, hl->output, hl->ctrl_in.S, hl->ctrl_in.rv_idx);
rm_turbo_rx(&hl->q, hl->input, hl->in_len, hl->output, hl->ctrl_in.S,
hl->ctrl_in.rv_idx);
hl->out_len = hl->ctrl_in.S;
}
return 0;

@ -39,39 +39,39 @@
*
************************************************/
const int f1_list[NOF_TC_CB_SIZES] = { 3, 7, 19, 7, 7, 11, 5, 11, 7, 41, 103, 15, 9, 17,
9, 21, 101, 21, 57, 23, 13, 27, 11, 27, 85, 29, 33, 15, 17, 33, 103, 19,
19, 37, 19, 21, 21, 115, 193, 21, 133, 81, 45, 23, 243, 151, 155, 25,
51, 47, 91, 29, 29, 247, 29, 89, 91, 157, 55, 31, 17, 35, 227, 65, 19,
37, 41, 39, 185, 43, 21, 155, 79, 139, 23, 217, 25, 17, 127, 25, 239,
17, 137, 215, 29, 15, 147, 29, 59, 65, 55, 31, 17, 171, 67, 35, 19, 39,
19, 199, 21, 211, 21, 43, 149, 45, 49, 71, 13, 17, 25, 183, 55, 127, 27,
29, 29, 57, 45, 31, 59, 185, 113, 31, 17, 171, 209, 253, 367, 265, 181,
39, 27, 127, 143, 43, 29, 45, 157, 47, 13, 111, 443, 51, 51, 451, 257,
57, 313, 271, 179, 331, 363, 375, 127, 31, 33, 43, 33, 477, 35, 233,
357, 337, 37, 71, 71, 37, 39, 127, 39, 39, 31, 113, 41, 251, 43, 21, 43,
45, 45, 161, 89, 323, 47, 23, 47, 263 };
const int f2_list[NOF_TC_CB_SIZES] = { 10, 12, 42, 16, 18, 20, 22, 24, 26, 84, 90, 32,
34, 108, 38, 120, 84, 44, 46, 48, 50, 52, 36, 56, 58, 60, 62, 32, 198,
68, 210, 36, 74, 76, 78, 120, 82, 84, 86, 44, 90, 46, 94, 48, 98, 40,
102, 52, 106, 72, 110, 168, 114, 58, 118, 180, 122, 62, 84, 64, 66, 68,
420, 96, 74, 76, 234, 80, 82, 252, 86, 44, 120, 92, 94, 48, 98, 80, 102,
52, 106, 48, 110, 112, 114, 58, 118, 60, 122, 124, 84, 64, 66, 204, 140,
72, 74, 76, 78, 240, 82, 252, 86, 88, 60, 92, 846, 48, 28, 80, 102, 104,
954, 96, 110, 112, 114, 116, 354, 120, 610, 124, 420, 64, 66, 136, 420,
216, 444, 456, 468, 80, 164, 504, 172, 88, 300, 92, 188, 96, 28, 240,
204, 104, 212, 192, 220, 336, 228, 232, 236, 120, 244, 248, 168, 64,
130, 264, 134, 408, 138, 280, 142, 480, 146, 444, 120, 152, 462, 234,
158, 80, 96, 902, 166, 336, 170, 86, 174, 176, 178, 120, 182, 184, 186,
94, 190, 480 };
const int f1_list[NOF_TC_CB_SIZES] = { 3, 7, 19, 7, 7, 11, 5, 11, 7, 41, 103,
15, 9, 17, 9, 21, 101, 21, 57, 23, 13, 27, 11, 27, 85, 29, 33, 15, 17, 33,
103, 19, 19, 37, 19, 21, 21, 115, 193, 21, 133, 81, 45, 23, 243, 151, 155,
25, 51, 47, 91, 29, 29, 247, 29, 89, 91, 157, 55, 31, 17, 35, 227, 65, 19,
37, 41, 39, 185, 43, 21, 155, 79, 139, 23, 217, 25, 17, 127, 25, 239, 17,
137, 215, 29, 15, 147, 29, 59, 65, 55, 31, 17, 171, 67, 35, 19, 39, 19, 199,
21, 211, 21, 43, 149, 45, 49, 71, 13, 17, 25, 183, 55, 127, 27, 29, 29, 57,
45, 31, 59, 185, 113, 31, 17, 171, 209, 253, 367, 265, 181, 39, 27, 127,
143, 43, 29, 45, 157, 47, 13, 111, 443, 51, 51, 451, 257, 57, 313, 271, 179,
331, 363, 375, 127, 31, 33, 43, 33, 477, 35, 233, 357, 337, 37, 71, 71, 37,
39, 127, 39, 39, 31, 113, 41, 251, 43, 21, 43, 45, 45, 161, 89, 323, 47, 23,
47, 263 };
const int f2_list[NOF_TC_CB_SIZES] = { 10, 12, 42, 16, 18, 20, 22, 24, 26, 84,
90, 32, 34, 108, 38, 120, 84, 44, 46, 48, 50, 52, 36, 56, 58, 60, 62, 32,
198, 68, 210, 36, 74, 76, 78, 120, 82, 84, 86, 44, 90, 46, 94, 48, 98, 40,
102, 52, 106, 72, 110, 168, 114, 58, 118, 180, 122, 62, 84, 64, 66, 68, 420,
96, 74, 76, 234, 80, 82, 252, 86, 44, 120, 92, 94, 48, 98, 80, 102, 52, 106,
48, 110, 112, 114, 58, 118, 60, 122, 124, 84, 64, 66, 204, 140, 72, 74, 76,
78, 240, 82, 252, 86, 88, 60, 92, 846, 48, 28, 80, 102, 104, 954, 96, 110,
112, 114, 116, 354, 120, 610, 124, 420, 64, 66, 136, 420, 216, 444, 456,
468, 80, 164, 504, 172, 88, 300, 92, 188, 96, 28, 240, 204, 104, 212, 192,
220, 336, 228, 232, 236, 120, 244, 248, 168, 64, 130, 264, 134, 408, 138,
280, 142, 480, 146, 444, 120, 152, 462, 234, 158, 80, 96, 902, 166, 336,
170, 86, 174, 176, 178, 120, 182, 184, 186, 94, 190, 480 };
int tc_interl_LTE_gen(tc_interl_t *h, int long_cb) {
int cb_table_idx, f1, f2;
unsigned long long i, j;
if (long_cb > h->max_long_cb) {
fprintf(stderr, "Interleaver initiated for max_long_cb=%d\n",h->max_long_cb);
fprintf(stderr, "Interleaver initiated for max_long_cb=%d\n",
h->max_long_cb);
return -1;
}
@ -89,7 +89,7 @@ int tc_interl_LTE_gen(tc_interl_t *h, int long_cb) {
h->forward[0] = 0;
h->reverse[0] = 0;
for (i = 1; i < long_cb; i++) {
j = (f1*i + f2*i*i) % (long_cb);
j = (f1 * i + f2 * i * i) % (long_cb);
h->forward[i] = j;
h->reverse[j] = i;
}
@ -97,13 +97,3 @@ int tc_interl_LTE_gen(tc_interl_t *h, int long_cb) {
}

@ -46,13 +46,12 @@ int mcd(int x, int y);
#define MAX_COLS 256
const unsigned short table_p[52] = { 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257 };
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
211, 223, 227, 229, 233, 239, 241, 251, 257 };
const unsigned char table_v[52] = { 3, 2, 2, 3, 2, 5, 2, 3, 2, 6, 3, 5, 2, 2, 2,
2, 7, 5, 3, 2, 3, 5, 2, 5, 2, 6, 3, 3, 2, 3, 2, 2, 6, 5, 2, 5, 2, 2, 2,
19, 5, 2, 3, 2, 3, 2, 6, 3, 7, 7, 6, 3 };
2, 7, 5, 3, 2, 3, 5, 2, 5, 2, 6, 3, 3, 2, 3, 2, 2, 6, 5, 2, 5, 2, 2, 2, 19,
5, 2, 3, 2, 3, 2, 6, 3, 7, 7, 6, 3 };
int tc_interl_init(tc_interl_t *h, int max_long_cb) {
int ret = -1;
@ -68,8 +67,7 @@ int tc_interl_init(tc_interl_t *h, int max_long_cb) {
}
h->max_long_cb = max_long_cb;
ret = 0;
clean_exit:
if (ret == -1) {
clean_exit: if (ret == -1) {
tc_interl_free(h);
}
return ret;
@ -100,7 +98,8 @@ int tc_interl_UMTS_gen(tc_interl_t *h, int long_cb) {
M_long = long_cb;
if (long_cb > h->max_long_cb) {
fprintf(stderr, "Interleaver initiated for max_long_cb=%d\n",h->max_long_cb);
fprintf(stderr, "Interleaver initiated for max_long_cb=%d\n",
h->max_long_cb);
return -1;
}

@ -47,14 +47,15 @@ void tcod_free(tcod_t *h) {
int tcod_encode(tcod_t *h, char *input, char *output, int long_cb) {
char reg1_0,reg1_1,reg1_2, reg2_0,reg2_1,reg2_2;
int i,k=0,j;
char reg1_0, reg1_1, reg1_2, reg2_0, reg2_1, reg2_2;
int i, k = 0, j;
char bit;
char in,out;
char in, out;
int *per;
if (long_cb > h->max_long_cb) {
fprintf(stderr, "Turbo coder initiated for max_long_cb=%d\n", h->max_long_cb);
fprintf(stderr, "Turbo coder initiated for max_long_cb=%d\n",
h->max_long_cb);
return -1;
}
@ -63,81 +64,81 @@ int tcod_encode(tcod_t *h, char *input, char *output, int long_cb) {
return -1;
}
per=h->interl.forward;
per = h->interl.forward;
reg1_0=0;
reg1_1=0;
reg1_2=0;
reg1_0 = 0;
reg1_1 = 0;
reg1_2 = 0;
reg2_0=0;
reg2_1=0;
reg2_2=0;
reg2_0 = 0;
reg2_1 = 0;
reg2_2 = 0;
k=0;
for (i=0;i<long_cb;i++) {
bit=input[i];
k = 0;
for (i = 0; i < long_cb; i++) {
bit = input[i];
output[k]=bit;
output[k] = bit;
k++;
in=bit^(reg1_2^reg1_1);
out=reg1_2^(reg1_0^in);
in = bit ^ (reg1_2 ^ reg1_1);
out = reg1_2 ^ (reg1_0 ^ in);
reg1_2=reg1_1;
reg1_1=reg1_0;
reg1_0=in;
reg1_2 = reg1_1;
reg1_1 = reg1_0;
reg1_0 = in;
output[k]=out;
output[k] = out;
k++;
bit=input[per[i]];
bit = input[per[i]];
in=bit^(reg2_2^reg2_1);
out=reg2_2^(reg2_0^in);
in = bit ^ (reg2_2 ^ reg2_1);
out = reg2_2 ^ (reg2_0 ^ in);
reg2_2=reg2_1;
reg2_1=reg2_0;
reg2_0=in;
reg2_2 = reg2_1;
reg2_1 = reg2_0;
reg2_0 = in;
output[k]=out;
output[k] = out;
k++;
}
k=3*long_cb;
k = 3 * long_cb;
/* TAILING CODER #1 */
for (j=0;j<NOF_REGS;j++) {
bit=reg1_2^reg1_1;
for (j = 0; j < NOF_REGS; j++) {
bit = reg1_2 ^ reg1_1;
output[k]=bit;
output[k] = bit;
k++;
in=bit^(reg1_2^reg1_1);
out=reg1_2^(reg1_0^in);
in = bit ^ (reg1_2 ^ reg1_1);
out = reg1_2 ^ (reg1_0 ^ in);
reg1_2=reg1_1;
reg1_1=reg1_0;
reg1_0=in;
reg1_2 = reg1_1;
reg1_1 = reg1_0;
reg1_0 = in;
output[k]=out;
output[k] = out;
k++;
}
/* TAILING CODER #2 */
for (j=0;j<NOF_REGS;j++) {
bit=reg2_2^reg2_1;
for (j = 0; j < NOF_REGS; j++) {
bit = reg2_2 ^ reg2_1;
output[k]=bit;
output[k] = bit;
k++;
in=bit^(reg2_2^reg2_1);
out=reg2_2^(reg2_0^in);
in = bit ^ (reg2_2 ^ reg2_1);
out = reg2_2 ^ (reg2_0 ^ in);
reg2_2=reg2_1;
reg2_1=reg2_0;
reg2_0=in;
reg2_2 = reg2_1;
reg2_1 = reg2_0;
reg2_0 = in;
output[k]=out;
output[k] = out;
k++;
}
return 0;

@ -25,7 +25,6 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -47,7 +46,7 @@ void map_gen_beta(map_gen_t *s, llr_t *input, llr_t *parity, int long_cb) {
llr_t *beta = s->beta;
int i;
for (i=0;i<8;i++) {
for (i = 0; i < 8; i++) {
old[i] = beta[8 * (end) + i];
}
@ -75,7 +74,7 @@ void map_gen_beta(map_gen_t *s, llr_t *input, llr_t *parity, int long_cb) {
new[6] = old[3] + xy;
new[7] = old[3];
for (i=0;i<8;i++) {
for (i = 0; i < 8; i++) {
if (m_b[i] > new[i])
new[i] = m_b[i];
beta[8 * k + i] = new[i];
@ -84,7 +83,8 @@ void map_gen_beta(map_gen_t *s, llr_t *input, llr_t *parity, int long_cb) {
}
}
void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output, int long_cb) {
void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output,
int long_cb) {
llr_t m_b[8], new[8], old[8], max1[8], max0[8];
llr_t m1, m0;
llr_t x, y, xy;
@ -95,7 +95,7 @@ void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output, int
int i;
old[0] = 0;
for (i=1;i<8;i++) {
for (i = 1; i < 8; i++) {
old[i] = -INF;
}
@ -123,7 +123,7 @@ void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output, int
new[6] = old[4] + x;
new[7] = old[7] + xy;
for (i=0;i<8;i++) {
for (i = 0; i < 8; i++) {
max0[i] = m_b[i] + beta[8 * k + i];
max1[i] = new[i] + beta[8 * k + i];
}
@ -131,14 +131,14 @@ void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output, int
m1 = max1[0];
m0 = max0[0];
for (i=1;i<8;i++) {
for (i = 1; i < 8; i++) {
if (max1[i] > m1)
m1 = max1[i];
if (max0[i] > m0)
m0 = max0[i];
}
for (i=0;i<8;i++) {
for (i = 0; i < 8; i++) {
if (m_b[i] > new[i])
new[i] = m_b[i];
old[i] = new[i];
@ -151,7 +151,7 @@ void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output, int
int map_gen_init(map_gen_t *h, int max_long_cb) {
bzero(h, sizeof(map_gen_t));
h->beta = malloc(sizeof(llr_t) * (max_long_cb + TOTALTAIL + 1)* NUMSTATES);
h->beta = malloc(sizeof(llr_t) * (max_long_cb + TOTALTAIL + 1) * NUMSTATES);
if (!h->beta) {
perror("malloc");
return -1;
@ -167,7 +167,8 @@ void map_gen_free(map_gen_t *h) {
bzero(h, sizeof(map_gen_t));
}
void map_gen_dec(map_gen_t *h, llr_t *input, llr_t *parity, llr_t *output, int long_cb) {
void map_gen_dec(map_gen_t *h, llr_t *input, llr_t *parity, llr_t *output,
int long_cb) {
int k;
h->beta[(long_cb + TAIL) * NUMSTATES] = 0;
@ -178,14 +179,6 @@ void map_gen_dec(map_gen_t *h, llr_t *input, llr_t *parity, llr_t *output, int l
map_gen_alpha(h, input, parity, output, long_cb);
}
/************************************************
*
* TURBO DECODER INTERFACE
@ -233,8 +226,7 @@ int tdec_init(tdec_t *h, int max_long_cb) {
}
ret = 0;
clean_and_exit:
if (ret == -1) {
clean_and_exit: if (ret == -1) {
tdec_free(h);
}
return ret;
@ -272,7 +264,7 @@ void tdec_iteration(tdec_t *h, llr_t *input, int long_cb) {
h->syst[i] = input[RATE * i] + h->w[i];
h->parity[i] = input[RATE * i + 1];
}
for (i=long_cb;i<long_cb+RATE;i++) {
for (i = long_cb; i < long_cb + RATE; i++) {
h->syst[i] = input[RATE * long_cb + NINPUTS * (i - long_cb)];
h->parity[i] = input[RATE * long_cb + NINPUTS * (i - long_cb) + 1];
}
@ -282,12 +274,15 @@ void tdec_iteration(tdec_t *h, llr_t *input, int long_cb) {
// Prepare systematic and parity bits for MAP DEC #1
for (i = 0; i < long_cb; i++) {
h->syst[i] = h->llr1[h->interleaver.forward[i]] - h->w[h->interleaver.forward[i]];
h->syst[i] = h->llr1[h->interleaver.forward[i]]
- h->w[h->interleaver.forward[i]];
h->parity[i] = input[RATE * i + 2];
}
for (i=long_cb;i<long_cb+RATE;i++) {
h->syst[i] = input[RATE * long_cb + NINPUTS * RATE + NINPUTS * (i - long_cb)];
h->parity[i] = input[RATE * long_cb + NINPUTS * RATE + NINPUTS * (i - long_cb) + 1];
for (i = long_cb; i < long_cb + RATE; i++) {
h->syst[i] =
input[RATE * long_cb + NINPUTS * RATE + NINPUTS * (i - long_cb)];
h->parity[i] = input[RATE * long_cb + NINPUTS * RATE
+ NINPUTS * (i - long_cb) + 1];
}
// Run MAP DEC #1
@ -303,7 +298,8 @@ void tdec_iteration(tdec_t *h, llr_t *input, int long_cb) {
int tdec_reset(tdec_t *h, int long_cb) {
memset(h->w, 0, sizeof(llr_t) * long_cb);
if (long_cb > h->max_long_cb) {
fprintf(stderr, "TDEC was initialized for max_long_cb=%d\n", h->max_long_cb);
fprintf(stderr, "TDEC was initialized for max_long_cb=%d\n",
h->max_long_cb);
return -1;
}
return tc_interl_LTE_gen(&h->interleaver, long_cb);
@ -316,7 +312,8 @@ void tdec_decision(tdec_t *h, char *output, int long_cb) {
}
}
void tdec_run_all(tdec_t *h, llr_t *input, char *output, int nof_iterations, int long_cb) {
void tdec_run_all(tdec_t *h, llr_t *input, char *output, int nof_iterations,
int long_cb) {
int iter = 0;
tdec_reset(h, long_cb);

@ -36,7 +36,7 @@
#include "lte.h"
int nof_tx_bits=-1, nof_rx_bits=-1;
int nof_tx_bits = -1, nof_rx_bits = -1;
int rv_idx = 0;
void usage(char *prog) {
@ -71,7 +71,6 @@ void parse_args(int argc, char **argv) {
}
}
int main(int argc, char **argv) {
int i;
char *bits, *rm_bits;
@ -102,22 +101,23 @@ int main(int argc, char **argv) {
exit(-1);
}
for (i=0;i<nof_tx_bits;i++) {
bits[i] = rand()%2;
for (i = 0; i < nof_tx_bits; i++) {
bits[i] = rand() % 2;
}
rm_turbo_init(&rm_turbo, 2000);
rm_turbo_tx(&rm_turbo, bits, nof_tx_bits, rm_bits, nof_rx_bits, rv_idx);
for (i=0;i<nof_rx_bits;i++) {
rm_symbols[i] = (float) rm_bits[i]?1:-1;
for (i = 0; i < nof_rx_bits; i++) {
rm_symbols[i] = (float) rm_bits[i] ? 1 : -1;
}
rm_turbo_rx(&rm_turbo, rm_symbols, nof_rx_bits, unrm_symbols, nof_tx_bits, rv_idx);
rm_turbo_rx(&rm_turbo, rm_symbols, nof_rx_bits, unrm_symbols, nof_tx_bits,
rv_idx);
nof_errors = 0;
for (i=0;i<nof_tx_bits;i++) {
for (i = 0; i < nof_tx_bits; i++) {
if (unrm_symbols[i] > 0 && ((unrm_symbols[i] > 0) != bits[i])) {
nof_errors++;
}

@ -41,7 +41,7 @@
typedef _Complex float cf_t;
int frame_length = 1000, nof_frames=100;
int frame_length = 1000, nof_frames = 100;
float ebno_db = 100.0;
unsigned int seed = 0;
int K = -1;
@ -57,7 +57,8 @@ int test_errors = 0;
void usage(char *prog) {
printf("Usage: %s [nlesv]\n", prog);
printf("\t-k Test with known data (ignores frame_length) [Default disabled]\n");
printf(
"\t-k Test with known data (ignores frame_length) [Default disabled]\n");
printf("\t-i nof_iterations [Default %d]\n", nof_iterations);
printf("\t-n nof_frames [Default %d]\n", nof_frames);
printf("\t-l frame_length [Default %d]\n", frame_length);
@ -109,7 +110,7 @@ void output_matlab(float ber[MAX_ITERATIONS][SNR_POINTS], int snr_points) {
exit(-1);
}
fprintf(f, "ber=[");
for (j=0;j<MAX_ITERATIONS;j++) {
for (j = 0; j < MAX_ITERATIONS; j++) {
for (i = 0; i < snr_points; i++) {
fprintf(f, "%g ", ber[j][i]);
}
@ -119,7 +120,8 @@ void output_matlab(float ber[MAX_ITERATIONS][SNR_POINTS], int snr_points) {
fprintf(f, "snr=linspace(%g,%g-%g/%d,%d);\n", SNR_MIN, SNR_MAX, SNR_MAX,
snr_points, snr_points);
fprintf(f, "semilogy(snr,ber,snr,0.5*erfc(sqrt(10.^(snr/10))));\n");
fprintf(f, "legend('1 iter','2 iter', '3 iter', '4 iter', 'theory-uncoded');");
fprintf(f,
"legend('1 iter','2 iter', '3 iter', '4 iter', 'theory-uncoded');");
fprintf(f, "grid on;\n");
fclose(f);
}
@ -153,7 +155,7 @@ int main(int argc, char **argv) {
frame_length = lte_cb_size(lte_find_cb_index(frame_length));
}
coded_length = 3*(frame_length)+TOTALTAIL;
coded_length = 3 * (frame_length) + TOTALTAIL;
printf(" Frame length: %d\n", frame_length);
if (ebno_db < 100.0) {
@ -229,7 +231,7 @@ int main(int argc, char **argv) {
/* coded BER */
if (test_known_data) {
for (j=0;j<coded_length;j++) {
for (j = 0; j < coded_length; j++) {
symbols[j] = known_data_encoded[j];
}
} else {
@ -251,26 +253,31 @@ int main(int argc, char **argv) {
} else {
t = nof_iterations;
}
for (j=0;j<t;j++) {
for (j = 0; j < t; j++) {
if (!j) gettimeofday(&tdata[1],NULL); // Only measure 1 iteration
if (!j)
gettimeofday(&tdata[1], NULL); // Only measure 1 iteration
tdec_iteration(&tdec, llr, frame_length);
tdec_decision(&tdec, data_rx, frame_length);
if (!j) gettimeofday(&tdata[2],NULL);
if (!j) get_time_interval(tdata);
if (!j) mean_usec = (float) mean_usec*0.9+(float) tdata[0].tv_usec*0.1;
if (!j)
gettimeofday(&tdata[2], NULL);
if (!j)
get_time_interval(tdata);
if (!j)
mean_usec = (float) mean_usec * 0.9 + (float) tdata[0].tv_usec * 0.1;
/* check errors */
errors[j] += bit_diff(data_tx, data_rx, frame_length);
if (j < MAX_ITERATIONS) {
ber[j][i] = (float) errors[j] /(frame_cnt * frame_length);
ber[j][i] = (float) errors[j] / (frame_cnt * frame_length);
}
}
frame_cnt++;
printf("Eb/No: %3.2f %10d/%d ",
SNR_MIN + i * ebno_inc,frame_cnt,nof_frames);
printf("BER: %.2e ",(float) errors[j-1] / (frame_cnt * frame_length));
printf("%3.1f Mbps (%6.2f usec)", (float) frame_length/mean_usec, mean_usec);
SNR_MIN + i * ebno_inc, frame_cnt, nof_frames);
printf("BER: %.2e ", (float) errors[j - 1] / (frame_cnt * frame_length));
printf("%3.1f Mbps (%6.2f usec)", (float) frame_length / mean_usec,
mean_usec);
printf("\r");
}
@ -278,29 +285,30 @@ int main(int argc, char **argv) {
if (snr_points == 1) {
if (test_known_data && seed == KNOWN_DATA_SEED
&& ebno_db == KNOWN_DATA_EBNO
&& frame_cnt == KNOWN_DATA_NFRAMES) {
for (j=0;j<MAX_ITERATIONS;j++) {
&& ebno_db == KNOWN_DATA_EBNO && frame_cnt == KNOWN_DATA_NFRAMES) {
for (j = 0; j < MAX_ITERATIONS; j++) {
if (errors[j] > known_data_errors[j]) {
fprintf(stderr, "Expected %d errors but got %d\n",
known_data_errors[j], errors[j]);
exit(-1);
}else {
printf("Iter %d ok\n", j+1);
} else {
printf("Iter %d ok\n", j + 1);
}
}
} else {
for (j=0;j<MAX_ITERATIONS;j++) {
for (j = 0; j < MAX_ITERATIONS; j++) {
printf("BER: %g\t%u errors\n",
(float) errors[j] / (frame_cnt * frame_length), errors[j]);
if (test_errors) {
if (errors[j] > get_expected_errors(frame_cnt, seed, j+1, frame_length, ebno_db)) {
if (errors[j]
> get_expected_errors(frame_cnt, seed, j + 1, frame_length,
ebno_db)) {
fprintf(stderr, "Expected %d errors but got %d\n",
get_expected_errors(frame_cnt, seed, j+1, frame_length, ebno_db),
errors[j]);
get_expected_errors(frame_cnt, seed, j + 1, frame_length,
ebno_db), errors[j]);
exit(-1);
} else {
printf("Iter %d ok\n", j+1);
printf("Iter %d ok\n", j + 1);
}
}
}

@ -25,8 +25,6 @@
*
*/
#include <stdio.h>
#include <assert.h>
#include <complex.h>
@ -41,42 +39,43 @@ int precoding_single(cf_t *x, cf_t *y, int nof_symbols) {
memcpy(y, x, nof_symbols * sizeof(cf_t));
return nof_symbols;
}
int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports, int nof_symbols) {
int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports,
int nof_symbols) {
int i;
if (nof_ports == 2) {
/* FIXME: Use VOLK here */
for (i=0;i<nof_symbols;i++) {
y[0][2*i] = x[0][i]/sqrtf(2);
y[1][2*i] = -conjf(x[1][i])/sqrtf(2);
y[0][2*i+1] = x[1][i]/sqrtf(2);
y[1][2*i+1] = conjf(x[0][i])/sqrtf(2);
for (i = 0; i < nof_symbols; i++) {
y[0][2 * i] = x[0][i] / sqrtf(2);
y[1][2 * i] = -conjf(x[1][i]) / sqrtf(2);
y[0][2 * i + 1] = x[1][i] / sqrtf(2);
y[1][2 * i + 1] = conjf(x[0][i]) / sqrtf(2);
}
return 2*i;
return 2 * i;
} else if (nof_ports == 4) {
//int m_ap = (nof_symbols%4)?(nof_symbols*4-2):nof_symbols*4;
int m_ap = 4 * nof_symbols;
for (i=0;i<m_ap/4;i++) {
y[0][4*i] = x[0][i]/sqrtf(2);
y[1][4*i] = 0;
y[2][4*i] = -conjf(x[1][i])/sqrtf(2);
y[3][4*i] = 0;
y[0][4*i+1] = x[1][i]/sqrtf(2);
y[1][4*i+1] = 0;
y[2][4*i+1] = conjf(x[0][i])/sqrtf(2);
y[3][4*i+1] = 0;
y[0][4*i+2] = 0;
y[1][4*i+2] = x[2][i]/sqrtf(2);
y[2][4*i+2] = 0;
y[3][4*i+2] = -conjf(x[3][i])/sqrtf(2);
y[0][4*i+3] = 0;
y[1][4*i+3] = x[3][i]/sqrtf(2);
y[2][4*i+3] = 0;
y[3][4*i+3] = conjf(x[2][i])/sqrtf(2);
}
return 4*i;
for (i = 0; i < m_ap / 4; i++) {
y[0][4 * i] = x[0][i] / sqrtf(2);
y[1][4 * i] = 0;
y[2][4 * i] = -conjf(x[1][i]) / sqrtf(2);
y[3][4 * i] = 0;
y[0][4 * i + 1] = x[1][i] / sqrtf(2);
y[1][4 * i + 1] = 0;
y[2][4 * i + 1] = conjf(x[0][i]) / sqrtf(2);
y[3][4 * i + 1] = 0;
y[0][4 * i + 2] = 0;
y[1][4 * i + 2] = x[2][i] / sqrtf(2);
y[2][4 * i + 2] = 0;
y[3][4 * i + 2] = -conjf(x[3][i]) / sqrtf(2);
y[0][4 * i + 3] = 0;
y[1][4 * i + 3] = x[3][i] / sqrtf(2);
y[2][4 * i + 3] = 0;
y[3][4 * i + 3] = conjf(x[2][i]) / sqrtf(2);
}
return 4 * i;
} else {
fprintf(stderr, "Number of ports must be 2 or 4 for transmit diversity\n");
return -1;
@ -84,24 +83,27 @@ int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports,
}
/* 36.211 v10.3.0 Section 6.3.4 */
int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int nof_ports, int nof_symbols,
lte_mimo_type_t type) {
int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers,
int nof_ports, int nof_symbols, lte_mimo_type_t type) {
if (nof_ports > MAX_PORTS) {
fprintf(stderr, "Maximum number of ports is %d (nof_ports=%d)\n", MAX_PORTS, nof_ports);
fprintf(stderr, "Maximum number of ports is %d (nof_ports=%d)\n", MAX_PORTS,
nof_ports);
return -1;
}
if (nof_layers > MAX_LAYERS) {
fprintf(stderr, "Maximum number of layers is %d (nof_layers=%d)\n", MAX_LAYERS, nof_layers);
fprintf(stderr, "Maximum number of layers is %d (nof_layers=%d)\n",
MAX_LAYERS, nof_layers);
return -1;
}
switch(type) {
switch (type) {
case SINGLE_ANTENNA:
if (nof_ports == 1 && nof_layers == 1) {
return precoding_single(x[0], y[0], nof_symbols);
} else {
fprintf(stderr, "Number of ports and layers must be 1 for transmission on single antenna ports\n");
fprintf(stderr,
"Number of ports and layers must be 1 for transmission on single antenna ports\n");
return -1;
}
break;
@ -109,7 +111,8 @@ int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int
if (nof_ports == nof_layers) {
return precoding_diversity(x, y, nof_ports, nof_symbols);
} else {
fprintf(stderr, "Error number of layers must equal number of ports in transmit diversity\n");
fprintf(stderr,
"Error number of layers must equal number of ports in transmit diversity\n");
return -1;
}
case SPATIAL_MULTIPLEX:
@ -119,7 +122,6 @@ int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int
return 0;
}
/* ZF detector */
int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols) {
vec_div_ccc(y, ce, x, nof_symbols);
@ -127,45 +129,45 @@ int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols) {
}
/* ZF detector */
int predecoding_diversity_zf(cf_t *y, cf_t *ce[MAX_PORTS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_symbols) {
int predecoding_diversity_zf(cf_t *y, cf_t *ce[MAX_PORTS], cf_t *x[MAX_LAYERS],
int nof_ports, int nof_symbols) {
int i;
cf_t h0, h1, h2, h3, r0, r1, r2, r3;
float hh, hh02, hh13;
if (nof_ports == 2) {
/* TODO: Use VOLK here */
for (i=0;i<nof_symbols/2;i++) {
h0 = ce[0][2*i];
h1 = ce[1][2*i];
hh = crealf(h0)*crealf(h0)+cimagf(h0)*cimagf(h0)+
crealf(h1)*crealf(h1)+cimagf(h1)*cimagf(h1);
r0 = y[2*i];
r1 = y[2*i+1];
x[0][i] = (conjf(h0)*r0 + h1*conjf(r1))/hh * sqrt(2);
x[1][i] = (-h1*conj(r0) + conj(h0)*r1)/hh * sqrt(2);
for (i = 0; i < nof_symbols / 2; i++) {
h0 = ce[0][2 * i];
h1 = ce[1][2 * i];
hh = crealf(h0) * crealf(h0) + cimagf(h0) * cimagf(h0)
+ crealf(h1) * crealf(h1) + cimagf(h1) * cimagf(h1);
r0 = y[2 * i];
r1 = y[2 * i + 1];
x[0][i] = (conjf(h0) * r0 + h1 * conjf(r1)) / hh * sqrt(2);
x[1][i] = (-h1 * conj(r0) + conj(h0) * r1) / hh * sqrt(2);
}
return i;
} else if (nof_ports == 4) {
int m_ap = (nof_symbols%4)?((nof_symbols-2)/4):nof_symbols/4;
for (i=0;i<m_ap;i++) {
h0 = ce[0][4*i];
h1 = ce[1][4*i+2];
h2 = ce[2][4*i];
h3 = ce[3][4*i+2];
hh02 = crealf(h0)*crealf(h0)+cimagf(h0)*cimagf(h0)
+ crealf(h2)*crealf(h2)+cimagf(h2)*cimagf(h2);
hh13 = crealf(h1)*crealf(h1)+cimagf(h1)*cimagf(h1)
+ crealf(h3)*crealf(h3)+cimagf(h3)*cimagf(h3);
r0 = y[4*i];
r1 = y[4*i+1];
r2 = y[4*i+2];
r3 = y[4*i+3];
x[0][i] = (conjf(h0)*r0 + h2*conjf(r1))/hh02 * sqrt(2);
x[1][i] = (-h2*conjf(r0) + conjf(h0)*r1)/hh02 * sqrt(2);
x[2][i] = (conjf(h1)*r2 + h3*conjf(r3))/hh13 * sqrt(2);
x[3][i] = (-h3*conjf(r2) + conjf(h1)*r3)/hh13 * sqrt(2);
int m_ap = (nof_symbols % 4) ? ((nof_symbols - 2) / 4) : nof_symbols / 4;
for (i = 0; i < m_ap; i++) {
h0 = ce[0][4 * i];
h1 = ce[1][4 * i + 2];
h2 = ce[2][4 * i];
h3 = ce[3][4 * i + 2];
hh02 = crealf(h0) * crealf(h0) + cimagf(h0) * cimagf(h0)
+ crealf(h2) * crealf(h2) + cimagf(h2) * cimagf(h2);
hh13 = crealf(h1) * crealf(h1) + cimagf(h1) * cimagf(h1)
+ crealf(h3) * crealf(h3) + cimagf(h3) * cimagf(h3);
r0 = y[4 * i];
r1 = y[4 * i + 1];
r2 = y[4 * i + 2];
r3 = y[4 * i + 3];
x[0][i] = (conjf(h0) * r0 + h2 * conjf(r1)) / hh02 * sqrt(2);
x[1][i] = (-h2 * conjf(r0) + conjf(h0) * r1) / hh02 * sqrt(2);
x[2][i] = (conjf(h1) * r2 + h3 * conjf(r3)) / hh13 * sqrt(2);
x[3][i] = (-h3 * conjf(r2) + conjf(h1) * r3) / hh13 * sqrt(2);
}
return i;
@ -176,25 +178,27 @@ int predecoding_diversity_zf(cf_t *y, cf_t *ce[MAX_PORTS],
}
/* 36.211 v10.3.0 Section 6.3.4 */
int predecoding_type(cf_t *y, cf_t *ce[MAX_PORTS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_layers, int nof_symbols, lte_mimo_type_t type) {
int predecoding_type(cf_t *y, cf_t *ce[MAX_PORTS], cf_t *x[MAX_LAYERS],
int nof_ports, int nof_layers, int nof_symbols, lte_mimo_type_t type) {
if (nof_ports > MAX_PORTS) {
fprintf(stderr, "Maximum number of ports is %d (nof_ports=%d)\n", MAX_PORTS, nof_ports);
fprintf(stderr, "Maximum number of ports is %d (nof_ports=%d)\n", MAX_PORTS,
nof_ports);
return -1;
}
if (nof_layers > MAX_LAYERS) {
fprintf(stderr, "Maximum number of layers is %d (nof_layers=%d)\n", MAX_LAYERS, nof_layers);
fprintf(stderr, "Maximum number of layers is %d (nof_layers=%d)\n",
MAX_LAYERS, nof_layers);
return -1;
}
switch(type) {
switch (type) {
case SINGLE_ANTENNA:
if (nof_ports == 1 && nof_layers == 1) {
return predecoding_single_zf(y, ce[0], x[0], nof_symbols);
} else{
fprintf(stderr, "Number of ports and layers must be 1 for transmission on single antenna ports\n");
} else {
fprintf(stderr,
"Number of ports and layers must be 1 for transmission on single antenna ports\n");
return -1;
}
break;
@ -202,7 +206,8 @@ int predecoding_type(cf_t *y, cf_t *ce[MAX_PORTS],
if (nof_ports == nof_layers) {
return predecoding_diversity_zf(y, ce, x, nof_ports, nof_symbols);
} else {
fprintf(stderr, "Error number of layers must equal number of ports in transmit diversity\n");
fprintf(stderr,
"Error number of layers must equal number of ports in transmit diversity\n");
return -1;
}
break;

@ -43,7 +43,9 @@ int nof_layers = 1, nof_ports = 1;
char *mimo_type_name = NULL;
void usage(char *prog) {
printf("Usage: %s -m [single|diversity|multiplex] -l [nof_layers] -p [nof_ports]\n", prog);
printf(
"Usage: %s -m [single|diversity|multiplex] -l [nof_layers] -p [nof_ports]\n",
prog);
printf("\t-n num_symbols [Default %d]\n", nof_symbols);
}
@ -77,7 +79,8 @@ void parse_args(int argc, char **argv) {
int main(int argc, char **argv) {
int i, j;
float mse;
cf_t *x[MAX_LAYERS], *r[MAX_PORTS], *y[MAX_PORTS], *h[MAX_PORTS], *xr[MAX_LAYERS];
cf_t *x[MAX_LAYERS], *r[MAX_PORTS], *y[MAX_PORTS], *h[MAX_PORTS],
*xr[MAX_LAYERS];
lte_mimo_type_t type;
parse_args(argc, argv);
@ -92,7 +95,7 @@ int main(int argc, char **argv) {
exit(-1);
}
for (i=0;i<nof_layers;i++) {
for (i = 0; i < nof_layers; i++) {
x[i] = malloc(sizeof(cf_t) * nof_symbols);
if (!x[i]) {
perror("malloc");
@ -104,7 +107,7 @@ int main(int argc, char **argv) {
exit(-1);
}
}
for (i=0;i<nof_ports;i++) {
for (i = 0; i < nof_ports; i++) {
y[i] = malloc(sizeof(cf_t) * nof_symbols * nof_layers);
// TODO: The number of symbols per port is different in spatial multiplexing.
if (!y[i]) {
@ -126,9 +129,10 @@ int main(int argc, char **argv) {
}
/* generate random data */
for (i=0;i<nof_layers;i++) {
for (j=0;j<nof_symbols;j++) {
x[i][j] = 100 * ((float) rand()/RAND_MAX + (float) I*rand()/RAND_MAX);
for (i = 0; i < nof_layers; i++) {
for (j = 0; j < nof_symbols; j++) {
x[i][j] = 100
* ((float) rand() / RAND_MAX + (float) I * rand() / RAND_MAX);
}
}
@ -139,10 +143,10 @@ int main(int argc, char **argv) {
}
/* generate channel */
for (i=0;i<nof_ports;i++) {
for (j=0;j<nof_symbols * nof_layers;j++) {
float hc = -1+(float) i/nof_ports;
h[i][j] = (3+hc) * cexpf(I * hc);
for (i = 0; i < nof_ports; i++) {
for (j = 0; j < nof_symbols * nof_layers; j++) {
float hc = -1 + (float) i / nof_ports;
h[i][j] = (3 + hc) * cexpf(I * hc);
}
}
@ -151,32 +155,33 @@ int main(int argc, char **argv) {
/* there's only one receiver antenna, signals from different transmitter
* ports are simply combined at the receiver
*/
for (j=0;j<nof_symbols * nof_layers;j++) {
for (j = 0; j < nof_symbols * nof_layers; j++) {
r[0][j] = 0;
for (i=0;i<nof_ports;i++) {
for (i = 0; i < nof_ports; i++) {
r[0][j] += y[i][j] * h[i][j];
}
}
/* predecoding / equalization */
if (predecoding_type(r[0], h, xr, nof_ports, nof_layers, nof_symbols * nof_layers, type) < 0) {
if (predecoding_type(r[0], h, xr, nof_ports, nof_layers,
nof_symbols * nof_layers, type) < 0) {
fprintf(stderr, "Error layer mapper encoder\n");
exit(-1);
}
/* check errors */
mse = 0;
for (i=0;i<nof_layers;i++) {
for (j=0;j<nof_symbols;j++) {
mse += cabsf(xr[i][j] - x[i][j])/nof_layers/nof_symbols;
for (i = 0; i < nof_layers; i++) {
for (j = 0; j < nof_symbols; j++) {
mse += cabsf(xr[i][j] - x[i][j]) / nof_layers / nof_symbols;
}
}
for (i=0;i<nof_layers;i++) {
for (i = 0; i < nof_layers; i++) {
free(x[i]);
free(xr[i]);
}
for (i=0;i<nof_ports;i++) {
for (i = 0; i < nof_ports; i++) {
free(y[i]);
free(h[i]);
}

@ -25,7 +25,6 @@
*
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@ -59,12 +58,12 @@ void dci_free(dci_t *q) {
}
void dci_candidate_fprint(FILE *f, dci_candidate_t *q) {
fprintf(f, "L: %d, nCCE: %d, RNTI: 0x%x, nBits: %d\n",
q->L, q->ncce, q->rnti, q->nof_bits);
fprintf(f, "L: %d, nCCE: %d, RNTI: 0x%x, nBits: %d\n", q->L, q->ncce, q->rnti,
q->nof_bits);
}
int dci_msg_candidate_set(dci_msg_t *msg, int L, int nCCE, unsigned short rnti) {
if (L >= 0 && L <=3) {
if (L >= 0 && L <= 3) {
msg->location.L = (unsigned char) L;
} else {
fprintf(stderr, "Invalid L %d\n", L);
@ -81,14 +80,14 @@ int dci_msg_candidate_set(dci_msg_t *msg, int L, int nCCE, unsigned short rnti)
}
int riv_nbits(int nof_prb) {
return (int) ceilf(log2f((float) nof_prb*((float) nof_prb+1)/2));
return (int) ceilf(log2f((float) nof_prb * ((float) nof_prb + 1) / 2));
}
const int ambiguous_sizes[10] = {12, 14, 16, 20, 24, 26, 32, 40, 44, 56};
const int ambiguous_sizes[10] = { 12, 14, 16, 20, 24, 26, 32, 40, 44, 56 };
bool is_ambiguous_size(int size) {
int i;
for (i=0;i<10;i++) {
for (i = 0; i < 10; i++) {
if (size == ambiguous_sizes[i]) {
return true;
}
@ -96,20 +95,17 @@ bool is_ambiguous_size(int size) {
return false;
}
/**********************************
* PAYLOAD sizeof functions
* ********************************/
int dci_format0_sizeof_(int nof_prb) {
return 1+1+riv_nbits(nof_prb)+5+1+2+3+1;
return 1 + 1 + riv_nbits(nof_prb) + 5 + 1 + 2 + 3 + 1;
}
int dci_format1A_sizeof(int nof_prb) {
int n;
n = 1+1+riv_nbits(nof_prb)+5+3+1+2+2;
while(n < dci_format0_sizeof_(nof_prb)) {
n = 1 + 1 + riv_nbits(nof_prb) + 5 + 3 + 1 + 2 + 2;
while (n < dci_format0_sizeof_(nof_prb)) {
n++;
}
if (is_ambiguous_size(n)) {
@ -118,7 +114,6 @@ int dci_format1A_sizeof(int nof_prb) {
return n;
}
int dci_format0_sizeof(int nof_prb) {
int n = dci_format0_sizeof_(nof_prb);
while (n < dci_format1A_sizeof(nof_prb)) {
@ -129,12 +124,12 @@ int dci_format0_sizeof(int nof_prb) {
int dci_format1_sizeof(int nof_prb) {
int n = (int) ceilf((float) nof_prb/ra_type0_P(nof_prb))+5+3+1+2+2;
int n = (int) ceilf((float) nof_prb / ra_type0_P(nof_prb)) + 5 + 3 + 1 + 2
+ 2;
if (nof_prb > 10) {
n++;
}
while(n == dci_format0_sizeof(nof_prb)
|| n == dci_format1A_sizeof(nof_prb)
while (n == dci_format0_sizeof(nof_prb) || n == dci_format1A_sizeof(nof_prb)
|| is_ambiguous_size(n)) {
n++;
}
@ -144,7 +139,7 @@ int dci_format1_sizeof(int nof_prb) {
int dci_format1C_sizeof(int nof_prb) {
int n_vrb_dl_gap1 = ra_type2_n_vrb_dl(nof_prb, true);
int n_step = ra_type2_n_rb_step(nof_prb);
int n = + riv_nbits((int) n_vrb_dl_gap1/n_step) + 5;
int n = +riv_nbits((int) n_vrb_dl_gap1 / n_step) + 5;
if (nof_prb >= 50) {
n++;
}
@ -152,7 +147,7 @@ int dci_format1C_sizeof(int nof_prb) {
}
int dci_format_sizeof(dci_format_t format, int nof_prb) {
switch(format) {
switch (format) {
case Format0:
return dci_format0_sizeof(nof_prb);
case Format1:
@ -166,13 +161,10 @@ int dci_format_sizeof(dci_format_t format, int nof_prb) {
}
}
/**********************************
* DCI Resource Allocation functions
* ********************************/
/* Packs DCI format 0 data to a sequence of bits and store them in msg according
* to 36.212 5.3.3.1.1
*
@ -203,7 +195,8 @@ int dci_format0_pack(ra_pusch_t *data, dci_msg_t *msg, int nof_prb) {
/* pack RIV according to 8.1 of 36.213 */
uint32_t riv;
if (data->type2_alloc.L_crb) {
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start, nof_prb);
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start,
nof_prb);
} else {
riv = data->type2_alloc.riv;
}
@ -222,7 +215,8 @@ int dci_format0_pack(ra_pusch_t *data, dci_msg_t *msg, int nof_prb) {
} else {
if (data->mcs.tbs) {
if (data->mcs.tbs) {
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs, ra_nprb_ul(data, nof_prb));
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs,
ra_nprb_ul(data, nof_prb));
}
}
mcs = ra_mcs_to_table_idx(&data->mcs);
@ -248,7 +242,7 @@ int dci_format0_pack(ra_pusch_t *data, dci_msg_t *msg, int nof_prb) {
// Padding with zeros
int n = dci_format0_sizeof(nof_prb);
while (y-msg->data < n) {
while (y - msg->data < n) {
*y++ = 0;
}
msg->location.nof_bits = (y - msg->data);
@ -271,7 +265,8 @@ int dci_format0_unpack(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
return -1;
}
if (*y++ != 0) {
fprintf(stderr, "Invalid format differentiation field value. This is Format1A\n");
fprintf(stderr,
"Invalid format differentiation field value. This is Format1A\n");
return -1;
}
if (*y++ == 0) {
@ -283,31 +278,33 @@ int dci_format0_unpack(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
data->freq_hop_fl = *y++;
} else {
n_ul_hop = 2; // Table 8.4-1 of 36.213
data->freq_hop_fl = y[0]<<1 | y[1];
data->freq_hop_fl = y[0] << 1 | y[1];
y += 2;
}
}
/* unpack RIV according to 8.1 of 36.213 */
uint32_t riv = bit_unpack(&y, riv_nbits(nof_prb) - n_ul_hop);
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, nof_prb, nof_prb);
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start,
nof_prb, nof_prb);
bit_pack(riv, &y, riv_nbits(nof_prb) - n_ul_hop);
data->type2_alloc.riv = riv;
/* unpack MCS according to 8.6 of 36.213 */
uint32_t mcs = bit_unpack(&y, 5);
data->ndi = *y++?true:false;
data->ndi = *y++ ? true : false;
// TCP and DM RS commands not implemented
y+= 5;
y += 5;
// CQI request
data->cqi_request = *y++?true:false;
data->cqi_request = *y++ ? true : false;
// 8.6.2 First paragraph
if (mcs <= 28) {
ra_mcs_from_idx_ul(mcs, &data->mcs);
data->mcs.tbs = ra_tbs_from_idx(data->mcs.tbs_idx, ra_nprb_ul(data, nof_prb));
data->mcs.tbs = ra_tbs_from_idx(data->mcs.tbs_idx,
ra_nprb_ul(data, nof_prb));
}
// 8.6.1 and 8.6.2 36.213 second paragraph
@ -340,18 +337,20 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
/* Resource allocation: type0 or type 1 */
int P = ra_type0_P(nof_prb);
int alloc_size = (int) ceilf((float) nof_prb/P);
switch(data->alloc_type) {
int alloc_size = (int) ceilf((float) nof_prb / P);
switch (data->alloc_type) {
case alloc_type0:
bit_pack(data->type0_alloc.rbg_bitmask, &y, alloc_size);
break;
case alloc_type1:
bit_pack(data->type1_alloc.rbg_subset, &y, (int) ceilf(log2f(P)));
*y++ = data->type1_alloc.shift?1:0;
bit_pack(data->type1_alloc.vrb_bitmask, &y, alloc_size - (int) ceilf(log2f(P)) - 1);
*y++ = data->type1_alloc.shift ? 1 : 0;
bit_pack(data->type1_alloc.vrb_bitmask, &y,
alloc_size - (int) ceilf(log2f(P)) - 1);
break;
default:
fprintf(stderr, "Format 1 accepts type0 or type1 resource allocation only\n");
fprintf(stderr,
"Format 1 accepts type0 or type1 resource allocation only\n");
return -1;
}
@ -361,7 +360,8 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
mcs = data->mcs.mcs_idx;
} else {
if (data->mcs.tbs) {
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs, ra_nprb_dl(data, nof_prb));
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs,
ra_nprb_dl(data, nof_prb));
}
mcs = ra_mcs_to_table_idx(&data->mcs);
}
@ -381,7 +381,7 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
// Padding with zeros
int n = dci_format1_sizeof(nof_prb);
while (y-msg->data < n) {
while (y - msg->data < n) {
*y++ = 0;
}
msg->location.nof_bits = (y - msg->data);
@ -408,18 +408,20 @@ int dci_format1_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
/* Resource allocation: type0 or type 1 */
int P = ra_type0_P(nof_prb);
int alloc_size = (int) ceilf((float) nof_prb/P);
switch(data->alloc_type) {
int alloc_size = (int) ceilf((float) nof_prb / P);
switch (data->alloc_type) {
case alloc_type0:
data->type0_alloc.rbg_bitmask = bit_unpack(&y, alloc_size);
break;
case alloc_type1:
data->type1_alloc.rbg_subset = bit_unpack(&y, (int) ceilf(log2f(P)));
data->type1_alloc.shift = *y++?true:false;
data->type1_alloc.vrb_bitmask = bit_unpack(&y, alloc_size - (int) ceilf(log2f(P)) - 1);
data->type1_alloc.shift = *y++ ? true : false;
data->type1_alloc.vrb_bitmask = bit_unpack(&y,
alloc_size - (int) ceilf(log2f(P)) - 1);
break;
default:
fprintf(stderr, "Format 1 accepts type0 or type1 resource allocation only\n");
fprintf(stderr,
"Format 1 accepts type0 or type1 resource allocation only\n");
return -1;
}
@ -432,23 +434,22 @@ int dci_format1_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
/* harq process number */
data->harq_process = bit_unpack(&y, 3);
data->ndi = *y++?true:false;
data->ndi = *y++ ? true : false;
// rv version
data->rv_idx = bit_unpack(&y, 2);
// TPC not implemented
return 0;
}
/* Packs DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3
*
* TODO: RA procedure initiated by PDCCH, TPC commands
*/
int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_is_crnti) {
int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb,
bool crc_is_crnti) {
/* pack bits */
char *y = msg->data;
@ -464,7 +465,8 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
if (data->type2_alloc.mode == t2_loc) {
if (data->type2_alloc.L_crb > nof_prb) {
fprintf(stderr, "L_CRB=%d can not exceed system BW for localized type2\n", data->type2_alloc.L_crb);
fprintf(stderr, "L_CRB=%d can not exceed system BW for localized type2\n",
data->type2_alloc.L_crb);
return -1;
}
} else {
@ -472,17 +474,20 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
if (crc_is_crnti && nof_prb > 50) {
n_vrb_dl = 16;
} else {
n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap==t2_ng1);
n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
}
if (data->type2_alloc.L_crb > n_vrb_dl) {
fprintf(stderr, "L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n", data->type2_alloc.L_crb, n_vrb_dl);
fprintf(stderr,
"L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n",
data->type2_alloc.L_crb, n_vrb_dl);
return -1;
}
}
/* pack RIV according to 7.1.6.3 of 36.213 */
uint32_t riv;
if (data->type2_alloc.L_crb) {
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start, nof_prb);
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start,
nof_prb);
} else {
riv = data->type2_alloc.riv;
}
@ -491,7 +496,7 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
nb_gap = 1;
*y++ = data->type2_alloc.n_gap;
}
bit_pack(riv, &y, riv_nbits(nof_prb)-nb_gap);
bit_pack(riv, &y, riv_nbits(nof_prb) - nb_gap);
// in format1A, MCS = TBS according to 7.1.7.2 of 36.213
uint32_t mcs;
@ -504,7 +509,7 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
if (!crc_is_crnti) {
n_prb = ra_nprb_dl(data, nof_prb);
} else {
n_prb = data->type2_alloc.n_prb1a==nprb1a_2?2:3;
n_prb = data->type2_alloc.n_prb1a == nprb1a_2 ? 2 : 3;
}
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs, n_prb);
}
@ -534,7 +539,7 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
// Padding with zeros
int n = dci_format1A_sizeof(nof_prb);
while (y-msg->data < n) {
while (y - msg->data < n) {
*y++ = 0;
}
msg->location.nof_bits = (y - msg->data);
@ -545,7 +550,8 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
/* Unpacks DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3
*
*/
int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc_is_crnti) {
int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb,
bool crc_is_crnti) {
/* pack bits */
char *y = msg->data;
@ -557,7 +563,8 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
}
if (*y++ != 1) {
fprintf(stderr, "Invalid format differentiation field value. This is Format0\n");
fprintf(stderr,
"Invalid format differentiation field value. This is Format0\n");
return -1;
}
@ -580,7 +587,8 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
nof_vrb = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
}
uint32_t riv = bit_unpack(&y, riv_nbits(nof_prb) - nb_gap);
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, nof_prb, nof_vrb);
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start,
nof_prb, nof_vrb);
data->type2_alloc.riv = riv;
// unpack MCS
@ -610,7 +618,7 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
if (crc_is_crnti) {
n_prb = ra_nprb_dl(data, nof_prb);
} else {
n_prb = data->type2_alloc.n_prb1a==nprb1a_2?2:3;
n_prb = data->type2_alloc.n_prb1a == nprb1a_2 ? 2 : 3;
}
data->mcs.tbs = ra_tbs_from_idx(data->mcs.tbs_idx, n_prb);
data->mcs.mod = QPSK;
@ -627,7 +635,8 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
char *y = msg->data;
if (data->alloc_type != alloc_type2 || data->type2_alloc.mode != t2_dist) {
fprintf(stderr, "Format 1C accepts distributed type2 resource allocation only\n");
fprintf(stderr,
"Format 1C accepts distributed type2 resource allocation only\n");
return -1;
}
@ -635,11 +644,12 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
*y++ = data->type2_alloc.n_gap;
}
int n_step = ra_type2_n_rb_step(nof_prb);
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap==t2_ng1);
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
if (data->type2_alloc.L_crb > ((int) n_vrb_dl/n_step)*n_step) {
fprintf(stderr, "L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n", data->type2_alloc.L_crb,
((int) n_vrb_dl/n_step)*n_step);
if (data->type2_alloc.L_crb > ((int) n_vrb_dl / n_step) * n_step) {
fprintf(stderr,
"L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n",
data->type2_alloc.L_crb, ((int) n_vrb_dl / n_step) * n_step);
return -1;
}
if (data->type2_alloc.L_crb % n_step) {
@ -650,8 +660,8 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
fprintf(stderr, "RB_start must be multiple of n_step\n");
return -1;
}
int L_p = data->type2_alloc.L_crb/n_step;
int RB_p = data->type2_alloc.RB_start/n_step;
int L_p = data->type2_alloc.L_crb / n_step;
int RB_p = data->type2_alloc.RB_start / n_step;
int n_vrb_p = (int) n_vrb_dl / n_step;
uint32_t riv;
@ -660,7 +670,7 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
} else {
riv = data->type2_alloc.riv;
}
bit_pack(riv, &y, riv_nbits((int) n_vrb_dl/n_step));
bit_pack(riv, &y, riv_nbits((int) n_vrb_dl / n_step));
// in format1C, MCS = TBS according to 7.1.7.2 of 36.213
uint32_t mcs;
@ -695,9 +705,9 @@ int dci_format1Cs_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
data->type2_alloc.n_gap = *y++;
}
int n_step = ra_type2_n_rb_step(nof_prb);
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap==t2_ng1);
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
uint32_t riv = bit_unpack(&y, riv_nbits((int) n_vrb_dl/n_step));
uint32_t riv = bit_unpack(&y, riv_nbits((int) n_vrb_dl / n_step));
int n_vrb_p = (int) n_vrb_dl / n_step;
ra_type2_from_riv(riv, &L_p, &RB_p, n_vrb_p, n_vrb_p);
@ -715,8 +725,9 @@ int dci_format1Cs_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
return 0;
}
int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format, int nof_prb, bool crc_is_crnti) {
switch(format) {
int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format,
int nof_prb, bool crc_is_crnti) {
switch (format) {
case Format1:
return dci_format1_pack(data, msg, nof_prb);
case Format1A:
@ -724,12 +735,14 @@ int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format, in
case Format1C:
return dci_format1Cs_pack(data, msg, nof_prb);
default:
fprintf(stderr, "Invalid DCI format %s for PDSCH resource allocation\n", dci_format_string(format));
fprintf(stderr, "Invalid DCI format %s for PDSCH resource allocation\n",
dci_format_string(format));
return -1;
}
}
int dci_msg_unpack_pdsch(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc_is_crnti) {
int dci_msg_unpack_pdsch(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb,
bool crc_is_crnti) {
if (msg->location.nof_bits == dci_format_sizeof(Format1, nof_prb)) {
return dci_format1_unpack(msg, data, nof_prb);
} else if (msg->location.nof_bits == dci_format_sizeof(Format1A, nof_prb)) {
@ -750,7 +763,7 @@ int dci_msg_unpack_pusch(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
}
char* dci_format_string(dci_format_t format) {
switch(format) {
switch (format) {
case Format0:
return "Format0";
case Format1:
@ -765,26 +778,28 @@ char* dci_format_string(dci_format_t format) {
}
void dci_msg_type_fprint(FILE *f, dci_msg_type_t type) {
switch(type.type) {
switch (type.type) {
case PUSCH_SCHED:
fprintf(f,"%s PUSCH Scheduling\n", dci_format_string(type.format));
fprintf(f, "%s PUSCH Scheduling\n", dci_format_string(type.format));
break;
case PDSCH_SCHED:
fprintf(f,"%s PDSCH Scheduling\n", dci_format_string(type.format));
fprintf(f, "%s PDSCH Scheduling\n", dci_format_string(type.format));
break;
case RA_PROC_PDCCH:
fprintf(f,"%s Random access initiated by PDCCH\n", dci_format_string(type.format));
fprintf(f, "%s Random access initiated by PDCCH\n",
dci_format_string(type.format));
break;
case MCCH_CHANGE:
fprintf(f,"%s MCCH change notification\n", dci_format_string(type.format));
fprintf(f, "%s MCCH change notification\n", dci_format_string(type.format));
break;
case TPC_COMMAND:
fprintf(f,"%s TPC command\n", dci_format_string(type.format));
fprintf(f, "%s TPC command\n", dci_format_string(type.format));
break;
}
}
int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, int nof_prb, unsigned short crnti) {
int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, int nof_prb,
unsigned short crnti) {
if (msg->location.nof_bits == dci_format_sizeof(Format0, nof_prb)
&& !msg->data[0]) {
type->type = PUSCH_SCHED;

@ -25,7 +25,6 @@
*
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@ -43,18 +42,16 @@
#include "lte/utils/debug.h"
const char crc_mask[4][16] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}
};
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 }, { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 } };
bool pbch_exists(int nframe, int nslot) {
return (!(nframe % 5) && nslot == 1);
}
int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id, bool put) {
int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id,
bool put) {
int i;
cf_t *ptr;
assert(cell_id >= 0);
@ -67,17 +64,17 @@ int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id, bo
}
/* symbol 0 & 1 */
for (i=0;i<2;i++) {
prb_cp_ref(&input, &output, cell_id%3, 4, 6, put);
for (i = 0; i < 2; i++) {
prb_cp_ref(&input, &output, cell_id % 3, 4, 6, put);
}
/* symbols 2 & 3 */
if (CP_ISNORM(cp)) {
for (i=0;i<2;i++) {
for (i = 0; i < 2; i++) {
prb_cp(&input, &output, 6);
}
} else {
prb_cp(&input, &output, 6);
prb_cp_ref(&input, &output, cell_id%3, 4, 6, put);
prb_cp_ref(&input, &output, cell_id % 3, 4, 6, put);
}
if (put) {
return input - ptr;
@ -93,7 +90,8 @@ int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id, bo
*
* 36.211 10.3 section 6.6.4
*/
int pbch_put(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp, int cell_id) {
int pbch_put(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp,
int cell_id) {
return pbch_cp(pbch, slot1_data, nof_prb, cp, cell_id, true);
}
@ -104,7 +102,8 @@ int pbch_put(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp, int cell_id
*
* 36.211 10.3 section 6.6.4
*/
int pbch_get(cf_t *slot1_data, cf_t *pbch, int nof_prb, lte_cp_t cp, int cell_id) {
int pbch_get(cf_t *slot1_data, cf_t *pbch, int nof_prb, lte_cp_t cp,
int cell_id) {
return pbch_cp(slot1_data, pbch, nof_prb, cp, cell_id, false);
}
@ -129,7 +128,7 @@ int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp) {
goto clean;
}
int poly[3] = {0x6D, 0x4F, 0x57};
int poly[3] = { 0x6D, 0x4F, 0x57 };
if (viterbi_init(&q->decoder, viterbi_37, poly, 40, true)) {
goto clean;
}
@ -141,14 +140,14 @@ int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp) {
q->encoder.tail_biting = true;
memcpy(q->encoder.poly, poly, 3 * sizeof(int));
q->nof_symbols = (CP_ISNORM(q->cp)) ? PBCH_RE_CPNORM: PBCH_RE_CPEXT;
q->nof_symbols = (CP_ISNORM(q->cp)) ? PBCH_RE_CPNORM : PBCH_RE_CPEXT;
q->pbch_d = malloc(sizeof(cf_t) * q->nof_symbols);
if (!q->pbch_d) {
goto clean;
}
int i;
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i = 0; i < MAX_PORTS_CTRL; i++) {
q->ce[i] = malloc(sizeof(cf_t) * q->nof_symbols);
if (!q->ce[i]) {
goto clean;
@ -188,8 +187,7 @@ int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp) {
}
ret = 0;
clean:
if (ret == -1) {
clean: if (ret == -1) {
pbch_free(q);
}
return ret;
@ -200,7 +198,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_CTRL; i++) {
if (q->ce[i]) {
free(q->ce[i]);
}
@ -241,7 +239,7 @@ void pbch_mib_unpack(char *msg, pbch_mib_t *mib) {
int bw, phich_res;
bw = bit_unpack(&msg, 3);
switch(bw) {
switch (bw) {
case 0:
mib->nof_prb = 6;
break;
@ -249,7 +247,7 @@ void pbch_mib_unpack(char *msg, pbch_mib_t *mib) {
mib->nof_prb = 15;
break;
default:
mib->nof_prb = (bw-1)*25;
mib->nof_prb = (bw - 1) * 25;
break;
}
if (*msg) {
@ -260,7 +258,7 @@ void pbch_mib_unpack(char *msg, pbch_mib_t *mib) {
msg++;
phich_res = bit_unpack(&msg, 2);
switch(phich_res) {
switch (phich_res) {
case 0:
mib->phich_resources = R_1_6;
break;
@ -277,28 +275,27 @@ void pbch_mib_unpack(char *msg, pbch_mib_t *mib) {
mib->sfn = bit_unpack(&msg, 8) << 2;
}
/** Unpacks MIB from PBCH message.
* msg buffer must be 24 byte length at least
*/
void pbch_mib_pack(pbch_mib_t *mib, char *msg) {
int bw, phich_res=0;
int bw, phich_res = 0;
bzero(msg, 24);
if (mib->nof_prb<=6) {
if (mib->nof_prb <= 6) {
bw = 0;
} else if (mib->nof_prb <= 15) {
bw = 1;
} else {
bw = 1 + mib->nof_prb/25;
bw = 1 + mib->nof_prb / 25;
}
bit_pack(bw, &msg, 3);
*msg = mib->phich_length == PHICH_EXT;
msg++;
switch(mib->phich_resources) {
switch (mib->phich_resources) {
case R_1_6:
phich_res = 0;
break;
@ -319,9 +316,10 @@ void pbch_mib_pack(pbch_mib_t *mib, char *msg) {
void pbch_mib_fprint(FILE *stream, pbch_mib_t *mib) {
printf(" - Nof ports: %d\n", mib->nof_ports);
printf(" - PRB: %d\n", mib->nof_prb);
printf(" - PHICH Length: %s\n", mib->phich_length==PHICH_EXT?"Extended":"Normal");
printf(" - PHICH Length: %s\n",
mib->phich_length == PHICH_EXT ? "Extended" : "Normal");
printf(" - PHICH Resources: ");
switch(mib->phich_resources) {
switch (mib->phich_resources) {
case R_1_6:
printf("1/6");
break;
@ -343,16 +341,14 @@ void pbch_decode_reset(pbch_t *q) {
q->frame_idx = 0;
}
void crc_set_mask(char *data, int nof_ports) {
int i;
for (i=0;i<16;i++) {
data[24+i] = (data[24+i] + crc_mask[nof_ports-1][i]) % 2;
for (i = 0; i < 16; i++) {
data[24 + i] = (data[24 + i] + crc_mask[nof_ports - 1][i]) % 2;
}
}
/* Checks CRC after applying the mask for the given number of ports.
*
* The bits buffer size must be at least 40 bytes.
@ -366,18 +362,21 @@ int pbch_crc_check(pbch_t *q, char *bits, int nof_ports) {
return crc_checksum(&q->crc, data, 40);
}
int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n, int nof_bits, int nof_ports) {
int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n,
int nof_bits, int nof_ports) {
int j;
memcpy(&q->temp[dst*nof_bits], &q->pbch_llr[src*nof_bits], n*nof_bits*sizeof(float));
memcpy(&q->temp[dst * nof_bits], &q->pbch_llr[src * nof_bits],
n * nof_bits * sizeof(float));
/* descramble */
scrambling_f_offset(&q->seq_pbch, &q->temp[dst*nof_bits], dst*nof_bits, n*nof_bits);
scrambling_f_offset(&q->seq_pbch, &q->temp[dst * nof_bits], dst * nof_bits,
n * nof_bits);
for (j=0;j<dst*nof_bits;j++) {
for (j = 0; j < dst * nof_bits; j++) {
q->temp[j] = RX_NULL;
}
for (j=(dst+n)*nof_bits;j<4*nof_bits;j++) {
for (j = (dst + n) * nof_bits; j < 4 * nof_bits; j++) {
q->temp[j] = RX_NULL;
}
@ -385,7 +384,7 @@ int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n, int n
rm_conv_rx(q->temp, 4 * nof_bits, q->pbch_rm_f, 120);
/* FIXME: If channel estimates are zero, received LLR are NaN. Check and return error */
for (j=0;j<120;j++) {
for (j = 0; j < 120; j++) {
if (isnan(q->pbch_rm_f[j]) || isinf(q->pbch_rm_f[j])) {
return 0;
}
@ -394,12 +393,12 @@ int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n, int n
/* decode */
viterbi_decode_f(&q->decoder, q->pbch_rm_f, q->data, 40);
int c=0;
for (j=0;j<40;j++) {
c+=q->data[j];
int c = 0;
for (j = 0; j < 40; j++) {
c += q->data[j];
}
if (!c) {
c=1;
c = 1;
}
if (!pbch_crc_check(q, q->data, nof_ports)) {
@ -407,7 +406,7 @@ int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n, int n
pbch_mib_unpack(q->data, mib);
mib->nof_ports = nof_ports;
mib->sfn += dst-src;
mib->sfn += dst - src;
return 1;
} else {
@ -423,9 +422,10 @@ int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n, 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_CTRL],
float ebno, pbch_mib_t *mib) {
int src, dst, res, nb;
int nant_[3] = {1, 2, 4};
int nant_[3] = { 1, 2, 4 };
int na, nant;
/* Set pointers for layermapping & precoding */
@ -434,22 +434,23 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
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_CTRL; i++) {
x[i] = q->pbch_x[i];
}
memset(&x[MAX_PORTS_CTRL], 0, sizeof(cf_t*) * (MAX_LAYERS - MAX_PORTS_CTRL));
/* extract symbols */
if (q->nof_symbols != pbch_get(slot1_symbols, q->pbch_symbols[0], q->nof_prb,
q->cp, q->cell_id)) {
if (q->nof_symbols
!= pbch_get(slot1_symbols, q->pbch_symbols[0], q->nof_prb, q->cp,
q->cell_id)) {
fprintf(stderr, "There was an error getting the PBCH symbols\n");
return -1;
}
/* extract channel estimates */
for (i=0;i<MAX_PORTS_CTRL;i++) {
if (q->nof_symbols != pbch_get(ce[i], q->ce[i], q->nof_prb,
q->cp, q->cell_id)) {
for (i = 0; i < MAX_PORTS_CTRL; 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");
return -1;
}
@ -459,7 +460,7 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
res = 0;
/* Try decoding for 1 to 4 antennas */
for (na=0;na<3 && !res;na++) {
for (na = 0; na < 3 && !res; na++) {
nant = nant_[na];
INFO("Trying %d TX antennas with %d frames\n", nant, q->frame_idx);
@ -467,10 +468,12 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
/* in conctrol channels, only diversity is supported */
if (nant == 1) {
/* no need for layer demapping */
predecoding_single_zf(q->pbch_symbols[0], q->ce[0], q->pbch_d, q->nof_symbols);
predecoding_single_zf(q->pbch_symbols[0], q->ce[0], q->pbch_d,
q->nof_symbols);
} else {
predecoding_diversity_zf(q->pbch_symbols[0], q->ce, x, nant, q->nof_symbols);
layerdemap_diversity(x, q->pbch_d, nant, q->nof_symbols/nant);
predecoding_diversity_zf(q->pbch_symbols[0], q->ce, x, nant,
q->nof_symbols);
layerdemap_diversity(x, q->pbch_d, nant, q->nof_symbols / nant);
}
/* demodulate symbols */
@ -485,11 +488,12 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
* FIXME: There are unnecessary checks because 2,3,4 have already been processed in the previous
* calls.
*/
for (nb=0;nb<q->frame_idx && !res;nb++) {
for (dst=0;(dst<4-nb) && !res;dst++) {
for (src=0;src<q->frame_idx-nb && !res;src++) {
DEBUG("Trying %d blocks at offset %d as subframe mod4 number %d\n", nb+1, src, dst);
res = pbch_decode_frame(q, mib, src, dst, nb+1, nof_bits, nant);
for (nb = 0; nb < q->frame_idx && !res; nb++) {
for (dst = 0; (dst < 4 - nb) && !res; dst++) {
for (src = 0; src < q->frame_idx - nb && !res; src++) {
DEBUG("Trying %d blocks at offset %d as subframe mod4 number %d\n",
nb + 1, src, dst);
res = pbch_decode_frame(q, mib, src, dst, nb + 1, nof_bits, nant);
}
}
}
@ -503,10 +507,10 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
return res;
}
/** 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) {
void pbch_encode(pbch_t *q, pbch_mib_t *mib,
cf_t *slot1_symbols[MAX_PORTS_CTRL], int nof_ports) {
int i;
int nof_bits = 2 * q->nof_symbols;
@ -516,7 +520,7 @@ void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL]
cf_t *x[MAX_LAYERS];
/* number of layers equals number of ports */
for (i=0;i<nof_ports;i++) {
for (i = 0; i < nof_ports; i++) {
x[i] = q->pbch_x[i];
}
memset(&x[nof_ports], 0, sizeof(cf_t*) * (MAX_LAYERS - nof_ports));
@ -537,21 +541,22 @@ void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL]
scrambling_b_offset(&q->seq_pbch, &q->pbch_rm_b[q->frame_idx * nof_bits],
q->frame_idx * nof_bits, nof_bits);
mod_modulate(&q->mod, &q->pbch_rm_b[q->frame_idx * nof_bits], q->pbch_d, nof_bits);
mod_modulate(&q->mod, &q->pbch_rm_b[q->frame_idx * nof_bits], q->pbch_d,
nof_bits);
/* layer mapping & precoding */
if (nof_ports > 1) {
layermap_diversity(q->pbch_d, x, nof_ports, q->nof_symbols);
precoding_diversity(x, q->pbch_symbols, nof_ports, q->nof_symbols/nof_ports);
precoding_diversity(x, q->pbch_symbols, nof_ports,
q->nof_symbols / nof_ports);
} else {
memcpy(q->pbch_symbols[0], q->pbch_d, q->nof_symbols * sizeof(cf_t));
}
/* mapping to resource elements */
for (i=0;i<nof_ports;i++) {
pbch_put(q->pbch_symbols[i], slot1_symbols[i], q->nof_prb, q->cp, q->cell_id);
for (i = 0; i < nof_ports; i++) {
pbch_put(q->pbch_symbols[i], slot1_symbols[i], q->nof_prb, q->cp,
q->cell_id);
}
q->frame_idx++;
if (q->frame_idx == 4) {
@ -559,5 +564,3 @@ void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL]
}
}

@ -25,7 +25,6 @@
*
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@ -42,23 +41,22 @@
#include "lte/utils/vector.h"
#include "lte/utils/debug.h"
// Table 5.3.4-1
static char cfi_table[4][PCFICH_CFI_LEN] = {
{0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1},
{1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0},
{1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // reserved
static char cfi_table[4][PCFICH_CFI_LEN] = { { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1,
1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 }, { 1, 0, 1,
1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
0, 1, 1, 0 }, { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } // reserved
};
bool pcfich_exists(int nframe, int nslot) {
return true;
}
/** Initializes the pcfich channel receiver */
int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_ports, lte_cp_t cp) {
int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb,
int nof_ports, lte_cp_t cp) {
int ret = -1;
if (cell_id < 0) {
return -1;
@ -77,8 +75,8 @@ int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_por
demod_hard_init(&q->demod);
demod_hard_table_set(&q->demod, LTE_QPSK);
for (int nsf=0;nsf<NSUBFRAMES_X_FRAME;nsf++) {
if (sequence_pcfich(&q->seq_pcfich[nsf], 2*nsf, q->cell_id)) {
for (int nsf = 0; nsf < NSUBFRAMES_X_FRAME; nsf++) {
if (sequence_pcfich(&q->seq_pcfich[nsf], 2 * nsf, q->cell_id)) {
goto clean;
}
}
@ -86,15 +84,14 @@ int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_por
q->nof_symbols = PCFICH_RE;
ret = 0;
clean:
if (ret == -1) {
clean: if (ret == -1) {
pcfich_free(q);
}
return ret;
}
void pcfich_free(pcfich_t *q) {
for (int ns=0;ns<NSUBFRAMES_X_FRAME;ns++) {
for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) {
sequence_free(&q->seq_pcfich[ns]);
}
modem_table_free(&q->mod);
@ -105,12 +102,12 @@ void pcfich_free(pcfich_t *q) {
*/
int pcfich_cfi_decode(char bits[PCFICH_CFI_LEN], int *cfi) {
int i, j;
int distance, index=-1;
int distance, index = -1;
int min = 32;
for (i=0;i<3;i++) {
for (i = 0; i < 3; i++) {
distance = 0;
for (j=0;j<PCFICH_CFI_LEN;j++) {
for (j = 0; j < PCFICH_CFI_LEN; j++) {
distance += (bits[j] ^ cfi_table[i][j]);
}
DEBUG("CFI=%d, distance:%d\n", i, distance);
@ -120,13 +117,12 @@ int pcfich_cfi_decode(char bits[PCFICH_CFI_LEN], int *cfi) {
}
}
if (cfi) {
*cfi = index+1;
*cfi = index + 1;
}
return min;
}
/** Encodes the CFI producing a vector of 32 bits.
* 36.211 10.3 section 5.3.4
*/
@ -135,16 +131,16 @@ int pcfich_cfi_encode(int cfi, char bits[PCFICH_CFI_LEN]) {
fprintf(stderr, "Invalid CFI %d\n", cfi);
return -1;
}
memcpy(bits, cfi_table[cfi-1], PCFICH_CFI_LEN * sizeof(char));
memcpy(bits, cfi_table[cfi - 1], PCFICH_CFI_LEN * sizeof(char));
return 0;
}
/* Decodes the PCFICH channel and saves the CFI in the cfi pointer.
*
* 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 nsubframe, int *cfi, int *distance) {
int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
int nsubframe, int *cfi, int *distance) {
int dist;
/* Set pointers for layermapping & precoding */
@ -158,21 +154,22 @@ int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int
}
/* number of layers equals number of ports */
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i = 0; i < MAX_PORTS_CTRL; i++) {
x[i] = q->pcfich_x[i];
}
for (i=0;i<MAX_PORTS;i++) {
for (i = 0; i < MAX_PORTS; i++) {
ce_precoding[i] = q->ce[i];
}
/* extract symbols */
if (q->nof_symbols != regs_pcfich_get(q->regs, slot_symbols, q->pcfich_symbols[0])) {
if (q->nof_symbols
!= regs_pcfich_get(q->regs, slot_symbols, q->pcfich_symbols[0])) {
fprintf(stderr, "There was an error getting the PCFICH symbols\n");
return -1;
}
/* extract channel estimates */
for (i=0;i<q->nof_ports;i++) {
for (i = 0; i < q->nof_ports; i++) {
if (q->nof_symbols != regs_pcfich_get(q->regs, ce[i], q->ce[i])) {
fprintf(stderr, "There was an error getting the PCFICH symbols\n");
return -1;
@ -182,10 +179,13 @@ int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int
/* in control channels, only diversity is supported */
if (q->nof_ports == 1) {
/* no need for layer demapping */
predecoding_single_zf(q->pcfich_symbols[0], q->ce[0], q->pcfich_d, q->nof_symbols);
predecoding_single_zf(q->pcfich_symbols[0], q->ce[0], q->pcfich_d,
q->nof_symbols);
} else {
predecoding_diversity_zf(q->pcfich_symbols[0], ce_precoding, x, q->nof_ports, q->nof_symbols);
layerdemap_diversity(x, q->pcfich_d, q->nof_ports, q->nof_symbols/q->nof_ports);
predecoding_diversity_zf(q->pcfich_symbols[0], ce_precoding, x,
q->nof_ports, q->nof_symbols);
layerdemap_diversity(x, q->pcfich_d, q->nof_ports,
q->nof_symbols / q->nof_ports);
}
/* demodulate symbols */
@ -206,10 +206,10 @@ int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int
}
}
/** Encodes CFI and maps symbols to the slot
*/
int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int nsubframe) {
int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL],
int nsubframe) {
int i;
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
@ -222,10 +222,10 @@ int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int
cf_t *symbols_precoding[MAX_PORTS];
/* number of layers equals number of ports */
for (i=0;i<q->nof_ports;i++) {
for (i = 0; i < q->nof_ports; i++) {
x[i] = q->pcfich_x[i];
}
for (i=0;i<MAX_PORTS;i++) {
for (i = 0; i < MAX_PORTS; i++) {
symbols_precoding[i] = q->pcfich_symbols[i];
}
@ -240,13 +240,14 @@ int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int
/* layer mapping & precoding */
if (q->nof_ports > 1) {
layermap_diversity(q->pcfich_d, x, q->nof_ports, q->nof_symbols);
precoding_diversity(x, symbols_precoding, q->nof_ports, q->nof_symbols/q->nof_ports);
precoding_diversity(x, symbols_precoding, q->nof_ports,
q->nof_symbols / q->nof_ports);
} else {
memcpy(q->pcfich_symbols[0], q->pcfich_d, q->nof_symbols * sizeof(cf_t));
}
/* mapping to resource elements */
for (i=0;i<q->nof_ports;i++) {
for (i = 0; i < q->nof_ports; i++) {
if (regs_pcfich_put(q->regs, q->pcfich_symbols[i], slot_symbols[i]) < 0) {
fprintf(stderr, "Error putting PCHICH resource elements\n");
return -1;
@ -256,4 +257,3 @@ int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int
return 0;
}

@ -48,17 +48,18 @@
#define PDCCH_FORMAT_NOF_BITS(i) ((1<<i)*72)
#define NOF_COMMON_FORMATS 2
const dci_format_t common_formats[NOF_COMMON_FORMATS] = {Format1A, Format1C};
const dci_format_t common_formats[NOF_COMMON_FORMATS] = { Format1A, Format1C };
#define NOF_UE_FORMATS 2
const dci_format_t ue_formats[NOF_UE_FORMATS] = {Format0, Format1}; // 1A has the same payload as 0
const dci_format_t ue_formats[NOF_UE_FORMATS] = { Format0, Format1 }; // 1A has the same payload as 0
#define MIN(a,b) ((a>b)?b:a)
/**
* 36.213 9.1
*/
int gen_common_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned short rnti) {
int gen_common_search(dci_candidate_t *c, int nof_cce, int nof_bits,
unsigned short rnti) {
int i, l, L, k;
k = 0;
for (l = 3; l > 1; l--) {
@ -79,7 +80,8 @@ int gen_common_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned sh
/**
* 36.213 9.1
*/
int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned short rnti, int subframe) {
int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits,
unsigned short rnti, int subframe) {
int i, l, L, k, m;
unsigned int Yk;
const int S[4] = { 6, 12, 8, 16 };
@ -87,11 +89,12 @@ int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned short
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]: ");
if (VERBOSE_ISINFO())
printf("[INFO]: ");
}
for (l = 3; l >= 0; l--) {
L = (1 << l);
for (i = 0; i < MIN(nof_cce/L,16/S[l]); i++) {
for (i = 0; i < MIN(nof_cce / L, 16 / S[l]); i++) {
c[k].L = l;
c[k].nof_bits = nof_bits;
c[k].rnti = rnti;
@ -109,14 +112,16 @@ int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned short
}
}
if (!subframe) {
if (VERBOSE_ISINFO()) printf("\n");
if (VERBOSE_ISINFO())
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);
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];
@ -124,7 +129,7 @@ void pdcch_init_common(pdcch_t *q, pdcch_search_t *s, unsigned short rnti) {
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++) {
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++;
@ -149,19 +154,21 @@ void pdcch_init_search_ue(pdcch_t *q, unsigned short c_rnti) {
int l, 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));
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);
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++) {
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++) {
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);
}
@ -210,13 +217,13 @@ 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_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;
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);
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);
if (modem_table_std(&q->mod, LTE_QPSK, true)) {
goto clean;
@ -279,7 +286,7 @@ int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
void pdcch_free(pdcch_t *q) {
int i, j;
for (i=0;i<PDCCH_NOF_SEARCH_MODES;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]);
@ -321,8 +328,7 @@ void pdcch_free(pdcch_t *q) {
*
* TODO: UE transmit antenna selection CRC mask
*/
unsigned short dci_decode(pdcch_t *q, float *e, char *data, int E,
int nof_bits) {
unsigned short dci_decode(pdcch_t *q, float *e, char *data, int E, int nof_bits) {
float tmp[3 * (DCI_MAX_BITS + 16)];
unsigned short p_bits, crc_res;
@ -342,13 +348,14 @@ unsigned short dci_decode(pdcch_t *q, float *e, char *data, int E,
viterbi_decode_f(&q->decoder, tmp, data, nof_bits + 16);
if (VERBOSE_ISDEBUG()) {
bit_fprint(stdout, data, nof_bits+16);
bit_fprint(stdout, data, nof_bits + 16);
}
x = &data[nof_bits];
p_bits = (unsigned short) bit_unpack(&x, 16);
crc_res = ((unsigned short) crc_checksum(&q->crc, data, nof_bits) & 0xffff);
DEBUG("p_bits: 0x%x, crc_res: 0x%x, tot: 0x%x\n", p_bits, crc_res, p_bits ^ crc_res);
DEBUG("p_bits: 0x%x, crc_res: 0x%x, tot: 0x%x\n", p_bits, crc_res,
p_bits ^ crc_res);
return (p_bits ^ crc_res);
}
@ -356,17 +363,14 @@ 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",
c->nof_bits, PDCCH_FORMAT_NOF_BITS(c->L), c->ncce, c->L,
c->rnti);
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);
if (c->rnti == crc_res) {
memcpy(&msg->location, c, sizeof(dci_candidate_t));
INFO(
"FOUND Candidate: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n",
c->nof_bits, PDCCH_FORMAT_NOF_BITS(c->L), c->ncce, c->L,
c->rnti);
INFO("FOUND Candidate: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n",
c->nof_bits, PDCCH_FORMAT_NOF_BITS(c->L), c->ncce, c->L, c->rnti);
return 1;
}
return 0;
@ -398,7 +402,8 @@ int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
/* extract symbols */
int n = regs_pdcch_get(q->regs, slot_symbols, q->pdcch_symbols[0]);
if (q->nof_symbols != n) {
fprintf(stderr, "Expected %d PDCCH symbols but got %d symbols\n", q->nof_symbols, n);
fprintf(stderr, "Expected %d PDCCH symbols but got %d symbols\n",
q->nof_symbols, n);
return -1;
}
@ -406,7 +411,8 @@ int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
for (i = 0; i < q->nof_ports; i++) {
n = regs_pdcch_get(q->regs, ce[i], q->ce[i]);
if (q->nof_symbols != n) {
fprintf(stderr, "Expected %d PDCCH symbols but got %d symbols\n", q->nof_symbols, n);
fprintf(stderr, "Expected %d PDCCH symbols but got %d symbols\n",
q->nof_symbols, n);
return -1;
}
}
@ -452,7 +458,8 @@ int pdcch_decode_current_mode(pdcch_t *q, float *llr, dci_t *dci, int subframe)
k = 0;
}
for (i = 0; i < q->search_mode[q->current_search_mode].nof_candidates
for (i = 0;
i < q->search_mode[q->current_search_mode].nof_candidates
&& dci->nof_dcis < dci->max_dcis; i++) {
if (pdcch_decode_candidate(q, q->pdcch_llr,
&q->search_mode[q->current_search_mode].candidates[k][i],
@ -476,7 +483,6 @@ int pdcch_decode_ue(pdcch_t *q, float *llr, dci_t *dci, int nsubframe) {
return pdcch_decode_current_mode(q, llr, dci, nsubframe);
}
/* Decodes PDCCH channels
*
* dci->nof_dcis is the size of the dci->msg buffer (ie max number of messages)
@ -486,8 +492,7 @@ int pdcch_decode_ue(pdcch_t *q, float *llr, dci_t *dci, int nsubframe) {
int pdcch_decode(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
dci_t *dci, int nsubframe, float ebno) {
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, ebno)) {
return -1;
}
@ -514,7 +519,8 @@ void crc_set_mask_rnti(char *crc, unsigned short rnti) {
/** 36.212 5.3.3.2 to 5.3.3.4
* TODO: UE transmit antenna selection CRC mask
*/
void dci_encode(pdcch_t *q, char *data, char *e, int nof_bits, int E, unsigned short rnti) {
void dci_encode(pdcch_t *q, char *data, char *e, int nof_bits, int E,
unsigned short rnti) {
convcoder_t encoder;
char tmp[3 * (DCI_MAX_BITS + 16)];
@ -564,18 +570,21 @@ int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS_CTRL],
/* Encode DCIs */
for (i = 0; i < dci->nof_dcis; i++) {
/* do some sanity checks */
if (dci->msg[i].location.ncce + PDCCH_FORMAT_NOF_CCE(dci->msg[i].location.L) > q->nof_cce
|| dci->msg[i].location.L > 3
if (dci->msg[i].location.ncce + PDCCH_FORMAT_NOF_CCE(dci->msg[i].location.L)
> q->nof_cce || dci->msg[i].location.L > 3
|| dci->msg[i].location.nof_bits > DCI_MAX_BITS) {
fprintf(stderr, "Illegal DCI message %d\n", i);
return -1;
}
INFO("Encoding DCI %d: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n",
i, dci->msg[i].location.nof_bits, PDCCH_FORMAT_NOF_BITS(dci->msg[i].location.L),
dci->msg[i].location.ncce, dci->msg[i].location.L, dci->msg[i].location.rnti);
INFO("Encoding DCI %d: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n", i,
dci->msg[i].location.nof_bits,
PDCCH_FORMAT_NOF_BITS(dci->msg[i].location.L),
dci->msg[i].location.ncce, dci->msg[i].location.L,
dci->msg[i].location.rnti);
dci_encode(q, dci->msg[i].data, &q->pdcch_e[72 * dci->msg[i].location.ncce],
dci->msg[i].location.nof_bits, PDCCH_FORMAT_NOF_BITS(dci->msg[i].location.L),
dci->msg[i].location.nof_bits,
PDCCH_FORMAT_NOF_BITS(dci->msg[i].location.L),
dci->msg[i].location.rnti);
}

@ -56,9 +56,10 @@ 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", prb_alloc->re_sf[nsubframe], prb_alloc->slot[0].nof_prb);
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) {
nof_refs = 2;
@ -81,8 +82,7 @@ int pdsch_cp(pdsch_t *q, cf_t *input, cf_t *output, ra_prb_t *prb_alloc,
// Skip PSS/SSS signals
if (s == 0 && (nsubframe == 0 || nsubframe == 5)) {
if (prb_alloc->slot[s].prb_idx[n] >= q->nof_prb / 2 - 3
&& prb_alloc->slot[s].prb_idx[n]
<= q->nof_prb / 2 + 3) {
&& prb_alloc->slot[s].prb_idx[n] <= q->nof_prb / 2 + 3) {
lend = CP_NSYMB(q->cp) - 2;
is_sss = true;
}
@ -90,22 +90,23 @@ int pdsch_cp(pdsch_t *q, cf_t *input, cf_t *output, ra_prb_t *prb_alloc,
// Skip PBCH
if (s == 1 && nsubframe == 0) {
if (prb_alloc->slot[s].prb_idx[n] >= q->nof_prb / 2 - 3
&& prb_alloc->slot[s].prb_idx[n]
<= q->nof_prb / 2 + 3) {
&& prb_alloc->slot[s].prb_idx[n] <= q->nof_prb / 2 + 3) {
lstart = 4;
is_pbch = true;
}
}
lp = l+s*CP_NSYMB(q->cp);
lp = l + s * CP_NSYMB(q->cp);
if (put) {
out_ptr = &output[(lp*q->nof_prb+prb_alloc->slot[s].prb_idx[n]) * RE_X_RB];
out_ptr = &output[(lp * q->nof_prb + prb_alloc->slot[s].prb_idx[n])
* RE_X_RB];
} else {
in_ptr = &input[(lp*q->nof_prb+prb_alloc->slot[s].prb_idx[n]) * RE_X_RB];
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 (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);
}
@ -122,9 +123,9 @@ int pdsch_cp(pdsch_t *q, cf_t *input, cf_t *output, ra_prb_t *prb_alloc,
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 (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);
}
@ -465,8 +466,8 @@ int pdsch_decode_tb(pdsch_t *q, char *data, int tbs, int nb_e, int rv_idx) {
/** Decodes the PDSCH from the received symbols
*/
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) {
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;
@ -478,18 +479,19 @@ int pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS],
nof_bits_e = nof_symbols * q->mod[mcs.mod - 1].nbits_x_symbol;
if (nof_bits > nof_bits_e) {
fprintf(stderr, "Invalid code rate %.2f\n",
(float) nof_bits / nof_bits_e);
fprintf(stderr, "Invalid code rate %.2f\n", (float) nof_bits / nof_bits_e);
return -1;
}
if (nof_symbols > q->max_symbols) {
fprintf(stderr, "Error too many RE per subframe (%d). PDSCH configured for %d RE (%d PRB)\n",
fprintf(stderr,
"Error too many RE per subframe (%d). PDSCH configured for %d RE (%d PRB)\n",
nof_symbols, q->max_symbols, q->nof_prb);
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) {
@ -524,7 +526,7 @@ int pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS],
}
/* demodulate symbols */
demod_soft_sigma_set(&q->demod, 2.0 / q->mod[mcs.mod-1].nbits_x_symbol);
demod_soft_sigma_set(&q->demod, 2.0 / q->mod[mcs.mod - 1].nbits_x_symbol);
demod_soft_table_set(&q->demod, &q->mod[mcs.mod - 1]);
demod_soft_demodulate(&q->demod, q->pdsch_d, q->pdsch_llr, nof_symbols);
@ -656,12 +658,14 @@ int pdsch_encode(pdsch_t *q, char *data, cf_t *sf_symbols[MAX_PORTS],
}
if (nof_symbols > q->max_symbols) {
fprintf(stderr, "Error too many RE per subframe (%d). PDSCH configured for %d RE (%d PRB)\n",
fprintf(stderr,
"Error too many RE per subframe (%d). PDSCH configured for %d RE (%d PRB)\n",
nof_symbols, q->max_symbols, q->nof_prb);
return -1;
}
INFO("Encoding PDSCH SF: %d, Mod %d, NofBits: %d, NofSymbols: %d, NofBitsE: %d\n",
INFO(
"Encoding PDSCH SF: %d, Mod %d, NofBits: %d, NofSymbols: %d, NofBitsE: %d\n",
nsubframe, mcs.mod, nof_bits, nof_symbols, nof_bits_e);
/* number of layers equals number of ports */
@ -672,8 +676,7 @@ int pdsch_encode(pdsch_t *q, char *data, cf_t *sf_symbols[MAX_PORTS],
pdsch_encode_tb(q, data, nof_bits, nof_bits_e, 0);
scrambling_b_offset(&q->seq_pdsch[nsubframe], q->pdsch_e_bits, 0,
nof_bits_e);
scrambling_b_offset(&q->seq_pdsch[nsubframe], q->pdsch_e_bits, 0, nof_bits_e);
mod_modulate(&q->mod[mcs.mod - 1], q->pdsch_e_bits, q->pdsch_d, nof_bits_e);

@ -59,7 +59,7 @@ int phich_ngroups(phich_t *q) {
void phich_reset(phich_t *q, cf_t *slot_symbols[MAX_PORTS_CTRL]) {
int i;
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i = 0; i < MAX_PORTS_CTRL; i++) {
regs_phich_reset(q->regs, slot_symbols[i]);
}
}
@ -114,7 +114,7 @@ char phich_ack_decode(char bits[PHICH_NBITS], int *distance) {
INFO("PHICH decoder: %d, %d, %d\n", bits[0], bits[1], bits[2]);
if (n >= 2) {
if (distance) {
*distance = 3-n;
*distance = 3 - n;
}
return 1;
} else {
@ -177,16 +177,14 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
/* extract symbols */
if (PHICH_MAX_NSYMB
!= regs_phich_get(q->regs, slot_symbols, q->phich_symbols[0],
ngroup)) {
!= regs_phich_get(q->regs, slot_symbols, q->phich_symbols[0], ngroup)) {
fprintf(stderr, "There was an error getting the phich symbols\n");
return -1;
}
/* extract channel estimates */
for (i = 0; i < q->nof_tx_ports; i++) {
if (PHICH_MAX_NSYMB
!= regs_phich_get(q->regs, ce[i], q->ce[i], ngroup)) {
if (PHICH_MAX_NSYMB != regs_phich_get(q->regs, ce[i], q->ce[i], ngroup)) {
fprintf(stderr, "There was an error getting the phich symbols\n");
return -1;
}
@ -203,9 +201,10 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
layerdemap_diversity(x, q->phich_d0, q->nof_tx_ports,
PHICH_MAX_NSYMB / q->nof_tx_ports);
}
DEBUG("Recv!!: \n",0);
DEBUG("d0: ",0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_d0, PHICH_MAX_NSYMB);
DEBUG("Recv!!: \n", 0);
DEBUG("d0: ", 0);
if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_d0, PHICH_MAX_NSYMB);
if (CP_ISEXT(q->cp)) {
if (ngroup % 2) {
@ -223,32 +222,34 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
memcpy(q->phich_d, q->phich_d0, PHICH_MAX_NSYMB * sizeof(cf_t));
}
DEBUG("d: ",0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_d, PHICH_EXT_MSYMB);
DEBUG("d: ", 0);
if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_d, PHICH_EXT_MSYMB);
scrambling_c(&q->seq_phich[nsubframe], q->phich_d);
/* De-spreading */
if (CP_ISEXT(q->cp)) {
for (i=0;i<PHICH_NBITS;i++) {
for (i = 0; i < PHICH_NBITS; i++) {
q->phich_z[i] = 0;
for (j=0;j<PHICH_EXT_NSF;j++) {
q->phich_z[i] += conjf(w_ext[nseq][j]) *
q->phich_d[i*PHICH_EXT_NSF+j]/PHICH_EXT_NSF;
for (j = 0; j < PHICH_EXT_NSF; j++) {
q->phich_z[i] += conjf(w_ext[nseq][j])
* q->phich_d[i * PHICH_EXT_NSF + j] / PHICH_EXT_NSF;
}
}
} else {
for (i=0;i<PHICH_NBITS;i++) {
for (i = 0; i < PHICH_NBITS; i++) {
q->phich_z[i] = 0;
for (j=0;j<PHICH_NORM_NSF;j++) {
q->phich_z[i] += conjf(w_normal[nseq][j]) *
q->phich_d[i*PHICH_NORM_NSF+j]/PHICH_NORM_NSF;
for (j = 0; j < PHICH_NORM_NSF; j++) {
q->phich_z[i] += conjf(w_normal[nseq][j])
* q->phich_d[i * PHICH_NORM_NSF + j] / PHICH_NORM_NSF;
}
}
}
DEBUG("z: ",0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_z, PHICH_NBITS);
DEBUG("z: ", 0);
if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_z, PHICH_NBITS);
demod_hard_demodulate(&q->demod, q->phich_z, q->data, PHICH_NBITS);
@ -304,8 +305,9 @@ int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
mod_modulate(&q->mod, q->data, q->phich_z, PHICH_NBITS);
DEBUG("data: ",0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_z, PHICH_NBITS);
DEBUG("data: ", 0);
if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_z, PHICH_NBITS);
/* Spread with w */
if (CP_ISEXT(q->cp)) {
@ -320,8 +322,9 @@ int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
}
}
DEBUG("d: ",0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_d, PHICH_EXT_MSYMB);
DEBUG("d: ", 0);
if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_d, PHICH_EXT_MSYMB);
scrambling_c(&q->seq_phich[nsubframe], q->phich_d);
@ -346,11 +349,10 @@ int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
memcpy(q->phich_d0, q->phich_d, PHICH_MAX_NSYMB * sizeof(cf_t));
}
DEBUG("d0: ",0);
DEBUG("d0: ", 0);
if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_d0, PHICH_MAX_NSYMB);
/* layer mapping & precoding */
if (q->nof_tx_ports > 1) {
layermap_diversity(q->phich_d0, x, q->nof_tx_ports, PHICH_MAX_NSYMB);
@ -363,8 +365,8 @@ int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
/* mapping to resource elements */
for (i = 0; i < q->nof_tx_ports; i++) {
if (regs_phich_add(q->regs, q->phich_symbols[i], ngroup,
slot_symbols[i]) < 0) {
if (regs_phich_add(q->regs, q->phich_symbols[i], ngroup, slot_symbols[i])
< 0) {
fprintf(stderr, "Error putting PCHICH resource elements\n");
return -1;
}

@ -41,8 +41,8 @@
#define min(a,b) (a<b?a:b)
/* Returns the number of RE in a PRB in a slot and subframe */
int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb, int nof_ports,
int nof_ctrl_symbols, lte_cp_t cp) {
int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb,
int nof_ports, int nof_ctrl_symbols, lte_cp_t cp) {
int re;
bool skip_refs = false;
@ -54,8 +54,8 @@ int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb, int nof_port
}
/* if it's the prb in the middle, there are less RE due to PBCH and PSS/SSS */
if ((nsubframe == 0 || nsubframe == 5) &&
(prb_idx >= nof_prb/2-3 && prb_idx <= nof_prb/2+3)) {
if ((nsubframe == 0 || nsubframe == 5)
&& (prb_idx >= nof_prb / 2 - 3 && prb_idx <= nof_prb / 2 + 3)) {
if (nsubframe == 0) {
if (nslot == 0) {
re = (CP_NSYMB(cp) - nof_ctrl_symbols - 2) * RE_X_RB;
@ -64,7 +64,7 @@ int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb, int nof_port
re = (CP_NSYMB(cp) - 4) * RE_X_RB;
skip_refs = true;
} else {
re = (CP_NSYMB(cp) - 4) * RE_X_RB + 2*nof_ports;
re = (CP_NSYMB(cp) - 4) * RE_X_RB + 2 * nof_ports;
}
}
} else if (nsubframe == 5) {
@ -72,13 +72,14 @@ int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb, int nof_port
re = (CP_NSYMB(cp) - nof_ctrl_symbols - 2) * RE_X_RB;
}
}
if ((nof_prb%2) && (prb_idx == nof_prb/2-3 || prb_idx == nof_prb/2+3)) {
if ((nof_prb % 2)
&& (prb_idx == nof_prb / 2 - 3 || prb_idx == nof_prb / 2 + 3)) {
if (nslot == 0) {
re += 2 * RE_X_RB / 2;
} else if (nsubframe == 0) {
re += 4 * RE_X_RB / 2 - nof_ports;
if (CP_ISEXT(cp)) {
re -= nof_ports>2?2:nof_ports;
re -= nof_ports > 2 ? 2 : nof_ports;
}
}
}
@ -86,7 +87,7 @@ int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb, int nof_port
// remove references
if (!skip_refs) {
switch(nof_ports) {
switch (nof_ports) {
case 1:
case 2:
re -= 2 * (nslot + 1) * nof_ports;
@ -108,29 +109,29 @@ int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb, int nof_port
}
/* Computes the number of RE for each PRB in the prb_dist structure */
void ra_prb_get_re(ra_prb_t *prb_dist, int nof_prb, int nof_ports, int nof_ctrl_symbols, lte_cp_t cp) {
void ra_prb_get_re(ra_prb_t *prb_dist, int nof_prb, int nof_ports,
int nof_ctrl_symbols, lte_cp_t cp) {
int i, j, s;
/* Set start symbol according to Section 7.1.6.4 in 36.213 */
prb_dist->lstart = nof_ctrl_symbols;
// Compute number of RE per subframe
for (i=0;i<NSUBFRAMES_X_FRAME;i++) {
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], nof_prb,
nof_ports, nof_ctrl_symbols, cp);
for (i = 0; i < NSUBFRAMES_X_FRAME; i++) {
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],
nof_prb, nof_ports, nof_ctrl_symbols, cp);
}
}
}
}
void ra_prb_fprint(FILE *f, ra_prb_slot_t *prb) {
int i, j, nrows;
nrows = (prb->nof_prb - 1)/ 25 + 1;
for (j=0;j<nrows;j++) {
for (i=0;i<min(25, prb->nof_prb-j*25);i++) {
fprintf(f, "%3d, ", prb->prb_idx[j*25+i]);
nrows = (prb->nof_prb - 1) / 25 + 1;
for (j = 0; j < nrows; j++) {
for (i = 0; i < min(25, prb->nof_prb - j * 25); i++) {
fprintf(f, "%3d, ", prb->prb_idx[j * 25 + i]);
}
fprintf(f, "\n");
}
@ -143,14 +144,13 @@ int ra_prb_get_ul(ra_prb_slot_t *prb, ra_pusch_t *ra, int nof_prb) {
fprintf(stderr, "Uplink only accepts type2 localized scheduling\n");
return -1;
}
for (i=0;i<ra->type2_alloc.L_crb;i++) {
prb->prb_idx[i] = i+ra->type2_alloc.RB_start;
for (i = 0; i < ra->type2_alloc.L_crb; i++) {
prb->prb_idx[i] = i + ra->type2_alloc.RB_start;
prb->nof_prb++;
}
return 0;
}
/** Compute PRB allocation for Downlink as defined in 7.1.6 of 36.213 */
int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
int i, j;
@ -159,14 +159,14 @@ int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
int n_rb_rbg_subset, n_rb_type1;
bzero(prb_dist, sizeof(ra_prb_t));
switch(ra->alloc_type) {
switch (ra->alloc_type) {
case alloc_type0:
bitmask = ra->type0_alloc.rbg_bitmask;
int nb = (int) ceilf((float)nof_prb/P);
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;
int nb = (int) ceilf((float) nof_prb / P);
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++;
}
}
@ -175,19 +175,19 @@ int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
break;
case alloc_type1:
n_rb_type1 = ra_type1_N_rb(nof_prb);
if (ra->type1_alloc.rbg_subset < (nof_prb/P) % P) {
n_rb_rbg_subset = ((nof_prb-1)/(P*P)) * P + P;
} else if (ra->type1_alloc.rbg_subset == ((nof_prb/P) % P)) {
n_rb_rbg_subset = ((nof_prb-1)/(P*P)) * P + ((nof_prb-1)%P)+1;
if (ra->type1_alloc.rbg_subset < (nof_prb / P) % P) {
n_rb_rbg_subset = ((nof_prb - 1) / (P * P)) * P + P;
} else if (ra->type1_alloc.rbg_subset == ((nof_prb / P) % P)) {
n_rb_rbg_subset = ((nof_prb - 1) / (P * P)) * P + ((nof_prb - 1) % P) + 1;
} else {
n_rb_rbg_subset = ((nof_prb-1)/(P*P)) * P;
n_rb_rbg_subset = ((nof_prb - 1) / (P * P)) * P;
}
int shift = ra->type1_alloc.shift?(n_rb_rbg_subset-n_rb_type1):0;
int shift = ra->type1_alloc.shift ? (n_rb_rbg_subset - n_rb_type1) : 0;
bitmask = ra->type1_alloc.vrb_bitmask;
for (i=0;i<n_rb_type1;i++) {
if (bitmask & (1<<(n_rb_type1-i-1))) {
prb_dist->slot[0].prb_idx[prb_dist->slot[0].nof_prb] = ((i+shift)/P)*P*P+
ra->type1_alloc.rbg_subset*P+(i+shift)%P;
for (i = 0; i < n_rb_type1; i++) {
if (bitmask & (1 << (n_rb_type1 - i - 1))) {
prb_dist->slot[0].prb_idx[prb_dist->slot[0].nof_prb] = ((i + shift) / P)
* P * P + ra->type1_alloc.rbg_subset * P + (i + shift) % P;
prb_dist->slot[0].nof_prb++;
}
}
@ -195,8 +195,8 @@ int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
break;
case alloc_type2:
if (ra->type2_alloc.mode == t2_loc) {
for (i=0;i<ra->type2_alloc.L_crb;i++) {
prb_dist->slot[0].prb_idx[i] = i+ra->type2_alloc.RB_start;
for (i = 0; i < ra->type2_alloc.L_crb; i++) {
prb_dist->slot[0].prb_idx[i] = i + ra->type2_alloc.RB_start;
prb_dist->slot[0].nof_prb++;
}
memcpy(&prb_dist->slot[1], &prb_dist->slot[0], sizeof(ra_prb_slot_t));
@ -204,44 +204,53 @@ int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
/* Mapping of Virtual to Physical RB for distributed type is defined in
* 6.2.3.2 of 36.211
*/
int N_gap, N_tilde_vrb, n_tilde_vrb, n_tilde_prb, n_tilde2_prb, N_null, N_row, n_vrb;
int N_gap, N_tilde_vrb, n_tilde_vrb, n_tilde_prb, n_tilde2_prb, N_null,
N_row, n_vrb;
int n_tilde_prb_odd, n_tilde_prb_even;
if (ra->type2_alloc.n_gap == t2_ng1) {
N_tilde_vrb = nof_prb;
N_gap = ra_type2_ngap(nof_prb, true);
} else {
N_tilde_vrb = 2*nof_prb;
N_tilde_vrb = 2 * nof_prb;
N_gap = ra_type2_ngap(nof_prb, false);
}
N_row = (int) ceilf((float) N_tilde_vrb/(4*P))*P;
N_null = 4*N_row-N_tilde_vrb;
for (i=0;i<ra->type2_alloc.L_crb;i++) {
n_vrb = i+ra->type2_alloc.RB_start;
n_tilde_vrb = n_vrb%N_tilde_vrb;
n_tilde_prb = 2*N_row*(n_tilde_vrb % 2)+n_tilde_vrb/2+N_tilde_vrb*(n_vrb/N_tilde_vrb);
n_tilde2_prb = N_row*(n_tilde_vrb % 4)+n_tilde_vrb/4+N_tilde_vrb*(n_vrb/N_tilde_vrb);
if (N_null != 0 && n_tilde_vrb >= (N_tilde_vrb - N_null) && (n_tilde_vrb%2) == 1) {
n_tilde_prb_odd = n_tilde_prb-N_row;
} else if (N_null != 0 && n_tilde_vrb >= (N_tilde_vrb - N_null) && (n_tilde_vrb%2) == 0) {
n_tilde_prb_odd = n_tilde_prb-N_row+N_null/2;
} else if (N_null != 0 && n_tilde_vrb < (N_tilde_vrb - N_null) && (n_tilde_vrb%4) >= 2) {
n_tilde_prb_odd = n_tilde2_prb-N_null/2;
N_row = (int) ceilf((float) N_tilde_vrb / (4 * P)) * P;
N_null = 4 * N_row - N_tilde_vrb;
for (i = 0; i < ra->type2_alloc.L_crb; i++) {
n_vrb = i + ra->type2_alloc.RB_start;
n_tilde_vrb = n_vrb % N_tilde_vrb;
n_tilde_prb = 2 * N_row * (n_tilde_vrb % 2) + n_tilde_vrb / 2
+ N_tilde_vrb * (n_vrb / N_tilde_vrb);
n_tilde2_prb = N_row * (n_tilde_vrb % 4) + n_tilde_vrb / 4
+ N_tilde_vrb * (n_vrb / N_tilde_vrb);
if (N_null != 0 && n_tilde_vrb >= (N_tilde_vrb - N_null)
&& (n_tilde_vrb % 2) == 1) {
n_tilde_prb_odd = n_tilde_prb - N_row;
} else if (N_null != 0 && n_tilde_vrb >= (N_tilde_vrb - N_null)
&& (n_tilde_vrb % 2) == 0) {
n_tilde_prb_odd = n_tilde_prb - N_row + N_null / 2;
} else if (N_null != 0 && n_tilde_vrb < (N_tilde_vrb - N_null)
&& (n_tilde_vrb % 4) >= 2) {
n_tilde_prb_odd = n_tilde2_prb - N_null / 2;
} else {
n_tilde_prb_odd = n_tilde2_prb;
}
n_tilde_prb_even = (n_tilde_prb_odd+N_tilde_vrb/2)%N_tilde_vrb+N_tilde_vrb*(n_vrb/N_tilde_vrb);
n_tilde_prb_even = (n_tilde_prb_odd + N_tilde_vrb / 2) % N_tilde_vrb
+ N_tilde_vrb * (n_vrb / N_tilde_vrb);
if (n_tilde_prb_odd < N_tilde_vrb/2) {
if (n_tilde_prb_odd < N_tilde_vrb / 2) {
prb_dist->slot[0].prb_idx[i] = n_tilde_prb_odd;
} else {
prb_dist->slot[0].prb_idx[i] = n_tilde_prb_odd+N_gap-N_tilde_vrb/2;
prb_dist->slot[0].prb_idx[i] = n_tilde_prb_odd + N_gap
- N_tilde_vrb / 2;
}
prb_dist->slot[0].nof_prb++;
if (n_tilde_prb_even < N_tilde_vrb/2) {
if (n_tilde_prb_even < N_tilde_vrb / 2) {
prb_dist->slot[1].prb_idx[i] = n_tilde_prb_even;
} else {
prb_dist->slot[1].prb_idx[i] = n_tilde_prb_even+N_gap-N_tilde_vrb/2;
prb_dist->slot[1].prb_idx[i] = n_tilde_prb_even + N_gap
- N_tilde_vrb / 2;
}
prb_dist->slot[1].nof_prb++;
}
@ -263,22 +272,23 @@ int ra_nprb_ul(ra_pusch_t *ra, int nof_prb) {
int ra_nprb_dl(ra_pdsch_t *ra, int nof_prb) {
int nprb;
int nof_rbg, P;
switch(ra->alloc_type) {
switch (ra->alloc_type) {
case alloc_type0:
// Get the number of allocated RBG except the last RBG
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)) {
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));
(int) ceilf((float) nof_prb / P));
return -1;
}
nprb = nof_rbg * P;
// last RBG may have smaller size. Add if set
int P_last = (nof_prb%P);
if (!P_last) P_last = P;
nprb += P_last*(ra->type0_alloc.rbg_bitmask&1);
int P_last = (nof_prb % P);
if (!P_last)
P_last = P;
nprb += P_last * (ra->type0_alloc.rbg_bitmask & 1);
break;
case alloc_type1:
nprb = bit_count(ra->type1_alloc.vrb_bitmask);
@ -313,35 +323,35 @@ int ra_type0_P(int nof_prb) {
/* Returns N_rb_type1 according to section 7.1.6.2 */
int ra_type1_N_rb(int nof_prb) {
int P = ra_type0_P(nof_prb);
return (int) ceilf((float) nof_prb/P) - (int) ceilf(log2f((float) P)) - 1;
return (int) ceilf((float) nof_prb / P) - (int) ceilf(log2f((float) P)) - 1;
}
/* Convert Type2 scheduling L_crb and RB_start to RIV value */
uint32_t ra_type2_to_riv(uint16_t L_crb, uint16_t RB_start, int nof_prb) {
uint32_t riv;
if (L_crb <= (int) nof_prb/2) {
riv = nof_prb*(L_crb-1) + RB_start;
if (L_crb <= (int) nof_prb / 2) {
riv = nof_prb * (L_crb - 1) + RB_start;
} else {
riv = nof_prb*(nof_prb-L_crb+1) + nof_prb - 1 - RB_start;
riv = nof_prb * (nof_prb - L_crb + 1) + nof_prb - 1 - RB_start;
}
return riv;
}
/* Convert Type2 scheduling RIV value to L_crb and RB_start values */
void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start, int nof_prb, int nof_vrb) {
*L_crb = (int) (riv/nof_prb) + 1;
*RB_start = riv%nof_prb;
void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start,
int nof_prb, int nof_vrb) {
*L_crb = (int) (riv / nof_prb) + 1;
*RB_start = riv % nof_prb;
if (*L_crb > nof_vrb - *RB_start) {
*L_crb = nof_prb - (int) (riv/nof_prb) + 1;
*RB_start = nof_prb - riv%nof_prb - 1;
*L_crb = nof_prb - (int) (riv / nof_prb) + 1;
*RB_start = nof_prb - riv % nof_prb - 1;
}
}
/* Table 6.2.3.2-1 in 36.211 */
int ra_type2_ngap(int nof_prb, bool ngap_is_1) {
if (nof_prb <= 10) {
return nof_prb/2;
return nof_prb / 2;
} else if (nof_prb == 11) {
return 4;
} else if (nof_prb <= 19) {
@ -353,15 +363,14 @@ int ra_type2_ngap(int nof_prb, bool ngap_is_1) {
} else if (nof_prb <= 49) {
return 27;
} else if (nof_prb <= 63) {
return ngap_is_1?27:9;
return ngap_is_1 ? 27 : 9;
} else if (nof_prb <= 79) {
return ngap_is_1?32:16;
return ngap_is_1 ? 32 : 16;
} else {
return ngap_is_1?48:16;
return ngap_is_1 ? 48 : 16;
}
}
/* Table 7.1.6.3-1 in 36.213 */
int ra_type2_n_rb_step(int nof_prb) {
if (nof_prb < 50) {
@ -371,14 +380,13 @@ int ra_type2_n_rb_step(int nof_prb) {
}
}
/* as defined in 6.2.3.2 of 36.211 */
int ra_type2_n_vrb_dl(int nof_prb, bool ngap_is_1) {
int ngap = ra_type2_ngap(nof_prb, ngap_is_1);
if (ngap_is_1) {
return 2*(ngap<(nof_prb-ngap)?ngap:nof_prb-ngap);
return 2 * (ngap < (nof_prb - ngap) ? ngap : nof_prb - ngap);
} else {
return ((int) nof_prb/ngap)*2*ngap;
return ((int) nof_prb / ngap) * 2 * ngap;
}
}
@ -403,10 +411,10 @@ int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs) {
mcs->tbs_idx = idx;
} else if (idx < 17) {
mcs->mod = QAM16;
mcs->tbs_idx = idx-1;
mcs->tbs_idx = idx - 1;
} else if (idx < 29) {
mcs->mod = QAM64;
mcs->tbs_idx = idx-2;
mcs->tbs_idx = idx - 2;
} else if (idx == 29) {
mcs->mod = QPSK;
mcs->tbs_idx = 0;
@ -424,7 +432,6 @@ int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs) {
return 0;
}
/* Converts MCS index to ra_mcs_t structure for Uplink as defined in Table 8.6.1-1 on 36.213 */
int ra_mcs_from_idx_ul(uint8_t idx, ra_mcs_t *mcs) {
if (idx < 11) {
@ -432,10 +439,10 @@ int ra_mcs_from_idx_ul(uint8_t idx, ra_mcs_t *mcs) {
mcs->tbs_idx = idx;
} else if (idx < 21) {
mcs->mod = QAM16;
mcs->tbs_idx = idx-1;
mcs->tbs_idx = idx - 1;
} else if (idx < 29) {
mcs->mod = QAM64;
mcs->tbs_idx = idx-2;
mcs->tbs_idx = idx - 2;
} else {
mcs->mod = MOD_NULL;
mcs->tbs_idx = 0;
@ -461,9 +468,8 @@ int ra_tbs_to_table_idx_format1c(int tbs) {
if (tbs < tbs_format1c_table[0]) {
return -1;
}
for (idx=1;idx<32;idx++) {
if (tbs_format1c_table[idx-1] <= tbs &&
tbs_format1c_table[idx] >= tbs) {
for (idx = 1; idx < 32; idx++) {
if (tbs_format1c_table[idx - 1] <= tbs && tbs_format1c_table[idx] >= tbs) {
return idx;
}
}
@ -471,9 +477,9 @@ int ra_tbs_to_table_idx_format1c(int tbs) {
}
/* Downlink Transport Block size determination as defined in 7.1.7.2 on 36.213 */
int ra_tbs_from_idx(uint8_t tbs_idx, int n_prb ) {
int ra_tbs_from_idx(uint8_t tbs_idx, int n_prb) {
if (tbs_idx < 27 && n_prb > 0 && n_prb <= 110) {
return tbs_table[tbs_idx][n_prb-1];
return tbs_table[tbs_idx][n_prb - 1];
} else {
return -1;
}
@ -490,9 +496,8 @@ int ra_tbs_to_table_idx(int tbs, int n_prb) {
if (tbs < tbs_table[0][n_prb]) {
return -1;
}
for (idx=1;idx<28;idx++) {
if (tbs_table[idx-1][n_prb] <= tbs &&
tbs_table[idx][n_prb] >= tbs) {
for (idx = 1; idx < 28; idx++) {
if (tbs_table[idx - 1][n_prb] <= tbs && tbs_table[idx][n_prb] >= tbs) {
return idx;
}
}
@ -523,7 +528,7 @@ void ra_pusch_fprint(FILE *f, ra_pusch_t *ra, int nof_prb) {
}
char *ra_type_string(ra_type_t alloc_type) {
switch(alloc_type) {
switch (alloc_type) {
case alloc_type0:
return "Type 0";
case alloc_type1:
@ -544,24 +549,25 @@ void ra_pdsch_set_mcs(ra_pdsch_t *ra, ra_mod_t mod, uint8_t tbs_idx) {
ra->mcs.tbs_idx = tbs_idx;
}
void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) {
fprintf(f, " - Resource Allocation Type:\t\t%s\n",ra_type_string(ra->alloc_type));
switch(ra->alloc_type) {
fprintf(f, " - Resource Allocation Type:\t\t%s\n",
ra_type_string(ra->alloc_type));
switch (ra->alloc_type) {
case alloc_type0:
fprintf(f, " + Resource Block Group Size:\t\t%d\n",ra_type0_P(nof_prb));
fprintf(f, " + RBG Bitmap:\t\t\t0x%x\n",ra->type0_alloc.rbg_bitmask);
fprintf(f, " + Resource Block Group Size:\t\t%d\n", ra_type0_P(nof_prb));
fprintf(f, " + RBG Bitmap:\t\t\t0x%x\n", ra->type0_alloc.rbg_bitmask);
break;
case alloc_type1:
fprintf(f, " + Resource Block Group Size:\t\t%d\n",ra_type0_P(nof_prb));
fprintf(f, " + RBG Bitmap:\t\t\t0x%x\n",ra->type1_alloc.vrb_bitmask);
fprintf(f, " + RBG Subset:\t\t\t%d\n",ra->type1_alloc.rbg_subset);
fprintf(f, " + RBG Shift:\t\t\t\t%s\n",ra->type1_alloc.shift?"Yes":"No");
fprintf(f, " + Resource Block Group Size:\t\t%d\n", ra_type0_P(nof_prb));
fprintf(f, " + RBG Bitmap:\t\t\t0x%x\n", ra->type1_alloc.vrb_bitmask);
fprintf(f, " + RBG Subset:\t\t\t%d\n", ra->type1_alloc.rbg_subset);
fprintf(f, " + RBG Shift:\t\t\t\t%s\n",
ra->type1_alloc.shift ? "Yes" : "No");
break;
case alloc_type2:
fprintf(f, " + Type:\t\t\t\t%s\n",
ra->type2_alloc.mode==t2_loc?"Localized":"Distributed");
fprintf(f, " + Resource Indicator Value:\t\t%d\n",ra->type2_alloc.riv);
ra->type2_alloc.mode == t2_loc ? "Localized" : "Distributed");
fprintf(f, " + Resource Indicator Value:\t\t%d\n", ra->type2_alloc.riv);
if (ra->type2_alloc.mode == t2_loc) {
fprintf(f, " + VRB Assignment:\t\t\t%d VRB starting with VRB %d\n",
ra->type2_alloc.L_crb, ra->type2_alloc.RB_start);
@ -569,7 +575,7 @@ void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) {
fprintf(f, " + VRB Assignment:\t\t\t%d VRB starting with VRB %d\n",
ra->type2_alloc.L_crb, ra->type2_alloc.RB_start);
fprintf(f, " + VRB gap selection:\t\t\tGap %d\n",
ra->type2_alloc.n_gap == t2_ng1?1:2);
ra->type2_alloc.n_gap == t2_ng1 ? 1 : 2);
fprintf(f, " + VRB gap:\t\t\t\t%d\n",
ra_type2_ngap(nof_prb, ra->type2_alloc.n_gap == t2_ng1));
}
@ -578,7 +584,7 @@ void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) {
ra_prb_t alloc;
ra_prb_get_dl(&alloc, ra, nof_prb);
for (int s=0;s<2;s++) {
for (int s = 0; s < 2; s++) {
fprintf(f, " - PRB Bitmap Assignment %dst slot:\n", s);
ra_prb_fprint(f, &alloc.slot[s]);
}
@ -588,7 +594,7 @@ void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) {
fprintf(f, " - Modulation type:\t\t\t%s\n", ra_mod_string(ra->mcs.mod));
fprintf(f, " - Transport block size:\t\t%d\n", ra->mcs.tbs);
fprintf(f, " - HARQ process:\t\t\t%d\n", ra->harq_process);
fprintf(f, " - New data indicator:\t\t\t%s\n", ra->ndi?"Yes":"No");
fprintf(f, " - New data indicator:\t\t\t%s\n", ra->ndi ? "Yes" : "No");
fprintf(f, " - Redundancy version:\t\t\t%d\n", ra->rv_idx);
fprintf(f, " - TPC command for PUCCH:\t\t--\n");
}

@ -54,7 +54,7 @@ int main(int argc, char **argv) {
nof_prb = atoi(argv[1]);
len = atoi(argv[2]);
nwords = (len-1)/32+1;
nwords = (len - 1) / 32 + 1;
if (argc < 3 + nwords) {
usage(argv[0]);
@ -64,9 +64,9 @@ int main(int argc, char **argv) {
y = msg.data;
rlen = 0;
unsigned int x;
for (i=0;i<nwords;i++) {
x = strtoul(argv[i+3],NULL,16);
if (len-rlen < 32) {
for (i = 0; i < nwords; i++) {
x = strtoul(argv[i + 3], NULL, 16);
if (len - rlen < 32) {
bit_pack(x, &y, len - rlen);
} else {
bit_pack(x, &y, 32);
@ -74,8 +74,8 @@ int main(int argc, char **argv) {
}
printf("DCI message len %d:\n",len);
for (i=0;i<len;i++) {
printf("DCI message len %d:\n", len);
for (i = 0; i < len; i++) {
printf("%d, ", msg.data[i]);
}
printf("\n");
@ -90,7 +90,7 @@ int main(int argc, char **argv) {
printf("\n");
printf("Message type:");
dci_msg_type_fprint(stdout, dci_type);
switch(dci_type.type) {
switch (dci_type.type) {
case PDSCH_SCHED:
bzero(&ra_dl, sizeof(ra_pdsch_t));
dci_msg_unpack_pdsch(&msg, &ra_dl, nof_prb, false);

@ -50,7 +50,7 @@ void usage(char *prog) {
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "cpnfv")) != -1) {
switch(opt) {
switch (opt) {
case 'p':
nof_ports = atoi(argv[optind]);
break;
@ -73,33 +73,27 @@ void parse_args(int argc, char **argv) {
}
}
int test_dci_payload_size() {
int i, j;
int x[4];
const dci_format_t formats[4] = {Format0, Format1, Format1A, Format1C};
const int prb[6]={6, 15, 25, 50, 75, 100};
const int dci_sz[6][5] = {
{21, 19, 21, 8},
{22, 23, 22, 10},
{25, 27, 25, 12},
{27, 31, 27, 13},
{27, 33, 27, 14},
{28, 39, 28, 15}
};
const dci_format_t formats[4] = { Format0, Format1, Format1A, Format1C };
const int prb[6] = { 6, 15, 25, 50, 75, 100 };
const int dci_sz[6][5] = { { 21, 19, 21, 8 }, { 22, 23, 22, 10 }, { 25, 27,
25, 12 }, { 27, 31, 27, 13 }, { 27, 33, 27, 14 }, { 28, 39, 28, 15 } };
printf("Testing DCI payload sizes...\n");
printf(" PRB\t0\t1\t1A\t1C\n");
for (i=0;i<6;i++) {
int n=prb[i];
for (j=0;j<4;j++) {
for (i = 0; i < 6; i++) {
int n = prb[i];
for (j = 0; j < 4; j++) {
x[j] = dci_format_sizeof(formats[j], n);
if (x[j] != dci_sz[i][j]) {
fprintf(stderr, "Invalid DCI payload size for %s\n", dci_format_string(formats[j]));
fprintf(stderr, "Invalid DCI payload size for %s\n",
dci_format_string(formats[j]));
return -1;
}
}
printf(" %2d:\t%2d\t%2d\t%2d\t%2d\n",n,x[0],x[1],x[2],x[3]);
printf(" %2d:\t%2d\t%2d\t%2d\t%2d\n", n, x[0], x[1], x[2], x[3]);
}
printf("Ok\n");
return 0;
@ -117,7 +111,7 @@ int main(int argc, char **argv) {
int nof_dcis;
int ret = -1;
parse_args(argc,argv);
parse_args(argc, argv);
nof_re = CPNORM_NSYMB * nof_prb * RE_X_RB;
@ -126,13 +120,13 @@ int main(int argc, char **argv) {
}
/* init memory */
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i = 0; i < MAX_PORTS_CTRL; i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
exit(-1);
}
for (j=0;j<nof_re;j++) {
for (j = 0; j < nof_re; j++) {
ce[i][j] = 1;
}
slot_symbols[i] = malloc(sizeof(cf_t) * nof_re);
@ -179,8 +173,8 @@ int main(int argc, char **argv) {
pdcch_encode(&pdcch, &dci_tx, slot_symbols, 0);
/* combine outputs */
for (i=1;i<nof_ports;i++) {
for (j=0;j<nof_re;j++) {
for (i = 1; i < nof_ports; i++) {
for (j = 0; j < nof_re; j++) {
slot_symbols[0][j] += slot_symbols[i][j];
}
}
@ -192,7 +186,7 @@ int main(int argc, char **argv) {
if (nof_dcis < 0) {
printf("Error decoding\n");
} else if (nof_dcis == dci_tx.nof_dcis) {
for (i=0;i<nof_dcis;i++) {
for (i = 0; i < nof_dcis; i++) {
if (dci_tx.msg[i].location.L != dci_rx.msg[i].location.L
|| dci_tx.msg[i].location.ncce != dci_rx.msg[i].location.ncce
|| dci_tx.msg[i].location.nof_bits != dci_rx.msg[i].location.nof_bits
@ -203,7 +197,8 @@ int main(int argc, char **argv) {
goto quit;
}
if (memcmp(dci_tx.msg[i].data, dci_rx.msg[i].data, dci_tx.msg[i].location.nof_bits)) {
if (memcmp(dci_tx.msg[i].data, dci_rx.msg[i].data,
dci_tx.msg[i].location.nof_bits)) {
printf("Error in DCI %d: Received data does not match\n", i);
goto quit;
}
@ -213,13 +208,12 @@ int main(int argc, char **argv) {
goto quit;
}
ret = 0;
quit:
pdcch_free(&pdcch);
quit: pdcch_free(&pdcch);
regs_free(&regs);
dci_free(&dci_tx);
dci_free(&dci_rx);
for (i=0;i<MAX_PORTS_CTRL;i++) {
for (i = 0; i < MAX_PORTS_CTRL; i++) {
free(ce[i]);
free(slot_symbols[i]);
}

@ -30,7 +30,7 @@
#include "lte/resampling/resample_arb.h"
#include "lte/utils/debug.h"
float polyfilt[RESAMPLE_ARB_N][RESAMPLE_ARB_M] =
float resample_arb_polyfilt[RESAMPLE_ARB_N][RESAMPLE_ARB_M] =
{{0,0.002400347599485495,-0.006922416132556366,0.0179104136912176,0.99453086623794,-0.008521087756729117,0.0008598969867484128,0.0004992625165376107},
{-0.001903604727400391,0.004479591950094871,-0.01525319260830623,0.04647449496926549,0.9910477342662829,-0.03275243420114668,0.008048813755373533,-0.001216900416836847},
{-0.001750442300940216,0.006728826416921727,-0.02407540632178267,0.07708575473589654,0.9841056525667189,-0.05473739187922162,0.01460652754040275,-0.002745266140572769},
@ -66,7 +66,7 @@ float polyfilt[RESAMPLE_ARB_N][RESAMPLE_ARB_M] =
// TODO: use lte/utils/vector.h and Volk
cf_t dot_prod(cf_t* x, float *y, int len)
cf_t resample_arb_dot_prod(cf_t* x, float *y, int len)
{
cf_t res = 0+0*I;
for(int i=0;i<len;i++){
@ -76,7 +76,7 @@ cf_t dot_prod(cf_t* x, float *y, int len)
}
// Right-shift our window of samples
void push(resample_arb_t *q, cf_t x)
void resample_arb_push(resample_arb_t *q, cf_t x)
{
memmove(&q->reg[1], &q->reg[0], (RESAMPLE_ARB_M-1)*sizeof(cf_t));
q->reg[0] = x;
@ -98,7 +98,7 @@ int resample_arb_compute(resample_arb_t *q, cf_t *input, cf_t *output, int n_in)
while(cnt < n_in)
{
*output = dot_prod(q->reg, polyfilt[idx], RESAMPLE_ARB_M);
*output = resample_arb_dot_prod(q->reg, resample_arb_polyfilt[idx], RESAMPLE_ARB_M);
output++;
n_out++;
q->acc += q->step;
@ -107,7 +107,7 @@ int resample_arb_compute(resample_arb_t *q, cf_t *input, cf_t *output, int n_in)
q->acc -= RESAMPLE_ARB_N;
idx -= RESAMPLE_ARB_N;
if(cnt < n_in)
push(q, input[cnt++]);
resample_arb_push(q, input[cnt++]);
}
}
return n_out;

@ -25,7 +25,6 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -41,7 +40,7 @@ void scrambling_f_offset(sequence_t *s, float *data, int offset, int len) {
assert (len + offset <= s->len);
for (i = 0; i < len; i++) {
data[i] = data[i]*(1-2*s->c[i+offset]);
data[i] = data[i] * (1 - 2 * s->c[i + offset]);
}
}
@ -54,7 +53,7 @@ void scrambling_c_offset(sequence_t *s, cf_t *data, int offset, int len) {
assert (len + offset <= s->len);
for (i = 0; i < len; i++) {
data[i] = data[i]*(1-2*s->c[i+offset]);
data[i] = data[i] * (1 - 2 * s->c[i + offset]);
}
}
@ -70,7 +69,7 @@ void scrambling_b_offset(sequence_t *s, char *data, int offset, int len) {
int i;
assert (len + offset <= s->len);
for (i = 0; i < len; i++) {
data[i] = (data[i] + s->c[i+offset]) % 2;
data[i] = (data[i] + s->c[i + offset]) % 2;
}
}
@ -80,21 +79,22 @@ int compute_sequences(scrambling_hl* h) {
switch (h->init.channel) {
case SCRAMBLING_PBCH:
return sequence_pbch(&h->obj.seq[0], h->init.nof_symbols == CPNORM_NSYMB?CPNORM:CPEXT,
h->init.cell_id);
return sequence_pbch(&h->obj.seq[0],
h->init.nof_symbols == CPNORM_NSYMB ? CPNORM : CPEXT, h->init.cell_id);
case SCRAMBLING_PDSCH:
for (int ns=0;ns<NSUBFRAMES_X_FRAME;ns++) {
sequence_pdsch(&h->obj.seq[ns], h->init.nrnti, 0, 2*ns, h->init.cell_id, LTE_NSOFT_BITS);
for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) {
sequence_pdsch(&h->obj.seq[ns], h->init.nrnti, 0, 2 * ns, h->init.cell_id,
LTE_NSOFT_BITS);
}
return 0;
case SCRAMBLING_PCFICH:
for (int ns=0;ns<NSUBFRAMES_X_FRAME;ns++) {
sequence_pcfich(&h->obj.seq[ns], 2*ns, h->init.cell_id);
for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) {
sequence_pcfich(&h->obj.seq[ns], 2 * ns, h->init.cell_id);
}
return 0;
case SCRAMBLING_PDCCH:
for (int ns=0;ns<NSUBFRAMES_X_FRAME;ns++) {
sequence_pdcch(&h->obj.seq[ns], 2*ns, h->init.cell_id, LTE_NSOFT_BITS);
for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) {
sequence_pdcch(&h->obj.seq[ns], 2 * ns, h->init.cell_id, LTE_NSOFT_BITS);
}
return 0;
case SCRAMBLING_PMCH:
@ -137,7 +137,7 @@ int scrambling_work(scrambling_hl* hl) {
int scrambling_stop(scrambling_hl* hl) {
int i;
for (i=0;i<NSUBFRAMES_X_FRAME;i++) {
for (i = 0; i < NSUBFRAMES_X_FRAME; i++) {
sequence_free(&hl->obj.seq[i]);
}
return 0;

@ -183,7 +183,7 @@ int pss_synch_set_N_id_2(pss_synch_t *q, int N_id_2) {
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(PSS_LEN_FREQ - 1, COMPLEX_2_COMPLEX, BACKWARD, &plan)) {
if (dft_plan(&plan, PSS_LEN_FREQ - 1, COMPLEX_2_COMPLEX, BACKWARD)) {
return -1;
}
plan.options = DFT_MIRROR_PRE | DFT_DC_OFFSET;

@ -42,7 +42,7 @@ void generate_N_id_1_table(int table[30][30]);
int sss_synch_init(sss_synch_t *q) {
bzero(q, sizeof(sss_synch_t));
if (dft_plan(SSS_DFT_LEN, COMPLEX_2_COMPLEX, FORWARD, &q->dftp_input)) {
if (dft_plan(&q->dftp_input, SSS_DFT_LEN, COMPLEX_2_COMPLEX, FORWARD)) {
return -1;
}
generate_N_id_1_table(q->N_id_1_table);

@ -29,6 +29,8 @@
#include <stdint.h>
#include <stdio.h>
#include "lte/utils/bit.h"
void bit_pack(uint32_t value, char **bits, int nof_bits)
{
int i;

@ -44,13 +44,13 @@ int conv_fft_cc_init(conv_fft_cc_t *state, int input_len, int filter_len) {
if (!state->input_fft || !state->filter_fft || !state->output_fft) {
return -1;
}
if (dft_plan(state->output_len,COMPLEX_2_COMPLEX,FORWARD,&state->input_plan)) {
if (dft_plan(&state->input_plan,state->output_len,COMPLEX_2_COMPLEX,FORWARD)) {
return -2;
}
if (dft_plan(state->output_len,COMPLEX_2_COMPLEX,FORWARD,&state->filter_plan)) {
if (dft_plan(&state->filter_plan,state->output_len,COMPLEX_2_COMPLEX,FORWARD)) {
return -3;
}
if (dft_plan(state->output_len,COMPLEX_2_COMPLEX,BACKWARD,&state->output_plan)) {
if (dft_plan(&state->output_plan,state->output_len,COMPLEX_2_COMPLEX,BACKWARD)) {
return -4;
}
return 0;

@ -36,40 +36,44 @@
#define div(a,b) ((a-1)/b+1)
int dft_plan_multi(const int *dft_points, dft_mode_t *modes, dft_dir_t *dirs,
int nof_plans, dft_plan_t *plans) {
int dft_plan_vector(dft_plan_t *plans, const int *dft_points,
dft_mode_t *modes, dft_dir_t *dirs, int nof_plans) {
int i;
for (i=0;i<nof_plans;i++) {
if (dft_plan(dft_points[i],modes[i],dirs[i], &plans[i])) {
if (dft_plan(&plans[i], dft_points[i],modes[i],dirs[i])) {
return -1;
}
}
return 0;
}
int dft_plan_multi_c2c(const int *dft_points, dft_dir_t dir, int nof_plans, dft_plan_t *plans) {
int dft_plan_multi_c2c(dft_plan_t *plans, const int *dft_points,
dft_dir_t dir, int nof_plans) {
int i;
for (i=0;i<nof_plans;i++) {
if (dft_plan(dft_points[i],COMPLEX_2_COMPLEX,dir,&plans[i])) {
if (dft_plan(&plans[i],dft_points[i],COMPLEX_2_COMPLEX,dir)) {
return -1;
}
}
return 0;
}
int dft_plan_multi_c2r(const int *dft_points, dft_dir_t dir, int nof_plans, dft_plan_t *plans) {
int dft_plan_multi_c2r(dft_plan_t *plans, const int *dft_points,
dft_dir_t dir, int nof_plans) {
int i;
for (i=0;i<nof_plans;i++) {
if (dft_plan(dft_points[i],COMPLEX_2_REAL,dir,&plans[i])) {
if (dft_plan(&plans[i], dft_points[i],COMPLEX_2_REAL,dir)) {
return -1;
}
}
return 0;
}
int dft_plan_multi_r2r(const int *dft_points, dft_dir_t dir, int nof_plans, dft_plan_t *plans) {
int dft_plan_multi_r2r(dft_plan_t *plans, const int *dft_points,
dft_dir_t dir, int nof_plans) {
int i;
for (i=0;i<nof_plans;i++) {
if (dft_plan(dft_points[i],REAL_2_REAL,dir,&plans[i])) {
if (dft_plan(&plans[i], dft_points[i],REAL_2_REAL,dir)) {
return -1;
}
}
@ -77,21 +81,22 @@ int dft_plan_multi_r2r(const int *dft_points, dft_dir_t dir, int nof_plans, dft_
}
int dft_plan(const int dft_points, dft_mode_t mode, dft_dir_t dir, dft_plan_t *plan) {
int dft_plan(dft_plan_t *plan, const int dft_points,
dft_mode_t mode, dft_dir_t dir) {
switch(mode) {
case COMPLEX_2_COMPLEX:
if (dft_plan_c2c(dft_points,dir,plan)) {
if (dft_plan_c2c(plan,dft_points,dir)) {
return -1;
}
break;
case REAL_2_REAL:
if (dft_plan_r2r(dft_points,dir,plan)) {
if (dft_plan_r2r(plan,dft_points,dir)) {
return -1;
}
break;
case COMPLEX_2_REAL:
if (dft_plan_c2r(dft_points,dir,plan)) {
if (dft_plan_c2r(plan,dft_points,dir)) {
return -1;
}
break;
@ -104,7 +109,7 @@ static void allocate(dft_plan_t *plan, int size_in, int size_out, int len) {
plan->out = fftwf_malloc(size_out*len);
}
int dft_plan_c2c(const int dft_points, dft_dir_t dir, dft_plan_t *plan) {
int dft_plan_c2c(dft_plan_t *plan, const int dft_points, dft_dir_t dir) {
int sign;
sign = (dir == FORWARD) ? FFTW_FORWARD : FFTW_BACKWARD;
allocate(plan,sizeof(fftwf_complex),sizeof(fftwf_complex), dft_points);
@ -120,7 +125,7 @@ int dft_plan_c2c(const int dft_points, dft_dir_t dir, dft_plan_t *plan) {
return 0;
}
int dft_plan_r2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan) {
int dft_plan_r2r(dft_plan_t *plan, const int dft_points, dft_dir_t dir) {
int sign;
sign = (dir == FORWARD) ? FFTW_R2HC : FFTW_HC2R;
@ -137,8 +142,8 @@ int dft_plan_r2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan) {
return 0;
}
int dft_plan_c2r(const int dft_points, dft_dir_t dir, dft_plan_t *plan) {
if (dft_plan_c2c(dft_points, dir, plan)) {
int dft_plan_c2r(dft_plan_t *plan, const int dft_points, dft_dir_t dir) {
if (dft_plan_c2c(plan, dft_points, dir)) {
return -1;
}
plan->mode = COMPLEX_2_REAL;

Loading…
Cancel
Save