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 fgSetString("/sim/messages/atc", text.c_str());
138 else if ( _propagation_model == 1 ) {
139 // TODO: free space, round earth
140 double signal = LOS_calculate_attenuation(tx_pos, freq, ground_to_air);
146 fgSetString("/sim/messages/atc", text.c_str());
147 /** write signal strength above threshold to the property tree
148 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
150 _root_node->setDoubleValue("station[0]/signal", signal);
153 else if ( _propagation_model == 2 ) {
154 // Use ITM propagation model
155 double signal = ITM_calculate_attenuation(tx_pos, freq, ground_to_air);
159 if ((signal > 0.0) && (signal < 12.0)) {
160 /** for low SNR values implement a way to make the conversation
161 * hard to understand but audible
162 * in the real world, the receiver AGC fails to capture the slope
163 * and the signal, due to being amplitude modulated, decreases volume after demodulation
164 * the workaround below is more akin to what would happen on a FM transmission
165 * therefore the correct way would be to work on the volume
168 string hash_noise = " ";
169 int reps = (int) (fabs(floor(signal - 11.0)) * 2);
170 int t_size = text.size();
171 for (int n = 1; n <= reps; ++n) {
172 int pos = rand() % (t_size -1);
173 text.replace(pos,1, hash_noise);
176 double volume = (fabs(signal - 12.0) / 12);
177 double old_volume = fgGetDouble("/sim/sound/voices/voice/volume");
178 SG_LOG(SG_GENERAL, SG_BULK, "Usable signal at limit: " << signal);
179 //cerr << "Usable signal at limit: " << signal << endl;
180 fgSetDouble("/sim/sound/voices/voice/volume", volume);
181 fgSetString("/sim/messages/atc", text.c_str());
182 _root_node->setDoubleValue("station[0]/signal", signal);
183 fgSetDouble("/sim/sound/voices/voice/volume", old_volume);
186 fgSetString("/sim/messages/atc", text.c_str());
187 /** write signal strength above threshold to the property tree
188 * to implement a simple S-meter just divide by 3 dB per grade (VHF norm)
190 _root_node->setDoubleValue("station[0]/signal", signal);
199 /*** Implement radio attenuation
200 based on the Longley-Rice propagation model
202 double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
206 /** ITM default parameters
207 TODO: take them from tile materials (especially for sea)?
209 double eps_dielect=15.0;
210 double sgm_conductivity = 0.005;
213 if( (freq < 118.0) || (freq > 137.0) )
214 frq_mhz = 125.0; // sane value, middle of bandplan
217 int radio_climate = 5; // continental temperate
218 int pol= _polarization;
219 double conf = 0.90; // 90% of situations and time, take into account speed
223 int p_mode = 0; // propgation mode selector: 0 LOS, 1 diffraction dominant, 2 troposcatter
227 double clutter_loss = 0.0; // loss due to vegetation and urban
228 double tx_pow = _transmitter_power;
229 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
233 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
235 FGScenery * scenery = globals->get_scenery();
237 double own_lat = fgGetDouble("/position/latitude-deg");
238 double own_lon = fgGetDouble("/position/longitude-deg");
239 double own_alt_ft = fgGetDouble("/position/altitude-ft");
240 double own_alt= own_alt_ft * SG_FEET_TO_METER;
243 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
245 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
246 SGGeod max_own_pos = SGGeod::fromDegM( own_lon, own_lat, SG_MAX_ELEVATION_M );
247 SGGeoc center = SGGeoc::fromGeod( max_own_pos );
248 SGGeoc own_pos_c = SGGeoc::fromGeod( own_pos );
251 double sender_alt_ft,sender_alt;
252 double transmitter_height=0.0;
253 double receiver_height=0.0;
254 SGGeod sender_pos = pos;
256 sender_alt_ft = sender_pos.getElevationFt();
257 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
258 SGGeod max_sender_pos = SGGeod::fromGeodM( pos, SG_MAX_ELEVATION_M );
259 SGGeoc sender_pos_c = SGGeoc::fromGeod( sender_pos );
260 //cerr << "ITM:: sender Lat: " << parent->getLatitude() << ", Lon: " << parent->getLongitude() << ", Alt: " << sender_alt << endl;
262 double point_distance= _terrain_sampling_distance;
263 double course = SGGeodesy::courseRad(own_pos_c, sender_pos_c);
264 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
265 double probe_distance = 0.0;
266 /** If distance larger than this value (300 km), assume reception imposssible */
267 if (distance_m > 300000)
269 /** If above 8000 meters, consider LOS mode and calculate free-space att */
270 if (own_alt > 8000) {
271 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
272 SG_LOG(SG_GENERAL, SG_BULK,
273 "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation");
274 //cerr << "ITM Free-space mode:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, free-space attenuation" << endl;
275 signal = link_budget - dbloss;
280 int max_points = (int)floor(distance_m / point_distance);
281 double delta_last = fmod(distance_m, point_distance);
283 deque<double> _elevations;
284 deque<string> materials;
287 double elevation_under_pilot = 0.0;
288 if (scenery->get_elevation_m( max_own_pos, elevation_under_pilot, NULL )) {
289 receiver_height = own_alt - elevation_under_pilot;
292 double elevation_under_sender = 0.0;
293 if (scenery->get_elevation_m( max_sender_pos, elevation_under_sender, NULL )) {
294 transmitter_height = sender_alt - elevation_under_sender;
297 transmitter_height = sender_alt;
301 transmitter_height += _tx_antenna_height;
302 receiver_height += _rx_antenna_height;
305 SG_LOG(SG_GENERAL, SG_BULK,
306 "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters");
307 //cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl;
308 _root_node->setDoubleValue("station[0]/rx-height", receiver_height);
309 _root_node->setDoubleValue("station[0]/tx-height", transmitter_height);
310 _root_node->setDoubleValue("station[0]/distance", distance_m);
312 unsigned int e_size = (deque<unsigned>::size_type)max_points;
314 while (_elevations.size() <= e_size) {
315 probe_distance += point_distance;
316 SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance ));
317 const SGMaterial *mat = 0;
318 double elevation_m = 0.0;
320 if (scenery->get_elevation_m( probe, elevation_m, &mat )) {
321 if((transmission_type == 3) || (transmission_type == 4)) {
322 _elevations.push_back(elevation_m);
324 const std::vector<string> mat_names = mat->get_names();
325 materials.push_back(mat_names[0]);
328 materials.push_back("None");
332 _elevations.push_front(elevation_m);
334 const std::vector<string> mat_names = mat->get_names();
335 materials.push_front(mat_names[0]);
338 materials.push_front("None");
343 if((transmission_type == 3) || (transmission_type == 4)) {
344 _elevations.push_back(0.0);
345 materials.push_back("None");
348 _elevations.push_front(0.0);
349 materials.push_front("None");
353 if((transmission_type == 3) || (transmission_type == 4)) {
354 _elevations.push_front(elevation_under_pilot);
355 if (delta_last > (point_distance / 2) ) // only add last point if it's farther than half point_distance
356 _elevations.push_back(elevation_under_sender);
359 _elevations.push_back(elevation_under_pilot);
360 if (delta_last > (point_distance / 2) )
361 _elevations.push_front(elevation_under_sender);
365 double num_points= (double)_elevations.size();
367 _elevations.push_front(point_distance);
368 _elevations.push_front(num_points -1);
369 int size = _elevations.size();
370 double itm_elev[size];
371 for(int i=0;i<size;i++) {
372 itm_elev[i]=_elevations[i];
373 //cerr << "ITM:: itm_elev: " << _elevations[i] << endl;
376 if((transmission_type == 3) || (transmission_type == 4)) {
377 // the sender and receiver roles are switched
378 point_to_point(itm_elev, receiver_height, transmitter_height,
379 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
380 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
381 if( _root_node->getBoolValue( "use-clutter-attenuation", false ) )
382 clutterLoss(frq_mhz, distance_m, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss);
385 point_to_point(itm_elev, transmitter_height, receiver_height,
386 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
387 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
388 if( _root_node->getBoolValue( "use-clutter-attenuation", false ) )
389 clutterLoss(frq_mhz, distance_m, itm_elev, materials, transmitter_height, receiver_height, p_mode, horizons, clutter_loss);
392 double pol_loss = 0.0;
393 if (_polarization == 1) {
394 pol_loss = polarization_loss();
396 SG_LOG(SG_GENERAL, SG_BULK,
397 "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
398 //cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
399 _root_node->setDoubleValue("station[0]/link-budget", link_budget);
400 _root_node->setDoubleValue("station[0]/terrain-attenuation", dbloss);
401 _root_node->setStringValue("station[0]/prop-mode", strmode);
402 _root_node->setDoubleValue("station[0]/clutter-attenuation", clutter_loss);
403 _root_node->setDoubleValue("station[0]/polarization-attenuation", pol_loss);
404 //cerr << "Clutter loss: " << clutter_loss << endl;
405 //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used
407 signal = link_budget - dbloss - clutter_loss + pol_loss;
412 /*** Calculate losses due to vegetation and urban clutter (WIP)
413 * We are only worried about clutter loss, terrain influence
414 * on the first Fresnel zone is calculated in the ITM functions
416 void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm_elev[], deque<string> materials,
417 double transmitter_height, double receiver_height, int p_mode,
418 double horizons[], double &clutter_loss) {
420 distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points
422 if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone
425 for (int k=3;k < (int)(itm_elev[0]) + 2;k++) {
427 double clutter_height = 0.0; // mean clutter height for a certain terrain type
428 double clutter_density = 0.0; // percent of reflected wave
429 get_material_properties(materials[mat], clutter_height, clutter_density);
431 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
432 // First Fresnel radius
433 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) );
435 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
437 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
438 double d1 = j * itm_elev[1];
439 if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
440 d1 = (itm_elev[0] - j) * itm_elev[1];
442 double ray_height = (grad * d1) + min_elev;
444 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
445 double intrusion = fabs(clearance);
447 if (clearance >= 0) {
450 else if (clearance < 0 && (intrusion < clutter_height)) {
452 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
454 else if (clearance < 0 && (intrusion > clutter_height)) {
455 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
465 else if (p_mode == 1) { // diffraction
467 if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point
468 int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m );
469 int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m );
470 //cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl;
472 /** perform the first pass */
475 for (int k=3;k < num_points_1st + 2;k++) {
476 if (num_points_1st < 1)
478 double clutter_height = 0.0; // mean clutter height for a certain terrain type
479 double clutter_density = 0.0; // percent of reflected wave
480 get_material_properties(materials[mat], clutter_height, clutter_density);
482 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
483 // First Fresnel radius
484 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) );
486 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
488 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
489 double d1 = j * itm_elev[1];
490 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
491 d1 = (num_points_1st - j) * itm_elev[1];
493 double ray_height = (grad * d1) + min_elev;
495 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
496 double intrusion = fabs(clearance);
498 if (clearance >= 0) {
501 else if (clearance < 0 && (intrusion < clutter_height)) {
503 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
505 else if (clearance < 0 && (intrusion > clutter_height)) {
506 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
516 /** and the second pass */
518 j =1; // first point is diffraction edge, 2nd the RX elevation
519 for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) {
520 if (num_points_2nd < 1)
522 double clutter_height = 0.0; // mean clutter height for a certain terrain type
523 double clutter_density = 0.0; // percent of reflected wave
524 get_material_properties(materials[mat], clutter_height, clutter_density);
526 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
527 // First Fresnel radius
528 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) );
530 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
532 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
533 double d1 = j * itm_elev[1];
534 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
535 d1 = (num_points_2nd - j) * itm_elev[1];
537 double ray_height = (grad * d1) + min_elev;
539 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
540 double intrusion = fabs(clearance);
542 if (clearance >= 0) {
545 else if (clearance < 0 && (intrusion < clutter_height)) {
547 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
549 else if (clearance < 0 && (intrusion > clutter_height)) {
550 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
560 else { // double horizon: same as single horizon, except there are 3 segments
562 int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m );
563 int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m );
564 int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd;
565 //cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl;
566 //cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl;
568 /** perform the first pass */
570 int j=1; // first point is TX elevation, 2nd is obstruction elevation
571 for (int k=3;k < num_points_1st +2;k++) {
572 if (num_points_1st < 1)
574 double clutter_height = 0.0; // mean clutter height for a certain terrain type
575 double clutter_density = 0.0; // percent of reflected wave
576 get_material_properties(materials[mat], clutter_height, clutter_density);
578 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
579 // First Fresnel radius
580 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) );
582 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
584 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
585 double d1 = j * itm_elev[1];
586 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
587 d1 = (num_points_1st - j) * itm_elev[1];
589 double ray_height = (grad * d1) + min_elev;
591 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
592 double intrusion = fabs(clearance);
594 if (clearance >= 0) {
597 else if (clearance < 0 && (intrusion < clutter_height)) {
599 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
601 else if (clearance < 0 && (intrusion > clutter_height)) {
602 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
611 /** and the second pass */
613 j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation
614 for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) {
615 if (num_points_2nd < 1)
617 double clutter_height = 0.0; // mean clutter height for a certain terrain type
618 double clutter_density = 0.0; // percent of reflected wave
619 get_material_properties(materials[mat], clutter_height, clutter_density);
621 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m;
622 // First Fresnel radius
623 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) );
625 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
627 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height);
628 double d1 = j * itm_elev[1];
629 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) {
630 d1 = (num_points_2nd - j) * itm_elev[1];
632 double ray_height = (grad * d1) + min_elev;
634 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
635 double intrusion = fabs(clearance);
637 if (clearance >= 0) {
640 else if (clearance < 0 && (intrusion < clutter_height)) {
642 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
644 else if (clearance < 0 && (intrusion > clutter_height)) {
645 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
655 /** third and final pass */
657 j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation
658 for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) {
659 if (num_points_3rd < 1)
661 double clutter_height = 0.0; // mean clutter height for a certain terrain type
662 double clutter_density = 0.0; // percent of reflected wave
663 get_material_properties(materials[mat], clutter_height, clutter_density);
665 double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
666 // First Fresnel radius
667 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) );
670 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
672 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
673 double d1 = j * itm_elev[1];
674 if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
675 d1 = (num_points_3rd - j) * itm_elev[1];
677 double ray_height = (grad * d1) + min_elev;
679 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
680 double intrusion = fabs(clearance);
682 if (clearance >= 0) {
685 else if (clearance < 0 && (intrusion < clutter_height)) {
687 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
689 else if (clearance < 0 && (intrusion > clutter_height)) {
690 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
702 else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
708 /*** Temporary material properties database
709 * height: median clutter height
710 * density: radiowave attenuation factor
712 void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
714 if(mat_name == "Landmass") {
719 else if(mat_name == "SomeSort") {
724 else if(mat_name == "Island") {
728 else if(mat_name == "Default") {
732 else if(mat_name == "EvergreenBroadCover") {
736 else if(mat_name == "EvergreenForest") {
740 else if(mat_name == "DeciduousBroadCover") {
744 else if(mat_name == "DeciduousForest") {
748 else if(mat_name == "MixedForestCover") {
752 else if(mat_name == "MixedForest") {
756 else if(mat_name == "RainForest") {
760 else if(mat_name == "EvergreenNeedleCover") {
764 else if(mat_name == "WoodedTundraCover") {
768 else if(mat_name == "DeciduousNeedleCover") {
772 else if(mat_name == "ScrubCover") {
776 else if(mat_name == "BuiltUpCover") {
780 else if(mat_name == "Urban") {
784 else if(mat_name == "Construction") {
788 else if(mat_name == "Industrial") {
792 else if(mat_name == "Port") {
796 else if(mat_name == "Town") {
800 else if(mat_name == "SubUrban") {
804 else if(mat_name == "CropWoodCover") {
808 else if(mat_name == "CropWood") {
812 else if(mat_name == "AgroForest") {
823 /*** implement simple LOS propagation model (WIP)
825 double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
827 if( (freq < 118.0) || (freq > 137.0) )
828 frq_mhz = 125.0; // sane value, middle of bandplan
832 double tx_pow = _transmitter_power;
833 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
836 double sender_alt_ft,sender_alt;
837 double transmitter_height=0.0;
838 double receiver_height=0.0;
839 double own_lat = fgGetDouble("/position/latitude-deg");
840 double own_lon = fgGetDouble("/position/longitude-deg");
841 double own_alt_ft = fgGetDouble("/position/altitude-ft");
842 double own_alt= own_alt_ft * SG_FEET_TO_METER;
845 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
847 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
849 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
851 SGGeod sender_pos = pos;
853 sender_alt_ft = sender_pos.getElevationFt();
854 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
856 receiver_height = own_alt;
857 transmitter_height = sender_alt;
859 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
862 transmitter_height += _tx_antenna_height;
863 receiver_height += _rx_antenna_height;
866 /** radio horizon calculation with wave bending k=4/3 */
867 double receiver_horizon = 4.12 * sqrt(receiver_height);
868 double transmitter_horizon = 4.12 * sqrt(transmitter_height);
869 double total_horizon = receiver_horizon + transmitter_horizon;
871 if (distance_m > total_horizon) {
874 double pol_loss = 0.0;
875 if (_polarization == 1) {
876 pol_loss = polarization_loss();
878 // free-space loss (distance calculation should be changed)
879 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
880 signal = link_budget - dbloss + pol_loss;
881 SG_LOG(SG_GENERAL, SG_BULK,
882 "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm ");
883 //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl;
888 /*** calculate loss due to polarization mismatch
889 * this function is only reliable for vertical polarization
890 * due to the V-shape of horizontally polarized antennas
892 double FGRadioTransmission::polarization_loss() {
895 double roll = fgGetDouble("/orientation/roll-deg");
896 if (fabs(roll) > 85.0)
898 double pitch = fgGetDouble("/orientation/pitch-deg");
899 if (fabs(pitch) > 85.0)
901 double theta = fabs( atan( sqrt(
902 pow(tan(roll * SGD_DEGREES_TO_RADIANS), 2) +
903 pow(tan(pitch * SGD_DEGREES_TO_RADIANS), 2) )) * SGD_RADIANS_TO_DEGREES);
905 if (_polarization == 0)
906 theta_deg = 90.0 - theta;
909 if (theta_deg > 85.0) // we don't want to converge into infinity
912 double loss = 10 * log10( pow(cos(theta_deg * SGD_DEGREES_TO_RADIANS), 2) );
913 //cerr << "Polarization loss: " << loss << " dBm " << endl;
918 double FGRadioTransmission::power_to_dbm(double power_watt) {
919 return 10 * log10(1000 * power_watt); // returns dbm
922 double FGRadioTransmission::dbm_to_power(double dbm) {
923 return exp( (dbm-30) * log(10) / 10); // returns Watts
926 double FGRadioTransmission::dbm_to_microvolt(double dbm) {
927 return sqrt(dbm_to_power(dbm) * 50) * 1000000; // returns microvolts