comparison rs_fsp7_noisetest.py @ 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
comparison
equal deleted inserted replaced
46:a6e5c97b4767 47:fa728cf34f50
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE. 25 # SUCH DAMAGE.
26 # 26 #
27 27
28 import math 28 import math
29 import numpy
30 import optparse
29 import rsib 31 import rsib
32 import scipy
30 import scpi 33 import scpi
31 import sys 34 import sys
32 35
33 def setup(r): 36 def findenr(frq):
37 # ENR values from the noise source
38 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])
39 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])
40
41 # Convert back to linear values
42 enr = 10 ** (enrdb / 10)
43
44 # Interpolate
45 rtn = scipy.interp([frq], enrfrq, enr)
46
47 # Convert to dB
48 rtndb = 10 * math.log10(rtn)
49
50 return rtndb
51
52 def setup(r, freq, span, sweeps):
34 # Reset to defaults 53 # Reset to defaults
35 r.write("*RST") 54 r.write("*RST")
36 55
37 # Set to single sweep mode 56 # Set to single sweep mode
38 r.write("INIT:CONT OFF") 57 r.write("INIT:CONT OFF")
39 58
40 # Enable display updates 59 # Enable display updates
41 r.write("SYST:DISP:UPD ON") 60 r.write("SYST:DISP:UPD ON")
42 61
43 # Set frequency range 62 # Set frequency range
44 r.write("FREQ:CEN 10.7MHz;SPAN 1MHz") 63 r.write("SENSE1:FREQ:CENT %f Hz" % (freq))
64 r.write("SENSE1:FREQ:SPAN %f Hz" % (span))
45 65
46 # Switch marker 1 on in screen A 66 # Switch marker 1 on in screen A
47 r.write("CALC:MARK1 ON") 67 r.write("CALC:MARK1 ON")
48 68
49 # Enable noise measurement 69 # Enable noise measurement
50 r.write("CALC:MARK1:FUNC:NOIS ON") 70 r.write("CALC:MARK1:FUNC:NOIS ON")
51 71
52 # Set number of sweeps 72 # Set number of sweeps
53 r.write("SWE:COUN 20") 73 r.write("SWE:COUN %d" % (sweeps))
54 74
55 # Set resolution bandwidth 75 # Set resolution bandwidth
56 r.write("SENS1:BAND:RES 10kHz") 76 r.write("SENS1:BAND:RES 1kHz")
57 77
58 # Set video bandwidth (10x res BW) 78 # Set video bandwidth (10x res BW)
59 r.write("SENS1:BAND:VID 100kHz") 79 r.write("SENS1:BAND:VID 10kHz")
60 80
61 def getnoise(r): 81 def getnoise(r):
62 # Trigger the sweep 82 # Trigger the sweep
63 r.write("INIT;*WAI") 83 r.write("INIT;*WAI")
64 84
103 setnoise(r, True) 123 setnoise(r, True)
104 on = getnoise(r) 124 on = getnoise(r)
105 return off, on, calcnf(enr, off, on) 125 return off, on, calcnf(enr, off, on)
106 126
107 if __name__ == '__main__': 127 if __name__ == '__main__':
108 enr = 15.55 # From back of noise source 128 parser = optparse.OptionParser(usage = '%prog [options] address frequency')
109 r = rsib.RSIBDevice('analyzer') 129 parser.add_option('-s', '--span', dest = 'span', default = 1e6, help = 'Span frequency (Hz)', type = float)
130 parser.add_option('-i', '--input', dest = 'input', default = None, help = 'Input frequency (Hz) for down converters', type = float)
131 parser.add_option('-w', '--sweeps', dest = 'sweeps', default = 20, help = 'Number of sweeps', type = int)
132
133 (options, args) = parser.parse_args()
134
135 if len(args) != 2:
136 parser.error('Must supply the specan address and centre frequency')
137
138 addr = args[0]
139 try:
140 freq = float(args[1])
141 except ValueError:
142 parser.error('Unable to parse frequency')
143
144 if options.input == None:
145 options.input = freq
146
147 # Compute ENR at frequency of interest
148 enr = findenr(options.input)
149
150 # Connect to the analyser
151 r = rsib.RSIBDevice(addr)
110 152
111 # ID instrument 153 # ID instrument
112 r.write('*IDN?') 154 r.write('*IDN?')
113 print "ID is " + r.read(5) 155 print "ID is " + r.read(5)
114 156
115 #setup(r) 157 # Setup parameters
158 setup(r, freq, options.span, options.sweeps)
159
116 r.write("INIT:CONT OFF") 160 r.write("INIT:CONT OFF")
117 161
118 while True: 162 while True:
119 off, on, nf = donoisetest(r, enr) 163 off, on, nf = donoisetest(r, enr)
120 print "Off %.3f dB, on %.3f dB, NF %.2f" % (off, on, nf) 164 print "Off %.3f dB, on %.3f dB, ENR %.2f, NF %.2f" % (off, on, enr, nf)
121 print "Press enter to perform a new measurement" 165 print "Press enter to perform a new measurement"
122 sys.stdin.readline() 166 sys.stdin.readline()
123 167