Exposing GNU Radio: Developing and Debugging
GNU Radio Maintainer
May 27, 2012
GNU Radio Tutorial
May 27, 2012
1 / 79
Download Materials
http://www.trondeau.com/gr-tutorial Presentation PDF Case Study materials
GNU Radio apps to run examples. Links to source code for analysis. Data le for rst case study. Images of expected output. Exercises.
GNU Radio Tutorial
May 27, 2012
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
GNU Radio Tutorial
May 27, 2012
3 / 79
Prologue
Software Dened Radio
THE PHYSICAL LAYER IS DEAD!
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.
GNU Radio Tutorial
May 27, 2012
4 / 79
Prologue
Software Dened Radio
GNU Radio helps us realize this
Communications Building Blocks
1 2 3 4
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.
GNU Radio Tutorial
May 27, 2012
5 / 79
Prologue
Software Dened Radio
How GNU Radio Helps
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.
GNU Radio Tutorial
May 27, 2012
6 / 79
Prologue
GNU Radio Information
Information Sources for GNU Radio
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
GNU Radio Tutorial
May 27, 2012
7 / 79
Prologue
GNU Radio Information
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.
GNU Radio Tutorial
May 27, 2012
8 / 79
Prologue
Programming Preview
Basics of Python Programming
./example basics.py
fr om g n u r a d i o i m p o r t gr , filter c l a s s my topblock ( gr . t o p b l o c k ) : def init ( self ): gr . t o p b l o c k . init ( self ) amp = 1 taps = f i l t e r . f i r d e s . low pass (1 , 1, 0.1 , 0.01)
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 )
GNU Radio Tutorial
May 27, 2012
9 / 79
Chapter the First: Scheduling
Chapter the First: Scheduling
Oh dear! Oh dear! I shall be late! - Lewis Carroll, Alices Adventures in Wonderland
GNU Radio Tutorial
May 27, 2012
10 / 79
Chapter the First: Scheduling
The Flow Graph
GNU Radio Fundamentals
A real-time, streaming signal processing platform.
GNU Radio Tutorial
May 27, 2012
11 / 79
Chapter the First: Scheduling
The Flow Graph
Fundamentals: The Flowgraph
GNU Radio Tutorial
May 27, 2012
12 / 79
Chapter the First: Scheduling
The Flow Graph
Fundamentals: The Flowgraph
GNU Radio Tutorial
May 27, 2012
13 / 79
Chapter the First: Scheduling
The Flow Graph
Fundamentals: The Flowgraph
GNU Radio Tutorial
May 27, 2012
14 / 79
Chapter the First: Scheduling
The Flow Graph
Fundamentals: The Flowgraph
GNU Radio Tutorial
May 27, 2012
15 / 79
Chapter the First: Scheduling
The Flow Graph
Fundamentals: Dynamic Scheduling
The dynamic scheduler passes chunks of items between signal processing blocks.
GNU Radio Tutorial
May 27, 2012
16 / 79
Chapter the First: Scheduling
The Flow Graph
Fundamentals: I/O Signatures
GNU Radio Tutorial
May 27, 2012
17 / 79
Chapter the First: Scheduling
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.
GNU Radio Tutorial
May 27, 2012
18 / 79
Chapter the First: Scheduling
Software Structure
GNU Radio Processing Blocks
Basic mathematical and logical operations. Large library of lter design and processing algorithms. I/O support for many domains. Type conversions. Analog (AM/FM) processing techniques. Synchronization algorithms (PLL, Costas loop, etc.). Data and ow graph management blocks. Narrowband and OFDM digital modulation capabilities. Various audio vocoders. Trellis, convolutional coding, and similar algorithm support. Graphical visualization tools (oscilloscopes, PSD, and waterfall viewers). Many examples for all dierent areas of signal processing.
Tom Rondeau
[email protected] GNU Radio Tutorial May 27, 2012 19 / 79
Chapter the First: Scheduling
Software Structure
GNU Radio Top-Level Components (as of v3.7)
Fundamentals gr-analog gr-block gr-digital gr-fec gr-t gr-lter gr-runtime gr-trellis gr-vocoder gr-wavelet
Graphical Interfaces gr-qtgui gr-wxgui Hardware Interfaces gr-audio gr-comedi gr-fcd gr-shd gr-uhd
GNU Radio Tutorial
May 27, 2012
20 / 79
Chapter the Second: Graphical User Interfaces
Chapter the Second: Graphical User Interfaces
Here, then, we have, in the very beginning, the groundwork for something more than a mere guess. - Edgar Allan Poe, The Gold Bug
GNU Radio Tutorial
May 27, 2012
21 / 79
Chapter the Second: Graphical User Interfaces
Classic Problem
I have an app. It doesnt work. Why?
GNU Radio Tutorial
May 27, 2012
22 / 79
Chapter the Second: Graphical User Interfaces
Classic Problem
Visualizing the signal at dierent points can illuminate the problem.
GNU Radio Tutorial
May 27, 2012
23 / 79
Chapter the Second: Graphical User Interfaces
Example: example gui.grc
A graph that does something
GNU Radio Tutorial
May 27, 2012
24 / 79
Chapter the Second: Graphical User Interfaces
Example: example gui.grc
Visualizing the state with les
GNU Radio Tutorial
May 27, 2012
25 / 79
Chapter the Second: Graphical User Interfaces
Example: example gui.grc
Read in the data with your favorite language/program
import sci p y , pylab # Read i n t h e d a t a i n t o t w o v a r i a b l e s = s c i p y . f r o m f i l e ( open ( i n p u t . 3 2 f c , r ) , in data d t yp e=s c i p y . com p l ex64 , c o u n t =10000) o u t d a t a = s c i p y . f r o m f i l e ( open ( o u t p u t . 3 2 f c , r ) , d t yp e=s c i p y . com p l ex64 , c o u n t =10000) # Do some d a t a manipulations here
# Plot the data f i g = p y l a b . f i g u r e ( 1 , f i g s i z e = ( 1 4 , 8 ) , f a c e c o l o r = w ) sp = f i g . a d d s u b p l o t ( 1 , 1 , 1 ) sp . p l o t ( i n d a t a . r e a l [ 1 2 0 0 : 1 3 0 0 ] , bo , l i n e w i d t h =2) sp . p l o t ( o u t d a t a . r e a l [ 1 2 0 0 : 1 3 0 0 ] , r s , l i n e w i d t h =2) p y l a b . show ( )
GNU Radio Tutorial
May 27, 2012
26 / 79
Chapter the Second: Graphical User Interfaces
Example: example gui.grc
Pythons Pylab output
1.5
1.0
0.5
0.0
0.5
1.0
1.5 0
20
40
60
80
100
GNU Radio Tutorial
May 27, 2012
27 / 79
Chapter the Second: Graphical User Interfaces
Example: example gui.grc
Realtime Visualization: QT-GUI
GNU Radio Tutorial
May 27, 2012
28 / 79
Chapter the Second: Graphical User Interfaces
Example: example gui.grc
QT-GUI output from rst (Input) sink
GNU Radio Tutorial
May 27, 2012
29 / 79
Chapter the Second: Graphical User Interfaces
Example: example gui.grc
QT-GUI output from second (Output) sink
GNU Radio Tutorial
May 27, 2012
30 / 79
Chapter the Third: Filtering
Chapter the Third: Filtering
The need for lters intrudes on any thought experiment about the wonders of abundant information. - James Gleik, The Information
GNU Radio Tutorial
May 27, 2012
31 / 79
Chapter the Third: Filtering
FIR Filter Basics
FIR Filters = Convolution
Python Example ./convolution.py ./convolve lter.py Convolution: y [i ] = tN n1 x [i + n]
GNU Radio Tutorial
May 27, 2012
32 / 79
Chapter the Third: Filtering
FIR Filter Basics
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)
GNU Radio Tutorial
May 27, 2012
33 / 79
Chapter the Third: Filtering
FIR Filter Basics
Demonstration
gr lter design
GNU Radio Tutorial
May 27, 2012
34 / 79
Chapter the Third: Filtering
FIR Filter Basics
Time vs. Frequency Domain
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 ))
GNU Radio Tutorial
May 27, 2012
35 / 79
Chapter the Third: Filtering
FIR Filter Basics
How Complexity Helps
The FFT method quickly takes over
3.0
Time to Process 1e+07 Complex Samples (sec)
2.5
2.0
1.5
1.0
0.5
0.0 0
100
200
Number of Taps
300
400
500
GNU Radio Tutorial
May 27, 2012
36 / 79
Chapter the Third: Filtering
FFT Filter Demo
Using rdes to create a lter
gr.rdes.low pass 2 (after v3.7: lter.rdes.low pass 2) gr.firdes.low_pass_2(gain, sample rate, bandwidth, transition band, stopband attenuation (dB)) gain: constant multiplication coecient to all taps sample rate: sample rate of lter in samples/second bandwidth: end of passband (3 dB point); units relative to sample rate transition band: distance between end of passband and start of stopband; units relative to sample rate stopband attenuation: attenuation (in dB) in stopband
GNU Radio Tutorial
May 27, 2012
37 / 79
Chapter the Third: Filtering
FFT Filter Demo
GRC Example Environment (example t lter.grc)
Update lter taps to adjust bandwidth
Generate white noise Uses FFT lter with taps in variable taps Taps dened using bw variable adjustable at runtime
Tom Rondeau [email protected] GNU Radio Tutorial May 27, 2012 38 / 79
Chapter the Third: Filtering
Changing Sample Rate
Rate Change is Fundamental to Software Radio
Downsampling (decimation)
Upsampling (interpolation)
GNU Radio Tutorial
May 27, 2012
39 / 79
Chapter the Third: Filtering
Changing Sample Rate
Downsampling aliases outside bands
The Nyquist Zones now fall into the new passband
GNU Radio Tutorial
May 27, 2012
40 / 79
Chapter the Third: Filtering
Changing Sample Rate
Upsampling creates images
GNU Radio Tutorial
May 27, 2012
41 / 79
Chapter the Third: Filtering
Changing Sample Rate
Always Filter when Changing Rates
Filter Signals Before Downsampling
Upsample and then Remove Images
GNU Radio Tutorial
May 27, 2012
42 / 79
Chapter the Third: Filtering
Changing Sample Rate
Rate Changing GNU Radio Blocks
Downsampling r lter ccc, ccf, fcc, f, fsf, scc t lter ccc, f pfb decimator ccf pfb channelizer ccf Upsampling interp r lter ccc, ccf, fcc, f, fsf, scc pfb interpolator ccf pfb synthesize ccf Resampling pfb arb resampler ccf, f fractional interpolator cc,
Tom Rondeau
[email protected] GNU Radio Tutorial May 27, 2012 43 / 79
Chapter the Fifth: Programming Blocks
Chapter the Fourth: Programming Blocks
Computers are good at following instructions, but not at reading your mind. - Donald Knuth
GNU Radio Tutorial
May 27, 2012
44 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
The Flowgraph Structure, Revisited
GNU Radio Tutorial
May 27, 2012
45 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
Input and Output Buers of a Streaming System
GNU Radio Tutorial
May 27, 2012
46 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
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.
GNU Radio Tutorial
May 27, 2012
47 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
The Full Program
./example basics.py
fr om g n u r a d i o i m p o r t gr , filter c l a s s my topblock ( gr . t o p b l o c k ) : def init ( self ): gr . t o p b l o c k . init ( self ) amp = 1 taps = f i l t e r . f i r d e s . low pass (1 , 1, 0.1 , 0.01)
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 )
GNU Radio Tutorial
May 27, 2012
48 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
Create a top block
A class that inherits from gr.top block
fr om g n u r a d i o i m p o r t gr , filter c l a s s my topblock ( gr . t o p b l o c k ) : def init ( self ): gr . t o p b l o c k . init ( self )
GNU Radio Tutorial
May 27, 2012
49 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
Instantiate the blocks for the app
Using GR block constructors
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 )
GNU Radio Tutorial
May 27, 2012
50 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
Connect blocks to for a graph
self is a top block with a connect member
s e l f . connect ( s e l f . src , s e l f . connect ( s e l f . f l t , self . flt ) s e l f . sn k )
GNU Radio Tutorial
May 27, 2012
51 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
Start and run the graph
Use start() or run() from a function
if name == m a i n : tb = my topblock ( ) tb . s t a r t ( ) tb . wait ( ) #t b . r u n ( ) # r u n b o t h s t a r t ( )
and w a i t ( )
GNU Radio Tutorial
May 27, 2012
52 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
Another Look at the Full Program
./example basics.py
fr om g n u r a d i o i m p o r t gr , filter c l a s s my topblock ( gr . t o p b l o c k ) : def init ( self ): gr . t o p b l o c k . init ( self ) amp = 1 taps = f i l t e r . f i r d e s . low pass (1 , 1, 0.1 , 0.01)
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 )
GNU Radio Tutorial
May 27, 2012
53 / 79
Chapter the Fifth: Programming Blocks
Programming GNU Radio Apps
Visualizing the Program
example python prog.grc
GNU Radio Tutorial
May 27, 2012
54 / 79
Chapter the Fifth: Programming Blocks
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.
GNU Radio Tutorial
May 27, 2012
55 / 79
Chapter the Fifth: Programming Blocks
Programming Practices
Programming Practices
Layered API
GNU Radio Tutorial
May 27, 2012
56 / 79
Chapter the Fifth: Programming Blocks
Programming Practices
Programming Practices
Layered API: Python Wrapper through SWIG
GNU Radio Tutorial
May 27, 2012
57 / 79
Chapter the Fifth: Programming Blocks
Programming Practices
Programming Practices
Layered API: GNU Radio Companion GUI
GNU Radio Tutorial
May 27, 2012
58 / 79
Chapter the Fifth: Programming Blocks
Programming Practices
Programming Practices
Layered API: Direct C++ Applications
GNU Radio Tutorial
May 27, 2012
59 / 79
Chapter the Fifth: Programming Blocks
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 [email protected] GNU Radio Tutorial May 27, 2012 60 / 79
Chapter the Fifth: Programming Blocks
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.
GNU Radio Tutorial
May 27, 2012
61 / 79
Chapter the Fifth: Programming Blocks
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.
GNU Radio Tutorial
May 27, 2012
62 / 79
Chapter the Fifth: Programming Blocks
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 /
GNU Radio Tutorial
May 27, 2012
63 / 79
Chapter the Fifth: Programming Blocks
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 /
GNU Radio Tutorial
May 27, 2012
64 / 79
Chapter the Fifth: Programming Blocks
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,
s i z eo f ( in type )) , s i z e o f ( out type ) ) )
here
GNU Radio Tutorial
May 27, 2012
65 / 79
Chapter the Fifth: Programming Blocks
Programming Practices
Component Structure
Private Source File (cont.): foo impl.cc
d t yp e b ar i mp l : : var ( ) { return d var ; } void b a r i m p l : : s e t v a r ( d t yp e v a r ) { d var = var ; }
GNU Radio Tutorial
May 27, 2012
66 / 79
Chapter the Fifth: Programming Blocks
Programming Practices
Component Structure
Private Source File (cont.): foo impl.cc
int b a r i m p l : : 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 ) { const i n typ e in = ( const i n typ e ) i n p u t i tem s [ 0 ] ; o u t t y p e ou t = ( o u t t y p e ) o u t p u t i t e m s [ 0 ] ; // P er for m w or k ; } } / n am espace f o o / } / n am espace g r / r e a d fr om in , write to out .
return noutput items ;
GNU Radio Tutorial
May 27, 2012
67 / 79
Chapter the Fifth: Programming Blocks
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 ) ;
GR SWIG BLOCK MAGIC2( f o o ,
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 [email protected] GNU Radio Tutorial May 27, 2012 68 / 79
Chapter the Fifth: Programming Blocks
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).
GNU Radio Tutorial
May 27, 2012
69 / 79
Chapter the Fifth: Programming Blocks
Programming Practices
Buer Pointers: Readers and Writers
Ciruclar Buer Structure
Read and write to buers. Blocks are told how much they can read and write.
GNU Radio Tutorial
May 27, 2012
70 / 79
Chapter the Fifth: Programming Blocks
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 ++) {
GNU Radio Tutorial
May 27, 2012
71 / 79
Chapter the Fifth: Programming Blocks
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 ; }
GNU Radio Tutorial
May 27, 2012
72 / 79
Chapter the Fifth: Programming Blocks
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 ; }
GNU Radio Tutorial
May 27, 2012
73 / 79
Chapter the Fifth: Programming Blocks
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 }
GNU Radio Tutorial
May 27, 2012
74 / 79
Chapter the Fifth: Programming Blocks
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.
GNU Radio Tutorial
May 27, 2012
75 / 79
Chapter the Fifth: Programming Blocks
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.
Example usage: gr-digital/examples/example costas.py
GNU Radio Tutorial
May 27, 2012
76 / 79
Chapter the Last: Conclusions
Chapter the Last: Conclusions
I never am really satised that I understand anything; because, understand it well as I may, my comprehension can only be an innitesimal fraction of all I want to understand. - Ada Lovelace
GNU Radio Tutorial
May 27, 2012
77 / 79
Chapter the Last: Conclusions
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.
GNU Radio Tutorial
May 27, 2012
78 / 79
Chapter the Last: Conclusions
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
GNU Radio Tutorial
May 27, 2012
79 / 79