9d471f663a988e374d7ece7a70cdc86f88b101aa
[debian/gnuradio] / docs / exploring-gnuradio / exploring-gnuradio.xml
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3           "docbookx.dtd" [
4   <!ENTITY dial_tone_example SYSTEM "dial_tone_example.xml">
5   <!ENTITY fm_demod_example SYSTEM "fm_demod_example.xml">
6 ]>
7
8 <article>
9 <articleinfo>
10   <title>Exploring GNU Radio</title>
11   <author>
12      <firstname>Eric</firstname>
13      <surname>Blossom</surname>
14      <affiliation>
15         <address>
16            <email>eb@comsec.com</email>
17         </address>
18      </affiliation>
19   </author>
20
21 <revhistory>
22   <revision>
23   <revnumber>v1.1</revnumber>
24   <date>2004-11-29</date>
25   <revremark>
26     Revised and expanded.  Examples now use 2.x code base.
27   </revremark>
28   </revision>
29
30   <revision>
31   <revnumber>v1.0</revnumber>
32   <date>2004-02-29</date>
33   <revremark>
34   Initial version published in Linux Journal, Issue 122, June 2004, as
35   <emphasis>GNU Radio: Tools for Exploring the RF Spectrum</emphasis>.
36   </revremark>
37   </revision>
38 </revhistory>
39
40 <abstract><para>This article provides an overview of the GNU Radio
41 toolkit for building software radios.
42 </para></abstract>
43
44 </articleinfo>
45
46 <sect1 id="intro"><title>Introduction</title>
47
48 <para>Software radio is the technique of getting code as close to the
49 antenna as possible. It turns radio hardware problems into software
50 problems. The fundamental characteristic of software radio is that
51 software defines the transmitted waveforms, and software demodulates
52 the received waveforms. This is in contrast to most radios in which
53 the processing is done with either analog circuitry or analog
54 circuitry combined with digital chips. GNU Radio is a free software
55 toolkit for building software radios.</para>
56
57 <para>Software radio is a revolution in radio design due to its ability to
58 create radios that change on the fly, creating new choices for
59 users. At the baseline, software radios can do pretty much anything a
60 traditional radio can do. The exciting part is the flexibility that
61 software provides you. Instead of a bunch of fixed function gadgets,
62 in the next few years we'll see a move to universal communication
63 devices. Imagine a device that can morph into a cell phone and get you
64 connectivity using GPRS, 802.11 Wi-Fi, 802.16 WiMax, a satellite
65 hookup or the emerging standard of the day. You could determine your
66 location using GPS, GLONASS or both.</para>
67
68 <para>Perhaps most exciting of all is the potential to build decentralized
69 communication systems. If you look at today's systems, the vast
70 majority are infrastructure-based. Broadcast radio and TV provide a
71 one-way channel, are tightly regulated and the content is controlled
72 by a handful of organizations. Cell phones are a great convenience,
73 but the features your phone supports are determined by the operator's
74 interests, not yours.</para>
75
76 <para>A centralized system limits the rate of innovation. We could take some
77 lessons from the Internet and push the smarts out to the
78 edges. Instead of cell phones being second-class citizens, usable only
79 if infrastructure is in place and limited to the capabilities
80 determined worthwhile by the operator, we could build smarter
81 devices. These user-owned devices would generate the network. They'd
82 create a mesh among themselves, negotiate for backhaul and be free to
83 evolve new solutions, features and applications.</para>
84
85 </sect1>
86
87 <sect1 id="block-diagram"><title>The Block Diagram</title>
88
89 <para><xref linkend="block-diagram-fig"/> shows a typical block
90 diagram for a software radio. To understand the software part of the
91 radio, we first need to understand a bit about the associated
92 hardware. Examining the receive path in the figure,
93 we see an antenna, a mysterious RF front end, an analog-to-digital
94 converter (ADC) and a bunch of code. The analog-to-digital converter
95 is the bridge between the physical world of continuous analog signals
96 and the world of discrete digital samples manipulated by
97 software.</para>
98
99 <figure id="block-diagram-fig"><title>Typical software radio block diagram</title>
100 <mediaobject>
101 <imageobject><imagedata fileref="swr-block-diagram.eps" format="EPS"/></imageobject>
102 <imageobject><imagedata fileref="swr-block-diagram.png" format="PNG"/></imageobject>
103 <caption><para></para></caption>
104 </mediaobject>
105 </figure>
106
107 <para>ADCs have two primary characteristics, sampling rate and dynamic
108 range. Sampling rate is the number of times per second that the ADC
109 measures the analog signal. Dynamic range refers to the difference
110 between the smallest and largest signal that can be distinguished;
111 it's a function of the number of bits in the ADC's digital output and
112 the design of the converter. For example, an 8-bit converter at most
113 can represent 256 (2<superscript>8</superscript>) signal levels, while
114 a 16-bit converter represents up to 65,536 levels. Generally speaking,
115 device physics and cost impose trade-offs between the sample rate and
116 dynamic range.</para>
117
118 <para>Before we dive into the software, we need to talk about a bit of
119 theory. In 1927, a Swedish-born physicist and electrical engineer
120 named Harry Nyquist determined that to avoid aliasing when converting
121 from analog to digital, the ADC sampling frequency must be at least
122 twice the bandwidth of the signal of interest. Aliasing is what makes
123 the wagon wheels look like they're going backward in the old westerns:
124 the sampling rate of the movie camera is not fast enough to represent
125 the position of the spokes unambiguously.</para>
126
127 <para>Assuming we're dealing with low pass signals - signals where the
128 bandwidth of interest goes from 0 to f<subscript>MAX</subscript>, the
129 Nyquist criterion states that our sampling frequency needs to be at
130 least 2 * f<subscript>MAX</subscript>. But if our ADC runs at 20 MHz,
131 how can we listen to broadcast FM radio at 92.1 MHz? The answer is the
132 RF front end. The receive RF front end translates a range of
133 frequencies appearing at its input to a lower range at its output. For
134 example, we could imagine an RF front end that translated the signals
135 occurring in the 90 - 100 MHz range down to the 0 - 10 MHz
136 range.</para>
137
138 <para>Mostly, we can treat the RF front end as a black box with a single
139 control, the center of the input range that's to be translated. As a
140 concrete example, a cable modem tuner module that we've employed
141 successfully has the following characteristics. It translates a 6 MHz
142 chunk of the spectrum centered between about 50 MHz and 800 MHz down to
143 an output range centered at 5.75 MHz. The center frequency of the
144 output range is called the intermediate frequency, or IF.</para>
145
146 <para>In the simplest-thing-that-possibly-could-work category, the RF front
147 end may be eliminated altogether. One GNU Radio experimenter has
148 listened to AM and shortwave broadcasts by connecting a 100-foot piece
149 of wire directly to his 20M sample/sec ADC.</para>
150
151 </sect1> 
152
153 <sect1 id="software"><title>On to the Software</title>
154
155 <para>GNU Radio provides a library of signal processing blocks and the
156 glue to tie it all together. The programmer builds a radio by creating
157 a graph (as in graph theory) where the vertices are signal processing
158 blocks and the edges represent the data flow between them. The
159 signal processing blocks are implemented in C++. Conceptually,
160 blocks process infinite streams of data flowing from their input
161 ports to their output ports. Blocks' attributes include the number
162 of input and output ports they have as well as the type of data that
163 flows through each. The most frequently used types are short, float
164 and complex.</para>
165
166 <para>Some blocks have only output ports or input ports. These serve as
167 data sources and sinks in the graph. There are sources that read from
168 a file or ADC, and sinks that write to a file, digital-to-analog
169 converter (DAC) or graphical display. About 100 blocks come with
170 GNU Radio. Writing new blocks is not difficult.</para>
171
172 <para>Graphs are constructed and run in Python.
173 <!-- <xref linkend="dial_tone_ex"/> -->
174 Example 1
175 is the "Hello World" of GNU Radio. It generates two sine waves and outputs
176 them to the sound card, one on the left channel, one on the
177 right.</para>
178
179 &dial_tone_example;
180
181 <para>We start by creating a flow graph to hold the blocks and
182 connections between them. The two sine waves are generated by the
183 gr.sig_source_f calls. The f suffix indicates that the source produces
184 floats. One sine wave is at 350 Hz, and the other is at
185 440 Hz. Together, they sound like the US dial tone.</para>
186
187 <para>audio.sink is a sink that writes its input to the sound card. It
188 takes one or more streams of floats in the range -1 to +1 as its
189 input. We connect the three blocks together using the 
190 <methodname>connect</methodname> method of the flow graph.</para>
191
192 <para><methodname>connect</methodname> takes two parameters, the
193 source endpoint and the destination endpoint, and creates a connection
194 from the source to the destination.  An endpoint has two components: a
195 signal processing block and a port number.  The port number specifies
196 which input or output port of the specified block is to be connected.
197 In the most general form, an endpoint is represented as a python tuple
198 like this: <literal>(block, port_number)</literal>.  When
199 <literal>port_number</literal> is zero, the block may be used alone.
200 </para>
201
202 <para>These two expressions are equivalent:</para>
203 <programlisting>
204 fg.connect ((src1, 0), (dst, 1))
205 fg.connect (src1, (dst, 1))
206 </programlisting>
207
208 <para>Once the graph is built, we start it. Calling
209 <methodname>start</methodname> forks one or more threads to run the
210 computation described by the graph and returns control immediately to
211 the caller. In this case, we simply wait for any keystroke.</para>
212
213 </sect1>
214
215 <sect1 id="fm-receiver"><title>A Complete FM Receiver</title>
216
217 <para>
218 <!-- <xref linkend="fm_demod_ex"/> -->
219 Example 2
220 shows a somewhat simplified but
221 complete broadcast FM receiver. It includes control of the RF front
222 end and all required signal processing. This example uses an RF front
223 end built from a cable modem tuner and a 20M sample/sec
224 analog-to-digital converter.</para>
225
226 &fm_demod_example;
227
228 <para>Like the Hello World example, we build a graph, connect the
229 blocks together and start it. In this case, our source, mc4020.source,
230 is an interface to the Measurement Computing PCI-DAS 4020/12
231 high-speed ADC.  We follow it with gr.freq_xlating_fir_filter_scf, a
232 finite impulse response (FIR) filter that selects the FM station we're
233 looking for and translates it to baseband (0Hz, DC). With the 20M
234 sample/sec converter and cable modem tuner, we're really grabbing
235 something in the neighborhood of a 6 MHz chunk of the spectrum. This
236 single chunk may contain ten or more FM stations, and
237 gr.freq_xlating_fir_filter_scf allows us to select the one we
238 want.</para>
239
240 <para>In this case, we select the one at the exact center of the IF of
241 the RF front end (5.75 MHz). The output of
242 gr.freq_xlating_fir_filter_scf is a stream of complex samples at
243 160,000 samples/second. We feed the complex baseband signal into
244 gr.quadrature_demod_cf, the block that does the actual FM
245 demodulation.</para>
246
247 <para>gr.quadrature_demod_cf works by subtracting the angle of
248 each adjacent complex sample, effectively differentiating the
249 frequency. The output of gr.quadrature_demod_cf contains the
250 left-plus-right FM mono audio signal, the stereo pilot tone at 19kHz,
251 the left-minus-right stereo information centered at 38kHz and any
252 other sub-carriers above that. For this simplified receiver, we finish
253 off by low pass filtering and decimating the stream, keeping only the
254 left-plus-right audio information, and send that to the sound card at
255 32,000 samples/sec.</para>
256
257 <para>For a more indepth look at how the FM receiver
258 works, please see "Listening to FM, Step by Step."</para>
259
260 </sect1>
261
262 <sect1 id="gui"><title>Graphical User Interfaces</title>
263
264 <para>Graphical interfaces for GNU Radio applications are built in
265 Python. Interfaces may be built using any toolkit you can access from
266 Python; we recommend wxPython to maximize cross-platform
267 portability. GNU Radio provides blocks that use interprocess
268 communication to transfer chunks of data from the real-time C++ flow
269 graph to Python-land. </para>
270
271 <!-- please add more here, including example code and screen shots -->
272
273 </sect1>
274
275 <sect1 id="hardware-requirements"><title>Hardware Requirements</title>
276
277 <para>GNU Radio is reasonably hardware-independent. Today's commodity
278 multi-gigahertz, super-scalar CPUs with single-cycle floating-point
279 units mean that serious digital signal processing is possible on the
280 desktop. A 3 GHz Pentium or Athlon can evaluate 3 billion
281 floating-point FIR taps/s. We now can build, virtually all in
282 software, communication systems unthinkable only a few years ago.</para>
283
284 <para>Your computational requirements depend on what you're trying to do,
285 but generally speaking, a 1 or 2 GHz machine with at least 256 MB of RAM
286 should suffice. You also need some way to connect the analog world to
287 your computer. Low-cost options include built-in sound cards and
288 audiophile quality 96 kHz, 24-bit, add-in cards. With either of these
289 options, you are limited to processing relatively narrow band signals
290 and need to use some kind of narrow-band RF front end.</para>
291
292 <para>Another possible solution is an off-the-shelf, high-speed PCI
293 analog-to-digital board. These are available in the 20M sample/sec
294 range, but they are expensive, about the cost of a complete PC. For
295 these high-speed boards, cable modem tuners make reasonable RF front
296 ends.</para>
297
298 <para>Finding none of these alternatives completely satisfactory, we
299 designed the Universal Software Radio Peripheral, or USRP for short.
300 </para>
301
302 </sect1>
303
304 <sect1 id="usrp"><title>The Universal Software Radio Peripheral</title>
305
306 <para>Our preferred hardware solution is the Universal Software Radio
307 Peripheral (USRP). <xref linkend="usrp-block-diagram-fig"/> shows the
308 block diagram of the USRP. The brainchild of Matt Ettus, the USRP is
309 an extremely flexible USB device that connects your PC to the RF
310 world. The USRP consists of a small motherboard containing up to four
311 12-bit 64M sample/sec ADCs, four 14-bit, 128M sample/sec DACs, a
312 million gate-field programmable gate array (FPGA) and a programmable
313 USB 2.0 controller. Each fully populated USRP motherboard supports
314 four daughterboards, two for receive and two for transmit. RF front
315 ends are implemented on the daughterboards. A variety of
316 daughterboards is available to handle different frequency bands. For
317 amateur radio use, low-power daughterboards are available that receive
318 and transmit in the 440 MHz band and the 1.24 GHz band. A receive-only
319 daughterboard based on a cable modem tuner is available that covers
320 the range from 50 MHz to 800 MHz. Daughterboards are designed to be easy
321 to prototype by hand in order to facilitate experimentation.</para>
322
323 <figure id="usrp-block-diagram-fig"><title>Universal Software Radio Peripheral</title>
324 <mediaobject>
325 <imageobject><imagedata fileref="usrp-block-diagram.eps" format="EPS"/></imageobject>
326 <imageobject><imagedata fileref="usrp-block-diagram.png" format="PNG"/></imageobject>
327 <caption><para></para></caption>
328 </mediaobject>
329 </figure>
330
331 <para>The flexibility of the USRP comes from the two programmable components
332 on the board and their interaction with the host-side library. To get
333 a feel for the USRP, let's look at its boot sequence. The USRP itself
334 contains no ROM-based firmware, merely a few bytes that specify the
335 vendor ID (VID), product ID (PID) and revision. When the USRP is
336 plugged in to the USB for the first time, the host-side library sees
337 an unconfigured USRP. It can tell it's unconfigured by reading the
338 VID, PID and revision. The first thing the library code does is
339 download the 8051 code that defines the behavior of the USB peripheral
340 controller. When this code boots, the USRP simulates a USB disconnect
341 and reconnect. When it reconnects, the host sees a different device:
342 the VID, PID and revision are different. The firmware now running
343 defines the USB endpoints, interfaces and command handlers. One of the
344 commands the USB controller now understands is load the FPGA. The
345 library code, after seeing the USRP reconnect as the new device, goes
346 to the next stage of the boot process and downloads the FPGA
347 configuration bitstream.</para>
348
349 <para>FPGAs are generic hardware chips whose behavior is determined by the
350 configuration bitstream that's loaded into them. You can think of the
351 bitstream as object code. The bitstream is the output of compiling a
352 high-level description of the design. In our case, the design is coded
353 in the Verilog hardware description language. This is source code and,
354 like the rest of the code in GNU Radio, is licensed under the GNU
355 General Public License.</para>
356
357 </sect1>
358
359 <sect1 id="fpga"><title>What Goes in the FPGA?</title>
360
361 <para>An FPGA is like a small, massively parallel computer that you design
362 to do exactly what you want. Programming the FPGA takes a bit of
363 skill, and mistakes can fry the board permanently. That said, we
364 provide a standard configuration that is useful for a wide variety of
365 applications.</para>
366
367 <para>Using a good USB host controller, the USRP can sustain 32 MB/sec across
368 the USB. The USB is half-duplex. Based on your needs, you partition
369 the 32 MB/sec between the transmit and the receive directions. In the
370 receive direction, the standard configuration allows you to select the
371 part or parts of the digitized spectrum you're interested in,
372 translate them to baseband and decimate as required. This is exactly
373 equivalent to what's happening in the RF front end, only now we're
374 doing it on digitized samples. The block of code that performs this
375 function is called a digital down converter (<xref linkend="ddc-fig"/>).
376 One advantage of performing this function in the digital domain is we can change the
377 center frequency instantaneously, which is handy for frequency hopping
378 spread spectrum systems.</para>
379
380 <figure id="ddc-fig"><title>Digital Down Converter Block Diagram</title>
381 <mediaobject>
382 <imageobject><imagedata fileref="ddc.eps" format="EPS"/></imageobject>
383 <imageobject><imagedata fileref="ddc.png" format="PNG"/></imageobject>
384 <caption><para></para></caption>
385 </mediaobject>
386 </figure>
387
388
389 <para>In the transmit direction, the exact inverse is performed. The FPGA
390 contains multiple instances of the digital up and down
391 converters. These instances can be connected to the same or different
392 ADCs, depending on your needs. We don't have room here to cover all
393 the theory behind them; see the GNU Radio Wiki for more information.</para>
394
395 </sect1>
396
397 <sect1 id="apps"><title>GNU Radio Applications</title>
398
399 <para>In addition to the examples discussed above, GNU Radio comes with a
400 complete HDTV transmitter and receiver, a spectrum analyzer, an
401 oscilloscope, concurrent multichannel receiver and an ever-growing
402 collection of modulators and demodulators.</para>
403
404 <para>Projects under investigation or in progress include:</para>
405
406 <itemizedlist>
407 <listitem><para>A TiVo equivalent for radio, capable of recording multiple stations simultaneously.</para></listitem>
408 <listitem><para>Time Division Multiple Access (TDMA) waveforms.</para></listitem>
409 <listitem><para>A passive radar system that takes advantage of
410 broadcast TV for its signal source. For those of you with old TVs
411 hooked to antennas, think about the flutter you see when airplanes fly
412 over.</para></listitem>
413 <listitem><para>Radio astronomy.</para></listitem>
414 <listitem><para>TETRA transceiver.</para></listitem>
415 <listitem><para>Digital Radio Mundial (DRM).</para></listitem>
416 <listitem><para>Software GPS.</para></listitem>
417 <listitem><para>Distributed sensor networks.</para></listitem>
418 <listitem><para>Distributed measurement of spectrum utilization.</para></listitem>
419 <listitem><para>Amateur radio transceivers.</para></listitem>
420 <listitem><para>Ad hoc mesh networks.</para></listitem>
421 <listitem><para>RFID detector/reader.</para></listitem>
422 <listitem><para>Multiple input multiple output (MIMO) processing. </para></listitem>
423 </itemizedlist>
424
425 </sect1>
426
427 <sect1 id="politics"><title>Politics</title>
428
429 <para>Every revolution has its political issues. Free software for building
430 radios is troublesome to some people. In the US, we've run into
431 opposition from the Motion Picture Association of America and its
432 attempt with the Broadcast Flag to restrict the kinds of receivers
433 that can be built for over-the-air digital TV.</para>
434
435 <para>The US Federal Communications Commission has issued a Notice of
436 Proposed Rule Making (NPRM) concerning Cognitive Radio
437 Technologies and Software Defined Radios.  Several troublesome
438 issues are raised in the NPRM, including restricting the sale of
439 high-speed digital-to-analog converters, requirements for digital
440 signatures or similar methods to keep unauthorized software out of
441 software radio hardware and new restrictions on radios built for the
442 amateur radio market.</para>
443
444 </sect1>
445
446 <sect1 id="summary"><title>Summary</title>
447
448 <para>Software radio is an exciting field, and GNU Radio provides the tools
449 to start exploring. A deep understanding of software radio requires
450 knowledge from many domains. We're doing our best to lower the
451 barriers to entry.</para>
452 </sect1>
453
454 <!-- FIXME
455 <sect1 id="resource"><title>Resources</title>
456 <para></para>
457 </sect1>
458 -->
459
460 </article>