[Positioning] Measurement: test avg. computation
This commit pass finally all unit tests without any warning! Measurement: - Finish unit test (test the average SS). - Fix update_average_ss() and add_ss(). - average_ss is now double.
This commit is contained in:
parent
a9a2331cfa
commit
12d14b805f
|
@ -11,9 +11,6 @@
|
|||
owlps-positioning/tests/include
|
||||
owlps-positioning/doc (générée par doxygen)
|
||||
|
||||
- Measurement
|
||||
Vérifier le calcul de moyenne (a priori OK).
|
||||
|
||||
- Revoir le diagramme UML
|
||||
° Associations : devraient êtres représentées par des attributs
|
||||
pointeurs.
|
||||
|
|
|
@ -48,31 +48,20 @@ Measurement::~Measurement()
|
|||
/* *** Write accessors *** */
|
||||
|
||||
|
||||
void Measurement::update_average_ss()
|
||||
{
|
||||
average_ss = 0 ;
|
||||
|
||||
for (vector<int>::const_iterator i = ss_list.begin() ;
|
||||
i != ss_list.end() ; ++i)
|
||||
{
|
||||
float ss_mwatts =
|
||||
pow(10, (float) *i / 10.0) +
|
||||
(ss_list.size() * pow(10, average_ss / 10.0)) ;
|
||||
average_ss = 10 * log10(ss_mwatts / ss_list.size()) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* #average_ss is updated to include the new value.
|
||||
* @param ss_dbm The signal strength to add to #ss_list (in dBm).
|
||||
*/
|
||||
void Measurement::add_ss(const int &ss)
|
||||
void Measurement::add_ss(const int &ss_dbm)
|
||||
{
|
||||
float ss_mwatts =
|
||||
pow(10, (float) ss / 10.0) +
|
||||
(ss_list.size() * pow(10, average_ss / 10.0)) ;
|
||||
ss_list.push_back(ss) ;
|
||||
average_ss = 10 * log10(ss_mwatts / ss_list.size()) ;
|
||||
double total_ss_mwatts =
|
||||
pow(10, static_cast<double>(ss_dbm) / 10.0) + // New SS in mW
|
||||
(ss_list.size() * pow(10, average_ss / 10.0)) ; // Other values in mW
|
||||
|
||||
ss_list.push_back(ss_dbm) ; // Add new value (dBm)
|
||||
|
||||
// Update average converting back in dBm
|
||||
average_ss = 10.0 * log10(total_ss_mwatts / ss_list.size()) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -101,6 +90,30 @@ void Measurement::clear()
|
|||
|
||||
|
||||
|
||||
/* *** Operations *** */
|
||||
|
||||
|
||||
void Measurement::update_average_ss()
|
||||
{
|
||||
if (ss_list.size() == 0)
|
||||
{
|
||||
average_ss = 0 ;
|
||||
return ;
|
||||
}
|
||||
|
||||
double total_ss_mwatts = 0 ;
|
||||
|
||||
for (vector<int>::const_iterator i = ss_list.begin() ;
|
||||
i != ss_list.end() ; ++i)
|
||||
// Add the current value in mW to the total
|
||||
total_ss_mwatts += pow(10, static_cast<double>(*i) / 10.0) ;
|
||||
|
||||
// Compute the average in mW and convert it to dBm
|
||||
average_ss = 10 * log10(total_ss_mwatts / ss_list.size()) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* *** Operators *** */
|
||||
|
||||
|
||||
|
|
|
@ -13,13 +13,17 @@ class Measurement
|
|||
protected:
|
||||
/// The AccessPoint that performed the measurement
|
||||
AccessPoint *ap ;
|
||||
/// List of signal strengths captured
|
||||
/// List of signal strengths captured (in dBm)
|
||||
std::vector<int> ss_list ;
|
||||
/// Average of all signal strength captured
|
||||
float average_ss ;
|
||||
/// Average of all signal strength captured (dBm)
|
||||
double average_ss ;
|
||||
|
||||
/** @name Operations */
|
||||
//@{
|
||||
/// Recalculates #average_ss from #ss_list
|
||||
void update_average_ss(void) ;
|
||||
//@}
|
||||
|
||||
|
||||
public:
|
||||
/// Constructs a Measurement from an AccessPoint (or default constructor)
|
||||
|
@ -40,7 +44,7 @@ public:
|
|||
/// #ss_list read accessor
|
||||
const std::vector<int>& get_ss_list() const ;
|
||||
/// #average_ss read accessor
|
||||
float get_average_ss() const ;
|
||||
double get_average_ss() const ;
|
||||
//float get_ss_square_distance(const float &ss) const ;
|
||||
//@}
|
||||
|
||||
|
@ -49,7 +53,7 @@ public:
|
|||
/// #ap write accessor
|
||||
void set_ap(const AccessPoint *_ap) ;
|
||||
/// Adds a signal strength to #ss_list
|
||||
void add_ss(const int &ss) ;
|
||||
void add_ss(const int &ss_dbm) ;
|
||||
/// #ss_list write accessor
|
||||
void set_ss_list(const std::vector<int> &_ss_list) ;
|
||||
/// Reinitialises the Measurement
|
||||
|
@ -85,7 +89,7 @@ inline const std::vector<int>& Measurement::get_ss_list() const
|
|||
}
|
||||
|
||||
|
||||
inline float Measurement::get_average_ss() const
|
||||
inline double Measurement::get_average_ss() const
|
||||
{
|
||||
return average_ss ;
|
||||
}
|
||||
|
@ -98,7 +102,7 @@ inline float Measurement::get_average_ss() const
|
|||
|
||||
|
||||
|
||||
/* *** write accessors *** */
|
||||
/* *** Write accessors *** */
|
||||
|
||||
|
||||
inline void Measurement::set_ap(const AccessPoint *_ap)
|
||||
|
|
|
@ -44,14 +44,32 @@ public:
|
|||
vi1.push_back(-78) ;
|
||||
vi1.push_back(-21) ;
|
||||
TS_ASSERT_EQUALS(m1.get_ss_list(), vi1) ;
|
||||
TS_WARN("TODO: Test average SS.") ;
|
||||
|
||||
/* *** Average computation ***
|
||||
*
|
||||
* We need to convert all dBm values into mW, compute the average
|
||||
* and convert mW back to dBm.
|
||||
* (1) P[mW] = 10^(P[dBm] / 10)
|
||||
* (2) P[dBm] = 10 log10(P[mW])
|
||||
*
|
||||
* So for the dBm values -33, -78, -21, we have:
|
||||
* -33 dBm = 10^(-33/10) mW = 0.0005012 mW
|
||||
* -78 dBm = 10^(-78/10) mW = 0.00000001585 mW
|
||||
* -21 dBm = 10^(-21/10) mW = 0.0079433 mW
|
||||
* And:
|
||||
* ( 10^(-33/10) + 10^(-78/10) + 10^(-21/10) ) / 3 = 0.0028148 mW
|
||||
* Back to dBm:
|
||||
* 0.0028148 mW = -25.505481 dBm
|
||||
*/
|
||||
TS_ASSERT_DELTA(m1.get_average_ss(), -25.505481, 0.0001) ;
|
||||
|
||||
m1.clear() ;
|
||||
std::vector<int> vi2 ;
|
||||
vi1.push_back(-54) ;
|
||||
vi1.push_back(-1) ;
|
||||
vi2.push_back(-54) ;
|
||||
vi2.push_back(-1) ;
|
||||
m1.set_ss_list(vi2) ;
|
||||
TS_ASSERT_EQUALS(m1.get_ss_list(), vi2) ;
|
||||
TS_WARN("TODO: Test average SS.") ;
|
||||
TS_ASSERT_DELTA(m1.get_average_ss(), -4.0102782, 0.0001) ;
|
||||
|
||||
m1.clear() ;
|
||||
Measurement m2 ;
|
||||
|
|
Loading…
Reference in New Issue