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() {
40 _receiver_sensitivity = -110.0; // typical AM receiver sensitivity seems to be 0.8 microVolt at 12dB SINAD
42 /** AM transmitter power in dBm.
43 * Typical output powers for ATC ground equipment, VHF-UHF:
44 * 40 dBm - 10 W (ground, clearance)
45 * 44 dBm - 20 W (tower)
46 * 47 dBm - 50 W (center, sectors)
47 * 50 dBm - 100 W (center, sectors)
48 * 53 dBm - 200 W (sectors, on directional arrays)
50 _transmitter_power = 43.0;
52 _tx_antenna_height = 2.0; // TX antenna height above ground level
54 _rx_antenna_height = 2.0; // RX antenna height above ground level
57 _rx_antenna_gain = 1.0; // gain expressed in dBi
58 _tx_antenna_gain = 1.0;
60 _rx_line_losses = 2.0; // to be configured for each station
61 _tx_line_losses = 2.0;
63 _polarization = 1; // default vertical
65 _propagation_model = 2;
66 _terrain_sampling_distance = fgGetDouble("/sim/radio/sampling-distance", 90.0); // regular SRTM is 90 meters
69 FGRadioTransmission::~FGRadioTransmission()
74 double FGRadioTransmission::getFrequency(int radio) {
78 freq = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
81 freq = fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz");
84 freq = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
90 /*** TODO: receive multiplayer chat message and voice
92 void FGRadioTransmission::receiveChat(SGGeod tx_pos, double freq, string text, int ground_to_air) {
96 /*** TODO: receive navaid
98 double FGRadioTransmission::receiveNav(SGGeod tx_pos, double freq, int transmission_type) {
100 // typical VOR/LOC transmitter power appears to be 200 Watt ~ 53 dBm
101 // vor/loc typical sensitivity between -107 and -101 dBm
102 // glideslope sensitivity between -85 and -81 dBm
103 if ( _propagation_model == 1) {
104 return LOS_calculate_attenuation(tx_pos, freq, 1);
106 else if ( _propagation_model == 2) {
107 return ITM_calculate_attenuation(tx_pos, freq, 1);
114 /*** Receive ATC radio communication as text
116 void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) {
119 if(ground_to_air == 1) {
120 _transmitter_power += 6.0;
121 _tx_antenna_height += 30.0;
122 _tx_antenna_gain += 3.0;
126 double comm1 = getFrequency(1);
127 double comm2 = getFrequency(2);
128 if ( !(fabs(freq - comm1) <= 0.0001) && !(fabs(freq - comm2) <= 0.0001) ) {
133 if ( _propagation_model == 0) {
134 fgSetString("/sim/messages/atc", text.c_str());
136 else if ( _propagation_model == 1 ) {
137 // TODO: free space, round earth
138 double signal = LOS_calculate_attenuation(tx_pos, freq, ground_to_air);
144 fgSetString("/sim/messages/atc", text.c_str());
145 /** write signal strength above threshold to the property tree
146 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
148 fgSetDouble("/sim/radio/comm1-signal", signal);
151 else if ( _propagation_model == 2 ) {
152 // Use ITM propagation model
153 double signal = ITM_calculate_attenuation(tx_pos, freq, ground_to_air);
157 if ((signal > 0.0) && (signal < 12.0)) {
158 /** for low SNR values implement a way to make the conversation
159 * hard to understand but audible
160 * in the real world, the receiver AGC fails to capture the slope
161 * and the signal, due to being amplitude modulated, decreases volume after demodulation
162 * the workaround below is more akin to what would happen on a FM transmission
163 * therefore the correct way would be to work on the volume
166 string hash_noise = " ";
167 int reps = (int) (fabs(floor(signal - 11.0)) * 2);
168 int t_size = text.size();
169 for (int n = 1; n <= reps; ++n) {
170 int pos = rand() % (t_size -1);
171 text.replace(pos,1, hash_noise);
174 double volume = (fabs(signal - 12.0) / 12);
175 double old_volume = fgGetDouble("/sim/sound/voices/voice/volume");
176 SG_LOG(SG_GENERAL, SG_BULK, "Usable signal at limit: " << signal);
177 //cerr << "Usable signal at limit: " << signal << endl;
178 fgSetDouble("/sim/sound/voices/voice/volume", volume);
179 fgSetString("/sim/messages/atc", text.c_str());
180 fgSetDouble("/sim/radio/comm1-signal", signal);
181 fgSetDouble("/sim/sound/voices/voice/volume", old_volume);
184 fgSetString("/sim/messages/atc", text.c_str());
185 /** write signal strength above threshold to the property tree
186 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
188 fgSetDouble("/sim/radio/comm1-signal", signal);
197 /*** Implement radio attenuation
198 based on the Longley-Rice propagation model
200 double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
204 /** ITM default parameters
205 TODO: take them from tile materials (especially for sea)?
207 double eps_dielect=15.0;
208 double sgm_conductivity = 0.005;
211 if( (freq < 118.0) || (freq > 137.0) )
212 frq_mhz = 125.0; // sane value, middle of bandplan
215 int radio_climate = 5; // continental temperate
216 int pol= _polarization;
217 double conf = 0.90; // 90% of situations and time, take into account speed
221 int p_mode = 0; // propgation mode selector: 0 LOS, 1 diffraction dominant, 2 troposcatter
225 double clutter_loss = 0.0; // loss due to vegetation and urban
226 double tx_pow = _transmitter_power;
227 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
231 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
233 FGScenery * scenery = globals->get_scenery();
235 double own_lat = fgGetDouble("/position/latitude-deg");
236 double own_lon = fgGetDouble("/position/longitude-deg");
237 double own_alt_ft = fgGetDouble("/position/altitude-ft");
238 double own_alt= own_alt_ft * SG_FEET_TO_METER;
241 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
243 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
244 SGGeod max_own_pos = SGGeod::fromDegM( own_lon, own_lat, SG_MAX_ELEVATION_M );
245 SGGeoc center = SGGeoc::fromGeod( max_own_pos );
246 SGGeoc own_pos_c = SGGeoc::fromGeod( own_pos );
249 double sender_alt_ft,sender_alt;
250 double transmitter_height=0.0;
251 double receiver_height=0.0;
252 SGGeod sender_pos = pos;
254 sender_alt_ft = sender_pos.getElevationFt();
255 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
256 SGGeod max_sender_pos = SGGeod::fromGeodM( pos, SG_MAX_ELEVATION_M );
257 SGGeoc sender_pos_c = SGGeoc::fromGeod( sender_pos );
258 //cerr << "ITM:: sender Lat: " << parent->getLatitude() << ", Lon: " << parent->getLongitude() << ", Alt: " << sender_alt << endl;
260 double point_distance= _terrain_sampling_distance;
261 double course = SGGeodesy::courseRad(own_pos_c, sender_pos_c);
262 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
263 double probe_distance = 0.0;
264 /** If distance larger than this value (300 km), assume reception imposssible */
265 if (distance_m > 300000)
267 /** If above 8000 meters, consider LOS mode and calculate free-space att */
268 if (own_alt > 8000) {
269 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
270 SG_LOG(SG_GENERAL, SG_BULK,
271 "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation");
272 //cerr << "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation" << endl;
273 signal = link_budget - dbloss;
278 int max_points = (int)floor(distance_m / point_distance);
279 double delta_last = fmod(distance_m, point_distance);
281 deque<double> _elevations;
282 deque<string> materials;
285 double elevation_under_pilot = 0.0;
286 if (scenery->get_elevation_m( max_own_pos, elevation_under_pilot, NULL )) {
287 receiver_height = own_alt - elevation_under_pilot;
290 double elevation_under_sender = 0.0;
291 if (scenery->get_elevation_m( max_sender_pos, elevation_under_sender, NULL )) {
292 transmitter_height = sender_alt - elevation_under_sender;
295 transmitter_height = sender_alt;
299 transmitter_height += _tx_antenna_height;
300 receiver_height += _rx_antenna_height;
303 SG_LOG(SG_GENERAL, SG_BULK,
304 "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters");
305 cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl;
307 unsigned int e_size = (deque<unsigned>::size_type)max_points;
309 while (_elevations.size() <= e_size) {
310 probe_distance += point_distance;
311 SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance ));
312 const SGMaterial *mat = 0;
313 double elevation_m = 0.0;
315 if (scenery->get_elevation_m( probe, elevation_m, &mat )) {
316 if((transmission_type == 3) || (transmission_type == 4)) {
317 _elevations.push_back(elevation_m);
319 const std::vector<string> mat_names = mat->get_names();
320 materials.push_back(mat_names[0]);
323 materials.push_back("None");
327 _elevations.push_front(elevation_m);
329 const std::vector<string> mat_names = mat->get_names();
330 materials.push_front(mat_names[0]);
333 materials.push_front("None");
338 if((transmission_type == 3) || (transmission_type == 4)) {
339 _elevations.push_back(0.0);
340 materials.push_back("None");
343 _elevations.push_front(0.0);
344 materials.push_front("None");
348 if((transmission_type == 3) || (transmission_type == 4)) {
349 _elevations.push_front(elevation_under_pilot);
350 if (delta_last > (point_distance / 2) ) // only add last point if it's farther than half point_distance
351 _elevations.push_back(elevation_under_sender);
354 _elevations.push_back(elevation_under_pilot);
355 if (delta_last > (point_distance / 2) )
356 _elevations.push_front(elevation_under_sender);
360 double max_alt_between=0.0;
361 for( deque<double>::size_type i = 0; i < _elevations.size(); i++ ) {
362 if (_elevations[i] > max_alt_between) {
363 max_alt_between = _elevations[i];
367 double num_points= (double)_elevations.size();
369 _elevations.push_front(point_distance);
370 _elevations.push_front(num_points -1);
371 int size = _elevations.size();
372 double itm_elev[size];
373 for(int i=0;i<size;i++) {
374 itm_elev[i]=_elevations[i];
375 //cerr << "ITM:: itm_elev: " << _elevations[i] << endl;
378 if((transmission_type == 3) || (transmission_type == 4)) {
379 // the sender and receiver roles are switched
380 point_to_point(itm_elev, receiver_height, transmitter_height,
381 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
382 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
383 if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) )
384 clutterLoss(frq_mhz, distance_m, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss);
387 point_to_point(itm_elev, transmitter_height, receiver_height,
388 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
389 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
390 if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) )
391 clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss);
393 SG_LOG(SG_GENERAL, SG_BULK,
394 "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
395 cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
397 cerr << "Clutter loss: " << clutter_loss << endl;
398 //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used
400 signal = link_budget - dbloss - clutter_loss;
405 /*** Calculate losses due to vegetation and urban clutter (WIP)
406 * We are only worried about clutter loss, terrain influence
407 * on the first Fresnel zone is calculated in the ITM functions
409 void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm_elev[], deque<string> materials,
410 double transmitter_height, double receiver_height, int p_mode,
411 double horizons[], double &clutter_loss) {
413 distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points
415 if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone
418 for (int k=3;k < (int)(itm_elev[0]) + 2;k++) {
420 double clutter_height = 0.0; // mean clutter height for a certain terrain type
421 double clutter_density = 0.0; // percent of reflected wave
422 get_material_properties(materials[mat], clutter_height, clutter_density);
424 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
425 // First Fresnel radius
426 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) );
428 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
430 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
431 double d1 = j * itm_elev[1];
432 if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
433 d1 = (itm_elev[0] - j) * itm_elev[1];
435 double ray_height = (grad * d1) + min_elev;
437 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
438 double intrusion = fabs(clearance);
440 if (clearance >= 0) {
443 else if (clearance < 0 && (intrusion < clutter_height)) {
445 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
447 else if (clearance < 0 && (intrusion > clutter_height)) {
448 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
458 else if (p_mode == 1) { // diffraction
460 if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point
461 int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m );
462 int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m );
463 //cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl;
465 /** perform the first pass */
468 for (int k=3;k < num_points_1st + 2;k++) {
469 if (num_points_1st < 1)
471 double clutter_height = 0.0; // mean clutter height for a certain terrain type
472 double clutter_density = 0.0; // percent of reflected wave
473 get_material_properties(materials[mat], clutter_height, clutter_density);
475 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
476 // First Fresnel radius
477 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) );
479 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
481 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
482 double d1 = j * itm_elev[1];
483 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
484 d1 = (num_points_1st - j) * itm_elev[1];
486 double ray_height = (grad * d1) + min_elev;
488 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
489 double intrusion = fabs(clearance);
491 if (clearance >= 0) {
494 else if (clearance < 0 && (intrusion < clutter_height)) {
496 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
498 else if (clearance < 0 && (intrusion > clutter_height)) {
499 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
509 /** and the second pass */
511 j =1; // first point is diffraction edge, 2nd the RX elevation
512 for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) {
513 if (num_points_2nd < 1)
515 double clutter_height = 0.0; // mean clutter height for a certain terrain type
516 double clutter_density = 0.0; // percent of reflected wave
517 get_material_properties(materials[mat], clutter_height, clutter_density);
519 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
520 // First Fresnel radius
521 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) );
523 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
525 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
526 double d1 = j * itm_elev[1];
527 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
528 d1 = (num_points_2nd - j) * itm_elev[1];
530 double ray_height = (grad * d1) + min_elev;
532 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
533 double intrusion = fabs(clearance);
535 if (clearance >= 0) {
538 else if (clearance < 0 && (intrusion < clutter_height)) {
540 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
542 else if (clearance < 0 && (intrusion > clutter_height)) {
543 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
553 else { // double horizon: same as single horizon, except there are 3 segments
555 int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m );
556 int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m );
557 int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd;
558 //cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl;
559 //cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl;
561 /** perform the first pass */
563 int j=1; // first point is TX elevation, 2nd is obstruction elevation
564 for (int k=3;k < num_points_1st +2;k++) {
565 if (num_points_1st < 1)
567 double clutter_height = 0.0; // mean clutter height for a certain terrain type
568 double clutter_density = 0.0; // percent of reflected wave
569 get_material_properties(materials[mat], clutter_height, clutter_density);
571 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
572 // First Fresnel radius
573 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) );
575 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
577 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
578 double d1 = j * itm_elev[1];
579 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
580 d1 = (num_points_1st - j) * itm_elev[1];
582 double ray_height = (grad * d1) + min_elev;
584 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
585 double intrusion = fabs(clearance);
587 if (clearance >= 0) {
590 else if (clearance < 0 && (intrusion < clutter_height)) {
592 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
594 else if (clearance < 0 && (intrusion > clutter_height)) {
595 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
604 /** and the second pass */
606 j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation
607 for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) {
608 if (num_points_2nd < 1)
610 double clutter_height = 0.0; // mean clutter height for a certain terrain type
611 double clutter_density = 0.0; // percent of reflected wave
612 get_material_properties(materials[mat], clutter_height, clutter_density);
614 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m;
615 // First Fresnel radius
616 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) );
618 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
620 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height);
621 double d1 = j * itm_elev[1];
622 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) {
623 d1 = (num_points_2nd - j) * itm_elev[1];
625 double ray_height = (grad * d1) + min_elev;
627 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
628 double intrusion = fabs(clearance);
630 if (clearance >= 0) {
633 else if (clearance < 0 && (intrusion < clutter_height)) {
635 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
637 else if (clearance < 0 && (intrusion > clutter_height)) {
638 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
648 /** third and final pass */
650 j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation
651 for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) {
652 if (num_points_3rd < 1)
654 double clutter_height = 0.0; // mean clutter height for a certain terrain type
655 double clutter_density = 0.0; // percent of reflected wave
656 get_material_properties(materials[mat], clutter_height, clutter_density);
658 double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
659 // First Fresnel radius
660 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) );
663 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
665 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
666 double d1 = j * itm_elev[1];
667 if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
668 d1 = (num_points_3rd - j) * itm_elev[1];
670 double ray_height = (grad * d1) + min_elev;
672 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
673 double intrusion = fabs(clearance);
675 if (clearance >= 0) {
678 else if (clearance < 0 && (intrusion < clutter_height)) {
680 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
682 else if (clearance < 0 && (intrusion > clutter_height)) {
683 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
695 else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
701 /*** Temporary material properties database
702 * height: median clutter height
703 * density: radiowave attenuation factor
705 void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
707 if(mat_name == "Landmass") {
712 else if(mat_name == "SomeSort") {
717 else if(mat_name == "Island") {
721 else if(mat_name == "Default") {
725 else if(mat_name == "EvergreenBroadCover") {
729 else if(mat_name == "EvergreenForest") {
733 else if(mat_name == "DeciduousBroadCover") {
737 else if(mat_name == "DeciduousForest") {
741 else if(mat_name == "MixedForestCover") {
745 else if(mat_name == "MixedForest") {
749 else if(mat_name == "RainForest") {
753 else if(mat_name == "EvergreenNeedleCover") {
757 else if(mat_name == "WoodedTundraCover") {
761 else if(mat_name == "DeciduousNeedleCover") {
765 else if(mat_name == "ScrubCover") {
769 else if(mat_name == "BuiltUpCover") {
773 else if(mat_name == "Urban") {
777 else if(mat_name == "Construction") {
781 else if(mat_name == "Industrial") {
785 else if(mat_name == "Port") {
789 else if(mat_name == "Town") {
793 else if(mat_name == "SubUrban") {
797 else if(mat_name == "CropWoodCover") {
801 else if(mat_name == "CropWood") {
805 else if(mat_name == "AgroForest") {
816 /*** implement simple LOS propagation model (WIP)
818 double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
820 if( (freq < 118.0) || (freq > 137.0) )
821 frq_mhz = 125.0; // sane value, middle of bandplan
825 double tx_pow = _transmitter_power;
826 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
829 double sender_alt_ft,sender_alt;
830 double transmitter_height=0.0;
831 double receiver_height=0.0;
832 double own_lat = fgGetDouble("/position/latitude-deg");
833 double own_lon = fgGetDouble("/position/longitude-deg");
834 double own_alt_ft = fgGetDouble("/position/altitude-ft");
835 double own_alt= own_alt_ft * SG_FEET_TO_METER;
838 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
840 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
842 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
844 SGGeod sender_pos = pos;
846 sender_alt_ft = sender_pos.getElevationFt();
847 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
849 receiver_height = own_alt;
850 transmitter_height = sender_alt;
852 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
855 transmitter_height += _tx_antenna_height;
856 receiver_height += _rx_antenna_height;
859 /** radio horizon calculation with wave bending k=4/3 */
860 double receiver_horizon = 4.12 * sqrt(receiver_height);
861 double transmitter_horizon = 4.12 * sqrt(transmitter_height);
862 double total_horizon = receiver_horizon + transmitter_horizon;
864 if (distance_m > total_horizon) {
868 // free-space loss (distance calculation should be changed)
869 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
870 signal = link_budget - dbloss;
871 SG_LOG(SG_GENERAL, SG_BULK,
872 "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm ");
873 //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl;