Skip to content

Instantly share code, notes, and snippets.

@athurg
Created December 25, 2011 11:30
Show Gist options
  • Save athurg/1519115 to your computer and use it in GitHub Desktop.
Save athurg/1519115 to your computer and use it in GitHub Desktop.
vswr and rp traslate
## fileencoding=gbk ##
from math import *
import sys
def vswr_to_rp(vswr):
'''Translate VSWR to Return Power'''
rl=20*log10((vswr+1)/(vswr-1))
rp=pout/pow(10,rl/10)
return rp
def line_to_db(val):
'''Translate linear value to dB'''
return 10*log10(val)
if __name__ == '__main__':
print(sys.argv)
# Output power & VSWR
pout=10
vswr=(1.3, 1.6)
preal=[0,0]
# Calc return power
preal[0] = pout - vswr_to_rp(vswr[0])
preal[1] = pout - vswr_to_rp(vswr[1])
# check delta
dp=line_to_db(preal[0]/preal[1])
dp=round(dp,2)
print "输出功率:",pout,"W"
print "功率差异:",dp,"dB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment