Upload
sabina-serban
View
220
Download
0
Embed Size (px)
Citation preview
7/29/2019 Basics.gnu
1/43
1
Chapter 17
GNU Radio for Cognitive RadioExperimentation
Cognitive Radio Communications and Networks: Principles and Practice
By A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
7/29/2019 Basics.gnu
2/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
2
Outline
What is GNU Radio?
Basic Concepts
GNU Radio Architecture & Python
Dial Tone ExampleDigital Communications
Cognitive Transmitter
7/29/2019 Basics.gnu
3/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
What is GNU Radio?
Software toolkit for signal
processingSoftware radio construction
Rapid development
Cognitive radio
USRP (Universal Software Radio Peripheral)
Hardware frontend for sendingand receiving waveforms
7/29/2019 Basics.gnu
4/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
GNU Radio Components
Hardware Frontend Host Computer
RF Frontend(Daugtherboard)
ADC/DAC andDigital Frontend(USRP)
GNU RadioSoftware
7/29/2019 Basics.gnu
5/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
GNU 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 (flowgraph)
7/29/2019 Basics.gnu
6/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
GNU Radio Hardware
Sends/receives waveforms
USRP FeaturesUSB 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
7/29/2019 Basics.gnu
7/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
GNU Radio Hardware Schematic
RX/TXDaughterboa
rd
ADC/DAC
Host Computer
FPGAUSB
Interface
7/29/2019 Basics.gnu
8/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
8
Outline
What is GNU Radio?
Basic Concepts
GNU Radio Architecture & Python
Dial Tone ExampleDigital Communications
Cognitive Transmitter
7/29/2019 Basics.gnu
9/43
Basics: Blocks
Signal Processing Block
Accepts 0 or more inputstreams
Produces 0 or moreoutputstreams
Source: No input noi se_sour ce,
si gnal _sour ce,usr p_sour ce
Sink: No outputs audi o_al sa_si nk,
usr p_si nk
7/29/2019 Basics.gnu
10/43
Basics: Data Streams
Blocks operate onstreamsof data
1 5 3
3 7 9
4 12 12
7/29/2019 Basics.gnu
11/43
Basics: Data Types
Blocks operate on certain
data types char, short, int, float,
complex
Vectors
Input Signature:
Data types for inputstreams
Output Signature:
Data types for outputstreams
Two streamsoff l oat
One streamofcompl ex
7/29/2019 Basics.gnu
12/43
Basics: Flow Graph
Blocks composed as aflow graph
Data stream flowing fromsourcestosinks
7/29/2019 Basics.gnu
13/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
13
Outline
What is GNU Radio?
Basic Concepts
GNU Radio Architecture & Python
Dial Tone ExampleDigital Communications
Cognitive Transmitter
7/29/2019 Basics.gnu
14/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
GNU Radio Architecture
User-defined
CodeRF
Front end
Sender
DACUSB FPGA
mother board
PC
USRP
daughter board
GNU radio has provided some useful APIs
What we are interested in at this time ishow to use theexisting modulesthat has been provided in GNU radioprojectto communicate between two end systems
7/29/2019 Basics.gnu
15/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
GNU Radio Architecture - software
How these modules co-work? Signal processing block and flow-graph C++: Extensive library of signal processing blocks
Performance-critical modules Python: Environment for composing blocks Glueto connect modules
Non performance-critical modules
7/29/2019 Basics.gnu
16/43
GNU Radio Architecture software(2)
Python
Application developmentFlow graph construction
C++
Signal processing blocks
Python scripting languageused forcreating "signal flow graphs
C++used for creatingsignal processingblocks
An already existing library of signalingblocks
Thescheduler is using Pythons built-inmodule threading, to control the
starting, stopping or waitingoperations of the signal flow graph.
Scheduler
Control flow graph
7/29/2019 Basics.gnu
17/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
GNU Radio Architecture software(3)
C++
C++ C++
C++
C++ C++V1
V2
V3
V1
V2
V3Source
Sink
7/29/2019 Basics.gnu
18/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
Python - running
Why Python?
Object-oriented
Free
Mixable (python/c++)
Python scripts can be written in text files with thesuffix .py
Example: $ python script.py
This will simply execute the script and return to theterminal afterwards
7/29/2019 Basics.gnu
19/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
Python - format
Module: a python file containing definitions and statements
frompick_bitrate import pick_tx_bitrate(fromfileimport function) fromgnuradio import gr, (or *)
(frompackageimportsubpackage or all) Some modules are built-in e.g. sys (import sys)
Indentation: it is Pythons way of grouping statements Example: while b < 10:
print breturn
Body of loop has to be indented by the same amount toindicate statements of the loop
7/29/2019 Basics.gnu
20/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
Python function & class (1)
Function definitions have the following basic structure:
def func(args):
return values
Regardless of the arguments, (including the case of noarguments) a function call must end with parentheses
Example:def f1(x):
return x*(x-1)f1(3) = 6
7/29/2019 Basics.gnu
21/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
Python function & class (2)
Classes
class ClassName:
. . .
Objects
x = ClassName() creates a new instance of this class and assigns the
object to the variable x
Initial state: for instantiation and parameter pass
def__init__(self):
7/29/2019 Basics.gnu
22/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
Creating Your Own Signal Block
Basics
A block is a C++ classTypically derived from gr_block or gr_sync_block class
Three componentsmy_block_xx.h: Block definition
my_block_xx.cc: Block implementation
my_block_xx.i: Python bindings (SWIG interface)
(SWIG, a tool that generates wrapper code around your C++functions and classes, so that they are callable from Python)
7/29/2019 Basics.gnu
23/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
23
Outline
What is GNU Radio?
Basic Concepts
GNU Radio Architecture & Python
Dial Tone ExampleDigital Communications
Cognitive Transmitter
7/29/2019 Basics.gnu
24/43
Dial Tone Example
Sine Generator
(350Hz)
Sine Generator
(440Hz)
Audio Sink
7/29/2019 Basics.gnu
25/43
Dial Tone Example#! / usr / bi n/ env python
f r om gnur adi o i mpor t grf r om gnur adi o i mpor t audi of r om gnur adi o. eng_opt i on i mport eng_opt i onf r omopt parse i mport Opt i onPar ser
cl ass my_t op_bl ock( gr . t op_bl ock) :def __ i ni t __(sel f ) :
gr . t op_bl ock. __ i ni t __(sel f )
parser = Opt i onPar ser( opt i on_cl ass=eng_opt i on) par ser . add_opt i on( "- O", "- - audi o- out put ", t ype="st r i ng", def aul t ="" ,
hel p="pcm out put devi ce name. E. g. , hw: 0, 0") par ser . add_opt i on( "- r ", "- - sampl e- r at e", t ype="eng_f l oat ", def aul t =48000,
hel p="set sampl e rat e to RATE ( 48000) " ) ( opt i ons, args) = par ser . par se_args ( ) i f l en( ar gs) ! = 0:
par ser . pr i nt _hel p( ) r ai se SystemExi t , 1
sampl e_rate = i nt ( opt i ons. sampl e_r ate) ampl = 0. 1
sr c0 = gr . si g_sour ce_f ( sampl e_r ate, gr . GR_SI N_WAVE, 350, ampl ) sr c1 = gr . si g_sour ce_f ( sampl e_r ate, gr . GR_SI N_WAVE, 440, ampl ) dst = audi o. si nk ( sampl e_r at e, opt i ons. audi o_out put ) sel f . connect ( src0, ( dst, 0) ) sel f . connect ( src1, ( dst, 1) )
i f __ name__ == ' __mai n__ ' :t ry :
my_t op_bl ock() . r un( ) except Keyboar dI nt er r upt :
pass
7/29/2019 Basics.gnu
26/43
Dial Tone Example (1)
f r om gnur adi o i mpor t gr
f r om gnur adi o i mpor t audi of r om gnur adi o. eng_opt i on i mpor t eng_opt i onf r om opt par se i mpor t Opt i onPar ser
Import modules from GNU Radio library
7/29/2019 Basics.gnu
27/43
Dial Tone Example (2)
cl ass my_t op_bl ock( gr . t op_bl ock) :def __ i ni t __ ( sel f ) :
gr . t op_bl ock. __i ni t __( sel f )
Define container for Flow Graph;
gr . t op_bl ock class maintains thegraph
7/29/2019 Basics.gnu
28/43
Dial Tone Example (3)
par ser = Opt i onPar ser ( opt i on_cl ass=eng_opt i on) par ser . add_opt i on( " - O" , "- - audi o- out put " , t ype="st r i ng" , def aul t ="" ,
hel p="pcm out put devi ce name. E. g. , hw: 0, 0" ) par ser . add_opt i on( " - r " , " - - sampl e- r at e" , t ype="eng_f l oat " , def aul t =48000,
hel p="set sampl e r at e t o RATE ( 48000) " ) ( opt i ons, ar gs) = par ser . par se_ar gs ( ) i f l en( ar gs) ! = 0:
par ser . pr i nt _hel p( ) r ai se Syst emExi t , 1
Define and parse command-line options
7/29/2019 Basics.gnu
29/43
Dial Tone Example (4)
sampl e_r at e = i nt ( opt i ons. sampl e_r at e) ampl = 0. 1
sr c0 = gr . si g_sour ce_f ( sampl e_r at e, gr . GR_SI N_WAVE, 350, ampl ) sr c1 = gr . si g_sour ce_f ( sampl e_r at e, gr . GR_SI N_WAVE, 440, ampl )
dst = audi o. si nk ( sampl e_r at e, opt i ons. audi o_out put )
sel f . connect ( src0, ( dst , 0) ) sel f . connect ( src1, ( dst , 1) )
Create and connect signal processing blocks
7/29/2019 Basics.gnu
30/43
Dial Tone Example (5)
i f __name__ == ' __mai n__ ' :t ry :
my_t op_bl ock( ) . r un( ) except Keyboar dI nt er r upt :
pass
Run the flow graph when the program is executed
7/29/2019 Basics.gnu
31/43
31
Outline
What is GNU Radio?
Basic ConceptsGNU Radio Architecture & Python
Dial Tone ExampleDigital Communications
Cognitive Transmitter
7/29/2019 Basics.gnu
32/43
Digital Communications: Transmitter
Top level block of digital transmitter
PacketModulator
AmplifierUSRP
Transmitter
7/29/2019 Basics.gnu
33/43
Digital Transmitter
Building the RadioModulating the dataSetting up the USRP
Running the TransmitterThe main functionStarting the program
7/29/2019 Basics.gnu
34/43
Digital Communications: Receiver
Top level block of digital receiver
PacketDemodulator
ChannelFilter
USRPReceiver
FFTDisplay
7/29/2019 Basics.gnu
35/43
Digital Receiver
Building the RadioDemodulating the dataSetting up the USRPPacket callback function (different from the transmitter)
Running the ReceiverThe main function
Starting the program
7/29/2019 Basics.gnu
36/43
36
Outline
What is GNU Radio?
Basic ConceptsGNU Radio Architecture & Python
Dial Tone ExampleDigital Communications
Cognitive Transmitter
7/29/2019 Basics.gnu
37/43
Cognitive Transmitter
Top level block of cognitive transmitter
Transmit (Tx) Flow Graph
PacketModulator
AmplifierUSRP
Transmitter
Noise Calculation (Rx) Flow Graph
USRPReceiver
SignalNoise
Calculator
CustomLogic
7/29/2019 Basics.gnu
38/43
Cognitive Transmitter
Building the RadioModulating the dataSetting up the USRP
Running the TransmitterTimer control of flow graphsThe main function
Starting the program
7/29/2019 Basics.gnu
39/43
Cognitive Transmitter: Timer Control
Time division of cognitive transmitter
Rx Tx
One Second Nine Seconds
7/29/2019 Basics.gnu
40/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
40
Chapter 17 SummaryThis chapter introduces the reader to GNU radio for cognitive radio experimentation.The Introduction section provides an overview of software defined radio and the
GNU Radio toolkit. The hardware commonly used with this software, the UniversalSoftware Radio Peripheral (USRP), is also introduced.
The analog communication section is focused on the Python level, introducing somePython basics and how Python is used in GNU Radio to connect signal processing
blocks and control the flow of the digital data.
The most common type of modern communication is digital. Building upon theanalog communication section, a digital radio is developed to transmit a randomlygenerated bitstream modulated using DBPSK.
In the last section, a time division protocol is implemented to enable channel noisecalculations by the transmitter. This time division is similar to the one specified bythe 802.22 standard and outlines how cognitive engines can be added to GR.
7/29/2019 Basics.gnu
41/43
Appendix 1: GNU Radio modules fromgnuradio import MODULENAME
Mi scel l aneous ut i l i t i es, mat hemat i cal and ot her s.gru
Use from gnuradio.eng_options import eng_options t o i mpor t t hi s f eat ur e. Thi smodul e ext ends Pyt hons optparse modul e t o under st and engi neer i ngnot at i on ( see above) .
eng_opti ons
Adds some f unct i ons t o deal s wi t h number s i n engi neer i ng not at i onsuch as `100M' f or 100 * 106' .
eng_notat i
on
Thi s modul e cont ai ns addi t i onal bl ocks wr i t t en i n Pyt hon whi chi ncl ude of t en- used t asks l i ke modul at or s and demodul at or s, someext r a f i l t er code, r esampl er s, squel ch and so on.
bl ks2
Soundcar d cont r ol s ( sour ces, si nks) . You can use t hi s t o send orr ecei ve audi o t o t he sound cards, but you can al so use yoursound card as a nar r ow band r ecei ver wi t h an ext er nal RFf r ont end.
audi o
USRP sour ces and si nks and cont r ol s.usrp
The mai n GNU Radi o l i brar y. You wi l l near l y al ways need t hi s.gr
7/29/2019 Basics.gnu
42/43
Appendix 2: GNU Radio scheduler
Unl ock a f l ow gr aph i n pr epar at i on f or r econf i gur at i on. When anequal number of cal l s t o l ock( ) and unl ock( ) have occur r ed, t hef l ow gr aph wi l l be r est ar t ed aut omat i cal l y.
unlock()
Lock a f l ow gr aph i n pr epar at i on f or r econf i gur at i on.lock()
Wai t f or a f l ow gr aph t o compl et e. Fl owgr aphs compl et e when ei t her( 1) al l bl ocks i ndi cat e t hat t hey ar e done, or ( 2) af t er st op hasbeen cal l ed t o request shut down.
wait()
St op t he r unni ng f l ow gr aph. Not i f i es each t hr ead cr eat ed by t heschedul er t o shut down, t hen r et ur ns t o cal l er .
stop()
St ar t t he cont ai ned f l ow gr aph. Ret ur ns t o t he cal l er once t het hr eads are cr eat ed.
start()
The si mpl est way t o r un a f l ow gr aph. Cal l s st ar t ( ) , t hen wai t ( ) .Used t o r un a f l ow gr aph t hat wi l l st op on i t s own, or t o r un af l ow gr aph i ndef i ni t el y unt i l SI GI NT i s recei ved.
run()
7/29/2019 Basics.gnu
43/43
Cognitive Radio Communications and Networks: Principles and PracticeBy A. M. Wyglinski, M. Nekovee, Y. T. Hou (Elsevier, December 2009)
Appendix 3: 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