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 num_points= (double)_elevations.size();
362 _elevations.push_front(point_distance);
363 _elevations.push_front(num_points -1);
364 int size = _elevations.size();
365 double itm_elev[size];
366 for(int i=0;i<size;i++) {
367 itm_elev[i]=_elevations[i];
368 //cerr << "ITM:: itm_elev: " << _elevations[i] << endl;
371 if((transmission_type == 3) || (transmission_type == 4)) {
372 // the sender and receiver roles are switched
373 point_to_point(itm_elev, receiver_height, transmitter_height,
374 eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
375 pol, conf, rel, dbloss, strmode, p_mode, horizons, errnum);
376 if( fgGetBool( "/sim/radio/use-clutter-attenuation", false ) )
377 clutterLoss(frq_mhz, distance_m, itm_elev, materials, receiver_height, transmitter_height, p_mode, horizons, clutter_loss);
380 point_to_point(itm_elev, transmitter_height, receiver_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, transmitter_height, receiver_height, p_mode, horizons, clutter_loss);
386 SG_LOG(SG_GENERAL, SG_BULK,
387 "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
388 cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
390 cerr << "Clutter loss: " << clutter_loss << endl;
391 //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used
393 signal = link_budget - dbloss - clutter_loss;
398 /*** Calculate losses due to vegetation and urban clutter (WIP)
399 * We are only worried about clutter loss, terrain influence
400 * on the first Fresnel zone is calculated in the ITM functions
402 void FGRadioTransmission::clutterLoss(double freq, double distance_m, double itm_elev[], deque<string> materials,
403 double transmitter_height, double receiver_height, int p_mode,
404 double horizons[], double &clutter_loss) {
406 distance_m = itm_elev[0] * itm_elev[1]; // only consider elevation points
408 if (p_mode == 0) { // LOS: take each point and see how clutter height affects first Fresnel zone
411 for (int k=3;k < (int)(itm_elev[0]) + 2;k++) {
413 double clutter_height = 0.0; // mean clutter height for a certain terrain type
414 double clutter_density = 0.0; // percent of reflected wave
415 get_material_properties(materials[mat], clutter_height, clutter_density);
417 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
418 // First Fresnel radius
419 double frs_rad = 548 * sqrt( (j * itm_elev[1] * (itm_elev[0] - j) * itm_elev[1] / 1000000) / ( distance_m * freq / 1000) );
421 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
423 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
424 double d1 = j * itm_elev[1];
425 if ((itm_elev[2] + transmitter_height) > ( itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
426 d1 = (itm_elev[0] - j) * itm_elev[1];
428 double ray_height = (grad * d1) + min_elev;
430 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
431 double intrusion = fabs(clearance);
433 if (clearance >= 0) {
436 else if (clearance < 0 && (intrusion < clutter_height)) {
438 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
440 else if (clearance < 0 && (intrusion > clutter_height)) {
441 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
451 else if (p_mode == 1) { // diffraction
453 if (horizons[1] == 0.0) { // single horizon: same as above, except pass twice using the highest point
454 int num_points_1st = (int)floor( horizons[0] * itm_elev[0]/ distance_m );
455 int num_points_2nd = (int)ceil( (distance_m - horizons[0]) * itm_elev[0] / distance_m );
456 //cerr << "Diffraction 1 horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << endl;
458 /** perform the first pass */
461 for (int k=3;k < num_points_1st + 2;k++) {
462 if (num_points_1st < 1)
464 double clutter_height = 0.0; // mean clutter height for a certain terrain type
465 double clutter_density = 0.0; // percent of reflected wave
466 get_material_properties(materials[mat], clutter_height, clutter_density);
468 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
469 // First Fresnel radius
470 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) );
472 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
474 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
475 double d1 = j * itm_elev[1];
476 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
477 d1 = (num_points_1st - j) * itm_elev[1];
479 double ray_height = (grad * d1) + min_elev;
481 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
482 double intrusion = fabs(clearance);
484 if (clearance >= 0) {
487 else if (clearance < 0 && (intrusion < clutter_height)) {
489 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
491 else if (clearance < 0 && (intrusion > clutter_height)) {
492 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
502 /** and the second pass */
504 j =1; // first point is diffraction edge, 2nd the RX elevation
505 for (int k=last+2;k < (int)(itm_elev[0]) + 2;k++) {
506 if (num_points_2nd < 1)
508 double clutter_height = 0.0; // mean clutter height for a certain terrain type
509 double clutter_density = 0.0; // percent of reflected wave
510 get_material_properties(materials[mat], clutter_height, clutter_density);
512 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
513 // First Fresnel radius
514 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) );
516 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
518 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
519 double d1 = j * itm_elev[1];
520 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
521 d1 = (num_points_2nd - j) * itm_elev[1];
523 double ray_height = (grad * d1) + min_elev;
525 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
526 double intrusion = fabs(clearance);
528 if (clearance >= 0) {
531 else if (clearance < 0 && (intrusion < clutter_height)) {
533 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
535 else if (clearance < 0 && (intrusion > clutter_height)) {
536 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
546 else { // double horizon: same as single horizon, except there are 3 segments
548 int num_points_1st = (int)floor( horizons[0] * itm_elev[0] / distance_m );
549 int num_points_2nd = (int)floor(horizons[1] * itm_elev[0] / distance_m );
550 int num_points_3rd = (int)itm_elev[0] - num_points_1st - num_points_2nd;
551 //cerr << "Double horizon:: horizon1: " << horizons[0] << " horizon2: " << horizons[1] << " distance: " << distance_m << endl;
552 //cerr << "Double horizon:: points1: " << num_points_1st << " points2: " << num_points_2nd << " points3: " << num_points_3rd << endl;
554 /** perform the first pass */
556 int j=1; // first point is TX elevation, 2nd is obstruction elevation
557 for (int k=3;k < num_points_1st +2;k++) {
558 if (num_points_1st < 1)
560 double clutter_height = 0.0; // mean clutter height for a certain terrain type
561 double clutter_density = 0.0; // percent of reflected wave
562 get_material_properties(materials[mat], clutter_height, clutter_density);
564 double grad = fabs(itm_elev[2] + transmitter_height - itm_elev[num_points_1st + 2] + clutter_height) / distance_m;
565 // First Fresnel radius
566 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) );
568 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
570 double min_elev = SGMiscd::min(itm_elev[2] + transmitter_height, itm_elev[num_points_1st + 2] + clutter_height);
571 double d1 = j * itm_elev[1];
572 if ( (itm_elev[2] + transmitter_height) > (itm_elev[num_points_1st + 2] + clutter_height) ) {
573 d1 = (num_points_1st - j) * itm_elev[1];
575 double ray_height = (grad * d1) + min_elev;
577 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
578 double intrusion = fabs(clearance);
580 if (clearance >= 0) {
583 else if (clearance < 0 && (intrusion < clutter_height)) {
585 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
587 else if (clearance < 0 && (intrusion > clutter_height)) {
588 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
597 /** and the second pass */
599 j =1; // first point is 1st obstruction elevation, 2nd is 2nd obstruction elevation
600 for (int k=last+2;k < num_points_1st + num_points_2nd +2;k++) {
601 if (num_points_2nd < 1)
603 double clutter_height = 0.0; // mean clutter height for a certain terrain type
604 double clutter_density = 0.0; // percent of reflected wave
605 get_material_properties(materials[mat], clutter_height, clutter_density);
607 double grad = fabs(itm_elev[last+1] + clutter_height - itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) / distance_m;
608 // First Fresnel radius
609 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) );
611 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
613 double min_elev = SGMiscd::min(itm_elev[last+1] + clutter_height, itm_elev[num_points_1st + num_points_2nd +2] + clutter_height);
614 double d1 = j * itm_elev[1];
615 if ( (itm_elev[last+1] + clutter_height) > (itm_elev[num_points_1st + num_points_2nd + 2] + clutter_height) ) {
616 d1 = (num_points_2nd - j) * itm_elev[1];
618 double ray_height = (grad * d1) + min_elev;
620 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
621 double intrusion = fabs(clearance);
623 if (clearance >= 0) {
626 else if (clearance < 0 && (intrusion < clutter_height)) {
628 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
630 else if (clearance < 0 && (intrusion > clutter_height)) {
631 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
641 /** third and final pass */
643 j =1; // first point is 2nd obstruction elevation, 3rd is RX elevation
644 for (int k=last2+2;k < (int)itm_elev[0] + 2;k++) {
645 if (num_points_3rd < 1)
647 double clutter_height = 0.0; // mean clutter height for a certain terrain type
648 double clutter_density = 0.0; // percent of reflected wave
649 get_material_properties(materials[mat], clutter_height, clutter_density);
651 double grad = fabs(itm_elev[last2+1] + clutter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m;
652 // First Fresnel radius
653 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) );
656 //double earth_h = distance_m * (distance_m - j * itm_elev[1]) / ( 1000000 * 12.75 * 1.33 ); // K=4/3
658 double min_elev = SGMiscd::min(itm_elev[last2+1] + clutter_height, itm_elev[(int)itm_elev[0] + 2] + receiver_height);
659 double d1 = j * itm_elev[1];
660 if ( (itm_elev[last2+1] + clutter_height) > (itm_elev[(int)itm_elev[0] + 2] + receiver_height) ) {
661 d1 = (num_points_3rd - j) * itm_elev[1];
663 double ray_height = (grad * d1) + min_elev;
665 double clearance = ray_height - (itm_elev[k] + clutter_height) - frs_rad * 8/10;
666 double intrusion = fabs(clearance);
668 if (clearance >= 0) {
671 else if (clearance < 0 && (intrusion < clutter_height)) {
673 clutter_loss += clutter_density * (intrusion / (frs_rad * 2) ) * (freq/100) * (itm_elev[1]/100);
675 else if (clearance < 0 && (intrusion > clutter_height)) {
676 clutter_loss += clutter_density * (clutter_height / (frs_rad * 2 ) ) * (freq/100) * (itm_elev[1]/100);
688 else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
694 /*** Temporary material properties database
695 * height: median clutter height
696 * density: radiowave attenuation factor
698 void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
700 if(mat_name == "Landmass") {
705 else if(mat_name == "SomeSort") {
710 else if(mat_name == "Island") {
714 else if(mat_name == "Default") {
718 else if(mat_name == "EvergreenBroadCover") {
722 else if(mat_name == "EvergreenForest") {
726 else if(mat_name == "DeciduousBroadCover") {
730 else if(mat_name == "DeciduousForest") {
734 else if(mat_name == "MixedForestCover") {
738 else if(mat_name == "MixedForest") {
742 else if(mat_name == "RainForest") {
746 else if(mat_name == "EvergreenNeedleCover") {
750 else if(mat_name == "WoodedTundraCover") {
754 else if(mat_name == "DeciduousNeedleCover") {
758 else if(mat_name == "ScrubCover") {
762 else if(mat_name == "BuiltUpCover") {
766 else if(mat_name == "Urban") {
770 else if(mat_name == "Construction") {
774 else if(mat_name == "Industrial") {
778 else if(mat_name == "Port") {
782 else if(mat_name == "Town") {
786 else if(mat_name == "SubUrban") {
790 else if(mat_name == "CropWoodCover") {
794 else if(mat_name == "CropWood") {
798 else if(mat_name == "AgroForest") {
809 /*** implement simple LOS propagation model (WIP)
811 double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
813 if( (freq < 118.0) || (freq > 137.0) )
814 frq_mhz = 125.0; // sane value, middle of bandplan
818 double tx_pow = _transmitter_power;
819 double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
822 double sender_alt_ft,sender_alt;
823 double transmitter_height=0.0;
824 double receiver_height=0.0;
825 double own_lat = fgGetDouble("/position/latitude-deg");
826 double own_lon = fgGetDouble("/position/longitude-deg");
827 double own_alt_ft = fgGetDouble("/position/altitude-ft");
828 double own_alt= own_alt_ft * SG_FEET_TO_METER;
831 double link_budget = tx_pow - _receiver_sensitivity - _rx_line_losses - _tx_line_losses + ant_gain;
833 //cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
835 SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
837 SGGeod sender_pos = pos;
839 sender_alt_ft = sender_pos.getElevationFt();
840 sender_alt = sender_alt_ft * SG_FEET_TO_METER;
842 receiver_height = own_alt;
843 transmitter_height = sender_alt;
845 double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
848 transmitter_height += _tx_antenna_height;
849 receiver_height += _rx_antenna_height;
852 /** radio horizon calculation with wave bending k=4/3 */
853 double receiver_horizon = 4.12 * sqrt(receiver_height);
854 double transmitter_horizon = 4.12 * sqrt(transmitter_height);
855 double total_horizon = receiver_horizon + transmitter_horizon;
857 if (distance_m > total_horizon) {
861 // free-space loss (distance calculation should be changed)
862 dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
863 signal = link_budget - dbloss;
864 SG_LOG(SG_GENERAL, SG_BULK,
865 "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm ");
866 //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl;
871 /*** calculate loss due to polarization mismatch
872 * this function is only reliable for vertical polarization
873 * due to the V-shape of horizontally polarized antennas
875 double FGRadioTransmission::polarization_loss() {
878 double roll = fgGetDouble("/orientation/roll-deg");
879 double pitch = fgGetDouble("/orientation/pitch-deg");
880 double theta = acos( sqrt( cos(roll) * cos(roll) + cos(pitch) * cos(pitch) ));
881 if (_polarization == 1)
882 theta_deg = 90.0 - theta;
885 if (fabs(theta_deg) > 85.0) // we don't want to converge into infinity
887 return 10 * log10(cos(theta_deg) * cos(theta_deg));