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 = fgGetDouble("/sim/radio/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
432 if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone
435 for (int k=3;k < (int)(itm_elev[0]) + 2;k++) {
437 double clutter_height = 0.0; // mean clutter height for a certain terrain type
438 double clutter_density = 0.0; // percent of reflected wave
439 get_material_properties(materials[mat], clutter_height, clutter_density);
441 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
442 // First Fresnel radius
443 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) );
446 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
448 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
449 double d1 = j * itm_elev[1];
450 if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
451 d1 = (itm_elev[0] - j) * itm_elev[1];
453 double ray_height = (grad * d1) + min_elev;
455 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
456 double intrusion = fabs(clearance);
458 if (clearance >= 0) {
461 else if (clearance < 0 && (intrusion < clutter_height)) {
463 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
465 else if (clearance < 0 && (intrusion > clutter_height)) {
466 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
476 else if (p_mode == 1) { // diffraction
478 if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point
479 int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m );
480 int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m );
481 cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl;
483 /** perform the first pass */
486 for (int k=3;k < num_points_1st + 2;k++) {
487 if (num_points_1st < 1)
489 double clutter_height = 0.0; // mean clutter height for a certain terrain type
490 double clutter_density = 0.0; // percent of reflected wave
491 get_material_properties(materials[mat], clutter_height, clutter_density);
493 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
494 // First Fresnel radius
495 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) );
498 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
500 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
501 double d1 = j * itm_elev[1];
502 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
503 d1 = (num_points_1st - j) * itm_elev[1];
505 double ray_height = (grad * d1) + min_elev;
507 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
508 double intrusion = fabs(clearance);
510 if (clearance >= 0) {
513 else if (clearance < 0 && (intrusion < clutter_height)) {
515 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
517 else if (clearance < 0 && (intrusion > clutter_height)) {
518 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
528 /** and the second pass */
530 j =1; // first point is diffraction edge, 2nd the RX elevation
531 for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) {
532 if (num_points_2nd < 1)
534 double clutter_height = 0.0; // mean clutter height for a certain terrain type
535 double clutter_density = 0.0; // percent of reflected wave
536 get_material_properties(materials[mat], clutter_height, clutter_density);
538 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
539 // First Fresnel radius
540 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) );
543 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
545 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
546 double d1 = j * itm_elev[1];
547 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
548 d1 = (num_points_2nd - j) * itm_elev[1];
550 double ray_height = (grad * d1) + min_elev;
552 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
553 double intrusion = fabs(clearance);
555 if (clearance >= 0) {
558 else if (clearance < 0 && (intrusion < clutter_height)) {
560 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
562 else if (clearance < 0 && (intrusion > clutter_height)) {
563 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
573 else { // double horizon: same as single horizon, except there are 3 segments
575 int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m );
576 int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m );
577 int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd;
578 cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl;
579 cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl;
581 /** perform the first pass */
583 int j=1; // first point is TX elevation, 2nd is obstruction elevation
584 for (int k=3;k < num_points_1st +2;k++) {
585 if (num_points_1st < 1)
587 double clutter_height = 0.0; // mean clutter height for a certain terrain type
588 double clutter_density = 0.0; // percent of reflected wave
589 get_material_properties(materials[mat], clutter_height, clutter_density);
591 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
592 // First Fresnel radius
593 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) );
596 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
598 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
599 double d1 = j * itm_elev[1];
600 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
601 d1 = (num_points_1st - j) * itm_elev[1];
603 double ray_height = (grad * d1) + min_elev;
605 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
606 double intrusion = fabs(clearance);
608 if (clearance >= 0) {
611 else if (clearance < 0 && (intrusion < clutter_height)) {
613 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
615 else if (clearance < 0 && (intrusion > clutter_height)) {
616 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
625 /** and the second pass */
627 j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation
628 for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) {
629 if (num_points_2nd < 1)
631 double clutter_height = 0.0; // mean clutter height for a certain terrain type
632 double clutter_density = 0.0; // percent of reflected wave
633 get_material_properties(materials[mat], clutter_height, clutter_density);
635 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m;
636 // First Fresnel radius
637 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) );
638 //cerr << "Double horizon second pass:: fresnel radius: " << frs_rad << " points2: " << num_points_2nd << " j: " << j << endl;
640 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
642 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height);
643 double d1 = j * itm_elev[1];
644 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) {
645 d1 = (num_points_2nd - j) * itm_elev[1];
647 double ray_height = (grad * d1) + min_elev;
649 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
650 double intrusion = fabs(clearance);
652 if (clearance >= 0) {
655 else if (clearance < 0 && (intrusion < clutter_height)) {
657 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
659 else if (clearance < 0 && (intrusion > clutter_height)) {
660 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
670 /** third and final pass */
672 j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation
673 for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) {
674 if (num_points_3rd < 1)
676 double clutter_height = 0.0; // mean clutter height for a certain terrain type
677 double clutter_density = 0.0; // percent of reflected wave
678 get_material_properties(materials[mat], clutter_height, clutter_density);
680 double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
681 // First Fresnel radius
682 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) );
683 //cerr << "Double horizon third pass:: fresnel radius: " << frs_rad << " points3: " << num_points_3rd << " j: " << j << endl;
686 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
688 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
689 double d1 = j * itm_elev[1];
690 if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
691 d1 = (num_points_3rd - j) * itm_elev[1];
693 double ray_height = (grad * d1) + min_elev;
695 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
696 double intrusion = fabs(clearance);
698 if (clearance >= 0) {
701 else if (clearance < 0 && (intrusion < clutter_height)) {
703 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
705 else if (clearance < 0 && (intrusion > clutter_height)) {
706 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
718 else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
724 /*** Temporary material properties database
725 * height: median clutter height
726 * density: radiowave attenuation factor
728 void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
730 if(mat_name == "Landmass") {
735 else if(mat_name == "SomeSort") {
740 else if(mat_name == "Island") {
744 else if(mat_name == "Default") {
748 else if(mat_name == "EvergreenBroadCover") {
752 else if(mat_name == "EvergreenForest") {
756 else if(mat_name == "DeciduousBroadCover") {
760 else if(mat_name == "DeciduousForest") {
764 else if(mat_name == "MixedForestCover") {
768 else if(mat_name == "MixedForest") {
772 else if(mat_name == "RainForest") {
776 else if(mat_name == "EvergreenNeedleCover") {
780 else if(mat_name == "WoodedTundraCover") {
784 else if(mat_name == "DeciduousNeedleCover") {
788 else if(mat_name == "ScrubCover") {
792 else if(mat_name == "BuiltUpCover") {
796 else if(mat_name == "Urban") {
800 else if(mat_name == "Construction") {
804 else if(mat_name == "Industrial") {
808 else if(mat_name == "Port") {
812 else if(mat_name == "Town") {
816 else if(mat_name == "SubUrban") {
820 else if(mat_name == "CropWoodCover") {
824 else if(mat_name == "CropWood") {
828 else if(mat_name == "AgroForest") {
839 /*** implement simple LOS propagation model (WIP)
841 double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
843 if( (freq < 118.0) || (freq > 137.0) )
844 frq_mhz = 125.0; // sane value, middle of bandplan
848 double tx_pow = _transmitter_power;
849 double ant_gain = _antenna_gain;
851 double ATC_HAAT = 30.0;
852 double Aircraft_HAAT = 5.0;
853 double sender_alt_ft,sender_alt;
854 double transmitter_height=0.0;
855 double receiver_height=0.0;
856 double own_lat = fgGetDouble("/position/latitude-deg");
857 double own_lon = fgGetDouble("/position/longitude-deg");
858 double own_alt_ft = fgGetDouble("/position/altitude-ft");
859 double own_alt= own_alt_ft * SG_FEET_TO_METER;
861 if(transmission_type == 1)
862 tx_pow = _transmitter_power + 6.0;
864 if((transmission_type == 1) || (transmission_type == 3))
865 ant_gain = _antenna_gain + 3.0; //pilot plane's antenna gain + ground station antenna gain
867 double link_budget = tx_pow - _receiver_sensitivity + ant_gain;
869 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
871 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
873 SGGeod sender_pos = pos;
875 sender_alt_ft = sender_pos.getElevationFt();
876 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
878 receiver_height = own_alt;
879 transmitter_height = sender_alt;
881 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
883 if(transmission_type == 1)
884 transmitter_height += ATC_HAAT;
886 transmitter_height += Aircraft_HAAT;
888 /** radio horizon calculation with wave bending k=4/3 */
889 double receiver_horizon = 4.12 * sqrt(receiver_height);
890 double transmitter_horizon = 4.12 * sqrt(transmitter_height);
891 double total_horizon = receiver_horizon + transmitter_horizon;
893 if (distance_m > total_horizon) {
897 // free-space loss (distance calculation should be changed)
898 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
899 signal = link_budget - dbloss;
900 SG_LOG(SG_GENERAL, SG_BULK,
901 "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm ");
902 //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl;