so here i a little code that I need to calculate the average of some rssi values:
#include <stdio.h>
#include <math.h>
int main (void)
{
int8_t rssi_linear_sum;
int8_t rssi_val;
int8_t rssi_avg;
int8_t rssi_num = 0;
int8_t get_rssi(int8_t i)
{
return i;
}
/* rssi_get() in my actual code is a function that gets rssi
values through a bluetooth service, it returns an int8_t value, for the
sake of concision, I replaced it with a loop that
would return similar values to what I get.*/
for (int8_t i = -100; i <-10; i+=10)
{
rssi_val= get_rssi(i);
rssi_linear_sum += powf(10, (float)rssi_val / 20);
rssi_num ++;
}
rssi_avg = 20 * log10f(rssi_linear_sum / rssi_num);
printf("%d",rssi_avg );
}
so I know that to have a precise average to decibel values, you have to linear them first and then get the average. I am just not sure if my code expresses that perfectly. this is more of a logique question rather than a code question, but maybe you can introduce me to a function that does thi or verify that my logique does actually get me the average of values.