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.
31 #include <simgear/scene/material/mat.hxx>
32 #include <Scenery/scenery.hxx>
34 #define WITH_POINT_TO_POINT 1
38 FGRadioTransmission::FGRadioTransmission() {
40 /** radio parameters (which should probably be set for each radio) */
42 _receiver_sensitivity = -110.0; // typical AM receiver sensitivity seems to be 0.8 microVolt at 12dB SINAD
44 /** AM transmitter power in dBm.
45 * Note this value is calculated from the typical final transistor stage output
46 * small aircraft have portable transmitters which operate at 36 dBm output (4 Watts) others operate in the range 10-20 W
47 * later possibly store this value in aircraft description
48 * ATC comms usually operate high power equipment, thus making the link asymetrical; this is taken care of in propagation routines
49 * Typical output powers for ATC ground equipment, VHF-UHF:
50 * 40 dBm - 10 W (ground, clearance)
51 * 44 dBm - 20 W (tower)
52 * 47 dBm - 50 W (center, sectors)
53 * 50 dBm - 100 W (center, sectors)
54 * 53 dBm - 200 W (sectors, on directional arrays)
56 _transmitter_power = 43.0;
58 _tx_antenna_height = 2.0; // TX antenna height above ground level
60 _rx_antenna_height = 2.0; // RX antenna height above ground level
62 /** pilot plane's antenna gain + AI aircraft antenna gain
63 * real-life gain for conventional monopole/dipole antenna
67 _rx_antenna_gain = 1.0;
68 _tx_antenna_gain = 1.0;
70 _rx_line_losses = 2.0; // to be configured for each station
71 _tx_line_losses = 2.0;
73 _propagation_model = 2; // choose between models via option: realistic radio on/off
74 _terrain_sampling_distance = fgGetDouble("/sim/radio/sampling-distance", 90.0); // regular SRTM is 90 meters
77 FGRadioTransmission::~FGRadioTransmission()
82 double FGRadioTransmission::getFrequency(int radio) {
86 freq = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
89 freq = fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz");
92 freq = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
98 /*** TODO: receive multiplayer chat message and voice
100 void FGRadioTransmission::receiveChat(SGGeod tx_pos, double freq, string text, int ground_to_air) {
104 /*** TODO: receive navaid
106 double FGRadioTransmission::receiveNav(SGGeod tx_pos, double freq, int transmission_type) {
108 // typical VOR/LOC transmitter power appears to be 200 Watt ~ 53 dBm
109 // vor/loc typical sensitivity between -107 and -101 dBm
110 // glideslope sensitivity between -85 and -81 dBm
111 if ( _propagation_model == 1) {
112 return LOS_calculate_attenuation(tx_pos, freq, 1);
114 else if ( _propagation_model == 2) {
115 return ITM_calculate_attenuation(tx_pos, freq, 1);
122 /*** Receive ATC radio communication as text
124 void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) {
127 double comm1 = getFrequency(1);
128 double comm2 = getFrequency(2);
129 if ( !(fabs(freq - comm1) <= 0.0001) && !(fabs(freq - comm2) <= 0.0001) ) {
130 //cerr << "Frequency not tuned: " << freq << " Radio1: " << comm1 << " Radio2: " << comm2 << endl;
135 if ( _propagation_model == 0) {
136 fgSetString("/sim/messages/atc", text.c_str());
138 else if ( _propagation_model == 1 ) {
139 // TODO: free space, round earth
140 double signal = LOS_calculate_attenuation(tx_pos, freq, ground_to_air);
142 SG_LOG(SG_GENERAL, SG_BULK, "Signal below receiver minimum sensitivity: " << signal);
143 //cerr << "Signal below receiver minimum sensitivity: " << signal << endl;
147 SG_LOG(SG_GENERAL, SG_BULK, "Signal completely readable: " << signal);
148 //cerr << "Signal completely readable: " << signal << endl;
149 fgSetString("/sim/messages/atc", text.c_str());
150 /** write signal strength above threshold to the property tree
151 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
153 fgSetDouble("/sim/radio/comm1-signal", signal);
156 else if ( _propagation_model == 2 ) {
157 // Use ITM propagation model
158 double signal = ITM_calculate_attenuation(tx_pos, freq, ground_to_air);
160 SG_LOG(SG_GENERAL, SG_BULK, "Signal below receiver minimum sensitivity: " << signal);
161 //cerr << "Signal below receiver minimum sensitivity: " << signal << endl;
164 if ((signal > 0.0) && (signal < 12.0)) {
165 /** for low SNR values implement a way to make the conversation
166 * hard to understand but audible
167 * in the real world, the receiver AGC fails to capture the slope
168 * and the signal, due to being amplitude modulated, decreases volume after demodulation
169 * the workaround below is more akin to what would happen on a FM transmission
170 * therefore the correct way would be to work on the volume
173 string hash_noise = " ";
174 int reps = (int) (fabs(floor(signal - 11.0)) * 2);
175 int t_size = text.size();
176 for (int n = 1; n <= reps; ++n) {
177 int pos = rand() % (t_size -1);
178 text.replace(pos,1, hash_noise);
181 double volume = (fabs(signal - 12.0) / 12);
182 double old_volume = fgGetDouble("/sim/sound/voices/voice/volume");
183 SG_LOG(SG_GENERAL, SG_BULK, "Usable signal at limit: " << signal);
184 //cerr << "Usable signal at limit: " << signal << endl;
185 fgSetDouble("/sim/sound/voices/voice/volume", volume);
186 fgSetString("/sim/messages/atc", text.c_str());
187 fgSetDouble("/sim/radio/comm1-signal", signal);
188 fgSetDouble("/sim/sound/voices/voice/volume", old_volume);
191 SG_LOG(SG_GENERAL, SG_BULK, "Signal completely readable: " << signal);
192 //cerr << "Signal completely readable: " << signal << endl;
193 fgSetString("/sim/messages/atc", text.c_str());
194 /** write signal strength above threshold to the property tree
195 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
197 fgSetDouble("/sim/radio/comm1-signal", signal);
206 /*** Implement radio attenuation
207 based on the Longley-Rice propagation model
209 double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
213 /** ITM default parameters
214 TODO: take them from tile materials (especially for sea)?
216 double eps_dielect=15.0;
217 double sgm_conductivity = 0.005;
220 if( (freq < 118.0) || (freq > 137.0) )
221 frq_mhz = 125.0; // sane value, middle of bandplan
224 int radio_climate = 5; // continental temperate
225 int pol=1; // assuming vertical polarization although this is more complex in reality
226 double conf = 0.90; // 90% of situations and time, take into account speed
230 int p_mode = 0; // propgation mode selector: 0 LOS, 1 diffraction dominant, 2 troposcatter
234 double clutter_loss = 0.0; // loss due to vegetation and urban
235 double tx_pow = _transmitter_power;
236 double ant_gain = _antenna_gain;
239 if(transmission_type == 1)
240 tx_pow = _transmitter_power + 6.0;
242 if((transmission_type == 1) || (transmission_type == 3))
243 ant_gain = _antenna_gain + 3.0; //pilot plane's antenna gain + ground station antenna gain
245 double link_budget = tx_pow - _receiver_sensitivity + ant_gain;
247 FGScenery * scenery = globals->get_scenery();
249 double own_lat = fgGetDouble("/position/latitude-deg");
250 double own_lon = fgGetDouble("/position/longitude-deg");
251 double own_alt_ft = fgGetDouble("/position/altitude-ft");
252 double own_alt= own_alt_ft * SG_FEET_TO_METER;
255 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
257 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
258 SGGeod max_own_pos = SGGeod::fromDegM( own_lon, own_lat, SG_MAX_ELEVATION_M );
259 SGGeoc center = SGGeoc::fromGeod( max_own_pos );
260 SGGeoc own_pos_c = SGGeoc::fromGeod( own_pos );
262 /** position of sender radio antenna (HAAT)
263 sender can be aircraft or ground station
265 double ATC_HAAT = 30.0;
266 double Aircraft_HAAT = 5.0;
267 double sender_alt_ft,sender_alt;
268 double transmitter_height=0.0;
269 double receiver_height=0.0;
270 SGGeod sender_pos = pos;
272 sender_alt_ft = sender_pos.getElevationFt();
273 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
274 SGGeod max_sender_pos = SGGeod::fromGeodM( pos, SG_MAX_ELEVATION_M );
275 SGGeoc sender_pos_c = SGGeoc::fromGeod( sender_pos );
276 //cerr << "ITM:: sender Lat: " << parent->getLatitude() << ", Lon: " << parent->getLongitude() << ", Alt: " << sender_alt << endl;
278 double point_distance= _terrain_sampling_distance;
279 double course = SGGeodesy::courseRad(own_pos_c, sender_pos_c);
280 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
281 double probe_distance = 0.0;
282 /** If distance larger than this value (300 km), assume reception imposssible */
283 if (distance_m > 300000)
285 /** If above 8000 meters, consider LOS mode and calculate free-space att */
286 if (own_alt > 8000) {
287 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
288 SG_LOG(SG_GENERAL, SG_BULK,
289 "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation");
290 //cerr << "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation" << endl;
291 signal = link_budget - dbloss;
296 int max_points = (int)floor(distance_m / point_distance);
297 double delta_last = fmod(distance_m, point_distance);
299 deque<double> _elevations;
300 deque<string> materials;
303 double elevation_under_pilot = 0.0;
304 if (scenery->get_elevation_m( max_own_pos, elevation_under_pilot, NULL )) {
305 receiver_height = own_alt - elevation_under_pilot + 3; //assume antenna located 3 meters above ground
308 double elevation_under_sender = 0.0;
309 if (scenery->get_elevation_m( max_sender_pos, elevation_under_sender, NULL )) {
310 transmitter_height = sender_alt - elevation_under_sender;
313 transmitter_height = sender_alt;
316 if(transmission_type == 1)
317 transmitter_height += ATC_HAAT;
319 transmitter_height += Aircraft_HAAT;
321 SG_LOG(SG_GENERAL, SG_BULK,
322 "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters");
323 cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl;
325 unsigned int e_size = (deque<unsigned>::size_type)max_points;
327 while (_elevations.size() <= e_size) {
328 probe_distance += point_distance;
329 SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance ));
330 const SGMaterial *mat = 0;
331 double elevation_m = 0.0;
333 if (scenery->get_elevation_m( probe, elevation_m, &mat )) {
334 if((transmission_type == 3) || (transmission_type == 4)) {
335 _elevations.push_back(elevation_m);
337 const std::vector<string> mat_names = mat->get_names();
338 materials.push_back(mat_names[0]);
341 materials.push_back("None");
345 _elevations.push_front(elevation_m);
347 const std::vector<string> mat_names = mat->get_names();
348 materials.push_front(mat_names[0]);
351 materials.push_front("None");
356 if((transmission_type == 3) || (transmission_type == 4)) {
357 _elevations.push_back(0.0);
358 materials.push_back("None");
361 _elevations.push_front(0.0);
362 materials.push_front("None");
366 if((transmission_type == 3) || (transmission_type == 4)) {
367 _elevations.push_front(elevation_under_pilot);
368 if (delta_last > (point_distance / 2) ) // only add last point if it's farther than half point_distance
369 _elevations.push_back(elevation_under_sender);
372 _elevations.push_back(elevation_under_pilot);
373 if (delta_last > (point_distance / 2) )
374 _elevations.push_front(elevation_under_sender);
378 double max_alt_between=0.0;
379 for( deque<double>::size_type i = 0; i < _elevations.size(); i++ ) {
380 if (_elevations[i] > max_alt_between) {
381 max_alt_between = _elevations[i];
385 double num_points= (double)_elevations.size();
386 //cerr << "ITM:: Max alt between: " << max_alt_between << ", num points:" << num_points << endl;
387 _elevations.push_front(point_distance);
388 _elevations.push_front(num_points -1);
389 int size = _elevations.size();
390 double itm_elev[size];
391 for(int i=0;i<size;i++) {
392 itm_elev[i]=_elevations[i];
393 //cerr << "ITM:: itm_elev: " << _elevations[i] << endl;
396 if((transmission_type == 3) || (transmission_type == 4)) {
397 // the sender and receiver roles are switched
398 point_to_point(itm_elev, receiver_height, transmitter_height,
399 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
400 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
401 if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) )
402 clutterLoss(frq_mhz, distance_m, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss);
405 point_to_point(itm_elev, transmitter_height, receiver_height,
406 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
407 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
408 if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) )
409 clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss);
411 SG_LOG(SG_GENERAL, SG_BULK,
412 "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
413 cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
415 cerr << "Clutter loss: " << clutter_loss << endl;
416 //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used
418 signal = link_budget - dbloss - clutter_loss;
423 /*** Calculate losses due to vegetation and urban clutter (WIP)
424 * We are only worried about clutter loss, terrain influence
425 * on the first Fresnel zone is calculated in the ITM functions
427 void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm_elev[], deque<string> materials,
428 double transmitter_height, double receiver_height, int p_mode,
429 double horizons[], double &clutter_loss) {
431 distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points
433 if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone
436 for (int k=3;k < (int)(itm_elev[0]) + 2;k++) {
438 double clutter_height = 0.0; // mean clutter height for a certain terrain type
439 double clutter_density = 0.0; // percent of reflected wave
440 get_material_properties(materials[mat], clutter_height, clutter_density);
442 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
443 // First Fresnel radius
444 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) );
447 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
449 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
450 double d1 = j * itm_elev[1];
451 if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
452 d1 = (itm_elev[0] - j) * itm_elev[1];
454 double ray_height = (grad * d1) + min_elev;
456 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
457 double intrusion = fabs(clearance);
459 if (clearance >= 0) {
462 else if (clearance < 0 && (intrusion < clutter_height)) {
464 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
466 else if (clearance < 0 && (intrusion > clutter_height)) {
467 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
477 else if (p_mode == 1) { // diffraction
479 if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point
480 int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m );
481 int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m );
482 //cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl;
484 /** perform the first pass */
487 for (int k=3;k < num_points_1st + 2;k++) {
488 if (num_points_1st < 1)
490 double clutter_height = 0.0; // mean clutter height for a certain terrain type
491 double clutter_density = 0.0; // percent of reflected wave
492 get_material_properties(materials[mat], clutter_height, clutter_density);
494 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
495 // First Fresnel radius
496 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) );
499 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
501 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
502 double d1 = j * itm_elev[1];
503 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
504 d1 = (num_points_1st - j) * itm_elev[1];
506 double ray_height = (grad * d1) + min_elev;
508 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
509 double intrusion = fabs(clearance);
511 if (clearance >= 0) {
514 else if (clearance < 0 && (intrusion < clutter_height)) {
516 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
518 else if (clearance < 0 && (intrusion > clutter_height)) {
519 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
529 /** and the second pass */
531 j =1; // first point is diffraction edge, 2nd the RX elevation
532 for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) {
533 if (num_points_2nd < 1)
535 double clutter_height = 0.0; // mean clutter height for a certain terrain type
536 double clutter_density = 0.0; // percent of reflected wave
537 get_material_properties(materials[mat], clutter_height, clutter_density);
539 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
540 // First Fresnel radius
541 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) );
544 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
546 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
547 double d1 = j * itm_elev[1];
548 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
549 d1 = (num_points_2nd - j) * itm_elev[1];
551 double ray_height = (grad * d1) + min_elev;
553 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
554 double intrusion = fabs(clearance);
556 if (clearance >= 0) {
559 else if (clearance < 0 && (intrusion < clutter_height)) {
561 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
563 else if (clearance < 0 && (intrusion > clutter_height)) {
564 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
574 else { // double horizon: same as single horizon, except there are 3 segments
576 int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m );
577 int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m );
578 int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd;
579 //cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl;
580 //cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl;
582 /** perform the first pass */
584 int j=1; // first point is TX elevation, 2nd is obstruction elevation
585 for (int k=3;k < num_points_1st +2;k++) {
586 if (num_points_1st < 1)
588 double clutter_height = 0.0; // mean clutter height for a certain terrain type
589 double clutter_density = 0.0; // percent of reflected wave
590 get_material_properties(materials[mat], clutter_height, clutter_density);
592 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
593 // First Fresnel radius
594 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) );
597 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
599 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
600 double d1 = j * itm_elev[1];
601 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
602 d1 = (num_points_1st - j) * itm_elev[1];
604 double ray_height = (grad * d1) + min_elev;
606 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
607 double intrusion = fabs(clearance);
609 if (clearance >= 0) {
612 else if (clearance < 0 && (intrusion < clutter_height)) {
614 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
616 else if (clearance < 0 && (intrusion > clutter_height)) {
617 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
626 /** and the second pass */
628 j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation
629 for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) {
630 if (num_points_2nd < 1)
632 double clutter_height = 0.0; // mean clutter height for a certain terrain type
633 double clutter_density = 0.0; // percent of reflected wave
634 get_material_properties(materials[mat], clutter_height, clutter_density);
636 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m;
637 // First Fresnel radius
638 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) );
641 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
643 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height);
644 double d1 = j * itm_elev[1];
645 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) {
646 d1 = (num_points_2nd - j) * itm_elev[1];
648 double ray_height = (grad * d1) + min_elev;
650 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
651 double intrusion = fabs(clearance);
653 if (clearance >= 0) {
656 else if (clearance < 0 && (intrusion < clutter_height)) {
658 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
660 else if (clearance < 0 && (intrusion > clutter_height)) {
661 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
671 /** third and final pass */
673 j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation
674 for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) {
675 if (num_points_3rd < 1)
677 double clutter_height = 0.0; // mean clutter height for a certain terrain type
678 double clutter_density = 0.0; // percent of reflected wave
679 get_material_properties(materials[mat], clutter_height, clutter_density);
681 double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
682 // First Fresnel radius
683 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) );
687 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
689 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
690 double d1 = j * itm_elev[1];
691 if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
692 d1 = (num_points_3rd - j) * itm_elev[1];
694 double ray_height = (grad * d1) + min_elev;
696 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
697 double intrusion = fabs(clearance);
699 if (clearance >= 0) {
702 else if (clearance < 0 && (intrusion < clutter_height)) {
704 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
706 else if (clearance < 0 && (intrusion > clutter_height)) {
707 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
719 else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
725 /*** Temporary material properties database
726 * height: median clutter height
727 * density: radiowave attenuation factor
729 void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
731 if(mat_name == "Landmass") {
736 else if(mat_name == "SomeSort") {
741 else if(mat_name == "Island") {
745 else if(mat_name == "Default") {
749 else if(mat_name == "EvergreenBroadCover") {
753 else if(mat_name == "EvergreenForest") {
757 else if(mat_name == "DeciduousBroadCover") {
761 else if(mat_name == "DeciduousForest") {
765 else if(mat_name == "MixedForestCover") {
769 else if(mat_name == "MixedForest") {
773 else if(mat_name == "RainForest") {
777 else if(mat_name == "EvergreenNeedleCover") {
781 else if(mat_name == "WoodedTundraCover") {
785 else if(mat_name == "DeciduousNeedleCover") {
789 else if(mat_name == "ScrubCover") {
793 else if(mat_name == "BuiltUpCover") {
797 else if(mat_name == "Urban") {
801 else if(mat_name == "Construction") {
805 else if(mat_name == "Industrial") {
809 else if(mat_name == "Port") {
813 else if(mat_name == "Town") {
817 else if(mat_name == "SubUrban") {
821 else if(mat_name == "CropWoodCover") {
825 else if(mat_name == "CropWood") {
829 else if(mat_name == "AgroForest") {
840 /*** implement simple LOS propagation model (WIP)
842 double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
844 if( (freq < 118.0) || (freq > 137.0) )
845 frq_mhz = 125.0; // sane value, middle of bandplan
849 double tx_pow = _transmitter_power;
850 double ant_gain = _antenna_gain;
852 double ATC_HAAT = 30.0;
853 double Aircraft_HAAT = 5.0;
854 double sender_alt_ft,sender_alt;
855 double transmitter_height=0.0;
856 double receiver_height=0.0;
857 double own_lat = fgGetDouble("/position/latitude-deg");
858 double own_lon = fgGetDouble("/position/longitude-deg");
859 double own_alt_ft = fgGetDouble("/position/altitude-ft");
860 double own_alt= own_alt_ft * SG_FEET_TO_METER;
862 if(transmission_type == 1)
863 tx_pow = _transmitter_power + 6.0;
865 if((transmission_type == 1) || (transmission_type == 3))
866 ant_gain = _antenna_gain + 3.0; //pilot plane's antenna gain + ground station antenna gain
868 double link_budget = tx_pow - _receiver_sensitivity + ant_gain;
870 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
872 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
874 SGGeod sender_pos = pos;
876 sender_alt_ft = sender_pos.getElevationFt();
877 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
879 receiver_height = own_alt;
880 transmitter_height = sender_alt;
882 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
884 if(transmission_type == 1)
885 transmitter_height += ATC_HAAT;
887 transmitter_height += Aircraft_HAAT;
889 /** radio horizon calculation with wave bending k=4/3 */
890 double receiver_horizon = 4.12 * sqrt(receiver_height);
891 double transmitter_horizon = 4.12 * sqrt(transmitter_height);
892 double total_horizon = receiver_horizon + transmitter_horizon;
894 if (distance_m > total_horizon) {
898 // free-space loss (distance calculation should be changed)
899 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
900 signal = link_budget - dbloss;
901 SG_LOG(SG_GENERAL, SG_BULK,
902 "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm ");
903 //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl;