mirror of https://github.com/pvnis/srsRAN_4G.git
Added CRC. Changed ratematching to FEC directory
parent
887c3a8e80
commit
6fe5a05952
@ -0,0 +1,180 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2014 The libLTE Developers. See the
|
||||||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the libLTE library.
|
||||||
|
*
|
||||||
|
* libLTE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* libLTE is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Lesser General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "lte/fec/rm_turbo.h"
|
||||||
|
|
||||||
|
#define NCOLS 32
|
||||||
|
#define NROWS_MAX NCOLS
|
||||||
|
#define RATE 3
|
||||||
|
|
||||||
|
unsigned char RM_PERM_CC[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_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_turbo_tx(char *input, char *output, int in_len, int out_len) {
|
||||||
|
|
||||||
|
char tmp[RATE * NCOLS * NROWS_MAX];
|
||||||
|
int nrows, ndummy, K_p;
|
||||||
|
|
||||||
|
int i, j, k, s;
|
||||||
|
|
||||||
|
nrows = (int) (in_len / RATE - 1) / NCOLS + 1;
|
||||||
|
if (nrows > NROWS_MAX) {
|
||||||
|
fprintf(stderr, "Input too large. Max input length is %d\n",
|
||||||
|
RATE * NCOLS * NROWS_MAX);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
K_p = nrows * NCOLS;
|
||||||
|
ndummy = K_p - in_len / RATE;
|
||||||
|
if (ndummy < 0) {
|
||||||
|
ndummy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sub-block interleaver 5.1.4.1.1 */
|
||||||
|
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) {
|
||||||
|
tmp[k] = TX_NULL;
|
||||||
|
} else {
|
||||||
|
tmp[k] = input[(i * NCOLS + RM_PERM_CC[j] - ndummy) * 3 + s];
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Bit collection, selection and transmission 5.1.4.1.2 */
|
||||||
|
k = 0;
|
||||||
|
j = 0;
|
||||||
|
while (k < out_len) {
|
||||||
|
if (tmp[j] != TX_NULL) {
|
||||||
|
output[k] = tmp[j];
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
if (j == RATE * K_p) {
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Undoes Convolutional Code Rate Matching.
|
||||||
|
* 3GPP TS 36.212 v10.1.0 section 5.1.4.2
|
||||||
|
*/
|
||||||
|
int rm_turbo_rx(float *input, float *output, int in_len, int out_len) {
|
||||||
|
|
||||||
|
int nrows, ndummy, K_p;
|
||||||
|
int i, j, k;
|
||||||
|
int d_i, d_j;
|
||||||
|
|
||||||
|
float tmp[RATE * NCOLS * NROWS_MAX];
|
||||||
|
|
||||||
|
nrows = (int) (out_len / RATE - 1) / NCOLS + 1;
|
||||||
|
if (nrows > NROWS_MAX) {
|
||||||
|
fprintf(stderr, "Output too large. Max output length is %d\n",
|
||||||
|
RATE * NCOLS * NROWS_MAX);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
K_p = nrows * NCOLS;
|
||||||
|
|
||||||
|
ndummy = K_p - out_len / RATE;
|
||||||
|
if (ndummy < 0) {
|
||||||
|
ndummy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < RATE * K_p; i++) {
|
||||||
|
tmp[i] = RX_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Undo bit collection. Account for dummy bits */
|
||||||
|
k = 0;
|
||||||
|
j = 0;
|
||||||
|
while (k < in_len) {
|
||||||
|
d_i = (j % K_p) / nrows;
|
||||||
|
d_j = (j % K_p) % nrows;
|
||||||
|
|
||||||
|
if (d_j * NCOLS + RM_PERM_CC[d_i] >= ndummy) {
|
||||||
|
if (tmp[j] == RX_NULL) {
|
||||||
|
tmp[j] = input[k];
|
||||||
|
} else if (input[k] != RX_NULL) {
|
||||||
|
tmp[j] += input[k]; /* soft combine LLRs */
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
if (j == RATE * K_p) {
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* interleaving and bit selection */
|
||||||
|
for (i = 0; i < out_len / RATE; i++) {
|
||||||
|
d_i = (i + ndummy) / NCOLS;
|
||||||
|
d_j = (i + ndummy) % NCOLS;
|
||||||
|
for (j = 0; j < RATE; j++) {
|
||||||
|
float o = tmp[K_p * j + RM_PERM_CC_INV[d_j] * nrows + d_i];
|
||||||
|
if (o != RX_NULL) {
|
||||||
|
output[i * RATE + j] = o;
|
||||||
|
} else {
|
||||||
|
output[i * RATE + j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** High-level API */
|
||||||
|
|
||||||
|
int rm_turbo_initialize(rm_turbo_hl* h) {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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->input, hl->output, hl->in_len, hl->ctrl_in.S);
|
||||||
|
hl->out_len = hl->ctrl_in.S;
|
||||||
|
} else {
|
||||||
|
rm_turbo_rx(hl->input, hl->output, hl->in_len, hl->ctrl_in.E);
|
||||||
|
hl->out_len = hl->ctrl_in.E;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rm_turbo_stop(rm_turbo_hl* hl) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,135 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2014 The libLTE Developers. See the
|
||||||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the libLTE library.
|
||||||
|
*
|
||||||
|
* libLTE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* libLTE is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Lesser General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "lte.h"
|
||||||
|
|
||||||
|
int nof_tx_bits=-1, nof_rx_bits=-1;
|
||||||
|
|
||||||
|
void usage(char *prog) {
|
||||||
|
printf("Usage: %s -t nof_tx_bits -r nof_rx_bits\n", prog);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_args(int argc, char **argv) {
|
||||||
|
int opt;
|
||||||
|
while ((opt = getopt(argc, argv, "tr")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 't':
|
||||||
|
nof_tx_bits = atoi(argv[optind]);
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
nof_rx_bits = atoi(argv[optind]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nof_tx_bits == -1) {
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
if (nof_rx_bits == -1) {
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int i;
|
||||||
|
char *bits, *rm_bits;
|
||||||
|
float *rm_symbols, *unrm_symbols;
|
||||||
|
int nof_errors;
|
||||||
|
|
||||||
|
parse_args(argc, argv);
|
||||||
|
|
||||||
|
bits = malloc(sizeof(char) * nof_tx_bits);
|
||||||
|
if (!bits) {
|
||||||
|
perror("malloc");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
rm_bits = malloc(sizeof(char) * nof_rx_bits);
|
||||||
|
if (!rm_bits) {
|
||||||
|
perror("malloc");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
rm_symbols = malloc(sizeof(float) * nof_rx_bits);
|
||||||
|
if (!rm_symbols) {
|
||||||
|
perror("malloc");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
unrm_symbols = malloc(sizeof(float) * nof_tx_bits);
|
||||||
|
if (!unrm_symbols) {
|
||||||
|
perror("malloc");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0;i<nof_tx_bits;i++) {
|
||||||
|
bits[i] = rand()%2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rm_conv_tx(bits, rm_bits, nof_tx_bits, nof_rx_bits)) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0;i<nof_rx_bits;i++) {
|
||||||
|
rm_symbols[i] = rm_bits[i]?1:-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rm_conv_rx(rm_symbols, unrm_symbols, nof_rx_bits, nof_tx_bits)) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
nof_errors = 0;
|
||||||
|
for (i=0;i<nof_tx_bits;i++) {
|
||||||
|
if ((unrm_symbols[i] > 0) != bits[i]) {
|
||||||
|
nof_errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nof_rx_bits > nof_tx_bits) {
|
||||||
|
if (nof_errors) {
|
||||||
|
printf("nof_errors=%d\n", nof_errors);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(bits);
|
||||||
|
free(rm_bits);
|
||||||
|
free(rm_symbols);
|
||||||
|
free(unrm_symbols);
|
||||||
|
|
||||||
|
printf("Ok\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
@ -1,33 +0,0 @@
|
|||||||
#
|
|
||||||
# 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/.
|
|
||||||
#
|
|
||||||
|
|
||||||
########################################################################
|
|
||||||
# RATEMATCHING TEST
|
|
||||||
########################################################################
|
|
||||||
|
|
||||||
ADD_EXECUTABLE(rm_conv_test rm_conv_test.c)
|
|
||||||
TARGET_LINK_LIBRARIES(rm_conv_test lte)
|
|
||||||
|
|
||||||
ADD_TEST(rm_conv_test_1 rm_conv_test -t 480 -r 1920)
|
|
||||||
ADD_TEST(rm_conv_test_2 rm_conv_test -t 1920 -r 480)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue