diff --git a/agc.c b/agc.c index dc42328..88b9905 100755 --- a/agc.c +++ b/agc.c @@ -10,6 +10,8 @@ void AGC_Init(agc_t *pObj, uint32_t windowLength, radio_float_t w_init) { pObj->w = w_init; + pObj->w_max = 4; + pObj->w_min = 0; SlidingMinMaxInit(&pObj->slMax, windowLength, (radio_float_t)1E12, 1); } @@ -31,6 +33,14 @@ void AGC_Process(agc_t *pObj, radio_float_t x, radio_float_t mu, radio_float_t t void AGC_Train(agc_t *pObj, radio_float_t e, radio_float_t mu) { pObj->w += mu*e; + if (pObj->w > pObj->w_max) + { + pObj->w = pObj->w_max; + } + if (pObj->w < pObj->w_min) + { + pObj->w = pObj->w_min; + } } radio_float_t AGC_GetWeight(agc_t *pObj) diff --git a/agc.h b/agc.h index 6e4631c..cc97ad4 100755 --- a/agc.h +++ b/agc.h @@ -12,6 +12,8 @@ typedef struct _agc_t { radio_float_t w; + radio_float_t w_max; + radio_float_t w_min; sl_minmax_t slMax; } agc_t;