Guided Tutorial Hardware Considerations: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
(remove section on PSK)
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<p><b>This page is my working space while editing Wiki pages.</b></p>
<!-- "Using GNU Radio with Hardware" -->
<hr>
<!-- 16 May 2020 -->
<!-- Guided_Tutorial_Hardware_Considerations -->
== Introduction ==
== Introduction ==


One of the great strengths of GNU Radio is how easy it is to move from simulation to real-world operation. In this tutorial, we will build on what you have learned so far and create a complete FM radio receiver that you can use to listen to your local FM radio stations. Along the way, we will discuss a number of considerations that come into play when working with real-world radio hardware.
One of the more basic (and also incredibly useful) things you can do in GNU Radio with a receiver is to create a software radio spectrum analyzer. This is also a great first step because it will verify that your hardware has basic functionality.
 
== Prerequisites ==
 
* [[SuggestedReading|Our Suggested Reading list]]
* Tutorials:
** [[Guided_Tutorial_Introduction|'''A brief introduction to GNU Radio, SDR, and DSP''']]
** [[Guided_Tutorial_GRC|'''Intro to GR usage: GRC and flowgraphs''']]
** [[Sample_Rate_Tutorial|'''Understanding sample rate''']]


== What Will I Need? ==
== What Will I Need? ==


If you don't have an actual radio to work with, this tutorial is still useful. You can simply use a recording from an actual radio, with nothing done to the data. We have provided a recording, which you can find [https://github.com/gnuradio/gr-tutorial/blob/master/examples/tutorial6/fm_101.8MHz_1Msps.cfile in the gr-tutorials repository]. You can use this in your flowgraph to simulate hardware passing you samples.
There is a large and growing number of SDRs that have GNU Radio support.  They span from very cheap ($20) receivers like the RTL-SDR to very high-performance tens-of-thousands-of-dollars systems. Examples of four popular devices are presented below. Other devices are listed in [[Hardware]].
 
This tutorial will be most useful, though, if you have a piece of radio hardware that you can use with GNU Radio. There is a large and growing number of vendors that provide hardware with GNU Radio drivers, and they span from very cheap $20 receivers to very high-performance tens-of-thousands-of-dollars sort of systems. This tutorial is possible if you have a radio that can only receive, assuming it can tune to the FM bands. Most countries allot between ~87 MHz and ~108 MHz to FM broadcast radio, with some slight variations on the floor and ceiling of the range.
 
== Using UHD Blocks ==
 
The author is using an [https://kb.ettus.com/B200/B210/B200mini/B205mini Ettus Research USRP B200], which uses the [https://github.com/EttusResearch/uhd USRP Hardware Driver (UHD)]. Thus, the hardware sources &amp; sinks used in this tutorial will be [https://github.com/gnuradio/gnuradio/tree/master/gr-uhd/grc gr-uhd] blocks.
 
If you are using a different piece of hardware, you should use the blocks suggested by your hardware vendor. Another set of popular HW blocks, for example, is [http://sdr.osmocom.org/trac/wiki/GrOsmoSDR gr-osmosdr].
 
In order to use UHD blocks, you must have UHD installed. There are a number of ways to install UHD, which you can read about [http://code.ettus.com/redmine/ettus/projects/uhd/wiki here]. If you built GNU Radio from source, you should have seen '''gr-uhd''' in the list of components being built in the CMake output. If GNU Radio successfully found your UHD installation, you should see a group of UHD blocks in the GNU Radio Companion:
 
[[File:grc_uhd_blocks.png|250px|]]
 
== Building an FM Radio Receiver ==
 
In this section, we will build a working FM radio receiver that you can use to listen to your local FM broadcast stations. This content is based on the tutorial slide series prepared by Balint Seeber, available here: [http://files.ettus.com/tutorials/ files.ettus.com/tutorials]
 
=== Creating a Software Radio Spectrum Analyzer ===
 
One of the more basic (but also incredibly useful) things you can do in GNU Radio with a receiver is simply plot a real-time FFT of what your receiver sees. It's a software radio spectrum analyzer. This is also a great first step because it will verify that your hardware is working correctly, and we can use it to identify broadcast stations in your area that we will tune to later on.
 
Create a new flowgraph. Drop a 'UHD: USRP Source' and 'QT GUI Sink' into the canvas. In the previous section, we used static variables for frequency and gain. Here, let's make them changeable on-the-fly. Find the 'QT GUI Range', and add two of them to your flowgraph. Open each of them, and fill out the following fields as appropriate for your hardware. Mine are filled out, below, to match the capabilities of the USRP B200:
 
'''''QT GUI Range 1:'''''
 
* '''ID:''' freq
* '''Label:''' freq
* '''Default Value:''' 1e9
* '''Start:''' 70e6
* '''Stop:''' 6e9
* '''Step:''' 10e6
 
'''''QT GUI Range 2:'''''
 
* '''ID:''' gain
* '''Label:''' gain
* '''Default Value:''' 0
* '''Start:''' 0
* '''Stop:''' 74
* '''Step:''' 1
 
Change your 'samp_rate' variable block value to something interesting. I set mine to 32 MSps. Now, open up the properties for the 'UHD: USRP Source'. Just as we used our variable blocks in the previous section for our radio parameters, we will do the same here. Use the 'ID's from the 'range blocks', above, to set the 'UHD Source' parameters:
 
* '''Samp Rate (Sps):''' samp_rate
* '''Ch0: Center Freq (Hz):''' freq
* '''Ch0: Gain (dB):''' gain
* '''Ch0: Antenna:''' &quot;TX/RX&quot;
* '''Ch0: Bandwidth (Hz):''' samp_rate
 
When you are done, your flowgraph should look something like this:
 
[[File:simple_spec_an.png|500px|]]
 
You can also [https://raw.githubusercontent.com/gnuradio/gr-tutorial/master/examples/tutorial6/gr-tutorial-simple-spec-an.grc download this flowgraph if you want the reference file].
 
You should be all set!
 
=== Using Your Software Radio Spectrum Analyzer ===
 
Go ahead and run your flowgraph. You should see your received spectrum in real-time. Play with the sliders and values, and you should see everything update in real-time, as well. The default GNU Radio QT FFT sink has a number of useful features, such as averaging and peak-hold. Take some time to get familiar with them, now.
 
=== Building a Broadcast FM Receiver ===
 
Now that you have a basic receiver application running with a real-time display of your received data, let's build a useful application! Leave your current flowgraph in place. We will simply add more functionality into the flowgraph rather than replacing what is already there.
 
First, as you might have guessed, we will need to add a few more blocks to the flowgraph. Locate and add the following blocks:
 
* 1x Rational Resampler
* 1x WBFM Receiver
* 1x Audio Sink
* 2x Variable
 
Our flow of data will be the USRP Source -> Rational Resampler -> WBFM Receiver --> Audio Sink. Go ahead and connect the blocks together in that order. GNU Radio will likely highlight a lot of fields in red, indicating errors. We will now go through and configure the parameters, which will resolve these.
 
First, let's set-up those two new variable blocks you added. Create the following two variables with them:
 
'''''Variable:'''''
 
* '''ID:''' audio_interp
* '''Value:''' 4
 
'''''Variable:'''''
 
* '''ID:''' audio_rate
* '''Value:''' 48e3
 
Let's also go back and tune our sample rate variable, which we had previously. Change that variable to '''250e3''' (250 kHz).
 
'''''Variable:''''' samp_rate
 
* '''ID:''' samp_rate
* '''Value:''' 250e3
 
Now, let's configure your other three new blocks.
 
'''''Audio Sink'''''<br />
This block is fairly straight-forward. It takes a stream of samples and plays them through your speakers. This block is installed with the ''gr-audio'' library, which is part of the core GNU Radio distribution. There are a few common / default rates that sound cards use - one of the most common is 48 kHz, which is what we will use, here (hence your configuration of the 'audio_rate' variable, above).
 
Open up the parameters of the Audio Sink. Make the following changes:


* '''Sample Rate:''' audio_rate
== Creating a Software Radio Spectrum Analyzer ==
* '''OK to Block:''' &quot;No&quot;


Now, we just need to turn the samples from your hardware into something that you can play through your speakers! Let's go two blocks back up the chain, next.
This example uses an [[USRP Source]] block, so it should work for almost all USRP SDRs, such as the [https://kb.ettus.com/B200/B210/B200mini/B205mini USRP B series] which have a continuous frequency coverage from 70 MHz to 6 GHz and a maximum sample rate of 56 MHz.  


'''''Rational Resampler'''''<br />
In order to use UHD blocks, you must have UHD installed, although most methods of installing GNU Radio come with UHD. See [https://kb.ettus.com/Building_and_Installing_the_USRP_Open-Source_Toolchain_(UHD_and_GNU_Radio)_on_Linux Installing the USRP] for more info.
The USRP Source is streaming at a rate of 'samp_rate', which we just set to 250e3. The Audio Sink is configured for a sample (consumption) rate of 'audio rate', which is 48e3. But, we have a problem: our source sample rate isn't an integer multiple of the audio rate: 250000 / 48000 = 5.208. To fix this problem, we will 'resample' the stream. Think of resampling here as impedance-matching. We have to convert from the rate of the input stream to the rate of the output stream.


The rational resampler block allows you to adjust the rate of a data stream. It does this by interpolating or decimating to achieve a desired sample rate. Open up the properties of this block, and let's tune the parameters.
Using gnuradio-companion (GRC), build the following flowgraph.<br>


Set the 'Type' to 'Complex-&gt;Complex', thus telling the block to use complex taps. Now we need to tune the actual rates. There is some intelligence built into this block - if we give it the different non-divisable sample rates, the code will calculate the GCD and make it all 'just work' for us. We know the incoming rate is 250 kSps, so let's enter that into 'Decimation'. But, this parameter must be an integer, and our 'samp_rate' is a float. Thus, we need to use the Python function 'int()' to convert it.
[[File:HW_tutorial_fg.png]]


Now we need to set the 'Interpolation' rate. There is a 'gotcha' here, because the WBFM block further down our chain will actually perform an additional decimation-by-four, so we need to actually tell this block to output a rate four times what we want. We know what we actually want is 'audio_rate', so use your 'audio_interp' variable to set the actual rate.
=== Setting Parameters ===


At this point, you should have made these settings:
The USRP Source parameters are set as shown below. 


* '''Type:''' Complex-&gt;Complex (Complex Taps)
Note that we want the Automatic Gain Control (AGC) to be disabled, because we will be browsing spectrum that often will be empty, and it's tough to tell when a signal is present or not when the AGC is constantly adjusting the gain so that the received samples are always at a constant level.  You can think of AGC like something automatically adjusting the volume knob.  AGC being enabled is better suited for applications when you know a signal exists on the frequency you are tuned to.
* '''Interpolation:''' audio_rate * audio_interp
* '''Decimation:''' int(samp_rate)


By leaving the 'Taps' parameter blank, we tell the block that we want it to compute the taps automatically. The 'Fractional BW' parameter affects the shape of the low-pass filter that is generated when no filter taps are supplied. By leaving this set to zero, we will just use a reasonable default.
[[File:HW_tutorial_p1.png|400px]] &nbsp;&nbsp;&nbsp;&nbsp; [[File:HW_tutorial_p2.png|400px]]


'''Note:''' Depending on the accuracy of the clock references in your hardware, you may need to tune the ''Interpolation'' field, above. This is one of the many hardware impairments that you may need to deal with. When I first ran this flowgraph, I heard a lot of noise. I then tuned that ''Interpolation'' rate, and it cleaned up. My final numbers were:
=== Tuning and Using the Spectrum Analyzer ===


* '''Interpolation:''' int(1.05 * (audio_rate * audio_interp))
Set the following parameters in the [[QT_GUI_Sink|QT GUI Sink block]]:
* '''Decimation:''' int(samp_rate)
* Center Frequency (Hz): tuning
* Bandwidth (Hz): samp_rate
* Show RF Freq: Yes
* Show Msg Ports: True


Now, let's configure our last block!
The analyzer can be tuned with the Frequency control widget. If you check the "Display RF Frequencies" box in the run-time GUI window, then the scale on the 'Frequency Display' and 'Waterfall Display' tabs will show the actual frequencies with the tuned frequency in the center.  Keep in mind that the IQ samples coming from the SDR are at baseband, i.e. at 0 Hz, the signal was down-converted to baseband before it was sampled by the Analog to Digital Converter (ADC).


'''''WBFM Receiver'''''<br />
With the message output of the QT GUI Sink block (freq) connected to the message input (command) of the USRP Source, you can double click the display on the Frequency or Waterfall screens and it also will tune to the selected frequency.  This is useful for centering on a signal. Before you click, the frequency will be displayed with the cursor.
At this point, configuring our last block is pretty simple. Open up the block's parameters. There are only two parameters to set: the rate of incoming samples, and the decimation rate. Well, we know both of these. We just configured the output rate of the rational resampler, and we know that rate divided-by-four equals our 'audio_rate'. Thus, you want:


* '''Quadrature Rate:''' audio_rate * audio_interp
You can adjust the Sample Rate to see more or less spectrum at a time (because these SDRs use quadrature sampling, the amount of bandwidth we see at once is equal to the sample rate). This trace shows four FM stations.
* '''Audio Decimation:''' audio_interp


=== A Working Software Radio Broadcast FM Receiver ===
[[File:HW_tutorial_freq.png|800px]]


And that should be it! You should now no longer see any red in your flowgraph, and you should be able to build your flowgraph without errors. The final result should look like this:
== Hardware Considerations ==


[[File:broadcast_fm_rx_flowgraph.png|600px|]]
Setting the sample rate involves several factors to consider.
* The various hardware devices have limits on what sample rates they can deliver. Some, such as the FunCube Pro+, have a fixed sample rate of 192kHz. Setting the flowgraph sample rate must be within the limitations of the device.
* The computer hardware and operating system you are using will set limitations on the data throughput, such as:
** USB2 vs USB3
** processor speed
** number of CPU cores
* If you are using a USRP, data overruns are indicated by the letter 'O' displayed on the terminal screen. These are because the input data stream is producing data faster than the computer can consume it, so it could be due to a USB bottleneck, or the flowgraph is trying to do too much with those samples, or the CPU is not powerful enough, etc. Adjusting the sample rate and/or the input buffer size (where available) may alleviate the problem.


You can also [https://raw.githubusercontent.com/gnuradio/gr-tutorial/master/examples/tutorial6/gr-tutorial-broadcast-fm-rx.grc download this flowgraph, for reference].
== Building an FM Receiver ==


Executing your flowgraph should bring up a GUI that looks something like what you see below. Changing the frequency and tuning to a local broadcast FM station should play the demodulated radio through your computer speakers.
Now that you have a tested input device, you can build an FM Receiver with it. See the following flowgraphs.


[[File:broadcast_fm_running.png|600px|]]<br />
* [https://wiki.gnuradio.org/index.php/File:USRP_FM_fg.png USRP FM Receiver]
* [https://wiki.gnuradio.org/index.php/File:Pluto_FM_fg.png PlutoSDR FM Receiver]
* [https://wiki.gnuradio.org/index.php/File:Broadcast_FM_fg.png FunCubePro+ FM Receiver]
* [https://wiki.gnuradio.org/index.php/File:RTLSDR_receive_fg.png RTL-SDR FM Receiver]


[[Category:Guided Tutorials]]
For audio considerations, see [[Audio_Sink]].

Revision as of 11:43, 7 April 2022

Introduction

One of the more basic (and also incredibly useful) things you can do in GNU Radio with a receiver is to create a software radio spectrum analyzer. This is also a great first step because it will verify that your hardware has basic functionality.

What Will I Need?

There is a large and growing number of SDRs that have GNU Radio support. They span from very cheap ($20) receivers like the RTL-SDR to very high-performance tens-of-thousands-of-dollars systems. Examples of four popular devices are presented below. Other devices are listed in Hardware.

Creating a Software Radio Spectrum Analyzer

This example uses an USRP Source block, so it should work for almost all USRP SDRs, such as the USRP B series which have a continuous frequency coverage from 70 MHz to 6 GHz and a maximum sample rate of 56 MHz.

In order to use UHD blocks, you must have UHD installed, although most methods of installing GNU Radio come with UHD. See Installing the USRP for more info.

Using gnuradio-companion (GRC), build the following flowgraph.

HW tutorial fg.png

Setting Parameters

The USRP Source parameters are set as shown below.

Note that we want the Automatic Gain Control (AGC) to be disabled, because we will be browsing spectrum that often will be empty, and it's tough to tell when a signal is present or not when the AGC is constantly adjusting the gain so that the received samples are always at a constant level. You can think of AGC like something automatically adjusting the volume knob. AGC being enabled is better suited for applications when you know a signal exists on the frequency you are tuned to.

HW tutorial p1.png      HW tutorial p2.png

Tuning and Using the Spectrum Analyzer

Set the following parameters in the QT GUI Sink block:

  • Center Frequency (Hz): tuning
  • Bandwidth (Hz): samp_rate
  • Show RF Freq: Yes
  • Show Msg Ports: True

The analyzer can be tuned with the Frequency control widget. If you check the "Display RF Frequencies" box in the run-time GUI window, then the scale on the 'Frequency Display' and 'Waterfall Display' tabs will show the actual frequencies with the tuned frequency in the center. Keep in mind that the IQ samples coming from the SDR are at baseband, i.e. at 0 Hz, the signal was down-converted to baseband before it was sampled by the Analog to Digital Converter (ADC).

With the message output of the QT GUI Sink block (freq) connected to the message input (command) of the USRP Source, you can double click the display on the Frequency or Waterfall screens and it also will tune to the selected frequency. This is useful for centering on a signal. Before you click, the frequency will be displayed with the cursor.

You can adjust the Sample Rate to see more or less spectrum at a time (because these SDRs use quadrature sampling, the amount of bandwidth we see at once is equal to the sample rate). This trace shows four FM stations.

HW tutorial freq.png

Hardware Considerations

Setting the sample rate involves several factors to consider.

  • The various hardware devices have limits on what sample rates they can deliver. Some, such as the FunCube Pro+, have a fixed sample rate of 192kHz. Setting the flowgraph sample rate must be within the limitations of the device.
  • The computer hardware and operating system you are using will set limitations on the data throughput, such as:
    • USB2 vs USB3
    • processor speed
    • number of CPU cores
  • If you are using a USRP, data overruns are indicated by the letter 'O' displayed on the terminal screen. These are because the input data stream is producing data faster than the computer can consume it, so it could be due to a USB bottleneck, or the flowgraph is trying to do too much with those samples, or the CPU is not powerful enough, etc. Adjusting the sample rate and/or the input buffer size (where available) may alleviate the problem.

Building an FM Receiver

Now that you have a tested input device, you can build an FM Receiver with it. See the following flowgraphs.

For audio considerations, see Audio_Sink.