Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate fsp7_phasenoise.py @ 74:b6ebe05f250f
Add some commentry about what it works with
author | Daniel O'Connor <doconnor@gsoft.com.au> |
---|---|
date | Wed, 25 Sep 2024 21:10:01 +0930 |
parents | |
children | e2bb136bd2ed |
rev | line source |
---|---|
74
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
2 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
3 # Copyright (c) 2014 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
5 # |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
6 # Redistribution and use in source and binary forms, with or without |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
7 # modification, are permitted provided that the following conditions |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
8 # are met: |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
9 # 1. Redistributions of source code must retain the above copyright |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
10 # notice, this list of conditions and the following disclaimer. |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
11 # 2. Redistributions in binary form must reproduce the above copyright |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
12 # notice, this list of conditions and the following disclaimer in the |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
13 # documentation and/or other materials provided with the distribution. |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
14 # |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
25 # SUCH DAMAGE. |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
26 # |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
27 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
28 import argparse |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
29 import math |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
30 import numpy |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
31 import rsib |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
32 import scipy |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
33 import scpi |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
34 import sys |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
35 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
36 def setup2(r, centre, span, rbw, vbw): |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
37 r.write('SENSE1:FREQ:CENT %f Hz' % (centre)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
38 r.write('SENSE1:FREQ:SPAN %f Hz' % (span)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
39 r.write('SENS1:BAND:RES %f Hz' % (rbw)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
40 r.write('SENS1:BAND:VID %f Hz' % (vbw)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
41 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
42 def dosweep(r, sweeps): |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
43 swt = float(r.ask('SWE:TIME?')) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
44 tout = swt * 5 * sweeps |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
45 if tout < 1: |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
46 tout = 1 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
47 #print('Sweep time', swt) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
48 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
49 # Trigger the sweep |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
50 r.write('INIT;*WAI') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
51 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
52 # Wait for it to be done |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
53 opc = int(r.ask('*OPC?', timeout = tout)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
54 assert(opc == 1) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
55 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
56 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
57 def setup(r, carrier, sweeps, rbw, vbw, ofs, atten): |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
58 cpwrlim = -30 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
59 measurements = ( |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
60 { 'offset' : 10, 'rbw' : 10, 'vbw' : 10 }, |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
61 { 'offset' : 100, 'rbw' : 10, 'vbw' : 10 }, |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
62 { 'offset' : 1e3, 'rbw' : 300, 'vbw' : 300 }, |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
63 { 'offset' : 10e3, 'rbw' : 300, 'vbw' : 300 }, |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
64 { 'offset' : 100e3, 'rbw' : 300, 'vbw' : 300 }, |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
65 { 'offset' : 1e6, 'rbw' : 1e3, 'vbw' : 3e3 }, |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
66 ) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
67 # Reset to defaults |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
68 r.write('*RST') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
69 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
70 # Set to single sweep mode |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
71 r.write('INIT:CONT OFF') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
72 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
73 # Enable display updates |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
74 r.write('SYST:DISP:UPD ON') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
75 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
76 # Set attenuation |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
77 r.write('INP:ATT %f' % atten) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
78 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
79 # |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
80 # Look for carrier |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
81 # |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
82 print('Measuring carrier') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
83 # Set frequency range etc |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
84 setup2(r, carrier, 1e3, 300, 300) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
85 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
86 # Switch marker 1 on in screen A |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
87 r.write('CALC:MARK1 ON') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
88 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
89 # Do the sweep |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
90 dosweep(r, 1) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
91 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
92 # Check the instrument is happy |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
93 status = int(r.ask('STAT:QUES:COND?')) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
94 pwrstat = int(r.ask('STAT:QUES:POW:COND?')) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
95 if status != 0 or pwrstat != 0: |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
96 raise Exception('Instrument warning, status %s power status %s' % |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
97 (bin(status), bin(pwrstat))) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
98 # Look for the carrier |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
99 r.write('CALC:MARK1:MAX') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
100 cpwr = float(r.ask('CALC:MARK1:Y?')) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
101 if cpwr < cpwrlim: |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
102 raise Exception('Carrier power too low / not found: %.1f dBm vs %.1f dBm' % (cpwr, cpwrlim)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
103 cmeas = float(r.ask('CALC:MARK1:X?')) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
104 print('Found carrier at %.7f MHz with power %.1f dBm' % (cmeas / 1e6, cpwr)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
105 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
106 # Turn averaging on |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
107 r.write('AVER:STAT ON') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
108 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
109 # Set number of sweeps |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
110 r.write('SWE:COUN %d' % (sweeps)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
111 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
112 # Enable phase noise measurement |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
113 r.write('CALC:DELT1:FUNC:PNO') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
114 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
115 for idx, m in enumerate(measurements): |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
116 # Setup measurement |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
117 setup2(r, carrier, m['offset'] * 2.1, m['rbw'], m['vbw']) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
118 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
119 # Do the sweep |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
120 dosweep(r, sweeps) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
121 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
122 # Set offset of phase noise measurement |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
123 r.write('CALC:DELT2:FUNC:FIX:RPO:X %f Hz' % (m['offset'])) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
124 meas = float(r.ask('CALC:DELT:FUNC:PNO:RES?')) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
125 print('Offset %.0fHz %.2f dBc/Hz' % (m['offset'], meas)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
126 return |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
127 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
128 def getphnoise(r): |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
129 # Trigger the sweep |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
130 r.write('INIT;*WAI') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
131 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
132 # Wait for it to be done |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
133 opc = int(r.ask('*OPC?', timeout = 1000)) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
134 #print 'OPC - %d' % (opc) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
135 assert(opc == 1) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
136 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
137 # Set data format |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
138 r.write('FORM:DATA ASC') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
139 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
140 # Read phase noise value |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
141 data = r.ask('CALC:MARK2:FUNC:NOIS:RES?') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
142 #print 'Data - ' + data |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
143 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
144 return float(data) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
145 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
146 if __name__ == '__main__': |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
147 parser = argparse.ArgumentParser(description = 'Configures a Rhode Schwartz FSP7 spectrum analyser to do a phase noise measurement') |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
148 parser.add_option('-s', '--span', dest = 'span', default = 1e6, help = 'Span frequency in Hz (default: %default)', type = float) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
149 parser.add_option('-w', '--sweeps', dest = 'sweeps', default = 20, help = 'Number of sweeps (default: %default)', type = int) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
150 parser.add_option('-r', '--rbw', dest = 'rbw', default = 1000, help = 'Resolution bandwidth in Hz (default: %default)', type = float) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
151 parser.add_option('-v', '--vbw', dest = 'vbw', default = 3000, help = 'Video bandwidth in Hz (default: %default)', type = float) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
152 parser.add_option('address', '--address', dest = 'address', help = 'Address of analyser', type = str) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
153 parser.add_option('centre', '--centre', dest = 'centreq', help = 'Centre frequency of measurement', type = float) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
154 parser.add_option('offset', '--offset', dest = 'offset', help = 'Offset frequency to take measurement at', type = float) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
155 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
156 (options, args) = parser.parse_args() |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
157 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
158 # Connect to the analyser |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
159 r = rsib.RSIBDevice(addr) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
160 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
161 # ID instrument |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
162 print('ID is', r.ask('*IDN?').decode('ascii')) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
163 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
164 # Setup parameters |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
165 setup(r, options.centre, options.span, options.sweeps, options.rbw, options.vbw, options.offset) |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
166 |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
167 while True: |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
168 print('Centre: %.1f Mhz, Span %.1f Mhz, RBW %.1f kHz, %d sweeps, Offset %.1fkHz: %.2f dBc/Hz' % ( |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
169 options.centre / 1e6, options.span / 1e6, options.rbw / 1e3, options.sweeps, |
b6ebe05f250f
Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
170 options.offset / 1e3, getphnoise(r))) |