00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include <math.h>
00055 #include <stdlib.h>
00056 #include <iostream.h>
00057
00058 #ifndef M_PI
00059 #define M_PI 3.14159265359
00060 #endif
00061
00062 double Friis(double Pt, double Gt, double Gr, double lambda, double L, double d)
00063 {
00064
00065
00066
00067
00068
00069
00070
00071 double M = lambda / (4 * M_PI * d);
00072 return (Pt * Gt * Gr * (M * M)) / L;
00073 }
00074
00075 double TwoRay(double Pt, double Gt, double Gr, double ht, double hr, double L, double d, double lambda)
00076 {
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 double Pr;
00092 double crossover_dist = (4 * M_PI * ht * hr) / lambda;
00093
00094 if (d < crossover_dist)
00095 Pr = Friis(Pt, Gt, Gr, lambda, L, d);
00096 else
00097 Pr = Pt * Gt * Gr * (hr * hr * ht * ht) / (d * d * d * d * L);
00098
00099 return Pr;
00100 }
00101
00102
00103
00104
00105 double inv_erfc(double y)
00106 {
00107 double s, t, u, w, x, z;
00108
00109 z = y;
00110 if (y > 1) {
00111 z = 2 - y;
00112 }
00113 w = 0.916461398268964 - log(z);
00114 u = sqrt(w);
00115 s = (log(u) + 0.488826640273108) / w;
00116 t = 1 / (u + 0.231729200323405);
00117 x = u * (1 - s * (s * 0.124610454613712 + 0.5)) -
00118 ((((-0.0728846765585675 * t + 0.269999308670029) * t +
00119 0.150689047360223) * t + 0.116065025341614) * t +
00120 0.499999303439796) * t;
00121 t = 3.97886080735226 / (x + 3.97886080735226);
00122 u = t - 0.5;
00123 s = (((((((((0.00112648096188977922 * u +
00124 1.05739299623423047e-4) * u - 0.00351287146129100025) * u -
00125 7.71708358954120939e-4) * u + 0.00685649426074558612) * u +
00126 0.00339721910367775861) * u - 0.011274916933250487) * u -
00127 0.0118598117047771104) * u + 0.0142961988697898018) * u +
00128 0.0346494207789099922) * u + 0.00220995927012179067;
00129 s = ((((((((((((s * u - 0.0743424357241784861) * u -
00130 0.105872177941595488) * u + 0.0147297938331485121) * u +
00131 0.316847638520135944) * u + 0.713657635868730364) * u +
00132 1.05375024970847138) * u + 1.21448730779995237) * u +
00133 1.16374581931560831) * u + 0.956464974744799006) * u +
00134 0.686265948274097816) * u + 0.434397492331430115) * u +
00135 0.244044510593190935) * t -
00136 z * exp(x * x - 0.120782237635245222);
00137 x += s * (x * s + 1);
00138 if (y > 1) {
00139 x = -x;
00140 }
00141 return x;
00142 }
00143
00144
00145
00146
00147
00148 double inv_Q(double y)
00149 {
00150 double x;
00151 x = sqrt(2.0) * inv_erfc(2.0 * y);
00152 return x;
00153 }
00154
00155
00156 int main(int argc, char** argv)
00157 {
00158
00159
00160 char** propModel = NULL;
00161 double Pt = 0.28183815;
00162 double Gt = 1.0;
00163 double Gr = 1.0;
00164 double freq = 914.0e6;
00165 double sysLoss = 1.0;
00166
00167
00168 double ht = 1.5;
00169 double hr = 1.5;
00170
00171
00172 double pathlossExp_ = 2.0;
00173 double std_db_ = 4.0;
00174 double dist0_ = 1.0;
00175 double prob = 0.95;
00176
00177 double rxThresh_;
00178
00179
00180 if (argc < 4) {
00181 cout << "USAGE: find receiving threshold for certain communication range (distance)" << endl;
00182 cout << endl;
00183 cout << "SYNOPSIS: threshold -m <propagation-model> [other-options] distance" << endl;
00184 cout << endl;
00185 cout << "<propagation-model>: FreeSpace, TwoRayGround or Shadowing" << endl;
00186 cout << "[other-options]: set parameters other than default values:" << endl;
00187 cout << endl << "Common parameters:" << endl;
00188 cout << "-Pt <transmit-power>" << endl;
00189 cout << "-fr <frequency>" << endl;
00190 cout << "-Gt <transmit-antenna-gain>" << endl;
00191 cout << "-Gr <receive-antenna-gain>" << endl;
00192 cout << "-L <system-loss>" << endl;
00193 cout << endl << "For two-ray ground model:" << endl;
00194 cout << "-ht <transmit-antenna-height>" << endl;
00195 cout << "-hr <receive-antenna-height>" << endl;
00196 cout << endl << "For shadowing model:" << endl;
00197 cout << "-pl <path-loss-exponent>" << endl;
00198 cout << "-std <shadowing-deviation>" << endl;
00199 cout << "-d0 <reference-distance>" << endl;
00200 cout << "-r <receiving-rate>" << endl;
00201 return 0;
00202 }
00203
00204
00205 double dist = atof(argv[argc-1]);
00206 cout << "distance = " << dist << endl;
00207
00208 int argCount = (argc - 2) / 2;
00209 argv++;
00210 for (int i = 0; i < argCount; i++) {
00211 if(!strcmp(*argv,"-m")) {
00212 propModel = argv + 1;
00213 cout << "propagation model: " << *propModel << endl;
00214 }
00215 if(!strcmp(*argv,"-Pt")) {
00216 Pt = atof(*(argv + 1));
00217 }
00218 if(!strcmp(*argv,"-fr")) {
00219 freq = atof(*(argv + 1));
00220 }
00221 if(!strcmp(*argv,"-Gt")) {
00222 Gt = atof(*(argv + 1));
00223 }
00224 if(!strcmp(*argv,"-Gr")) {
00225 Gr = atof(*(argv + 1));
00226 }
00227 if(!strcmp(*argv,"-L")) {
00228 sysLoss = atof(*(argv + 1));
00229 }
00230 if(!strcmp(*argv,"-ht")) {
00231 ht = atof(*(argv + 1));
00232 }
00233 if(!strcmp(*argv,"-hr")) {
00234 hr = atof(*(argv + 1));
00235 }
00236 if(!strcmp(*argv,"-pl")) {
00237 pathlossExp_ = atof(*(argv + 1));
00238 }
00239 if(!strcmp(*argv,"-std")) {
00240 std_db_ = atof(*(argv + 1));
00241 }
00242 if(!strcmp(*argv,"-d0")) {
00243 dist0_ = atof(*(argv + 1));
00244 }
00245 if(!strcmp(*argv,"-r")) {
00246 prob = atof(*(argv + 1));
00247 }
00248 argv += 2;
00249 }
00250
00251 if (propModel == NULL) {
00252 cout << "Must specify propagation model: -m <propagation model>" << endl;
00253 return 0;
00254 }
00255
00256 double lambda = 3.0e8/freq;
00257
00258
00259 if (!strcmp(*propModel, "FreeSpace")) {
00260 rxThresh_ = Friis(Pt, Gt, Gr, lambda, sysLoss, dist);
00261 cout << endl << "Selected parameters:" << endl;
00262 cout << "transmit power: " << Pt << endl;
00263 cout << "frequency: " << freq << endl;
00264 cout << "transmit antenna gain: " << Gt << endl;
00265 cout << "receive antenna gain: " << Gr << endl;
00266 cout << "system loss: " << sysLoss << endl;
00267 } else if (!strcmp(*propModel, "TwoRayGround")) {
00268 rxThresh_ = TwoRay(Pt, Gt, Gr, ht, hr, sysLoss, dist, lambda);
00269 cout << endl << "Selected parameters:" << endl;
00270 cout << "transmit power: " << Pt << endl;
00271 cout << "frequency: " << freq << endl;
00272 cout << "transmit antenna gain: " << Gt << endl;
00273 cout << "receive antenna gain: " << Gr << endl;
00274 cout << "system loss: " << sysLoss << endl;
00275 cout << "transmit antenna height: " << ht << endl;
00276 cout << "receive antenna height: " << hr << endl;
00277 } else if (!strcmp(*propModel, "Shadowing")) {
00278
00279 double Pr0 = Friis(Pt, Gt, Gr, lambda, sysLoss, dist0_);
00280
00281
00282 double avg_db = -10.0 * pathlossExp_ * log10(dist/dist0_);
00283
00284
00285 double invq = inv_Q(prob);
00286 double threshdb = invq * std_db_ + avg_db;
00287 rxThresh_ = Pr0 * pow(10.0, threshdb/10.0);
00288
00289 #ifdef DEBUG
00290 cout << "Pr0 = " << Pr0 << endl;
00291 cout << "avg_db = " << avg_db << endl;
00292 cout << "invq = " << invq << endl;
00293 cout << "threshdb = " << threshdb << endl;
00294 #endif
00295
00296 cout << endl << "Selected parameters:" << endl;
00297 cout << "transmit power: " << Pt << endl;
00298 cout << "frequency: " << freq << endl;
00299 cout << "transmit antenna gain: " << Gt << endl;
00300 cout << "receive antenna gain: " << Gr << endl;
00301 cout << "system loss: " << sysLoss << endl;
00302 cout << "path loss exp.: " << pathlossExp_ << endl;
00303 cout << "shadowing deviation: " << std_db_ << endl;
00304 cout << "close-in reference distance: " << dist0_ << endl;
00305 cout << "receiving rate: " << prob << endl;
00306 } else {
00307 cout << "Error: unknown propagation model." << endl;
00308 cout << "Available model: FreeSpace, TwoRayGround, Shadowing" << endl;
00309 return 0;
00310 }
00311
00312 cout << endl << "Receiving threshold RXThresh_ is: " << rxThresh_ << endl;
00313
00314 }