CS434/534: GNU Radio

Download Report

Transcript CS434/534: GNU Radio

GNU Radio
Outline
 What is GNU Radio?
 Basic Concepts
 Developing Applications
2
What is GNU Radio?
 Software toolkit for signal
processing

Software radio construction

Rapid development
 USRP (Universal Software Radio Peripheral)

Hardware frontend for sending
and receiving waveforms
GNU Radio Components
Hardware Frontend
RF Frontend
(Daugtherboard)
ADC/DAC and
Digital Frontend
(USRP)
Host Computer
GNU Radio
Software
http://mobiledevices.kom.aau.dk/fileadmin/mobiledevices/teaching/software_testing/Gnu_radio_lecture.pdf
GNU Radio Software
 Opensource software (GPL)


Don't know how something works? Take a look!
Existing examples: 802.11b(Wi-Fi), ATSC (HDTV), OFDM,
DBPSK, DQPSK
 Features


Extensive library of signal processing blocks
(C++/ and assembly)
Python environment for composing blocks (flow graph)
GNU Radio Hardware
 Sends/receives waveforms
 USRP Features

USB 2.0 interface (480Mbps)

FPGA (customizable)

64Msps Digital to Analog converters

128Msps Analog to Digital converteres

Daughterboards for different frequency ranges
 Available Daughterboard

400-500Mhz, 800-1000Mhz, 1150-1450Mhz, 1.5-2.1Ghz,
2.3-2.9Ghz
GNU Radio Hardware Schematic
Host Computer
RX/TX
Daughterboar
d
ADC/DAC
FPGA
USB
Interface
http://mobiledevices.kom.aau.dk/fileadmin/mobiledevices/teaching/software_testing/Gnu_radio_lecture.pdf
Outline
 What is GNU Radio?
 Basic Concepts
 Developing Applications
8
Basics: 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
Basics: Data Streams
 Blocks operate on streams of data
1
5
3
4
3
7
9
12
12
Basics: Data Types
 Blocks operate on
certain data types


char, short, int,
float, complex
Vectors
Two streams
of float
 Input Signature:

Data types for input
streams
 Output Signature:

Data types for output
streams
One stream
of complex
Basics: Flow Graph
 Blocks composed as a flow graph

Data stream flowing from sources to sinks
Example: OFDM Synchronizer
http://gnuradio.org/trac/raw-attachment/wiki/Wireless/gr_ofdm.pdf
GNU Radio Companion
GNU Radio Companion (Cont'd)
 GNU Radio Companion


Design flow graphs
graphically
Generate runnable code
 Demonstration
Outline
 What is GNU Radio?
 Basic Concepts
 Developing Applications
16
Development Architecture
 Python



Application management
(e.g., GUI)

Application development
Flow graph construction
Flow graph construction
Non-streaming code (e.g.,
MAC-layer)
 C++

Python
C++
Signal processing blocks
Signal processing blocks
Certain routines also
coded in assembly
Why is the hybrid
structure?
http://mobiledevices.kom.aau.dk/fileadmin/mobiledevices/teaching/software_testing/Gnu_radio_lecture.pdf
Dial Tone Example
#!/usr/bin/env python
from
from
from
from
gnuradio import gr
gnuradio import audio
gnuradio.eng_option import eng_option
optparse import OptionParser
class my_top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
parser = OptionParser(option_class=eng_option)
parser.add_option("-O", "--audio-output", type="string", default="",
help="pcm output device name. E.g., hw:0,0")
parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
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
Dial Tone Example (1)
from
from
from
from
gnuradio import gr
gnuradio import audio
gnuradio.eng_option import eng_option
optparse import OptionParser
Import modules from GNU Radio library
Dial 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 the
graph
Dial Tone Example (3)
Define and parse command-line options
parser = OptionParser(option_class=eng_option)
parser.add_option("-O", "--audio-output", type="string", default="",
help="pcm output device name. E.g., hw:0,0")
parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
help="set sample rate to RATE (48000)")
(options, args) = parser.parse_args ()
if len(args) != 0:
parser.print_help()
raise SystemExit, 1
Dial 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))
Dial Tone Example (5)
Run the flow graph when the program is executed
if __name__ == '__main__':
try:
my_top_block().run()
except KeyboardInterrupt:
pass
Useful Links
 Homepage (download, more links, etc)

http://gnuradio.org/trac/
 More comprehensive tutorial

http://gnuradio.org/trac/wiki/Tutorials/WritePythonApplications
 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
Backup
Creating 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)
Block Definition
#include <gr_sync_block.h>
class my_block_cc;
typedef boost::shared_ptr<cs434_my_block_cc> cs434_my_block_cc_sptr;
cs434_my_block_cc_sptr cs434_make_my_block_cc();
Create instances of block
class my_block_cc : public gr_sync_block
{
private:
unsigned 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);
};
Method for processing
input streams and
producing output streams
Block Implementation (1)
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <my_block_cc.h>
#include <gr_io_signature.h>
cs434_my_block_cc_sptr cs434_make_my_block_cc()
{
return cs434_my_block_cc_sptr(new cs434_my_block_cc());
}
cs434_my_block_cc::cs434_my_block_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
Block Implementation (2)
int cs434_my_block_cc::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const gr_complex* in = (const gr_complex*)input_items[0];
gr_complex* out = (gr_complex*)output_items[0];
memcpy(out, in, sizeof(*out) * noutput_items);
for (int i = 0; i < noutput_items; ++i)
fprintf(stderr, "%u\t<%.6f, %.6f>\n",
d_count++, in[i].real(), in[i].imag());
return noutput_items;
}
Copy input stream
to output stream
Echo samples
stderr
Return number
of items processed
SWIG Interface
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();
};
Condensed copy of
block definition
(in header file)
Outline
 What is GNU Radio?
 Basic Concepts
 Developing Applications
 HW2 Introduction
31
HW2 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/spring09/hw4/gr-cs434-hw4/