You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.5 KiB
C

/**
10 years ago
*
* \section COPYRIGHT
10 years ago
*
* Copyright 2013-2020 Software Radio Systems Limited
10 years ago
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
10 years ago
*
*/
/**********************************************************************************************
* File: agc.h
*
* Description: Automatic gain control
* This module is not currently used
*
* Reference:
*********************************************************************************************/
10 years ago
#ifndef SRSLTE_AGC_H
#define SRSLTE_AGC_H
10 years ago
#include <complex.h>
10 years ago
#include <stdbool.h>
#include <stdint.h>
#include "srslte/config.h"
10 years ago
#define SRSLTE_AGC_CALLBACK(NAME) void(NAME)(void* h, float gain_db)
#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 */
10 years ago
typedef enum SRSLTE_API { SRSLTE_AGC_MODE_ENERGY = 0, SRSLTE_AGC_MODE_PEAK_AMPLITUDE } srslte_agc_mode_t;
10 years ago
/*
* 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;
typedef struct SRSLTE_API {
10 years ago
float bandwidth;
float gain_db;
float gain_offset_db;
float min_gain_db;
float max_gain_db;
float default_gain_db;
10 years ago
float y_out;
bool isfirst;
void* uhd_handler;
SRSLTE_AGC_CALLBACK(*set_gain_callback);
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;
} srslte_agc_t;
10 years ago
SRSLTE_API int srslte_agc_init_acc(srslte_agc_t* q, srslte_agc_mode_t mode, uint32_t nof_frames);
10 years ago
SRSLTE_API int srslte_agc_init_uhd(srslte_agc_t* q,
srslte_agc_mode_t mode,
uint32_t nof_frames,
SRSLTE_AGC_CALLBACK(set_gain_callback),
void* uhd_handler);
10 years ago
SRSLTE_API void srslte_agc_free(srslte_agc_t* q);
10 years ago
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_db, float max_gain_db);
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_db);
SRSLTE_API void srslte_agc_process(srslte_agc_t* q, cf_t* signal, uint32_t len);
10 years ago
#endif // SRSLTE_AGC_H