Mercurial > ~darius > hgwebdir.cgi > pyinst
comparison rs_fsp7_noisetest.py @ 51:03b06d71f0fd
Allow bandwith to be set (maintains a 10:1 ratio of vid:res BW)
author | Daniel O'Connor <doconnor@gsoft.com.au> |
---|---|
date | Thu, 21 Mar 2013 11:11:10 +1030 |
parents | d143ef509fb7 |
children | c1891d9074c1 |
comparison
equal
deleted
inserted
replaced
50:d143ef509fb7 | 51:03b06d71f0fd |
---|---|
47 # Convert to dB | 47 # Convert to dB |
48 rtndb = 10 * math.log10(rtn) | 48 rtndb = 10 * math.log10(rtn) |
49 | 49 |
50 return rtndb | 50 return rtndb |
51 | 51 |
52 def setup(r, freq, span, sweeps): | 52 def setup(r, freq, span, sweeps, bw): |
53 # Reset to defaults | 53 # Reset to defaults |
54 r.write("*RST") | 54 r.write("*RST") |
55 | 55 |
56 # Set to single sweep mode | 56 # Set to single sweep mode |
57 r.write("INIT:CONT OFF") | 57 r.write("INIT:CONT OFF") |
74 | 74 |
75 # Set number of sweeps | 75 # Set number of sweeps |
76 r.write("SWE:COUN %d" % (sweeps)) | 76 r.write("SWE:COUN %d" % (sweeps)) |
77 | 77 |
78 # Set resolution bandwidth | 78 # Set resolution bandwidth |
79 r.write("SENS1:BAND:RES 1kHz") | 79 r.write("SENS1:BAND:RES %f Hz" % (bw)) |
80 | 80 |
81 # Set video bandwidth (10x res BW) | 81 # Set video bandwidth (10x res BW) |
82 r.write("SENS1:BAND:VID 10kHz") | 82 r.write("SENS1:BAND:VID %f Hz" % (bw * 10)) |
83 | 83 |
84 def getnoise(r): | 84 def getnoise(r): |
85 # Trigger the sweep | 85 # Trigger the sweep |
86 r.write("INIT;*WAI") | 86 r.write("INIT;*WAI") |
87 | 87 |
88 # Wait for it to be done | 88 # Wait for it to be done |
89 r.write("*OPC?") | 89 r.write("*OPC?") |
90 opc = scpi.getdata(r.read(60), int) | 90 opc = scpi.getdata(r.read(None), int) |
91 #print "OPC - %d" % (opc) | 91 #print "OPC - %d" % (opc) |
92 assert(opc == 1) | 92 assert(opc == 1) |
93 | 93 |
94 # Set data format | 94 # Set data format |
95 r.write("FORM:DATA ASC") | 95 r.write("FORM:DATA ASC") |
130 if __name__ == '__main__': | 130 if __name__ == '__main__': |
131 parser = optparse.OptionParser(usage = '%prog [options] address frequency') | 131 parser = optparse.OptionParser(usage = '%prog [options] address frequency') |
132 parser.add_option('-s', '--span', dest = 'span', default = 1e6, help = 'Span frequency (Hz)', type = float) | 132 parser.add_option('-s', '--span', dest = 'span', default = 1e6, help = 'Span frequency (Hz)', type = float) |
133 parser.add_option('-i', '--input', dest = 'input', default = None, help = 'Input frequency (Hz) for down converters', type = float) | 133 parser.add_option('-i', '--input', dest = 'input', default = None, help = 'Input frequency (Hz) for down converters', type = float) |
134 parser.add_option('-w', '--sweeps', dest = 'sweeps', default = 20, help = 'Number of sweeps', type = int) | 134 parser.add_option('-w', '--sweeps', dest = 'sweeps', default = 20, help = 'Number of sweeps', type = int) |
135 parser.add_option('-b', '--bw', dest = 'bw', default = 1000, help = 'Bandwidth (Hz)', type = float) | |
135 | 136 |
136 (options, args) = parser.parse_args() | 137 (options, args) = parser.parse_args() |
137 | 138 |
138 if len(args) != 2: | 139 if len(args) != 2: |
139 parser.error('Must supply the specan address and centre frequency') | 140 parser.error('Must supply the specan address and centre frequency') |
156 # ID instrument | 157 # ID instrument |
157 r.write('*IDN?') | 158 r.write('*IDN?') |
158 print "ID is " + r.read(5) | 159 print "ID is " + r.read(5) |
159 | 160 |
160 # Setup parameters | 161 # Setup parameters |
161 setup(r, freq, options.span, options.sweeps) | 162 setup(r, freq, options.span, options.sweeps, options.bw) |
162 | 163 |
163 r.write("INIT:CONT OFF") | 164 r.write("INIT:CONT OFF") |
164 | 165 |
165 print "Centre: %.1f Mhz, Span %.1f Mhz, Input %.1f MHz, %d sweeps, ENR %.2f dB" % (freq / 1e6, options.span / 1e6, options.input / 1e6, options.sweeps, enr) | 166 print "Centre: %.1f Mhz, Span %.1f Mhz, Input %.1f MHz, BW %.1f kHz, %d sweeps, ENR %.2f dB" % (freq / 1e6, options.span / 1e6, options.input / 1e6, options.bw / 1e3, options.sweeps, enr) |
166 while True: | 167 while True: |
167 off, on, nf = donoisetest(r, enr) | 168 off, on, nf = donoisetest(r, enr) |
168 print "Off %.3f dBm/Hz, on %.3f dBm/Hz, NF %.2f dB" % (off, on, nf) | 169 print "Off %.3f dBm/Hz, on %.3f dBm/Hz, NF %.2f dB" % (off, on, nf) |
169 print "Press enter to perform a new measurement" | 170 print "Press enter to perform a new measurement" |
170 sys.stdin.readline() | 171 sys.stdin.readline() |