Mercurial > ~darius > hgwebdir.cgi > pyinst
changeset 47:fa728cf34f50
- Calculate ENR (based on table on the back of our noise source)
- Accept options to set frequency, span, etc
- Actually call the setup routine
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 31 Jan 2013 11:24:49 +1030 |
parents | a6e5c97b4767 |
children | 386e1cb04799 |
files | rs_fsp7_noisetest.py |
diffstat | 1 files changed, 53 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/rs_fsp7_noisetest.py Thu Dec 20 11:48:19 2012 +1030 +++ b/rs_fsp7_noisetest.py Thu Jan 31 11:24:49 2013 +1030 @@ -26,11 +26,30 @@ # import math +import numpy +import optparse import rsib +import scipy import scpi import sys -def setup(r): +def findenr(frq): + # ENR values from the noise source + enrdb = numpy.array([15.55, 15.96, 15.68, 15.11, 15.07, 14.84, 14.77, 14.82, 14.86, 14.79, 14.83, 14.93, 14.93, 15.07, 15.19, 15.08, 15.14, 14.87, 14.97, 14.59]) + enrfrq = numpy.array([0.01e9, 0.1e9, 1.0e9, 2.0e9, 3.0e9, 4.0e9, 5.0e9, 6.0e9, 7.0e9, 8.0e9, 9.0e9, 10.0e9, 11.0e9, 12.0e9, 13.0e9, 14.0e9, 15.0e9, 16.0e9, 17.0e9, 18.0e9]) + + # Convert back to linear values + enr = 10 ** (enrdb / 10) + + # Interpolate + rtn = scipy.interp([frq], enrfrq, enr) + + # Convert to dB + rtndb = 10 * math.log10(rtn) + + return rtndb + +def setup(r, freq, span, sweeps): # Reset to defaults r.write("*RST") @@ -41,7 +60,8 @@ r.write("SYST:DISP:UPD ON") # Set frequency range - r.write("FREQ:CEN 10.7MHz;SPAN 1MHz") + r.write("SENSE1:FREQ:CENT %f Hz" % (freq)) + r.write("SENSE1:FREQ:SPAN %f Hz" % (span)) # Switch marker 1 on in screen A r.write("CALC:MARK1 ON") @@ -50,13 +70,13 @@ r.write("CALC:MARK1:FUNC:NOIS ON") # Set number of sweeps - r.write("SWE:COUN 20") + r.write("SWE:COUN %d" % (sweeps)) # Set resolution bandwidth - r.write("SENS1:BAND:RES 10kHz") + r.write("SENS1:BAND:RES 1kHz") # Set video bandwidth (10x res BW) - r.write("SENS1:BAND:VID 100kHz") + r.write("SENS1:BAND:VID 10kHz") def getnoise(r): # Trigger the sweep @@ -105,19 +125,43 @@ return off, on, calcnf(enr, off, on) if __name__ == '__main__': - enr = 15.55 # From back of noise source - r = rsib.RSIBDevice('analyzer') + parser = optparse.OptionParser(usage = '%prog [options] address frequency') + parser.add_option('-s', '--span', dest = 'span', default = 1e6, help = 'Span frequency (Hz)', type = float) + parser.add_option('-i', '--input', dest = 'input', default = None, help = 'Input frequency (Hz) for down converters', type = float) + parser.add_option('-w', '--sweeps', dest = 'sweeps', default = 20, help = 'Number of sweeps', type = int) + + (options, args) = parser.parse_args() + + if len(args) != 2: + parser.error('Must supply the specan address and centre frequency') + + addr = args[0] + try: + freq = float(args[1]) + except ValueError: + parser.error('Unable to parse frequency') + + if options.input == None: + options.input = freq + + # Compute ENR at frequency of interest + enr = findenr(options.input) + + # Connect to the analyser + r = rsib.RSIBDevice(addr) # ID instrument r.write('*IDN?') print "ID is " + r.read(5) - #setup(r) + # Setup parameters + setup(r, freq, options.span, options.sweeps) + r.write("INIT:CONT OFF") while True: off, on, nf = donoisetest(r, enr) - print "Off %.3f dB, on %.3f dB, NF %.2f" % (off, on, nf) + print "Off %.3f dB, on %.3f dB, ENR %.2f, NF %.2f" % (off, on, enr, nf) print "Press enter to perform a new measurement" sys.stdin.readline()