Tools4SDR   A new version of the website is under development, powered by MediaWiki! You can already use it here.
 
 
 
 

Valid HTML 4.01 Transitional

A simple GNU Radio/USRP scheme: Spectrum analyzer of the UHF bands

This page describe a very simple example of GNU Radio scheme: a spectrum analyzer of the UHF bands.

Spectrum analyzer with USRP and GNU Radio

1. What is requiered ?

  • An USRP with the TVRX daughterboard
  • A (working version) of gnuradio 3.1.3
  • This script has been tested with cygwin/windows XP
To launch the script, use the command ./FFT_Analyzer.py

2. Code structure

The code is composed of two files (it can be downloaded at the bottom of this page - [Spectrum_analyzer.zip]):
  • FFT_Analyzer.py : the main script. It creates the frame and the USRP object
  • Layout.py : it creates the panel (IHM). It also controls the USRP
The main part of the code are described in this page.

2.1. USRP object creation

This portion of code is place in the file FFT_Analyzer.py. It initializes the USRP:
self.usrp_obj = usrp.source_c()
usrp_decim = 8
self.usrp_obj.set_decim_rate(usrp_decim)

rx_subdev_spec = pick_subdevice(self.usrp_obj)
self.usrp_obj.set_mux(usrp.determine_rx_mux_value(self.usrp_obj, rx_subdev_spec))
self.subdev = usrp.selected_subdev(self.usrp_obj, rx_subdev_spec)
The USRP object is created first. The first part of the code concerns the motherboard. The source_c function means that we expect the USRP to deliver complex samples. Then the decimation rate of the ADC is set to 8. It means that we want signals with 8MHz bandwidth.

The second part of this code initialize the TVRX daughterboard. If is only selected. Its control is done from the second file.

2.2. GNU Radio scheme

The GNU Radio scheme is set up in the file Layout.py. The code is the following one:
# Graph creation
self.fg = gr.flow_graph()

# FFT output object
fft_src = fftsink.fft_sink_c (self.fg, panel_fft, title="Spectrum", fft_size=fft_size,sample_rate=sampling_freq, baseband_freq=0,ref_level=10, y_per_div=20)

# Set the board gain
g = app.subdev.gain_range()
gain = float(g[1]-g[0])*0.5+g[0]
app.subdev.set_gain(gain)

# change RF frequency
target_freq = (474+(Channel-21)*8)*1e6
r = usrp.tune(app.usrp_obj, 0, app.subdev, target_freq)

# Software AGC
agc = gr.agc_cc(1e-7, 1, 1)

# Connect the chain
self.fg.connect(app.usrp_obj, agc,fft_src)

# GO
self.fg.start()
The target_freq variable takes the center frequency value of the channel Channel.

2.3. GNU Radio scheme updates

The only parameters that can be changed with this first example is the channel. This control is also done in the file Layout.py:
# Update the RF frequency
Channel = int(self.Spin_Ampl.GetValue())
target_freq = (474+(Channel-21)*8)*1e6
r = usrp.tune(self.parent.usrp_obj, 0, self.parent.subdev, target_freq)

# Update the gain
g = self.parent.subdev.gain_range()
gain = float(g[1]-g[0])*0.5+g[0]
self.parent.subdev.set_gain(gain)

3. Troubleshooting

If you have the error, can't import gr, check your python path (see the installation page of gnuradio).

If the script can't find the USRP (at least 2-3 consecutive times), despite you are sure it is correctly pluged, you probably don't have the correct drivers installed. See the driver installation page.

Attached files:

[ AF1 ] Spectrum_analyzer.zip
About | Contact | Site map | Support