[This post is originally from my blog. I'm bringing this spectrum analyzer to Darren Kitchen's Hak5 event at OMSI this Saturday (2013/05/25).]
Here's some details of my radio spectrum analyzer hack at Maker Faire. But firs...
[This post is originally from my blog. I'm bringing this spectrum analyzer to Darren Kitchen's Hak5 event at OMSI this Saturday (2013/05/25).]
Here's some details of my radio spectrum analyzer hack at Maker Faire. But first, a quick video of the
hack in action:
src="http://www.youtube.com/embed/rmVu_mw3aJU" width="640">
Technical Details
This project is built around the HackRF, a
software-defined radio transciever. I programmed it to sample 20MHz of radio spectrum from an antenna, do
a frequency analysis on the data, and display the results on a Noritake vacuum fluorescent display. I
added the tuning wheel mid-afternoon on Sunday, and it really improved the interactivity of the display.
It felt really cool to spin the wheel around and watch the spectrum scroll back and forth. Too bad I
didn't capture that in the video...
href="http://www.sharebrained.com/wp-content/2013/05/radio-spectrum-analyzer1-e1369184474197.jpg">
alt="" class="aligncenter size-medium wp-image-1009" height="560"
src="http://www.sharebrained.com/wp-content/2013/05/radio-spectrum-analyzer1-e1369184474197-420x560.jpg"
title="Radio Spectrum Analyzer at Maker Faire 2013" width="420">
The HackRF's microcontroller is
an ARM Cortex-M4F +
Cortex-M0 "dual core" chip. Both are running at 204MHz. The M4F has hardware floating point, which
drastically simplifies the signal processing code.
The ARM grabs 512 complex samples at a time from
the radio analog-to-digital converter (ADC). It applies a
href="http://en.wikipedia.org/wiki/Window_function">window function that reduces artifacts from
sampling arbitrary chunks of a radio signal. The windowed samples are converted to
href="http://en.wikipedia.org/wiki/Frequency_domain">frequency domain data through a 512-point
href="http://en.wikipedia.org/wiki/Fft">fast-Fourier transform (FFT). The frequency data that comes
out of the FFT (frequency vs. a complex vector)
is converted to real magnitudes. I take the logarithm
of each magnitude to get values vs. frequency that resemble
href="http://en.wikipedia.org/wiki/Decibel">decibels. Then, I scale the log-magnitude data to fit
nicely on the vacuum fluorescent display, which
is 384 x 32 pixels. For each frequency in the scaled data, I render a bar into a frame buffer I maintain
in RAM, using cute bit-shifting tricks. Then, I render marks at 1MHz intervals to provide a tick-mark
scale on the display. In the left corner of the display, I render minimum and maximum sample buffer values
for each of the two sampling channels -- this is so I can tell if I need to turn up or down the gain on
the receiver. I draw the current tuning frequency in MHz at the center of the display. Lastly, I scan out
each of the pixels, one byte at a time, into the VFD's parallel 8-bit interface, using the display's
"Graphic DMA" mode.
The optical
href="http://en.wikipedia.org/wiki/Rotary_encoder#Single-track_Gray_encoding">quadrature encoder runs
purely on interrupts. Whenever a positive- or negative-going edge is detected on either of the two optical
sensors, an interrupt is generated. Based on the current and previous values of the optical sensors, the
software (borrowed from PJRC's Encoder
Library) decides if the wheel has moved, and if so, which way it has moved. Based on that decision,
the tuning frequency is incremented or decremented.
There was a hairy bit of wiring between
the HackRF and the VFD. I needed to interface the HackRF, which is a 3.3 Volt device, to the VFD, which
communicates at 5 Volts. So I needed to translate several signals between those two voltages. I had an old
circuit board from my Robotron-FPGA project
that did exactly that, for a completely different purpose. But with enough wires and headers and
disgusting rewiring, I made it work. But it wasn't pretty. I had to keep poking it and twisting it, as
some signals were intermittent and sometimes needed my help.
The Faire
Experience
The HackRF can tune from below 10MHz (where it