2024-06-16 05:31:13 -04:00
|
|
|
/* meter.c
|
|
|
|
|
|
|
|
This file is part of a program that implements a Software-Defined Radio.
|
|
|
|
|
|
|
|
Copyright (C) 2013 Warren Pratt, NR0V
|
|
|
|
Copyright (C) 2024 Edouard Griffiths, F4EXB Adapted to SDRangel
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
The author can be reached by email at
|
|
|
|
|
|
|
|
warren@wpratt.com
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "comm.hpp"
|
|
|
|
#include "meterlog10.hpp"
|
|
|
|
#include "meter.hpp"
|
2024-06-24 04:20:14 -04:00
|
|
|
#include "RXA.hpp"
|
|
|
|
#include "TXA.hpp"
|
2024-06-16 05:31:13 -04:00
|
|
|
|
|
|
|
namespace WDSP {
|
|
|
|
|
|
|
|
void METER::calc_meter (METER *a)
|
|
|
|
{
|
|
|
|
a->mult_average = exp(-1.0 / (a->rate * a->tau_average));
|
|
|
|
a->mult_peak = exp(-1.0 / (a->rate * a->tau_peak_decay));
|
|
|
|
flush_meter(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
METER* METER::create_meter (
|
|
|
|
int run,
|
|
|
|
int* prun,
|
|
|
|
int size,
|
2024-06-24 21:50:48 -04:00
|
|
|
float* buff,
|
2024-06-16 05:31:13 -04:00
|
|
|
int rate,
|
|
|
|
double tau_av,
|
|
|
|
double tau_decay,
|
2024-07-12 21:53:57 -04:00
|
|
|
double* result,
|
2024-06-16 05:31:13 -04:00
|
|
|
int enum_av,
|
|
|
|
int enum_pk,
|
|
|
|
int enum_gain,
|
|
|
|
double* pgain
|
|
|
|
)
|
|
|
|
{
|
|
|
|
METER *a = new METER;
|
|
|
|
a->run = run;
|
|
|
|
a->prun = prun;
|
|
|
|
a->size = size;
|
|
|
|
a->buff = buff;
|
2024-07-16 18:39:28 -04:00
|
|
|
a->rate = (double) rate;
|
2024-06-16 05:31:13 -04:00
|
|
|
a->tau_average = tau_av;
|
|
|
|
a->tau_peak_decay = tau_decay;
|
|
|
|
a->result = result;
|
|
|
|
a->enum_av = enum_av;
|
|
|
|
a->enum_pk = enum_pk;
|
|
|
|
a->enum_gain = enum_gain;
|
|
|
|
a->pgain = pgain;
|
|
|
|
calc_meter(a);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void METER::destroy_meter (METER *a)
|
|
|
|
{
|
|
|
|
delete a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void METER::flush_meter (METER *a)
|
|
|
|
{
|
|
|
|
a->avg = 0.0;
|
|
|
|
a->peak = 0.0;
|
2024-07-14 15:51:22 -04:00
|
|
|
a->result[a->enum_av] = -100.0;
|
|
|
|
a->result[a->enum_pk] = -100.0;
|
|
|
|
|
2024-06-16 05:31:13 -04:00
|
|
|
if ((a->pgain != 0) && (a->enum_gain >= 0))
|
2024-07-14 15:51:22 -04:00
|
|
|
a->result[a->enum_gain] = 0.0;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void METER::xmeter (METER *a)
|
|
|
|
{
|
|
|
|
int srun;
|
2024-07-13 17:59:46 -04:00
|
|
|
|
2024-06-16 05:31:13 -04:00
|
|
|
if (a->prun != 0)
|
|
|
|
srun = *(a->prun);
|
|
|
|
else
|
|
|
|
srun = 1;
|
2024-07-13 17:59:46 -04:00
|
|
|
|
2024-06-16 05:31:13 -04:00
|
|
|
if (a->run && srun)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
double smag;
|
|
|
|
double np = 0.0;
|
2024-07-13 17:59:46 -04:00
|
|
|
|
2024-06-16 05:31:13 -04:00
|
|
|
for (i = 0; i < a->size; i++)
|
|
|
|
{
|
2024-07-16 18:39:28 -04:00
|
|
|
double xr = a->buff[2 * i + 0];
|
|
|
|
double xi = a->buff[2 * i + 1];
|
|
|
|
smag = xr*xr + xi*xi;
|
2024-06-16 05:31:13 -04:00
|
|
|
a->avg = a->avg * a->mult_average + (1.0 - a->mult_average) * smag;
|
|
|
|
a->peak *= a->mult_peak;
|
2024-07-14 15:51:22 -04:00
|
|
|
|
|
|
|
if (smag > np)
|
|
|
|
np = smag;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
2024-07-13 17:59:46 -04:00
|
|
|
|
|
|
|
if (np > a->peak)
|
|
|
|
a->peak = np;
|
|
|
|
|
2024-06-16 05:31:13 -04:00
|
|
|
a->result[a->enum_av] = 10.0 * MemLog::mlog10 (a->avg + 1.0e-40);
|
|
|
|
a->result[a->enum_pk] = 10.0 * MemLog::mlog10 (a->peak + 1.0e-40);
|
2024-07-13 17:59:46 -04:00
|
|
|
|
2024-06-16 05:31:13 -04:00
|
|
|
if ((a->pgain != 0) && (a->enum_gain >= 0))
|
|
|
|
a->result[a->enum_gain] = 20.0 * MemLog::mlog10 (*a->pgain + 1.0e-40);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-14 15:51:22 -04:00
|
|
|
if (a->enum_av >= 0)
|
|
|
|
a->result[a->enum_av] = -100.0;
|
|
|
|
if (a->enum_pk >= 0)
|
|
|
|
a->result[a->enum_pk] = -100.0;
|
|
|
|
if (a->enum_gain >= 0)
|
|
|
|
a->result[a->enum_gain] = 0.0;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-24 21:50:48 -04:00
|
|
|
void METER::setBuffers_meter (METER *a, float* in)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
|
|
|
a->buff = in;
|
|
|
|
}
|
|
|
|
|
|
|
|
void METER::setSamplerate_meter (METER *a, int rate)
|
|
|
|
{
|
2024-07-16 18:39:28 -04:00
|
|
|
a->rate = (double) rate;
|
2024-06-16 05:31:13 -04:00
|
|
|
calc_meter(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void METER::setSize_meter (METER *a, int size)
|
|
|
|
{
|
|
|
|
a->size = size;
|
|
|
|
flush_meter (a);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************************
|
|
|
|
* *
|
|
|
|
* RXA Properties *
|
|
|
|
* *
|
|
|
|
********************************************************************************************************/
|
|
|
|
|
2024-07-12 21:53:57 -04:00
|
|
|
double METER::GetMeter (RXA& rxa, int mt)
|
2024-06-24 04:20:14 -04:00
|
|
|
{
|
2024-07-14 15:51:22 -04:00
|
|
|
double val = rxa.meter[mt];
|
2024-06-24 04:20:14 -04:00
|
|
|
return val;
|
|
|
|
}
|
2024-06-16 05:31:13 -04:00
|
|
|
|
|
|
|
/********************************************************************************************************
|
|
|
|
* *
|
|
|
|
* TXA Properties *
|
|
|
|
* *
|
|
|
|
********************************************************************************************************/
|
|
|
|
|
2024-07-12 21:53:57 -04:00
|
|
|
double METER::GetMeter (TXA& txa, int mt)
|
2024-06-24 04:20:14 -04:00
|
|
|
{
|
2024-07-14 15:51:22 -04:00
|
|
|
double val = txa.meter[mt];
|
2024-06-24 04:20:14 -04:00
|
|
|
return val;
|
|
|
|
}
|
2024-06-16 05:31:13 -04:00
|
|
|
|
|
|
|
} // namespace WDSP
|