From charlesreid1

The Hardware

What It Is

Conceptual diagram:

(Antenna)---(USB Dongle)---(Computer)

Or, to make it a bit more complicated:

(Antenna)---(Antenna male PAL connector)---(USB dongle female PAL connector)---(USB dongle)---(USB dongle USB connector male)---(computer USB port female)---(computer)

How The DVB-T Works

The way this thing works is, the little antenna can receive radio signals that are transmitted on different frequencies. The way the antenna is designed dictates which frequencies it can listen to and what its range is. It's a small antenna, but many of the signals it recieves are very powerful, and are at a wavelength where they travel through walls pretty well (for example, you can get FM radio stations in a LOT of places) without much of an antenna.

The radio signals received in the antenna create a voltage signal, which is fed into crystal oscillators - that's the heart of what makes a radio a radio. That's what radios do - they turn radio signals into voltages, extract information from the signal with the oscillators, and feed that resulting voltage signal through a speaker or into a computer.

The hardware on the antenna just converts radio signals to raw voltages; the hardware on the DVB-T USB dongle is what does the hard work of processing the signal and creating raw IQ signals. Once these raw IQ signals have been extracted, you're now in the realm of software.

Tiny handheld Yaesu radios and laptops running GNU Radio are doing the same thing, basically: turning those raw IQ signals into something else - either sound in a speaker, or doing further processing, or whatever.

How The Ham It Up Works

You can also add a real antenna, and put a ham-it-up between the real antenna and the SDR USB dongle. It will require lots of adapters.

This works because the Ham It Up is designed to shift frequencies of radio signals - meaning, you can shift whatever your antenna receives, into whatever your USB dongle receives. Then you don't need a special SDR unit to convert radio waves of a particular frequency - you've got the hardware already.

In other words:

Without the Ham It Up, you might have a 40 meter antenna, but you can't feed those radio signals to the comptuer without an expensive SDR card that works for 7 MHz:

(signal at 7 MHz)---(antenna for 7 MHz)---$$$$$$$---(your computer)

And with the USB dongle, you can now listen to radio signals on your computer, within a given frequency:

(signal at 900 MHz)--(antenna for 900MHz)---(DVB-T USB dongle)---(your computer)

and finally, you can get the best of both worlds with the Ham It Up:

(signal at 7 MHz)--(antenna for 7 MHz)--(Ham It Up: shifts 7 MHz to 900 MHz)--(DVB-T USB dongle)---(your computer)

But like I said, it requires lots of adapters!

https://www.youtube.com/watch?v=9q2TYdo9cWY

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

Plug It In

First thing is to hook up the antenna to the USB dongle, and plug the USB dongle into the computer, and make sure the computer sees it:

$ lsusb | grep -i rtl
Bus 001 Device 003: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T

The Software

Gnu Radio

First thing is to install gnuradio.

apt-get install gnuradio

Cmake

Yer gonna need Cmake

apt-get install cmake

Boost/GSL Development

Then we'll install the Boost and GSL headers/development libraries for building scripts:

apt-get install libboost-1.49 libboost-dev libgsl0-dev

(Note that both of these were found using aptitude search [keyword]).

RTL-SDR Project

Next, clone into the rtl-sdr repository:

git clone git://git.osmocom.org/rtl-sdr.git

This project contains the software needed to interpret the raw I/Q packets sent from the antenna to the computer.

Now build the RTL-SDR project:

mkdir build
cd build
cmake ../

LibUSB Error

cmake ../
-- The C compiler identification is GNU 4.7.2
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Build type not specified: defaulting to release.
-- Extracting version information from git describe...
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.26") 
-- checking for module 'libusb-1.0'
--   package 'libusb-1.0' not found
-- Looking for libusb_handle_events_timeout_completed
-- Looking for libusb_handle_events_timeout_completed - not found
-- Looking for libusb_error_name
-- Looking for libusb_error_name - not found
-- libusb-1.0 not found.
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
CMake Error at CMakeLists.txt:69 (message):
  LibUSB 1.0 required to compile rtl-sdr


-- Configuring incomplete, errors occurred!

Oh no dude! We're doomed!

Naw, it's cool, we can fix that by installing LibUSB, since that's what the last line of the error said to do.

$ apt-get install libusb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libusb

Oh no dude! We're doomed!

Naw, just kidding, we can fix that by looking for libusb-related packaged with aptitude:

$ aptitude search libusb
p   libusb++-0.1-4c2                                       - userspace C++ USB programming library                           
p   libusb++-dev                                           - userspace C++ USB programming library development files         
i   libusb-0.1-4                                           - userspace USB programming library                               
i A libusb-1.0-0                                           - userspace USB programming library                               
p   libusb-1.0-0-dbg                                       - userspace USB programming library development files             
p   libusb-1.0-0-dev                                       - userspace USB programming library development files             
p   libusb-1.0-doc                                         - documentation for userspace USB programming                     
i A libusb-dev                                             - userspace USB programming library development files             
[......]

We need both the regular and the development versions of LibUSB 1.0. So the package we need is: libusb-1.0-0-dev

apt-get install libusb-1.0-0-dev

Return to the SDR Project

Okay, now we can go back to our build directory in the rtll-sdr project, and re-run cmake:

$ cmake ../
-- Build type not specified: defaulting to release.
-- Extracting version information from git describe...
-- checking for module 'libusb-1.0'
--   found libusb-1.0, version 1.0.17
-- Found libusb-1.0: /usr/include/libusb-1.0, /usr/lib/x86_64-linux-gnu/libusb-1.0.so
-- Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON
-- Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable
-- Building for version: v0.5.3-12-ge3c0 / 0.5git
-- Using install prefix: /usr/local
-- Configuring done
-- Generating done
-- Build files have been written to: /root/codes/sdr/rtl-sdr/build

All done! Just kidding, you gotta make it first:

make
Scanning dependencies of target convenience_static
[  5%] Building C object src/CMakeFiles/convenience_static.dir/convenience/convenience.c.o
Linking C static library libconvenience_static.a
[  5%] Built target convenience_static
Scanning dependencies of target rtlsdr_shared
[ 10%] Building C object src/CMakeFiles/rtlsdr_shared.dir/librtlsdr.c.o
[ 15%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_e4k.c.o
[ 20%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0012.c.o
[ 25%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0013.c.o
[ 30%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc2580.c.o
[ 35%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_r82xx.c.o
Linking C shared library librtlsdr.so
[ 35%] Built target rtlsdr_shared
Scanning dependencies of target rtl_adsb
[ 40%] Building C object src/CMakeFiles/rtl_adsb.dir/rtl_adsb.c.o
Linking C executable rtl_adsb
[ 40%] Built target rtl_adsb
Scanning dependencies of target rtl_eeprom
[ 45%] Building C object src/CMakeFiles/rtl_eeprom.dir/rtl_eeprom.c.o
Linking C executable rtl_eeprom
[ 45%] Built target rtl_eeprom
Scanning dependencies of target rtl_fm
[ 50%] Building C object src/CMakeFiles/rtl_fm.dir/rtl_fm.c.o
Linking C executable rtl_fm
[ 50%] Built target rtl_fm
Scanning dependencies of target rtl_power
[ 55%] Building C object src/CMakeFiles/rtl_power.dir/rtl_power.c.o
Linking C executable rtl_power
[ 55%] Built target rtl_power
Scanning dependencies of target rtl_sdr
[ 60%] Building C object src/CMakeFiles/rtl_sdr.dir/rtl_sdr.c.o
Linking C executable rtl_sdr
[ 60%] Built target rtl_sdr
Scanning dependencies of target rtl_tcp
[ 65%] Building C object src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.o
Linking C executable rtl_tcp
[ 65%] Built target rtl_tcp
Scanning dependencies of target rtl_test
[ 70%] Building C object src/CMakeFiles/rtl_test.dir/rtl_test.c.o
Linking C executable rtl_test
[ 70%] Built target rtl_test
Scanning dependencies of target rtlsdr_static
[ 75%] Building C object src/CMakeFiles/rtlsdr_static.dir/librtlsdr.c.o
[ 80%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_e4k.c.o
[ 85%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc0012.c.o
[ 90%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc0013.c.o
[ 95%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_fc2580.c.o
[100%] Building C object src/CMakeFiles/rtlsdr_static.dir/tuner_r82xx.c.o
Linking C static library librtlsdr.a
[100%] Built target rtlsdr_static

Okay, NOW we are done. Just one more thing to install.

Gnu Radio Baz

The Baz extension for gnu radio:

$ apt-get install libgnuradio-baz libgnuradio-baz-dev

Python Multimode Receiver

This project looks interesting, but requires a beta 3.7 version of GNU Radio: https://github.com/bgamari/gnuradio-multimode

If you try and install it with GNU Radio 3.6 it will fail.

Just sayin.

Using RTL-SDR

Now that we've installed RTL-SDR, it is time to use it.

The Binary

You can enter the src/ directory of your Cmake build, and you'll see your rtl-sdr binary:

ls -1 src/
CMakeFiles
cmake_install.cmake
libconvenience_static.a
librtlsdr.a
librtlsdr.so
librtlsdr.so.0
librtlsdr.so.0.5git
Makefile
rtl_adsb
rtl_eeprom
rtl_fm
rtl_power
rtl_sdr
rtl_tcp
rtl_test

Test

First thing I ran was the sdr_test binary:

./rtl_test 
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM

Kernel driver is active, or device is claimed by second instance of librtlsdr.
In the first case, please either detach or blacklist the kernel module
(dvb_usb_rtl28xxu), or enable automatic detaching at compile time.

usb_claim_interface error -6
Failed to open rtlsdr device #0.

We can detach driver modules from the kernel by using rmmod, so we'll detach this module:

rmmod dvb_usb_rtl28xxu

and try again.

Hello RTL-SDR World!

HelloSDRWorld.png

$ ./rtl_test 
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 
[R82XX] PLL not locked!
Sampling at 2048000 S/s.

Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.

Reading samples in async mode...

What does all this mean?!?

The antenna is basically ingesting raw radio frequency information, at whatever frequency it happens to be listening on (it's variable), and is reading 2048000 samples per second. That means, if we want to scan a whole range of frequencies, we can grab a handful of samples from each frequency, and loop through every single frequency, and it won't take very long. That enables us to create a "waterfall" display of activity across a whole range of frequencies, even though an antenna can only listen to one frequency at a time.

Dumping What You Hear

You can dump out what the antenna hears with the rtl_sdr script, which does a raw dump of binary data from onboard the SDR chip. This has a couple of nice parameters:

./rtl_sdr
rtl_sdr, an I/Q recorder for RTL2832 based DVB-T receivers

Usage:	 -f frequency_to_tune_to [Hz]
	[-s samplerate (default: 2048000 Hz)]
	[-d device_index (default: 0)]
	[-g gain (default: 0 for auto)]
	[-p ppm_error (default: 0)]
	[-b output_block_size (default: 16 * 16384)]
	[-n number of samples to read (default: 0, infinite)]
	[-S force sync output (default: async)]
	filename (a '-' dumps samples to stdout)

Suppose we want to listen to 900 MHz, like all the other cool hipster hacker kids who are doing HamProxy SDR projects. Since radio operators are the hipsters of the airwaves, always wanting to find a new, hip frequency to use that no one else is using, we will do that, and use 920 MHz.

We'll be reading somewhere around 2-3 million samples pre second. Give that time to sink in - it's mind-boggling. In the time it takes you to drink a cup of coffee, it probably generates more information than all the bureaucrats of royal France did over the course of a century. (It could have been bureaucrats from anywhere, really, but I picked French because the word bureaucrat is from French.)

We can specify a number of samples, which doesn't correspond to the number of samples the RTL-SDR device is taking per second because the two don't match up at all:

$ ./rtl_sdr /tmp/raw_sdr -f 920e6 -n 1e6

This will make a file full of gibberish:

SDRGibberish.png

Freeze. Kill. Respawn. Repeat.

If you run into problems with the radio freezing up or listening forever and not responding to Contrl+C, you can always do a killall on your process, unplug the USB dongle, re-plug it in, and run:

rmmod dvb_usb_rtl28xxu

What Next

We've got our basic "Hello SDR World" program up and running. We can grab raw data. We can feed the raw data to an audio player. So far, so AWESOME.

But here's what comes next:

  • Gnu Radio
  • Ham It Up for better antennas
  • Adapters


Useful Links