Documentation chapters

How-to

Python

Python receives the four channels through the SoapySDR driver and the SoapySDR Python bindings. The samples arrive as NumPy arrays.

Requirements

ItemValue
HostLinux, set up as in Host setup
DriverSoapyVortarian, built and installed: SoapySDR driver
Packagespython3-soapysdr, python3-numpy; python3-matplotlib for plots, python3-scipy for filters
sudo apt install python3-soapysdr python3-numpy python3-matplotlib

Check that Python loads the driver (the board is not contacted):

python3 -c "import SoapySDR; print([dict(d) for d in SoapySDR.Device.enumerate('driver=vortarian')])"

Capture example

One contiguous block of all four channels, then the strongest spectral line of each channel in dBFS:

import numpy as np
import SoapySDR
from SoapySDR import SOAPY_SDR_RX, SOAPY_SDR_CF32, SOAPY_SDR_OVERFLOW

N = 2**20                                    # samples per channel, 8.4 ms
dev = SoapySDR.Device("driver=vortarian,host=192.168.67.2")
dev.setFrequency(SOAPY_SDR_RX, 0, 375e6)     # NCO of ADC 1: RX A, RX B
dev.setFrequency(SOAPY_SDR_RX, 2, 375e6)     # NCO of ADC 2: RX C, RX D
dev.setGain(SOAPY_SDR_RX, 0, 20)             # RF gain 0 or 20 dB, all channels

rx = dev.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32, [0, 1, 2, 3])
x = np.zeros((4, N), np.complex64)           # rows: RX A to RX D, 1.0 = full scale
dev.activateStream(rx)                       # the board starts streaming
try:
    got = 0
    while got < N:
        r = dev.readStream(rx, [ch[got:] for ch in x], N - got, timeoutUs=1000000)
        if r.ret > 0:
            if got == 0:
                t0 = r.timeNs                # board time of the first sample [ns]
            got += r.ret
        elif r.ret == SOAPY_SDR_OVERFLOW:    # datagrams lost: start the block again
            got = 0
        else:
            raise RuntimeError(f"readStream returned {r.ret}")
finally:
    dev.deactivateStream(rx)                 # the board stops streaming
    dev.closeStream(rx)

w = np.hanning(N)
P = 20 * np.log10(np.abs(np.fft.fftshift(np.fft.fft(x * w), axes=1)) / w.sum() + 1e-12)
f = 375 + np.fft.fftshift(np.fft.fftfreq(N, 1 / 125e6)) / 1e6      # [MHz]
for name, p in zip("ABCD", P):
    k = p.argmax()
    print(f"RX {name}: {p[k]:6.1f} dBFS at {f[k]:.3f} MHz, median {np.median(p):6.1f} dBFS")
print(f"board time of the first sample: {t0 / 1e9:.6f} s")
  • activateStream sends debug on, deactivateStream sends debug off; the finally block stops the stream also after an error.
  • When the board has not been initialized since power-up, the driver runs init when the device is opened.
  • Row k of x is the same sampling instant in all four channels.

Example scripts

Scripts in host-tools/python:

ScriptFunction
vortarian_spectrogram.pySpectrogram of one contiguous capture of all four channels, saved as PNG.
vortarian_waterfall.pyLive spectra and waterfalls of four channels.
vortarian_detail.pyDetail of a few hundred microseconds: zoomed spectrogram, level, instantaneous frequency.
vortarian_ble_packet.pyOne Bluetooth Low Energy advertising packet: level, I and Q, frequency with the decoded bits.
vortarian_tone_check.pyFrequency, level and noise floor of the strongest tone of each channel, phase between the channels.
vortarian_pcap_check.pyHeader fields, lost datagrams and timestamps of a tcpdump capture; needs no driver.

Spectrogram

python3 vortarian_spectrogram.py --args driver=vortarian,host=192.168.67.2 --nco 375e6 --rf 2450e6
Spectrograms of RX A to RX D around 2450 MHz over 16.8 ms, drawn by the Python script: three Bluetooth Low Energy advertising packets, Wi-Fi frames and periodic bursts on RX A and RX B

vortarian_spectrogram.py with the 4R2C-2G5 front-end (2450 MHz at IF 375 MHz), RF gain 20 dB, antennas on RX A and RX B, none on RX C and RX D. 2050 spectra of 1024 samples, each line the mean power of 4 spectra (32.8 µs). One Bluetooth Low Energy advertising event: packets on 2402, 2426 and 2480 MHz at about 8.2, 8.8 and 9.4 ms. Wi-Fi frames between 2400 and 2445 MHz, periodic bursts from 2450 MHz upwards. Same window, scaling and axes as the GNU Octave and MATLAB spectrogram scripts.

OptionDefaultMeaning
--ms20capture length in ms; the capture is held in memory, 4 bytes per sample and channel
--nconot setNCO frequency of both ADCs in Hz; IF axis
--rfnot setRF frequency at the NCO frequency in Hz; adds the RF axis
--fft1024FFT length, Hann window
--channels0 1 2 3channels to capture
--lim−105 −40colour scale in dBFS; a full-scale tone reads 0 dBFS
--rows600maximum number of lines; a longer capture is reduced by combining spectra
--holdmeanmean or max of the spectra combined into one line; max keeps short bursts
--outvortarian_spectrogram.pngoutput file

Detail of a signal

vortarian_detail.py cuts a few hundred microseconds out of a capture and draws them three ways. --save keeps the capture, --load reads it again, so one capture can be examined at several places and resolutions.

python3 vortarian_detail.py --args driver=vortarian,host=192.168.67.2 --save cap.npy
python3 vortarian_detail.py --load cap.npy --channel 1 --at 0.55 --us 700 --fft 256
Zoomed spectrogram, level and instantaneous frequency of 700 µs on RX B: two pulses of a carrier at 2450.5 MHz whose frequency runs upwards when it switches off, and the end of a Wi-Fi frame

700 µs of RX B. A carrier at 2450.5 MHz is switched on about every 510 µs for about 100 µs at −46 dBFS; at switch-on its frequency settles from 5 MHz above within about 3 µs, at switch-off it runs up by 27 MHz in about 30 µs while the level falls by 10 dB. A weaker source at 2466 MHz shows the same pattern. The Wi-Fi frame at 2437 MHz ends at about 277 µs: the level drops from −59 to −63 dBFS. In the 16.8 ms spectrogram above, the same pulses are the row of dashes at 2450 MHz.

PanelComputed asResolution
SpectrogramFFT of --fft samples, Hann window, 7/8 overlap256 samples: 2.05 µs and 488 kHz per bin; 1024 samples: 8.19 µs and 122 kHz
Level|x|² averaged over 64 samples, in dBFS0.5 µs; whole 125 MHz band
Instantaneous frequencyphase step between consecutive samples × fs / 2π, averaged over 16 samples0.13 µs; valid while one signal dominates, drawn above --threshold
OptionDefaultMeaning
--save, --loadnot setwrite or read the capture: .npy, 4 × N complex64, 1.0 = full scale
--channel00 to 3 = RX A to RX D
--threshold−55level in dBFS that starts the detail
--atnot setstart of the detail in ms, instead of the threshold
--us700length of the detail in µs
--fft256FFT length of the zoomed spectrogram

Signal in the time domain

A narrow-band signal is taken out of the capture by mixing it to 0 Hz, filtering and decimating. With x from the capture example (NCO 375 MHz at RF 2450 MHz), the Bluetooth Low Energy advertising channel on 2402 MHz of RX A:

from scipy import signal                     # python3-scipy

fs, D = 125e6, 5
y = x[0] * np.exp(-2j * np.pi * (2402e6 - 2450e6) / fs * np.arange(N))   # 2402 MHz to 0 Hz
y = signal.lfilter(signal.firwin(129, 1e6, fs=fs), 1, y)[::D]            # 2 MHz wide, 25 MS/s
level = 20 * np.log10(np.abs(y) + 1e-9)                                  # envelope [dBFS]
f = np.angle(y[1:] * np.conj(y[:-1])) * (fs / D) / (2 * np.pi)           # instantaneous frequency [Hz]
Envelope, I and Q, and instantaneous frequency of a Bluetooth Low Energy advertising packet received on RX A, with the decoded preamble and access address bits

vortarian_ble_packet.py: one advertising packet from a capture, antenna on RX A, RF gain 20 dB. Top: envelope, −29.4 dBFS, about 55 dB above the noise in the 2 MHz channel; the transmitter is on for about 400 µs, about 20 µs of carrier and then the 376 µs packet. Middle: I and Q of the first 44 µs. Bottom: instantaneous frequency, GFSK at 1 Mbit/s with about ±230 kHz deviation; the 8 preamble bits and the 32 bits of the advertising access address 0x8E89BED6 can be read directly. The bit labels were added for the figure.

Calls

CallFunction
SoapySDR.Device("driver=vortarian,host=...")Opens the board. Arguments: SoapySDR driver.
setFrequency(SOAPY_SDR_RX, ch, f)NCO frequency, 250e6 to 500e6. Channels 0 and 1 share one NCO, channels 2 and 3 the other.
setGain(SOAPY_SDR_RX, 0, g)RF gain, 0 or 20 dB, common to all channels.
setupStream(SOAPY_SDR_RX, fmt, [0, 1, 2, 3])SOAPY_SDR_CF32: complex float, 1.0 = full scale. SOAPY_SDR_CS16: int16 pairs, native.
readStream(stream, buffers, n, timeoutUs=...)Fills up to n samples per channel. Returns the count in ret and the board time of the first sample in timeNs.
getHardwareTime()Board time at the end of the newest datagram received, in ns.

Return values of readStream

retMeaningAction
> 0number of samples written to every buffercontinue
SOAPY_SDR_OVERFLOWdatagrams were lost, or the board reported a full FIFOthe block is not contiguous: start it again
SOAPY_SDR_TIMEOUTno datagrams within the timeoutcheck the links and Host setup

Memory and speed

QuantityValue
CF32, four channels4 GB per second
CS16, four channels2 GB per second
Reading at the full ratesustained with 12.5 and 25 million samples per readStream call

Allocate the buffers once and read into slices of them, as in the example. Converting or copying per call costs more time than the reception.