mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
feat: multisegment scan support in python script
This commit is contained in:
parent
dbfdad4fd9
commit
115047045c
|
|
@ -3,9 +3,7 @@ import serial
|
|||
import numpy as np
|
||||
import pylab as pl
|
||||
import scipy.signal as signal
|
||||
import time
|
||||
import struct
|
||||
import os
|
||||
from serial.tools import list_ports
|
||||
|
||||
VID = 0x0483 #1155
|
||||
|
|
@ -44,7 +42,7 @@ class NanoVNA:
|
|||
def frequencies(self):
|
||||
return self._frequencies
|
||||
|
||||
def set_sweep(self, start = 1e6, stop = 900e6, points = None):
|
||||
def set_frequencies(self, start = 1e6, stop = 900e6, points = None):
|
||||
if points:
|
||||
self.points = points
|
||||
self._frequencies = np.linspace(start, stop, self.points)
|
||||
|
|
@ -63,6 +61,12 @@ class NanoVNA:
|
|||
self.serial.write(cmd.encode())
|
||||
self.serial.readline() # discard empty line
|
||||
|
||||
def set_sweep(self, start, stop):
|
||||
if start is not None:
|
||||
self.send_command("sweep start %d\r" % start)
|
||||
if stop is not None:
|
||||
self.send_command("sweep stop %d\r" % stop)
|
||||
|
||||
def set_frequency(self, freq):
|
||||
if freq is not None:
|
||||
self.send_command("freq %d\r" % freq)
|
||||
|
|
@ -162,7 +166,7 @@ class NanoVNA:
|
|||
def pause(self):
|
||||
self.send_command("pause\r")
|
||||
|
||||
def scan(self, port = None):
|
||||
def scan_gamma0(self, port = None):
|
||||
self.set_port(port)
|
||||
return np.vectorize(self.gamma)(self.frequencies)
|
||||
|
||||
|
|
@ -195,13 +199,12 @@ class NanoVNA:
|
|||
else:
|
||||
self.send_command("scan %d %d\r"%(start, stop))
|
||||
|
||||
def scan_multisegment(self, start = 1e6, stop = 900e6, points = 201):
|
||||
def scan(self):
|
||||
segment_length = 101
|
||||
array0 = []
|
||||
array1 = []
|
||||
freqs = np.linspace(start, stop, points)
|
||||
self._frequencies = freqs
|
||||
while len(freqs) > 1:
|
||||
freqs = self._frequencies
|
||||
while len(freqs) > 0:
|
||||
seg_start = freqs[0]
|
||||
seg_stop = freqs[segment_length-1] if len(freqs) >= segment_length else freqs[-1]
|
||||
length = segment_length if len(freqs) >= segment_length else len(freqs)
|
||||
|
|
@ -355,6 +358,15 @@ if __name__ == '__main__':
|
|||
parser.add_option("-c", "--scan", dest="scan",
|
||||
action="store_true", default=False,
|
||||
help="scan by script", metavar="SCAN")
|
||||
parser.add_option("-S", "--start", dest="start",
|
||||
type="float", default=1e6,
|
||||
help="start frequency", metavar="START")
|
||||
parser.add_option("-E", "--stop", dest="stop",
|
||||
type="float", default=900e6,
|
||||
help="stop frequency", metavar="STOP")
|
||||
parser.add_option("-N", "--points", dest="points",
|
||||
type="int", default=101,
|
||||
help="scan points", metavar="POINTS")
|
||||
parser.add_option("-P", "--port", type="int", dest="port",
|
||||
help="port", metavar="PORT")
|
||||
parser.add_option("-d", "--dev", dest="device",
|
||||
|
|
@ -365,7 +377,7 @@ if __name__ == '__main__':
|
|||
help="gain (0-95)", metavar="GAIN")
|
||||
parser.add_option("-O", "--offset", type="int", dest="offset",
|
||||
help="offset frequency", metavar="OFFSET")
|
||||
parser.add_option("-S", "--strength", type="int", dest="strength",
|
||||
parser.add_option("--strength", type="int", dest="strength",
|
||||
help="drive strength(0-3)", metavar="STRENGTH")
|
||||
parser.add_option("-v", "--verbose",
|
||||
action="store_true", dest="verbose", default=False,
|
||||
|
|
@ -403,16 +415,17 @@ if __name__ == '__main__':
|
|||
print(np.average(samp[0::2] * samp[1::2]))
|
||||
pl.show()
|
||||
exit(0)
|
||||
if opt.start or opt.stop or opt.points:
|
||||
nv.set_frequencies(opt.start, opt.stop, opt.points)
|
||||
plot = opt.phase or opt.plot or opt.vswr or opt.delay or opt.groupdelay or opt.smith or opt.unwrapphase or opt.polar or opt.tdr
|
||||
if plot:
|
||||
if opt.scan:
|
||||
#s = nv.scan()
|
||||
s = nv.scan_multisegment()
|
||||
s = s[0]
|
||||
p = int(opt.port) if opt.port else 0
|
||||
if opt.scan or opt.points > 101:
|
||||
s = nv.scan()
|
||||
s = s[p]
|
||||
else:
|
||||
p = 0
|
||||
if opt.port:
|
||||
p = int(opt.port)
|
||||
if opt.start or opt.stop:
|
||||
nv.set_sweep(opt.start, opt.stop)
|
||||
s = nv.data(p)
|
||||
if opt.smith:
|
||||
nv.smith(s)
|
||||
|
|
|
|||
Loading…
Reference in a new issue