1 / 79
Download Materials
2 / 79
Prologue
Prologue
The fundamental problem of communication is that of reproducing at one point either exactly or approximately a message selected at another point. - Claude Shannon, A Mathematical Theory of Communication
3 / 79
Prologue
Long live the physical layer... Innovation these days comes from the use of the PHY layer. Flexibility and recongurability are key. Rapidly prototype and experiment to prove new ideas. Communications is still very hard.
4 / 79
Prologue
Rapid prototyping of PHY layer systems. Analysis and development of signals. Educational material to teach the workings of various comms. Expose engineering techniques and tricks.
5 / 79
Prologue
Provides... 1 Basic data structure, the ow graph, to build streaming signal processing systems.
2 3 4 5 6
Connections to and from hardware and software. A set of I/O and signal processing blocks. A framework of programming tools and examples. A community of experts and enthusiasts. Open source licensing.
6 / 79
Prologue
Tools and Manuals Project website: gnuradio.org Download source: gnuradio.org/redmine/projects/gnuradio/wiki/Download Online C++ Manual: gnuradio.org/doc/doxygen/ Online Python Manual: gnuradio.org/doc/sphinx/ My webite for news and analysis: www.trondeau.com
7 / 79
Prologue
Community
Active developer community producing examples. Large participation on our mailing list. The Complimentary GNU Radio Archive Network (CGRAN). Growing list of projects on github. Large participation at conferenes like the Wireless Innovation Forums WinnComm11. Impressive turnout and participation at the 2011 GNU Radio Conference. GNU Radio Conference 2012 comming soon.
8 / 79
Prologue
Programming Preview
s e l f . s r c = g r . n o i s e s o u r c e c ( g r . GR GAUSSIAN, amp ) s e l f . f l t = f i l t e r . f i r f i l t e r c c f (1 , taps ) s e l f . sn k = g r . n u l l s i n k ( g r . s i z e o f g r c o m p l e x ) s e l f . connect ( s e l f . src , if name == m a i n tb = my topblock ( ) tb . s t a r t ( ) tb . wait ( ) : self . flt , s e l f . sn k )
9 / 79
10 / 79
11 / 79
12 / 79
13 / 79
14 / 79
15 / 79
The dynamic scheduler passes chunks of items between signal processing blocks.
16 / 79
17 / 79
Software Structure
Programming Model
All low level work and signal processing is done in C++. Wrapped into Python for use as a scripting language. GNU Radio Companion: a graphical interface to build GNU Radio applications that sits on top of Python.
18 / 79
Software Structure
Software Structure
Graphical Interfaces gr-qtgui gr-wxgui Hardware Interfaces gr-audio gr-comedi gr-fcd gr-shd gr-uhd
20 / 79
21 / 79
Classic Problem
22 / 79
Classic Problem
23 / 79
24 / 79
25 / 79
26 / 79
1.0
0.5
0.0
0.5
1.0
1.5 0
20
40
60
80
100
27 / 79
28 / 79
29 / 79
30 / 79
31 / 79
32 / 79
Common Filters
Standard Types Low Pass High Pass Band Pass Band Reject (Notch) Nyquist / Gaussian / pulse shapping Standard Implementations Tapered Windowing of Sinc (Hamming, Hann, Blackman-harris, etc.) Equiripple (via Parks-McClellen algorithm)
33 / 79
Demonstration
gr lter design
34 / 79
Convolution in Time Multiplication in Frequency F (t x ) = F (t ) F (x ) t x = F 1 (F (t ) F (x )) F is the Fourier transform operator. And we know an FFT can be done with complexity O(N log(N ))
35 / 79
2.5
2.0
1.5
1.0
0.5
0.0 0
100
200
Number of Taps
300
400
500
36 / 79
37 / 79
Generate white noise Uses FFT lter with taps in variable taps Taps dened using bw variable adjustable at runtime
Tom Rondeau tom@trondeau.com GNU Radio Tutorial May 27, 2012 38 / 79
Downsampling (decimation)
Upsampling (interpolation)
39 / 79
40 / 79
41 / 79
42 / 79
44 / 79
45 / 79
46 / 79
Python Programming
How to construct a basic application Create a top block. Instantiate the blocks for the app. Connect blocks to for a graph. Start and run the graph.
47 / 79
s e l f . s r c = g r . n o i s e s o u r c e c ( g r . GR GAUSSIAN, amp ) s e l f . f l t = f i l t e r . f i r f i l t e r c c f (1 , taps ) s e l f . sn k = g r . n u l l s i n k ( g r . s i z e o f g r c o m p l e x ) s e l f . connect ( s e l f . src , if name == m a i n tb = my topblock ( ) tb . s t a r t ( ) tb . wait ( ) : self . flt , s e l f . sn k )
48 / 79
49 / 79
50 / 79
51 / 79
and w a i t ( )
52 / 79
s e l f . s r c = g r . n o i s e s o u r c e c ( g r . GR GAUSSIAN, amp ) s e l f . f l t = f i l t e r . f i r f i l t e r c c f (1 , taps ) s e l f . sn k = g r . n u l l s i n k ( g r . s i z e o f g r c o m p l e x ) s e l f . connect ( s e l f . src , if name == m a i n tb = my topblock ( ) tb . s t a r t ( ) tb . wait ( ) : self . flt , s e l f . sn k )
53 / 79
54 / 79
Programming Practices
Programming Practices
New model as of GNU Radio v3.7 We will discuss building component foo. We will develop the block bar. These will be accessible under the namespace gr::foo.
55 / 79
Programming Practices
Programming Practices
Layered API
56 / 79
Programming Practices
Programming Practices
Layered API: Python Wrapper through SWIG
57 / 79
Programming Practices
Programming Practices
Layered API: GNU Radio Companion GUI
58 / 79
Programming Practices
Programming Practices
Layered API: Direct C++ Applications
59 / 79
Programming Practices
Component Structure
Each component foo contains: apps any full-edged applications specic to the component doc place for extra documentation, including Doxygen .dox les to describe the component. examples example code to demonstrate usage of component blocks and algorithms. grc GNU Radio Companion les and block tree. include public header les include/foo actual location of public header les. Headers in included using #include <foo/bar.h>. lib location of the implementation source and private header les (bar impl.h and bar impl.cc, generally). swig location of SWIG interface le. We use a simplied structure that only includes the public header le for SWIGing.
Tom Rondeau tom@trondeau.com GNU Radio Tutorial May 27, 2012 60 / 79
Programming Practices
Component Structure
Private Implementation, Public Header The API of the block is dened in a public header le in include/foo/bar.h. Only methods dened in the public header le are accessible through the library and through the Python interface to the block. The factory make function is a member of the public class. It will instantiate a private implementation of the block. A block can have more than one make function. Multiple private implementations can be dened for a block base on architecture, platform, experiments, etc.
61 / 79
Programming Practices
Component Structure
Private Implementation Specics Implementation les contain a header and a source as lib/bar impl.h and lib/bar impl.cc Creates a private class that inherits from the public class. Implements the public make function. When multiple implementations, replace the impl with a more appropriate sux. The blocks that implement FFTs (like t vcc tw) are good examples by using FFTW.
62 / 79
Programming Practices
Component Structure
Public Header File: foo.h
#i f n d e f INCLUDED FOO BAR H #d e f i n e INCLUDED FOO BAR H #i n c l u d e < f o o / a p i . h> #i n c l u d e < g r s y n c b l o c k . h> namespace g r { namespace f o o { c l a s s FOO API b ar : v i r t u a l p u b l i c g r s y n c b l o c k { public : t y p e d e f b o o s t : : s h a r e d p t r <bar > s p t r ; / ! Manual d o c u m e n t a t i o n . \ param v a r e x p l a n a t i o n o f a r g u m e n t v a r . / s t a t i c FOO API s p t r make ( d t yp e v a r ) ; v i r t u a l v o i d s e t v a r ( d t yp e v a r ) = 0 ; v i r t u a l d t yp e v a r ( ) = 0 ; }; } / n am espace f o o / } / n am espace g r / #e n d i f / INCLUDED FOO BAR H /
63 / 79
Programming Practices
Component Structure
Private Header File: foo impl.h
#i f n d e f INCLUDED FOO BAR IMPL H #d e f i n e INCLUDED FOO BAR IMPL H #i n c l u d e < f o o / b ar . h> namespace g r { namespace f o o { c l a s s FOO API b a r i m p l { private : d t yp e d v a r ;
p u b l i c b ar
public : b a r i m p l ( d t yp e v a r ) ; bar impl ( ) ; v o i d s e t v a r ( d t yp e v a r ) ; d t yp e v a r ( ) ; i n t work ( i n t n o u t p u t i t e m s , g r v e c t o r c o n s t v o i d s t a r &i n p u t i t e m s , g r v e c t o r v o i d s t a r &o u t p u t i t e m s ) ; }; } / n am espace f o o / } / n am espace g r / #e n d i f / INCLUDED FOO BAR H /
64 / 79
Programming Practices
Component Structure
Private Source File: foo impl.cc
#i f d e f HAVE CONFIG H #i n c l u d e c o n f i g . h #e n d i f #i n c l u d e b a r i m p l . h #i n c l u d e < g r i o s i g n a t u r e . h> namespace g r { namespace f o o { b ar : : s p t r b ar : : make ( d t yp e v a r ) { r e t u r n g n u r a d i o : : g e t i n i t i a l s p t r ( new b a r i m p l ( v a r ) ) ; } b a r i m p l : : b a r i m p l ( d t yp e v a r ) : g r s y n c b l o c k ( b ar , gr make io signature (1 , gr make io signature (1 , { s e t v a r ( var ) ; } bar impl : : bar impl ( ) { // any c l e a n u p c o d e }
1, 1,
here
65 / 79
Programming Practices
Component Structure
66 / 79
Programming Practices
Component Structure
67 / 79
Programming Practices
Component Structure
Exporting to Python through SWIG: swig/foo swig.i
#d e f i n e FOO API %i n c l u d e gnuradio . i
// l o a d g e n e r a t e d p y t h o n d o c s t r i n g s %i n c l u d e f o o s w i g d o c . i %{ #i n c l u d e %} %i n c l u d e f o o / b ar . h
f o o / b ar . h b ar ) ;
NOTE We are using GR SWIG BLOCK MAGIC2 for the denitions now. When we are completely converted over, this will be replaced by GR SWIG BLOCK MAGIC.
Tom Rondeau tom@trondeau.com GNU Radio Tutorial May 27, 2012 68 / 79
Programming Practices
Block Methods
Various Important Block Properties noutput items The number of items the output buer can handle. consume The number of input items processed. produce The number of output items produced. rates Determines the input/output ratio (synch, decimation, interpolation, or other).
69 / 79
Programming Practices
Read and write to buers. Blocks are told how much they can read and write.
70 / 79
Programming Practices
Work Functions
gr sync block (see: digital costas loop) noutput items: number available on input and output. return call tells scheduler to produce and consume that amount.
consume all(noutput items); produce all(noutput items); return WORK CALLED PRODUCE;
int f o o b a r : : work ( i n t n o u t p u t i t e m s , g r v e c t o r c o n s t v o i d s t a r &i n p u t i t e m s , g r v e c t o r v o i d s t a r &o u t p u t i t e m s ) { con st gr complex i n = ( gr complex ) i n p u t i t e m s [ 0 ] ; g r c o m p l e x ou t = ( g r c o m p l e x ) o u t p u t i t e m s [ 0 ] ; f o r ( int i = 0; i < noutput items ; ou t [ i ] = f u n c t i o n ( i n [ i ] ) ; } return noutput items ; } i ++) {
71 / 79
Programming Practices
Work Functions
gr sync decimator (see: goertzel fc impl.cc) noutput items: number available to output. return call tells scheduler to produce noutput items/decimation.
consume all(noutput items*decimation); produce all(noutput items);
int f o o b a r : : work ( i n t n o u t p u t i t e m s , g r v e c t o r c o n s t v o i d s t a r &i n p u t i t e m s , g r v e c t o r v o i d s t a r &o u t p u t i t e m s ) { con st gr complex i n = ( gr complex ) i n p u t i t e m s [ 0 ] ; g r c o m p l e x ou t = ( g r c o m p l e x ) o u t p u t i t e m s [ 0 ] ; int j = 0; f o r ( i n t i = 0 ; i < n o u t p u t i t e m s ; i ++) { ou t [ i ] = f u n c t i o n ( i n [ j > ( j + d e c i m a t i o n ( ) ) ] ) ; j += d e c i m a t i o n ( ) ; } return noutput items ; }
72 / 79
Programming Practices
Work Functions
gr sync interpolator (see: gr pfb synthesizer ccf) noutput items: number available to output. return call tells scheduler to consume noutput items/interpolation.
consume all(noutput items/interpolation); produce all(noutput items);
int f o o b a r : : work ( i n t n o u t p u t i t e m s , g r v e c t o r c o n s t v o i d s t a r &i n p u t i t e m s , g r v e c t o r v o i d s t a r &o u t p u t i t e m s ) { con st gr complex i n = ( gr complex ) i n p u t i t e m s [ 0 ] ; g r c o m p l e x ou t = ( g r c o m p l e x ) o u t p u t i t e m s [ 0 ] ; int j = 0; f o r ( i n t i = 0 ; i < n o u t p u t i t e m s / i n t e r p o l a t i o n ; i ++) { ou t [ j > ( j + i n t e r p o l a t i o n ( ) ) ] = f u n c t i o n ( i n [ i ] ) ; j += i n t e r p o p a t i o n ( ) ; } return noutput items ; }
73 / 79
Programming Practices
Work Functions
gr block (see: gr pfb arb resampler ccf) No set relationship of input to output
consume(i, M); produce(o, N); return WORK CALLED PRODUCE;
int f o o b a r : : gen eral work ( i n t noutput items , g r v e c t o r i n t &n i n p u t i t e m s , g r v e c t o r c o n s t v o i d s t a r &i n p u t i t e m s , g r v e c t o r v o i d s t a r &o u t p u t i t e m s ) { con st gr complex i n = ( gr complex ) i n p u t i t e m s [ 0 ] ; g r c o m p l e x ou t = ( g r c o m p l e x ) o u t p u t i t e m s [ 0 ] ; f o r ( i n t i = 0 ; i < [ c o n d i t i o n ] ; i ++) { ou t [ x ] = f u n c t i o n ( i n [ y ] ) ; } f o r ( i n t i = 0 ; i < i n p u t i t e m s . s i z e ( ) ; i ++) { consume ( i , n i t e m s [ i ] ) ; } r e t u r n n o u t p u t i t e m s ; // o r p r o d u c e ( o , M) f o r e a c h o u t p u t }
74 / 79
Case Studies
Case Study 1
gr quadrature demod cf < v3.7: gnuradio-core/src/lib/general/ v3.7: gr-analog/ Good example of a gr sync block. Uses set history to ensure we can look behind us. y [i ] = g tan1 (x [i ]x [i 1]) Always produces and consumes noutput items during work.
75 / 79
Case Studies
Case Study 2
digital costas loop cc Found in: gr-digital/ A sync block with a loop. Inherits from gri control loop; implements:
advance loop from current error estimate. sets and gets for all control values (including: damping factor, loop bandwidth, alpha and beta gains, current frequency and phase estimates).
Can be used with BPSK, QPSK, 8PSK. Two loops if second output of frequency estimate is used.
Done for performance reasons: reduce branches in inner loop.
76 / 79
77 / 79
What We Covered
What We Covered Basic understanding of what GNU Radio is and is for. What the GNU Radio software package consists of. Some fundamental components and blocks. How to deal with ltering and sample rates. Building GNU Radio apps in Python. Basics of programming new blocks.
78 / 79
GRCon12
GNU Radio Conference 2012 September 24 - 27 Sheraton Gateway Hotel Atlanta Airport More info: www.trondeau.com/gnu-radio-conference-2012 Follows on the success of GRCon11 Hosted by UPenns Computer and Information Systems dept. Over 50 participants. Three days of talks and discussions. Huge amount of energy and excitement. More info: www.trondeau.com/gnu-radio-conference-2011
79 / 79