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 += 6.0;
123 _tx_antenna_height += 30.0;
124 _tx_antenna_gain += 3.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());
148 /** write signal strength above threshold to the property tree
149 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
151 _root_node->setDoubleValue("station[0]/signal", signal);
154 else if ( _propagation_model == 2 ) {
155 // Use ITM propagation model
156 double signal = ITM_calculate_attenuation(tx_pos, freq, ground_to_air);
160 if ((signal > 0.0) && (signal < 12.0)) {
161 /** for low SNR values implement a way to make the conversation
162 * hard to understand but audible
163 * in the real world, the receiver AGC fails to capture the slope
164 * and the signal, due to being amplitude modulated, decreases volume after demodulation
165 * the workaround below is more akin to what would happen on a FM transmission
166 * therefore the correct way would be to work on the volume
169 string hash_noise = " ";
170 int reps = (int) (fabs(floor(signal - 11.0)) * 2);
171 int t_size = text.size();
172 for (int n = 1; n <= reps; ++n) {
173 int pos = rand() % (t_size -1);
174 text.replace(pos,1, hash_noise);
177 double volume = (fabs(signal - 12.0) / 12);
178 double old_volume = fgGetDouble("/sim/sound/voices/voice/volume");
179 SG_LOG(SG_GENERAL, SG_BULK, "Usable signal at limit: " << signal);
180 //cerr << "Usable signal at limit: " << signal << endl;
181 fgSetDouble("/sim/sound/voices/voice/volume", volume);
182 fgSetString("/sim/messages/atc", text.c_str());
183 _root_node->setDoubleValue("station[0]/signal", signal);
184 fgSetDouble("/sim/sound/voices/voice/volume", old_volume);
187 fgSetString("/sim/messages/atc", text.c_str());
188 /** write signal strength above threshold to the property tree
189 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
191 _root_node->setDoubleValue("station[0]/signal", signal);
200 /*** Implement radio attenuation
201 based on the Longley-Rice propagation model
203 double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
207 /** ITM default parameters
208 TODO: take them from tile materials (especially for sea)?
210 double eps_dielect=15.0;
211 double sgm_conductivity = 0.005;
214 if( (freq < 118.0) || (freq > 137.0) )
215 frq_mhz = 125.0; // sane value, middle of bandplan
218 int radio_climate = 5; // continental temperate
219 int pol= _polarization;
220 double conf = 0.90; // 90% of situations and time, take into account speed
224 int p_mode = 0; // propgation mode selector: 0 LOS, 1 diffraction dominant, 2 troposcatter
228 double clutter_loss = 0.0; // loss due to vegetation and urban
229 double tx_pow = _transmitter_power;
230 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
234 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
235 double signal_strength = tx_pow - _rx_line_losses - _tx_line_losses + ant_gain;
237 FGScenery * scenery = globals->get_scenery();
239 double own_lat = fgGetDouble("/position/latitude-deg");
240 double own_lon = fgGetDouble("/position/longitude-deg");
241 double own_alt_ft = fgGetDouble("/position/altitude-ft");
242 double own_alt= own_alt_ft * SG_FEET_TO_METER;
245 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
247 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
248 SGGeod max_own_pos = SGGeod::fromDegM( own_lon, own_lat, SG_MAX_ELEVATION_M );
249 SGGeoc center = SGGeoc::fromGeod( max_own_pos );
250 SGGeoc own_pos_c = SGGeoc::fromGeod( own_pos );
253 double sender_alt_ft,sender_alt;
254 double transmitter_height=0.0;
255 double receiver_height=0.0;
256 SGGeod sender_pos = pos;
258 sender_alt_ft = sender_pos.getElevationFt();
259 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
260 SGGeod max_sender_pos = SGGeod::fromGeodM( pos, SG_MAX_ELEVATION_M );
261 SGGeoc sender_pos_c = SGGeoc::fromGeod( sender_pos );
262 //cerr << "ITM:: sender Lat: " << parent->getLatitude() << ", Lon: " << parent->getLongitude() << ", Alt: " << sender_alt << endl;
264 double point_distance= _terrain_sampling_distance;
265 double course = SGGeodesy::courseRad(own_pos_c, sender_pos_c);
266 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
267 double probe_distance = 0.0;
268 /** If distance larger than this value (300 km), assume reception imposssible */
269 if (distance_m > 300000)
271 /** If above 8000 meters, consider LOS mode and calculate free-space att */
272 if (own_alt > 8000) {
273 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
274 SG_LOG(SG_GENERAL, SG_BULK,
275 "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation");
276 //cerr << "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation" << endl;
277 signal = link_budget - dbloss;
282 int max_points = (int)floor(distance_m / point_distance);
283 double delta_last = fmod(distance_m, point_distance);
285 deque<double> _elevations;
286 deque<string> materials;
289 double elevation_under_pilot = 0.0;
290 if (scenery->get_elevation_m( max_own_pos, elevation_under_pilot, NULL )) {
291 receiver_height = own_alt - elevation_under_pilot;
294 double elevation_under_sender = 0.0;
295 if (scenery->get_elevation_m( max_sender_pos, elevation_under_sender, NULL )) {
296 transmitter_height = sender_alt - elevation_under_sender;
299 transmitter_height = sender_alt;
303 transmitter_height += _tx_antenna_height;
304 receiver_height += _rx_antenna_height;
307 SG_LOG(SG_GENERAL, SG_BULK,
308 "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters");
309 //cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl;
310 _root_node->setDoubleValue("station[0]/rx-height", receiver_height);
311 _root_node->setDoubleValue("station[0]/tx-height", transmitter_height);
312 _root_node->setDoubleValue("station[0]/distance", distance_m);
314 unsigned int e_size = (deque<unsigned>::size_type)max_points;
316 while (_elevations.size() <= e_size) {
317 probe_distance += point_distance;
318 SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance ));
319 const SGMaterial *mat = 0;
320 double elevation_m = 0.0;
322 if (scenery->get_elevation_m( probe, elevation_m, &mat )) {
323 if((transmission_type == 3) || (transmission_type == 4)) {
324 _elevations.push_back(elevation_m);
326 const std::vector<string> mat_names = mat->get_names();
327 materials.push_back(mat_names[0]);
330 materials.push_back("None");
334 _elevations.push_front(elevation_m);
336 const std::vector<string> mat_names = mat->get_names();
337 materials.push_front(mat_names[0]);
340 materials.push_front("None");
345 if((transmission_type == 3) || (transmission_type == 4)) {
346 _elevations.push_back(0.0);
347 materials.push_back("None");
350 _elevations.push_front(0.0);
351 materials.push_front("None");
355 if((transmission_type == 3) || (transmission_type == 4)) {
356 _elevations.push_front(elevation_under_pilot);
357 if (delta_last > (point_distance / 2) ) // only add last point if it's farther than half point_distance
358 _elevations.push_back(elevation_under_sender);
361 _elevations.push_back(elevation_under_pilot);
362 if (delta_last > (point_distance / 2) )
363 _elevations.push_front(elevation_under_sender);
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( _root_node->getBoolValue( "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( _root_node->getBoolValue( "use-clutter-attenuation", false ) )
391 clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss);
394 double pol_loss = 0.0;
395 if (_polarization == 1) {
396 pol_loss = polarization_loss();
398 SG_LOG(SG_GENERAL, SG_BULK,
399 "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
400 //cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
401 _root_node->setDoubleValue("station[0]/link-budget", link_budget);
402 _root_node->setDoubleValue("station[0]/terrain-attenuation", dbloss);
403 _root_node->setStringValue("station[0]/prop-mode", strmode);
404 _root_node->setDoubleValue("station[0]/clutter-attenuation", clutter_loss);
405 _root_node->setDoubleValue("station[0]/polarization-attenuation", pol_loss);
406 //cerr << "Clutter loss: " << clutter_loss << endl;
407 //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used
409 signal = link_budget - dbloss - clutter_loss + pol_loss;
410 double signal_strength_dbm = signal_strength - dbloss - clutter_loss + pol_loss;
411 double field_strength_uV = dbm_to_microvolt(signal_strength_dbm);
412 _root_node->setDoubleValue("station[0]/signal-dbm", signal_strength_dbm);
413 _root_node->setDoubleValue("station[0]/field-strength-uV", field_strength_uV);
418 /*** Calculate losses due to vegetation and urban clutter (WIP)
419 * We are only worried about clutter loss, terrain influence
420 * on the first Fresnel zone is calculated in the ITM functions
422 void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm_elev[], deque<string> materials,
423 double transmitter_height, double receiver_height, int p_mode,
424 double horizons[], double &clutter_loss) {
426 distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points
428 if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone
431 for (int k=3;k < (int)(itm_elev[0]) + 2;k++) {
433 double clutter_height = 0.0; // mean clutter height for a certain terrain type
434 double clutter_density = 0.0; // percent of reflected wave
435 get_material_properties(materials[mat], clutter_height, clutter_density);
437 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
438 // First Fresnel radius
439 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) );
441 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
443 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
444 double d1 = j * itm_elev[1];
445 if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
446 d1 = (itm_elev[0] - j) * itm_elev[1];
448 double ray_height = (grad * d1) + min_elev;
450 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
451 double intrusion = fabs(clearance);
453 if (clearance >= 0) {
456 else if (clearance < 0 && (intrusion < clutter_height)) {
458 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
460 else if (clearance < 0 && (intrusion > clutter_height)) {
461 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
471 else if (p_mode == 1) { // diffraction
473 if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point
474 int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m );
475 int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m );
476 //cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl;
478 /** perform the first pass */
481 for (int k=3;k < num_points_1st + 2;k++) {
482 if (num_points_1st < 1)
484 double clutter_height = 0.0; // mean clutter height for a certain terrain type
485 double clutter_density = 0.0; // percent of reflected wave
486 get_material_properties(materials[mat], clutter_height, clutter_density);
488 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
489 // First Fresnel radius
490 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) );
492 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
494 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
495 double d1 = j * itm_elev[1];
496 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
497 d1 = (num_points_1st - j) * itm_elev[1];
499 double ray_height = (grad * d1) + min_elev;
501 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
502 double intrusion = fabs(clearance);
504 if (clearance >= 0) {
507 else if (clearance < 0 && (intrusion < clutter_height)) {
509 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
511 else if (clearance < 0 && (intrusion > clutter_height)) {
512 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
522 /** and the second pass */
524 j =1; // first point is diffraction edge, 2nd the RX elevation
525 for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) {
526 if (num_points_2nd < 1)
528 double clutter_height = 0.0; // mean clutter height for a certain terrain type
529 double clutter_density = 0.0; // percent of reflected wave
530 get_material_properties(materials[mat], clutter_height, clutter_density);
532 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
533 // First Fresnel radius
534 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) );
536 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
538 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
539 double d1 = j * itm_elev[1];
540 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
541 d1 = (num_points_2nd - j) * itm_elev[1];
543 double ray_height = (grad * d1) + min_elev;
545 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
546 double intrusion = fabs(clearance);
548 if (clearance >= 0) {
551 else if (clearance < 0 && (intrusion < clutter_height)) {
553 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
555 else if (clearance < 0 && (intrusion > clutter_height)) {
556 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
566 else { // double horizon: same as single horizon, except there are 3 segments
568 int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m );
569 int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m );
570 int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd;
571 //cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl;
572 //cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl;
574 /** perform the first pass */
576 int j=1; // first point is TX elevation, 2nd is obstruction elevation
577 for (int k=3;k < num_points_1st +2;k++) {
578 if (num_points_1st < 1)
580 double clutter_height = 0.0; // mean clutter height for a certain terrain type
581 double clutter_density = 0.0; // percent of reflected wave
582 get_material_properties(materials[mat], clutter_height, clutter_density);
584 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
585 // First Fresnel radius
586 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) );
588 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
590 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
591 double d1 = j * itm_elev[1];
592 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
593 d1 = (num_points_1st - j) * itm_elev[1];
595 double ray_height = (grad * d1) + min_elev;
597 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
598 double intrusion = fabs(clearance);
600 if (clearance >= 0) {
603 else if (clearance < 0 && (intrusion < clutter_height)) {
605 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
607 else if (clearance < 0 && (intrusion > clutter_height)) {
608 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
617 /** and the second pass */
619 j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation
620 for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) {
621 if (num_points_2nd < 1)
623 double clutter_height = 0.0; // mean clutter height for a certain terrain type
624 double clutter_density = 0.0; // percent of reflected wave
625 get_material_properties(materials[mat], clutter_height, clutter_density);
627 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m;
628 // First Fresnel radius
629 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) );
631 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
633 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height);
634 double d1 = j * itm_elev[1];
635 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) {
636 d1 = (num_points_2nd - j) * itm_elev[1];
638 double ray_height = (grad * d1) + min_elev;
640 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
641 double intrusion = fabs(clearance);
643 if (clearance >= 0) {
646 else if (clearance < 0 && (intrusion < clutter_height)) {
648 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
650 else if (clearance < 0 && (intrusion > clutter_height)) {
651 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
661 /** third and final pass */
663 j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation
664 for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) {
665 if (num_points_3rd < 1)
667 double clutter_height = 0.0; // mean clutter height for a certain terrain type
668 double clutter_density = 0.0; // percent of reflected wave
669 get_material_properties(materials[mat], clutter_height, clutter_density);
671 double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
672 // First Fresnel radius
673 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) );
676 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
678 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
679 double d1 = j * itm_elev[1];
680 if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
681 d1 = (num_points_3rd - j) * itm_elev[1];
683 double ray_height = (grad * d1) + min_elev;
685 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
686 double intrusion = fabs(clearance);
688 if (clearance >= 0) {
691 else if (clearance < 0 && (intrusion < clutter_height)) {
693 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
695 else if (clearance < 0 && (intrusion > clutter_height)) {
696 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
708 else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
714 /*** Temporary material properties database
715 * height: median clutter height
716 * density: radiowave attenuation factor
718 void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
720 if(mat_name == "Landmass") {
725 else if(mat_name == "SomeSort") {
730 else if(mat_name == "Island") {
734 else if(mat_name == "Default") {
738 else if(mat_name == "EvergreenBroadCover") {
742 else if(mat_name == "EvergreenForest") {
746 else if(mat_name == "DeciduousBroadCover") {
750 else if(mat_name == "DeciduousForest") {
754 else if(mat_name == "MixedForestCover") {
758 else if(mat_name == "MixedForest") {
762 else if(mat_name == "RainForest") {
766 else if(mat_name == "EvergreenNeedleCover") {
770 else if(mat_name == "WoodedTundraCover") {
774 else if(mat_name == "DeciduousNeedleCover") {
778 else if(mat_name == "ScrubCover") {
782 else if(mat_name == "BuiltUpCover") {
786 else if(mat_name == "Urban") {
790 else if(mat_name == "Construction") {
794 else if(mat_name == "Industrial") {
798 else if(mat_name == "Port") {
802 else if(mat_name == "Town") {
806 else if(mat_name == "SubUrban") {
810 else if(mat_name == "CropWoodCover") {
814 else if(mat_name == "CropWood") {
818 else if(mat_name == "AgroForest") {
829 /*** implement simple LOS propagation model (WIP)
831 double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
833 if( (freq < 118.0) || (freq > 137.0) )
834 frq_mhz = 125.0; // sane value, middle of bandplan
838 double tx_pow = _transmitter_power;
839 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
842 double sender_alt_ft,sender_alt;
843 double transmitter_height=0.0;
844 double receiver_height=0.0;
845 double own_lat = fgGetDouble("/position/latitude-deg");
846 double own_lon = fgGetDouble("/position/longitude-deg");
847 double own_alt_ft = fgGetDouble("/position/altitude-ft");
848 double own_alt= own_alt_ft * SG_FEET_TO_METER;
851 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
853 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
855 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
857 SGGeod sender_pos = pos;
859 sender_alt_ft = sender_pos.getElevationFt();
860 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
862 receiver_height = own_alt;
863 transmitter_height = sender_alt;
865 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
868 transmitter_height += _tx_antenna_height;
869 receiver_height += _rx_antenna_height;
872 /** radio horizon calculation with wave bending k=4/3 */
873 double receiver_horizon = 4.12 * sqrt(receiver_height);
874 double transmitter_horizon = 4.12 * sqrt(transmitter_height);
875 double total_horizon = receiver_horizon + transmitter_horizon;
877 if (distance_m > total_horizon) {
880 double pol_loss = 0.0;
881 if (_polarization == 1) {
882 pol_loss = polarization_loss();
884 // free-space loss (distance calculation should be changed)
885 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
886 signal = link_budget - dbloss + pol_loss;
887 SG_LOG(SG_GENERAL, SG_BULK,
888 "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm ");
889 //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl;
894 /*** calculate loss due to polarization mismatch
895 * this function is only reliable for vertical polarization
896 * due to the V-shape of horizontally polarized antennas
898 double FGRadioTransmission::polarization_loss() {
901 double roll = fgGetDouble("/orientation/roll-deg");
902 if (fabs(roll) > 85.0)
904 double pitch = fgGetDouble("/orientation/pitch-deg");
905 if (fabs(pitch) > 85.0)
907 double theta = fabs( atan( sqrt(
908 pow(tan(roll * SGD_DEGREES_TO_RADIANS), 2) +
909 pow(tan(pitch * SGD_DEGREES_TO_RADIANS), 2) )) * SGD_RADIANS_TO_DEGREES);
911 if (_polarization == 0)
912 theta_deg = 90.0 - theta;
915 if (theta_deg > 85.0) // we don't want to converge into infinity
918 double loss = 10 * log10( pow(cos(theta_deg * SGD_DEGREES_TO_RADIANS), 2) );
919 //cerr << "Polarization loss: " << loss << " dBm " << endl;
924 double FGRadioTransmission::power_to_dbm(double power_watt) {
925 return 10 * log10(1000 * power_watt); // returns dbm
928 double FGRadioTransmission::dbm_to_power(double dbm) {
929 return exp( (dbm-30) * log(10) / 10); // returns Watts
932 double FGRadioTransmission::dbm_to_microvolt(double dbm) {
933 return sqrt(dbm_to_power(dbm) * 50) * 1000000; // returns microvolts