I'm trying to create software that can process the live IQ stream from an RTL SDR receiver. Problem is, these stream data at a rate of 2.4 MILLION samples per second. That's VERY fast. In fact, it's 50 times the speed of a normal sound card with a SR of 48000 smp/sec. This means every imaginable optimization must be made for processing the signal. Now I'm writing a test program to see if it can process data at a sufficient speed. It reads data from a raw IQ file (previously saved from an RTL SDR) and processes it one block at a time via FFT and IFFT, simply converting it from a complex IQ file to a real valued signal (at twice the sample rate, that is 4.8 Msmp/sec), and then saving that to another file on the harddrive. The input blocks are 4096 complex samples, and the output blocks are 8192 real samples. Each I or Q sample is a 16bit integer, which is then converted to a 64bit "double" floating point value. This conversion is needed, as FFTs depend on floating point number, and can't process integers. The output signal is not converted back to integers, and instead is left as blocks of 64bit "double" floating point values, which are then saved to a file.
Unfortunately, my program takes 23 seconds to process a file which is a 10 second recording from an RTL SDR. This means that if it was processing a live stream, it wouldn't be able to keep up and would drop half of the signal. And that is without ANY additional processing (no SSB or AM or FM demodulation, which requires additional processing steps after conversion to a realvalued signal).
So it seems my program won't work. Though this could just be due to the writing speed of my harddrive (maybe it can't keep up with a writing speed of 307,200,000 bits per second, which is what you get when you multiply the sample rate of 4.8Msmp/sec by 64bits per sample). Maybe if I process it inmemory, and then resample it to a lower sample rate such as 48000 smp/sec like a normal soundcard and then save it, it would work. Or maybe if I convert the sample format back to a 16bit integer (so bit rate would be only 76,800,000 bits per second) my harddrive could keep up.
Or maybe there's some kind of optimized processing that's normally done in SDR software like HDSDR and SDR# (possibly even using some form of integer FFT instead of the normal floating point FFT) in order to make the computer be able to keep up with the high sample rate of the SDR.
Any help here would be great.
I need some advice in creating IQ processing software

 Posts: 47
 Joined: Thu Jan 25, 2018 10:48 pm
Re: I need some advice in creating IQ processing software
2.4 million samples per second is not so much, that's pretty normal flow. 40 million samples per second is much harder to process and it really requires optimization.
Regarding to FFT, just use FFTW library. On my machine with 64 bit double precision it takes about:
 0.8 ms for 4096 points FFT
 7 ms for 250000 points FFT
 32.6 ms for 1048576 points FFT
465 ms for 14000000 points FFT
So, you can process 14 millions complex points FFT with 64 bit double precision at least 2 times per second.
Or 4096 complex points FFT at least 1250 times per second.
You can do 250000 complex points FFT about 142 times per second. It's enough for 100 Hz display to update spectrum every frame.
Regarding to FFT, just use FFTW library. On my machine with 64 bit double precision it takes about:
 0.8 ms for 4096 points FFT
 7 ms for 250000 points FFT
 32.6 ms for 1048576 points FFT
465 ms for 14000000 points FFT
So, you can process 14 millions complex points FFT with 64 bit double precision at least 2 times per second.
Or 4096 complex points FFT at least 1250 times per second.
You can do 250000 complex points FFT about 142 times per second. It's enough for 100 Hz display to update spectrum every frame.
Re: I need some advice in creating IQ processing software
I wrote my own FFT DLL, because FFTW is GPL licensed. This means that if I make a program that uses it, the program itself (not just the FFTW DLL) MUST have its source code published, or at least be made available upon request (or else you are breaking the law by violating the terms of the license).radiolistener wrote: ↑Fri Jul 26, 2019 10:03 pm2.4 million samples per second is not so much, that's pretty normal flow. 40 million samples per second is much harder to process and it really requires optimization.
Regarding to FFT, just use FFTW library. On my machine with 64 bit double precision it takes about:
 0.8 ms for 4096 points FFT
 7 ms for 250000 points FFT
 32.6 ms for 1048576 points FFT
465 ms for 14000000 points FFT
So, you can process 14 millions complex points FFT with 64 bit double precision at least 2 times per second.
Or 4096 complex points FFT at least 1250 times per second.
You can do 250000 complex points FFT about 142 times per second. It's enough for 100 Hz display to update spectrum every frame.
This is a nogo for me, because I'm looking to make a commercial application, and the whole purpose of a commercial application is to sell it, not give away its source code for free. My program MUST be closed source for it to be commercially viable, and this means that NONE of the components that go into the program (even external files such as DLLs) can be GPL licensed. So my FFT had to be written from scratch (there is no other FFT DLL available on the net that doesn't have GPL attached). My FFT may not be the most optimized, but I was able to find some pseudocode on Wikipedia for an inplace FFT calculated via the radix2 TukeyCooley algorithm. By reading the pseudocode I was able to implement this algorithm in my own programming language of choice for DLL creation (Visual C++ is great, as it's got lots of speed optimization features), and then compiled the DLL. The main application I am writing in VB6, because it has a nice dragdrop way for creating the GUI (no need to use Windows API functions for creating windows and buttons and everything in the GUI, before you even start writing the actual program's code, as you'd have to do if you coded the application in VC++).
The FFT is the most CPUheavy part of processing an IQ signal, so once I got that put in a DLL compiled with speed optimizations, writing the main program itself should be pretty easy, and not require so many optimizations.
However, I found out something interesting. It's pretty slow, at least when reading from (and writing to) the harddrive. I'm wondering if this is the major slowdown, is simply the harddrive reading/writing operations? I know harddrives are not nearly as fast as directly reading/writing from memory. Or maybe it's just VB6's builtin file loading and saving functions that are slow. Maybe if I used the Windows API functions for file access, it would be faster.
What do you think?

 Posts: 47
 Joined: Thu Jan 25, 2018 10:48 pm
Re: I need some advice in creating IQ processing software
yes, usual harddrive has some limit at about 50100 megabytes per second. So if you're using complex 64 bit, it will be limited with about 390000780000 samples per second. But SSD harddrive has much more higher speed.
Regarding to FFT, if you're want your own implementation, you're needs to use highly optimized algorithm and use SSE CPU extensions for optimization. Another way is to use GPU acceleration written in CUDA.
Regarding to FFT, if you're want your own implementation, you're needs to use highly optimized algorithm and use SSE CPU extensions for optimization. Another way is to use GPU acceleration written in CUDA.

 Posts: 23
 Joined: Wed Dec 27, 2017 4:36 am
 Location: Colorado
Re: I need some advice in creating IQ processing software
There are many many c fft implementations out there, I'm sure you can find one that's not GPL licensed. Here is one:
https://www.nayuki.io/page/freesmallf ... languages
And many more on github (check the licenses of each):
https://github.com/search?l=C&q=fft&type=Repositories
2.4 MSPS processing is fairly demanding, but certainly possible on modern machines. Make sure any filters or other DSP that operates at this full sample rate are fairly optimized (low number of points in your FIR, or use an IIR instead, etc).
For your test, maybe read the hard drive data into memory first, then push it through your FFT for timing.
https://www.nayuki.io/page/freesmallf ... languages
And many more on github (check the licenses of each):
https://github.com/search?l=C&q=fft&type=Repositories
2.4 MSPS processing is fairly demanding, but certainly possible on modern machines. Make sure any filters or other DSP that operates at this full sample rate are fairly optimized (low number of points in your FIR, or use an IIR instead, etc).
For your test, maybe read the hard drive data into memory first, then push it through your FFT for timing.
Re: I need some advice in creating IQ processing software
A few million IQ samples per second isn't really fast on any modern CPU (including those on mobile devices and Raspberry Pi's) which can perform Billions of floating point operations per second. You may have to use a moderately optimized FFT library, but there are many libraries (other than FFTW) available for Android, iOS, macOS, and Linux (etc.). Some with source code, so you can compile the FFT into your app.
I use Apple's vDSP/Accelerate library in my iPhone rtl_tcp SDR app, and even older iPhones don't even breath hard at 2.4 Msps, FFT filtering, demodulating, and displaying rtl_tcp IQ data streams.
I use Apple's vDSP/Accelerate library in my iPhone rtl_tcp SDR app, and even older iPhones don't even breath hard at 2.4 Msps, FFT filtering, demodulating, and displaying rtl_tcp IQ data streams.