Importing a bunch of pages from old websites.
[website_subgeniuskitty.com] / data / development / test_equipment / hp_3586_gpib_spectrum_analyzer.md
CommitLineData
f6e94cb2
AT
1# Overview #
2
3While listening to shortwave, I noticed that huge chunks of the spectrum were being swamped at certain times of day. Since my spectrum analyzers are all analog, I decided to write a quick script to allow use of the HP 3586 selective level meter as a rudimentary spectrum analyzer.
4
5%%BEGIN_GALLERY%%
6hp_3586_gpib_spectrum_analyzer.files/hp3586_specan_squarewave.png|A quick test, 200 Hz square wave.
7hp_3586_gpib_spectrum_analyzer.files/hp3586_specan_publicspectrum.png|Local spectrum, no stations active.
8hp_3586_gpib_spectrum_analyzer.files/hp3586_specan_publicblanket.png|Tail end of noise source. Note that the horizontal axis is both time and frequency due to the length of time required to sweep.
9hp_3586_gpib_spectrum_analyzer.files/hp3586_specan_publicblanket_3d.png|161 hours of listening. Vertical axis is UNIX timestamps. Noise source is immediately visible.
10%%END_GALLERY%%
11
12# Instructions #
13
14To use the script, edit it with a text editor and change the starting frequency ($freq_start), ending frequency($freq_end), step size($freq_increment), and number of sweeps to perform ($scan_rep). All frequencies are in kilohertz. Then, run the script and redirect output to a file. For example,
15
16 ataylor:~$ perl hp3586_specan.pl > output.data.txt
17
18After the sweep is finished you can generate 2D or 3D plots with the following gnuplot scripts. Either change the xrange and yrange to match your data or comment out the lines so gnuplot autoscales each axis.
19
20 # 2D Plot
21 #
22 # General
23 #
24 set term postscript
25 set output "filename.ps"
26 set xrange [9250:10250]
27 set yrange [-115:-60]
28 set xlabel 'Frequency (kHz)'
29 set ylabel 'Amplitude (dBm)'
30 set pointsize 0.4
31 #
32 # Plot everything
33 #
34 plot "filename.dat" using 1:3 notitle with lines
35
36 # 3D Plot
37 #
38 # General
39 #
40 set term postscript enhanced eps
41 set output "filename.pdf"
42 set xrange [9200:10300]
43 set zrange [-110:-75]
44 set xlabel 'Frequency (kHz)'
45 set ylabel 'Time (Unix)'
46 #
47 # Plot everything
48 #
49 set view map
50 set palette defined (-110 "blue", -105 "white", -95 "red")
51 splot "filename.dat" using 1:2:3 notitle with points palette pt 5 ps 0.6
52
53# Source Code #
54
55The source code below contains two sleep() statements. You can reduce them in order to perform a faster sweep, but reducing them too far will cause odd behavior when the 3586 is not yet ready to supply a reading at the new frequency. As an example, it took just over two hours for a sweep from 9.25-10.25 MHz in 1 kHz steps with a 3.1 kHz RBW and sample averaging, as shown in the sample data file on this page.
56
57 # Quick script to use HP 3586C SLM
58 # as a rudimentary spectrum analyzer.
59
60 use Device::SerialPort;
61
62 # Set up the serial port
63 # 19200, 81N on the USB ftdi driver
64 my $port = Device::SerialPort->new("/dev/ttyUSB0");
65 $port->databits(8);
66 $port->baudrate(19200);
67 $port->parity("none");
68 $port->stopbits(1);
69
70 # Initialize Prologix USB-GPIB Controller
71 $port->write("++mode 1\n");
72 $port->write("++auto 1\n");
73 $port->write("++addr 16\n");
74
75 # Initialize HP 3586C
76 $port->write("Remote\n");
77 $port->write("B3\n"); # Set BW Filter
78 $port->write("T1\n"); # Terminate in 50 ohms
79 $port->write("A1\n"); # Average: On
80
81 # Frequency Sweep Definition
82 $freq_start = 9250;
83 $freq_end = 10250;
84 $freq_increment = 1;
85 $freq_index = $freq_start;
86 while ($freq_index <= $freq_end) {
87 push (@frequency, $freq_index);
88 $freq_index = $freq_index + $freq_increment;
89 }
90
91 $scan_rep = 70;
92 $scan_index = 1;
93 print "#(kHz) (UNIXtime) (dBm)\n";
94 print "Freq Time Amplitude\n";
95 while ($scan_index <= $scan_rep) {
96 print "# Starting Repetition: $scan_index\n";
97 # Gather and print the measurements
98 # If you want to sweep faster, adjust the two sleep() statements.
99 # Check manual for minimum settling times for your configuration of
100 # BW filter, averaging, etc.
101 foreach $freq (@frequency) {
102 $port->write("FR,$freq,KZ\n");
103 sleep(6);
104 $port->write("TR\n");
105 sleep(2);
106 my $char = $port->lookfor();
107 $char =~ s/N//g;
108 $char =~ s/\r//g; # To match the newlines from the HP 3586C
109 chomp $char;
110 $time = time;
111 print "$freq $time $char \n";
112 }
113
114 $scan_index = $scan_index + 1;
115 }
116
117# Files #
118
119* [Perl source code](hp_3586_gpib_spectrum_analyzer.files/hp3586_specan.pl)
120* [Sample data - 31m Band - 50 Sweeps - Weekend - 9250-10250 kHz Span - 3100 Hz RBW](hp_3586_gpib_spectrum_analyzer.files/31m_Band_-_50_Sweeps_-_Weekend_-_9250-10250_kHz_Span_-_3100_Hz_RBW.dat)
121* [2D gnuplot source code](hp_3586_gpib_spectrum_analyzer.files/hp3586_specan_gnuplot_2d.plt)
122* [3D gnuplot source code](hp_3586_gpib_spectrum_analyzer.files/hp3586_specan_gnuplot_3d.plt)