Advertisement
Guest User

RTLSDR Panorama VSWR plot

a guest
Jan 12th, 2016
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. import os, sys, string, math
  2. import pygal
  3.  
  4. def getFileData2(i_fName):
  5.     lines = open(i_fName).readlines()
  6.     res= {}
  7.     for i in xrange(len(lines)):
  8.         l = lines[i]
  9.         tokens = string.split(l)
  10.         freq = int(tokens[2][:-1]) / 1000000
  11.         power = float(tokens[-1])
  12.         res[freq] = power
  13.     return res
  14.  
  15. def listDiff(a, b):
  16.     Len  = min(len(a), len(b))
  17.     res = [None] * Len
  18.     for i in xrange(Len):
  19.         res[i] = a[i] - b[i]
  20.     return res
  21.  
  22. def ReduceArray(i_arr, maxCount = 30):
  23.     skip = len(i_arr)/(maxCount-1)
  24.     if skip==0:
  25.         skip = 1
  26.     return i_arr[0::skip]
  27.  
  28. def PlotLines2d(x_data, y_data, outFile):
  29.     line_chart = pygal.Line(style=pygal.style.DarkSolarizedStyle, logarithmic=True, x_label_rotation=90, height=500, width=1600)
  30.     line_chart.title = ''
  31.  
  32.     line_chart.x_labels = map(str, ReduceArray(x_data[:], 100))
  33.  
  34.     line_chart.add('VSWR', ReduceArray(y_data, 100), show_dots=False)
  35.     line_chart.render_to_file(outFile)
  36.  
  37. def main():
  38.     pNoAnt = getFileData2(sys.argv[1]) # no antenna connected
  39.     pWithAnt = getFileData2(sys.argv[2]) # antenna connected
  40.     freqs = list(set(pNoAnt.keys()) & set(pWithAnt.keys()))
  41.     freqs = sorted(freqs)
  42.  
  43.     # leave only samples present in both files
  44.     for k in pNoAnt.keys():
  45.         if k not in freqs:
  46.             del pNoAnt[k]
  47.  
  48.     for k in pWithAnt.keys():
  49.         if k not in freqs:
  50.             del pWithAnt[k]
  51.  
  52.     returnLoss = [None] * len(freqs)
  53.     for i in xrange(len(freqs)):
  54.         returnLoss[i] = max( .0001, pNoAnt[freqs[i]] - pWithAnt[freqs[i]] )
  55.     print returnLoss
  56.  
  57.     vswr = map(lambda x: (pow(10, x/20) + 1)/(pow(10, x/20) - 1), returnLoss)
  58.     print vswr
  59.     PlotLines2d(freqs, vswr, sys.argv[3])
  60.  
  61.  
  62. if __name__ == '__main__':
  63.     if len(sys.argv) < 4:
  64.         print '''Usage:\n \
  65. VSWR.py noAntennaConnected.csv antenaConnected.csv outputPlot.svg
  66.         '''
  67.     else:
  68.         main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement