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;
67 _root_node = fgGetNode("sim/radio", true);
68 _terrain_sampling_distance = _root_node->getDoubleValue("sampling-distance", 90.0); // regular SRTM is 90 meters
71 FGRadioTransmission::~FGRadioTransmission()
76 double FGRadioTransmission::getFrequency(int radio) {
80 freq = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
83 freq = fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz");
86 freq = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
92 /*** TODO: receive multiplayer chat message and voice
94 void FGRadioTransmission::receiveChat(SGGeod tx_pos, double freq, string text, int ground_to_air) {
98 /*** TODO: receive navaid
100 double FGRadioTransmission::receiveNav(SGGeod tx_pos, double freq, int transmission_type) {
102 // typical VOR/LOC transmitter power appears to be 200 Watt ~ 53 dBm
103 // vor/loc typical sensitivity between -107 and -101 dBm
104 // glideslope sensitivity between -85 and -81 dBm
105 if ( _propagation_model == 1) {
106 return LOS_calculate_attenuation(tx_pos, freq, 1);
108 else if ( _propagation_model == 2) {
109 return ITM_calculate_attenuation(tx_pos, freq, 1);
116 /*** Receive ATC radio communication as text
118 void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) {
121 if(ground_to_air == 1) {
122 _transmitter_power += 4.0;
123 _tx_antenna_height += 30.0;
124 _tx_antenna_gain += 2.0;
128 double comm1 = getFrequency(1);
129 double comm2 = getFrequency(2);
130 if ( !(fabs(freq - comm1) <= 0.0001) && !(fabs(freq - comm2) <= 0.0001) ) {
135 if ( _propagation_model == 0) {
136 // skip propagation routines entirely
137 fgSetString("/sim/messages/atc", text.c_str());
139 else if ( _propagation_model == 1 ) {
140 // Use free-space, round earth
141 double signal = LOS_calculate_attenuation(tx_pos, freq, ground_to_air);
147 fgSetString("/sim/messages/atc", text.c_str());
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/sound/voices/voice/volume", old_volume);
183 fgSetString("/sim/messages/atc", text.c_str());
192 /*** Implement radio attenuation
193 based on the Longley-Rice propagation model
195 double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
199 /** ITM default parameters
200 TODO: take them from tile materials (especially for sea)?
202 double eps_dielect=15.0;
203 double sgm_conductivity = 0.005;
206 if( (freq < 118.0) || (freq > 137.0) )
207 frq_mhz = 125.0; // sane value, middle of bandplan
210 int radio_climate = 5; // continental temperate
211 int pol= _polarization;
212 double conf = 0.90; // 90% of situations and time, take into account speed
216 int p_mode = 0; // propgation mode selector: 0 LOS, 1 diffraction dominant, 2 troposcatter
220 double clutter_loss = 0.0; // loss due to vegetation and urban
221 double tx_pow = _transmitter_power;
222 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
226 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
227 double signal_strength = tx_pow - _rx_line_losses - _tx_line_losses + ant_gain;
228 double tx_erp = dbm_to_watt(tx_pow + _tx_antenna_gain - _tx_line_losses);
231 FGScenery * scenery = globals->get_scenery();
233 double own_lat = fgGetDouble("/position/latitude-deg");
234 double own_lon = fgGetDouble("/position/longitude-deg");
235 double own_alt_ft = fgGetDouble("/position/altitude-ft");
236 double own_alt= own_alt_ft * SG_FEET_TO_METER;
239 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
241 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
242 SGGeod max_own_pos = SGGeod::fromDegM( own_lon, own_lat, SG_MAX_ELEVATION_M );
243 SGGeoc center = SGGeoc::fromGeod( max_own_pos );
244 SGGeoc own_pos_c = SGGeoc::fromGeod( own_pos );
247 double sender_alt_ft,sender_alt;
248 double transmitter_height=0.0;
249 double receiver_height=0.0;
250 SGGeod sender_pos = pos;
252 sender_alt_ft = sender_pos.getElevationFt();
253 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
254 SGGeod max_sender_pos = SGGeod::fromGeodM( pos, SG_MAX_ELEVATION_M );
255 SGGeoc sender_pos_c = SGGeoc::fromGeod( sender_pos );
256 //cerr << "ITM:: sender Lat: " << parent->getLatitude() << ", Lon: " << parent->getLongitude() << ", Alt: " << sender_alt << endl;
258 double point_distance= _terrain_sampling_distance;
259 double course = SGGeodesy::courseRad(own_pos_c, sender_pos_c);
260 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
261 double probe_distance = 0.0;
262 /** If distance larger than this value (300 km), assume reception imposssible */
263 if (distance_m > 300000)
265 /** If above 8000 meters, consider LOS mode and calculate free-space att */
266 if (own_alt > 8000) {
267 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
268 SG_LOG(SG_GENERAL, SG_BULK,
269 "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation");
270 //cerr << "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation" << endl;
271 signal = link_budget - dbloss;
276 int max_points = (int)floor(distance_m / point_distance);
277 double delta_last = fmod(distance_m, point_distance);
279 deque<double> _elevations;
280 deque<string> materials;
283 double elevation_under_pilot = 0.0;
284 if (scenery->get_elevation_m( max_own_pos, elevation_under_pilot, NULL )) {
285 receiver_height = own_alt - elevation_under_pilot;
288 double elevation_under_sender = 0.0;
289 if (scenery->get_elevation_m( max_sender_pos, elevation_under_sender, NULL )) {
290 transmitter_height = sender_alt - elevation_under_sender;
293 transmitter_height = sender_alt;
297 transmitter_height += _tx_antenna_height;
298 receiver_height += _rx_antenna_height;
301 SG_LOG(SG_GENERAL, SG_BULK,
302 "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters");
303 //cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl;
304 _root_node->setDoubleValue("station[0]/rx-height", receiver_height);
305 _root_node->setDoubleValue("station[0]/tx-height", transmitter_height);
306 _root_node->setDoubleValue("station[0]/distance", distance_m / 1000);
308 unsigned int e_size = (deque<unsigned>::size_type)max_points;
310 while (_elevations.size() <= e_size) {
311 probe_distance += point_distance;
312 SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance ));
313 const SGMaterial *mat = 0;
314 double elevation_m = 0.0;
316 if (scenery->get_elevation_m( probe, elevation_m, &mat )) {
317 if((transmission_type == 3) || (transmission_type == 4)) {
318 _elevations.push_back(elevation_m);
320 const std::vector<string> mat_names = mat->get_names();
321 materials.push_back(mat_names[0]);
324 materials.push_back("None");
328 _elevations.push_front(elevation_m);
330 const std::vector<string> mat_names = mat->get_names();
331 materials.push_front(mat_names[0]);
334 materials.push_front("None");
339 if((transmission_type == 3) || (transmission_type == 4)) {
340 _elevations.push_back(0.0);
341 materials.push_back("None");
344 _elevations.push_front(0.0);
345 materials.push_front("None");
349 if((transmission_type == 3) || (transmission_type == 4)) {
350 _elevations.push_front(elevation_under_pilot);
351 if (delta_last > (point_distance / 2) ) // only add last point if it's farther than half point_distance
352 _elevations.push_back(elevation_under_sender);
355 _elevations.push_back(elevation_under_pilot);
356 if (delta_last > (point_distance / 2) )
357 _elevations.push_front(elevation_under_sender);
361 double num_points= (double)_elevations.size();
363 _elevations.push_front(point_distance);
364 _elevations.push_front(num_points -1);
366 int size = _elevations.size();
367 double itm_elev[10000];
369 for(int i=0;i<size;i++) {
370 itm_elev[i]=_elevations[i];
371 //cerr << "ITM:: itm_elev: " << _elevations[i] << endl;
374 if((transmission_type == 3) || (transmission_type == 4)) {
375 // the sender and receiver roles are switched
376 point_to_point(itm_elev, receiver_height, transmitter_height,
377 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
378 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
379 if( _root_node->getBoolValue( "use-clutter-attenuation", false ) )
380 clutterLoss(frq_mhz, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss);
383 point_to_point(itm_elev, transmitter_height, receiver_height,
384 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
385 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
386 if( _root_node->getBoolValue( "use-clutter-attenuation", false ) )
387 clutterLoss(frq_mhz, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss);
390 double pol_loss = 0.0;
391 if (_polarization == 1) {
392 pol_loss = polarization_loss();
394 SG_LOG(SG_GENERAL, SG_BULK,
395 "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
396 //cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
397 _root_node->setDoubleValue("station[0]/link-budget", link_budget);
398 _root_node->setDoubleValue("station[0]/terrain-attenuation", dbloss);
399 _root_node->setStringValue("station[0]/prop-mode", strmode);
400 _root_node->setDoubleValue("station[0]/clutter-attenuation", clutter_loss);
401 _root_node->setDoubleValue("station[0]/polarization-attenuation", pol_loss);
402 //cerr << "Clutter loss: " << clutter_loss << endl;
403 //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used
405 signal = link_budget - dbloss - clutter_loss + pol_loss;
406 double signal_strength_dbm = signal_strength - dbloss - clutter_loss + pol_loss;
407 double field_strength_uV = dbm_to_microvolt(signal_strength_dbm);
408 _root_node->setDoubleValue("station[0]/signal-dbm", signal_strength_dbm);
409 _root_node->setDoubleValue("station[0]/field-strength-uV", field_strength_uV);
410 _root_node->setDoubleValue("station[0]/signal", signal);
411 _root_node->setDoubleValue("station[0]/tx-erp", tx_erp);
416 /*** Calculate losses due to vegetation and urban clutter (WIP)
417 * We are only worried about clutter loss, terrain influence
418 * on the first Fresnel zone is calculated in the ITM functions
420 void FGRadioTransmission::clutterLoss(double freq, double itm_elev[], deque<string> materials,
421 double transmitter_height, double receiver_height, int p_mode,
422 double horizons[], double &clutter_loss) {
424 double distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points
426 if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone
429 for (int k=3;k < (int)(itm_elev[0]) + 2;k++) {
431 double clutter_height = 0.0; // mean clutter height for a certain terrain type
432 double clutter_density = 0.0; // percent of reflected wave
433 get_material_properties(materials[mat], clutter_height, clutter_density);
435 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
436 // First Fresnel radius
437 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) );
439 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
441 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
442 double d1 = j * itm_elev[1];
443 if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
444 d1 = (itm_elev[0] - j) * itm_elev[1];
446 double ray_height = (grad * d1) + min_elev;
448 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
449 double intrusion = fabs(clearance);
451 if (clearance >= 0) {
454 else if (clearance < 0 && (intrusion < clutter_height)) {
456 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
458 else if (clearance < 0 && (intrusion > clutter_height)) {
459 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
469 else if (p_mode == 1) { // diffraction
471 if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point
472 int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m );
473 int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m );
474 //cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl;
476 /** perform the first pass */
479 for (int k=3;k < num_points_1st + 2;k++) {
480 if (num_points_1st < 1)
482 double clutter_height = 0.0; // mean clutter height for a certain terrain type
483 double clutter_density = 0.0; // percent of reflected wave
484 get_material_properties(materials[mat], clutter_height, clutter_density);
486 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
487 // First Fresnel radius
488 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) );
490 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
492 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
493 double d1 = j * itm_elev[1];
494 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
495 d1 = (num_points_1st - j) * itm_elev[1];
497 double ray_height = (grad * d1) + min_elev;
499 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
500 double intrusion = fabs(clearance);
502 if (clearance >= 0) {
505 else if (clearance < 0 && (intrusion < clutter_height)) {
507 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
509 else if (clearance < 0 && (intrusion > clutter_height)) {
510 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
520 /** and the second pass */
522 j =1; // first point is diffraction edge, 2nd the RX elevation
523 for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) {
524 if (num_points_2nd < 1)
526 double clutter_height = 0.0; // mean clutter height for a certain terrain type
527 double clutter_density = 0.0; // percent of reflected wave
528 get_material_properties(materials[mat], clutter_height, clutter_density);
530 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
531 // First Fresnel radius
532 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) );
534 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
536 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
537 double d1 = j * itm_elev[1];
538 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
539 d1 = (num_points_2nd - j) * itm_elev[1];
541 double ray_height = (grad * d1) + min_elev;
543 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
544 double intrusion = fabs(clearance);
546 if (clearance >= 0) {
549 else if (clearance < 0 && (intrusion < clutter_height)) {
551 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
553 else if (clearance < 0 && (intrusion > clutter_height)) {
554 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
564 else { // double horizon: same as single horizon, except there are 3 segments
566 int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m );
567 int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m );
568 int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd;
569 //cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl;
570 //cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl;
572 /** perform the first pass */
574 int j=1; // first point is TX elevation, 2nd is obstruction elevation
575 for (int k=3;k < num_points_1st +2;k++) {
576 if (num_points_1st < 1)
578 double clutter_height = 0.0; // mean clutter height for a certain terrain type
579 double clutter_density = 0.0; // percent of reflected wave
580 get_material_properties(materials[mat], clutter_height, clutter_density);
582 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
583 // First Fresnel radius
584 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) );
586 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
588 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
589 double d1 = j * itm_elev[1];
590 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
591 d1 = (num_points_1st - j) * itm_elev[1];
593 double ray_height = (grad * d1) + min_elev;
595 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
596 double intrusion = fabs(clearance);
598 if (clearance >= 0) {
601 else if (clearance < 0 && (intrusion < clutter_height)) {
603 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
605 else if (clearance < 0 && (intrusion > clutter_height)) {
606 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
615 /** and the second pass */
617 j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation
618 for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) {
619 if (num_points_2nd < 1)
621 double clutter_height = 0.0; // mean clutter height for a certain terrain type
622 double clutter_density = 0.0; // percent of reflected wave
623 get_material_properties(materials[mat], clutter_height, clutter_density);
625 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m;
626 // First Fresnel radius
627 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) );
629 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
631 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height);
632 double d1 = j * itm_elev[1];
633 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) {
634 d1 = (num_points_2nd - j) * itm_elev[1];
636 double ray_height = (grad * d1) + min_elev;
638 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
639 double intrusion = fabs(clearance);
641 if (clearance >= 0) {
644 else if (clearance < 0 && (intrusion < clutter_height)) {
646 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
648 else if (clearance < 0 && (intrusion > clutter_height)) {
649 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
659 /** third and final pass */
661 j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation
662 for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) {
663 if (num_points_3rd < 1)
665 double clutter_height = 0.0; // mean clutter height for a certain terrain type
666 double clutter_density = 0.0; // percent of reflected wave
667 get_material_properties(materials[mat], clutter_height, clutter_density);
669 double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
670 // First Fresnel radius
671 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) );
674 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
676 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
677 double d1 = j * itm_elev[1];
678 if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
679 d1 = (num_points_3rd - j) * itm_elev[1];
681 double ray_height = (grad * d1) + min_elev;
683 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
684 double intrusion = fabs(clearance);
686 if (clearance >= 0) {
689 else if (clearance < 0 && (intrusion < clutter_height)) {
691 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
693 else if (clearance < 0 && (intrusion > clutter_height)) {
694 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
706 else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
712 /*** Temporary material properties database
713 * height: median clutter height
714 * density: radiowave attenuation factor
716 void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
718 if(mat_name == "Landmass") {
723 else if(mat_name == "SomeSort") {
728 else if(mat_name == "Island") {
732 else if(mat_name == "Default") {
736 else if(mat_name == "EvergreenBroadCover") {
740 else if(mat_name == "EvergreenForest") {
744 else if(mat_name == "DeciduousBroadCover") {
748 else if(mat_name == "DeciduousForest") {
752 else if(mat_name == "MixedForestCover") {
756 else if(mat_name == "MixedForest") {
760 else if(mat_name == "RainForest") {
764 else if(mat_name == "EvergreenNeedleCover") {
768 else if(mat_name == "WoodedTundraCover") {
772 else if(mat_name == "DeciduousNeedleCover") {
776 else if(mat_name == "ScrubCover") {
780 else if(mat_name == "BuiltUpCover") {
784 else if(mat_name == "Urban") {
788 else if(mat_name == "Construction") {
792 else if(mat_name == "Industrial") {
796 else if(mat_name == "Port") {
800 else if(mat_name == "Town") {
804 else if(mat_name == "SubUrban") {
808 else if(mat_name == "CropWoodCover") {
812 else if(mat_name == "CropWood") {
816 else if(mat_name == "AgroForest") {
827 /*** implement simple LOS propagation model (WIP)
829 double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
831 if( (freq < 118.0) || (freq > 137.0) )
832 frq_mhz = 125.0; // sane value, middle of bandplan
836 double tx_pow = _transmitter_power;
837 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
840 double sender_alt_ft,sender_alt;
841 double transmitter_height=0.0;
842 double receiver_height=0.0;
843 double own_lat = fgGetDouble("/position/latitude-deg");
844 double own_lon = fgGetDouble("/position/longitude-deg");
845 double own_alt_ft = fgGetDouble("/position/altitude-ft");
846 double own_alt= own_alt_ft * SG_FEET_TO_METER;
849 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
851 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
853 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
855 SGGeod sender_pos = pos;
857 sender_alt_ft = sender_pos.getElevationFt();
858 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
860 receiver_height = own_alt;
861 transmitter_height = sender_alt;
863 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
866 transmitter_height += _tx_antenna_height;
867 receiver_height += _rx_antenna_height;
870 /** radio horizon calculation with wave bending k=4/3 */
871 double receiver_horizon = 4.12 * sqrt(receiver_height);
872 double transmitter_horizon = 4.12 * sqrt(transmitter_height);
873 double total_horizon = receiver_horizon + transmitter_horizon;
875 if (distance_m > total_horizon) {
878 double pol_loss = 0.0;
879 if (_polarization == 1) {
880 pol_loss = polarization_loss();
882 // free-space loss (distance calculation should be changed)
883 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
884 signal = link_budget - dbloss + pol_loss;
885 SG_LOG(SG_GENERAL, SG_BULK,
886 "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm ");
887 //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl;
892 /*** calculate loss due to polarization mismatch
893 * this function is only reliable for vertical polarization
894 * due to the V-shape of horizontally polarized antennas
896 double FGRadioTransmission::polarization_loss() {
899 double roll = fgGetDouble("/orientation/roll-deg");
900 if (fabs(roll) > 85.0)
902 double pitch = fgGetDouble("/orientation/pitch-deg");
903 if (fabs(pitch) > 85.0)
905 double theta = fabs( atan( sqrt(
906 pow(tan(roll * SGD_DEGREES_TO_RADIANS), 2) +
907 pow(tan(pitch * SGD_DEGREES_TO_RADIANS), 2) )) * SGD_RADIANS_TO_DEGREES);
909 if (_polarization == 0)
910 theta_deg = 90.0 - theta;
913 if (theta_deg > 85.0) // we don't want to converge into infinity
916 double loss = 10 * log10( pow(cos(theta_deg * SGD_DEGREES_TO_RADIANS), 2) );
917 //cerr << "Polarization loss: " << loss << " dBm " << endl;
922 double FGRadioTransmission::watt_to_dbm(double power_watt) {
923 return 10 * log10(1000 * power_watt); // returns dbm
926 double FGRadioTransmission::dbm_to_watt(double dbm) {
927 return exp( (dbm-30) * log(10.0) / 10.0); // returns Watts
930 double FGRadioTransmission::dbm_to_microvolt(double dbm) {
931 return sqrt(dbm_to_watt(dbm) * 50) * 1000000; // returns microvolts