Fix issue in AGC confusing dB with linear

master
Ismael Gomez 5 years ago
parent 3159a5b84a
commit 713d98ecb9

@ -48,8 +48,8 @@ typedef enum SRSLTE_API {
typedef struct SRSLTE_API{ typedef struct SRSLTE_API{
float bandwidth; float bandwidth;
float gain; float gain;
float min_gain; float min_gain_db;
float max_gain; float max_gain_db;
float y_out; float y_out;
bool lock; bool lock;
bool isfirst; bool isfirst;
@ -76,7 +76,7 @@ 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, float min_gain, float max_gain); SRSLTE_API void srslte_agc_set_gain_range(srslte_agc_t *q, float min_gain_db, float max_gain_db);
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);
@ -91,7 +91,7 @@ SRSLTE_API float srslte_agc_get_output_level(srslte_agc_t *q);
SRSLTE_API float srslte_agc_get_gain(srslte_agc_t *q); SRSLTE_API float srslte_agc_get_gain(srslte_agc_t *q);
SRSLTE_API void srslte_agc_set_gain(srslte_agc_t *q, SRSLTE_API void srslte_agc_set_gain(srslte_agc_t *q,
float init_gain_value); float init_gain_value_db);
SRSLTE_API void srslte_agc_lock(srslte_agc_t *q, SRSLTE_API void srslte_agc_lock(srslte_agc_t *q,
bool enable); bool enable);

@ -39,8 +39,8 @@ int srslte_agc_init_acc(srslte_agc_t *q, srslte_agc_mode_t mode, uint32_t nof_fr
bzero(q, sizeof(srslte_agc_t)); bzero(q, sizeof(srslte_agc_t));
q->mode = mode; q->mode = mode;
q->nof_frames = nof_frames; q->nof_frames = nof_frames;
q->max_gain = 90.0; q->max_gain_db = 90.0;
q->min_gain = 0.0; q->min_gain_db = 0.0;
if (nof_frames > 0) { if (nof_frames > 0) {
q->y_tmp = srslte_vec_malloc(sizeof(float) * nof_frames); q->y_tmp = srslte_vec_malloc(sizeof(float) * nof_frames);
if (!q->y_tmp) { if (!q->y_tmp) {
@ -87,11 +87,10 @@ void srslte_agc_reset(srslte_agc_t *q) {
} }
} }
void srslte_agc_set_gain_range(srslte_agc_t* q, float min_gain, float max_gain) void srslte_agc_set_gain_range(srslte_agc_t *q, float min_gain_db, float max_gain_db) {
{
if (q) { if (q) {
q->min_gain = min_gain; q->min_gain_db = min_gain_db;
q->max_gain = max_gain; q->max_gain_db = max_gain_db;
} }
} }
@ -115,8 +114,8 @@ float srslte_agc_get_gain(srslte_agc_t *q) {
return q->gain; return q->gain;
} }
void srslte_agc_set_gain(srslte_agc_t *q, float init_gain_value) { void srslte_agc_set_gain(srslte_agc_t *q, float init_gain_value_db) {
q->gain = init_gain_value; q->gain = pow(10, init_gain_value_db/10);
} }
void srslte_agc_lock(srslte_agc_t *q, bool enable) { void srslte_agc_lock(srslte_agc_t *q, bool enable) {
@ -133,14 +132,14 @@ void srslte_agc_process(srslte_agc_t *q, cf_t *signal, uint32_t len) {
if (!q->uhd_handler) { if (!q->uhd_handler) {
srslte_vec_sc_prod_cfc(signal, q->gain, signal, len); srslte_vec_sc_prod_cfc(signal, q->gain, signal, len);
} else { } else {
if (gain_db < q->min_gain) { if (gain_db < q->min_gain_db) {
gain_db = q->min_gain + 5.0; gain_db = q->min_gain_db + 5.0;
INFO("Warning: Rx signal strength is too high. Forcing minimum Rx gain %.2fdB\n", gain_db); INFO("Warning: Rx signal strength is too high. Forcing minimum Rx gain %.2fdB\n", gain_db);
} else if (gain_db > q->max_gain) { } else if (gain_db > q->max_gain_db) {
gain_db = q->max_gain; gain_db = q->max_gain_db;
INFO("Warning: Rx signal strength is too weak. Forcing maximum Rx gain %.2fdB\n", gain_db); INFO("Warning: Rx signal strength is too weak. Forcing maximum Rx gain %.2fdB\n", gain_db);
} else if (isinf(gain_db) || isnan(gain_db)) { } else if (isinf(gain_db) || isnan(gain_db)) {
gain_db = (q->min_gain + q->max_gain) / 2.0; gain_db = (q->min_gain_db + q->max_gain_db) / 2.0;
INFO("Warning: AGC went to an unknown state. Setting Rx gain to %.2fdB\n", gain_db); INFO("Warning: AGC went to an unknown state. Setting Rx gain to %.2fdB\n", gain_db);
} }

Loading…
Cancel
Save