Title: CS434534: GNU Radio
1GNU Radio
Richard Alimi 3/24/2009
2Outline
- What is GNU Radio?
- Basic Concepts
- Developing Applications
- HW4 Introduction
2
3What is GNU Radio?
- Software toolkit for signalprocessing
- Software radio construction
- Rapid development
- Cognitive radio
- USRP (Universal Software Radio Peripheral)
- Hardware frontend for sendingand receiving
waveforms
4GNU Radio Components
Hardware Frontend
Host Computer
RF Frontend (Daugtherboard)
ADC/DAC and Digital Frontend (USRP)
GNU Radio Software
http//mobiledevices.kom.aau.dk/fileadmin/mobilede
vices/teaching/software_testing/Gnu_radio_lecture.
pdf
5GNU Radio Software
- Opensource software (GPL)
- Don't know how something works? Take a look!
- Existing examples 802.11b, Zigbee, ATSC (HDTV),
OFDM, DBPSK, DQPSK - Features
- Extensive library of signal processing
blocks(C/ and assembly) - Python environment for composing blocks (flow
graph)
6GNU Radio Hardware
- Sends/receives waveforms
- USRP Features
- USB 2.0 interface (480Mbps)
- FPGA (customizable)
- 64Msps Digital to Analog converters (receiving)
- 128Msps Analog to Digital converteres
(transmitting) - Daughterboards for different frequency ranges
- Available Daughterboard
- 400-500Mhz, 800-1000Mhz, 1150-1450Mhz,
1.5-2.1Ghz, 2.3-2.9Ghz
7GNU Radio Hardware Schematic
Host Computer
RX/TXDaughterboard
ADC/DAC
FPGA
USB Interface
http//mobiledevices.kom.aau.dk/fileadmin/mobilede
vices/teaching/software_testing/Gnu_radio_lecture.
pdf
8Outline
- What is GNU Radio?
- Basic Concepts
- Developing Applications
- HW4 Introduction
8
9Basics Blocks
- Signal Processing Block
- Accepts 0 or more input streams
- Produces 0 or more output streams
- Source No input
- noise_source,signal_source,usrp_source
- Sink No outputs
- audio_alsa_sink,usrp_sink
10Basics Data Streams
- Blocks operate on streams of data
1
5
3
4
12
12
3
7
9
11Basics Data Types
- Blocks operate on certain data types
- char, short, int, float, complex
- Vectors
- Input Signature
- Data types for input streams
- Output Signature
- Data types for output streams
Two streamsof float
One streamof complex
12Basics Flow Graph
- Blocks composed as a flow graph
- Data stream flowing from sources to sinks
13Example OFDM Synchronizer
http//gnuradio.org/trac/raw-attachment/wiki/Wirel
ess/gr_ofdm.pdf
14Example Superposition Receiver
15GNU Radio Companion
16GNU Radio Companion (Cont'd)
- GNU Radio Companion
- Design flow graphsgraphically
- Generate runnable code
- Demonstration
- Noisy sine wave (see sinewave.grc)
- Sending numbers via OFDM (see numbers.grc)
- Demos available online (see HW4)
17Outline
- What is GNU Radio?
- Basic Concepts
- Developing Applications
- HW4 Introduction
17
18Development Architecture
PythonApplication developmentFlow graph
construction
- Python
- Application management (e.g., GUI)
- Flow graph construction
- Non-streaming code (e.g., MAC-layer)
- C
- Signal processing blocks
- Certain routines also coded in assembly
CSignal processing blocks
http//mobiledevices.kom.aau.dk/fileadmin/mobilede
vices/teaching/software_testing/Gnu_radio_lecture.
pdf
19Dial Tone Example
!/usr/bin/env python from gnuradio import
gr from gnuradio import audio from
gnuradio.eng_option import eng_option from
optparse import OptionParser class
my_top_block(gr.top_block) def
__init__(self) gr.top_block.__init__(self
) parser OptionParser(option_classeng_
option) parser.add_option("-O",
"--audio-output", type"string", default"",
help"pcm output device
name. E.g., hw0,0") parser.add_option("-
r", "--sample-rate", type"eng_float",
default48000,
help"set sample rate to RATE (48000)")
(options, args) parser.parse_args () if
len(args) ! 0 parser.print_help()
raise SystemExit, 1
sample_rate int(options.sample_rate)
ampl 0.1 src0 gr.sig_source_f
(sample_rate, gr.GR_SIN_WAVE, 350, ampl)
src1 gr.sig_source_f (sample_rate,
gr.GR_SIN_WAVE, 440, ampl) dst
audio.sink (sample_rate, options.audio_output)
self.connect (src0, (dst, 0))
self.connect (src1, (dst, 1)) if __name__
'__main__' try my_top_block().run()
except KeyboardInterrupt pass
20Dial Tone Example (1)
from gnuradio import gr from gnuradio import
audio from gnuradio.eng_option import
eng_option from optparse import OptionParser
Import modules from GNU Radio library
21Dial Tone Example (2)
class my_top_block(gr.top_block) def
__init__(self) gr.top_block.__init__(self
)
Define container for Flow Graph gr.top_block
class maintains thegraph
22Dial Tone Example (3)
Define and parse command-line options
parser OptionParser(option_classeng_op
tion) parser.add_option("-O",
"--audio-output", type"string", default"",
help"pcm output device
name. E.g., hw0,0") parser.add_option("-
r", "--sample-rate", type"eng_float",
default48000,
help"set sample rate to RATE (48000)")
(options, args) parser.parse_args () if
len(args) ! 0 parser.print_help()
raise SystemExit, 1
23Dial Tone Example (4)
Create and connect signal processing blocks
sample_rate int(options.sample_rate)
ampl 0.1 src0 gr.sig_source_f
(sample_rate, gr.GR_SIN_WAVE, 350, ampl)
src1 gr.sig_source_f (sample_rate,
gr.GR_SIN_WAVE, 440, ampl) dst
audio.sink (sample_rate, options.audio_output)
self.connect (src0, (dst, 0))
self.connect (src1, (dst, 1))
24Dial Tone Example (5)
Run the flow graph when the program is executed
if __name__ '__main__' try
my_top_block().run() except
KeyboardInterrupt pass
25Creating Your Own Block
- Basics
- A block is a C class
- Typically derived from gr_block or gr_sync_block
class - Three components
- my_block_xx.h Block definition
- my_block_xx.cc Block implementation
- my_block_xx.i Python bindings (SWIG interface)
26Block Definition
include ltgr_sync_block.hgt class
my_block_cc typedef boostshared_ptrltcs434_my_b
lock_ccgt cs434_my_block_cc_sptr cs434_my_block_c
c_sptr cs434_make_my_block_cc() class
my_block_cc public gr_sync_block private uns
igned int d_count friend cs434_my_block_cc_sptr
cs434_make_my_block_cc() cs434_my_block_cc()
public int work(int noutput_items,
gr_vector_const_void_star input_items,
gr_vector_void_star output_items)
Create instances of block
Method for processing input streams andproducing
output streams
27Block Implementation (1)
ifdef HAVE_CONFIG_H include "config.h" endif
include ltmy_block_cc.hgt include
ltgr_io_signature.hgt cs434_my_block_cc_sptr
cs434_make_my_block_cc() return
cs434_my_block_cc_sptr(new cs434_my_block_cc())
cs434_hw4_sample_block_cccs434_hw4_sample_bloc
k_cc() gr_sync_block("my_block_cc", gr_make_
io_signature(1, 1, sizeof(gr_complex)), gr_make
_io_signature(1, 1, sizeof(gr_complex))),
d_count(0)
Helper method to create block
Define input and output signatures
28Block Implementation (2)
int cs434_my_block_ccwork(int
noutput_items, gr_vector_const_void_star
input_items, gr_vector_void_star
output_items) const gr_complex in (const
gr_complex)input_items0 gr_complex out
(gr_complex)output_items0 memcpy(out, in,
sizeof(out) noutput_items) for (int i 0
i lt noutput_items i) fprintf(stderr,
"u\tlt.6f, .6fgt\n", d_count, ini.real(),
ini.imag()) return noutput_items
Copy input stream to output stream
Echo samples stderr
Return number of items processed
29SWIG Interface
Condensed copy of block definition (in header
file)
GR_SWIG_BLOCK_MAGIC(cs434, my_block_cc) cs434_my
_block_cc_sptr cs434_make_my_block_cc() class
cs434_my_block_cc public gr_sync_block private
cs434_my_block_cc()
30Outline
- What is GNU Radio?
- Basic Concepts
- Developing Applications
- HW4 Introduction
30
31HW4 Overview
- Implement MAC layer for a wireless device
- Link-layer header
- Carrier-sensing and backoff
- Link-layer acknowledgments
- Template code at
- https//www-net.cs.yale.edu/svn/courses/cs434/spri
ng09/hw4/gr-cs434-hw4/
32Useful Links
- Homepage (download, more links, etc)
- http//gnuradio.org/trac/
- More comprehensive tutorial
- http//gnuradio.org/trac/wiki/Tutorials/WritePytho
nApplications - Available Signal Processing Blocks
- http//gnuradio.org/doc/doxygen/hierarchy.html
- GNU Radio Mailing List Archives
- http//www.gnu.org/software/gnuradio/mailinglists.
html - CGRAN 3rd Party GNU Radio Apps
- https//www.cgran.org/
- OFDM Implementation Presentation
- http//gnuradio.org/trac/wiki/Wireless