GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks...
Transcript of GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks...
![Page 1: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/1.jpg)
GNU Radio
Introduction and Computational Capabilities of the Open Source GNU Radio Project
Thomas W. RondeauGNU Radio maintainer
SDR Technical Conference, 2010
![Page 2: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/2.jpg)
Tutorial Scope
• An overview of GNU Radio and its purpose and capabilities
• A look inside to see how it works
• Understanding of the computational models, methods, and processes behind the software
• An appreciation for its multidisciplinary nature
![Page 3: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/3.jpg)
Tutorial Outline
boring stuff fun stuff more fun
stuff back to boring stuff
preachy stuff
interesting stufftechnical
stuffuseful stuff
introduction examplesGUIs
software
programming
profiling/design
computationalmodel
gnuradiocompanion
![Page 4: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/4.jpg)
OPENING INTRODUCTION
![Page 5: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/5.jpg)
GNU Radiognuradio.org
• Open source software radio
• Provides the scheduler for real-time operation
• Includes:– Many signal processing blocks
– Interfaces to a few radio front ends
– Graphical user interfaces (GUI)
– Examples
• A platform to build and explore radios (or any other communications platform)
![Page 6: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/6.jpg)
Python on top; C++ underneath
Python Interface C++ Libraries
USRP Source
Filter
FM Demod
AudioSink
libusrp.so
libgnuradio-core.so
libgnuradio-alsa.so
![Page 7: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/7.jpg)
Structuring the Python
• Get the namespace
• Inherit from top_block
• Class constructor
• Call top_block constructor
• Create some GNU Radio blocks
• Connect blocks
from gnuradio import gr
class myblock(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
self.block1 = gr.<block>
self.block2 = gr.<block>
self.connect(self.block1, self.block2)
![Page 8: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/8.jpg)
Using the Python class
• Some function to use the block
• Instantiate a myblock object
• Start the flowgraph
• Block until it finishes
def main():tb = myblock()
tb.start()
tb.wait()
![Page 9: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/9.jpg)
FM EXAMPLE WALKTHROUGH
![Page 10: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/10.jpg)
ANALYSIS TOOLS
![Page 11: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/11.jpg)
Visualization is an important part of analysis and debugging
On-line tools:wxPython GUI: www.wxpython.orgQT GUI: qt.nokia.com/products
www.riverbankcomputing.co.ukqwt.sourceforge.net
Off-line tools:Scipy: www.scipy.orgMatplotlib: matplotlib.sourceforge.net
![Page 12: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/12.jpg)
Basic Matplotlib Plotting
import scipy, pylab
t = scipy.arange(0, 1, 0.001)
x = scipy.cos(2*scipy.pi*(100)*t)
y = scipy.sin(2*scipy.pi*(100)*t)
fig = pylab.figure(1)
sp = fig.add_subplot(1,1,1)
p1 = sp.plot(t, x, “b-”, linewidth=2, label=“func1”)
p2 = sp.plot(t, y, “r-o”, linewidth=2, label=“func2”)
sp.legend()
pylab.show()
![Page 13: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/13.jpg)
Using Matplotlib with GNU Radio
• Use gr.head to stop graph after N items
– gr.head(gr.sizeof_gr_complex, N)
• Use gr.vector_sink_c to store data
– self.vsink = gr.vector_sink_c()
– After graph has run:
• self.vsink.data() returns the data as a Python list
• We can now plot all N items of vsink
![Page 14: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/14.jpg)
Matplotlib Output Examples:Plotting filter impulse responses
![Page 15: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/15.jpg)
Matplotlib Output Examples:Filtering noise
![Page 16: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/16.jpg)
USING MATPLOTLIB WITH FM EXAMPLE
![Page 17: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/17.jpg)
The wx and QT GUI’s add on-line support for visualization.
from gnuradio.qtgui import qtgui
Set up with an initial FFT size, window function, center frequency, sample rate, and window title.
Remaining arguments turn on/off the different plots
Can also set a parent to work in with other QT apps
self.qtsink = qtgui.sink_c(fftsize, window, fc, Rs, title,fft, waterfall, waterfall3D, time, const, parent)
![Page 18: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/18.jpg)
The QT GUI output offers multiple views:FFT (or PSD)
![Page 19: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/19.jpg)
The QT GUI output offers multiple views:Waterfall (or spectrogram)
![Page 20: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/20.jpg)
The QT GUI output offers multiple views:Time (with real and imaginary parts)
![Page 21: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/21.jpg)
USING QT GUI WITH FM EXAMPLE
![Page 22: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/22.jpg)
THINKING ABOUT SOFTWARE
![Page 23: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/23.jpg)
SOFTWARE Radio
• More than just signal processing algorithms
• We worry about implementation as well
• OSS project has many objectives:
– High quality, efficiency, and speed
– Readable (and therefore editable)
– Robust and reliable
![Page 24: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/24.jpg)
Things we think about
Profiling and performance testing
Unit testing
Installation and operation on multiple OSes
![Page 25: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/25.jpg)
Autotools: The worst build system aside from all the others…
• GNU’s Automake and Autconf
– Well-understood build system in GNU community
• Test operating system support
• Ensure dependencies are met
• make check and make distcheck to test full build system
![Page 26: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/26.jpg)
Unit Testing: make sure your code works and continues to work.
• For C++ code, we use the CppUnit test suite
• For blocks wrapped to Python, we use python.unittest
• Using Hudson Continuous Integration tool to monitor builds and tests
– hudson-ci.org
![Page 27: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/27.jpg)
Profiling Code
• First rule: “premature optimization is the root of all evil.”
• Code, test, get it right. Then optimize.
• Use profiling tools to find where your code needs work.
• Focus on measured performance problems and optimize.
• Things you think you know that just ain’t so…
![Page 28: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/28.jpg)
Designing a FIR filter
c0 c1 c2 c3
0 0 0 0 0 0 0 0
e g f e d c b ainput
taps (len = 4)
buffer (2xlen)
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 0
i = 0
yi = xic0 + xic1 + xic2 + xic3
![Page 29: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/29.jpg)
c0 c1 c2 c3
a 0 0 0 a 0 0 0
e g f e d c b ainput
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 0
Designing a FIR filter
i = 0
![Page 30: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/30.jpg)
c0 c1 c2 c3
a 0 0 0 a 0 0 0
e g f e d c b ainput
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 1
yi = 0 + 0 + 0 + ac3
Designing a FIR filter
i = 0
![Page 31: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/31.jpg)
c0 c1 c2 c3
a b 0 0 a b 0 0
e g f e d c b ainput
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 1
Designing a FIR filter
i = 1
![Page 32: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/32.jpg)
c0 c1 c2 c3
a b 0 0 a b 0 0
e g f e d c b ainput
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 2
yi = 0 + 0 + ac2 + bc3
Designing a FIR filter
i = 1
![Page 33: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/33.jpg)
c0 c1 c2 c3
a b c 0 a b c 0
e g f e d c b ainput
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 2
Designing a FIR filter
i = 2
![Page 34: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/34.jpg)
c0 c1 c2 c3
a b c 0 a b c 0
e g f e d c b ainput
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 3
yi = 0 + ac1 + bc2 + cc3
Designing a FIR filter
i = 2
![Page 35: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/35.jpg)
c0 c1 c2 c3
a b c d a b c d
e g f e d c b ainput
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 3
Designing a FIR filter
i = 3
![Page 36: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/36.jpg)
c0 c1 c2 c3
a b c d a b c d
e g f e d c b ainput
Update:1. Write next input to buffer at idx2. Write same input to buffer at idx+len3. increment len = len + 14. Perform filter calculation
idx = 4
yi = ac0 + bc1 + cc2 + dc3
Designing a FIR filter
i = 3
![Page 37: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/37.jpg)
c0 c1 c2 c3
e b c d e b c d
e g f e d c b ainput
Update:1. When idx == len, wrap around to 0
idx = 0
Designing a FIR filter
i = 4
![Page 38: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/38.jpg)
c0 c1 c2 c3
e b c d e b c d
e g f e d c b ainput
Update:1. When idx == len, wrap around to 0
idx = 1
yi = bc0 + cc1 + dc2 + ec3
Designing a FIR filter
i = 4
![Page 39: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/39.jpg)
c0 c1 c2 c3
e f c d e f c d
e g f e d c b ainput
Continue with this algorithm for all input items.
idx = 1
Designing a FIR filter
i = 5
![Page 40: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/40.jpg)
c0 c1 c2 c3
e f c d e f c d
e g f e d c b ainput
Continue with this algorithm for all input items.
idx = 2
yi = cc0 + dc1 + ec2 + fc3
Designing a FIR filter
i = 5
![Page 41: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/41.jpg)
• The only logic in this algorithm is to check when idx == len in order to reset idx = 0.
• How?
If statement modulo len
• Which is faster? Does it matter?
idx = idx + 1;if(idx == len)
idx = 0;idx = (idx+1) % len;
Designing a FIR filter
![Page 42: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/42.jpg)
Profiling tools
• Walk through an example using:
– Valgrind (http://valgrind.org)
– Cachegrind (http://valgrind.org/info/tools.html)
– KCachegrind (http://kcachegrind.sourceforge.net)
![Page 43: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/43.jpg)
PROFILING EXAMPLE
![Page 44: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/44.jpg)
PROGRAMMING MODEL
![Page 45: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/45.jpg)
We started off with this concept:
Python Interface C++ Libraries
USRP Source
Filter
FM Demod
AudioSink
libusrp.so
libgnuradio-core.so
libgnuradio-alsa.so
![Page 46: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/46.jpg)
Behind the scenes:
gr_buffer_reader
USRP Source
FilterFM
Demod
gr_buffer
gr_buffer_reader
gr_buffer
• Scheduler calls a block’s work function and tells it how many items it can produce based on the number of items in the gr_buffer.
• Blocks read from their input buffer and write to an output buffer.
• Scheduler is optimized for throughput.
![Page 47: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/47.jpg)
GNU Radio block work function
• There are N input streams– input_items[n] has ninput_items[n] items
• Can produce at most noutput_items number of items in any output_items output stream
• Tells scheduler – how many consumed from each input
– how many produced (<= noutput_items)
int general_work(int noutput_items,gr_vector_int &ninput_items,gr_vector_const_void_star &input_items,gr_vector_void_star &output_items)
![Page 48: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/48.jpg)
Example:multiply_const_ff
int general_work ( <see last slide> ){
const float *in = (const float*)input_items[0];float *out = (float*)ouput_items[0];
for(int i = 0; i < noutput_items; i++) {out[i] = k * in[i];
}
// an equal number of items consumed and producedconsume_each(noutput_items);return noutput_items;
}
gr_multiply_const_ff( k )
![Page 49: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/49.jpg)
Four basic types of blocks
• Sync blocks
– number of items in equals the number of items out
– like the multiply constant example
• Decimation blocks
– number of items IN is D times the number of items OUT
• Interpolation blocks
– number of items OUT is I times the number of items IN
• Blocks:
– relationship between input and output items is not straight-forward
![Page 50: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/50.jpg)
• Simple Wrapper Interface Generator (SWIG)• http://www.swig.org
SWIG wrapper
SWIG allows us to talk between the Python and C++ layers.
GNU Radio Python block
libgnuradio-core.soGNU Radio Core
shared library
![Page 51: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/51.jpg)
• SWIG produces Python modules out of the C++ blocks
• Builds an interface based on an interface description file (.i)
– The interface description file describes the API for talking between the two languages
– Its content is very similar to the C++ .h header file
Program GNU Radio in Python; computation handled in C++
![Page 52: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/52.jpg)
Advice:
If you want to write a new block, find a block that has similar properties and copy it.
![Page 53: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/53.jpg)
CONSIDERING ALGORITHMS
![Page 54: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/54.jpg)
Understanding GNU Radio’s quantization
• What is the proper scope of a block?
• Try to use good software principles:
– Increase usability
– Reduce duplication
• Find the smallest level the algorithm can run
• Expand the scope only as needed
– Only when the combination of other blocks cannot properly solve the problem
![Page 55: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/55.jpg)
Programming the algorithm
• Follow good programming practices that we discussed earlier
• Make as much gain from the algorithm as possible
– don’t just rely on super programming skills to overcome an inherently bad algorithm
• Takes a lot of multidisciplinary thinking
![Page 56: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/56.jpg)
Example:The FIR filter
• We know that filtering is convolution in time:
• Which means, its multiplication in frequency:
• With the efficiency of the FFT, convolution is faster in the frequency domain– “fast convolution”
][][ nxtny
1
0
][][][L
i
inXiTnY
![Page 57: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/57.jpg)
GNU Radio implements both kinds of FIR filters
• FIR done as time convolution
– gr_fir_filter_XXX
• FIR done in frequency domain
– gr_fft_filter_XXX
• The time domain has been SIMD optimized
• How do they compare in speed?
![Page 58: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/58.jpg)
Comparing the SIMD and non-SIMD time domain filters
![Page 59: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/59.jpg)
Comparing the time domain to frequency domain filters
![Page 60: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/60.jpg)
For all of our cleverness in the time domain
• Using the right algorithm produces a more efficient filter.
• FFT filter slower for small number of taps– around 22
• Not much slower at this point
• Some gains left to be made– SIMD optimize the multiplication loop
– Some FFT sizes are faster than others; use them and pad with zeros
![Page 61: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/61.jpg)
FFTW capabilities(http://www.fftw.org/speed/CoreDuo-3.0GHz-icc64/ )
Intell IPPSIntel MKL in-placeIntel MKL out-of-placeFFTW3 out-of-placeFFTW3 in-place
Other lines are from other FFT programs and are not important for this comparison
61
![Page 62: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/62.jpg)
THE GNU RADIO COMPANION
![Page 63: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/63.jpg)
Graphical tool for building GNU Radio flowgraphs
• Makes it easier to:
– Visualize the data flow
– Tie in with graphical sinks
– Browse available library of blocks
– Add live interactive capabilities through block callbacks
• gnuradio-companion is distributed with GNU Radio
![Page 64: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/64.jpg)
GNU Radio Companion features:
• Variables– Set values of blocks
– Dynamic variables add features such as sliders or edit boxes for on-line altering of parameters
• Python programming level:– many things can be altered by using Python
programming such as calling other modules, functions, or creating lambda functions
– Can even import new modules
• GUI interface is interactive and configurable– Add Notebooks for better on-screen organization
![Page 65: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/65.jpg)
EXAMPLES OF USING THE GNU RADIO COMPANION
![Page 66: GNU Radio - wirelessinnovation.org · •SWIG produces Python modules out of the C++ blocks •Builds an interface based on an interface description file (.i) –The interface description](https://reader030.fdocuments.us/reader030/viewer/2022040514/5e6ba76cb2d74e27815c2eb8/html5/thumbnails/66.jpg)
FIN