First, set up your script.
- Go to C:\Program Files\AGI\STK 12\CodeSamples\CodeSamples.zip.
- Extract the ZIP to a directory of your choice.
- Go to <chosen directory>\CodeSamples\Extend\PluginScripts\VB_AbsorpModel.vbs.
- Open the file and declare new variables:
- x (scale factor)
- xr (scale factor * range)
- XR_out (xr taken out of dB)
- noise_loss (used to calculate noise temperature)
- 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.
- Open STK.
- Create a new scenario or open an existing one.
- In the scenario's properties, go to the RF - Environment - Custom Models page.
- Select the Use A check box.
- Click the ellipsis (...), find and select your script, and then click Open.
- Back in the properties, click OK to accept your changes.
Finally, compute accesses and generate a report to assess the data.
- Compute Access between any Transmitter and Receiver.
- From within the Access panel, open the Report & Graph Manger.
- Create a new report style with the following data provider information:
- Link Information - Time
- Link Information - Range
- Link Information - UserCustomA Loss
- Click OK to accept your changes.
- Generate the new report.
- For a scale factor of x = 2, the data should resemble the following:
