diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2020-12-26 08:49:29 +0100 |
---|---|---|
committer | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2021-01-08 02:23:56 +0100 |
commit | 834ba05cd218e0f08685adf259e18a96368285ef (patch) | |
tree | 984869f4500c035417e09579b03853082c575dbb | |
parent | power_control: migrate MS/BS control loops to the new params (diff) | |
download | OsmoBTS-834ba05cd218e0f08685adf259e18a96368285ef.tar.xz OsmoBTS-834ba05cd218e0f08685adf259e18a96368285ef.zip |
power_control: generalize measurement pre-processing state
This way EWMA based filtering can also be applied to RxQual.
Change-Id: I439c00b394da670e314f217b3246cc85ce8213c6
Related: SYS#4918, SYS#4917
-rw-r--r-- | include/osmo-bts/gsm_data.h | 16 | ||||
-rw-r--r-- | src/common/power_control.c | 36 | ||||
-rw-r--r-- | tests/power/ms_power_loop_test.c | 5 |
3 files changed, 35 insertions, 22 deletions
diff --git a/include/osmo-bts/gsm_data.h b/include/osmo-bts/gsm_data.h index 6efc7176..253b115d 100644 --- a/include/osmo-bts/gsm_data.h +++ b/include/osmo-bts/gsm_data.h @@ -213,18 +213,28 @@ struct gsm_power_ctrl_params { /* Default MS/BS Power Control parameters */ extern const struct gsm_power_ctrl_params power_ctrl_params_def; +/* Measurement pre-processing state */ +struct gsm_power_ctrl_meas_proc_state { + /* Algorithm specific data */ + union { + struct { + /* Scaled up 100 times average value */ + int Avg100; + } ewma; + }; +}; + struct lchan_power_ctrl_state { /* Dynamic Power Control parameters (NULL in static mode) */ const struct gsm_power_ctrl_params *dpc_params; + /* Measurement pre-processing state (for dynamic mode) */ + struct gsm_power_ctrl_meas_proc_state rxlev_meas_proc; /* Depending on the context (MS or BS power control), fields 'current' and 'max' * reflect either the MS power level (magic numbers), or BS Power reduction level * (attenuation, in dB). */ uint8_t current; uint8_t max; - - /* Scaled up (100 times) average UL/DL RxLev (in dBm) */ - int avg100_rxlev_dbm; }; struct gsm_lchan { diff --git a/src/common/power_control.c b/src/common/power_control.c index e159740e..06296308 100644 --- a/src/common/power_control.c +++ b/src/common/power_control.c @@ -38,29 +38,29 @@ /* Base Low-Pass Single-Pole IIR Filter (EWMA) formula: * - * Avg[n] = a * Pwr[n] + (1 - a) * Avg[n - 1] + * Avg[n] = a * Val[n] + (1 - a) * Avg[n - 1] * - * where parameter 'a' determines how much weight of the latest UL RSSI measurement - * result 'Pwr[n]' carries vs the weight of the average 'Avg[n - 1]'. The value of - * 'a' is usually a float in range 0 .. 1, so: + * where parameter 'a' determines how much weight of the latest measurement value + * 'Val[n]' carries vs the weight of the accumulated average 'Avg[n - 1]'. The + * value of 'a' is usually a float in range 0 .. 1, so: * - * - value 0.5 gives equal weight to both 'Pwr[n]' and 'Avg[n - 1]'; + * - value 0.5 gives equal weight to both 'Val[n]' and 'Avg[n - 1]'; * - value 1.0 means no filtering at all (pass through); * - value 0.0 makes no sense. * * Further optimization: * - * Avg[n] = a * Pwr[n] + Avg[n - 1] - a * Avg[n - 1] + * Avg[n] = a * Val[n] + Avg[n - 1] - a * Avg[n - 1] * ^^^^^^ ^^^^^^^^^^ * * a) this can be implemented in C using '+=' operator: * - * Avg += a * Pwr - a * Avg - * Avg += a * (Pwr - Avg) + * Avg += a * Val - a * Avg + * Avg += a * (Val - Avg) * * b) everything is scaled up by 100 to avoid floating point stuff: * - * Avg100 += A * (Pwr - Avg) + * Avg100 += A * (Val - Avg) * * where 'Avg100' is 'Avg * 100' and 'A' is 'a * 100'. * @@ -70,20 +70,20 @@ * https://en.wikipedia.org/wiki/Low-pass_filter#Simple_infinite_impulse_response_filter * https://tomroelandts.com/articles/low-pass-single-pole-iir-filter */ -static int8_t do_pf_ewma(const struct gsm_power_ctrl_meas_params *mp, - struct lchan_power_ctrl_state *state, - const int8_t Pwr) +static int do_pf_ewma(const struct gsm_power_ctrl_meas_params *mp, + struct gsm_power_ctrl_meas_proc_state *mps, + const int Val) { const uint8_t A = mp->ewma.alpha; - int *Avg100 = &state->avg100_rxlev_dbm; + int *Avg100 = &mps->ewma.Avg100; /* We don't have 'Avg[n - 1]' if this is the first run */ if (*Avg100 == 0) { - *Avg100 = Pwr * EWMA_SCALE_FACTOR; - return Pwr; + *Avg100 = Val * EWMA_SCALE_FACTOR; + return Val; } - *Avg100 += A * (Pwr - *Avg100 / EWMA_SCALE_FACTOR); + *Avg100 += A * (Val - *Avg100 / EWMA_SCALE_FACTOR); return *Avg100 / EWMA_SCALE_FACTOR; } @@ -104,7 +104,9 @@ static int calc_delta(const struct gsm_power_ctrl_params *params, /* Filter RxLev value to reduce unnecessary Tx power oscillations */ switch (params->rxlev_meas.algo) { case GSM_PWR_CTRL_MEAS_AVG_ALGO_OSMO_EWMA: - rxlev_dbm_avg = do_pf_ewma(¶ms->rxlev_meas, state, rxlev_dbm); + rxlev_dbm_avg = do_pf_ewma(¶ms->rxlev_meas, + &state->rxlev_meas_proc, + rxlev_dbm); break; /* TODO: implement other pre-processing methods */ case GSM_PWR_CTRL_MEAS_AVG_ALGO_NONE: diff --git a/tests/power/ms_power_loop_test.c b/tests/power/ms_power_loop_test.c index e93a2efe..eb0e3e9b 100644 --- a/tests/power/ms_power_loop_test.c +++ b/tests/power/ms_power_loop_test.c @@ -164,7 +164,7 @@ static void test_pf_algo_ewma(void) init_test(__func__); lchan = &g_trx->ts[0].lchan[0]; - avg100 = &lchan->ms_power_ctrl.avg100_rxlev_dbm; + avg100 = &lchan->ms_power_ctrl.rxlev_meas_proc.ewma.Avg100; struct gsm_power_ctrl_meas_params *mp = &lchan->ms_dpc_params.rxlev_meas; mp->algo = GSM_PWR_CTRL_MEAS_AVG_ALGO_OSMO_EWMA; @@ -204,7 +204,8 @@ static void test_pf_algo_ewma(void) mp->ewma.alpha = 70; /* 30% smoothing */ lchan->ms_power_ctrl.current = 15; - lchan->ms_power_ctrl.avg100_rxlev_dbm = 0; + lchan->ms_power_ctrl.rxlev_meas_proc = \ + (struct gsm_power_ctrl_meas_proc_state) { 0 }; /* This is the first sample, the filter outputs it as-is */ apply_power_test(lchan, -50, 0, 15); |