diff --git a/lib/include/srslte/phy/agc/agc.h b/lib/include/srslte/phy/agc/agc.h index 8e345fd85..4f0a88d58 100644 --- a/lib/include/srslte/phy/agc/agc.h +++ b/lib/include/srslte/phy/agc/agc.h @@ -48,8 +48,8 @@ typedef enum SRSLTE_API { typedef struct SRSLTE_API{ float bandwidth; float gain; - float min_gain; - float max_gain; + float min_gain_db; + float max_gain_db; float y_out; bool lock; 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_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, 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 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, bool enable); diff --git a/lib/src/phy/agc/agc.c b/lib/src/phy/agc/agc.c index 8b533e88f..644823645 100644 --- a/lib/src/phy/agc/agc.c +++ b/lib/src/phy/agc/agc.c @@ -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)); q->mode = mode; q->nof_frames = nof_frames; - q->max_gain = 90.0; - q->min_gain = 0.0; + q->max_gain_db = 90.0; + q->min_gain_db = 0.0; if (nof_frames > 0) { q->y_tmp = srslte_vec_malloc(sizeof(float) * nof_frames); 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) { - q->min_gain = min_gain; - q->max_gain = max_gain; + q->min_gain_db = min_gain_db; + q->max_gain_db = max_gain_db; } } @@ -115,8 +114,8 @@ float srslte_agc_get_gain(srslte_agc_t *q) { return q->gain; } -void srslte_agc_set_gain(srslte_agc_t *q, float init_gain_value) { - q->gain = init_gain_value; +void srslte_agc_set_gain(srslte_agc_t *q, float init_gain_value_db) { + q->gain = pow(10, init_gain_value_db/10); } 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) { srslte_vec_sc_prod_cfc(signal, q->gain, signal, len); } else { - if (gain_db < q->min_gain) { - gain_db = q->min_gain + 5.0; + if (gain_db < q->min_gain_db) { + gain_db = q->min_gain_db + 5.0; INFO("Warning: Rx signal strength is too high. Forcing minimum Rx gain %.2fdB\n", gain_db); - } else if (gain_db > q->max_gain) { - gain_db = q->max_gain; + } else if (gain_db > q->max_gain_db) { + gain_db = q->max_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)) { - 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); }