You are on page 1of 7

Using GNU Radio Companion to receive AM signal

Abhishek Bhatta

June 27, 2017

1 Aim
The objective of this project is to use GNU Radio to perform amplitude modulation (AM)
and demodulation with the capability to use a RTL-SDR USB dongle for capturing real
sampled data.

2 Description
This document is a guide to perform amplitude modulation and, demodulation using GNU
Radio; open source tool-kit for Software Defined Radio (SDR) applications. The first part
of this practical uses a data file pre-recorded at AM broadcast band. The data file will
be provided to you. It is assumed that you are using a GNU Radio installation on an
Ubuntu platform and are familiar with basic Linux commands. You are also expected to
be knowledgeable of fundamental signal processing operations such as using an fast fourier
transform (FFT).

3 Procedure
1. Open a terminal window, create a working directory by typing: mkdir Prac1-AM and
go into the directory by typing: cd Prac1-AM.

2. Once inside the directory type: gnuradio-companion in the terminal to open the
graphical user interface of GNU Radio. Click on the + to create a new flowgraph.
To save it select “File− >Save As” and put in the name of the file e.g. Prac1AM.

3. Construct a basic flow graph with a source, throttle (if working without sampling
hardware) and a sink. To find these select one of the items in the list on the right (to
search an object click on the search icon from the toolbar at the top of the window
or press ctrl−F). In this case use File source, Throttle and QT GUI frequency sink as
shown in Figure 1. To get each block left click and drag the blocks over to the canvas.

1
Double click on each of the blocks to set the parameters. The basic parameters to be
set here are as follows:

– Options block, ID: top block (or any name you like) Generate Options: QT GUI
– variable block, ID: samp rate, Value: 256e3
– File Source block, ID: file source 0 ,File: (location of the file “am rx.dat” provided
to you), Output Type: Complex, Repeat: Yes, Vec Length: 1. The file can be
downloaded from (http://forge.ee.uct.ac.za/arch/gnuradio/).
– Throttle block, ID: throttle 0, Type: Complex, Sample Rate: samp rate, Vec
Length: 1.
– QT GUI Sink block, ID: qtgui sink 0, Type: Complex, Name: ”Sink Block”,
FFT Size: 1024, Window Type: Blackman-harris, Bandwidth (Hz): samp rate,
Select the plots you want to see by choosing the options on or off.

4. Keep every other option as default, save and run the file. Inspect the output and make
a note of what happens when you change some of the parameters. To connect the
blocks, left click on the blue output box (e.g. on the blue block on file source) and
then click on the target port (e.g. the blue block on the left of the throttle). The arrow
should then display showing the connection has been made. click generate flowgraph
to generate the python file that represents your block diagram design (this is the one
that then gets run).

Figure 1: Construct a basic flow graph

NB: Remember to save your work occasionally, as things may be lost if the program
crashes. You may want to save different versions of your .grc file.

5. The data was recorded with a SDR receiver named USRP and the center frequency of
the device was set to 710KHz. Your Task:

– Add a new variable block.


– Name the new block added and set the value to 710e3.
– Use this value at the QT GUI Sink block as a variable and set the Center Frequency
(Hz).

2
Figure 2: Construct a basic flow graph

Run the file and inspect the output. Figure 2 contains the expected output.

6. If you observed the previous plot properly, you would have noticed that the frequency
span of the FFT plot is the same as the sample rate used (256 KHz). While the
sample rate of the original data cannot be changed, it can be re-sampled to increase
or decrease the sample rate. In this case we will decrease the sample rate by using
decimation. Modify the flow graph as follows to perform decimation:

– Add a new variable block, ID: resamp factor, Value: 4.


– Add the Rational Resampler block, ID: rational resampler 0, Interpolation: 1,
Decimation: resamp factor.

This will divide the incoming data by the resamp factor, which in this case is 4 and
give a sample rate of 256e3/4 = 64e3. Place this block as shown in Figure 3.

7. Now the Throttle and QT GUI Sink will need new sample rates to match the Rational
Resampler, thus divide the sample rate variable in both the blocks by the resamp factor.
Run and observe the difference in the plots from the previous setup.

Figure 3: Extension of the basic flow graph

8. Next we need to insert a filter to get rid of the frequencies that are not necessary for
this design. Since the captured data moved the center frequency from 710 KHz to 0

3
KHz (That is the reason why we needed to add a variable called center freq) adding
a low pass filter should give the necessary frequency range. The settings for the filter
are as below:

– Add a Low Pass Filter block, ID: low pass filter 0, FIR Type: Complex − >
Complex (Decimating), Decimation: 1, Gain: 1 (Set the gain according to
your requirement, but 1 will also work), Sample Rate: samp rate/resamp factor,
Cutoff Freq: 5000, Transition Width: 100, Window: Hamming (Choose different
and see the differences in output). The Beta value is needed only for the Kaiser
window, read more about this window to find out what it means (e.g. https:
//www.dsprelated.com/freebooks/sasp/Kaiser_Window.html).

9. Save the plot, execute and observe the changes in the output compared to the previous
setup. Figure 4 shows how the flow graph should look.

Figure 4: Filtered output

10. Now, since the filtered signal is available, it is time to demodulate the signal. For
the AM case, the baseband signal is the envelope of the magnitude of the modulated
signal. Use a block called Complex to Mag in between the Low Pass Filter and
Throttle blocks. This is necessary as we are eventually going to connect the final
output to an audio sink block that takes the magnitude as input instead of the complex
data.

11. You may notice some of the arrows turn red, this means the input type to the block
does not match the expected input. Double click on the Throttle block and make
Type: float. Repeat the same for all the blocks after Complex to Mag. Figure 5 shows
how the flow graph should look.

4
Figure 5: Demodulated AM

12. Since it is an AM signal, the next step is to listen to it. Thus the sample rate needs
to be changed again to match the audio card sample rate. Most of the current audio
cards require a sample rate of 44.1 KHz but all of them work with a sample rate of
48 KHz. To do this we need to remove the Throttle block and add another Rational
Resampler block.

13. The sample rate from the Complex to Mag block is 64KHz, in orderto convert it to
64 × 3
48 KHz we need to divide it by 4 and multiply it by 3. = 48 KHz. Thus the
4
settings for the new Rational Resampler block are as follows:

– ID: rational resampler 1, Type: Float − > Float (Real Taps), Interpolation: 3,
Decimation: resamp factor.

14. To listen to the signal we need an Audio Sink block in parallel to the QT GUI Sink.
Set up the Sample Rate: 48 KHz.

15. Execute the flow graph, you will see the plots and may or may not be able to listen to
any audio. This is mostly because the value of the samples going to the speaker are
large and we need to attenuate the signal. To do that we will use a Multiply Const
block along with a QT GUI Range block. The settings for the blocks that I needed to
listen to the audio are as follows:

– QT GUI Range block, ID: audio range, Default Value: 0.001, Start: 0, Stop: 1,
Step: 0.001, Widget: Counter + Slider, Minimum Length: 200.
– Multiply Const block, Constant: audio range, Vec Length: 1.

Figure 6 shows the final flow graph necessary to demodulate the AM signal.

5
16. Next, if you have a SDR receiver, replace the File Source block with the appropriate
source block for the receiver hardware and set the parameters according to your
requirements. Have Fun!

Figure 6: Listen to demodulated AM Audio

Appendix I
You can also create your own AM Transmitter and Receiver in GNU Radio. Figure 7
gives a basic flow of how to do that. Based on your understanding of this prac, try
to make the transmitter and receiver using an audio file in *.wav format. You can use
“around the world-atc.wav” which is provided to you along this prac or any other

6
Figure 7: AM Modulator and Demodulator

4 Useful Websites

GNURadio Live cd : http://gnuradio.org/redmine/projects/gnuradio/


wiki/GNURadioLiveDVD

GNU Radio tutorials : http://gnuradio.org/redmine/projects/gnuradio/


wiki/Guided_Tutorials

RTL-SDR Tutorials : http://sdr.osmocom.org/trac/wiki/rtl-sdr

Maintainer and Lead : http://www.trondeau.com/


Developer of GNU
Radio

GNU Radio User : http://gnuradio.org/doc/doxygen/index.html


Guide

You might also like