soapy_power
===========

Obtain power spectrum from SoapySDR devices (RTL-SDR, Airspy, SDRplay, HackRF, bladeRF, USRP, LimeSDR, etc.)

Requirements
------------

- `Python 3 <https://www.python.org>`_
- `SimpleSoapy <https://github.com/xmikos/simplesoapy>`_
- Optional: `pyFFTW <https://github.com/pyFFTW/pyFFTW>`_ (for faster FFT calculations with FFTW library)

Usage
-----
::

    usage: soapy_power [-h] [-f Hz|Hz:Hz] [-O FILE] [-F {rtl_power,rtl_power_fftw,soapy_power_bin}] [-q] [--debug] [--detect]
                       [--version] [-b BINS | -B Hz] [-n REPEATS | -t SECONDS | -T SECONDS] [-c | -u RUNS | -e SECONDS]
                       [-d DEVICE] [-C CHANNEL] [-A ANTENNA] [-r Hz] [-w Hz] [-p PPM] [-g 1/10th of dB | -a] [--force-rate]
                       [--force-bandwidth] [--tune-delay SECONDS] [-o PERCENT | -k PERCENT] [-s BUFFER_SIZE]
                       [-S MAX_BUFFER_SIZE] [--even | --pow2] [--pyfftw] [--max-threads NUM] [--max-queue-size NUM] [-l] [-R]
                       [-D {no,constant,linear}]
                       [--fft-window {boxcar,hann,hamming,triang,blackman,bartlett,flattop,parzen,bohman,blackmanharris,nuttall,barthann}]
                       [--fft-overlap PERCENT]
    
    Obtain a power spectrum from SoapySDR devices
    
    Main options:
      -h, --help            show this help message and exit
      -f Hz|Hz:Hz, --freq Hz|Hz:Hz
                            center frequency or frequency range to scan, number can be followed by a k, M or G multiplier
                            (default: 1420405752)
      -O FILE, --output FILE
                            output to file (default is stdout)
      -F {rtl_power,rtl_power_fftw,soapy_power_bin}, --format {rtl_power,rtl_power_fftw,soapy_power_bin}
                            output format (default: rtl_power)
      -q, --quiet           limit verbosity
      --debug               detailed debugging messages
      --detect              detect connected SoapySDR devices and exit
      --version             show program's version number and exit
    
    FFT bins:
      -b BINS, --bins BINS  number of FFT bins (incompatible with -B, default: 512)
      -B Hz, --bin-size Hz  bin size in Hz (incompatible with -b)
    
    Averaging:
      -n REPEATS, --repeats REPEATS
                            number of spectra to average (incompatible with -t and -T, default: 1600)
      -t SECONDS, --time SECONDS
                            integration time (incompatible with -T and -n)
      -T SECONDS, --total-time SECONDS
                            total integration time of all hops (incompatible with -t and -n)
    
    Measurements:
      -c, --continue        repeat the measurement endlessly (incompatible with -u and -e)
      -u RUNS, --runs RUNS  number of measurements (incompatible with -c and -e, default: 1)
      -e SECONDS, --elapsed SECONDS
                            scan session duration (time limit in seconds, incompatible with -c and -u)
    
    Device settings:
      -d DEVICE, --device DEVICE
                            SoapySDR device to use
      -C CHANNEL, --channel CHANNEL
                            SoapySDR RX channel (default: 0)
      -A ANTENNA, --antenna ANTENNA
                            SoapySDR selected antenna
      -r Hz, --rate Hz      sample rate (default: 2000000.0)
      -w Hz, --bandwidth Hz
                            filter bandwidth (default: 0)
      -p PPM, --ppm PPM     frequency correction in ppm
      -g 1/10th of dB, --gain 1/10th of dB
                            gain, expressed in tenths of a decibel, e.g. 207 means 20.7 dB (incompatible with -a, default: 372)
      -a, --agc             enable Automatic Gain Control (incompatible with -g)
      --force-rate          ignore list of sample rates provided by device and allow any value
      --force-bandwidth     ignore list of filter bandwidths provided by device and allow any value
      --tune-delay SECONDS  time to delay measurement after changing frequency
    
    Crop:
      -o PERCENT, --overlap PERCENT
                            percent of overlap when frequency hopping (incompatible with -k)
      -k PERCENT, --crop PERCENT
                            percent of crop when frequency hopping (incompatible with -o)
    
    Performance options:
      -s BUFFER_SIZE, --buffer-size BUFFER_SIZE
                            base buffer size (number of samples, 0 = auto, default: 0)
      -S MAX_BUFFER_SIZE, --max-buffer-size MAX_BUFFER_SIZE
                            maximum buffer size (number of samples, -1 = unlimited, 0 = auto, default: 0)
      --even                use only even numbers of FFT bins
      --pow2                use only powers of 2 as number of FFT bins
      --pyfftw              use pyfftw library instead of scipy.fftpack (should be faster)
      --max-threads NUM     maximum number of FFT threads (0 = auto, default: 0)
      --max-queue-size NUM  maximum size of FFT work queue (-1 = unlimited, 0 = auto, default: 0)
    
    Other options:
      -l, --linear          linear power values instead of logarithmic
      -R, --remove-dc       interpolate central point to cancel DC bias (useful only with boxcar window)
      -D {no,constant,linear}, --detrend {no,constant,linear}
                            remove mean value or linear trend from data (default: no)
      --fft-window {boxcar,hann,hamming,triang,blackman,bartlett,flattop,parzen,bohman,blackmanharris,nuttall,barthann}
                            Welch's method window function (default: hann)
      --fft-overlap PERCENT
                            Welch's method overlap between segments (default: 50)

Example
-------
::

    [user@host ~] soapy_power -r 2.56M -f 88M:98M -B 100k -F rtl_power -t 10
    Found Rafael Micro R820T tuner
    INFO: Using device: RTLSDR
    [INFO] Using format CF32.
    WARNING: Required buffer size (25608192) will be shrinked to max_buffer_size (819200)!
    INFO: repeats: 984616
    INFO: samples: 25600016 (time: 10.00001 s)
    INFO: max_buffer_size (samples): 819200 (repeats: 31507.69, time: 0.32000 s)
    INFO: buffer_size (samples): 819200 (repeats: 31507.69, time: 0.32000 s)
    INFO: buffer_repeats: 32
    INFO: overlap: 0.00000
    INFO: bin_size: 98461.54 Hz
    INFO: bins: 26
    INFO: bins (after crop): 26
    INFO: sample_rate: 2.560 MHz
    INFO: sample_rate (after crop): 2.560 MHz
    INFO: freq_range: 10.000 MHz
    INFO: hopping: YES
    INFO: hop_size: 2.560 MHz
    INFO: hops: 4
    INFO: min_center_freq: 89.280 MHz
    INFO: max_center_freq: 96.960 MHz
    INFO: min_freq (after crop): 88.000 MHz
    INFO: max_freq (after crop): 98.240 MHz
    2017-02-22, 09:59:23, 88000000.0, 90560000.0, 98461.5384615, 819200, -112.592, -112.565, -111.646, -110.356, -109.202, -108.398, -107.95, -107.773, -107.719, -107.668, -107.57, -107.45, -108.163, -112.253, -108.291, -107.653, -107.87, -108.038, -108.1, -108.067, -108.057, -108.184, -108.588, -109.367, -110.495, -111.73
    2017-02-22, 09:59:33, 90560000.0, 93120000.0, 98461.5384615, 819200, -112.605, -112.568, -111.646, -110.356, -109.202, -108.409, -107.955, -107.775, -107.727, -107.681, -107.582, -107.454, -108.169, -112.26, -108.302, -107.661, -107.88, -108.058, -108.124, -108.097, -108.073, -108.205, -108.624, -109.402, -110.523, -111.751
    2017-02-22, 09:59:44, 93120000.0, 95680000.0, 98461.5384615, 819200, -112.612, -112.572, -111.649, -110.372, -109.21, -108.405, -107.946, -107.781, -107.736, -107.682, -107.586, -107.457, -108.169, -112.254, -108.275, -107.6, -107.875, -108.066, -108.13, -108.102, -108.086, -108.22, -108.636, -109.413, -110.529, -111.756
    2017-02-22, 09:59:54, 95680000.0, 98240000.0, 98461.5384615, 819200, -112.62, -112.579, -111.656, -110.373, -109.219, -108.411, -107.969, -107.791, -107.717, -107.501, -107.487, -107.463, -108.182, -112.262, -108.309, -107.629, -107.865, -108.078, -108.14, -108.114, -108.094, -108.233, -108.642, -109.427, -110.543, -111.764
    INFO: Total time: 41.049 s

