NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
NTN_PropagationUtils.c
1#include "NTN_PropagationModel.h"
2#include "LTENR_PropagationModel.h"
3#include "NTN_PropagationUtils.h"
4#include <math.h>
5
6#define BOLTZMANN 1.38064852e-23 //m2kgs-2K-1
7#define TEMPERATURE 300 //kelvin
8
9void updateNoisePower(ptrLTENR_PROPAGATIONINFO propInfo)
10{
11 ptrNTN_PROPAGATIONCONFIG ntnInfo = getNTN_PropInfo();
12 double noise = BOLTZMANN * TEMPERATURE * ntnInfo->channelBandwidth * 1000000; //in W
13 noise *= 1000; // in mW
14 propInfo->downlink.thermalNoise = MW_TO_DBM(noise);
15}
16
17double calculate_sinr(double dReceivedPower_dbm, double interferencePower_dBm, double bandwidth_mHz)
18{
19 double noise = BOLTZMANN * TEMPERATURE * bandwidth_mHz * 1000000; //in W
20 double Pmw = DBM_TO_MW(dReceivedPower_dbm);
21 double Imw = DBM_TO_MW(interferencePower_dBm);
22 noise *= 1000; // in mW
23 return MW_TO_DBM(Pmw / (Imw + noise));
24}
25
26double NTNget_LOS_probability(NTN_SCENARIO scenario, double elevationAngle)
27{
28 const int TABLE_SIZE = 9; // Constant table size for all scenarios
29
30 elevationAngle = quantizeElevationAngle(elevationAngle);
31 NTN_LOS_ElevationAngleTable* table;
32
33 switch (scenario)
34 {
35 case NTN_SCENARIO_DENSE_URBAN:
36 table = denseUrbanScenario;
37 break;
38 case NTN_SCENARIO_URBAN:
39 table = urbanScenario;
40 break;
41 case NTN_SCENARIO_RURAL:
42 table = ruralScenario;
43 break;
44 default:
45 fprintf(stderr, "Unknown scenario type");
46 return -1;
47 }
48
49 // Find the LOS probability based on elevation angle
50 for (int i = 0; i < TABLE_SIZE; i++)
51 {
52 if (table[i].elevationAngle == elevationAngle) {
53 return table[i].LOS_probability;
54 }
55 }
56 fprintf(stderr, "Elevation angle entry not found in the los probability table");
57 return -1;
58}
59
60double get_shadowingSD(NTN_SCENARIO scenario, NTN_LOS_NLOS_STATE state, NTN_CARRIER_BAND band,double elevationAngle)
61{
62 NTN_ShadowingSD_ElevationAngleTable* table;
63 const int TABLE_SIZE = 9;
64
65 elevationAngle = quantizeElevationAngle(elevationAngle);
66
67 // Select the appropriate table based on scenario and band
68 if (scenario == NTN_SCENARIO_DENSE_URBAN)
69 {
70 table = (band == NTN_BAND_S) ? sBandShadowingSD_DenseUrban : kaBandShadowingSD_DenseUrban;
71 }
72 else if (scenario == NTN_SCENARIO_URBAN)
73 {
74 table = (band == NTN_BAND_S) ? sBandShadowingSD_Urban : kaBandShadowingSD_Urban;
75 }
76 else if (scenario == NTN_SCENARIO_RURAL)
77 {
78 table = (band == NTN_BAND_S) ? sBandShadowingSD_Rural : kaBandShadowingSD_Rural;
79 }
80 else
81 table = NULL;
82
83 if (table == NULL) {
84 fprintf(stderr, "Unknown NTN scenario for shadowing SD calculations\n");
85 return 6; // Return -1 to indicate error
86 }
87
88 for (int i = 0; i < TABLE_SIZE; i++) {
89 if (table[i].elevationAngle == elevationAngle) {
90 // Return the appropriate standard deviation based on LOS or NLOS state
91 return (state == NTN_STATE_LOS) ? table[i].standardDeviation_LOS : table[i].standardDeviation_NLOS;
92 }
93 }
94
95 fprintf(stderr, "Nearest elevation angle not found for shadowing SD calculations");
96 return 6; //Ask what will be suitable to return
97}
98
99double get_clutterloss(NTN_SCENARIO scenario, NTN_LOS_NLOS_STATE state, NTN_CARRIER_BAND band, double elevationAngle)
100{
101 NTN_ShadowingSD_ElevationAngleTable* table;
102 const int TABLE_SIZE = 9;
103
104 elevationAngle = quantizeElevationAngle(elevationAngle);
105
106 if (scenario == NTN_SCENARIO_DENSE_URBAN)
107 {
108 table = (band == NTN_BAND_S) ? sBandShadowingSD_DenseUrban : kaBandShadowingSD_DenseUrban;
109 }
110 else if (scenario == NTN_SCENARIO_URBAN)
111 {
112 table = (band == NTN_BAND_S) ? sBandShadowingSD_Urban : kaBandShadowingSD_Urban;
113 }
114 else if (scenario == NTN_SCENARIO_RURAL)
115 {
116 table = (band == NTN_BAND_S) ? sBandShadowingSD_Rural : kaBandShadowingSD_Rural;
117 }
118 else
119 table = NULL;
120
121 if (table == NULL) {
122 fprintf(stderr, "Unknown NTN scenario for clutter loss calculations\n");
123 return -1; // Return -1 to indicate error
124 }
125
126 for (int i = 0; i < TABLE_SIZE; i++) {
127 if (table[i].elevationAngle == elevationAngle) {
128 // Return the respective clutterloss for NLOS scenarios as per table
129 return (state == NTN_STATE_LOS) ? 0 : table[i].clutterLoss_dB;
130 }
131 }
132
133 fprintf(stderr, "Nearest elevation angle not found for clutter loss calculations");
134 return -1; //Ask what will be suitable to return
135}
136
137double quantizeElevationAngle(double elevAngle) {
138
139 double elevAngleQuantized;
140
141 elevAngleQuantized = elevAngle <= 10 ? 10 : round(elevAngle / 10.0) * 10;
142 return elevAngleQuantized;
143}
144
145int countDistinctBeamChannels(BeamNode* head) {
146 int uniqueCount = 0;
147 int seen[20] = { 0 };
148
149 BeamNode* temp = head;
150
151 while (temp != NULL) {
152
153 if (!seen[temp->beamChannelId])
154 {
155 seen[temp->beamChannelId] = 1;
156 uniqueCount++;
157 }
158 temp = temp->next;
159 }
160
161 return uniqueCount;
162}