Fun Stuff, Yea
Actually doing something, FM Radio Decoding

I know decoding isn’t technically the correct term here which would be demodulation but I am primarily a software person and SDR is all about software. I have come to have a bit of a chip towards radio people because I think they really just don’t understand software at all. They are analog beasts for the most part. In a perfect world software people would throw a monster antenna on the roof and connect it to an equally giant ADC and just process it using a giant hadoop cluster. (Please no emails from radio people about how that could never work). Granted that would be overkill to get a local FM radio station on your laptop in practice but development isn’t about practice, it is about creating the shorting possible iteration cycle to keep things moving in the direction you want them. SDR is a big step there, in that you don’t need to build boards everytime you want to do something new but there is still too much hardware dependence and it sure seems like gnu radio was made for radio people and not for software people. /rant

So you have your usb tuner setup, gnu radio installed, now to do something actually interesting. Lets tune in to a local FM station and listen on your computer with all the processing happening in software.

You can open the gnuradio workflow I made for this here: http://pastebin.com/download.php?i=WwMEhRZx . Choose file open and load it into Gnu Radio Companion  (GRC). It should look something like this:

So what is going on here?


This is a graphical map of the processing steps grnu radio is doing with the input signal. On the left hand side there are two important blocks. They are variable blocks, you can define a value and a placeholder name. That when as you setup additional blocks you can reference the placeholder and if you want to change something like frequency you can just change it once in the variable block instead of having to change it all over the place. The other one is sample rate, this is how many samples of the stream are done per second.

The hardware will have an upper limit and some local system performance will also effect the result. I picked a safe value that worked well for me on my slightly older laptop. There are also some more complex decisions you would need to make about sample rate if you are working with more complex types of signals.

Double click the frequency and change that to a known good quality radio station frequency for your area. Note that it is in hertz to 91,500,000 is 91.5 on your car radio.

Next over in the workflow we have the rtl source, this is the raw data stream coming from the usb tuner hardware. It references the sample rate and frequency variable blocks we just reviewed.

Throttle is the next item, I don’t think this is strictly necessary with the rtl source but I saw it in frequent examples and I don’t know if there is any aspect of the rtl source that is inconsistent.

After throttle is a tee to two different blocks. One is WX GUI FFT which is a line graph visualization of the spectrum being captured. It isn’t necessary to hear the radio but you should be able to see a clear peak in activity at your specific frequency where the radio station you are tuning to should be.

The other side of the tee is the Low Pass Filter block. There is tons of extraneous noise flying all over the place, this is a software filter the blocks out frequencies beyond the bounds of the range specified. You can try adjusting the parameters here to try and improve the quality of the audio you get and eliminate fuzz or other interference.

The low pass goes into the WBFM Receive. This is where the magic happens that decodes the input stream into the actual audio that was encoded into the stream and bits suitable for sending to your soundcard.

Finally there is the Audio Sink, this is the output that connects the stream to your audio card.

With all that setup you can run the workflow. Now you can press F5 to “compile” your workflow, you should see “Generating …” in the bottom status window. Then press F6 to run your workflow, after some churning you should see the line graph window popup and you should start to hear either static or hopefully your radio station coming out your speakers. Success!

Click the GNU Radio Companion window in the background and hit F7 to kill the workflow. I am not having any luck getting a response from any of the controls in the popup, they seem static or read only. Once stopped you can alter the frequency in the variable block and jump to another station.

Enough fun for now, see what you can pickup, use the visualization to see what is out there on any frequency, and play with the low band filter or other filters to improve audio output quality. Good luck!

Loading the rtl-sdr source block into gnu radio

#4 Load the source block into GNU Radio

The source block is a plug and play module in gnu radio that will let you tap the rtl-sdr hardware directly from the UI and use it as a source for a processing flow. The simplest getting started “hello world” processing flow will be to decode a local FM radio station. For most setups this can be done in real time and will give you a set of opportunities to experiment with all the settings and processing aspects of gnu radio flows.

I think the osmocom folks are working on a source module also but I was not able to get that to load. I used the 

First make sure your gnuradio installation from the last step works. Do:

/usr/local/bin/gnuradio_companion

You should get something like the following screencap:

GNU Radio Companion GUI

If that checks out then you need to go back to your main directory for tracking all the rtl-sdr software.

Using git again do:

git clone https://github.com/balint256/gr-baz.git

cd gr-baz

chmod +x bootstrap

./boostrap

./configure

make

make check

make install

ldconfig

When you run gnuradio_companion again, you should see the “RTL2832 Source” in the source list on the right. See this screenshot:

Screen shot showing rtl-sdr source block

Loading GNURadio

#3 Installing GNU Radio

Thank the FSM for the guys and gals (shirleys bay radio astronomy consortium) who created this script but it does most of the horrible GNU Radio installation work for you. Just understand it takes hours and requires some occasional babysitting.

wget “http://www.sbrac.org/files/build-gnuradio”

chmod +x build-gnuradio

./build-gnuradio -v

Go get some fro-yo and come back. The script requires that you run it as a non-root user and then annoyingly asks for the sudo password several times which is the only thing preventing it running mostly autonomous. I think it does this to make sure the environment setup will be accessible by your regular user but it still annoys me. It may appear to be sitting frozen but most likely it is downloading files, I had to download about 400MB via the apt-get dependancies it triggered. The “-v” helps show some additional output so you can tell if it is still going. If you need to cancel it do cntrl-c and fortunately you should be able to rerun it, it should take the work already done into account.

Once done compiling and installing you just need to get the rtl-sdr source block working which is covered in the next post

How to get going quickly with RTLSDR

#2 Loading up the environment

There are a lot of dependencies and custom compiled libraries at the moment so my suggestion and what I did was load up a slightly older laptop (2.4ghz, 2gb ram) with Ubuntu 11.10 I could dedicate to radio projects.

These posts assume you have at least some knowledge of using the linux command line . If you don’t feel free to ask questions and I will do the best I can to answer.

Ubuntu is probably the easiest distro to get and keep working with this at this point so it is what I will stick with here. You can attempt to use a virtual instance inside vmware or such but radio is very performance demanding and the throughput of the USB to the virtual instance may not be great and you will probably loose any real time viewing/processing capabilities which makes getting started that much harder.

Make sure you have apt-get install build-essential installed because you need the complete compile chain. You also need GIT which is a tool that gets and manages source code. apt-get install git-core

So once in ubuntu you can verify you got the correct hardware by installing the rtlsdr library and just trying it from the command line.

Setup a place where it is ok for things to get messy, I made rtlsdr in my home folder.

Do:

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

This should make a directory:  rtl-sdr . You need to be root, I do sudo su root, some people hate that.

To compile do these steps:

cd rtl-sdr

autoconf -i

./configure

make

make install

ldconfig

Plug in your usb and connect the antenna that came with it into the little nub plug. Check your usb message using dmesg and you should see something like new high speed usb device . The plugs on my laptop are really worn and the usb tuner plug is really cheap so I had to use some tape to make sure I had a snug connection.

From the command line run:

/usr/local/bin/rtl_sdr /tmp/out.bin -s 1800000 -f 91500000

/tmp/out.bin is the output of the capture

-s 1800000 is the samples per second, that is 1.8 million samples per second. The best sample for these tuners/devices is still being worked out. The theoretically maximum for this chip combination is 3.2 million, practically it seems to fail above 2.8 million.

-f 91500000

is the frequency in megahertz, that would be 91.5 mhz (91 an 1/2 million hertz, 91,500,000) on the FM radio dial, that is NPR in phoenix. 

You should then see something like:

Found 1 device(s):

0: Generic RTL2832U (e.g. hama nano)

Using device 0: Generic RTL2832U (e.g. hama nano)

Found Elonics E4000 tuner

Tuned to 91500000 Hz.

Tuner gain set to 0 dB.

Reading samples in async mode…

After a second or two hit cntrl-c as the file /tmp/out.bin will get very large very quick. If the file is more than 0 bytes your tuner is successfully grabbing data. Next installment is on setting up gnuradio

From aliexpress

From aliexpress

Getting Started with RTLSDR

#1 Getting your device

I have been wanting to play with gnuradio for years and I finally saw that there was an SDR option that wasn’t a million dollars. I don’t see how having a completely proprietary design for the USRP fits with an open at all but that is another story (just try asking for the gerbers or source cad files, they are even rude about it). Actually much, much better than that, about $25.

You need to get a usb TV device with the RTL2832U chip and preferably the elonics e4000 tuner chip. I got 1 from ebay seller titled “USB Digital DVB-T HDTV TV Tuner Recorder Receiver P160” . It has to be the P160, confirm with sellers before purchasing that it is in fact the RTL2832U chipset if you are worried. Item listing was: http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=140561464529

It took about 3 weeks to get here. I also have on order another one from deal exrteme which by all appearances seems correct: http://www.dealextreme.com/p/mini-dvb-t-digital-tv-usb-2-0-dongle-with-fm-dab-remote-controller-92096?item=5

A quick note about business dealings with the chinese (and many asian cultures), you CANNOT bring your american style customer service expectations to interactions when purchasing things from china. It just doesn’t work that way. There are cultural and language issue too numerous to quantify. Contrary to many popular opinions 99.99% of the time chinese vendors are not intending to defraud or mislead, it is just a very buyer beware kind of deal. Be polite, use simple sentence structures, DO NOT USE expressions or euphemisms, BE POLITE.

Time zone, they are 15-19 hours ahead of the US west coast, take that into account when sending emails. Jan 15-Feb 20th give or take is the chinese new year season, during this period very, very little gets done at least in regard to filling US orders. On the other hand that is pretty much the only vacation time they take.

With that said you can order from china via: http://www.aliexpress.com/product-gs/535188805-Mini-USB-DVB-T-Stick-RTL2832U-Elonics-E4000-Radio-P160-SDR-Radio-64-1700-MHz-wholesalers.html

Expect it to take a while like 3-5 weeks because at that price it is coming via regular china mail to us mail.