The following programming example is written in Python and calculates ILD (Insertion Loss Deviation).
The Python file called from PLTS should contain a pure function definition block. The syntax is as follows:
def functionName( parameters ):
“function_docstring” (optional)
import modules
function_suite
return [expression]
The parameters passed from PLTS are treated as complex column vectors. The return value from the Python function back to PLTS should be a column vector.
def ILD(measFreq, Sdd21):
"Calculate insertion loss deviation"
import numpy as np
from numpy import transpose
from numpy.linalg import inv
Sdd21_dB = 20 * np.log10(np.squeeze(Sdd21))
freq = np.real(measFreq)
length = len(freq)
Fb = freq.item(length-1)
fILmin = 10e6
fILmax = Fb
startIndex = 0
stopIndex = length - 1
for i in range (length):
if freq.item(i)>=fILmin:
startIndex
= i
break
for i in range (length):
if freq.item(i) >= fILmax:
stopIndex
= i
break
freq_trunc = freq[startIndex:stopIndex+1]
Sdd21_trunc = Sdd21_dB[startIndex:stopIndex+1]
freq_trunc = np.matrix(freq_trunc).transpose()
Sdd21_trunc = np.matrix(Sdd21_trunc).transpose()
IL = -1 * Sdd21_trunc
item1 = np.sqrt(freq_trunc*1e-9)
item2 = freq_trunc*1e-9
item3 = np.power(freq_trunc*1e-9, 2)
F = np.array([item1, item2, item3])
F = np.matrix(F).transpose()
F_transpose = F.transpose()
product = np.matrix(F_transpose) * np.matrix(F)
F_inverse = inv(product)
temp = np.matmul(F_inverse, F_transpose)
coeff = np.matmul(temp, np.matrix(IL))
ILfitted = -1 * np.matmul(F, coeff)
ILD = np.power(10, 0.05 * (Sdd21_trunc - ILfitted))
return ILD