mirror of
https://github.com/fairwaves/UHD-Fairwaves.git
synced 2025-10-23 07:42:00 +00:00
host: Complete calculations for VSWR in Python utils + better sensors output.
This commit is contained in:
@@ -1,30 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
##########################
|
||||
### VSWR calculations
|
||||
##########################
|
||||
|
||||
# Implemented as described at:
|
||||
# http://www.markimicrowave.com/assets/data/return%20loss%20to%20vswr.pdf
|
||||
|
||||
import math
|
||||
|
||||
TM10_VSWR_cal=0.3
|
||||
|
||||
def vswr_volts_to_db(VPF, VPR, calibration=0, coef=0.05):
|
||||
return (VPF-VPR-calibration)/coef
|
||||
|
||||
def db_to_vswr(db):
|
||||
gamma = math.pow(10, -db/20.0)
|
||||
return (1+gamma)/(1-gamma)
|
||||
|
||||
|
||||
##########################
|
||||
### Query sensors
|
||||
##########################
|
||||
|
||||
from umtrx_property_tree import umtrx_property_tree
|
||||
from umtrx_vswr import umtrx_vswr
|
||||
|
||||
s = umtrx_property_tree()
|
||||
s.connect()
|
||||
@@ -33,10 +15,17 @@ sensors_path="/mboards/0/sensors"
|
||||
res = s.list_path_raw(sensors_path)
|
||||
sensors_list = res.get('result', [])
|
||||
|
||||
print "Sensors:"
|
||||
for sensor in sensors_list:
|
||||
print s.query_sensor_raw(sensors_path+"/"+sensor)
|
||||
reply = s.query_sensor_raw(sensors_path+"/"+sensor)
|
||||
if reply.has_key('result'):
|
||||
res = reply['result']
|
||||
print " %15s = %9s %s" % (res['name'], res['value'], res['unit'])
|
||||
else:
|
||||
print "Can't read sensor %s" % sensor
|
||||
|
||||
#vswr_calibration = TM10_VSWR_cal
|
||||
#vswr_calibration = TM3_VSWR_cal
|
||||
vswr_calibration = 0
|
||||
for num in [1, 2]:
|
||||
vpr_name = 'voltagePR'+str(num)
|
||||
@@ -44,11 +33,17 @@ for num in [1, 2]:
|
||||
if vpr_name in sensors_list and vpf_name in sensors_list:
|
||||
vpr = float(s.query_sensor_value(sensors_path+'/'+vpr_name))
|
||||
vpf = float(s.query_sensor_value(sensors_path+'/'+vpf_name))
|
||||
vswr_db = vswr_volts_to_db(vpf, vpr, vswr_calibration)
|
||||
if vswr_db == 0.0:
|
||||
vswr = float("inf")
|
||||
else:
|
||||
vswr = db_to_vswr(vswr_db)
|
||||
print "Channel %d VSWR = %.2f = %.1f dB" % (num, vswr, vswr_db)
|
||||
vswr = umtrx_vswr(vpf, vpr, vswr_calibration)
|
||||
print "TRX %d power detector:" % num
|
||||
print " VPF = %5.2f V" % vpf
|
||||
print " PF = %5.1f dBm" % vswr.pf()
|
||||
print " VPR = %5.2f V" % vpr
|
||||
print " PR = %5.1f dBm" % vswr.pr()
|
||||
print " VSWR = %6.2f" % vswr.vswr()
|
||||
print " Gamma = %5.3f" % vswr.gamma()
|
||||
print " Return Loss = %5.1f dB" % vswr.return_loss()
|
||||
print " Mismatch Loss = %5.3f dB" % vswr.mismatch_loss()
|
||||
print " Through power = %5.2f %%" % (100.0*vswr.pf_rate())
|
||||
print " Reflected power = %5.2f %%" % (100.0*vswr.pr_rate())
|
||||
|
||||
s.close()
|
||||
|
68
host/utils/umtrx_vswr.py
Normal file
68
host/utils/umtrx_vswr.py
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
##########################
|
||||
### VSWR calculations
|
||||
##########################
|
||||
|
||||
# Implemented as described at:
|
||||
# http://www.markimicrowave.com/assets/data/return%20loss%20to%20vswr.pdf
|
||||
|
||||
import math
|
||||
|
||||
# TODO: requires better calibration
|
||||
TM10_VSWR_cal=0.3/2
|
||||
|
||||
class umtrx_vswr:
|
||||
def __init__(self, VPF, VPR, calibration=0, coef=0.05):
|
||||
self.vpf = VPF
|
||||
self.vpr = VPR
|
||||
self.calibration = calibration
|
||||
self.coef = coef
|
||||
self._gamma = self._calc_gamma()
|
||||
|
||||
def _calc_gamma(self):
|
||||
''' Internal function: calculate Gamma '''
|
||||
return math.pow(10, -self.return_loss()/20.0)
|
||||
|
||||
def pf(self):
|
||||
''' Estimated through power, dBm '''
|
||||
return (self.vpf-self.calibration)/self.coef
|
||||
|
||||
def pr(self):
|
||||
''' Estimated reflected power, dBm '''
|
||||
return (self.vpr-self.calibration)/self.coef
|
||||
|
||||
def return_loss(self):
|
||||
''' Estimated return loss, dB '''
|
||||
return self.pf()-self.pr()
|
||||
|
||||
def gamma(self):
|
||||
''' Estimated Gamma '''
|
||||
return self._gamma
|
||||
|
||||
def vswr(self):
|
||||
''' Estimated VSWR '''
|
||||
gamma = self._gamma
|
||||
if gamma == 1.0:
|
||||
return float("inf")
|
||||
else:
|
||||
return (1+gamma)/(1-gamma)
|
||||
|
||||
def mismatch_loss(self):
|
||||
''' Estimated mismatch loss, dB '''
|
||||
gamma = self._gamma
|
||||
if gamma == 1.0:
|
||||
return float("-inf")
|
||||
else:
|
||||
return -10.0 * math.log(1.0-gamma*gamma, 10)
|
||||
|
||||
def pf_rate(self):
|
||||
''' Estimated reflected power rate, % '''
|
||||
gamma = self._gamma
|
||||
return 1.0 - gamma*gamma
|
||||
|
||||
def pr_rate(self):
|
||||
''' Estimated reflected power rate, % '''
|
||||
gamma = self._gamma
|
||||
return gamma*gamma
|
Reference in New Issue
Block a user