Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate rs_fsp7_noisetest.py @ 85:60ad91b4c67c default tip
Add 'quick' option to use a faster sweep time with no averaging.
Useful for testing the hardware is setup correctly without having to wait 3 minutes.
author | Daniel O'Connor <doconnor@gsoft.com.au> |
---|---|
date | Mon, 21 Oct 2024 14:12:50 +1030 |
parents | 4b4ae555067b |
children |
rev | line source |
---|---|
46 | 1 #!/usr/bin/env python |
2 | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
3 # Copyright (c) 2024 |
46 | 4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
5 # | |
6 # Redistribution and use in source and binary forms, with or without | |
7 # modification, are permitted provided that the following conditions | |
8 # are met: | |
9 # 1. Redistributions of source code must retain the above copyright | |
10 # notice, this list of conditions and the following disclaimer. | |
11 # 2. Redistributions in binary form must reproduce the above copyright | |
12 # notice, this list of conditions and the following disclaimer in the | |
13 # documentation and/or other materials provided with the distribution. | |
14 # | |
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 # SUCH DAMAGE. | |
26 # | |
27 | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
28 # This script uses the "Y Factor Method" as discussed here: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
29 # https://scdn.rohde-schwarz.com/ur/pws/dl_downloads/dl_application/application_notes/1ma178/1MA178_5e_NoiseFigure.pdf |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
30 # https://www.analog.com/en/resources/technical-articles/noise-figure-measurement-methods-and-formulas--maxim-integrated.html |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
31 # |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
32 # It requires an ENR and has hard coded values for the source we have. |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
33 |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
34 import argparse |
46 | 35 import math |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
36 import misc |
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
|
37 import numpy |
46 | 38 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
|
39 import scipy |
46 | 40 import scpi |
41 import sys | |
42 | |
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
|
43 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
|
44 # 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
|
45 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
|
46 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
|
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
|
48 # 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
|
49 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
|
50 |
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 # Interpolate |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
52 rtn = numpy.interp([frq], enrfrq, enr) |
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
|
53 |
fa728cf34f50
- Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents:
46
diff
changeset
|
54 # Convert to dB |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
55 rtndb = 10 * math.log10(rtn[0]) |
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
|
56 |
fa728cf34f50
- Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents:
46
diff
changeset
|
57 return rtndb |
77
23c96322cfb6
Spell Rohde Schwarz correctly.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
56
diff
changeset
|
58 |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
59 def setup(r, freq, span, sweeps, bw, atten, time): |
46 | 60 # Reset to defaults |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
61 r.write('*RST') |
46 | 62 |
63 # Set to single sweep mode | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
64 r.write('INIT:CONT OFF') |
46 | 65 |
66 # Enable display updates | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
67 r.write('SYST:DISP:UPD ON') |
46 | 68 |
69 # Set frequency range | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
70 r.write('SENSE1:FREQ:CENT %f Hz' % (freq)) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
71 r.write('SENSE1:FREQ:SPAN %f Hz' % (span)) |
46 | 72 |
73 # Switch marker 1 on in screen A | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
74 r.write('CALC:MARK1 ON') |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
75 |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
76 # Set marker to centre frequency |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
77 r.write('CALC:MARK1:X %f Hz ' % (freq)) |
46 | 78 |
79 # Enable noise measurement | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
80 r.write('CALC:MARK1:FUNC:NOIS ON') |
46 | 81 |
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
|
82 # Turn averaging on |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
83 r.write('AVER:STAT ON') |
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
|
84 |
46 | 85 # Set number of sweeps |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
86 r.write('SWE:COUN %d' % (sweeps)) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
87 |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
88 # Use RMS detector |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
89 r.write('SENS:DET RMS') |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
90 |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
91 # Set sweep time |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
92 r.write('SWE:TIME %f' % (time)) |
46 | 93 |
94 # Set resolution bandwidth | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
95 r.write('SENS1:BAND:RES %f Hz' % (bw)) |
46 | 96 |
97 # Set video bandwidth (10x res BW) | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
98 r.write('SENS1:BAND:VID %f Hz' % (bw * 10)) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
99 |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
100 r.write('INP:ATT %s' % atten) |
77
23c96322cfb6
Spell Rohde Schwarz correctly.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
56
diff
changeset
|
101 |
46 | 102 def getnoise(r): |
103 # Trigger the sweep | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
104 r.write('INIT;*WAI') |
46 | 105 |
106 # Wait for it to be done | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
107 r.ask('*OPC?') |
77
23c96322cfb6
Spell Rohde Schwarz correctly.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
56
diff
changeset
|
108 |
46 | 109 # Set data format |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
110 r.write('FORM:DATA ASC') |
46 | 111 |
112 # Read noise value | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
113 data = r.ask('CALC:MARK1:FUNC:NOIS:RES?') |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
114 #print 'Data - ' + data |
46 | 115 |
116 return float(data) | |
117 | |
118 def setnoise(r, en): | |
119 if en: | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
120 val = 'ON' |
46 | 121 else: |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
122 val = 'OFF' |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
123 r.write('DIAG:SERV:NSO ' + val) |
46 | 124 |
125 def calcnf(enrdb, offdb, ondb): | |
48 | 126 # Not possible but noisy results may result in it happening |
46 | 127 if ondb <= offdb: |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
128 return None |
46 | 129 ydb = ondb - offdb |
130 y = 10 ** (ydb / 10) | |
131 enr = 10 ** (enrdb / 10) | |
132 nf = 10 * math.log10(enr / (y - 1)) | |
133 return nf | |
77
23c96322cfb6
Spell Rohde Schwarz correctly.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
56
diff
changeset
|
134 |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
135 def donoisetest(r, enr, sweeps): |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
136 swt = float(r.ask('SWE:TIME?')) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
137 print('Acquiring with noise off.. (%.1f x %d = %.1f sec)' % (swt, sweeps, swt * sweeps)) |
46 | 138 setnoise(r, False) |
139 off = getnoise(r) | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
140 print('Acquiring with noise on.. (%.1f x %d = %.1f sec)' % (swt, sweeps, swt * sweeps)) |
46 | 141 setnoise(r, True) |
142 on = getnoise(r) | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
143 nf = calcnf(enr, off, on) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
144 #print(nf) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
145 return off, on, nf |
46 | 146 |
147 if __name__ == '__main__': | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
148 parser = argparse.ArgumentParser(description = 'Configures a Rohde Schwarz FSP7 spectrum analyser to do a noise figure test', |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
149 epilog = 'Note: video bandwidth is set to 10 times the resolution bandwidth') |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
150 parser.add_argument('-a', '--atten', default = 10, help = 'Input attenuation in dB (default: %(default).0f dB)', type = float) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
151 parser.add_argument('-b', '--bw', default = 1000, help = 'Resolution bandwidth in Hz (default: %(default).1f Hz)', type = float) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
152 parser.add_argument('-i', '--input', default = None, help = 'Frequency used to compute ENR (defaults to frequency)', type = float) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
153 parser.add_argument('-p', '--pause', default = False, action = 'store_true', |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
154 help = 'Wait between measurements (when not doing N repeats, default: %(default)s)') |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
155 parser.add_argument('-r', '--repeat', help = 'Number of repetitions, if not specified do one and ask to continue', type = int) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
156 parser.add_argument('-s', '--span', default = 1e6, help = 'Span frequency in Hz (default: %(default).0f Hz)', type = float) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
157 parser.add_argument('-t', '--time', default = 30, help = 'Sweep time (default: %(default)f sec)', type = float) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
158 parser.add_argument('-w', '--sweeps', default = 3, help = 'Number of sweeps to average (default: %(default)d)', type = int) |
85
60ad91b4c67c
Add 'quick' option to use a faster sweep time with no averaging.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
84
diff
changeset
|
159 parser.add_argument('-q', '--quick', action = 'store_true', help = 'Use presets for a quick test to check hardware is setup correctly') |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
160 parser.add_argument('address', help = 'Spectrum analyser address', type = str) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
161 parser.add_argument('centre', help = 'Centre frequency (Hz)', type = float) |
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
|
162 |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
163 args = parser.parse_args() |
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 |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
165 if args.input == None: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
166 args.input = args.centre |
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
|
167 |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
168 if args.time is not None and args.time <= 0: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
169 parser.error('Sweep time must be >0') |
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
|
170 |
85
60ad91b4c67c
Add 'quick' option to use a faster sweep time with no averaging.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
84
diff
changeset
|
171 if args.quick: |
60ad91b4c67c
Add 'quick' option to use a faster sweep time with no averaging.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
84
diff
changeset
|
172 args.time = 5 |
60ad91b4c67c
Add 'quick' option to use a faster sweep time with no averaging.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
84
diff
changeset
|
173 args.sweeps = 1 |
60ad91b4c67c
Add 'quick' option to use a faster sweep time with no averaging.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
84
diff
changeset
|
174 |
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
|
175 # Compute ENR at frequency of interest |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
176 enr = findenr(args.input) |
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
|
177 |
fa728cf34f50
- Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents:
46
diff
changeset
|
178 # Connect to the analyser |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
179 r = rsib.RSIBDevice(args.address) |
46 | 180 |
181 # ID instrument | |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
182 print('Device ID is ' + r.ask('*IDN?').decode('ascii')) |
46 | 183 |
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
|
184 # Setup parameters |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
185 setup(r, args.centre, args.span, args.sweeps, args.bw, args.atten, args.time) |
46 | 186 |
53
d90acb55ce31
Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
52
diff
changeset
|
187 nfs = [] |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
188 print('Centre: %s, Span %s, Input %s, RBW %s, Sweeps: %d, Sweep time: %.1f sec, ENR %.2f dB' % ( |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
189 misc.sifmt(args.centre), misc.sifmt(args.span), |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
190 misc.sifmt(args.input), misc.sifmt(args.bw), |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
191 args.sweeps, args.time, enr)) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
192 while args.repeat == None or args.repeat > 0: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
193 try: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
194 off, on, nf = donoisetest(r, enr, args.sweeps) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
195 if nf is None or nf < 0: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
196 nfstr = 'Invalid' |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
197 else: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
198 nfstr = '%.2f dB' % (nf) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
199 nfs.append(nf) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
200 print('Off %.3f dBm/Hz, on %.3f dBm/Hz, NF %s' % (off, on, nfstr)) |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
201 if args.repeat == None: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
202 if args.pause: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
203 print('Press enter to perform a new measurement') |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
204 sys.stdin.readline() |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
205 else: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
206 args.repeat -= 1 |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
207 except KeyboardInterrupt: |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
208 print('') |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
209 break |
53
d90acb55ce31
Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
52
diff
changeset
|
210 |
d90acb55ce31
Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
52
diff
changeset
|
211 if len(nfs) > 1: |
d90acb55ce31
Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
52
diff
changeset
|
212 nfs = numpy.array(nfs) |
84
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
213 |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
214 # XXX: not sure mean/std of dBm/Hz values is really meaningful |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
215 print('N: %d, NF min: %.1f dBm/Hz, max: %.1f dBm/Hz, avg: %.1f dBm/Hz, stddev: %.1f' % ( |
4b4ae555067b
Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
77
diff
changeset
|
216 len(nfs), nfs.min(), nfs.max(), nfs.mean(), numpy.std(nfs))) |