How does GQRX interface to devices (e.g. rtl_sdr)?

258 views
Skip to first unread message

Luca Attanasio

unread,
May 14, 2021, 10:18:05 AM5/14/21
to Gqrx SDR
Hi everyone,
I was wondering how GQRX interfaces to rtl_sdr devices as I do not find any mention in the github repo to the rtl-sdr library (https://github.com/osmocom/rtl-sdr). I though GQRX uses rtl_power to capture data but I could not find any mention to it. I would like to reproduce the same capture I am doing in gqrx with rtl_power or rtl_power_fftw. This is because, my rtl_power or rtl_power_fftw captures much slower than gqrx and I would like to understand where I am setting the wrong parameters,
thanks.

Adrian Musceac

unread,
May 14, 2021, 11:29:48 AM5/14/21
to gq...@googlegroups.com
Gqrx uses gr-osmosdr which wraps librtlsdr (and other libraries including SoapySDR device libraries) as an abstraction layer.
Gr-osmosdr is designed as a GNU radio source/sink provider and is stream oriented.

Adrian

Luca Attanasio

unread,
May 14, 2021, 12:29:03 PM5/14/21
to Gqrx SDR
Thanks a lot. So to have a capture behaviour similar to GQRX from command line is it possible to use`rtl_power`? I saw that the integration time (-i integration_interval) cannot be less than 1s and it seems like GQRX has a much lower value for that (am I right?). The range I have to capture is relatively short (1MHz). I also tried `rtl_power_fftw` but it behaves similarly.
By the way, since I only use rtl_sdr I see it pointless to use `rx_power` from `rx_tools` based on SoapySDR.

Luca Attanasio

unread,
May 14, 2021, 1:26:32 PM5/14/21
to Gqrx SDR
Specifically I am saying that, GQRX has a high FFT size 32768 and a low Time span (0.07s) and plots data very fast.
With similar arguments on rtl_power_fftw, the Time span is much slower:
`rtl_power_fftw -f 120M:130M -b 32768 -c > spectrum.dat`

Adrian Musceac

unread,
May 15, 2021, 8:42:12 AM5/15/21
to gq...@googlegroups.com
On Friday, May 14, 2021 7:29:03 PM EEST Luca Attanasio wrote:
> Thanks a lot. So to have a capture behaviour similar to GQRX from command
> line is it possible to use`rtl_power`? I saw that the integration time (-i
> integration_interval) cannot be less than 1s and it seems like GQRX has a
> much lower value for that (am I right?). The range I have to capture is
> relatively short (1MHz). I also tried `rtl_power_fftw` but it behaves
> similarly.
> By the way, since I only use rtl_sdr I see it pointless to use `rx_power`
> from `rx_tools` based on SoapySDR.

I'm not familiar with the rtl programs, you might have to read the source code
if it's not obvious from the documentation.

I think the Gqrx FFT block has changed recently so Clayton might correct me if
I'm wrong, but in GNU radio the way it works is like this: upstream blocks
pass a buffer of samples which usually has an automatic size which might be
different to the FFT buffer size. There is an internal accumulator which has the
same size as the FFT size (power of 2 value set by the user from the
interface). For example 32768. Once there are enough samples in this
accumulator, the FFT is computed and the points which represent power are
passed to the GUI for rendering.

There is a tradeoff between FFT resolution (number of points) and the time
required to get the FFT values for a given sample rate, because the samples
arrive at a particular rate (the sample rate). If the sample rate is the same
as the FFT size, it will take one second to get the samples needed to perform
the FFT, plus the computation time overhead. Generally, to increase FFT
resolution and keep the same time for FFT computation, you need to also
increase the sample rate and it will take more computing power.
I think that nowadays Gqrx has a setting called FFT overlap which allows the
GUI display to run faster than the FFT computation rate, by displaying the
same FFT values on a subsequent frame, when the new FFT data is not yet ready.
A little fuzzy on details here since I haven't looked at Gqrx source code in a
while.

Best regards,
Adrian


Luca Attanasio

unread,
May 19, 2021, 11:59:14 AM5/19/21
to Gqrx SDR
Thank you very much for your very informative answer. Probably if I explain my problem a little better you can help me. Could you suggest a way to reproduce the gqrx waterfall from python given the raw file recorded from gqrx?
I thought about working in these steps but it has not worked for me:
  1. calculate the absolute value from iq samples in the file
  2. reshape into (n,32768) where n*32768 is the size of the original array
  3. use imshow to plot the data as a waterfall
What am I doing wrong?
Thanks again.

Robin Gape

unread,
May 19, 2021, 1:35:18 PM5/19/21
to gq...@googlegroups.com

Luca,

1) your process doesn't mention where the FFT would be calculated. It is the output from an FFT (complex values) whose I & Q values are processed (taking the magnitude of the vector) to absolute values to provide a power spectrum.

2) you might have an easier time using GNU Radio Companion (GRC) (see https://en.wikipedia.org/wiki/GNU_Radio#GNU_Radio_Companion) which is a GUI front end to GNU Radio. GNU Radio, as Adrian indicated, is the underlying technology of GQRX. GRC offers power spectrum displays as processing blocks.

HTH, 73, Stay Safe,

Robin, G8DQX

Adrian Musceac

unread,
May 20, 2021, 2:59:10 AM5/20/21
to gq...@googlegroups.com
Your raw I/Q samples come in time/amplitude domain. You need the Fourier transform like Robin said to transition to frequency/power domain. GNU Radio uses the FFTW library for this transform.
The waterfall is different. It works in frequency/time/power domain and thus you need a second, "rolling" accumulator (which is just an image in Gqrx).
Most of these operations are normally done in C++ for performance reasons.
The suggestion to use gnuradio-companion for this is really good, I would take it.

Adrian

Roger David Powers

unread,
May 21, 2021, 12:20:20 PM5/21/21
to gq...@googlegroups.com
Sorry, no gqrx content in the below, but still thought I should share since I went down a similar path recently.

The basics of going from IQ samples to Power Spectrum Display (PSD) are covered in Chapter 3 of http://pysdr.org .


It uses Python as the programming language which IMHO is a good choice for students.

I highly recommend this site for anyone trying to learn more about SDR.

The PSD is in essence one line of the waterfall display. 

IIRC the site does have an assignment to do a waterfall.

There is an example on the author's web site: https://github.com/pysdr/pysdr/blob/master/pluto_waterfall.py

He is using the ADI 'Pluto' radio and its run time library.

If you want to dive in deeper, here are a few related projects I have used successfully with the well known rtl-sdr radio:

https://github.com/xmikos/simplesoapy -- a simple Python API that uses SoapySDR to drive lots of different kinds of SDRs

https://github.com/xmikos/soapy_power -- command line tool similar to rx_tools etc that uses simplesoapy to capture samples

https://github.com/xmikos/qspectrumanalyzer -- spectrum analyzer with waterfall based on all of the above

I read through a lot of the code in these three projects and it IMO shows there is a LOT of complexity in making this kind of application, but you learn a lot when figuring out how it is done.  

Regards,
RDP


Reply all
Reply to author
Forward
0 new messages