RTL-SDR Installation Instructions

chirp

EE123: Digital Signal Processing

chirp

Fall, 2012

RTL-SDR: Inexpensive Software Defined Radio

What is software-defined radio?

A software defined radio system is a system in which the components are implemented in software instead of the traditional way of hardware implementation. It consists of an RF front-end followed by and analog- to-digital converter which provides samples to a host computer. The rest of the processing is done solely in software.

Each student in the class will/or already gotten a TVB-T USB dongle based on the Realtek RTL2832U chip. This dongle was originally made to receive and decode the European standard digital television. Last February, a V4L/DVB kernel developer, Antii Palosaari, discovered that there is a device mode in which raw samples can be captured and transferred to a host computer. This feature enables this device to be used as an inexpensive ”Software Defined Radio”.

This is a photo of the dongle:

The E4000 Elonics chip is a digitally controlled tuner. The tuner selects a frequency band around a target center frequency and demodulates it to baseband. In our case, the RTL2832U chip serves as an analog to digital converter that samples the baseband signal and outputs the samples to a host computer through a USB2 port.

The device uses IQ baseband demodulation and sampling. Here are some Notes and Slides.

Driver Installation Instructions

All the installation instructions below were derived from the following links:

  • http://sdr.osmocom.org/trac/wiki/rtl-sdr

  • http://www.rtlsdr.org

Here, we will provide you with binaries and basic installation that will enable you to get tune to a frequency
and get samples into Matlab or GNU Octave. If you are bold, you can go to the aove websites and follow the installation instructions.
There are instructions there to install additional software, such as GNU-radio or SDR

There are three tools you must be able to run:

  • rtl_test: this will test the device and its function.

  • rtl_sdr: enables saving raw samples into a file

  • rtl_tcp: networked interface which we will use to dynamically load data into Matlab, change frequency etc.

MAC OSX:

  • Download and extract the archive rtlsdr_osx.zip

  • You should see the files: rtl_sdr, rtl_tcp, rtl_test, librtlsdr.dylib, librtlsdr.0.dylib,librtlsdr.0.0.0.dylib, libusb-1.0.0.dylib.

  • If they do not exist, in the terminal, create the following directories. (You will need administrator password)

>> sudo mkdir /usr/local/bin
>> sudo mkdir /usr/local/lib
  • In the terminal go to the directory path of the archive you downloaded and copy the files to the right place:

>> sudo cp rtl_sdr rtl_tcp rtl_test /usr/local/bin/
>> sudo cp lib* /usr/local/lib/
  • Connect your USB dongle to your computer and run the rtl_test. You should get the following output:

>> rtl_test -t
rtl_test -t
Found 1 device(s):
  0:  ezcap USB 2.0 DVB-T/DAB/FM dongle

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Elonics E4000 tuner
Supported gain values (18): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0 43.0 45.0 47.0 49.0
Benchmarking E4000 PLL...
[E4K] PLL not locked for 51000000 Hz!
[E4K] PLL not locked for 2227000000 Hz!
[E4K] PLL not locked for 1114000000 Hz!
[E4K] PLL not locked for 1241000000 Hz!
E4K range: 52 to 2226 MHz
E4K L-band gap: 1114 to 1241 MHz

Windows

  • Download and extract the archive rtlsdr_win.zip

  • You should see the file zadig.exe and two directories: x32 and x64. these correpond to 32bit and 64bit rtl_sdr binaries.

  • Plug your RTL device in for the first time, Windows may request a driver or automatically install a driver from Microsoft – this is OK as it will be replaced in the next few steps. Don’t install the software on the CD that comes with the device.

  • Run the Zadig.exe file and you should see the following with an empty list:

  • Click on Options and select “List All Devices”:

  • Choose the one that says “Bulk-In, Interface (Interface 0)”. This should be the primary endpoint of your RTL device:

  • In the box to the right of the green arrow make sure “WinUSB” is chosen – not libusb or libusbk. The big button underneath will say “Replace Driver” or “Reinstall Driver”. Before you proceed make sure the USBID matches the VID/PID.

  • Note that if you insert the dongle into a different USB port you may have to use Zadig again. It seems that you can change which driver is loaded depending on the USB port used. So you could use one USB port for RTLSDR and another port for using the dongle to watch DVB-T with the supplied Windows application.

  • In a command line window, run the test:

>> rtl_test.exe -t
Found 1 device(s):
  0:  ezcap USB 2.0 DVB-T/DAB/FM dongle

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Elonics E4000 tuner
Supported gain values (18): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0 43.0 45.0 47.0 49.0
Benchmarking E4000 PLL...
[E4K] PLL not locked for 51000000 Hz!
[E4K] PLL not locked for 2227000000 Hz!
[E4K] PLL not locked for 1114000000 Hz!
[E4K] PLL not locked for 1241000000 Hz!
E4K range: 52 to 2226 MHz
E4K L-band gap: 1114 to 1241 MHz

Linux

  • Marcus D. Leech has kindly integrated the forementioned build steps into his gnuradio installation script at rtlsdr/build-gnuradio. This is the most user-friendly option so far. It will install the entire gnu-radio suit, which is lots of fun!

  • Otherwise, follow the instructions on http://sdr.osmocom.org/trac/wiki/rtl-sdr to compile and install binaries from source.

  • After installation, in a command line window, run the test:

>> rtl_test -t
Found 1 device(s):
  0:  ezcap USB 2.0 DVB-T/DAB/FM dongle

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Elonics E4000 tuner
Supported gain values (18): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0 43.0 45.0 47.0 49.0
Benchmarking E4000 PLL...
[E4K] PLL not locked for 51000000 Hz!
[E4K] PLL not locked for 2227000000 Hz!
[E4K] PLL not locked for 1114000000 Hz!
[E4K] PLL not locked for 1241000000 Hz!
E4K range: 52 to 2226 MHz
E4K L-band gap: 1114 to 1241 MHz

Getting data into Matlab and GNU Octave

There are a couple of ways to capture data and transfer it into Matlab. The most simple way is using the rtl_sdr executable
to capture data and save it into a file. Then, reading the data from a file into Matlab. The other way is using
rtl_tcp which enables communication with the device over TCP connection. I’ve written several matlab functions that can
be used to interact with the device directly from Matlab. Unfortunately these do not work in GNU octave as they use Matlab built-in java interpreter. I will release GNU octave code soon.

  • Download and extract the archive rtlsdr/rtlsdr_matlab.zip. It contains all the code to work with the device from Matlab.

Using rtl_sdr to capture to a file

Example: to tune to 88.5Mhz and set the sample rate to 2.4Mhz use:

>> rtl_sdr  -s 2400000 -f 88500000  capture.bin

Use crtl-c to break the capture. Warning… the file will grow very quickly!

To load into Matlab/Octave use the provided function loadFile.m in the Matlab commandline

>> y = loadFile('capture.bin');

You will see that the samples are complex!
This is because the device uses IQ baseband demodulation and sampling to represent a single side of the spectrum. Here are some Notes and Slides about Quadrature demodulation and sampling.

Because of the automatic gain, in many cases the first couple of seconds of capture will not be useful. You should therefore discard them.
An alternative is to use manual gain, but you have to be careful not to overrange when the signal is strong. The Supported gain values (18): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0 43.0 45.0 47.0 49.0.

Example: to tune to 88.5Mhz and set the sample rate to 2.4Mhz and maximum gain use:

>> rtl_sdr -s 2400000 -f 88500000 -g 49.0  capture.bin

Using rtl_tcp to capture and control the device directly from Matlab

rtl_tcp comes with command line options which can be used to start the capture with specific frequency and rate. This is useful to save time
but it is also possible to start rtl_tcp without and options, in which case it will start with default parameters. From Matlab it is possible to
change these.

Example: to start a tcp erver with default parameters of tuning to 88.5Mhz and sample rate of 2.4Mhz

>> rtl_tcp -s 2400000 -f 88500000
Found 1 device(s).
Found Elonics E4000 tuner
Using ezcap USB 2.0 DVB-T/DAB/FM dongle
Tuned to 88500000 Hz.
listening...
Use the device argument 'rtl_tcp=127.0.0.1:1234' in OsmoSDR (gr-osmosdr) source
to receive samples in GRC and control rtl_tcp parameters (frequency, gain, ...).

To capture samples, in the Matlab command window run:

>> soc = rtl_sdr_connect;  % open local tcp socket to rtl_tcp
>> dummy = rtl_sdr_getData(soc,2.4e6); % get 1 second worth of samples, and throw away
>> y = rtl_sdr_getData(soc,2.4e6); % get 1 second worth of samples
>> soc.close;  % close socket

Immediately after invoking rtl_sdr_connect, the device will capture data and buffer it. To flush the buffer, you can either use
rtl_sdr_reset, or to read data till the buffer is flushed.

To change frequency to 162.4Mhz and rate to 1Mhz and then capture data in Matlab use:

>> soc = rtl_sdr_connect;  % open local tcp socket to rtl_tcp
>> rtl_sdr_setFreq(soc,162400000);
>> rtl_sdr_setRate(soc,1000000);
>> soc=rtl_sdr_reset(soc);
>> y = rtl_sdr_getData(soc,1e6); % get 1 second worth of samples

I hope you enjoy this device!

please let me know if there are any problems.

— Miki