# HG changeset patch # User darwin.astudillo@enseeiht.fr # Date 1318002897 -7200 # Node ID 96b20793ada3c55a76c7a43cfd98ae1aef3ecd6e # Parent fa9bc38208b6d07d6370a11aa622ba2199f9811c Optimization of function CalculatePe diff --git a/src/wifi/model/nist-error-rate-model.cc b/src/wifi/model/nist-error-rate-model.cc --- a/src/wifi/model/nist-error-rate-model.cc +++ b/src/wifi/model/nist-error-rate-model.cc @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Gary Pei + * Optimized by: Darwin Astudillo */ #include "nist-error-rate-model.h" #include "wifi-phy.h" @@ -101,56 +102,126 @@ double pms = pow (1 - pe, nbits); return pms; } + +//double NistErrorRateModel::powNist(double a, double b) { +// int tmp = (*(1 + (int *)&a)); +// int tmp2 = (int)(b * (tmp - 1072632447) + 1072632447); +// double p = 0.0; +// *(1 + (int * )&p) = tmp2; +// return p; +//} + double NistErrorRateModel::CalculatePe (double p, uint32_t bValue) const { double D = sqrt (4.0 * p * (1.0 - p)); double pe = 1.0; +// The code modified below there is not beautiful but is fastest. if (bValue == 1) { // code rate 1/2, use table 3.1.1 - pe = 0.5 * ( 36.0 * pow (D, 10.0) - + 211.0 * pow (D, 12.0) - + 1404.0 * pow (D, 14.0) - + 11633.0 * pow (D, 16.0) - + 77433.0 * pow (D, 18.0) - + 502690.0 * pow (D, 20.0) - + 3322763.0 * pow (D, 22.0) - + 21292910.0 * pow (D, 24.0) - + 134365911.0 * pow (D, 26.0) - ); +// pe = 0.5 * ( 36.0 * pow (D, 10.0) +// + 211.0 * pow (D, 12.0) +// + 1404.0 * pow (D, 14.0) +// + 11633.0 * pow (D, 16.0) +// + 77433.0 * pow (D, 18.0) +// + 502690.0 * pow (D, 20.0) +// + 3322763.0 * pow (D, 22.0) +// + 21292910.0 * pow (D, 24.0) +// + 134365911.0 * pow (D, 26.0) +// ); + double multi = D * D; + double acum = multi * multi * multi * multi * multi; + double pe = 18.0 * acum; + acum *= multi; // 12 + pe += 105.5 * acum; + acum *= multi; // 14 + pe += 702.0 * acum; + acum *= multi; // 16 + pe += 5816.5 * acum; + acum *= multi; // 18 + pe += 38716.5 * acum; + acum *= multi; // 20 + pe += 251345 * acum; + acum *= multi; // 22 + pe += 1661381.5 * acum; + acum *= multi; // 24 + pe += 10646455.0 * acum; + acum *= multi; // 26 + pe += 67182955.5 * acum; } else if (bValue == 2) { // code rate 2/3, use table 3.1.2 - pe = 1.0 / (2.0 * bValue) * - ( 3.0 * pow (D, 6.0) - + 70.0 * pow (D, 7.0) - + 285.0 * pow (D, 8.0) - + 1276.0 * pow (D, 9.0) - + 6160.0 * pow (D, 10.0) - + 27128.0 * pow (D, 11.0) - + 117019.0 * pow (D, 12.0) - + 498860.0 * pow (D, 13.0) - + 2103891.0 * pow (D, 14.0) - + 8784123.0 * pow (D, 15.0) - ); +// pe = 1.0 / (2.0 * bValue) * +// ( 3.0 * pow (D, 6.0) +// + 70.0 * pow (D, 7.0) +// + 285.0 * pow (D, 8.0) +// + 1276.0 * pow (D, 9.0) +// + 6160.0 * pow (D, 10.0) +// + 27128.0 * pow (D, 11.0) +// + 117019.0 * pow (D, 12.0) +// + 498860.0 * pow (D, 13.0) +// + 2103891.0 * pow (D, 14.0) +// + 8784123.0 * pow (D, 15.0) +// ); + double acum = D * D * D * D * D * D; + pe = 0.75 * acum; + acum *= D; // 7 + pe =+ 17.5 * acum; + acum *= D; // 8 + pe =+ 71.25 * acum; + acum *= D; // 9 + pe =+ 319.0 * acum; + acum *= D; // 10 + pe =+ 1540.0 * acum; + acum *= D; // 11 + pe =+ 6782.0 * acum; + acum *= D; // 12 + pe =+ 29254.75 * acum; + acum *= D; // 13 + pe =+ 124715.0 * acum; + acum *= D; // 14 + pe =+ 525972.75 * acum; + acum *= D; // 15 + pe =+ 2196030.75 * acum; } else if (bValue == 3) { // code rate 3/4, use table 3.1.2 - pe = 1.0 / (2.0 * bValue) * - ( 42.0 * pow (D, 5.0) - + 201.0 * pow (D, 6.0) - + 1492.0 * pow (D, 7.0) - + 10469.0 * pow (D, 8.0) - + 62935.0 * pow (D, 9.0) - + 379644.0 * pow (D, 10.0) - + 2253373.0 * pow (D, 11.0) - + 13073811.0 * pow (D, 12.0) - + 75152755.0 * pow (D, 13.0) - + 428005675.0 * pow (D, 14.0) - ); +// pe = 1.0 / (2.0 * bValue) * +// ( 42.0 * pow (D, 5.0) +// + 201.0 * pow (D, 6.0) +// + 1492.0 * pow (D, 7.0) +// + 10469.0 * pow (D, 8.0) +// + 62935.0 * pow (D, 9.0) +// + 379644.0 * pow (D, 10.0) +// + 2253373.0 * pow (D, 11.0) +// + 13073811.0 * pow (D, 12.0) +// + 75152755.0 * pow (D, 13.0) +// + 428005675.0 * pow (D, 14.0) +// ); + double acum = D * D * D * D * D; + pe = 42.0 * acum; + acum *= D; // 6 + pe += 201.0 * acum; + acum *= D; // 7 + pe += 1492.0 * acum; + acum *= D; // 8 + pe += 10469.0 * acum; + acum *= D; // 9 + pe += 62935.0 * acum; + acum *= D; // 10 + pe += 379644.0 * acum; + acum *= D; // 11 + pe += 2253373.0 * acum; + acum *= D; // 12 + pe += 13073811.0 * acum; + acum *= D; // 13 + pe += 75152755.0 * acum; + acum *= D; // 14 + pe += 428005675.0 * acum; + pe *= 1.0 / 6.0; } else {