Fixed soft demodulator

This commit is contained in:
Guillem Foreman 2019-07-16 17:01:20 +02:00 committed by Andre Puschmann
parent feafec2725
commit 2574de4d2d
2 changed files with 57 additions and 47 deletions

View File

@ -413,51 +413,66 @@ void demod_64qam_lte_b(const cf_t *symbols, int8_t *llr, int nsymbols)
void demod_256qam_lte(const cf_t* symbols, float* llr, int nsymbols) void demod_256qam_lte(const cf_t* symbols, float* llr, int nsymbols)
{ {
for (int i = 0; i < nsymbols; i++) { for (int i = 0; i < nsymbols; i++) {
float real = crealf(symbols[i]); float real = -__real__ symbols[i];
float imag = cimagf(symbols[i]); float imag = -__imag__ symbols[i];
*(llr++) = real;
llr[8 * i + 0] = -real; *(llr++) = imag;
llr[8 * i + 1] = -imag; real = fabsf(real) - 8.0f / sqrtf(170.0f);
llr[8 * i + 2] = fabsf(real) - 8 / sqrt(170); imag = fabsf(imag) - 8.0f / sqrtf(170.0f);
llr[8 * i + 3] = fabsf(imag) - 8 / sqrt(170); *(llr++) = real;
llr[8 * i + 4] = fabsf(llr[8 * i + 2]) - 4 / sqrt(170); *(llr++) = imag;
llr[8 * i + 5] = fabsf(llr[8 * i + 3]) - 4 / sqrt(170); real = fabsf(real) - 4.0f / sqrtf(170.0f);
llr[8 * i + 6] = fabsf(llr[8 * i + 4]) - 2 / sqrt(170); imag = fabsf(imag) - 4.0f / sqrtf(170.0f);
llr[8 * i + 7] = fabsf(llr[8 * i + 5]) - 2 / sqrt(170); *(llr++) = real;
*(llr++) = imag;
real = fabsf(real) - 2.0f / sqrtf(170.0f);
imag = fabsf(imag) - 2.0f / sqrtf(170.0f);
*(llr++) = real;
*(llr++) = imag;
} }
} }
void demod_256qam_lte_b(const cf_t* symbols, int8_t* llr, int nsymbols) void demod_256qam_lte_b(const cf_t* symbols, int8_t* llr, int nsymbols)
{ {
for (int i = 0; i < nsymbols; i++) { for (int i = 0; i < nsymbols; i++) {
float real = SCALE_BYTE_CONV_QAM256 * crealf(symbols[i]); float real = -__real__ symbols[i];
float imag = SCALE_BYTE_CONV_QAM256 * cimagf(symbols[i]); float imag = -__imag__ symbols[i];
*(llr++) = SCALE_BYTE_CONV_QAM256 * real;
llr[8 * i + 0] = -real; *(llr++) = SCALE_BYTE_CONV_QAM256 * imag;
llr[8 * i + 1] = -imag; real = fabsf(real) - 8.0f / sqrtf(170.0f);
llr[8 * i + 2] = fabsf(real) - SCALE_BYTE_CONV_QAM256 * 8 / sqrt(170); imag = fabsf(imag) - 8.0f / sqrtf(170.0f);
llr[8 * i + 3] = fabsf(imag) - SCALE_BYTE_CONV_QAM256 * 8 / sqrt(170); *(llr++) = SCALE_BYTE_CONV_QAM256 * real;
llr[8 * i + 4] = fabsf(llr[8 * i + 2]) - SCALE_BYTE_CONV_QAM256 * 4 / sqrt(170); *(llr++) = SCALE_BYTE_CONV_QAM256 * imag;
llr[8 * i + 5] = fabsf(llr[8 * i + 3]) - SCALE_BYTE_CONV_QAM256 * 4 / sqrt(170); real = fabsf(real) - 4.0f / sqrtf(170.0f);
llr[8 * i + 6] = fabsf(llr[8 * i + 4]) - SCALE_BYTE_CONV_QAM256 * 2 / sqrt(170); imag = fabsf(imag) - 4.0f / sqrtf(170.0f);
llr[8 * i + 7] = fabsf(llr[8 * i + 5]) - SCALE_BYTE_CONV_QAM256 * 2 / sqrt(170); *(llr++) = SCALE_BYTE_CONV_QAM256 * real;
*(llr++) = SCALE_BYTE_CONV_QAM256 * imag;
real = fabsf(real) - 2.0f / sqrtf(170.0f);
imag = fabsf(imag) - 2.0f / sqrtf(170.0f);
*(llr++) = SCALE_BYTE_CONV_QAM256 * real;
*(llr++) = SCALE_BYTE_CONV_QAM256 * imag;
} }
} }
void demod_256qam_lte_s(const cf_t* symbols, short* llr, int nsymbols) void demod_256qam_lte_s(const cf_t* symbols, short* llr, int nsymbols)
{ {
for (int i = 0; i < nsymbols; i++) { for (int i = 0; i < nsymbols; i++) {
float real = SCALE_SHORT_CONV_QAM256 * crealf(symbols[i]); float real = -__real__ symbols[i];
float imag = SCALE_SHORT_CONV_QAM256 * cimagf(symbols[i]); float imag = -__imag__ symbols[i];
*(llr++) = SCALE_SHORT_CONV_QAM256 * real;
llr[8 * i + 0] = -real; *(llr++) = SCALE_SHORT_CONV_QAM256 * imag;
llr[8 * i + 1] = -imag; real = fabsf(real) - 8.0f / sqrtf(170.0f);
llr[8 * i + 2] = fabsf(real) - SCALE_SHORT_CONV_QAM256 * 8 / sqrt(170); imag = fabsf(imag) - 8.0f / sqrtf(170.0f);
llr[8 * i + 3] = fabsf(imag) - SCALE_SHORT_CONV_QAM256 * 8 / sqrt(170); *(llr++) = SCALE_SHORT_CONV_QAM256 * real;
llr[8 * i + 4] = fabsf(llr[8 * i + 2]) - SCALE_SHORT_CONV_QAM256 * 4 / sqrt(170); *(llr++) = SCALE_SHORT_CONV_QAM256 * imag;
llr[8 * i + 5] = fabsf(llr[8 * i + 3]) - SCALE_SHORT_CONV_QAM256 * 4 / sqrt(170); real = fabsf(real) - 4.0f / sqrtf(170.0f);
llr[8 * i + 6] = fabsf(llr[8 * i + 4]) - SCALE_SHORT_CONV_QAM256 * 2 / sqrt(170); imag = fabsf(imag) - 4.0f / sqrtf(170.0f);
llr[8 * i + 7] = fabsf(llr[8 * i + 5]) - SCALE_SHORT_CONV_QAM256 * 2 / sqrt(170); *(llr++) = SCALE_SHORT_CONV_QAM256 * real;
*(llr++) = SCALE_SHORT_CONV_QAM256 * imag;
real = fabsf(real) - 2.0f / sqrtf(170.0f);
imag = fabsf(imag) - 2.0f / sqrtf(170.0f);
*(llr++) = SCALE_SHORT_CONV_QAM256 * real;
*(llr++) = SCALE_SHORT_CONV_QAM256 * imag;
} }
} }

View File

@ -82,11 +82,12 @@ void parse_args(int argc, char **argv) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int ret = SRSLTE_SUCCESS;
int i; int i;
srslte_modem_table_t mod; srslte_modem_table_t mod;
uint8_t *input, *input_bytes, *output; uint8_t *input, *input_bytes, *output;
cf_t *symbols, *symbols_bytes; cf_t *symbols, *symbols_bytes;
float *llr, *llr2; float* llr;
parse_args(argc, argv); parse_args(argc, argv);
@ -137,12 +138,6 @@ int main(int argc, char **argv) {
exit(-1); exit(-1);
} }
llr2 = srslte_vec_malloc(sizeof(float) * num_bits);
if (!llr2) {
perror("malloc");
exit(-1);
}
/* generate random data */ /* generate random data */
for (i=0;i<num_bits;i++) { for (i=0;i<num_bits;i++) {
input[i] = rand()%2; input[i] = rand()%2;
@ -177,26 +172,27 @@ int main(int argc, char **argv) {
exit(-1); exit(-1);
} }
} }
printf("Symbols OK\n");
bzero(llr, sizeof(float) * num_bits / mod.nbits_x_symbol);
printf("Symbols OK\n");
/* demodulate */ /* demodulate */
gettimeofday(&x, NULL); gettimeofday(&x, NULL);
srslte_demod_soft_demodulate(modulation, symbols, llr, num_bits / mod.nbits_x_symbol); srslte_demod_soft_demodulate(modulation, symbols, llr, num_bits / mod.nbits_x_symbol);
gettimeofday(&y, NULL); gettimeofday(&y, NULL);
printf("\nElapsed time [us]: %ld\n", y.tv_usec - x.tv_usec); printf("\nElapsed time [us]: %ld\n", y.tv_usec - x.tv_usec);
for (i=0;i<num_bits;i++) { for (i=0;i<num_bits;i++) {
output[i] = llr[i]>=0 ? 1 : 0; output[i] = llr[i]>=0 ? 1 : 0;
} }
/* check errors */ /* check errors */
for (i=0;i<num_bits;i++) { for (i = 0; i < num_bits && ret == SRSLTE_SUCCESS; i++) {
if (input[i] != output[i]) { if (input[i] != output[i]) {
ERROR("Error in bit %d\n", i); ERROR("Error in bit %d\n", i);
exit(-1); ret = SRSLTE_ERROR;
} }
} }
free(llr2);
free(llr); free(llr);
free(symbols); free(symbols);
free(symbols_bytes); free(symbols_bytes);
@ -206,6 +202,5 @@ int main(int argc, char **argv) {
srslte_modem_table_free(&mod); srslte_modem_table_free(&mod);
printf("Ok\n"); exit(ret);
exit(0);
} }