annotate rs_fsp7_noisetest.py @ 84:4b4ae555067b default tip

Use RMS detector and fix the sweep time for more accuracy. Add links to app notes discussing theory. Run forever without pause and print a summary on ctrl-c
author Daniel O'Connor <doconnor@gsoft.com.au>
date Thu, 03 Oct 2024 08:57:10 +0930
parents 23c96322cfb6
children
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
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
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
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 import scpi
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 import sys
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
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 # 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
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 # 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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
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 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
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 # 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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 def getnoise(r):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 return float(data)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 def setnoise(r, en):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 def calcnf(enrdb, offdb, ondb):
48
386e1cb04799 Fix comment
Daniel O'Connor <darius@dons.net.au>
parents: 47
diff changeset
126 # 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
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 ydb = ondb - offdb
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 y = 10 ** (ydb / 10)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131 enr = 10 ** (enrdb / 10)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 nf = 10 * math.log10(enr / (y - 1))
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 setnoise(r, False)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 setnoise(r, True)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
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)
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
159 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
160 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
161
84
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
162 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
163
84
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
164 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
165 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
166
84
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
167 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
168 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
169
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 # 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
171 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
172
fa728cf34f50 - Calculate ENR (based on table on the back of our noise source)
Daniel O'Connor <darius@dons.net.au>
parents: 46
diff changeset
173 # 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
174 r = rsib.RSIBDevice(args.address)
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
175
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
176 # 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
177 print('Device ID is ' + r.ask('*IDN?').decode('ascii'))
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
178
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
179 # 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
180 setup(r, args.centre, args.span, args.sweeps, args.bw, args.atten, args.time)
46
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
181
53
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
182 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
183 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
184 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
185 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
186 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
187 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
188 try:
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
189 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
190 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
191 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
192 else:
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 else:
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
201 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
202 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
203 print('')
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
204 break
53
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
205
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
206 if len(nfs) > 1:
d90acb55ce31 Log some stats after multiple runs.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 52
diff changeset
207 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
208
4b4ae555067b Use RMS detector and fix the sweep time for more accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
209 # 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
210 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
211 len(nfs), nfs.min(), nfs.max(), nfs.mean(), numpy.std(nfs)))