Added amplitude and power conversions to dB and viceversa

master
Xavier Arteaga 5 years ago committed by Xavier Arteaga
parent f75d0e5b26
commit 8dd1c59e18

@ -130,7 +130,8 @@ void sig_int_handler(int signo)
} }
} }
double srslte_rf_set_rx_gain_wrapper(void *h, double f) { float srslte_rf_set_rx_gain_wrapper(void* h, float f)
{
return srslte_rf_set_rx_gain((srslte_rf_t*) h, f); return srslte_rf_set_rx_gain((srslte_rf_t*) h, f);
} }
@ -255,8 +256,7 @@ int main(int argc, char **argv) {
results[i].cell.id, results[i].cell.id,
results[i].cell.nof_prb, results[i].cell.nof_prb,
results[i].cell.nof_ports, results[i].cell.nof_ports,
10*log10(results[i].power)); srslte_convert_power_to_dB(results[i].power));
} }
printf("\nBye\n"); printf("\nBye\n");

@ -999,7 +999,7 @@ int main(int argc, char **argv) {
if (!null_file_sink) { if (!null_file_sink) {
/* Apply AWGN */ /* Apply AWGN */
if (output_file_snr != +INFINITY) { if (output_file_snr != +INFINITY) {
float var = powf(10.0f, -(output_file_snr + 3.0f) / 20.0f); float var = srslte_convert_dB_to_amplitude(-(output_file_snr + 3.0f));
for (int k = 0; k < cell.nof_ports; k++) { for (int k = 0; k < cell.nof_ports; k++) {
srslte_ch_awgn_c(output_buffer[k], output_buffer[k], var, sf_n_samples); srslte_ch_awgn_c(output_buffer[k], output_buffer[k], var, sf_n_samples);
} }

@ -339,17 +339,18 @@ cf_t *sf_buffer[SRSLTE_MAX_PORTS] = {NULL};
#ifndef DISABLE_RF #ifndef DISABLE_RF
int srslte_rf_recv_wrapper(void* h, cf_t* data[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t* t) int srslte_rf_recv_wrapper(void* h, cf_t* data_[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t* t)
{ {
DEBUG(" ---- Receive %d samples ---- \n", nsamples); DEBUG(" ---- Receive %d samples ---- \n", nsamples);
void* ptr[SRSLTE_MAX_PORTS]; void* ptr[SRSLTE_MAX_PORTS];
for (int i = 0; i < SRSLTE_MAX_PORTS; i++) { for (int i = 0; i < SRSLTE_MAX_PORTS; i++) {
ptr[i] = data[i]; ptr[i] = data_[i];
} }
return srslte_rf_recv_with_time_multi(h, ptr, nsamples, true, NULL, NULL); return srslte_rf_recv_with_time_multi(h, ptr, nsamples, true, NULL, NULL);
} }
double srslte_rf_set_rx_gain_th_wrapper_(void *h, double f) { float srslte_rf_set_rx_gain_th_wrapper_(void* h, float f)
{
return srslte_rf_set_rx_gain_th((srslte_rf_t*)h, f); return srslte_rf_set_rx_gain_th((srslte_rf_t*)h, f);
} }
@ -879,7 +880,7 @@ int main(int argc, char **argv) {
if (sf_idx == 5) { if (sf_idx == 5) {
float gain = prog_args.rf_gain; float gain = prog_args.rf_gain;
if (gain < 0) { if (gain < 0) {
gain = 10 * log10(srslte_agc_get_gain(&ue_sync.agc)); gain = srslte_convert_power_to_dB(srslte_agc_get_gain(&ue_sync.agc));
} }
/* Print transmission scheme */ /* Print transmission scheme */
@ -1051,7 +1052,7 @@ void *plot_thread_run(void *arg) {
uint32_t nof_symbols = pdsch_cfg.grant.nof_re; uint32_t nof_symbols = pdsch_cfg.grant.nof_re;
if (!prog_args.disable_plots_except_constellation) { if (!prog_args.disable_plots_except_constellation) {
for (i = 0; i < nof_re; i++) { for (i = 0; i < nof_re; i++) {
tmp_plot[i] = 20 * log10f(cabsf(ue_dl.sf_symbols[0][i])); tmp_plot[i] = srslte_convert_amplitude_to_dB(cabsf(ue_dl.sf_symbols[0][i]));
if (isinf(tmp_plot[i])) { if (isinf(tmp_plot[i])) {
tmp_plot[i] = -80; tmp_plot[i] = -80;
} }
@ -1060,7 +1061,7 @@ void *plot_thread_run(void *arg) {
bzero(tmp_plot2, sizeof(float) * sz); bzero(tmp_plot2, sizeof(float) * sz);
int g = (sz - 12 * ue_dl.cell.nof_prb) / 2; int g = (sz - 12 * ue_dl.cell.nof_prb) / 2;
for (i = 0; i < 12 * ue_dl.cell.nof_prb; i++) { for (i = 0; i < 12 * ue_dl.cell.nof_prb; i++) {
tmp_plot2[g + i] = 20 * log10(cabs(ue_dl.chest_res.ce[0][0][i])); tmp_plot2[g + i] = srslte_convert_amplitude_to_dB(cabs(ue_dl.chest_res.ce[0][0][i]));
if (isinf(tmp_plot2[g + i])) { if (isinf(tmp_plot2[g + i])) {
tmp_plot2[g + i] = -80; tmp_plot2[g + i] = -80;
} }

@ -51,7 +51,7 @@ public:
virtual void set_tx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) = 0; virtual void set_tx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) = 0;
virtual void set_rx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) = 0; virtual void set_rx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) = 0;
virtual double set_rx_gain_th(const float& gain) = 0; virtual float set_rx_gain_th(const float& gain) = 0;
virtual void set_rx_gain(const uint32_t& radio_idx, const float& gain) = 0; virtual void set_rx_gain(const uint32_t& radio_idx, const float& gain) = 0;
virtual void set_tx_srate(const uint32_t& radio_idx, const double& srate) = 0; virtual void set_tx_srate(const uint32_t& radio_idx, const double& srate) = 0;
virtual void set_rx_srate(const uint32_t& radio_idx, const double& srate) = 0; virtual void set_rx_srate(const uint32_t& radio_idx, const double& srate) = 0;

@ -47,14 +47,14 @@ typedef enum SRSLTE_API {
typedef struct SRSLTE_API{ typedef struct SRSLTE_API{
float bandwidth; float bandwidth;
double gain; float gain;
double min_gain; float min_gain;
double max_gain; float max_gain;
float y_out; float y_out;
bool lock; bool lock;
bool isfirst; bool isfirst;
void* uhd_handler; void* uhd_handler;
double (*set_gain_callback) (void*,double); float (*set_gain_callback)(void*, float);
srslte_agc_mode_t mode; srslte_agc_mode_t mode;
float target; float target;
uint32_t nof_frames; uint32_t nof_frames;
@ -69,14 +69,14 @@ SRSLTE_API int srslte_agc_init_acc(srslte_agc_t *q, srslte_agc_mode_t mode, uint
SRSLTE_API int srslte_agc_init_uhd(srslte_agc_t* q, SRSLTE_API int srslte_agc_init_uhd(srslte_agc_t* q,
srslte_agc_mode_t mode, srslte_agc_mode_t mode,
uint32_t nof_frames, uint32_t nof_frames,
double (set_gain_callback)(void*, double), float(set_gain_callback)(void*, float),
void* uhd_handler); void* uhd_handler);
SRSLTE_API void srslte_agc_free(srslte_agc_t *q); SRSLTE_API void srslte_agc_free(srslte_agc_t *q);
SRSLTE_API void srslte_agc_reset(srslte_agc_t *q); SRSLTE_API void srslte_agc_reset(srslte_agc_t *q);
SRSLTE_API void srslte_agc_set_gain_range(srslte_agc_t *q, double min_gain, double max_gain); SRSLTE_API void srslte_agc_set_gain_range(srslte_agc_t* q, float min_gain, float max_gain);
SRSLTE_API void srslte_agc_set_bandwidth(srslte_agc_t *q, SRSLTE_API void srslte_agc_set_bandwidth(srslte_agc_t *q,
float bandwidth); float bandwidth);

@ -200,10 +200,10 @@ SRSLTE_API void srslte_ue_sync_set_nof_find_frames(srslte_ue_sync_t* q, uint32_t
SRSLTE_API srslte_frame_type_t srslte_ue_sync_get_frame_type(srslte_ue_sync_t* q); SRSLTE_API srslte_frame_type_t srslte_ue_sync_get_frame_type(srslte_ue_sync_t* q);
SRSLTE_API int srslte_ue_sync_start_agc(srslte_ue_sync_t* q, SRSLTE_API int srslte_ue_sync_start_agc(srslte_ue_sync_t* q,
double(set_gain_callback)(void*, double), float(set_gain_callback)(void*, float),
double min_gain, float min_gain,
double max_gain, float max_gain,
double init_gain_value); float init_gain_value);
SRSLTE_API uint32_t srslte_ue_sync_sf_len(srslte_ue_sync_t *q); SRSLTE_API uint32_t srslte_ue_sync_sf_len(srslte_ue_sync_t *q);

@ -34,10 +34,10 @@
extern "C" { extern "C" {
#endif #endif
#include <stdio.h>
#include <stdint.h>
#include "srslte/config.h" #include "srslte/config.h"
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#define SRSLTE_MAX(a,b) ((a)>(b)?(a):(b)) #define SRSLTE_MAX(a,b) ((a)>(b)?(a):(b))
#define SRSLTE_MIN(a,b) ((a)<(b)?(a):(b)) #define SRSLTE_MIN(a,b) ((a)<(b)?(a):(b))
@ -51,6 +51,26 @@ extern "C" {
// Exponential moving average // Exponential moving average
#define SRSLTE_VEC_EMA(data, average, alpha) ((alpha)*(data)+(1-alpha)*(average)) #define SRSLTE_VEC_EMA(data, average, alpha) ((alpha)*(data)+(1-alpha)*(average))
static inline float srslte_convert_amplitude_to_dB(float v)
{
return 20.0f * log10f(v);
}
static inline float srslte_convert_power_to_dB(float v)
{
return 10.0f * log10f(v);
}
static inline float srslte_convert_power_to_dBm(float v)
{
return srslte_convert_power_to_dB(v) + 30.0f;
}
static inline float srslte_convert_dB_to_amplitude(float v)
{
return powf(10.0f, v / 20.0f);
}
static inline float srslte_convert_dB_to_power(float v)
{
return powf(10.0f, v / 10.0f);
}
/*logical operations */ /*logical operations */
SRSLTE_API void srslte_vec_xor_bbb(int8_t *x,int8_t *y,int8_t *z, const uint32_t len); SRSLTE_API void srslte_vec_xor_bbb(int8_t *x,int8_t *y,int8_t *z, const uint32_t len);

@ -98,7 +98,7 @@ class radio {
void set_tx_gain(float gain); void set_tx_gain(float gain);
void set_rx_gain(float gain); void set_rx_gain(float gain);
void set_tx_rx_gain_offset(float offset); void set_tx_rx_gain_offset(float offset);
double set_rx_gain_th(float gain); float set_rx_gain_th(float gain);
void set_freq_offset(double freq); void set_freq_offset(double freq);
void set_tx_freq(uint32_t chan, double freq); void set_tx_freq(uint32_t chan, double freq);

@ -84,7 +84,7 @@ public:
return radios.at(radio_idx)->rx_now(buffer, nof_samples, rxd_time); return radios.at(radio_idx)->rx_now(buffer, nof_samples, rxd_time);
} }
void set_rx_gain(const uint32_t& radio_idx, const float& gain) override { radios.at(radio_idx)->set_rx_gain(gain); } void set_rx_gain(const uint32_t& radio_idx, const float& gain) override { radios.at(radio_idx)->set_rx_gain(gain); }
double set_rx_gain_th(const float& gain) override { return radios.at(0)->set_rx_gain_th(gain); } float set_rx_gain_th(const float& gain) override { return radios.at(0)->set_rx_gain_th(gain); }
float get_rx_gain(const uint32_t& radio_idx) override { return radios.at(radio_idx)->get_rx_gain(); } float get_rx_gain(const uint32_t& radio_idx) override { return radios.at(radio_idx)->get_rx_gain(); }
void set_tx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) override void set_tx_freq(const uint32_t& radio_idx, const uint32_t& channel_idx, const double& freq) override
{ {

@ -54,7 +54,12 @@ int srslte_agc_init_acc(srslte_agc_t *q, srslte_agc_mode_t mode, uint32_t nof_fr
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
int srslte_agc_init_uhd(srslte_agc_t *q, srslte_agc_mode_t mode, uint32_t nof_frames, double (set_gain_callback)(void*, double), void *uhd_handler) { int srslte_agc_init_uhd(srslte_agc_t* q,
srslte_agc_mode_t mode,
uint32_t nof_frames,
float(set_gain_callback)(void*, float),
void* uhd_handler)
{
if (!srslte_agc_init_acc(q, mode, nof_frames)) { if (!srslte_agc_init_acc(q, mode, nof_frames)) {
q->set_gain_callback = set_gain_callback; q->set_gain_callback = set_gain_callback;
q->uhd_handler = uhd_handler; q->uhd_handler = uhd_handler;
@ -74,15 +79,16 @@ void srslte_agc_free(srslte_agc_t *q) {
void srslte_agc_reset(srslte_agc_t *q) { void srslte_agc_reset(srslte_agc_t *q) {
q->bandwidth = SRSLTE_AGC_DEFAULT_BW; q->bandwidth = SRSLTE_AGC_DEFAULT_BW;
q->lock = false; q->lock = false;
q->gain = pow(10,50/10); q->gain = srslte_convert_dB_to_power(50.0f);
q->y_out = 1.0; q->y_out = 1.0;
q->isfirst = true; q->isfirst = true;
if (q->set_gain_callback && q->uhd_handler) { if (q->set_gain_callback && q->uhd_handler) {
q->set_gain_callback(q->uhd_handler, 10*log10(q->gain)); q->set_gain_callback(q->uhd_handler, srslte_convert_power_to_dB(q->gain));
} }
} }
void srslte_agc_set_gain_range(srslte_agc_t *q, double min_gain, double max_gain) { void srslte_agc_set_gain_range(srslte_agc_t* q, float min_gain, float max_gain)
{
if (q) { if (q) {
q->min_gain = min_gain; q->min_gain = min_gain;
q->max_gain = max_gain; q->max_gain = max_gain;
@ -119,8 +125,8 @@ void srslte_agc_lock(srslte_agc_t *q, bool enable) {
void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) { void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) {
if (!q->lock) { if (!q->lock) {
double gain_db = 10.0 * log10(q->gain); float gain_db = srslte_convert_power_to_dB(q->gain);
double gain_uhd_db = 50.0; float gain_uhd_db = 50.0f;
float y = 0; float y = 0;
// Apply current gain to input signal // Apply current gain to input signal
@ -140,7 +146,7 @@ void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) {
// Set gain // Set gain
gain_uhd_db = q->set_gain_callback(q->uhd_handler, gain_db); gain_uhd_db = q->set_gain_callback(q->uhd_handler, gain_db);
q->gain = pow(10, gain_uhd_db / 10); q->gain = srslte_convert_dB_to_power(gain_uhd_db);
} }
float *t; float *t;
switch(q->mode) { switch(q->mode) {

@ -839,33 +839,32 @@ static float get_rsrp_neighbour(srslte_chest_dl_t* q)
return max; return max;
} }
#define dbm(a) (10 * log10(a) + 30)
#define db(a) (10 * log10(a))
static void fill_res(srslte_chest_dl_t* q, srslte_chest_dl_res_t* res) static void fill_res(srslte_chest_dl_t* q, srslte_chest_dl_res_t* res)
{ {
res->noise_estimate = get_noise(q); res->noise_estimate = get_noise(q);
res->noise_estimate_dbm = dbm(res->noise_estimate); res->noise_estimate_dbm = srslte_convert_power_to_dBm(res->noise_estimate);
res->cfo = q->cfo; res->cfo = q->cfo;
res->rsrp = get_rsrp(q); res->rsrp = get_rsrp(q);
res->rsrp_dbm = dbm(res->rsrp); res->rsrp_dbm = srslte_convert_power_to_dBm(res->rsrp);
res->rsrp_neigh = get_rsrp_neighbour(q); res->rsrp_neigh = get_rsrp_neighbour(q);
res->rsrq = get_rsrq(q); res->rsrq = get_rsrq(q);
res->rsrq_db = db(res->rsrq); res->rsrq_db = srslte_convert_power_to_dB(res->rsrq);
res->snr_db = db(get_snr(q)); res->snr_db = srslte_convert_power_to_dB(get_snr(q));
res->rssi_dbm = dbm(get_rssi(q)); res->rssi_dbm = srslte_convert_power_to_dBm(get_rssi(q));
res->sync_error = q->sync_err[0][0]; // Take only the channel used for synch res->sync_error = q->sync_err[0][0]; // Take only the channel used for synch
for (uint32_t port_id = 0; port_id < q->cell.nof_ports; port_id++) { for (uint32_t port_id = 0; port_id < q->cell.nof_ports; port_id++) {
res->rsrp_port_dbm[port_id] = dbm(get_rsrp_port(q, port_id)); res->rsrp_port_dbm[port_id] = srslte_convert_power_to_dBm(get_rsrp_port(q, port_id));
for (uint32_t a = 0; a < q->nof_rx_antennas; a++) { for (uint32_t a = 0; a < q->nof_rx_antennas; a++) {
if (q->noise_estimate[a]) { if (q->noise_estimate[a]) {
res->snr_ant_port_db[a][port_id] = db(q->rsrp[a][port_id] / q->noise_estimate[a][port_id]); res->snr_ant_port_db[a][port_id] =
srslte_convert_power_to_dB(q->rsrp[a][port_id] / q->noise_estimate[a][port_id]);
} else { } else {
res->snr_ant_port_db[a][port_id] = 0.0; res->snr_ant_port_db[a][port_id] = 0.0f;
} }
res->rsrp_ant_port_dbm[a][port_id] = dbm(q->rsrp[a][port_id]); res->rsrp_ant_port_dbm[a][port_id] = srslte_convert_power_to_dBm(q->rsrp[a][port_id]);
res->rsrq_ant_port_db[a][port_id] = db(q->cell.nof_prb * q->rsrp[a][port_id] / q->rssi[a][port_id]); res->rsrq_ant_port_db[a][port_id] =
srslte_convert_power_to_dB(q->cell.nof_prb * q->rsrp[a][port_id] / q->rssi[a][port_id]);
} }
} }
} }

@ -320,8 +320,8 @@ int srslte_chest_ul_estimate_pusch(
res->snr = NAN; res->snr = NAN;
} }
res->snr_db = 10 * log10(res->snr); res->snr_db = srslte_convert_power_to_dB(res->snr);
res->noise_estimate_dbm = 10 * log10(res->noise_estimate) + 30; res->noise_estimate_dbm = srslte_convert_power_to_dBm(res->noise_estimate);
return 0; return 0;
} }

@ -47,7 +47,6 @@
srslte_nbiot_cell_t cell = {.base = {.nof_prb = 1, .cp = SRSLTE_CP_NORM, .id = 0}, srslte_nbiot_cell_t cell = {.base = {.nof_prb = 1, .cp = SRSLTE_CP_NORM, .id = 0},
.base.nof_ports = 1, .base.nof_ports = 1,
.base.nof_prb = 1,
.nbiot_prb = 0, .nbiot_prb = 0,
.n_id_ncell = 0}; .n_id_ncell = 0};
@ -184,7 +183,7 @@ int main(int argc, char** argv)
if (have_channel) { if (have_channel) {
// Add noise // Add noise
float std_dev = powf(10, -(snr_db + 3.0f) / 20.0f) * 0.1f; float std_dev = srslte_convert_dB_to_amplitude(-(snr_db + 3.0f)) * 0.1f;
srslte_ch_awgn_c(est.pilot_recv_signal, est.pilot_recv_signal, std_dev, SRSLTE_REFSIGNAL_MAX_NUM_SF(1)); srslte_ch_awgn_c(est.pilot_recv_signal, est.pilot_recv_signal, std_dev, SRSLTE_REFSIGNAL_MAX_NUM_SF(1));
} }

@ -22,14 +22,14 @@
#include <complex.h> #include <complex.h>
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <strings.h>
#include <math.h>
#include "gauss.h" #include "gauss.h"
#include "srslte/phy/channel/ch_awgn.h" #include <srslte/phy/channel/ch_awgn.h>
#include <srslte/phy/utils/vector.h>
float srslte_ch_awgn_get_variance(float ebno_db, float rate) { float srslte_ch_awgn_get_variance(float ebno_db, float rate) {
float esno_db = ebno_db + 10 * log10f(rate); float esno_db = ebno_db + srslte_convert_power_to_dB(rate);
return sqrtf(1 / (powf(10, esno_db / 10))); return srslte_convert_dB_to_amplitude(-esno_db);
} }
void srslte_ch_awgn_c(const cf_t* x, cf_t* y, float variance, uint32_t len) { void srslte_ch_awgn_c(const cf_t* x, cf_t* y, float variance, uint32_t len) {

@ -90,7 +90,7 @@ static inline float get_doppler_dispersion(double t, double a, double w, double
static inline void static inline void
generate_tap(float delay_ns, float power_db, float srate, float phase, cf_t* buf, uint32_t N, uint32_t path_delay) generate_tap(float delay_ns, float power_db, float srate, float phase, cf_t* buf, uint32_t N, uint32_t path_delay)
{ {
float amplitude = powf(10.0f, power_db / 20.0f); float amplitude = srslte_convert_dB_to_power(power_db);
float O = (delay_ns * 1e-9f * srate + path_delay) / (float)N; float O = (delay_ns * 1e-9f * srate + path_delay) / (float)N;
cf_t a0 = amplitude * cexpf(-_Complex_I * phase) / N; cf_t a0 = amplitude * cexpf(-_Complex_I * phase) / N;

@ -33,5 +33,5 @@ float rand_gauss (void) {
s = v1*v1 + v2*v2; s = v1*v1 + v2*v2;
} while ( s >= 1.0 || s == 0.0); } while ( s >= 1.0 || s == 0.0);
return (v1*sqrt(-2.0 * log(s) / s)); return (v1 * sqrtf(-2.0 * log(s) / s));
} }

@ -196,12 +196,12 @@ int main(int argc, char** argv)
srslte_dft_run_c_zerocopy(&fft, output_buffer, fft_buffer); srslte_dft_run_c_zerocopy(&fft, output_buffer, fft_buffer);
srslte_vec_prod_conj_ccc(fft_buffer, fft_buffer, fft_buffer, srate / 1000); srslte_vec_prod_conj_ccc(fft_buffer, fft_buffer, fft_buffer, srate / 1000);
for (int i = 0; i < srate / 1000; i++) { for (int i = 0; i < srate / 1000; i++) {
fft_mag[i] = 10.0f * log10f(__real__ fft_buffer[i]); fft_mag[i] = srslte_convert_power_to_dB(__real__ fft_buffer[i]);
} }
plot_real_setNewData(&plot_fft, fft_mag, srate / 1000); plot_real_setNewData(&plot_fft, fft_mag, srate / 1000);
for (int i = 0; i < channel_fading.N; i++) { for (int i = 0; i < channel_fading.N; i++) {
fft_mag[i] = 20.0f * log10f(cabsf(channel_fading.h_freq[i])); fft_mag[i] = srslte_convert_amplitude_to_dB(cabsf(channel_fading.h_freq[i]));
} }
plot_real_setNewData(&plot_h, fft_mag, channel_fading.N); plot_real_setNewData(&plot_h, fft_mag, channel_fading.N);

@ -313,7 +313,7 @@ void srslte_dft_run_c(srslte_dft_plan_t *plan, const cf_t *in, cf_t *out) {
} }
if (plan->db) { if (plan->db) {
for (i=0;i<plan->size;i++) { for (i=0;i<plan->size;i++) {
f_out[i] = 10*log10(f_out[i]); f_out[i] = srslte_convert_power_to_dB(f_out[i]);
} }
} }
copy_post((uint8_t*)out, (uint8_t*)plan->out, sizeof(cf_t), plan->size, copy_post((uint8_t*)out, (uint8_t*)plan->out, sizeof(cf_t), plan->size,
@ -342,7 +342,7 @@ void srslte_dft_run_r(srslte_dft_plan_t *plan, const float *in, float *out) {
} }
if (plan->db) { if (plan->db) {
for (i=0;i<len;i++) { for (i=0;i<len;i++) {
f_out[i] = 10*log10(f_out[i]); f_out[i] = srslte_convert_power_to_dB(f_out[i]);
} }
} }
memcpy(out,plan->out,sizeof(float)*plan->size); memcpy(out,plan->out,sizeof(float)*plan->size);

@ -402,7 +402,7 @@ int srslte_enb_dl_put_pmch(srslte_enb_dl_t* q, srslte_pmch_cfg_t* pmch_cfg, uint
void srslte_enb_dl_gen_signal(srslte_enb_dl_t* q) void srslte_enb_dl_gen_signal(srslte_enb_dl_t* q)
{ {
// TODO: PAPR control // TODO: PAPR control
float norm_factor = 0.05f / sqrt(q->cell.nof_prb); float norm_factor = 0.05f / sqrtf(q->cell.nof_prb);
if (q->dl_sf.sf_type == SRSLTE_SF_MBSFN) { if (q->dl_sf.sf_type == SRSLTE_SF_MBSFN) {
srslte_ofdm_tx_sf(&q->ifft_mbsfn); srslte_ofdm_tx_sf(&q->ifft_mbsfn);

@ -27,9 +27,10 @@
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include "srslte/srslte.h"
#include <srslte/phy/utils/random.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include "srslte/srslte.h"
#include "turbodecoder_test.h" #include "turbodecoder_test.h"
@ -114,6 +115,7 @@ void parse_args(int argc, char **argv) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
srslte_random_t random_gen = srslte_random_init(0);
uint32_t frame_cnt; uint32_t frame_cnt;
float *llr; float *llr;
short *llr_s; short *llr_s;
@ -122,7 +124,7 @@ int main(int argc, char **argv) {
uint32_t i, j; uint32_t i, j;
float var[SNR_POINTS]; float var[SNR_POINTS];
uint32_t snr_points; uint32_t snr_points;
uint32_t errors; uint32_t errors = 0;
uint32_t coded_length; uint32_t coded_length;
struct timeval tdata[3]; struct timeval tdata[3];
float mean_usec; float mean_usec;
@ -210,12 +212,12 @@ int main(int argc, char **argv) {
snr_points = SNR_POINTS; snr_points = SNR_POINTS;
for (i = 0; i < snr_points; i++) { for (i = 0; i < snr_points; i++) {
ebno_db = SNR_MIN + i * ebno_inc; ebno_db = SNR_MIN + i * ebno_inc;
esno_db = ebno_db + 10 * log10((double) 1 / 3); esno_db = ebno_db + srslte_convert_power_to_dB(1.0f / 3.0f);
var[i] = sqrt(1 / (pow(10, esno_db / 10))); var[i] = srslte_convert_dB_to_amplitude(-esno_db);
} }
} else { } else {
esno_db = ebno_db + 10 * log10((double) 1 / 3); esno_db = ebno_db + srslte_convert_power_to_dB(1.0f / 3.0f);
var[0] = sqrt(1 / (pow(10, esno_db / 10))); var[0] = srslte_convert_dB_to_amplitude(-esno_db);
snr_points = 1; snr_points = 1;
} }
for (i = 0; i < snr_points; i++) { for (i = 0; i < snr_points; i++) {
@ -229,7 +231,7 @@ int main(int argc, char **argv) {
if (test_known_data) { if (test_known_data) {
data_tx[j] = known_data[j]; data_tx[j] = known_data[j];
} else { } else {
data_tx[j] = rand() % 2; data_tx[j] = srslte_random_uniform_int_dist(random_gen, 0, 1);
} }
} }
@ -292,9 +294,7 @@ int main(int argc, char **argv) {
} }
} }
if (data_rx_bytes) {
free(data_rx_bytes); free(data_rx_bytes);
}
free(data_tx); free(data_tx);
free(symbols); free(symbols);
free(llr); free(llr);
@ -304,6 +304,7 @@ int main(int argc, char **argv) {
srslte_tdec_free(&tdec); srslte_tdec_free(&tdec);
srslte_tcod_free(&tcod); srslte_tcod_free(&tcod);
srslte_random_free(random_gen);
printf("\n"); printf("\n");
printf("Done\n"); printf("Done\n");

@ -19,13 +19,14 @@
* *
*/ */
#include <math.h>
#include <srslte/phy/utils/random.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <unistd.h>
#include <math.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#include "srslte/srslte.h" #include "srslte/srslte.h"
@ -87,7 +88,7 @@ int main(int argc, char **argv) {
uint16_t *llr_s; uint16_t *llr_s;
uint8_t *llr_c; uint8_t *llr_c;
uint8_t *data_tx, *data_rx, *data_rx2, *symbols; uint8_t *data_tx, *data_rx, *data_rx2, *symbols;
int i, j; int j;
float var[SNR_POINTS], varunc[SNR_POINTS]; float var[SNR_POINTS], varunc[SNR_POINTS];
int snr_points; int snr_points;
uint32_t errors; uint32_t errors;
@ -170,20 +171,20 @@ int main(int argc, char **argv) {
ebno_inc = (SNR_MAX - SNR_MIN) / SNR_POINTS; ebno_inc = (SNR_MAX - SNR_MIN) / SNR_POINTS;
if (ebno_db == 100.0) { if (ebno_db == 100.0) {
snr_points = SNR_POINTS; snr_points = SNR_POINTS;
for (i = 0; i < snr_points; i++) { for (uint32_t i = 0; i < snr_points; i++) {
ebno_db = SNR_MIN + i * ebno_inc; ebno_db = SNR_MIN + i * ebno_inc;
esno_db = ebno_db + 10 * log10((double) 1 / 3); esno_db = ebno_db + srslte_convert_power_to_dB(1.0f / 3.0f);
var[i] = sqrt(1 / (pow(10, esno_db / 10))); var[i] = srslte_convert_dB_to_amplitude(esno_db);
varunc[i] = sqrt(1 / (pow(10, ebno_db / 10))); varunc[i] = srslte_convert_dB_to_amplitude(ebno_db);
} }
} else { } else {
esno_db = ebno_db + 10 * log10((double) 1 / 3); esno_db = ebno_db + srslte_convert_power_to_dB(1.0f / 3.0f);
var[0] = sqrt(1 / (pow(10, esno_db / 10))); var[0] = srslte_convert_dB_to_amplitude(esno_db);
varunc[0] = sqrt(1 / (pow(10, ebno_db / 10))); varunc[0] = srslte_convert_dB_to_amplitude(ebno_db);
snr_points = 1; snr_points = 1;
} }
for (i = 0; i < snr_points; i++) { for (uint32_t i = 0; i < snr_points; i++) {
frame_cnt = 0; frame_cnt = 0;
errors = 0; errors = 0;
#ifdef TEST_SSE #ifdef TEST_SSE
@ -192,9 +193,11 @@ int main(int argc, char **argv) {
while (frame_cnt < nof_frames) { while (frame_cnt < nof_frames) {
/* generate data_tx */ /* generate data_tx */
srslte_random_t random_gen = srslte_random_init(0);
for (j = 0; j < frame_length; j++) { for (j = 0; j < frame_length; j++) {
data_tx[j] = rand() % 2; data_tx[j] = srslte_random_uniform_int_dist(random_gen, 0, 1);
} }
srslte_random_free(random_gen);
/* uncoded BER */ /* uncoded BER */
for (j = 0; j < frame_length; j++) { for (j = 0; j < frame_length; j++) {
@ -219,8 +222,7 @@ int main(int argc, char **argv) {
gettimeofday(&t[1], NULL); gettimeofday(&t[1], NULL);
int M = 1; int M = 1;
for (uint32_t i = 0; i < M; i++) {
for (int i=0;i<M;i++) {
#ifdef VITERBI_16 #ifdef VITERBI_16
srslte_viterbi_decode_us(&dec, llr_s, data_rx, frame_length); srslte_viterbi_decode_us(&dec, llr_s, data_rx, frame_length);
#else #else

@ -2469,8 +2469,12 @@ int srslte_precoding_pmi_select_1l(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS],
ret = srslte_precoding_pmi_select_1l_gen(h, nof_symbols, noise_estimate, pmi, sinr_list); ret = srslte_precoding_pmi_select_1l_gen(h, nof_symbols, noise_estimate, pmi, sinr_list);
#endif #endif
#endif #endif
INFO("Precoder PMI Select for 1 layer SINR=[%.1fdB; %.1fdB; %.1fdB; %.1fdB] PMI=%d\n", 10 * log10(sinr_list[0]), INFO("Precoder PMI Select for 1 layer SINR=[%.1fdB; %.1fdB; %.1fdB; %.1fdB] PMI=%d\n",
10 * log10(sinr_list[1]), 10 * log10(sinr_list[2]), 10 * log10(sinr_list[3]), *pmi); srslte_convert_power_to_dB(sinr_list[0]),
srslte_convert_power_to_dB(sinr_list[1]),
srslte_convert_power_to_dB(sinr_list[2]),
srslte_convert_power_to_dB(sinr_list[3]),
*pmi);
return ret; return ret;
} }
@ -2865,8 +2869,10 @@ int srslte_precoding_pmi_select_2l(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS],
#endif /* LV_HAVE_SSE */ #endif /* LV_HAVE_SSE */
#endif /* LV_HAVE_AVX */ #endif /* LV_HAVE_AVX */
INFO("Precoder PMI Select for 2 layers SINR=[%.1fdB; %.1fdB] PMI=%d\n", 10 * log10(sinr_list[0]), INFO("Precoder PMI Select for 2 layers SINR=[%.1fdB; %.1fdB] PMI=%d\n",
10 * log10(sinr_list[1]), *pmi); srslte_convert_power_to_dB(sinr_list[0]),
srslte_convert_power_to_dB(sinr_list[1]),
*pmi);
return ret; return ret;
} }

@ -41,6 +41,7 @@ char *mimo_type_name = NULL;
char decoder_type_name [17] = "zf"; char decoder_type_name [17] = "zf";
float snr_db = 100.0f; float snr_db = 100.0f;
float scaling = 0.1f; float scaling = 0.1f;
static srslte_random_t random_gen = NULL;
void usage(char *prog) { void usage(char *prog) {
printf("Usage: %s -m [%s|%s|%s|%s] -l [nof_layers] -p [nof_tx_ports]\n" printf("Usage: %s -m [%s|%s|%s|%s] -l [nof_layers] -p [nof_tx_ports]\n"
@ -108,7 +109,7 @@ void populate_channel_cdd(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uint32_t
for (i = 0; i < nof_tx_ports; i++) { for (i = 0; i < nof_tx_ports; i++) {
for (j = 0; j < nof_rx_ports; j++) { for (j = 0; j < nof_rx_ports; j++) {
for (k = 0; k < n; k++) { for (k = 0; k < n; k++) {
h[i][j][k] = (float) rand() / RAND_MAX + ((float) rand() / RAND_MAX) * _Complex_I; h[i][j][k] = srslte_random_uniform_complex_dist(random_gen, -1.0f, +1.0f);
} }
} }
} }
@ -120,7 +121,7 @@ void populate_channel_diversity(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], uin
for (i = 0; i < nof_tx_ports; i++) { for (i = 0; i < nof_tx_ports; i++) {
for (j = 0; j < nof_rx_ports; j++) { for (j = 0; j < nof_rx_ports; j++) {
for (k = 0; k < n / nof_layers; k++) { for (k = 0; k < n / nof_layers; k++) {
cf_t hsymb = (float) rand() / RAND_MAX + ((float) rand() / RAND_MAX) * _Complex_I; cf_t hsymb = srslte_random_uniform_complex_dist(random_gen, -1.0f, +1.0f);
for (l = 0; l < nof_layers; l++) { for (l = 0; l < nof_layers; l++) {
// assume the channel is the same for all symbols // assume the channel is the same for all symbols
h[i][j][k * nof_layers + l] = hsymb; h[i][j][k * nof_layers + l] = hsymb;
@ -134,7 +135,7 @@ void populate_channel_single(cf_t *h) {
int i; int i;
for (i = 0; i < nof_re; i++) { for (i = 0; i < nof_re; i++) {
h[i] = (float)rand() / RAND_MAX + ((float)rand() / RAND_MAX) * _Complex_I; h[i] = srslte_random_uniform_complex_dist(random_gen, -1.0f, +1.0f);
} }
} }
@ -156,7 +157,7 @@ void populate_channel(srslte_tx_scheme_t type, cf_t* h[SRSLTE_MAX_PORTS][SRSLTE_
static void awgn(cf_t *y[SRSLTE_MAX_PORTS], uint32_t n, float snr) { static void awgn(cf_t *y[SRSLTE_MAX_PORTS], uint32_t n, float snr) {
int i; int i;
float std_dev = powf(10, - (snr + 3.0f) / 20.0f) * scaling; float std_dev = srslte_convert_dB_to_amplitude(-(snr + 3.0f)) * scaling;
for (i = 0; i < nof_rx_ports; i++) { for (i = 0; i < nof_rx_ports; i++) {
srslte_ch_awgn_c(y[i], y[i], std_dev, n); srslte_ch_awgn_c(y[i], y[i], std_dev, n);
@ -251,14 +252,13 @@ int main(int argc, char** argv)
} }
/* Generate source random data */ /* Generate source random data */
srslte_random_t random_gen = srslte_random_init(0); random_gen = srslte_random_init(0);
for (i = 0; i < nof_layers; i++) { for (i = 0; i < nof_layers; i++) {
for (j = 0; j < nof_symbols; j++) { for (j = 0; j < nof_symbols; j++) {
__real__ x[i][j] = (2 * srslte_random_uniform_int_dist(random_gen, 0, 1) - 1) * M_SQRT1_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; __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) */ /* Execute Precoding (Tx) */
if (srslte_precoding_type(x, y, nof_layers, nof_tx_ports, codebook_idx, nof_symbols, scaling, type) < 0) { if (srslte_precoding_type(x, y, nof_layers, nof_tx_ports, codebook_idx, nof_symbols, scaling, type) < 0) {
@ -296,8 +296,18 @@ int main(int argc, char** argv)
/* predecoding / equalization */ /* predecoding / equalization */
struct timeval t[3]; struct timeval t[3];
gettimeofday(&t[1], NULL); gettimeofday(&t[1], NULL);
srslte_predecoding_type(r, h, xr, NULL, nof_rx_ports, nof_tx_ports, nof_layers, srslte_predecoding_type(r,
codebook_idx, nof_re, type, scaling, powf(10, -snr_db / 10)); h,
xr,
NULL,
nof_rx_ports,
nof_tx_ports,
nof_layers,
codebook_idx,
nof_re,
type,
scaling,
srslte_convert_dB_to_power(-snr_db));
gettimeofday(&t[2], NULL); gettimeofday(&t[2], NULL);
get_time_interval(t); get_time_interval(t);
@ -322,6 +332,8 @@ int main(int argc, char** argv)
} }
quit: quit:
srslte_random_free(random_gen);
/* Free all data */ /* Free all data */
for (i = 0; i < nof_layers; i++) { for (i = 0; i < nof_layers; i++) {
free(x[i]); free(x[i]);

@ -130,8 +130,8 @@ void demod_16qam_lte(const cf_t *symbols, float *llr, int nsymbols) {
llr[4*i+0] = -yre; llr[4*i+0] = -yre;
llr[4*i+1] = -yim; llr[4*i+1] = -yim;
llr[4*i+2] = fabsf(yre)-2/sqrt(10); llr[4 * i + 2] = fabsf(yre) - 2 / sqrtf(10);
llr[4*i+3] = fabsf(yim)-2/sqrt(10); llr[4 * i + 3] = fabsf(yim) - 2 / sqrtf(10);
} }
} }
@ -146,7 +146,7 @@ void demod_16qam_lte_s_neon(const cf_t *symbols, short *llr, int nsymbols) {
int8x16_t result11, result21; int8x16_t result11, result21;
result11 = vdupq_n_s8(0); result11 = vdupq_n_s8(0);
result21 = vdupq_n_s8(0); result21 = vdupq_n_s8(0);
int16x8_t offset = vdupq_n_s16(2 * SCALE_SHORT_CONV_QAM16 / sqrt(10)); int16x8_t offset = vdupq_n_s16(2 * SCALE_SHORT_CONV_QAM16 / sqrtf(10));
float32x4_t scale_v = vdupq_n_f32(-SCALE_SHORT_CONV_QAM16); float32x4_t scale_v = vdupq_n_f32(-SCALE_SHORT_CONV_QAM16);
for (int i = 0; i < nsymbols / 4; i++) { for (int i = 0; i < nsymbols / 4; i++) {
@ -180,8 +180,8 @@ void demod_16qam_lte_s_neon(const cf_t *symbols, short *llr, int nsymbols) {
llr[4 * i + 0] = -yre; llr[4 * i + 0] = -yre;
llr[4 * i + 1] = -yim; llr[4 * i + 1] = -yim;
llr[4 * i + 2] = abs(yre) - 2 * SCALE_SHORT_CONV_QAM16 / sqrt(10); llr[4 * i + 2] = abs(yre) - 2 * SCALE_SHORT_CONV_QAM16 / sqrtf(10);
llr[4 * i + 3] = abs(yim) - 2 * SCALE_SHORT_CONV_QAM16 / sqrt(10); llr[4 * i + 3] = abs(yim) - 2 * SCALE_SHORT_CONV_QAM16 / sqrtf(10);
} }
} }
@ -192,7 +192,7 @@ void demod_16qam_lte_b_neon(const cf_t *symbols, int8_t *llr, int nsymbols) {
int8x16_t symbol_i, symbol_abs; int8x16_t symbol_i, symbol_abs;
int16x8_t symbol_12, symbol_34; int16x8_t symbol_12, symbol_34;
int32x4_t symbol_i1, symbol_i2, symbol_i3, symbol_i4; int32x4_t symbol_i1, symbol_i2, symbol_i3, symbol_i4;
int8x16_t offset = vdupq_n_s8(2 * SCALE_BYTE_CONV_QAM16 / sqrt(10)); int8x16_t offset = vdupq_n_s8(2 * SCALE_BYTE_CONV_QAM16 / sqrtf(10));
int8x16_t result1n, result2n; int8x16_t result1n, result2n;
float32x4_t scale_v = vdupq_n_f32(-SCALE_BYTE_CONV_QAM16); float32x4_t scale_v = vdupq_n_f32(-SCALE_BYTE_CONV_QAM16);
@ -240,8 +240,8 @@ void demod_16qam_lte_b_neon(const cf_t *symbols, int8_t *llr, int nsymbols) {
llr[4 * i + 0] = -yre; llr[4 * i + 0] = -yre;
llr[4 * i + 1] = -yim; llr[4 * i + 1] = -yim;
llr[4 * i + 2] = abs(yre) - 2 * SCALE_BYTE_CONV_QAM16 / sqrt(10); llr[4 * i + 2] = abs(yre) - 2 * SCALE_BYTE_CONV_QAM16 / sqrtf(10);
llr[4 * i + 3] = abs(yim) - 2 * SCALE_BYTE_CONV_QAM16 / sqrt(10); llr[4 * i + 3] = abs(yim) - 2 * SCALE_BYTE_CONV_QAM16 / sqrtf(10);
} }
} }
@ -254,7 +254,7 @@ void demod_16qam_lte_s_sse(const cf_t *symbols, short *llr, int nsymbols) {
__m128i *resultPtr = (__m128i*) llr; __m128i *resultPtr = (__m128i*) llr;
__m128 symbol1, symbol2; __m128 symbol1, symbol2;
__m128i symbol_i1, symbol_i2, symbol_i, symbol_abs; __m128i symbol_i1, symbol_i2, symbol_i, symbol_abs;
__m128i offset = _mm_set1_epi16(2*SCALE_SHORT_CONV_QAM16/sqrt(10)); __m128i offset = _mm_set1_epi16(2 * SCALE_SHORT_CONV_QAM16 / sqrtf(10));
__m128i result11, result12, result22, result21; __m128i result11, result12, result22, result21;
__m128 scale_v = _mm_set1_ps(-SCALE_SHORT_CONV_QAM16); __m128 scale_v = _mm_set1_ps(-SCALE_SHORT_CONV_QAM16);
__m128i shuffle_negated_1 = _mm_set_epi8(0xff,0xff,0xff,0xff,7,6,5,4,0xff,0xff,0xff,0xff,3,2,1,0); __m128i shuffle_negated_1 = _mm_set_epi8(0xff,0xff,0xff,0xff,7,6,5,4,0xff,0xff,0xff,0xff,3,2,1,0);
@ -289,8 +289,8 @@ void demod_16qam_lte_s_sse(const cf_t *symbols, short *llr, int nsymbols) {
llr[4*i+0] = -yre; llr[4*i+0] = -yre;
llr[4*i+1] = -yim; llr[4*i+1] = -yim;
llr[4*i+2] = abs(yre)-2*SCALE_SHORT_CONV_QAM16/sqrt(10); llr[4 * i + 2] = abs(yre) - 2 * SCALE_SHORT_CONV_QAM16 / sqrtf(10);
llr[4*i+3] = abs(yim)-2*SCALE_SHORT_CONV_QAM16/sqrt(10); llr[4 * i + 3] = abs(yim) - 2 * SCALE_SHORT_CONV_QAM16 / sqrtf(10);
} }
} }
@ -299,7 +299,7 @@ void demod_16qam_lte_b_sse(const cf_t *symbols, int8_t *llr, int nsymbols) {
__m128i *resultPtr = (__m128i*) llr; __m128i *resultPtr = (__m128i*) llr;
__m128 symbol1, symbol2, symbol3, symbol4; __m128 symbol1, symbol2, symbol3, symbol4;
__m128i symbol_i1, symbol_i2, symbol_i3, symbol_i4, symbol_i, symbol_abs, symbol_12, symbol_34; __m128i symbol_i1, symbol_i2, symbol_i3, symbol_i4, symbol_i, symbol_abs, symbol_12, symbol_34;
__m128i offset = _mm_set1_epi8(2*SCALE_BYTE_CONV_QAM16/sqrt(10)); __m128i offset = _mm_set1_epi8(2 * SCALE_BYTE_CONV_QAM16 / sqrtf(10));
__m128i result1n, result1a, result2n, result2a; __m128i result1n, result1a, result2n, result2a;
__m128 scale_v = _mm_set1_ps(-SCALE_BYTE_CONV_QAM16); __m128 scale_v = _mm_set1_ps(-SCALE_BYTE_CONV_QAM16);
@ -342,8 +342,8 @@ void demod_16qam_lte_b_sse(const cf_t *symbols, int8_t *llr, int nsymbols) {
llr[4*i+0] = -yre; llr[4*i+0] = -yre;
llr[4*i+1] = -yim; llr[4*i+1] = -yim;
llr[4*i+2] = abs(yre)-2*SCALE_BYTE_CONV_QAM16/sqrt(10); llr[4 * i + 2] = abs(yre) - 2 * SCALE_BYTE_CONV_QAM16 / sqrtf(10);
llr[4*i+3] = abs(yim)-2*SCALE_BYTE_CONV_QAM16/sqrt(10); llr[4 * i + 3] = abs(yim) - 2 * SCALE_BYTE_CONV_QAM16 / sqrtf(10);
} }
} }
@ -362,8 +362,8 @@ void demod_16qam_lte_s(const cf_t *symbols, short *llr, int nsymbols) {
llr[4*i+0] = -yre; llr[4*i+0] = -yre;
llr[4*i+1] = -yim; llr[4*i+1] = -yim;
llr[4*i+2] = abs(yre)-2*SCALE_SHORT_CONV_QAM16/sqrt(10); llr[4 * i + 2] = abs(yre) - 2 * SCALE_SHORT_CONV_QAM16 / sqrtf(10);
llr[4*i+3] = abs(yim)-2*SCALE_SHORT_CONV_QAM16/sqrt(10); llr[4 * i + 3] = abs(yim) - 2 * SCALE_SHORT_CONV_QAM16 / sqrtf(10);
} }
#endif #endif
#endif #endif
@ -382,8 +382,8 @@ void demod_16qam_lte_b(const cf_t *symbols, int8_t *llr, int nsymbols) {
llr[4*i+0] = -yre; llr[4*i+0] = -yre;
llr[4*i+1] = -yim; llr[4*i+1] = -yim;
llr[4*i+2] = abs(yre)-2*SCALE_BYTE_CONV_QAM16/sqrt(10); llr[4 * i + 2] = abs(yre) - 2 * SCALE_BYTE_CONV_QAM16 / sqrtf(10);
llr[4*i+3] = abs(yim)-2*SCALE_BYTE_CONV_QAM16/sqrt(10); llr[4 * i + 3] = abs(yim) - 2 * SCALE_BYTE_CONV_QAM16 / sqrtf(10);
} }
#endif #endif
#endif #endif
@ -397,10 +397,10 @@ void demod_64qam_lte(const cf_t *symbols, float *llr, int nsymbols)
llr[6*i+0] = -yre; llr[6*i+0] = -yre;
llr[6*i+1] = -yim; llr[6*i+1] = -yim;
llr[6*i+2] = fabsf(yre)-4/sqrt(42); llr[6 * i + 2] = fabsf(yre) - 4 / sqrtf(42);
llr[6*i+3] = fabsf(yim)-4/sqrt(42); llr[6 * i + 3] = fabsf(yim) - 4 / sqrtf(42);
llr[6*i+4] = fabsf(llr[6*i+2])-2/sqrt(42); llr[6 * i + 4] = fabsf(llr[6 * i + 2]) - 2 / sqrtf(42);
llr[6*i+5] = fabsf(llr[6*i+3])-2/sqrt(42); llr[6 * i + 5] = fabsf(llr[6 * i + 3]) - 2 / sqrtf(42);
} }
} }
@ -412,8 +412,8 @@ void demod_64qam_lte_s_neon(const cf_t *symbols, short *llr, int nsymbols) {
float32x4_t symbol1, symbol2; float32x4_t symbol1, symbol2;
int16x8_t symbol_i, symbol_abs, symbol_abs2; int16x8_t symbol_i, symbol_abs, symbol_abs2;
int32x4_t symbol_i1, symbol_i2; int32x4_t symbol_i1, symbol_i2;
int16x8_t offset1 = vdupq_n_s16(4 * SCALE_SHORT_CONV_QAM64 / sqrt(42)); int16x8_t offset1 = vdupq_n_s16(4 * SCALE_SHORT_CONV_QAM64 / sqrtf(42));
int16x8_t offset2 = vdupq_n_s16(2 * SCALE_SHORT_CONV_QAM64 / sqrt(42)); int16x8_t offset2 = vdupq_n_s16(2 * SCALE_SHORT_CONV_QAM64 / sqrtf(42));
float32x4_t scale_v = vdupq_n_f32(-SCALE_SHORT_CONV_QAM64); float32x4_t scale_v = vdupq_n_f32(-SCALE_SHORT_CONV_QAM64);
int16x8_t result11 = vdupq_n_s16(0); int16x8_t result11 = vdupq_n_s16(0);
@ -461,12 +461,10 @@ void demod_64qam_lte_s_neon(const cf_t *symbols, short *llr, int nsymbols) {
llr[6 * i + 0] = -yre; llr[6 * i + 0] = -yre;
llr[6 * i + 1] = -yim; llr[6 * i + 1] = -yim;
llr[6 * i + 2] = abs(yre) - 4 * SCALE_SHORT_CONV_QAM64 / sqrt(42); llr[6 * i + 2] = abs(yre) - 4 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6 * i + 3] = abs(yim) - 4 * SCALE_SHORT_CONV_QAM64 / sqrt(42); llr[6 * i + 3] = abs(yim) - 4 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6 * i + 4] = llr[6 * i + 4] = abs(llr[6 * i + 2]) - 2 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
abs(llr[6 * i + 2]) - 2 * SCALE_SHORT_CONV_QAM64 / sqrt(42); llr[6 * i + 5] = abs(llr[6 * i + 3]) - 2 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6 * i + 5] =
abs(llr[6 * i + 3]) - 2 * SCALE_SHORT_CONV_QAM64 / sqrt(42);
} }
} }
@ -477,8 +475,8 @@ void demod_64qam_lte_b_neon(const cf_t *symbols, int8_t *llr, int nsymbols) {
int8x16_t symbol_i, symbol_abs, symbol_abs2; int8x16_t symbol_i, symbol_abs, symbol_abs2;
int16x8_t symbol_12, symbol_34; int16x8_t symbol_12, symbol_34;
int32x4_t symbol_i1, symbol_i2, symbol_i3, symbol_i4; int32x4_t symbol_i1, symbol_i2, symbol_i3, symbol_i4;
int8x16_t offset1 = vdupq_n_s8(4 * SCALE_BYTE_CONV_QAM64 / sqrt(42)); int8x16_t offset1 = vdupq_n_s8(4 * SCALE_BYTE_CONV_QAM64 / sqrtf(42));
int8x16_t offset2 = vdupq_n_s8(2 * SCALE_BYTE_CONV_QAM64 / sqrt(42)); int8x16_t offset2 = vdupq_n_s8(2 * SCALE_BYTE_CONV_QAM64 / sqrtf(42));
float32x4_t scale_v = vdupq_n_f32(-SCALE_BYTE_CONV_QAM64); float32x4_t scale_v = vdupq_n_f32(-SCALE_BYTE_CONV_QAM64);
int8x16_t result11 = vdupq_n_s8(0); int8x16_t result11 = vdupq_n_s8(0);
int8x16_t result21 = vdupq_n_s8(0); int8x16_t result21 = vdupq_n_s8(0);
@ -561,10 +559,10 @@ void demod_64qam_lte_b_neon(const cf_t *symbols, int8_t *llr, int nsymbols) {
llr[6 * i + 0] = -yre; llr[6 * i + 0] = -yre;
llr[6 * i + 1] = -yim; llr[6 * i + 1] = -yim;
llr[6 * i + 2] = abs(yre) - 4 * SCALE_BYTE_CONV_QAM64 / sqrt(42); llr[6 * i + 2] = abs(yre) - 4 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6 * i + 3] = abs(yim) - 4 * SCALE_BYTE_CONV_QAM64 / sqrt(42); llr[6 * i + 3] = abs(yim) - 4 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6 * i + 4] = abs(llr[6 * i + 2]) - 2 * SCALE_BYTE_CONV_QAM64 / sqrt(42); llr[6 * i + 4] = abs(llr[6 * i + 2]) - 2 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6 * i + 5] = abs(llr[6 * i + 3]) - 2 * SCALE_BYTE_CONV_QAM64 / sqrt(42); llr[6 * i + 5] = abs(llr[6 * i + 3]) - 2 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
} }
} }
@ -578,8 +576,8 @@ void demod_64qam_lte_s_sse(const cf_t *symbols, short *llr, int nsymbols)
__m128i *resultPtr = (__m128i*) llr; __m128i *resultPtr = (__m128i*) llr;
__m128 symbol1, symbol2; __m128 symbol1, symbol2;
__m128i symbol_i1, symbol_i2, symbol_i, symbol_abs, symbol_abs2; __m128i symbol_i1, symbol_i2, symbol_i, symbol_abs, symbol_abs2;
__m128i offset1 = _mm_set1_epi16(4*SCALE_SHORT_CONV_QAM64/sqrt(42)); __m128i offset1 = _mm_set1_epi16(4 * SCALE_SHORT_CONV_QAM64 / sqrtf(42));
__m128i offset2 = _mm_set1_epi16(2*SCALE_SHORT_CONV_QAM64/sqrt(42)); __m128i offset2 = _mm_set1_epi16(2 * SCALE_SHORT_CONV_QAM64 / sqrtf(42));
__m128 scale_v = _mm_set1_ps(-SCALE_SHORT_CONV_QAM64); __m128 scale_v = _mm_set1_ps(-SCALE_SHORT_CONV_QAM64);
__m128i result11, result12, result13, result22, result21,result23, result31, result32, result33; __m128i result11, result12, result13, result22, result21,result23, result31, result32, result33;
@ -628,10 +626,10 @@ void demod_64qam_lte_s_sse(const cf_t *symbols, short *llr, int nsymbols)
llr[6*i+0] = -yre; llr[6*i+0] = -yre;
llr[6*i+1] = -yim; llr[6*i+1] = -yim;
llr[6*i+2] = abs(yre)-4*SCALE_SHORT_CONV_QAM64/sqrt(42); llr[6 * i + 2] = abs(yre) - 4 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6*i+3] = abs(yim)-4*SCALE_SHORT_CONV_QAM64/sqrt(42); llr[6 * i + 3] = abs(yim) - 4 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6*i+4] = abs(llr[6*i+2])-2*SCALE_SHORT_CONV_QAM64/sqrt(42); llr[6 * i + 4] = abs(llr[6 * i + 2]) - 2 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6*i+5] = abs(llr[6*i+3])-2*SCALE_SHORT_CONV_QAM64/sqrt(42); llr[6 * i + 5] = abs(llr[6 * i + 3]) - 2 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
} }
} }
@ -641,8 +639,8 @@ void demod_64qam_lte_b_sse(const cf_t *symbols, int8_t *llr, int nsymbols)
__m128i *resultPtr = (__m128i*) llr; __m128i *resultPtr = (__m128i*) llr;
__m128 symbol1, symbol2, symbol3, symbol4; __m128 symbol1, symbol2, symbol3, symbol4;
__m128i symbol_i1, symbol_i2, symbol_i3, symbol_i4, symbol_i, symbol_abs, symbol_abs2,symbol_12, symbol_34; __m128i symbol_i1, symbol_i2, symbol_i3, symbol_i4, symbol_i, symbol_abs, symbol_abs2,symbol_12, symbol_34;
__m128i offset1 = _mm_set1_epi8(4*SCALE_BYTE_CONV_QAM64/sqrt(42)); __m128i offset1 = _mm_set1_epi8(4 * SCALE_BYTE_CONV_QAM64 / sqrtf(42));
__m128i offset2 = _mm_set1_epi8(2*SCALE_BYTE_CONV_QAM64/sqrt(42)); __m128i offset2 = _mm_set1_epi8(2 * SCALE_BYTE_CONV_QAM64 / sqrtf(42));
__m128 scale_v = _mm_set1_ps(-SCALE_BYTE_CONV_QAM64); __m128 scale_v = _mm_set1_ps(-SCALE_BYTE_CONV_QAM64);
__m128i result11, result12, result13, result22, result21,result23, result31, result32, result33; __m128i result11, result12, result13, result22, result21,result23, result31, result32, result33;
@ -697,10 +695,10 @@ void demod_64qam_lte_b_sse(const cf_t *symbols, int8_t *llr, int nsymbols)
llr[6*i+0] = -yre; llr[6*i+0] = -yre;
llr[6*i+1] = -yim; llr[6*i+1] = -yim;
llr[6*i+2] = abs(yre)-4*SCALE_BYTE_CONV_QAM64/sqrt(42); llr[6 * i + 2] = abs(yre) - 4 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6*i+3] = abs(yim)-4*SCALE_BYTE_CONV_QAM64/sqrt(42); llr[6 * i + 3] = abs(yim) - 4 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6*i+4] = abs(llr[6*i+2])-2*SCALE_BYTE_CONV_QAM64/sqrt(42); llr[6 * i + 4] = abs(llr[6 * i + 2]) - 2 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6*i+5] = abs(llr[6*i+3])-2*SCALE_BYTE_CONV_QAM64/sqrt(42); llr[6 * i + 5] = abs(llr[6 * i + 3]) - 2 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
} }
} }
@ -720,10 +718,10 @@ void demod_64qam_lte_s(const cf_t *symbols, short *llr, int nsymbols)
llr[6*i+0] = -yre; llr[6*i+0] = -yre;
llr[6*i+1] = -yim; llr[6*i+1] = -yim;
llr[6*i+2] = abs(yre)-4*SCALE_SHORT_CONV_QAM64/sqrt(42); llr[6 * i + 2] = abs(yre) - 4 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6*i+3] = abs(yim)-4*SCALE_SHORT_CONV_QAM64/sqrt(42); llr[6 * i + 3] = abs(yim) - 4 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6*i+4] = abs(llr[6*i+2])-2*SCALE_SHORT_CONV_QAM64/sqrt(42); llr[6 * i + 4] = abs(llr[6 * i + 2]) - 2 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
llr[6*i+5] = abs(llr[6*i+3])-2*SCALE_SHORT_CONV_QAM64/sqrt(42); llr[6 * i + 5] = abs(llr[6 * i + 3]) - 2 * SCALE_SHORT_CONV_QAM64 / sqrtf(42);
} }
#endif #endif
#endif #endif
@ -743,10 +741,10 @@ void demod_64qam_lte_b(const cf_t *symbols, int8_t *llr, int nsymbols)
llr[6*i+0] = -yre; llr[6*i+0] = -yre;
llr[6*i+1] = -yim; llr[6*i+1] = -yim;
llr[6*i+2] = abs(yre)-4*SCALE_BYTE_CONV_QAM64/sqrt(42); llr[6 * i + 2] = abs(yre) - 4 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6*i+3] = abs(yim)-4*SCALE_BYTE_CONV_QAM64/sqrt(42); llr[6 * i + 3] = abs(yim) - 4 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6*i+4] = abs(llr[6*i+2])-2*SCALE_BYTE_CONV_QAM64/sqrt(42); llr[6 * i + 4] = abs(llr[6 * i + 2]) - 2 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
llr[6*i+5] = abs(llr[6*i+3])-2*SCALE_BYTE_CONV_QAM64/sqrt(42); llr[6 * i + 5] = abs(llr[6 * i + 3]) - 2 * SCALE_BYTE_CONV_QAM64 / sqrtf(42);
} }
#endif #endif
#endif #endif

@ -176,7 +176,7 @@ void set_256QAMtable(cf_t* table)
real *= ((i & (1 << (2 * j + 1)))) ? +1 : -1; real *= ((i & (1 << (2 * j + 1)))) ? +1 : -1;
imag *= ((i & (1 << (2 * j + 0)))) ? +1 : -1; imag *= ((i & (1 << (2 * j + 0)))) ? +1 : -1;
} }
__real__ table[i] = real / sqrt(170); __real__ table[i] = real / sqrtf(170);
__imag__ table[i] = imag / sqrt(170); __imag__ table[i] = imag / sqrtf(170);
} }
} }

@ -23,8 +23,8 @@
#define QPSK_LEVEL M_SQRT1_2 #define QPSK_LEVEL M_SQRT1_2
#define QAM16_LEVEL_1 (1.0f / sqrt(10.0f)) #define QAM16_LEVEL_1 (1.0f / sqrtf(10.0f))
#define QAM16_LEVEL_2 (3.0f / sqrt(10.0f)) #define QAM16_LEVEL_2 (3.0f / sqrtf(10.0f))
#define QAM64_LEVEL_1 (1.0f / sqrtf(42.0f)) #define QAM64_LEVEL_1 (1.0f / sqrtf(42.0f))
#define QAM64_LEVEL_2 (3.0f / sqrtf(42.0f)) #define QAM64_LEVEL_2 (3.0f / sqrtf(42.0f))
@ -38,7 +38,7 @@
#define QAM64_THRESHOLD_3 (6.0f / sqrtf(42.0f)) #define QAM64_THRESHOLD_3 (6.0f / sqrtf(42.0f))
//=========================================// //=========================================//
#define QAM64_LEVEL_x 2/sqrt(42) #define QAM64_LEVEL_x 2 / sqrtf(42)
/* this is not an QAM64 level, but, rather, an auxiliary value that can be used for computing the /* this is not an QAM64 level, but, rather, an auxiliary value that can be used for computing the
* symbol from the bit sequence */ * symbol from the bit sequence */

@ -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; 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 */ /* 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 : M_SQRT2); float rho_a = srslte_convert_dB_to_amplitude(cfg->p_a) * ((q->cell.nof_ports == 1) ? 1.0f : M_SQRT2);
uint32_t idx0 = (q->cell.nof_ports == 1) ? 0 : 1; uint32_t idx0 = (q->cell.nof_ports == 1) ? 0 : 1;
float cell_specific_ratio = pdsch_cfg_cell_specific_ratio_table[idx0][cfg->p_b]; float cell_specific_ratio = pdsch_cfg_cell_specific_ratio_table[idx0][cfg->p_b];

@ -63,7 +63,8 @@ int rf_rssi_scan(srslte_rf_t *rf, float *freqs, float *rssi, int nof_bands, doub
} }
} }
rssi[i] = srslte_vec_avg_power_cf(buffer, nsamp); rssi[i] = srslte_vec_avg_power_cf(buffer, nsamp);
printf("[%3d]: Freq %4.1f Mhz - RSSI: %3.2f dBm\r", i, f/1000000, 10*log10f(rssi[i]) + 30); fflush(stdout); printf("[%3d]: Freq %4.1f Mhz - RSSI: %3.2f dBm\r", i, f / 1000000, srslte_convert_power_to_dBm(rssi[i]));
fflush(stdout);
if (SRSLTE_VERBOSE_ISINFO()) { if (SRSLTE_VERBOSE_ISINFO()) {
printf("\n"); printf("\n");
} }
@ -205,7 +206,7 @@ int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas,
srslte_cp_string(found_cells[i].cp), srslte_cp_string(found_cells[i].cp),
found_cells[i].mode * 100, found_cells[i].mode * 100,
found_cells[i].psr, found_cells[i].psr,
20 * log10(found_cells[i].peak * 1000)); srslte_convert_amplitude_to_dB(found_cells[i].peak * 1000));
} }
// Save result // Save result

@ -627,7 +627,7 @@ int rf_zmq_recv_with_time_multi(
} }
// Set gain // Set gain
float scale = powf(10.0f, handler->rx_gain / 20); float scale = srslte_convert_dB_to_amplitude(handler->rx_gain);
srslte_vec_sc_prod_cfc(data[0], scale, data[0], nsamples); srslte_vec_sc_prod_cfc(data[0], scale, data[0], nsamples);
// update rx time // update rx time

@ -278,13 +278,13 @@ void srslte_refsignal_dl_sync_run(srslte_refsignal_dl_sync_t* q, cf_t* buffer, u
} }
// Calculate in dBm // Calculate in dBm
q->rsrp_dBfs = 10.0f * log10f(rsrp_lin) + 30.0f; q->rsrp_dBfs = srslte_convert_power_to_dBm(rsrp_lin);
// Calculate RSSI in dBm // Calculate RSSI in dBm
q->rssi_dBfs = 10.0f * log10f(rssi_lin) + 30.0f; q->rssi_dBfs = srslte_convert_power_to_dBm(rssi_lin);
// Calculate RSRQ // Calculate RSRQ
q->rsrq_dB = 10.0f * log10f(q->refsignal.cell.nof_prb) + q->rsrp_dBfs - q->rssi_dBfs; q->rsrq_dB = srslte_convert_power_to_dB(q->refsignal.cell.nof_prb) + q->rsrp_dBfs - q->rssi_dBfs;
q->found = true; q->found = true;
q->cfo_Hz = cfo_acc; q->cfo_Hz = cfo_acc;

@ -184,7 +184,7 @@ int main(int argc, char** argv)
if (snr != -1.0) { if (snr != -1.0) {
snr -= 10.0; snr -= 10.0;
printf("Adding AWGN with target SNR: %.2fdB\n", snr); printf("Adding AWGN with target SNR: %.2fdB\n", snr);
float nstd = powf(10.0f, -snr / 20.0f); float nstd = srslte_convert_dB_to_amplitude(-snr);
srslte_ch_awgn_c(fft_buffer, fft_buffer, nstd, SFLEN); srslte_ch_awgn_c(fft_buffer, fft_buffer, nstd, SFLEN);
} }

@ -725,7 +725,7 @@ static int select_pmi(srslte_ue_dl_t* q, uint32_t ri, uint32_t* pmi, float* sinr
/* Set PMI */ /* Set PMI */
if (sinr_db != NULL) { if (sinr_db != NULL) {
*sinr_db = 10.0f * log10f(sinr_list[*pmi % SRSLTE_MAX_CODEBOOKS]); *sinr_db = srslte_convert_power_to_dB(sinr_list[*pmi % SRSLTE_MAX_CODEBOOKS]);
} }
} }

@ -137,10 +137,11 @@ void srslte_ue_sync_reset(srslte_ue_sync_t *q) {
} }
int srslte_ue_sync_start_agc(srslte_ue_sync_t* q, int srslte_ue_sync_start_agc(srslte_ue_sync_t* q,
double (set_gain_callback)(void *, double), float(set_gain_callback)(void*, float),
double min_gain, float min_gain,
double max_gain, float max_gain,
double init_gain_value) { float init_gain_value)
{
int n = srslte_agc_init_uhd(&q->agc, SRSLTE_AGC_MODE_PEAK_AMPLITUDE, 0, set_gain_callback, q->stream); int n = srslte_agc_init_uhd(&q->agc, SRSLTE_AGC_MODE_PEAK_AMPLITUDE, 0, set_gain_callback, q->stream);
q->do_agc = n==0?true:false; q->do_agc = n==0?true:false;
if (q->do_agc) { if (q->do_agc) {

@ -354,7 +354,7 @@ float srslte_ue_ul_pusch_power(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg, float
MPR = q->pusch_cfg.last_O_cqi; MPR = q->pusch_cfg.last_O_cqi;
} }
MPR /= q->pusch.dci.nof_re; MPR /= q->pusch.dci.nof_re;
delta = 10 * log10((pow(2, MPR * 1.25) - 1) * beta_offset_pusch); delta = 10 * log10f((powf(2, MPR * 1.25) - 1) * beta_offset_pusch);
} }
#else #else
printf("Do this in pusch??"); printf("Do this in pusch??");
@ -362,10 +362,10 @@ float srslte_ue_ul_pusch_power(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg, float
// TODO: This implements closed-loop power control // TODO: This implements closed-loop power control
float f = 0; float f = 0;
float pusch_power = 10 * log10(cfg->ul_cfg.pusch.grant.L_prb) + p0_pusch + alpha * PL + delta + f; float pusch_power = 10 * log10f(cfg->ul_cfg.pusch.grant.L_prb) + p0_pusch + alpha * PL + delta + f;
DEBUG("PUSCH: P=%f -- 10M=%f, p0=%f,alpha=%f,PL=%f,\n", DEBUG("PUSCH: P=%f -- 10M=%f, p0=%f,alpha=%f,PL=%f,\n",
pusch_power, pusch_power,
10 * log10(cfg->ul_cfg.pusch.grant.L_prb), 10 * log10f(cfg->ul_cfg.pusch.grant.L_prb),
p0_pusch, p0_pusch,
alpha, alpha,
PL); PL);
@ -464,12 +464,12 @@ float srs_power(srslte_ue_ul_t* q, srslte_ue_ul_cfg_t* cfg, float PL)
p_srs_offset = -10.5 + 1.5 * cfg->ul_cfg.power_ctrl.p_srs_offset; p_srs_offset = -10.5 + 1.5 * cfg->ul_cfg.power_ctrl.p_srs_offset;
} }
float p_srs = p_srs_offset + 10 * log10(M_sc) + p0_pusch + alpha * PL + f; float p_srs = p_srs_offset + 10 * log10f(M_sc) + p0_pusch + alpha * PL + f;
DEBUG("SRS: P=%f -- p_offset=%f, 10M=%f, p0_pusch=%f, alpha=%f, PL=%f, f=%f\n", DEBUG("SRS: P=%f -- p_offset=%f, 10M=%f, p0_pusch=%f, alpha=%f, PL=%f, f=%f\n",
p_srs, p_srs,
p_srs_offset, p_srs_offset,
10 * log10(M_sc), 10 * log10f(M_sc),
p0_pusch, p0_pusch,
alpha, alpha,
PL, PL,

@ -390,7 +390,7 @@ void srslte_vec_abs_dB_cf(const cf_t* x, float default_value, float* abs, const
// Check boundaries // Check boundaries
if (isnormal(abs[i])) { if (isnormal(abs[i])) {
// Avoid infinites and zeros // Avoid infinites and zeros
abs[i] = 20.0f * log10f(abs[i]); abs[i] = srslte_convert_amplitude_to_dB(abs[i]);
} else { } else {
// Set to default value instead // Set to default value instead
abs[i] = default_value; abs[i] = default_value;

@ -274,7 +274,7 @@ void radio::set_rx_gain(float gain)
srslte_rf_set_rx_gain(&rf_device, gain); srslte_rf_set_rx_gain(&rf_device, gain);
} }
double radio::set_rx_gain_th(float gain) float radio::set_rx_gain_th(float gain)
{ {
return srslte_rf_set_rx_gain_th(&rf_device, gain); return srslte_rf_set_rx_gain_th(&rf_device, gain);
} }

@ -150,9 +150,9 @@ void parse_args(int argc, char **argv) {
} }
} }
static double set_gain_callback(void* h, double gain) static float set_gain_callback(void* h, float gain)
{ {
radio* r = (radio*)h; auto r = (radio*)h;
return r->set_rx_gain_th(gain); return r->set_rx_gain_th(gain);
} }
@ -181,7 +181,7 @@ static void* plot_thread_run(void* arg)
srslte_vec_abs_square_cf(fft_plot_buffer[r], fft_plot_temp, fft_plot_buffer_size); srslte_vec_abs_square_cf(fft_plot_buffer[r], fft_plot_temp, fft_plot_buffer_size);
for (uint32_t j = 0; j < fft_plot_buffer_size; j++) { for (uint32_t j = 0; j < fft_plot_buffer_size; j++) {
fft_plot_temp[j] = 10.0f * log10f(fft_plot_temp[j]); fft_plot_temp[j] = srslte_convert_power_to_dB(fft_plot_temp[j]);
} }
plot_real_setNewData(&fft_plot[r], fft_plot_temp, fft_plot_buffer_size); plot_real_setNewData(&fft_plot[r], fft_plot_temp, fft_plot_buffer_size);
@ -189,7 +189,7 @@ static void* plot_thread_run(void* arg)
} }
} }
return NULL; return nullptr;
} }
static int init_plots(uint32_t frame_size) static int init_plots(uint32_t frame_size)

@ -107,7 +107,7 @@ void metrics_csv::set_metrics(enb_metrics_t &metrics, const uint32_t period_usec
std::string metrics_csv::float_to_string(float f, int digits, bool add_semicolon) std::string metrics_csv::float_to_string(float f, int digits, bool add_semicolon)
{ {
std::ostringstream os; std::ostringstream os;
const int precision = (f == 0.0) ? digits-1 : digits - log10(fabs(f))-2*DBL_EPSILON; const int precision = (f == 0.0) ? digits - 1 : digits - log10f(fabs(f)) - 2 * DBL_EPSILON;
os << std::fixed << std::setprecision(precision) << f; os << std::fixed << std::setprecision(precision) << f;
if (add_semicolon) if (add_semicolon)
os << ';'; os << ';';

@ -150,7 +150,7 @@ std::string metrics_stdout::float_to_string(float f, int digits)
precision = digits-1; precision = digits-1;
} }
else { else {
precision = digits - (int)(log10(fabs(f))-2*DBL_EPSILON); precision = digits - (int)(log10f(fabs(f)) - 2 * DBL_EPSILON);
} }
os << std::setw(6) << std::fixed << std::setprecision(precision) << f; os << std::setw(6) << std::fixed << std::setprecision(precision) << f;
return os.str(); return os.str();
@ -158,7 +158,7 @@ std::string metrics_stdout::float_to_string(float f, int digits)
std::string metrics_stdout::float_to_eng_string(float f, int digits) std::string metrics_stdout::float_to_eng_string(float f, int digits)
{ {
const int degree = (f == 0.0) ? 0 : lrint( floor( log10( fabs( f ) ) / 3) ); const int degree = (f == 0.0) ? 0 : lrint(floor(log10f(fabs(f)) / 3));
std::string factor; std::string factor;

@ -144,7 +144,7 @@ void metrics_csv::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec)
std::string metrics_csv::float_to_string(float f, int digits, bool add_semicolon) std::string metrics_csv::float_to_string(float f, int digits, bool add_semicolon)
{ {
std::ostringstream os; std::ostringstream os;
const int precision = (f == 0.0) ? digits-1 : digits - log10(fabs(f))-2*DBL_EPSILON; const int precision = (f == 0.0) ? digits - 1 : digits - log10f(fabs(f)) - 2 * DBL_EPSILON;
os << std::fixed << std::setprecision(precision) << f; os << std::fixed << std::setprecision(precision) << f;
if (add_semicolon) if (add_semicolon)
os << ';'; os << ';';

@ -129,7 +129,7 @@ std::string metrics_stdout::float_to_string(float f, int digits)
std::string metrics_stdout::float_to_eng_string(float f, int digits) std::string metrics_stdout::float_to_eng_string(float f, int digits)
{ {
const int degree = (f == 0.0) ? 0 : lrint( floor( log10( fabs( f ) ) / 3) ); const int degree = (f == 0.0) ? 0 : lrint(floor(log10f(fabs(f)) / 3));
std::string factor; std::string factor;

@ -79,9 +79,9 @@ static int radio_recv_callback(void* obj, cf_t* data[SRSLTE_MAX_PORTS], uint32_t
return ((async_scell_recv*)obj)->radio_recv_fnc(data, nsamples, rx_time); return ((async_scell_recv*)obj)->radio_recv_fnc(data, nsamples, rx_time);
} }
static double callback_set_rx_gain(void* h, double gain) static float callback_set_rx_gain(void* h, float gain)
{ {
return ((async_scell_recv*)h)->set_rx_gain(gain); return (float)((async_scell_recv*)h)->set_rx_gain(gain);
} }
void async_scell_recv::init(srslte::radio_interface_phy* _radio_handler, phy_common* _worker_com, srslte::log* _log_h) void async_scell_recv::init(srslte::radio_interface_phy* _radio_handler, phy_common* _worker_com, srslte::log* _log_h)

@ -84,17 +84,17 @@ void measure::set_cell(srslte_cell_t cell)
float measure::rssi() float measure::rssi()
{ {
return 10 * log10(mean_rssi); return srslte_convert_power_to_dB(mean_rssi);
} }
float measure::rsrp() float measure::rsrp()
{ {
return 10 * log10(mean_rsrp) + 30 - rx_gain_offset; return srslte_convert_power_to_dBm(mean_rsrp) - rx_gain_offset;
} }
float measure::rsrq() float measure::rsrq()
{ {
return 10 * log10(mean_rsrq); return srslte_convert_power_to_dB(mean_rsrq);
} }
float measure::snr() float measure::snr()
@ -112,9 +112,9 @@ uint32_t measure::frame_st_idx()
return final_offset; return final_offset;
} }
void measure::set_rx_gain_offset(float rx_gain_offset) void measure::set_rx_gain_offset(float rx_gain_offset_)
{ {
this->rx_gain_offset = rx_gain_offset; rx_gain_offset = rx_gain_offset_;
} }
measure::ret_code measure::run_multiple_subframes(cf_t* input_buffer, uint32_t offset, uint32_t sf_idx, uint32_t max_sf) measure::ret_code measure::run_multiple_subframes(cf_t* input_buffer, uint32_t offset, uint32_t sf_idx, uint32_t max_sf)

@ -294,9 +294,9 @@ void sf_worker::update_measurements()
if (get_id() == 0) { if (get_id() == 0) {
// Average RSSI over all symbols in antenna port 0 (make sure SF length is non-zero) // Average RSSI over all symbols in antenna port 0 (make sure SF length is non-zero)
float rssi_dbm = float rssi_dbm = SRSLTE_SF_LEN_PRB(cell.nof_prb) > 0
SRSLTE_SF_LEN_PRB(cell.nof_prb) > 0 ? (srslte_convert_power_to_dB(srslte_vec_avg_power_cf(cc_workers[0]->get_rx_buffer(0),
? (10 * log10(srslte_vec_avg_power_cf(cc_workers[0]->get_rx_buffer(0), SRSLTE_SF_LEN_PRB(cell.nof_prb))) + SRSLTE_SF_LEN_PRB(cell.nof_prb))) +
30) 30)
: 0; : 0;
if (std::isnormal(rssi_dbm)) { if (std::isnormal(rssi_dbm)) {

@ -38,7 +38,8 @@ int radio_recv_callback(void *obj, cf_t *data[SRSLTE_MAX_PORTS], uint32_t nsampl
return ((sync*)obj)->radio_recv_fnc(data, nsamples, rx_time); return ((sync*)obj)->radio_recv_fnc(data, nsamples, rx_time);
} }
double callback_set_rx_gain(void *h, double gain) { float callback_set_rx_gain(void* h, float gain)
{
return ((sync*)h)->set_rx_gain(gain); return ((sync*)h)->set_rx_gain(gain);
} }

@ -194,12 +194,11 @@ public:
} }
// Undo srslte_enb_dl_gen_signal scaling // Undo srslte_enb_dl_gen_signal scaling
float scale = sqrt(cell_base.nof_prb) / 0.05f / enb_dl.ifft->symbol_sz; float scale = sqrtf(cell_base.nof_prb) / 0.05f / enb_dl.ifft->symbol_sz;
// Apply Neighbour cell attenuation // Apply Neighbour cell attenuation
if (enb_dl.cell.id != cell_id_start) { if (enb_dl.cell.id != cell_id_start) {
float scale_dB = -ncell_attenuation_dB; scale *= srslte_convert_dB_to_amplitude(-ncell_attenuation_dB);
scale *= powf(10.0f, scale_dB / 20.0f);
} }
// Scale signal // Scale signal

Loading…
Cancel
Save