annotate fsp7_phasenoise.py @ 80:b280fe3b696a

Ignore macOS droppings and data directory
author Daniel O'Connor <doconnor@gsoft.com.au>
date Fri, 27 Sep 2024 16:55:01 +0930
parents 23c96322cfb6
children 1947d10f9395
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
3 # Copyright (c) 2024
74
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
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
31 import os
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
32 import PIL
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
33 import rsib
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
34 import scipy
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
35 import scpi
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
36 import sys
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
37 import time
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
38
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
39 def sifmt(_v, dp = 3, unit = 'Hz', sp = ' '):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
40 '''Format a number using SI prefixes'''
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
41 si_prefixes = ('T', 'G', 'M', 'k', '', 'm', 'ยต', 'n', 'p')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
42 scale = 10 ** 12
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
43 v = abs(_v)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
44 if v == 0:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
45 sip = ""
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
46 scale = 0
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
47 for i, sip in enumerate(si_prefixes):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
48 if v >= scale:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
49 break
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
50 scale /= 1e3
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
51 return ('%.' + str(dp) + 'f%s%s%s') % (_v / scale, sp, si_prefixes[i], unit)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
52
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
53 def setupsweep(r, rbw, vbw, centre = None, span = None, start = None, stop = None):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
54 '''Helper function to set various sweep parameters'''
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
55 if centre is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
56 r.write('SENSE1:FREQ:CENT %f Hz' % (centre))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
57 if span is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
58 r.write('SENSE1:FREQ:SPAN %f Hz' % (span))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
59 if start is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
60 r.write('SENSE1:FREQ:START %f Hz' % (start))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
61 if stop is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
62 r.write('SENSE1:FREQ:STOP %f Hz' % (stop))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
63 if rbw is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
64 r.write('SENS1:BAND:RES %f Hz' % (rbw))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
65 if vbw is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
66 r.write('SENS1:BAND:VID %f Hz' % (vbw))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
67
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
68 def dosweep(r, sweeps):
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
69 '''Helper function to trigger a sweep and wait for it to finish'''
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
70 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
71 tout = swt * 5 * sweeps
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
72 if tout < 1:
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
73 tout = 1
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
74 #print('Sweep time', swt)
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 # Trigger the sweep
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
77 r.write('INIT;*WAI')
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 # 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
80 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
81 assert(opc == 1)
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
82
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
83 def findpeaks(r, maxpeak = 5, minpwr = None):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
84 '''Ask instrument to find maxpeaks peaks and return a list of frequencies and powers'''
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
85 peaks_f = []
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
86 peaks_pwr = []
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
87 r.write('CALC:MARK1:MAX')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
88 for i in range(maxpeak):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
89 frq = float(r.ask('CALC:MARK1:X?'))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
90 pwr = float(r.ask('CALC:MARK1:Y?'))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
91 if minpwr is not None and pwr < minpwr:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
92 break
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
93 if i > 0:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
94 if frq == peaks_f[i - 1]:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
95 break
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
96 peaks_f.append(frq)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
97 peaks_pwr.append(pwr)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
98 r.write('CALC:MARK1:MAX:NEXT')
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
99
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
100 return peaks_f, peaks_pwr
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
101
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
102 def phasenoise(r, nominal, sweeps, atten, rlev, yscale, ssprefix):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
103 '''Main function to find a signal, do some phase noise measurements and wideband sweeps'''
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
104 cpwrlim = -30
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
105 measurements = (
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
106 { 'offset' : 10, 'span' : 100, 'rbw' : 10, 'vbw' : 10 },
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
107 { 'offset' : 100, 'span' : 250, 'rbw' : 10, 'vbw' : 10 },
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
108 { 'offset' : 1e3, 'span' : 2.5e3, 'rbw' : 10, 'vbw' : 30 },
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
109 { 'offset' : 10e3, 'span' : 25e3, 'rbw' : 100, 'vbw' : 300 },
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
110 { 'offset' : 100e3, 'span' : 250e3, 'rbw' : 100, 'vbw' : 300 },
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
111 { 'offset' : 1e6, 'span' : 2.1e6, 'rbw' : 1e3, 'vbw' : 3e3 },
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
112 )
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
113 # Reset to defaults
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
114 r.write('*RST')
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
115
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
116 # Set to single sweep mode
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
117 r.write('INIT:CONT OFF')
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 # Enable display updates
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
120 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
121
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
122 # Set attenuation
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
123 if atten is None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
124 r.write('INP:ATT AUTO')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
125 else:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
126 r.write('INP:ATT %s' % atten)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
127
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
128 # Set Y scale
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
129 if yscale is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
130 r.write('DISP:TRAC:Y %s dB' % (yscale))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
131
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
132 # Set reference level
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
133 if rlev is None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
134 r.write('DISP:WIND:TRAC:Y:RLEV AUTO')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
135 else:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
136 r.write('DISP:WIND:TRAC:Y:RLEV %f' % (rlev))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
137
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
138 #
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
139 # Look for signal
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
140 #
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
141 # Set frequency range etc
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
142 setupsweep(r, 10, 30, centre = nominal, span = 1e3)
74
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 # 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
145 r.write('CALC:MARK1 ON')
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
146 print('Looking for signal (%.1f seconds)' % (float(r.ask('SWE:TIME?'))))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
147
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
148 # Do the sweep
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
149 dosweep(r, 1)
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
150
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
151 # Check the instrument is happy
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
152 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
153 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
154 if status != 0 or pwrstat != 0:
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
155 print('Instrument warning, status %s power status %s' %
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
156 (bin(status), bin(pwrstat)))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
157 # Find the peak
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
158 r.write('CALC:MARK1:MAX')
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
159 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
160 if cpwr < cpwrlim:
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
161 Exception('Power too low / not found: %.1f dBm vs %.1f dBm' % (cpwr, cpwrlim))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
162 cmeas = float(r.ask('CALC:MARK1:X?'))
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
163 print('Found signal at %s with power %.1f dBm' % (sifmt(cmeas, dp = 6), cpwr))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
164
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
165 # Centre peak
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
166 r.write('CALC:MARK1:FUNC:CENT')
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
167
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
168 # Set number of sweeps
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
169 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
170
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
171 # Enable phase noise measurement
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
172 r.write('CALC:MARK:AOFF')
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
173 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
174
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
175 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
176 # Setup measurement
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
177 setupsweep(r, m['rbw'], m['vbw'], span = m['span'])
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
178
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
179 # Do the sweep
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
180 dosweep(r, sweeps)
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
181
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
182 # Set offset of phase noise measurement
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
183 r.write('CALC:MARK1:MAX')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
184 r.write('CALC:DELT1:MOD REL')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
185 r.write('CALC:DELT1:X %f Hz' % (m['offset']))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
186 meas = float(r.ask('CALC:DELT:FUNC:PNO:RES?'))
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
187 print('Offset %7s %7.2f dBc/Hz' % (sifmt(m['offset'], dp = 0), meas))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
188
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
189 # Take screen shot and save it
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
190 if ssprefix is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
191 screenshot(r, '%s-%d_%s_offset.png' % (
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
192 ssprefix, idx, sifmt(m['offset'], dp = 0, sp = '')))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
193
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
194 # Do a wide band scan
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
195 if ssprefix is not None:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
196 start = 1e6
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
197 stop = 100e6
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
198 setupsweep(r, 1e3, 3e3, start = start, stop = stop)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
199 print('Scanning %s - %s (%.1f seconds)' % (sifmt(start, dp = 0), sifmt(stop, dp = 0),
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
200 float(r.ask('SWE:TIME?'))))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
201 dosweep(r, sweeps)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
202 # Show peaks
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
203 r.write('CALC:MARK:AOFF')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
204 for i, (f, p) in enumerate(zip(*findpeaks(r, 4))):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
205 r.write('CALC:MARK%d:X %f Hz' % (i + 1, f))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
206 screenshot(r, '%s-sweep-%.1f-%.1fMHz.png' % (
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
207 ssprefix, start / 1e6, stop / 1e6))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
208
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
209 # Look from just before signal to just after second harmonic
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
210 start = nominal * 0.9
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
211 stop = 2 * nominal + nominal * 0.1
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
212 setupsweep(r, 1e3, 3e3, start = start, stop = stop)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
213 print('Scanning %s - %s (%.1f seconds)' % (sifmt(start, dp = 0), sifmt(stop, dp = 0),
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
214 float(r.ask('SWE:TIME?'))))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
215 dosweep(r, sweeps)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
216 # Show peaks
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
217 r.write('CALC:MARK:AOFF')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
218 for i, (f, p) in enumerate(zip(*findpeaks(r, 4))):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
219 r.write('CALC:MARK%d:X %f Hz' % (i + 1, f))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
220 screenshot(r, '%s-sweep-%.1f-%.1fMHz.png' % (
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
221 ssprefix, start / 1e6, stop / 1e6))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
222
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
223 def screenshot(r, ssname, sapath = '\'c:\\temp\\pntmp.bmp\''):
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
224 # Setup & take screen shot
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
225 r.write('HCOPY:DEV:LANG1 BMP')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
226 r.write('HCOPY:DEST1 MMEM')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
227 r.write('HCOPY:CMAP:DEF2')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
228 r.write('HCOPY:ITEM:ALL')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
229 r.write('MMEM:NAME %s' % (sapath,))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
230 r.write('HCOPY:IMM1')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
231 time.sleep(5)
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
232
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
233 # Grab it
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
234 r.write('MMEM:DATA? %s' % (sapath,))
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
235 bmpdat = scpi.getbin(r.read())
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
236 bmpname = ssname[0:-4] + '.bmp'
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
237
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
238 # Convert to whatever format
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
239 open(bmpname, 'wb').write(bmpdat)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
240 img = PIL.Image.open(bmpname)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
241 img.save(ssname)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
242 os.unlink(bmpname)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
243 r.write('MMEM:DEL %s' % (sapath,))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
244
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
245 if __name__ == '__main__':
77
23c96322cfb6 Spell Rohde Schwarz correctly.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 76
diff changeset
246 parser = argparse.ArgumentParser(description = 'Configures a Rohde Schwarz FSP7 spectrum analyser to do a phase noise measurement')
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
247 parser.add_argument('-a', '--atten', default = None, help = 'Attenuation level (default: autoamatic)')
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
248 parser.add_argument('-r', '--rlevel', default = 10, help = 'Reference level (default: %default dBm)', type = float)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
249 parser.add_argument('-s', '--ssprefix', default = None, help = 'Path name to save screenshots to (default: none)', type = str)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
250 parser.add_argument('-w', '--sweeps', default = 1, help = 'Number of sweeps (default: %default)', type = int)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
251 parser.add_argument('-y', '--yscale', default = 120, help = 'Y-scale extent (default: %default dB)', type = float)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
252 parser.add_argument('address', help = 'Address of analyser', type = str)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
253 parser.add_argument('nominal', help = 'Nominal frequency of measurement (Hz)', type = float)
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
254
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
255 args = parser.parse_args()
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
256
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
257 # Connect to the analyser
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
258 r = rsib.RSIBDevice(args.address)
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
259
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
260 # ID instrument
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
261 print('Device ID is', r.ask('*IDN?').decode('ascii'))
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
262
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
263 # Do measurements
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
264 phasenoise(r, args.nominal, args.sweeps, args.atten, args.rlevel, args.yscale, args.ssprefix)