annotate fsp7_phasenoise.py @ 83:4cc3d0706dd1

Add suffixes down to atto
author Daniel O'Connor <doconnor@gsoft.com.au>
date Thu, 03 Oct 2024 08:56:07 +0930
parents 6ce8ed5ba76d
children
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
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
30 import misc
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
31 import numpy
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
32 import os
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
33 import PIL
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
34 import rsib
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
35 import scipy
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
36 import scpi
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
37 import sys
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
38 import time
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
39
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
40 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
41 '''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
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 if rbw is not None:
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
51 # Need to use FFT filters below 10Hz BW
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
52 if rbw < 10:
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
53 r.write('BAND:TYPE FFT')
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
54 else:
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
55 r.write('BAND:TYPE NORM')
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
56 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
57 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
58 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
59
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
60 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
61 '''Helper function to trigger a sweep and wait for it to finish'''
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
62 tout = getsweeptime(r) * 5 * sweeps
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
63 if tout < 1:
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
64 tout = 1
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
65 #print('Sweep time', swt)
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 # Trigger the sweep
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
68 r.write('INIT;*WAI')
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 # 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
71 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
72 assert(opc == 1)
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
73
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
74 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
75 '''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
76 peaks_f = []
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
77 peaks_pwr = []
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
78 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
79 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
80 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
81 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
82 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
83 break
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
84 if i > 0:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
85 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
86 break
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
87 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
88 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
89 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
90
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
91 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
92
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
93 def getsweeptime(r):
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
94 '''Return sweep time in seconds'''
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
95 # According to the manual SWE:TIME works for both normal and FFT filters
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
96 # however in practise it doesn't get a response for FFT ones so we fake it
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
97
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
98 if r.ask('BAND:TYPE?').decode('ascii') == 'FFT':
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
99 return 5
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
100 else:
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
101 return float(r.ask('SWE:TIME?'))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
102
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
103 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
104 '''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
105 cpwrlim = -30
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
106 measurements = (
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
107 { 'offset' : 10, 'span' : 100, 'rbw' : 1, 'vbw' : 3 },
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
108 { 'offset' : 100, 'span' : 250, 'rbw' : 1, 'vbw' : 3 },
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
109 { 'offset' : 1e3, 'span' : 2.5e3, 'rbw' : 1, 'vbw' : 3 },
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
110 { '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
111 { '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
112 { '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
113 )
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
114 # Reset to defaults
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
115 r.write('*RST')
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
116 r.write('*CLS')
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
117
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
118 # Set to single sweep mode
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
119 r.write('INIT:CONT OFF')
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
120
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
121 # Enable display updates
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
122 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
123
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
124 # Set attenuation
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
125 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
126 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
127 else:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
128 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
129
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
130 # Set Y scale
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
131 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
132 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
133
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
134 # Set reference level
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
135 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
136 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
137 else:
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
138 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
139
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
140 #
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
141 # Look from 100kHz down to 100Hz to narrow down the exact frequency
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
142 #
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
143 found = False
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
144 cmeas = nominal
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
145 for idx, span in enumerate((100e3, 10e3, 1e3, 100)):
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
146 setupsweep(r, span / 50, span / 50 * 3, centre = cmeas, span = span)
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
147 print('Looking for signal at %s+/-%s (%.1f seconds)' % (
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
148 misc.sifmt(nominal), misc.sifmt(span, dp = 1),
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
149 getsweeptime(r)))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
150 # Do the sweep
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
151 dosweep(r, 1)
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
152
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
153 # Check the instrument is happy
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
154 status = int(r.ask('STAT:QUES:COND?'))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
155 pwrstat = int(r.ask('STAT:QUES:POW:COND?'))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
156 if status != 0 or pwrstat != 0:
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
157 # Dump a screenshot for debugging
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
158 screenshot(r, '%s-sweep-inst-warnings.png' % (ssprefix))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
159 raise Exception('Instrument warning, status %s power status %s' %
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
160 (bin(status), bin(pwrstat)))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
161 # Find the peak
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
162 r.write('CALC:MARK1 ON')
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
163 r.write('CALC:MARK1:MAX')
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
164 cpwr = float(r.ask('CALC:MARK1:Y?'))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
165 if cpwr < cpwrlim:
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
166 # Dump a screenshot for debugging
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
167 screenshot(r, '%s-sweep-no-power.png' % (ssprefix))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
168 raise Exception('Power too low / not found: %.1f dBm vs %.1f dBm' % (cpwr, cpwrlim))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
169 else:
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
170 found = True
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
171 cmeas = float(r.ask('CALC:MARK1:X?'))
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
172 print('Found signal at %s with power %.1f dBm' % (misc.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
173
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
174 if not found:
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
175 print('Unable to find signal')
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
176 # Centre peak
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
177 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
178
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
179 # Set number of sweeps
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
180 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
181
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
182 # 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
183 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
184 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
185
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
186 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
187 # Setup measurement
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
188 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
189 # Do the sweep
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
190 dosweep(r, sweeps)
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
191
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
192 # 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
193 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
194 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
195 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
196 meas = float(r.ask('CALC:DELT:FUNC:PNO:RES?'))
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
197 print('Offset %7s %7.2f dBc/Hz' % (misc.sifmt(m['offset'], dp = 0), meas))
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
198
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
199 # 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
200 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
201 screenshot(r, '%s-%d_%s_offset.png' % (
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
202 ssprefix, idx, misc.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
203
82
6ce8ed5ba76d Disable phasenoise measurement before doing wide sweeps.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 81
diff changeset
204 # Turn off markers (disables phasenoise mode)
6ce8ed5ba76d Disable phasenoise measurement before doing wide sweeps.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 81
diff changeset
205 r.write('CALC:MARK:AOFF')
6ce8ed5ba76d Disable phasenoise measurement before doing wide sweeps.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 81
diff changeset
206
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
207 # 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
208 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
209 start = 1e6
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
210 stop = 100e6
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
211 setupsweep(r, 1e3, 3e3, start = start, stop = stop)
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
212 print('Scanning %s - %s (%.1f seconds)' % (misc.sifmt(start, dp = 0), misc.sifmt(stop, dp = 0),
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
213 getsweeptime(r)))
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
214 dosweep(r, sweeps)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
215 # Show peaks
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
216 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
217 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
218 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
219 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
220 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
221
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
222 # 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
223 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
224 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
225 setupsweep(r, 1e3, 3e3, start = start, stop = stop)
81
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
226 print('Scanning %s - %s (%.1f seconds)' % (misc.sifmt(start, dp = 0), misc.sifmt(stop, dp = 0),
1947d10f9395 - Search for signal frequency iteratively to improve accuracy.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 77
diff changeset
227 getsweeptime(r)))
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
228 dosweep(r, sweeps)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
229 # Show peaks
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
230 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
231 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
232 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
233 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
234 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
235
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
236 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
237 # 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
238 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
239 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
240 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
241 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
242 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
243 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
244 time.sleep(5)
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
245
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
246 # Grab it
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
247 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
248 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
249 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
250
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
251 # 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
252 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
253 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
254 img.save(ssname)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
255 os.unlink(bmpname)
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
256 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
257
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
258 if __name__ == '__main__':
77
23c96322cfb6 Spell Rohde Schwarz correctly.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 76
diff changeset
259 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
260 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
261 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
262 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
263 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
264 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
265 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
266 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
267
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
268 args = parser.parse_args()
74
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
269
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
270 # 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
271 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
272
b6ebe05f250f Add some commentry about what it works with
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
273 # ID instrument
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
274 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
275
76
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
276 # Do measurements
e2bb136bd2ed Add script to use FSP7 to perform phasenoise measurements.
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 74
diff changeset
277 phasenoise(r, args.nominal, args.sweeps, args.atten, args.rlevel, args.yscale, args.ssprefix)