Software defined radio with rtl-sdr
I have lately been experimenting with a cheap way of software defined radio, SDR. Previously this would utilize quite expensive equipment but a while ago Realtek released a nice little chip with USB interface called RTL2832U. It is officially used for DAB/DAB+/FM demodulation but with the right piece of software it can be used to decode almost anything. The RTL2832U combined with a tuner chip is a complete and quite competent radio receiver. The most commonly available and most desirable tuners are the Elonics E4000 and the Rafael Micro R820T. They are quite similar in performance but some things differ. First off the E4000 is a direct conversion receiver and the R820T is a more conventional super-heterodyne receiver with an MF of 3.57Mhz. The tuning range for the E4000 is 52-2200MHz with a gap from 1100-1250MHz and while the R820T covers 24-1766MHz and no gaps. Exact frequency limits vary from chip to chip but not very much. I have acquired two USB-sticks with these chips. One RTL2832U + E4000 and one RTL2832U + R820T. Osmocom has developed drivers for these chips for use as a general purpose software defined receiver. Their software is called rtl-sdr and is the key for making this work. The software is open source and available from Osmocoms GIT repository. git clone git:// To compile the code under debian squeeze some packages are needed. apt-get install libusb-1.0-0 libusb-1.0-0-dev cmake Compilation and installation is quite straight forward. Enter the directory obtained from git and create a work directory "build". This is the directory that will be populated with the binaries. cd rtl-sdr/ mkdir build cd build cmake ../ make sudo make install sudo ldconfig To make the USB device accessible for non-root users Osmocom has a prepared set of udev rules. cd rtl-sdr/ sudo cp rtl-sdr.rules /etc/udev/rules.d/ Now we should have all software needed for using the USB sticks. One important thing with both the E4000 and the R820T is that they get quite hot when operating and their frequency tends to drift a bit until the temperature stabilizes. There is a tool called rtl_test that can measure this error so that we can use it later. First let the ships warm up for a while (around 20min to 1h) and then run the following. $ rtl_test -p 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 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 Reporting PPM error measurement every 10 seconds... Press ^C after a few minutes. Reading samples in async mode... real sample rate: 2048001 real sample rate: 2048081 real sample rate: 2048056 real sample rate: 2048056 real sample rate: 2048077 real sample rate: 2048059 real sample rate: 2048056 real sample rate: 2048080 real sample rate: 2048056 real sample rate: 2048056 real sample rate: 2048056 real sample rate: 2048079 real sample rate: 2048056 real sample rate: 2048056 real sample rate: 2048079 ^CSignal caught, exiting! User cancel, exiting... Cumulative PPM error: 28 Let the software run for a few minutes and the press ctrl+C to end measurement. The program will exit nicely and present the average frequency error. Remember this value. Now we are ready to receive some signals. Osmocom sends along a simple receiver application called rtl_fm. Do not be fooled by the application name. It decodes AM/USB/LSB as well. This is what the built-in help says. rtl_fm, a simple narrow band FM demodulator for RTL2832 based DVB-T receivers Use: rtl_fm -f freq [-options] [filename] -f frequency_to_tune_to [Hz] (use multiple -f for scanning, requires squelch) (ranges supported, -f 118M:137M:25k) [-s sample_rate (default: 24k)] [-d device_index (default: 0)] [-g tuner_gain (default: automatic)] [-l squelch_level (default: 0/off)] [-o oversampling (default: 1, 4 recommended)] [-p ppm_error (default: 0)] [-E sets lower edge tuning (default: center)] [-N enables NBFM mode (default: on)] [-W enables WBFM mode (default: off)] (-N -s 170k -o 4 -A fast -r 32k -l 0 -D) filename (a '-' dumps samples to stdout) (omitting the filename also uses stdout) Experimental options: [-r output_rate (default: same as -s)] [-t squelch_delay (default: 20)] (+values will mute/scan, -values will exit) [-M enables AM mode (default: off)] [-L enables LSB mode (default: off)] [-U enables USB mode (default: off)] [-R enables raw mode (default: off, 2x16 bit output)] [-F enables high quality FIR (default: off/square)] [-D enables de-emphasis (default: off)] [-C enables DC blocking of output (default: off)] [-A std/fast/lut choose atan math (default: std)] Produces signed 16 bit ints, use Sox or aplay to hear them. rtl_fm ... - | play -t raw -r 24k -e signed-integer -b 16 -c 1 -V1 - | aplay -r 24k -f S16_LE -t raw -c 1 -s 22.5k - | multimon -t raw /dev/stdin For example this line will monitor my local 70cm repeater. rtl_fm -p 28 -f 434.700M -N -s 8k -o 4 -l 100 | aplay -r 8k -f S16_LE -t raw -c 1 -p 28 will specify the frequency error in PPM taken from rtl_test above. -f 434.700M specifies the receive frequency, M for MHz. -s 8k specifies the sample rate and since this is SDR this will also specify the input filter width (remember Nyquist's theorem). I found that 8k is about right for NBFM and make sure you match this sample rate with the sample rate of aplay. -l 100 specifies the squelch level. You will have to set this to match your noise level. To use rtl-sdr with fancy softwares like SDR# there is a tool called rtl_tcp that allows the USB stick to be controlled over a network socket. By default rtl_tcp will listen only on localhost. To make the stick accessible from any address, specify the listen address with the -a argument. rtl_tcp -a One more thing to add about these sticks in that some of them do not have ESD protection diodes on the antenna input. Extra care should be taken. I strongly recommend soldering that in. Two 1N4148 in parallel and opposite direction from antenna input to ground will make up a quite efficient protection.

Write a comment

Name or handle

E-mail (optional and not visible to others)


Code from above