Attribute VB_Name = "Module1" Function Log10(X) Log10 = Log(X) / Log(10#) End Function Public Function dBPwr(WRatio) dBPwr = 10 * Log10(WRatio) End Function Public Function InvdB(dB10) InvdB = 10 ^ (dB10 / 10) End Function Public Function dBmToW(dBm) 'dBm to Watts dBmToW = 0.001 * 10 ^ (dBm / 10) End Function Public Function WTodBm(Watts) WTodBm = dBPwr(Watts * 1000) End Function Public Function CascNF(NF1, NF2, Gain1) CascNF = dBPwr(InvdB(NF1) + (InvdB(NF2) - 1) / InvdB(Gain1)) End Function Public Function PwrSum(dBm1, dBm2) PwrSum = WTodBm(dBmToW(dBm1) + dBmToW(dBm2)) End Function Public Function VoltSum(dBm1, dBm2) 'Used to cascade IM products R = 50 'value Not important VoltSum = dBmToV(dBm1, R) + dBmToV(dBm2, R) VoltSum = VTodBm(VoltSum, R) End Function Static Function dBmToV(dBm, R) 'Returns RMS voltage dBmToV = Sqr(InvdB(dBm) * R / 1000) End Function Public Function VTodBm(Vrms, R) 'Assumes V is the RMS value VTodBm = WTodBm(Vrms * Vrms / R) End Function Public Function CascIIP3(Order, IIP1, IIP2, Gain1) Ex = (Order - 1) / 2 Pwr1 = InvdB(IIP1) Pwr2 = InvdB(IIP2) GainRatio = InvdB(Gain1) Sum = 1 / (Pwr1 ^ Ex) + 1 / ((Pwr2 / GainRatio) ^ Ex) Casc = 1 / (Sum ^ 1 / Ex) CascIIP3 = dBPwr(Casc) End Function Public Function dBmPno(NF, G, BW) dBmPno = G + NF + dBPwr(BW) + KTdBm() If dBmPno < KTdBm() Then dBmPno = KTdBm() End If End Function Public Function Kb() 'Boltzman Constant Kb = 1.38 * 1E-23 End Function Public Function Tk() 'Standard Temp in Kelvin Tk = 290 End Function Public Function KTdBm() KTdBm = WTodBm(Kb() * Tk) End Function Public Function IMdBm(Order, IP, Tone) Delta = IP - Tone IMdBm = -(Delta * (Order - 1)) + Tone End Function Static Function Limit(SigIndBm, VoLimrms, GainMax, R) 'Returns the Available Gain Limit = GainMax Vcalc = dBmToV(SigIndBm + GainMax, R) If Vcalc > VoLimrms Then Limit = VTodBm(VoLimrms, R) - SigIndBm End If End Function Public Function RmsToPk(Vrms) RmsToPk = Vrms * Sqr(2) End Function Public Function IIP3(Sig_Gain, In_Tone_Pwr, Out_Prod_Pwr) 'In_Tone_Pwr is the dBm power of the interferer at the input to the system 'Out_Prod_Pwr is the dBm power of the distortion product at the output of the block 'Gain is the cascaded gain in dB for the signal path to the output of the block. In_Prod_Pwr = Out_Prod_Pwr - Sig_Gain Delta = In_Tone_Pwr - In_Prod_Pwr IIP3 = In_Tone_Pwr + Delta / 2 End Function Public Function RhoToZ(Rho, Zo) 'Calculates the Load impedance from Reflection coeficient 'and Characteristic. RhoToZ = Zo * (1 + Rho) / (1 - Rho) End Function Public Function ZToRho(Zo, Zload) 'Calculates the Reflection coeficient, given the characteristic 'impedance and the load impedance. ZToRho = (Zload - Zo) / (Zload + Zo) End Function Public Function VSWR(Rho) 'Calculates the Voltage Standing Wave Ratio, given the reflection 'coeficient. VSWR = (1 + Abs(Rho)) / (1 - Abs(Rho)) End Function