How to Attenuate RF Signals by Distance Using a Plugin Script

« Go Back

Information

 
ProblemHow can I dynamically model signal losses over distances with a known loss factor?
Solution
First, set up your script.
  1. Go to C:\Program Files\AGI\STK 12\CodeSamples\CodeSamples.zip.
  2. Extract the ZIP to a directory of your choice.
  3. Go to <chosen directory>\CodeSamples\Extend\PluginScripts\VB_AbsorpModel.vbs.
  4. Open the file and declare new variables:
    1. x (scale factor)
    2. xr (scale factor * range)
    3. XR_out (xr taken out of dB)
    4. noise_loss (used to calculate noise temperature)
  5. Replace lines 148 - 154 with the following code sample:
 
'Scale factor in dB/km (set by user).
x = 2
	
'Range in km (distance formula).
range = Sqr((fromX-toX)^2 + (fromY-toY)^2 + (fromZ-toZ)^2) / 1000
	
'Impose a lower bound to avoid underflow.
If range <= 0 Then
	
    range = 0.00001
    MsgBox("Range is 0. There will be no loss at this distance.")
	    'Note: if range <= 0, STK will throw an error, but the script will keep running.
	    'The error can be ignored for this application.
		
End If
	
'Scaled range value.
xr = x * range
	
'Impose an upper bound to avoid overflow.
If (xr) >= 3000 Then
	
	xr = 3000
	MsgBox("Loss is too high. There will be no signal received at this distance.")
		
End If
	
'Scaled range value taken out of dB (STK will put back in dB).
XR_out = 10^((xr)/10)

'Calculate free space and noise loss.
freeSpace = (4 * 3.141592 * range * freq) / 299792458.0
noise_loss = 10^(Log10(freeSpace * freeSpace)/10)

'Return values to STK.
returnValue(VB_AbsorpModel_Outputs.AbsorpLoss) = 1.0/(XR_out)
returnValue(VB_AbsorpModel_Outputs.NoiseTemp)  = 273.15 * (1 - 1.0/noise_loss)
 
Next, apply the script to your scenario.
  1. Open STK.
  2. Create a new scenario or open an existing one.
  3. In the scenario's properties, go to the RF - Environment - Custom Models page.
  4. Select the Use A check box.
  5. Click the ellipsis (...), find and select your script, and then click Open.
  6. Back in the properties, click OK to accept your changes.

image.png
 
Finally, compute accesses and generate a report to assess the data.
  1. Compute Access between any Transmitter and Receiver.
  2. From within the Access panel, open the Report & Graph Manger.
  3. Create a new report style with the following data provider information:
    1. Link Information - Time
    2. Link Information - Range
    3. Link Information - UserCustomA Loss
  4. Click OK to accept your changes.
  5. Generate the new report.
  6. For a scale factor of x = 2, the data should resemble the following:

image.png
ProductSTK
Version(s)
TitleHow to Attenuate RF Signals by Distance Using a Plugin Script
URL NameHow-to-Attenuate-RF-Signals-by-Distance-Using-a-Plugin-Script

Related Files