Experiment 1 Introduction to GNU Radio and USRP 2 ECE 4117 Telecommunications Laboratory Fall 2012 Purpose

vetinnocentSoftware and s/w Development

Nov 7, 2013 (3 years and 9 months ago)

139 views





ECE 4117

1


Experiment 1

Introduction to GNU Radio and USRP 2

ECE 41
1
7



Telecommunications Laboratory

Fall 2012

Purpose


The purpose of this lab is to get acquainted with software defined radio; the usage of GNU radio
and the mechanics of using the USRP2. This lab will go step by step through an example and
then will allow you to experiment and learn all the different aspec
ts of the equipment on your
own.



Introduction


Software defined radio (SDR)

has recently become an attractive
method to implement many RF
applications. In general, SDR enables the computer to handle many of the signal processing
processes within a softw
are environment
; where in

the
past,
this was handled by hardware
components.

This transition into the software domain

leads to several advantages that are not
available

on hardware based radio. The SDR is able to be more reconfigurable, where it can
reconfigured to adapt to new standards much easily. It can also be much more flexible, where its
platform can be universal and be used in a wide range of uses. It is upgradab
le and more cost
efficient when compared to hardware based radio. The SDR can also be used as a cognitive
radio, where it automatically changes its parameters so that it can select the best available
channel.


For more details on cognitive radio, please r
ead the following tutorial paper
:


Simon Haykin,


Cognitive Radio: Brain
-
Empowered

Wireless Communications
,”
IEEE
JOURNAL ON SELECTED AREAS IN COMMUNICATIONS, V
OL. 23, NO. 2, P.P 201
-
220,
FEBRUARY 2005.


For more information on the SDR

and GNU radio
, pleas
e read the following
links
:


SDR
/GNU Radio

Tutorials
-

University of Notre Dame

http://radioware.nd.edu/documentation/basic
-
gnuradio


SDR

Article



IEEE Spectrum

http://spectrum.ieee.org/computing/software/hardware
-
for
-
your
-
software
-
radio


Exploring GNU radio



GNU Radio website

http://www.gnu.org/software/gnuradio/doc/exploring
-
gnuradio.html




Software defined radio, does however, require the implementation of several hardware
components. The general
layout of the SDR is shown below, in figure 1
.





ECE 4117

2



















In general, the first two blocks of each path and the antenna make up the hardware side
of the
SDR and the third block is the computer/software.


For this lab and for all the labs in the semester, we will be using

the USRP 2 and GNU radio to
conduct all of our experiments.
GNU
radio

is an open source Python
-
based architecture for
building SD
R projects. It provides

a

variety of signal processing blocks which are written in
C++.

The software domain portion in the RX/TX path will be controlled
by GNU radio. Thus, all
of the experiments will be conducted and controlled from GNU radio.


The
Univ
ersal Software Radio Peripheral
(USRP

2
) is the hardware solution for GNU Radio.
Each USRP consists of a motherboard
that contains a digital
-
to
-
analog converter

(DAC)
, analog
-
to
-
digital converter

(ADC)
, 1MB SRAM,
gat
e
-
field programmable gate array (
FPGA)

a
nd a
gigabit
Ethernet interface.

The major components of USRP2 are listed as follows
:


1.

Radio frequency (RF) front
-
end is implemented on the daughterboard. There are a variety
of daughterboards that are available to work at different frequency band. The RF
front
end translates the range of frequencies at the receiving end to a lower range at its output.
The opposite occurs for the transmitting side, where the RF front end translates the range
of frequencies to the final higher frequency range.

2.

ADCs and DACs

are the bridge between the co
ntinuous analog signals and the
discrete
digital samples. All the ADCs and DACs

are connected to the FPGA. The
functionality
of the
FPGA is to perform the high
-
speed g
eneral purpose operations, such
as digital
-
up
conversion an
d digital
-
down conversion,

decimation, and interpolation,
and to reduce the
data rate feeding to

the gigabit Ethernet connection. This connects the FPGA to the
Receive Path:

Transmit

Path:

Figure
1
: Typical SDR TX/RX path





ECE 4117

3


computer, where all of the waveform specific processing is performed on the host
computer.

3.

Pytho
n is a dynamic object
-
oriented programming language that has
been
proven to have
strong integration capabilities with other languages. It is simple to use and offers much
more structure and support for large programs than shell scripts could offer. Python is
available on Windows, Mac OS, and
Linux

operating systems. In
t
he
GNU software radio
platform, all the signal processing blocks are written in C++, which are then connected
by Python.



USRP

2 and GNU radio


Setup


The USRP 2 and GNU radio will be used in Ubuntu, a Linux based operating system. This may
be unfamiliar

to several people, so a brief command list and setup instructions will be introduced

in this section. There are also a number of resources available online which can be utilized if
there are any remaining questions.


For several applications, the use of
the terminal window is not needed
,

so the GUI used in
Ubuntu is sufficient. However, several programs will require the use of the terminal window.
The terminal window shortcut is found on the toolbar next to the Firefox

logo.


Basic Linux Commands:


cd xx
xx



changes directory to xxxx

cd ..


go to previous directory

ls


lists the contents of the current directory

mkdir



create a new folder in current directory

chmod


change the permission of a file
, by using
chmod +x
, you can make a file executable
(co
mputer would identify the
.py
file as an executable python script
)

gedit


Opens a

t
ext editor

window
, Ubuntu equivalent of Notepad

sudo



gives admin status to command (may be required for several commands)


Many other commands exist and can be found
online
,

http://www.unixguide.net/linux/linuxshortcuts.shtml

http://ss64.com/bash/

http://linuxconfig.org/linux
-
commands


H
owever these commands should be sufficient for the experiments.


To start the GNU radio companion, a GUI for building projects, use the following command in
the terminal:

gnuradio
-
companion


To check if the usrp2 is

detected by the computer after plugging it in, use the following
command

by starting a new terminal
:

sudo
find_usrps





ECE 4117

4



Note that the
sudo

command require
s

the password for the user account.



If done correctly, the computer should display the MAC address
of the USRP, otherwise

check
connections and

try again.


Executing your project requires the use of Python, which can be invoked via the GUI or the
terminal. It is recommended to

execute any Python file

from

the

terminal with the
sudo

command
because gene
ral errors can result from lack of admin permission.
For example, t
o
execute a
file, the following command will enable you to run the python file ‘myfile.py’:


sudo python myfile.py


Many of the example files provided by GNU Radio also have options that
can be specified with
the execution command. To see if there are any options, use the following command.


sudo python myfile.py

help


That will provide a list of options. Many times, however, files will not have the ability to execute
options.


Dial Tone

Example


This example is known as the “Hello World” of the GNU Radio world, a simple example that
illustrates some of the functions of GNU radio. It i
s known as the dial tone example, where GNU
radio is used to produce a tone that is similar to the dial t
one one would hear from a landline
telephone.


In this example, Python code and the GUI interface of GNU radio will
both be used.


Below is
a diagram

of the dial tone generator.



Figure
2
: Dial tone diagram


Our aim f
or this example is to output the signal of the dial tone generator, which is the
summation of two sinusoids with different frequencies.


Python Coding


Below, we see the
simple Python code for this dial tone generator
.





ECE 4117

5




Figure
3
: Python code for dial tone generator


As mentioned before,

Python is the language used to
connect signal processing blocks together
.
A Python script file is always used to control what is done on the computer in terms of signal
processing and controls the

flow of either receiving or t
ransmitting in terms of the USRP. When
working with GNU radio and the USRP, Python code is always used for control, either directly
or indirectly.

Some tutorials of Python are listed as
follows

Official Python Tutorial


http://docs.python.org/tutorial/


Interactive Python Tutorial

http://www.learnpython.org/


The Python code in figure 3 is explained below. A review of the code shoul
d give a new user the
basic syntax structure of a GNU radio Python Script, as well as explain a few concepts.



Line 1 tells the shell that t
his is a Python file, and Python is needed to execute

the file;



Lines 6 and 7 imports necessary modules that are
needed to interpret different functions.
This similar to the C libraries, where #include is needed in order to use different
functions. gr is a basic GNU radio module and audio is an audio module for GNU radio





ECE 4117

6




Lines 9 to 20 make up and define the class “d
ial tone”



Lines 13 and 14 initialize parameters;



Lines 16 and 17 uses the gr.sig_source_f function to create a float
-
type sine wave with
the same amplitude and sampling rate but with
different frequencies, one at 440 [Hz] and
the other at 640[Hz]



Line 18
defines a sink/destination, which writes its input to the sound card at a sampling
rate of 32[KHz]



Line 19 connects the first signal source output to the input at the first port (port 0) of the
sound sink.



Line 20 connects the
second signal source output t
o the input at the second port (port 1)
of the sound sink.



Lines 22 to 27 indicate the run of the flow graph when the program is executed.

GNU Radio Companion

In addition to writing code, the GNU radio companion

(GRC)

can be used to produce Python
code wit
hout explicitly writing it. It u
tilizes
block diagrams in a GUI interface to produce the
same results of explicitly written Python code. However, it has limited functionality in
comparison to Python coding, thus is not used in more advanced and complex pro
jects.

It should
be, however, sufficient for the example.


Below, is a screenshot of GNU radio compan
ion with the block diagram of our example.









ECE 4117

7



Figure
4
: GNU radio companion
-

Dial Tone Example


Notice that the screenshot is similar to the diagram in figure 2. GNU radio companion allows for
the user to outline the process needed and the program produces the code. GNU radio companion
is thus a powerful tool to the beginner and allows for an immedia
te use of GNU radio, without
needing to learn a large amount of Python.



The program by default gives two blocks, the Options block and the Variable block
containing the variable samp_rate.



The Options block gives you various general options; you can cha
nge this block’s options
(or any block’s options) by double clicking. This block sets some general parameters for
the flow graph. By default, the ID is top_block. This ID gives the name of your Python
script and the name of your class within the script. Th
e project title, author, and
description fields places the information within the Python file that is useful for others
(and sometimes yourself) in identifying the purpose of the script. The generate options
controls the type of code generated. The default

is WX GUI which lets you generate
graphical sinks (Scopes, FFT, etc.) and graphical variable controls (
sliders, selectors
,
etc.). However, if you do not plan on using GUI's, you can select one of the other options.
The run option allows you to control th
e start of a program through a graphical switch.
The default is that the program starts automatically once you run the script.




The next block is a default variable, the samp_rate

variable. This variable automatically
defines the sampling rate for all the signal processing blocks within the GUI.






ECE 4117

8





Placing various blocks is simple. To the right of the
window are various dropdown
menus, with specific categories. Within the different categories are the signal processing
blocks
. For the dial tone example, only three blocks are needed, two sources and one
sink.



The signal sources are located under the sour
ces category and
can be added to the layout
by double clicking on it. Changing the options on the source is the same as changing the
options of option block.



The audio sink is located under the sinks category and is added the same way as before.
Again, th
e options can be changed by double clicking on the block.



Connecting the blocks is simple, just by clicking on the input tab of one block and the
output tab forms the connection.



After the flow process is finished, code can be generated by clicking Build

then Generate.
It will give you the option to save the layout if you haven’t done so. In any case, the code
generated is saved in
the folder where the layout is saved.



After generating
the file, it can be executed through the command line or through the
e
xecute option in the GNU radio companion.

In either case, the results should be the
same for both.

GUI frequency domain and time
domain d
isplay Example


Here, instead of sending a signal to an audio sink, we send

a signal

to a frequency and time
domain display.
The
signal’s frequency components

and the signal in the time domain are
displayed.


A diagram of the process is shown below. Note that the boxes contain the actual pieces of Python
code used to produce them.



Fig
ure
5
: Diagram of displaying signal




The process starts with a signal source, where it goes through a throttle and finally ends up in
two sinks, a scope sink (time domain) and an FFT sink (frequency domain).






ECE 4117

9


The throttle shown
in figure 5 throttles the data coming from the signal source to the sampling
rate. This allows for the computer to control the speed of the data and thus doesn’t overwhelm
the computer. If the throttle was not there, almost all of the free processing power

in the
computer would be dedicated to the display of the signals.


Below, we see the Python code

for the diagram in figure 5.




Figure
6
: Python code for GUI display of signal


The Python code is explained below.



Line 1 tells
the shell that this is a Python file, and Python is needed to execute

the file;



Lines 6 to 8 import necessary modules, where gr is the basic GNU Radio module,

stdgui2
contains

the

window class, fftsink2 is for

the
FFT
-
display, scopesink2 is for

the
Oscil
loscope
-
display, and wx provides some of the constants;



Lines
10

to 1
2

initialize

the

window class;



Line
14

initializes sample rate
;



Line 1
5

and 1
6 initializes
set up a FFT display window;



Lines 18 and 19 set up a oscilloscope display window;



Line 21
defines a sine wave input at 10 kHz with an amplitude 1000;



Line 22 adds a throttle to limit the sample rate to 300 kHz;



Lines 23 to 25 connect all the necessary blocks;



Lines 27 to 29 indicate the run of the flow graph when the program is executed.





ECE 4117

10



Procedures

1.

Open a terminal using the shortcut or through the applications menu.
In the terminal
, type
in
cd Documents
. This should change your current directory to Documents. Now type in
mkdir
xxxx
_lab1
, where you replace xxxx with your name.

Go into that directory by
typing
cd
xxx_lab1
.

Create your dial tone example.py

file as shown in Figure 3

by typing
at the terminal
gedit dial_tone_
example.py

&
.
Type and s
ave your code.
To execute
your code
, type in
sudo python
dial_tone_example.py

or
./dial_tone_e
xample.py

.
Make sure that this is done within your working directory.
If the code is not executable,
use
chmod +x dial_
tone
_
example.py

to
make it

executable.

Try different frequencies
to
generate different dial tones.


2.

Recreate figure 6 by cr
eating a new python file. Type in
gedit gui_scope.py &
in the
terminal
.

Type and save your script.
Execute your code and screen capture the resulting
graphs.
Screen capture
three other waveforms, a square wave, a triangle wave and a
sawtooth wave.


a.

The s
ignal

in figure 6

is generated by the

signal processing block
gr.sig_source_f(sampling rate, waveform type, frequency, amplitude, offset)

b.

Keep the

parameters

the same for all the waveforms, with a sampling rate of
300[KHz], an amplitude of 1000, and a freq
uency of 10[KHz].

c.

The waveform can be changed into a
square, triangle,
or

saw
tooth wave

by
defining the waveform

type gr.GR SQR WAVE, gr.GR TRI WAVE, gr.GR SAW
WAVE,

respectively.


3.

Redo step two for the sine waveform but this time use GNU radio companion.
Recreate
the process from figure 6

(make sure the data type is Float)
. Check to see if the waveform
is the same as step 2. Screen capture the resulting layout.

4.

Construct

a project in
GRC

by sending a dial tone signal to an audio sink as well as to a
frequency and time domain graph. Make sure that the audio and the signal being sent to
the scope and FFT are the same. Take a screenshot of both graphs
and the layout built in
the GRC once you

finish
.

5.

The following equation is a
w
ell
-
known trigonometric formula

of great intere
st and
usefulness

in this course:

Using GRC, construct a signal with an A of 1, B of 2, and with frequencies of 1
[KH
z]
and 10
[KH
z]. Display the res
ults within a scope sink and an FFT sink
. Capture the layout

and the graphs.





ECE 4117

11


6.

After connecting and checking the USRP, go to the terminal and go to the python
directory under the grc and gr
-
utils folder in the gnuradio folder. Run usrp
2_fft.py.
Observe the
resulting window. Capture the graphs.


Report

Construct a standard lab report with the following:



Introduction / Purpose



Methods
/Procedure



Data



Results/Discussion



Conclusion

Be sure to include the following topics:



Discuss the importance of SDR
and

how GNU SDR works through the usage of Python,
GRC and the USRP2.



Discuss each step of the procedure
s
. What is going on in each step?



Include all your data and screenshots when discussing the results from the procedures.



The

importance of the tr
igonome
tric formula from step
5 in reference to
telecommunications.
















ECE 4117

12