2019-04-26 12:27:38 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2013-2019 Software Radio Systems Limited
|
2014-07-21 08:54:25 -07:00
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* This file is part of srsLTE.
|
2014-07-21 08:54:25 -07:00
|
|
|
*
|
2015-03-18 05:31:13 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2015-05-08 08:05:40 -07:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2014-07-21 08:54:25 -07:00
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-03-18 05:31:13 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2014-07-21 08:54:25 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-05-08 08:05:40 -07:00
|
|
|
* GNU Affero General Public License for more details.
|
2014-07-21 08:54:25 -07:00
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
2014-07-21 08:54:25 -07:00
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-04-03 05:49:12 -07:00
|
|
|
/**********************************************************************************************
|
|
|
|
* File: agc.h
|
|
|
|
*
|
|
|
|
* Description: Automatic gain control
|
|
|
|
* This module is not currently used
|
|
|
|
*
|
|
|
|
* Reference:
|
|
|
|
*********************************************************************************************/
|
2014-07-21 08:54:25 -07:00
|
|
|
|
2018-03-31 10:04:04 -07:00
|
|
|
#ifndef SRSLTE_AGC_H
|
|
|
|
#define SRSLTE_AGC_H
|
2014-07-21 08:54:25 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
#include <complex.h>
|
2014-07-21 08:54:25 -07:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2015-03-18 05:16:28 -07:00
|
|
|
#include "srslte/config.h"
|
2014-07-21 08:54:25 -07:00
|
|
|
|
2019-12-19 03:40:26 -08:00
|
|
|
#define SRSLTE_AGC_CALLBACK(NAME) void(NAME)(void* h, float gain_db)
|
2020-01-23 04:28:47 -08:00
|
|
|
#define SRSLTE_AGC_DEFAULT_TARGET (0.3f) /* Average RMS target or maximum peak target*/
|
|
|
|
#define SRSLTE_AGC_DEFAULT_BW (0.3f) /* Moving average coefficient */
|
|
|
|
#define SRSLTE_AGC_HOLD_COUNT (20) /* Number of frames to wait after setting the gain before start measuring */
|
|
|
|
#define SRSLTE_AGC_MIN_MEASUREMENTS (10) /* Minimum number of measurements */
|
|
|
|
#define SRSLTE_AGC_MIN_GAIN_OFFSET (2.0f) /* Mimum of gain offset to set the radio gain */
|
2015-04-20 00:25:29 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
typedef enum SRSLTE_API { SRSLTE_AGC_MODE_ENERGY = 0, SRSLTE_AGC_MODE_PEAK_AMPLITUDE } srslte_agc_mode_t;
|
2014-07-21 08:54:25 -07:00
|
|
|
|
2020-01-23 04:28:47 -08:00
|
|
|
/*
|
|
|
|
* The AGC has been implemented using 3 states:
|
|
|
|
* - init: it simply starts the process of measuring
|
|
|
|
* - measure: performs a minimum of SRSLTE_AGC_MIN_MEASUREMENTS and does not set the gain until it needs
|
|
|
|
* SRSLTE_AGC_MIN_GAIN_OFFSET dB more of gain. The gain is set in the enter hold transition.
|
|
|
|
* - hold: waits for SRSLTE_AGC_HOLD_COUNT frames as a Rx gain transition period. After this period, it enters measure
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* FSM abstraction:
|
|
|
|
*
|
|
|
|
* +------+ Enter measure +---------+ Enter hold +------+
|
|
|
|
* | init | ---------------->| Measure |--------------->| Hold |
|
|
|
|
* +------+ +---------+ +------+
|
|
|
|
* ^ Enter measure |
|
|
|
|
* +-------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum { SRSLTE_AGC_STATE_INIT = 0, SRSLTE_AGC_STATE_MEASURE, SRSLTE_AGC_STATE_HOLD } srslte_agc_state_t;
|
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
typedef struct SRSLTE_API {
|
2014-07-21 08:54:25 -07:00
|
|
|
float bandwidth;
|
2020-01-23 04:28:47 -08:00
|
|
|
float gain_db;
|
|
|
|
float gain_offset_db;
|
2019-12-02 08:44:19 -08:00
|
|
|
float min_gain_db;
|
|
|
|
float max_gain_db;
|
2019-12-19 03:40:26 -08:00
|
|
|
float default_gain_db;
|
2014-07-21 08:54:25 -07:00
|
|
|
float y_out;
|
2019-11-28 05:27:31 -08:00
|
|
|
bool isfirst;
|
|
|
|
void* uhd_handler;
|
2019-12-19 03:40:26 -08:00
|
|
|
SRSLTE_AGC_CALLBACK(*set_gain_callback);
|
2020-01-23 04:28:47 -08:00
|
|
|
srslte_agc_mode_t mode;
|
|
|
|
float target;
|
|
|
|
uint32_t nof_frames;
|
|
|
|
uint32_t frame_cnt;
|
|
|
|
uint32_t hold_cnt;
|
|
|
|
float* y_tmp;
|
|
|
|
srslte_agc_state_t state;
|
2015-03-18 05:31:13 -07:00
|
|
|
} srslte_agc_t;
|
2014-07-21 08:54:25 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
SRSLTE_API int srslte_agc_init_acc(srslte_agc_t* q, srslte_agc_mode_t mode, uint32_t nof_frames);
|
2015-04-21 02:09:08 -07:00
|
|
|
|
2019-11-28 05:27:31 -08:00
|
|
|
SRSLTE_API int srslte_agc_init_uhd(srslte_agc_t* q,
|
|
|
|
srslte_agc_mode_t mode,
|
|
|
|
uint32_t nof_frames,
|
2019-12-19 03:40:26 -08:00
|
|
|
SRSLTE_AGC_CALLBACK(set_gain_callback),
|
2019-11-28 05:27:31 -08:00
|
|
|
void* uhd_handler);
|
2014-07-21 08:54:25 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
SRSLTE_API void srslte_agc_free(srslte_agc_t* q);
|
2014-07-21 08:54:25 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
SRSLTE_API void srslte_agc_reset(srslte_agc_t* q);
|
2014-07-22 07:56:56 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
SRSLTE_API void srslte_agc_set_gain_range(srslte_agc_t* q, float min_gain_db, float max_gain_db);
|
2018-06-11 04:14:47 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
SRSLTE_API float srslte_agc_get_gain(srslte_agc_t* q);
|
2014-07-22 07:56:56 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
SRSLTE_API void srslte_agc_set_gain(srslte_agc_t* q, float init_gain_value_db);
|
2015-04-21 12:05:51 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
SRSLTE_API void srslte_agc_process(srslte_agc_t* q, cf_t* signal, uint32_t len);
|
2014-07-21 08:54:25 -07:00
|
|
|
|
2018-03-31 10:04:04 -07:00
|
|
|
#endif // SRSLTE_AGC_H
|