Change M_SQRT2 and M_SQRT1_2 instead of sqrt(2) and 1/sqrt(2)

This commit is contained in:
Xavier Arteaga 2019-11-28 11:42:48 +01:00 committed by Xavier Arteaga
parent 6d4f746a61
commit f75d0e5b26
9 changed files with 57 additions and 52 deletions

View File

@ -393,7 +393,7 @@ static float estimate_noise_pss(srslte_chest_dl_t *q, cf_t *input, cf_t *ce)
srslte_vec_sub_ccc(q->tmp_pss_noisy, q->tmp_pss, q->tmp_pss_noisy, SRSLTE_PSS_LEN);
/* Compute average power */
float power = q->cell.nof_ports*srslte_vec_avg_power_cf(q->tmp_pss_noisy, SRSLTE_PSS_LEN)/sqrt(2);
float power = q->cell.nof_ports * srslte_vec_avg_power_cf(q->tmp_pss_noisy, SRSLTE_PSS_LEN) * M_SQRT1_2;
return power;
}

View File

@ -103,10 +103,11 @@ int srslte_refsignal_cs_set_cell(srslte_refsignal_t* q, srslte_cell_t cell)
/* Compute signal */
for (uint32_t i = 0; i < 2 * q->cell.nof_prb; i++) {
uint32_t idx = SRSLTE_REFSIGNAL_PILOT_IDX(i, (ns % 2) * nsymbols + l, q->cell);
mp = i + SRSLTE_MAX_PRB - cell.nof_prb;
/* save signal */
q->pilots[p][ns / 2][SRSLTE_REFSIGNAL_PILOT_IDX(i, (ns % 2) * nsymbols + l, q->cell)] =
(1 - 2 * (float)seq.c[2 * mp]) / sqrt(2) + _Complex_I * (1 - 2 * (float)seq.c[2 * mp + 1]) / sqrt(2);
__real__ q->pilots[p][ns / 2][idx] = (1 - 2 * (float)seq.c[2 * mp + 0]) * M_SQRT1_2;
__imag__ q->pilots[p][ns / 2][idx] = (1 - 2 * (float)seq.c[2 * mp + 1]) * M_SQRT1_2;
}
}
}
@ -384,10 +385,10 @@ int srslte_refsignal_mbsfn_gen_seq(srslte_refsignal_t* q, srslte_cell_t cell, ui
c_init = 512 * (7 * (slot + 1) + lp + 1) * (2 * N_mbsfn_id + 1) + N_mbsfn_id;
srslte_sequence_set_LTE_pr(&seq_mbsfn, SRSLTE_MAX_PRB * 20, c_init);
for (i = 0; i < 6 * q->cell.nof_prb; i++) {
uint32_t idx = SRSLTE_REFSIGNAL_PILOT_IDX_MBSFN(i, l, q->cell);
mp = i + 3 * (SRSLTE_MAX_PRB - cell.nof_prb);
q->pilots[p][ns][SRSLTE_REFSIGNAL_PILOT_IDX_MBSFN(i, l, q->cell)] =
(1 - 2 * (float)seq_mbsfn.c[2 * mp]) / sqrt(2) +
_Complex_I * (1 - 2 * (float)seq_mbsfn.c[2 * mp + 1]) / sqrt(2);
__real__ q->pilots[p][ns][idx] = (1 - 2 * (float)seq_mbsfn.c[2 * mp + 0]) * M_SQRT1_2;
__imag__ q->pilots[p][ns][idx] = (1 - 2 * (float)seq_mbsfn.c[2 * mp + 1]) * M_SQRT1_2;
}
}
}

View File

@ -162,8 +162,8 @@ int srslte_refsignal_dl_nbiot_set_cell(srslte_refsignal_dl_nbiot_t* q, srslte_nb
i,
nsymbols,
l);
q->pilots[p][ns / 2][idx] =
(1 - 2 * (float)seq.c[2 * mp]) / sqrt(2) + _Complex_I * (1 - 2 * (float)seq.c[2 * mp + 1]) / sqrt(2);
__real__ q->pilots[p][ns / 2][idx] = (1 - 2 * (float)seq.c[2 * mp + 0]) * M_SQRT1_2;
__imag__ q->pilots[p][ns / 2][idx] = (1 - 2 * (float)seq.c[2 * mp + 1]) * M_SQRT1_2;
}
}
}

View File

@ -198,7 +198,7 @@ int main(int argc, char **argv) {
/* uncoded BER */
for (j = 0; j < frame_length; j++) {
llr[j] = data_tx[j] ? sqrt(2) : -sqrt(2);
llr[j] = data_tx[j] ? M_SQRT2 : -M_SQRT2;
}
srslte_ch_awgn_f(llr, llr, varunc[i], frame_length);
@ -206,7 +206,7 @@ int main(int argc, char **argv) {
srslte_convcoder_encode(&cod, data_tx, symbols, frame_length);
for (j = 0; j < coded_length; j++) {
llr[j] = symbols[j] ? sqrt(2) : -sqrt(2);
llr[j] = symbols[j] ? M_SQRT2 : -M_SQRT2;
}
srslte_ch_awgn_f(llr, llr, var[i], coded_length);

View File

@ -376,8 +376,8 @@ int srslte_predecoding_diversity_gen_(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_
x1 += (-h10 * conj(r0) + conj(h01) * r1);
}
hh *= scaling;
x[0][i] = x0 / hh * sqrt(2);
x[1][i] = x1 / hh * sqrt(2);
x[0][i] = x0 / hh * M_SQRT2;
x[1][i] = x1 / hh * M_SQRT2;
}
return i;
} else if (nof_ports == 4) {
@ -410,10 +410,10 @@ int srslte_predecoding_diversity_gen_(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_
hh02 *= scaling;
hh13 *= scaling;
x[0][i] = x0 / hh02 * sqrt(2);
x[1][i] = x1 / hh02 * sqrt(2);
x[2][i] = x2 / hh13 * sqrt(2);
x[3][i] = x3 / hh13 * sqrt(2);
x[0][i] = x0 / hh02 * M_SQRT2;
x[1][i] = x1 / hh02 * M_SQRT2;
x[2][i] = x2 / hh13 * M_SQRT2;
x[3][i] = x3 / hh13 * M_SQRT2;
}
return i;
} else {
@ -444,8 +444,8 @@ int srslte_predecoding_diversity2_sse(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_
const float *yPtr1 = (const float*) y[1];
__m128 conjugator = _mm_setr_ps(0, -0.f, 0, -0.f);
__m128 sqrt2 = _mm_set1_ps(sqrtf(2)/scaling);
__m128 sqrt2 = _mm_set1_ps(M_SQRT2 / scaling);
__m128 h0Val_00, h0Val_10, h1Val_00, h1Val_10, h000, h00conj0, h010, h01conj0, h100, h110;
__m128 h0Val_01, h0Val_11, h1Val_01, h1Val_11, h001, h00conj1, h011, h01conj1, h101, h111;
__m128 hh, hhshuf, hhsum, hhadd;
@ -592,8 +592,8 @@ int srslte_predecoding_diversity_csi(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_M
csi[0][2*i + 1] = hh;
hh *= scaling;
x[0][i] = x0 / hh * sqrt(2);
x[1][i] = x1 / hh * sqrt(2);
x[0][i] = x0 / hh * M_SQRT2;
x[1][i] = x1 / hh * M_SQRT2;
}
return i;
} else if (nof_ports == 4) {
@ -650,10 +650,10 @@ int srslte_predecoding_diversity_csi(cf_t *y[SRSLTE_MAX_PORTS], cf_t *h[SRSLTE_M
csi[0][4 * i + 2] = a2 / nof_rxant;
csi[0][4 * i + 3] = a3 / nof_rxant;
x[0][i] = x0 / a0 * sqrtf(2.0f);
x[1][i] = x1 / a1 * sqrtf(2.0f);
x[2][i] = x2 / a2 * sqrtf(2.0f);
x[3][i] = x3 / a3 * sqrtf(2.0f);
x[0][i] = x0 / a0 * M_SQRT2;
x[1][i] = x1 / a1 * M_SQRT2;
x[2][i] = x2 / a2 * M_SQRT2;
x[3][i] = x3 / a3 * M_SQRT2;
}
return i;
} else {
@ -1856,11 +1856,11 @@ int srslte_precoding_diversity(cf_t *x[SRSLTE_MAX_LAYERS], cf_t *y[SRSLTE_MAX_PO
y[1][2 * i + 1] = conjf(x[0][i]);
}
// normalize
srslte_vec_sc_prod_cfc(y[0], scaling/sqrtf(2), y[0], 2*nof_symbols);
srslte_vec_sc_prod_cfc(y[1], scaling/sqrtf(2), y[1], 2*nof_symbols);
srslte_vec_sc_prod_cfc(y[0], scaling * M_SQRT1_2, y[0], 2 * nof_symbols);
srslte_vec_sc_prod_cfc(y[1], scaling * M_SQRT1_2, y[1], 2 * nof_symbols);
return 2 * i;
} else if (nof_ports == 4) {
scaling /= sqrtf(2);
scaling /= M_SQRT2;
//int m_ap = (nof_symbols%4)?(nof_symbols*4-2):nof_symbols*4;
int m_ap = 4 * nof_symbols;
@ -1987,7 +1987,7 @@ int srslte_precoding_multiplex(cf_t *x[SRSLTE_MAX_LAYERS], cf_t *y[SRSLTE_MAX_PO
int i = 0;
if (nof_ports == 2) {
if (nof_layers == 1) {
scaling /= sqrtf(2.0f);
scaling *= M_SQRT1_2;
switch(codebook_idx) {
case 0:
srslte_vec_sc_prod_cfc(x[0], scaling, y[0], nof_symbols);
@ -2015,7 +2015,7 @@ int srslte_precoding_multiplex(cf_t *x[SRSLTE_MAX_LAYERS], cf_t *y[SRSLTE_MAX_PO
} else if (nof_layers == 2) {
switch(codebook_idx) {
case 0:
scaling /= sqrtf(2.0f);
scaling *= M_SQRT1_2;
srslte_vec_sc_prod_cfc(x[0], scaling, y[0], nof_symbols);
srslte_vec_sc_prod_cfc(x[1], scaling, y[1], nof_symbols);
break;

View File

@ -19,14 +19,15 @@
*
*/
#include <math.h>
#include <srslte/phy/utils/random.h>
#include <stdbool.h>
#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 <unistd.h>
#include "srslte/srslte.h"
#include "srslte/phy/channel/ch_awgn.h"
@ -250,11 +251,14 @@ int main(int argc, char** argv)
}
/* Generate source random data */
srslte_random_t random_gen = srslte_random_init(0);
for (i = 0; i < nof_layers; i++) {
for (j = 0; j < nof_symbols; j++) {
x[i][j] = (2 * (rand() % 2) - 1 + (2 * (rand() % 2) - 1) * _Complex_I) / sqrt(2);
__real__ x[i][j] = (2 * srslte_random_uniform_int_dist(random_gen, 0, 1) - 1) * M_SQRT1_2;
__imag__ x[i][j] = (2 * srslte_random_uniform_int_dist(random_gen, 0, 1) - 1) * M_SQRT1_2;
}
}
srslte_random_free(random_gen);
/* Execute Precoding (Tx) */
if (srslte_precoding_type(x, y, nof_layers, nof_tx_ports, codebook_idx, nof_symbols, scaling, type) < 0) {

View File

@ -95,32 +95,32 @@ void demod_16qam_lte_s_sse(const cf_t *symbols, short *llr, int nsymbols);
void demod_bpsk_lte_b(const cf_t *symbols, int8_t *llr, int nsymbols) {
for (int i=0;i<nsymbols;i++) {
llr[i] = (int8_t) -SCALE_BYTE_CONV_QPSK*(crealf(symbols[i]) + cimagf(symbols[i]))/sqrt(2);
llr[i] = (int8_t)(-SCALE_BYTE_CONV_QPSK * (crealf(symbols[i]) + cimagf(symbols[i])) * M_SQRT1_2);
}
}
void demod_bpsk_lte_s(const cf_t *symbols, short *llr, int nsymbols) {
for (int i=0;i<nsymbols;i++) {
llr[i] = (short) -SCALE_SHORT_CONV_QPSK*(crealf(symbols[i]) + cimagf(symbols[i]))/sqrt(2);
llr[i] = (short)(-SCALE_SHORT_CONV_QPSK * (crealf(symbols[i]) + cimagf(symbols[i])) * M_SQRT1_2);
}
}
void demod_bpsk_lte(const cf_t *symbols, float *llr, int nsymbols) {
for (int i=0;i<nsymbols;i++) {
llr[i] = -(crealf(symbols[i]) + cimagf(symbols[i]))/sqrt(2);
llr[i] = -(crealf(symbols[i]) + cimagf(symbols[i])) * M_SQRT1_2;
}
}
void demod_qpsk_lte_b(const cf_t *symbols, int8_t *llr, int nsymbols) {
srslte_vec_convert_fb((const float*) symbols, -SCALE_BYTE_CONV_QPSK*sqrt(2), llr, nsymbols*2);
srslte_vec_convert_fb((const float*)symbols, -SCALE_BYTE_CONV_QPSK * M_SQRT2, llr, nsymbols * 2);
}
void demod_qpsk_lte_s(const cf_t *symbols, short *llr, int nsymbols) {
srslte_vec_convert_fi((const float*) symbols, -SCALE_SHORT_CONV_QPSK*sqrt(2), llr, nsymbols*2);
srslte_vec_convert_fi((const float*)symbols, -SCALE_SHORT_CONV_QPSK * M_SQRT2, llr, nsymbols * 2);
}
void demod_qpsk_lte(const cf_t *symbols, float *llr, int nsymbols) {
srslte_vec_sc_prod_fff((const float*) symbols, -sqrt(2), llr, nsymbols*2);
srslte_vec_sc_prod_fff((const float*)symbols, -M_SQRT2, llr, nsymbols * 2);
}
void demod_16qam_lte(const cf_t *symbols, float *llr, int nsymbols) {

View File

@ -19,23 +19,23 @@
*
*/
#define BPSK_LEVEL 1/sqrt(2)
#define BPSK_LEVEL M_SQRT1_2
#define QPSK_LEVEL 1/sqrt(2)
#define QPSK_LEVEL M_SQRT1_2
#define QAM16_LEVEL_1 1/sqrt(10)
#define QAM16_LEVEL_2 3/sqrt(10)
#define QAM16_LEVEL_1 (1.0f / sqrt(10.0f))
#define QAM16_LEVEL_2 (3.0f / sqrt(10.0f))
#define QAM64_LEVEL_1 1/sqrt(42)
#define QAM64_LEVEL_2 3/sqrt(42)
#define QAM64_LEVEL_3 5/sqrt(42)
#define QAM64_LEVEL_4 7/sqrt(42)
#define QAM64_LEVEL_1 (1.0f / sqrtf(42.0f))
#define QAM64_LEVEL_2 (3.0f / sqrtf(42.0f))
#define QAM64_LEVEL_3 (5.0f / sqrtf(42.0f))
#define QAM64_LEVEL_4 (7.0f / sqrtf(42.0f))
/* HARD DEMODULATION Thresholds, necessary for obtaining the zone of received symbol for optimized LLR approx implementation */
#define QAM16_THRESHOLD 2/sqrt(10)
#define QAM64_THRESHOLD_1 2/sqrt(42)
#define QAM64_THRESHOLD_2 4/sqrt(42)
#define QAM64_THRESHOLD_3 6/sqrt(42)
#define QAM16_THRESHOLD (2.0f / sqrtf(10.0f))
#define QAM64_THRESHOLD_1 (2.0f / sqrtf(42.0f))
#define QAM64_THRESHOLD_2 (4.0f / sqrtf(42.0f))
#define QAM64_THRESHOLD_3 (6.0f / sqrtf(42.0f))
//=========================================//
#define QAM64_LEVEL_x 2/sqrt(42)

View File

@ -522,7 +522,7 @@ static float apply_power_allocation(srslte_pdsch_t* q, srslte_pdsch_cfg_t* cfg,
uint32_t nof_re_symbol = SRSLTE_NRE * q->cell.nof_prb;
/* Set power allocation according to 3GPP 36.213 clause 5.2 Downlink power allocation */
float rho_a = powf(10.0f, cfg->p_a / 20.0f) * ((q->cell.nof_ports == 1) ? 1.0f : sqrtf(2.0f));
float rho_a = powf(10.0f, cfg->p_a / 20.0f) * ((q->cell.nof_ports == 1) ? 1.0f : M_SQRT2);
uint32_t idx0 = (q->cell.nof_ports == 1) ? 0 : 1;
float cell_specific_ratio = pdsch_cfg_cell_specific_ratio_table[idx0][cfg->p_b];