1 // radio.cxx -- implementation of FGRadio
2 // Class to manage radio propagation using the ITM model
3 // Written by Adrian Musceac, started August 2011.
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <simgear/scene/material/mat.hxx>
31 #include <Scenery/scenery.hxx>
33 #define WITH_POINT_TO_POINT 1
37 FGRadioTransmission::FGRadioTransmission() {
39 /** radio parameters (which should probably be set for each radio) */
41 _receiver_sensitivity = -110.0; // typical AM receiver sensitivity seems to be 0.8 microVolt at 12dB SINAD
43 /** AM transmitter power in dBm.
44 * Note this value is calculated from the typical final transistor stage output
45 * small aircraft have portable transmitters which operate at 36 dBm output (4 Watts) others operate in the range 10-20 W
46 * later possibly store this value in aircraft description
47 * ATC comms usually operate high power equipment, thus making the link asymetrical; this is taken care of in propagation routines
48 * Typical output powers for ATC ground equipment, VHF-UHF:
49 * 40 dBm - 10 W (ground, clearance)
50 * 44 dBm - 20 W (tower)
51 * 47 dBm - 50 W (center, sectors)
52 * 50 dBm - 100 W (center, sectors)
53 * 53 dBm - 200 W (sectors, on directional arrays)
55 _transmitter_power = 43.0;
57 _tx_antenna_height = 2.0; // TX antenna height above ground level
59 _rx_antenna_height = 2.0; // RX antenna height above ground level
61 /** pilot plane's antenna gain + AI aircraft antenna gain
62 * real-life gain for conventional monopole/dipole antenna
66 _rx_antenna_gain = 1.0;
67 _tx_antenna_gain = 1.0;
69 _rx_line_losses = 2.0; // to be configured for each station
70 _tx_line_losses = 2.0;
72 _propagation_model = 2; // choose between models via option: realistic radio on/off
73 _terrain_sampling_distance = 90.0; // regular SRTM is 90 meters
76 FGRadioTransmission::~FGRadioTransmission()
81 double FGRadioTransmission::getFrequency(int radio) {
85 freq = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
88 freq = fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz");
91 freq = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
97 /*** TODO: receive multiplayer chat message and voice
99 void FGRadioTransmission::receiveChat(SGGeod tx_pos, double freq, string text, int ground_to_air) {
103 /*** TODO: receive navaid
105 double FGRadioTransmission::receiveNav(SGGeod tx_pos, double freq, int transmission_type) {
107 // typical VOR/LOC transmitter power appears to be 200 Watt ~ 53 dBm
108 // vor/loc typical sensitivity between -107 and -101 dBm
109 // glideslope sensitivity between -85 and -81 dBm
110 if ( _propagation_model == 1) {
111 return LOS_calculate_attenuation(tx_pos, freq, 1);
113 else if ( _propagation_model == 2) {
114 return ITM_calculate_attenuation(tx_pos, freq, 1);
121 /*** Receive ATC radio communication as text
123 void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) {
126 double comm1 = getFrequency(1);
127 double comm2 = getFrequency(2);
128 if ( !(fabs(freq - comm1) <= 0.0001) && !(fabs(freq - comm2) <= 0.0001) ) {
129 //cerr << "Frequency not tuned: " << freq << " Radio1: " << comm1 << " Radio2: " << comm2 << endl;
134 if ( _propagation_model == 0) {
135 fgSetString("/sim/messages/atc", text.c_str());
137 else if ( _propagation_model == 1 ) {
138 // TODO: free space, round earth
139 double signal = LOS_calculate_attenuation(tx_pos, freq, ground_to_air);
141 SG_LOG(SG_GENERAL, SG_BULK, "Signal below receiver minimum sensitivity: " << signal);
142 //cerr << "Signal below receiver minimum sensitivity: " << signal << endl;
146 SG_LOG(SG_GENERAL, SG_BULK, "Signal completely readable: " << signal);
147 //cerr << "Signal completely readable: " << signal << endl;
148 fgSetString("/sim/messages/atc", text.c_str());
149 /** write signal strength above threshold to the property tree
150 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
152 fgSetDouble("/sim/radio/comm1-signal", signal);
155 else if ( _propagation_model == 2 ) {
156 // Use ITM propagation model
157 double signal = ITM_calculate_attenuation(tx_pos, freq, ground_to_air);
159 SG_LOG(SG_GENERAL, SG_BULK, "Signal below receiver minimum sensitivity: " << signal);
160 //cerr << "Signal below receiver minimum sensitivity: " << signal << endl;
163 if ((signal > 0.0) && (signal < 12.0)) {
164 /** for low SNR values implement a way to make the conversation
165 * hard to understand but audible
166 * in the real world, the receiver AGC fails to capture the slope
167 * and the signal, due to being amplitude modulated, decreases volume after demodulation
168 * the workaround below is more akin to what would happen on a FM transmission
169 * therefore the correct way would be to work on the volume
172 string hash_noise = " ";
173 int reps = (int) (fabs(floor(signal - 11.0)) * 2);
174 int t_size = text.size();
175 for (int n = 1; n <= reps; ++n) {
176 int pos = rand() % (t_size -1);
177 text.replace(pos,1, hash_noise);
180 double volume = (fabs(signal - 12.0) / 12);
181 double old_volume = fgGetDouble("/sim/sound/voices/voice/volume");
182 SG_LOG(SG_GENERAL, SG_BULK, "Usable signal at limit: " << signal);
183 //cerr << "Usable signal at limit: " << signal << endl;
184 fgSetDouble("/sim/sound/voices/voice/volume", volume);
185 fgSetString("/sim/messages/atc", text.c_str());
186 fgSetDouble("/sim/radio/comm1-signal", signal);
187 fgSetDouble("/sim/sound/voices/voice/volume", old_volume);
190 SG_LOG(SG_GENERAL, SG_BULK, "Signal completely readable: " << signal);
191 //cerr << "Signal completely readable: " << signal << endl;
192 fgSetString("/sim/messages/atc", text.c_str());
193 /** write signal strength above threshold to the property tree
194 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
196 fgSetDouble("/sim/radio/comm1-signal", signal);
205 /*** Implement radio attenuation
206 based on the Longley-Rice propagation model
208 double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
212 /** ITM default parameters
213 TODO: take them from tile materials (especially for sea)?
215 double eps_dielect=15.0;
216 double sgm_conductivity = 0.005;
219 if( (freq < 118.0) || (freq > 137.0) )
220 frq_mhz = 125.0; // sane value, middle of bandplan
223 int radio_climate = 5; // continental temperate
224 int pol=1; // assuming vertical polarization although this is more complex in reality
225 double conf = 0.90; // 90% of situations and time, take into account speed
229 int p_mode = 0; // propgation mode selector: 0 LOS, 1 diffraction dominant, 2 troposcatter
233 double clutter_loss = 0.0; // loss due to vegetation and urban
234 double tx_pow = _transmitter_power;
235 double ant_gain = _antenna_gain;
238 if(transmission_type == 1)
239 tx_pow = _transmitter_power + 6.0;
241 if((transmission_type == 1) || (transmission_type == 3))
242 ant_gain = _antenna_gain + 3.0; //pilot plane's antenna gain + ground station antenna gain
244 double link_budget = tx_pow - _receiver_sensitivity + ant_gain;
246 FGScenery * scenery = globals->get_scenery();
248 double own_lat = fgGetDouble("/position/latitude-deg");
249 double own_lon = fgGetDouble("/position/longitude-deg");
250 double own_alt_ft = fgGetDouble("/position/altitude-ft");
251 double own_alt= own_alt_ft * SG_FEET_TO_METER;
254 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
256 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
257 SGGeod max_own_pos = SGGeod::fromDegM( own_lon, own_lat, SG_MAX_ELEVATION_M );
258 SGGeoc center = SGGeoc::fromGeod( max_own_pos );
259 SGGeoc own_pos_c = SGGeoc::fromGeod( own_pos );
261 /** position of sender radio antenna (HAAT)
262 sender can be aircraft or ground station
264 double ATC_HAAT = 30.0;
265 double Aircraft_HAAT = 5.0;
266 double sender_alt_ft,sender_alt;
267 double transmitter_height=0.0;
268 double receiver_height=0.0;
269 SGGeod sender_pos = pos;
271 sender_alt_ft = sender_pos.getElevationFt();
272 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
273 SGGeod max_sender_pos = SGGeod::fromGeodM( pos, SG_MAX_ELEVATION_M );
274 SGGeoc sender_pos_c = SGGeoc::fromGeod( sender_pos );
275 //cerr << "ITM:: sender Lat: " << parent->getLatitude() << ", Lon: " << parent->getLongitude() << ", Alt: " << sender_alt << endl;
277 double point_distance= _terrain_sampling_distance;
278 double course = SGGeodesy::courseRad(own_pos_c, sender_pos_c);
279 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
280 double probe_distance = 0.0;
281 /** If distance larger than this value (300 km), assume reception imposssible */
282 if (distance_m > 300000)
284 /** If above 8000 meters, consider LOS mode and calculate free-space att */
285 if (own_alt > 8000) {
286 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
287 SG_LOG(SG_GENERAL, SG_BULK,
288 "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation");
289 //cerr << "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation" << endl;
290 signal = link_budget - dbloss;
295 int max_points = (int)floor(distance_m / point_distance);
296 double delta_last = fmod(distance_m, point_distance);
298 deque<double> _elevations;
299 deque<string> materials;
302 double elevation_under_pilot = 0.0;
303 if (scenery->get_elevation_m( max_own_pos, elevation_under_pilot, NULL )) {
304 receiver_height = own_alt - elevation_under_pilot + 3; //assume antenna located 3 meters above ground
307 double elevation_under_sender = 0.0;
308 if (scenery->get_elevation_m( max_sender_pos, elevation_under_sender, NULL )) {
309 transmitter_height = sender_alt - elevation_under_sender;
312 transmitter_height = sender_alt;
315 if(transmission_type == 1)
316 transmitter_height += ATC_HAAT;
318 transmitter_height += Aircraft_HAAT;
320 SG_LOG(SG_GENERAL, SG_BULK,
321 "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters");
322 cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl;
324 unsigned int e_size = (deque<unsigned>::size_type)max_points;
326 while (_elevations.size() <= e_size) {
327 probe_distance += point_distance;
328 SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance ));
329 const SGMaterial *mat = 0;
330 double elevation_m = 0.0;
332 if (scenery->get_elevation_m( probe, elevation_m, &mat )) {
333 if((transmission_type == 3) || (transmission_type == 4)) {
334 _elevations.push_back(elevation_m);
336 const std::vector<string> mat_names = mat->get_names();
337 materials.push_back(mat_names[0]);
340 materials.push_back("None");
344 _elevations.push_front(elevation_m);
346 const std::vector<string> mat_names = mat->get_names();
347 materials.push_front(mat_names[0]);
350 materials.push_front("None");
355 if((transmission_type == 3) || (transmission_type == 4)) {
356 _elevations.push_back(0.0);
357 materials.push_back("None");
360 _elevations.push_front(0.0);
361 materials.push_front("None");
365 if((transmission_type == 3) || (transmission_type == 4)) {
366 _elevations.push_front(elevation_under_pilot);
367 if (delta_last > (point_distance / 2) ) // only add last point if it's farther than half point_distance
368 _elevations.push_back(elevation_under_sender);
371 _elevations.push_back(elevation_under_pilot);
372 if (delta_last > (point_distance / 2) )
373 _elevations.push_front(elevation_under_sender);
377 double max_alt_between=0.0;
378 for( deque<double>::size_type i = 0; i < _elevations.size(); i++ ) {
379 if (_elevations[i] > max_alt_between) {
380 max_alt_between = _elevations[i];
384 double num_points= (double)_elevations.size();
385 //cerr << "ITM:: Max alt between: " << max_alt_between << ", num points:" << num_points << endl;
386 _elevations.push_front(point_distance);
387 _elevations.push_front(num_points -1);
388 int size = _elevations.size();
389 double itm_elev[size];
390 for(int i=0;i<size;i++) {
391 itm_elev[i]=_elevations[i];
392 //cerr << "ITM:: itm_elev: " << _elevations[i] << endl;
395 if((transmission_type == 3) || (transmission_type == 4)) {
396 // the sender and receiver roles are switched
397 point_to_point(itm_elev, receiver_height, transmitter_height,
398 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
399 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
400 if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) )
401 clutterLoss(frq_mhz, distance_m, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss);
404 point_to_point(itm_elev, transmitter_height, receiver_height,
405 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
406 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
407 if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) )
408 clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss);
410 SG_LOG(SG_GENERAL, SG_BULK,
411 "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
412 cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
414 cerr << "Clutter loss: " << clutter_loss << endl;
415 //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used
417 signal = link_budget - dbloss - clutter_loss;
422 /*** Calculate losses due to vegetation and urban clutter (WIP)
423 * We are only worried about clutter loss, terrain influence
424 * on the first Fresnel zone is calculated in the ITM functions
426 void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm_elev[], deque<string> materials,
427 double transmitter_height, double receiver_height, int p_mode,
428 double horizons[], double &clutter_loss) {
430 distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points
431 if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone
433 int j=1; // first point is TX elevation, last is RX elevation
434 for (int k=3;k < (int)(itm_elev[0]) + 2;k++) {
436 double clutter_height = 0.0; // mean clutter height for a certain terrain type
437 double clutter_density = 0.0; // percent of reflected wave
438 get_material_properties(materials[mat], clutter_height, clutter_density);
439 //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl;
440 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
441 // First Fresnel radius
442 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) );
444 //cerr << "Clutter:: fresnel radius: " << frs_rad << endl;
445 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
447 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
448 double d1 = j * itm_elev[1];
449 if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
450 d1 = (itm_elev[0] - j) * itm_elev[1];
452 double ray_height = (grad * d1) + min_elev;
453 //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl;
454 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
455 double intrusion = fabs(clearance);
456 //cerr << "Clutter:: clearance: " << clearance << endl;
457 if (clearance >= 0) {
460 else if (clearance < 0 && (intrusion < clutter_height)) {
462 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100;
464 else if (clearance < 0 && (intrusion > clutter_height)) {
465 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100;
475 else if (p_mode == 1) { // diffraction
477 if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point
478 int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m );
479 int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m );
480 cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl;
482 /** perform the first pass */
484 int j=1; // first point is TX elevation, 2nd is obstruction elevation
485 for (int k=3;k < num_points_1st + 2;k++) {
486 if (num_points_1st < 1)
488 double clutter_height = 0.0; // mean clutter height for a certain terrain type
489 double clutter_density = 0.0; // percent of reflected wave
490 get_material_properties(materials[mat], clutter_height, clutter_density);
491 //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl;
492 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
493 // First Fresnel radius
494 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) );
496 //cerr << "Clutter:: fresnel radius: " << frs_rad << endl;
497 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
499 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
500 double d1 = j * itm_elev[1];
501 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
502 d1 = (num_points_1st - j) * itm_elev[1];
504 double ray_height = (grad * d1) + min_elev;
505 //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl;
506 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
507 double intrusion = fabs(clearance);
508 //cerr << "Clutter:: clearance: " << clearance << endl;
509 if (clearance >= 0) {
512 else if (clearance < 0 && (intrusion < clutter_height)) {
514 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100;
516 else if (clearance < 0 && (intrusion > clutter_height)) {
517 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100;
527 /** and the second pass */
529 j =1; // first point is diffraction edge, 2nd the RX elevation
530 for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) {
531 if (num_points_2nd < 1)
533 double clutter_height = 0.0; // mean clutter height for a certain terrain type
534 double clutter_density = 0.0; // percent of reflected wave
535 get_material_properties(materials[mat], clutter_height, clutter_density);
536 //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl;
537 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
538 // First Fresnel radius
539 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) );
541 //cerr << "Clutter:: fresnel radius: " << frs_rad << endl;
542 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
544 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
545 double d1 = j * itm_elev[1];
546 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
547 d1 = (num_points_2nd - j) * itm_elev[1];
549 double ray_height = (grad * d1) + min_elev;
550 //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl;
551 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
552 double intrusion = fabs(clearance);
553 //cerr << "Clutter:: clearance: " << clearance << endl;
554 if (clearance >= 0) {
557 else if (clearance < 0 && (intrusion < clutter_height)) {
559 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100;
561 else if (clearance < 0 && (intrusion > clutter_height)) {
562 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100;
572 else { // double horizon: same as single horizon, except there are 3 segments
574 int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m );
575 int num_points_2nd = (int)ceil( (horizons[1] - horizons[0]) * itm_elev[0] / distance_m );
576 int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd;
578 cerr << "Clutter:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl;
580 /** perform the first pass */
582 int j=1; // first point is TX elevation, 2nd is obstruction elevation
583 for (int k=3;k < num_points_1st +2;k++) {
584 if (num_points_1st < 1)
586 double clutter_height = 0.0; // mean clutter height for a certain terrain type
587 double clutter_density = 0.0; // percent of reflected wave
588 get_material_properties(materials[mat], clutter_height, clutter_density);
589 //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl;
590 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
591 // First Fresnel radius
592 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_1st - j) * itm_elev[1] / 1000000) / ( num_points_1st * itm_elev[1] * freq / 1000) );
594 //cerr << "Clutter:: fresnel radius: " << frs_rad << endl;
595 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
597 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
598 double d1 = j * itm_elev[1];
599 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
600 d1 = (num_points_1st - j) * itm_elev[1];
602 double ray_height = (grad * d1) + min_elev;
603 //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl;
604 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
605 double intrusion = fabs(clearance);
606 //cerr << "Clutter:: clearance: " << clearance << endl;
607 if (clearance >= 0) {
610 else if (clearance < 0 && (intrusion < clutter_height)) {
612 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100;
614 else if (clearance < 0 && (intrusion > clutter_height)) {
615 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100;
624 /** and the second pass */
626 j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation
627 for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) {
628 if (num_points_2nd < 1)
630 double clutter_height = 0.0; // mean clutter height for a certain terrain type
631 double clutter_density = 0.0; // percent of reflected wave
632 get_material_properties(materials[mat], clutter_height, clutter_density);
633 //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl;
634 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m;
635 // First Fresnel radius
636 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_2nd - j) * itm_elev[1] / 1000000) / ( num_points_2nd * itm_elev[1] * freq / 1000) );
637 //cerr << "Clutter:: fresnel radius: " << frs_rad << " points2: " << num_points_2nd << " j: " << j << endl;
639 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
641 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height);
642 double d1 = j * itm_elev[1];
643 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) {
644 d1 = (num_points_2nd - j) * itm_elev[1];
646 double ray_height = (grad * d1) + min_elev;
647 //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl;
648 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
649 double intrusion = fabs(clearance);
650 //cerr << "Clutter:: clearance: " << clearance << endl;
651 if (clearance >= 0) {
654 else if (clearance < 0 && (intrusion < clutter_height)) {
656 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100;
658 else if (clearance < 0 && (intrusion > clutter_height)) {
659 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100;
669 /** third and final pass */
671 j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation
672 for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) {
673 if (num_points_3rd < 1)
675 double clutter_height = 0.0; // mean clutter height for a certain terrain type
676 double clutter_density = 0.0; // percent of reflected wave
677 get_material_properties(materials[mat], clutter_height, clutter_density);
678 //cerr << "Clutter:: material: " << materials[mat] << " height: " << clutter_height << ", density: " << clutter_density << endl;
679 double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
680 // First Fresnel radius
681 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (num_points_3rd - j) * itm_elev[1] / 1000000) / ( num_points_3rd * itm_elev[1] * freq / 1000) );
682 cerr << "Clutter:: fresnel radius: " << frs_rad << " points2: " << num_points_3rd << " j: " << j << endl;
684 //cerr << "Clutter:: fresnel radius: " << frs_rad << endl;
685 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
687 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
688 double d1 = j * itm_elev[1];
689 if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
690 d1 = (num_points_3rd - j) * itm_elev[1];
692 double ray_height = (grad * d1) + min_elev;
693 //cerr << "Clutter:: ray height: " << ray_height << " ground height:" << itm_elev[k] << endl;
694 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
695 double intrusion = fabs(clearance);
696 //cerr << "Clutter:: clearance: " << clearance << endl;
697 if (clearance >= 0) {
700 else if (clearance < 0 && (intrusion < clutter_height)) {
702 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * freq/100;
704 else if (clearance < 0 && (intrusion > clutter_height)) {
705 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * freq/100;
717 else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
723 /*** Temporary material properties database
724 * height: median clutter height
725 * density: radiowave attenuation factor
727 void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
729 if(mat_name == "Landmass") {
734 else if(mat_name == "SomeSort") {
739 else if(mat_name == "Island") {
743 else if(mat_name == "Default") {
747 else if(mat_name == "EvergreenBroadCover") {
751 else if(mat_name == "EvergreenForest") {
755 else if(mat_name == "DeciduousBroadCover") {
759 else if(mat_name == "DeciduousForest") {
763 else if(mat_name == "MixedForestCover") {
767 else if(mat_name == "MixedForest") {
771 else if(mat_name == "RainForest") {
775 else if(mat_name == "EvergreenNeedleCover") {
779 else if(mat_name == "WoodedTundraCover") {
783 else if(mat_name == "DeciduousNeedleCover") {
787 else if(mat_name == "ScrubCover") {
791 else if(mat_name == "BuiltUpCover") {
795 else if(mat_name == "Urban") {
799 else if(mat_name == "Construction") {
803 else if(mat_name == "Industrial") {
807 else if(mat_name == "Port") {
811 else if(mat_name == "Town") {
815 else if(mat_name == "SubUrban") {
819 else if(mat_name == "CropWoodCover") {
823 else if(mat_name == "CropWood") {
827 else if(mat_name == "AgroForest") {
838 /*** implement simple LOS propagation model (WIP)
840 double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
842 if( (freq < 118.0) || (freq > 137.0) )
843 frq_mhz = 125.0; // sane value, middle of bandplan
847 double tx_pow = _transmitter_power;
848 double ant_gain = _antenna_gain;
850 double ATC_HAAT = 30.0;
851 double Aircraft_HAAT = 5.0;
852 double sender_alt_ft,sender_alt;
853 double transmitter_height=0.0;
854 double receiver_height=0.0;
855 double own_lat = fgGetDouble("/position/latitude-deg");
856 double own_lon = fgGetDouble("/position/longitude-deg");
857 double own_alt_ft = fgGetDouble("/position/altitude-ft");
858 double own_alt= own_alt_ft * SG_FEET_TO_METER;
860 if(transmission_type == 1)
861 tx_pow = _transmitter_power + 6.0;
863 if((transmission_type == 1) || (transmission_type == 3))
864 ant_gain = _antenna_gain + 3.0; //pilot plane's antenna gain + ground station antenna gain
866 double link_budget = tx_pow - _receiver_sensitivity + ant_gain;
868 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
870 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
872 SGGeod sender_pos = pos;
874 sender_alt_ft = sender_pos.getElevationFt();
875 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
877 receiver_height = own_alt;
878 transmitter_height = sender_alt;
880 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
882 if(transmission_type == 1)
883 transmitter_height += ATC_HAAT;
885 transmitter_height += Aircraft_HAAT;
887 /** radio horizon calculation with wave bending k=4/3 */
888 double receiver_horizon = 4.12 * sqrt(receiver_height);
889 double transmitter_horizon = 4.12 * sqrt(transmitter_height);
890 double total_horizon = receiver_horizon + transmitter_horizon;
892 if (distance_m > total_horizon) {
896 // free-space loss (distance calculation should be changed)
897 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
898 signal = link_budget - dbloss;
899 SG_LOG(SG_GENERAL, SG_BULK,
900 "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm ");
901 //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl;