Revert "Review soft demodulator zero check"

This reverts commit b8a9a7fc70.
This commit is contained in:
Xavier Arteaga 2021-04-19 11:06:52 +02:00 committed by Andre Puschmann
parent 0999b271ba
commit 1c1d7e2447
4 changed files with 52 additions and 90 deletions

View File

@ -33,14 +33,4 @@ SRSRAN_API int srsran_demod_soft_demodulate_s(srsran_mod_t modulation, const cf_
SRSRAN_API int srsran_demod_soft_demodulate_b(srsran_mod_t modulation, const cf_t* symbols, int8_t* llr, int nsymbols);
/**
* @brief Soft-demodulates complex symbols into 8-bit LLR. It forces zero symbols produce zero LLRs.
* @param modulation Modulation
* @param symbols Complex symbols
* @param llr 8-bit LLRs
* @param nsymbols Number of symbols
* @return SRSLTE_SUCCESS if the provided pointers are valid, SRSLTE_ERROR code otherwise
*/
SRSRAN_API int srsran_demod_soft_demodulate2_b(srsran_mod_t modulation, const cf_t* symbols, int8_t* llr, int nsymbols);
#endif // SRSRAN_DEMOD_SOFT_H

View File

@ -883,9 +883,6 @@ int srsran_demod_soft_demodulate(srsran_mod_t modulation, const cf_t* symbols, f
int srsran_demod_soft_demodulate_s(srsran_mod_t modulation, const cf_t* symbols, short* llr, int nsymbols)
{
if (symbols == NULL || llr == NULL) {
return SRSRAN_ERROR_INVALID_INPUTS;
}
switch (modulation) {
case SRSRAN_MOD_BPSK:
demod_bpsk_lte_s(symbols, llr, nsymbols);
@ -911,9 +908,6 @@ int srsran_demod_soft_demodulate_s(srsran_mod_t modulation, const cf_t* symbols,
int srsran_demod_soft_demodulate_b(srsran_mod_t modulation, const cf_t* symbols, int8_t* llr, int nsymbols)
{
if (symbols == NULL || llr == NULL) {
return SRSRAN_ERROR_INVALID_INPUTS;
}
switch (modulation) {
case SRSRAN_MOD_BPSK:
demod_bpsk_lte_b(symbols, llr, nsymbols);
@ -932,34 +926,17 @@ int srsran_demod_soft_demodulate_b(srsran_mod_t modulation, const cf_t* symbols,
break;
default:
ERROR("Invalid modulation %d", modulation);
return SRSRAN_ERROR;
}
return SRSRAN_SUCCESS;
}
int srsran_demod_soft_demodulate2_b(srsran_mod_t modulation, const cf_t* symbols, int8_t* llr, int nsymbols)
{
if (symbols == NULL || llr == NULL) {
return SRSRAN_ERROR_INVALID_INPUTS;
}
if (srsran_demod_soft_demodulate_b(modulation, symbols, llr, nsymbols) < SRSRAN_SUCCESS) {
return SRSRAN_ERROR;
return -1;
}
// If the number of bits is 2 or less, this is unnecessary
if (modulation < SRSRAN_MOD_16QAM) {
return SRSRAN_SUCCESS;
}
// Iterate all symbols seeking for zero LLR
uint32_t nof_bits_x_symbol = srsran_mod_bits_x_symbol(modulation);
for (uint32_t i = 0; i < nsymbols; i++) {
if (symbols[i] == 0.0f) {
if (!isnormal(__real__ symbols[i]) || !isnormal(__imag__ symbols[i])) {
for (uint32_t j = 0; j < nof_bits_x_symbol; j++) {
llr[i * nof_bits_x_symbol + j] = 0;
}
}
}
return SRSRAN_SUCCESS;
}
return 0;
}

View File

@ -10,8 +10,11 @@
*
*/
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>
@ -22,7 +25,7 @@ static uint32_t nof_frames = 10;
static uint32_t num_bits = 1000;
static srsran_mod_t modulation = SRSRAN_MOD_NITEMS;
static void usage(char* prog)
void usage(char* prog)
{
printf("Usage: %s [nfv] -m modulation (1: BPSK, 2: QPSK, 4: QAM16, 6: QAM64)\n", prog);
printf("\t-n num_bits [Default %d]\n", num_bits);
@ -30,7 +33,7 @@ static void usage(char* prog)
printf("\t-v srsran_verbose [Default None]\n");
}
static void parse_args(int argc, char** argv)
void parse_args(int argc, char** argv)
{
int opt;
while ((opt = getopt(argc, argv, "nmvf")) != -1) {
@ -79,16 +82,33 @@ static void parse_args(int argc, char** argv)
}
}
float mse_threshold()
{
switch (modulation) {
case SRSRAN_MOD_BPSK:
return 1.0e-6;
case SRSRAN_MOD_QPSK:
return 1.0e-6;
case SRSRAN_MOD_16QAM:
return 0.11;
case SRSRAN_MOD_64QAM:
return 0.19;
case SRSRAN_MOD_256QAM:
return 0.3;
default:
return -1.0f;
}
}
int main(int argc, char** argv)
{
int i;
srsran_modem_table_t mod;
uint8_t* input = NULL;
cf_t* symbols = NULL;
float* llr = NULL;
short* llr_s = NULL;
int8_t* llr_b = NULL;
int8_t* llr_b2 = NULL;
srsran_random_t random_gen = srsran_random_init(0);
uint8_t * input, *output;
cf_t* symbols;
float* llr;
short* llr_s;
int8_t* llr_b;
parse_args(argc, argv);
@ -107,6 +127,11 @@ int main(int argc, char** argv)
perror("malloc");
exit(-1);
}
output = srsran_vec_u8_malloc(num_bits);
if (!output) {
perror("malloc");
exit(-1);
}
symbols = srsran_vec_cf_malloc(num_bits / mod.nbits_x_symbol);
if (!symbols) {
perror("malloc");
@ -131,21 +156,17 @@ int main(int argc, char** argv)
exit(-1);
}
llr_b2 = srsran_vec_i8_malloc(num_bits);
if (!llr_b2) {
perror("malloc");
exit(-1);
}
/* generate random data */
srand(0);
int ret = -1;
struct timeval t[3];
float mean_texec = 0.0f;
float mean_texec_s = 0.0f;
float mean_texec_b = 0.0f;
float mean_texec_b2 = 0.0f;
float mean_texec = 0.0;
float mean_texec_s = 0.0;
float mean_texec_b = 0.0;
for (int n = 0; n < nof_frames; n++) {
for (int i = 0; i < num_bits; i++) {
input[i] = srsran_random_uniform_int_dist(random_gen, 0, 1);
for (i = 0; i < num_bits; i++) {
input[i] = rand() % 2;
}
/* modulate */
@ -179,15 +200,6 @@ int main(int argc, char** argv)
mean_texec_b = SRSRAN_VEC_CMA((float)t[0].tv_usec, mean_texec_b, n - 1);
}
gettimeofday(&t[1], NULL);
srsran_demod_soft_demodulate2_b(modulation, symbols, llr_b2, num_bits / mod.nbits_x_symbol);
gettimeofday(&t[2], NULL);
get_time_interval(t);
if (n > 0) {
mean_texec_b2 = SRSRAN_VEC_CMA((float)t[0].tv_usec, mean_texec_b2, n - 1);
}
if (SRSRAN_VERBOSE_ISDEBUG()) {
printf("bits=");
srsran_vec_fprint_b(stdout, input, num_bits);
@ -203,27 +215,12 @@ int main(int argc, char** argv)
printf("llr_b=");
srsran_vec_fprint_bs(stdout, llr_b, num_bits);
printf("llr_b2=");
srsran_vec_fprint_bs(stdout, llr_b2, num_bits);
}
// Check demodulation errors
for (int j = 0; j < num_bits; j++) {
if (input[j] != (llr[j] > 0 ? 1 : 0)) {
ERROR("Error in bit %d\n", j);
goto clean_exit;
}
if (input[j] != (llr_s[j] > 0 ? 1 : 0)) {
ERROR("Error in bit %d\n", j);
goto clean_exit;
}
if (input[j] != (llr_b[j] > 0 ? 1 : 0)) {
ERROR("Error in bit %d\n", j);
goto clean_exit;
}
if (input[j] != (llr_b2[j] > 0 ? 1 : 0)) {
ERROR("Error in bit %d\n", j);
for (int i = 0; i < num_bits; i++) {
if (input[i] != (llr[i] > 0 ? 1 : 0)) {
printf("Error in bit %d\n", i);
goto clean_exit;
}
}
@ -231,23 +228,21 @@ int main(int argc, char** argv)
ret = 0;
clean_exit:
srsran_random_free(random_gen);
free(llr_b);
free(llr_s);
free(llr);
free(symbols);
free(output);
free(input);
srsran_modem_table_free(&mod);
printf("Mean Throughput: %.2f/%.2f/%.2f/%.2f. Mbps ExTime: %.2f/%.2f/%.2f/%.2f us\n",
printf("Mean Throughput: %.2f/%.2f/%.2f. Mbps ExTime: %.2f/%.2f/%.2f us\n",
num_bits / mean_texec,
num_bits / mean_texec_s,
num_bits / mean_texec_b,
num_bits / mean_texec_b2,
mean_texec,
mean_texec_s,
mean_texec_b,
mean_texec_b2);
mean_texec_b);
exit(ret);
}

View File

@ -458,7 +458,7 @@ static inline int pdsch_nr_decode_codeword(srsran_pdsch_nr_t* q,
// Demodulation
int8_t* llr = (int8_t*)q->b[tb->cw_idx];
if (srsran_demod_soft_demodulate2_b(tb->mod, q->d[tb->cw_idx], llr, tb->nof_re)) {
if (srsran_demod_soft_demodulate_b(tb->mod, q->d[tb->cw_idx], llr, tb->nof_re)) {
return SRSRAN_ERROR;
}