annotate rs_fsp7_noisetest.py @ 46:a6e5c97b4767

Add noise test
author Daniel O'Connor <darius@dons.net.au>
date Thu, 20 Dec 2012 11:48:19 +1030
parents
children fa728cf34f50
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
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 import rsib
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 import scpi
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 import sys
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 def setup(r):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 # Reset to defaults
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 r.write("*RST")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 # Set to single sweep mode
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 r.write("INIT:CONT OFF")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 # Enable display updates
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 r.write("SYST:DISP:UPD ON")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 # Set frequency range
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 r.write("FREQ:CEN 10.7MHz;SPAN 1MHz")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 # Switch marker 1 on in screen A
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 r.write("CALC:MARK1 ON")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 # Enable noise measurement
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 r.write("CALC:MARK1:FUNC:NOIS ON")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 # Set number of sweeps
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 r.write("SWE:COUN 20")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 # Set resolution bandwidth
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 r.write("SENS1:BAND:RES 10kHz")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 # Set video bandwidth (10x res BW)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 r.write("SENS1:BAND:VID 100kHz")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 def getnoise(r):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 # Trigger the sweep
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 r.write("INIT;*WAI")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 # Wait for it to be done
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 r.write("*OPC?")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 opc = scpi.getdata(r.read(60), int)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 #print "OPC - %d" % (opc)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 assert(opc == 1)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 # Set data format
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 r.write("FORM:DATA ASC")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 # Read noise value
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 r.write("CALC:MARK1:FUNC:NOIS:RES?")
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 data = r.read(10)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 #print "Data - " + data
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 return float(data)
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 def setnoise(r, en):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 if en:
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 val = "ON"
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 else:
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 val = "OFF"
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 r.write("DIAG:SERV:NSO " + val)
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 def calcnf(enrdb, offdb, ondb):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 # Not possible but weak results may give it
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 if ondb <= offdb:
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 return 0
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 ydb = ondb - offdb
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 y = 10 ** (ydb / 10)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 enr = 10 ** (enrdb / 10)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 nf = 10 * math.log10(enr / (y - 1))
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 return nf
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 def donoisetest(r, enr):
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 print "Acquiring with noise off.."
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 setnoise(r, False)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101 off = getnoise(r)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 print "Acquiring with noise on.."
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 setnoise(r, True)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 on = getnoise(r)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 return off, on, calcnf(enr, off, on)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 if __name__ == '__main__':
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 enr = 15.55 # From back of noise source
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 r = rsib.RSIBDevice('analyzer')
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 # ID instrument
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 r.write('*IDN?')
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 print "ID is " + r.read(5)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 #setup(r)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 r.write("INIT:CONT OFF")
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 while True:
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 off, on, nf = donoisetest(r, enr)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 print "Off %.3f dB, on %.3f dB, NF %.2f" % (off, on, nf)
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 print "Press enter to perform a new measurement"
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 sys.stdin.readline()
a6e5c97b4767 Add noise test
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123