annotate rs_fsp7_noisetest.py @ 55:ad5942d22f78

Use BaseException rather than strings. Add ask method. Wrap tag to a byte.
author Daniel O'Connor <doconnor@gsoft.com.au>
date Tue, 08 Dec 2020 13:59:05 +1030
parents 42621291eb9b
children 91b476ebc0f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #!/usr/bin/env python
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 # Copyright (c) 2012
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 #
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 # Redistribution and use in source and binary forms, with or without
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 # modification, are permitted provided that the following conditions
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 # are met:
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 # notice, this list of conditions and the following disclaimer.
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 # documentation and/or other materials provided with the distribution.
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 #
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 # SUCH DAMAGE.
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 #
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 import math
47
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
29 import numpy
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
30 import optparse
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 import rsib
47
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
32 import scipy
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 import scpi
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 import sys
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35
47
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
36 def findenr(frq):
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
37 # ENR values from the noise source
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
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])
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
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])
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
40
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
41 # Convert back to linear values
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
42 enr = 10 ** (enrdb / 10)
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
43
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
44 # Interpolate
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
45 rtn = scipy.interp([frq], enrfrq, enr)
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
46
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
47 # Convert to dB
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
48 rtndb = 10 * math.log10(rtn)
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
49
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
50 return rtndb
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
51
51
03b06d71f0fd Allow bandwith to be set (maintains a 10:1 ratio of vid:res BW)
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 50
diff changeset
52 def setup(r, freq, span, sweeps, bw):
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 # Reset to defaults
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 r.write("*RST")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 # Set to single sweep mode
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 r.write("INIT:CONT OFF")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 # Enable display updates
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 r.write("SYST:DISP:UPD ON")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 # Set frequency range
47
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
63 r.write("SENSE1:FREQ:CENT %f Hz" % (freq))
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
64 r.write("SENSE1:FREQ:SPAN %f Hz" % (span))
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 # Switch marker 1 on in screen A
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 r.write("CALC:MARK1 ON")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 # Enable noise measurement
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 r.write("CALC:MARK1:FUNC:NOIS ON")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71
49
22187590594b Turn averaging on otherwise we throw away all but the last sweep.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 48
diff changeset
72 # Turn averaging on
22187590594b Turn averaging on otherwise we throw away all but the last sweep.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 48
diff changeset
73 r.write("AVER:STAT ON")
22187590594b Turn averaging on otherwise we throw away all but the last sweep.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 48
diff changeset
74
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 # Set number of sweeps
47
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
76 r.write("SWE:COUN %d" % (sweeps))
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 # Set resolution bandwidth
51
03b06d71f0fd Allow bandwith to be set (maintains a 10:1 ratio of vid:res BW)
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 50
diff changeset
79 r.write("SENS1:BAND:RES %f Hz" % (bw))
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 # Set video bandwidth (10x res BW)
51
03b06d71f0fd Allow bandwith to be set (maintains a 10:1 ratio of vid:res BW)
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 50
diff changeset
82 r.write("SENS1:BAND:VID %f Hz" % (bw * 10))
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 def getnoise(r):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 # Trigger the sweep
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 r.write("INIT;*WAI")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 # Wait for it to be done
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 r.write("*OPC?")
51
03b06d71f0fd Allow bandwith to be set (maintains a 10:1 ratio of vid:res BW)
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 50
diff changeset
90 opc = scpi.getdata(r.read(None), int)
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 #print "OPC - %d" % (opc)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 assert(opc == 1)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 # Set data format
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 r.write("FORM:DATA ASC")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 # Read noise value
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 r.write("CALC:MARK1:FUNC:NOIS:RES?")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 data = r.read(10)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 #print "Data - " + data
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 return float(data)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 def setnoise(r, en):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 if en:
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 val = "ON"
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 else:
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 val = "OFF"
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 r.write("DIAG:SERV:NSO " + val)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 def calcnf(enrdb, offdb, ondb):
48
386e1cb04799 Fix comment
Daniel O'Connor <darius@dons.net.au>
parents: 47
diff changeset
112 # Not possible but noisy results may result in it happening
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 if ondb <= offdb:
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 return 0
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 ydb = ondb - offdb
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 y = 10 ** (ydb / 10)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 enr = 10 ** (enrdb / 10)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 nf = 10 * math.log10(enr / (y - 1))
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 return nf
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 def donoisetest(r, enr):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 print "Acquiring with noise off.."
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 setnoise(r, False)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 off = getnoise(r)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 print "Acquiring with noise on.."
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 setnoise(r, True)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 on = getnoise(r)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 return off, on, calcnf(enr, off, on)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 if __name__ == '__main__':
54
42621291eb9b Improve usage message.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 53
diff changeset
131 parser = optparse.OptionParser(usage = '%prog [options] address frequency',
42621291eb9b Improve usage message.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 53
diff changeset
132 description = 'Configures a Rhode Schwartz FSP7 spectrum analyser to do a noise figure test',
42621291eb9b Improve usage message.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 53
diff changeset
133 epilog = 'video bandwidth is set to 10 times the resolution bandwidth')
42621291eb9b Improve usage message.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 53
diff changeset
134 parser.add_option('-s', '--span', dest = 'span', default = 1e6, help = 'Span frequency in Hz (default: %default)', type = float)
42621291eb9b Improve usage message.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 53
diff changeset
135 parser.add_option('-i', '--input', dest = 'input', default = None, help = 'Frequency used to compute ENR (defaults to frequency)', type = float)
42621291eb9b Improve usage message.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 53
diff changeset
136 parser.add_option('-w', '--sweeps', dest = 'sweeps', default = 20, help = 'Number of sweeps (default: %default)', type = int)
42621291eb9b Improve usage message.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 53
diff changeset
137 parser.add_option('-b', '--bw', dest = 'bw', default = 1000, help = 'Resolution bandwidth in Hz (default: %default)', type = float)
42621291eb9b Improve usage message.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 53
diff changeset
138 parser.add_option('-r', '--repeat', dest = 'repeat', help = 'Number of repetitions, if not specified do one and ask to continue', type = int)
47
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
139
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
140 (options, args) = parser.parse_args()
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
141
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
142 if len(args) != 2:
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
143 parser.error('Must supply the specan address and centre frequency')
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
144
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
145 addr = args[0]
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
146 try:
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
147 freq = float(args[1])
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
148 except ValueError:
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
149 parser.error('Unable to parse frequency')
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
150
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
151 if options.input == None:
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
152 options.input = freq
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
153
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
154 # Compute ENR at frequency of interest
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
155 enr = findenr(options.input)
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
156
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
157 # Connect to the analyser
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
158 r = rsib.RSIBDevice(addr)
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160 # ID instrument
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 r.write('*IDN?')
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162 print "ID is " + r.read(5)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163
47
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
164 # Setup parameters
51
03b06d71f0fd Allow bandwith to be set (maintains a 10:1 ratio of vid:res BW)
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 50
diff changeset
165 setup(r, freq, options.span, options.sweeps, options.bw)
47
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
166
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167 r.write("INIT:CONT OFF")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168
53
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
169 nfs = []
51
03b06d71f0fd Allow bandwith to be set (maintains a 10:1 ratio of vid:res BW)
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 50
diff changeset
170 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)
52
c1891d9074c1 Add option to run for N iterations and exit.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 51
diff changeset
171 while options.repeat == None or options.repeat > 0:
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
172 off, on, nf = donoisetest(r, enr)
50
d143ef509fb7 - Print configuration details before starting
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 49
diff changeset
173 print "Off %.3f dBm/Hz, on %.3f dBm/Hz, NF %.2f dB" % (off, on, nf)
53
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
174 nfs.append(nf)
52
c1891d9074c1 Add option to run for N iterations and exit.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 51
diff changeset
175 if options.repeat == None:
c1891d9074c1 Add option to run for N iterations and exit.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 51
diff changeset
176 print "Press enter to perform a new measurement"
c1891d9074c1 Add option to run for N iterations and exit.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 51
diff changeset
177 sys.stdin.readline()
c1891d9074c1 Add option to run for N iterations and exit.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 51
diff changeset
178 else:
c1891d9074c1 Add option to run for N iterations and exit.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 51
diff changeset
179 options.repeat -= 1
53
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
180
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
181 if len(nfs) > 1:
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
182 nfs = numpy.array(nfs)
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
183 print "NF min: %.1f dBm/Hz, max: %.1f dBm/Hz, avg: %.1f dBm/hz, stddev: %.1f" % (
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
184 nfs.min(), nfs.max(), nfs.sum() / len(nfs), numpy.std(nfs))