Overview
Some time ago it was discovered by Antti Palosaari, Eric Fry, and Osmocom that DVB-T TV Tuner dongles using the RTL2832U chipset have a special mode which allows direct access to the I/Q data stream, meaning that a cheap, $20.00 DVB-T tuner can be used as a wideband software defined radio receiver. Please note that this is only a receiver. There is absolutely no transmission capability whatsoever.
There are many software defined radios on the market, from Airspy ($199.00), SDRPlay ($149.00), all the way up professional grade devices from National Instruments, such as the USRP series, which starts around $1000.00 and go all the way up to $9000.00 for a high end device with an FPGA embedded for signal analysis. Most of these SDRs can transmit in addition reception.
The table below shows a comparison between an NI USRP 2954R and an RTL-SDR. Here the limitations of the RTL-SDR become apparent, which is why the RTL-SDR stands in absolutely no competition whatsoever with these devices.
|
USRP-2954R |
RTL-SDR |
|
|
Frequency Range |
10 MHz to 6 GHz |
50 MHz to 1800 MHz (model specific) |
|
Bandwith |
160 MHz (max) |
2 MHz (max) |
|
ADC Bit Depth |
16-bit |
8-bit |
|
2x2 MIMO |
Yes |
No |
|
Transmit |
Yes |
No |
|
Bus |
PCIe x4 |
USB 2.0 |
|
FPGA DSP |
Yes |
No |
Given all these limitations, it is still possible to use the RTL-SDR for many educational projects. After all, the engineer must constantly educate himself to stay current and cannot rely that the knowledge gained in a post-secondary institution will suffice for his entire career.
For more information on projects and software already available, please visit http://www.rtl-sdr.com
Additionally, please note that there is a similar project called SDRLab by András Retzler. Mr. Retzler also uses an RTL-SDR and Labview, but relies on an additional program called rtl_tcp which acquires the signal and transmits the raw IQ data over a tcp connection.
Description
In order to get RTL-SDR to work with Labview, it was necessary to write a wrapper around the rtlsdr.dll, which was written by Steve Markgraf and Dimitri Stolnikov, who, fortunately for us, have made this library available under the GPL. This means we not only have access to the binary .dll release, but also to the documented header file, which gives us all the information we need to call the functions contained therein.
Fortunately, all the heavy lifting of writing the wrapper, packaging it into a vipm package, and documenting its functions has already been done by the author of this paper.
Steps to Implement or Execute Code
Preparing to work with Labview and RTL-SDR
In order to begin working with RTL-SDR under Labview, a little bit of preparation is needed. First, an RTL-SDR must be purchased. These devices are readily available on various sizes, including amazon.com and ebay. Searching for “rtl-sdr” will yield many results.
When a RTL-SDR device is available, it must be connected via USB to the computer. Windows will then proceed to install the drivers. The drivers installed by the operating system itself are for the DVB-T function. New drivers must be installed which are supported by the libusb interface that the rtlsdr.dll uses to interface with the hardware. To do this, download a tool called Zadig, available at http://zadig.akeo.ie/ . Once downloaded you can select the RTL-SDR device and install the WinUSB drivers.
Once the WinUSB drivers have been installed, the computer and the operating system are ready. What you can do at this point to verify that the device is working as it should is to download sdrsharp. It is a C# based SDR software which allows using the RTL-SDR as well. It is available from www.airspy.com in the downloads section under core tools. It is part of the SDR Software Package download.
Using RTL-SDR with Labview
In order to get RTL-SDR to work with Labview, it was necessary to write a wrapper around the rtlsdr.dll, which was written by Steve Markgraf and Dimitri Stolnikov, who, fortunately for us, have made this library available under the GPL. This means we not only have access to the binary .dll release, but also to the documented header file, which gives us all the information we need to call the functions contained therein.
Fortunately, all the heavy lifting of writing the wrapper, packaging it into a vipm package, and documenting its functions has already been done by the author of this paper. Consequently, all the user has to do is install the library and use the functions, just like with any other hardware. All the .dll ugliness has already been hidden. Unfortunately, the author does not have acccess to the pro version of the VI Package Manager, so it is not possible to download this package from a repository.
Upon installation of the library, which is conveniently packaged in a vi package manager file, there will be a new palette in the block diagram.
In this palette, all the functions required to work with rtl sdr have been combined for easy access.
The Example VI contains an example which opens a device, retrieves anumber of samples, computes and FFT, then displays the results.
This example shows one real signal. At 85.5 MHz, there is a two tone, FM modulated signal generated by using a signal generator, and a second signal, at 86.4 MHz, which is the third harmonic of the local oscillator. The local oscillator of the RTL-SDR operates at 28.8 MHz. It leaks into the signal and since the board was not designed to limit oscillator leakage, it can be seen at multiples of 28.8 MHz. Fortunately, the higher the tuned frequency, the lower the power level of the oscillator harmonic. Theoretically, we could mask these frequencies in the DSP chain, but it is important to know that they are there.
We can also see another limitation of cheap SDRs. This is called the DC spike, and happens because there is always a small DC offset in the downconverter and will always be in the center, no matter what center frequency the device is tuned to and will always be at the center frequency. There are several software techniques used in other software packages, such as SDR#, to correct this. These applications correct the display only, however, using estimation techniques. The basic problem remains.
An additional reason for the DC spike is that the rtlsdr .dll returns samples as an array of U8. This means that there are no negative values and that the signal amplitude is centered at about 127, which is the midpoint between 0 and 255. To fix this, simply convert to a signed data type (double is good for additional signal processing) and subtract 127.5 from the array. This will remove the offset and recenter the signal around 0.
I'm going out on a limb here and speculate that the ADCs on the rtl-sdr have a positive range, much like the ADCs on an Arduino have a range of 0V to 5V. To acquire an audio or RF signal (which usually bob around 0V) with ADCs like this, a dc bias is applied, centering the signal around VADCmax/2 (in the arduino example, this would be 2.5V). Then it's acquired and processed.
Technical Details
The entire library is based upon calls to a shared library, or dll file on a windows system. In order to use shared libraries from a labview program, it is necessary to use the “Call Library Function” function from the “Libraries and Executables” sub-palette, which is under the “Connectivity” category. A simple example of a call to this library looks like this:

Double clicking on the node brings up the configuration screen.
The function tab defines where the library is, which function to call, and how to perform the function call.
The real work however goes into the parameters tab. Here we defined all the parameters of the function call, and this the connectors on the “call library function” connector pane.
This is only a very simple example for a function which only has a numeric return. The reader will appretiate that this can get quite complex if pointers to arrays and complex data types are used in function calls. Please refer to the attached code for more detailed examples, and also to the Labview Help.
Outlook
This was the first part in a series on RTL-SDR. The second part will focus on using a MyRIO and attaching the RTLSDR directly to it. At this point, the data is gathered by the Labview RT system. Streaming directly into a cRIO/myRIO system means that we no longer have to bother the host with acquisition, and can then use the integrated FPGA as an FFT/DSP coprocessor to Labview RT.
The key learing of that part will be compiling the rtlsdr shared library directly on a myRIO, as there is currently no binary package available. Don’t worry, it sounds uglier than it is.
Sources
http://www.kerrywong.com/2014/11/16/testing-an-rtl-sdr-spectrum-analyzer/
Requirements
Software
Labview 2016
Hardware
RTL-SDR Dongle
Notes
I have tried to make this library bug free and consistent with the style guides publised by National Instruments. Should find any bugs, or have any improvement ideas, please feel free to comment or send me a pn.
Disclaimer
This is a private contribution to the community and is not endorsed by rtl-sdr.com, National Instruments, or any other entity, except me. Additionally, as this is example code, I will give no warranty for anything.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.