diff --git a/lib/src/phy/ch_estimation/chest_dl.c b/lib/src/phy/ch_estimation/chest_dl.c index 5435709bf..839e5197d 100644 --- a/lib/src/phy/ch_estimation/chest_dl.c +++ b/lib/src/phy/ch_estimation/chest_dl.c @@ -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; } diff --git a/lib/src/phy/ch_estimation/refsignal_dl.c b/lib/src/phy/ch_estimation/refsignal_dl.c index 052089a00..f25154c2e 100644 --- a/lib/src/phy/ch_estimation/refsignal_dl.c +++ b/lib/src/phy/ch_estimation/refsignal_dl.c @@ -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; } } } diff --git a/lib/src/phy/ch_estimation/refsignal_dl_nbiot.c b/lib/src/phy/ch_estimation/refsignal_dl_nbiot.c index 85b4dc6c3..0273f43bd 100644 --- a/lib/src/phy/ch_estimation/refsignal_dl_nbiot.c +++ b/lib/src/phy/ch_estimation/refsignal_dl_nbiot.c @@ -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; } } } diff --git a/lib/src/phy/fec/test/viterbi_test.c b/lib/src/phy/fec/test/viterbi_test.c index 73873350d..6776a3827 100644 --- a/lib/src/phy/fec/test/viterbi_test.c +++ b/lib/src/phy/fec/test/viterbi_test.c @@ -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); diff --git a/lib/src/phy/mimo/precoding.c b/lib/src/phy/mimo/precoding.c index f49405fa0..443c9bfc4 100644 --- a/lib/src/phy/mimo/precoding.c +++ b/lib/src/phy/mimo/precoding.c @@ -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; diff --git a/lib/src/phy/mimo/test/precoder_test.c b/lib/src/phy/mimo/test/precoder_test.c index e3d01c9fc..6d2c95313 100644 --- a/lib/src/phy/mimo/test/precoder_test.c +++ b/lib/src/phy/mimo/test/precoder_test.c @@ -19,14 +19,15 @@ * */ +#include +#include +#include #include #include #include #include -#include -#include #include -#include +#include #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) { diff --git a/lib/src/phy/modem/demod_soft.c b/lib/src/phy/modem/demod_soft.c index b2269ca46..c8e6b948d 100644 --- a/lib/src/phy/modem/demod_soft.c +++ b/lib/src/phy/modem/demod_soft.c @@ -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;icell.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];