Open Cloud Blog

Openstack, Contrail and more

Sound generator using Gnuradio

Gnuradio is a powerful tool to process all sorts of signals using wave functions. This covers AM, FM, all sorts of modulation and much more.

A simple starting point to play with Gnuradio is audio. It’s easy to built a tool to generate an audio tone, vary the frequency using a slider and output this using the soundcard of a PC.

Install Gnuradio

The first step is to install gnuradio and the necessary libraries. You should install gnuradio and all libgnuradio* libraries, and also libvolk.

Start Gnuradio Designer

The next step is to start Gnuradio designer

The GUI has 3 areas. The large one is the area which shows the built signal flow, the area on the right are the components (blocks), which can be used. The area on the bottom is a message window.

Define the components

We need the following components to create our „sound generator“:

  • A signal source from the sources block. This component has two input values, the amplitude and the frequency. Use the variables defined in the two widgets defined below.
  • A WX GUI Slider from the WX GUI Widgets block to vary the frequency of the signal source. Default value=5000, min=10 and max=20000
  • WX GUI Slider from the WX GUI Widgets block to vary the amplitude of the signal source. Default value=0.7, min=0.0 and max=1.0
  • A Noise Source from the sources block. This is added to create a more realistic scenario. Use the variable of the widget below.
  • WX GUI Slider from the WX GUI Widgets block to vary the amplitude of the noise source. Default value=0.01, min=0.0 and max=1.0
  • An Add from the operators block. This is used to add the output from the signal source and the noise source.
  • A Complex to Real conversion from the Type Conversions block. This is needed to feed real values to the sound sink. The input is connected to the add output.
  • A Audio Sink from the Sinks block. This sends the output signal to the soundcard. The input is connected to the Complex to Real output.
  • A graphical display WX GUI Waterfall Sink from the WX GUI Widgets block. This shows the time/FFT spectrum. Set the FFT size to 2048. The input is connected to the add output.
  • A graphical display WX GUI FFT Sink from the WX GUI Widgtes block. This shows the FFT spectrum. Set the FFT size to 2048, peak hold to on and average alpha to 0.1 . The input is connected to the add output.

The variable samp_rate should be set to the highest possible value for your soundcard. Most modern PCs accept a sampling rate of 192000. Setting this to high values reduces distortions of the output signal.

Now the signal flow area should look like the following screenshot:

Gnuradio Soundgenerator

Gnuradio Soundgenerator

 

Then you should save this setup using „save“.  If you do not like to create the generator by yourself, you can use the saved Gnuradio configuration file frequency-generator.grc.

Run the generator

Use Build –> Execute to start the Sound generator. A new windows is opened, and you should now hear a tone (5000 Hz) out of the PC speaker/headphone. The window looks like:

Gnuradio Run Window

Gnuradio Run Window

The shown controls and graphics are:

  • The slider Noise on the top defines the amplitude of the signal noise. Do not change it at the beginning.
  • The second slider Loudness controls the amplitude of the audio signal source.
  • The third slider Frequency is the real interesting one. If you move the slider slowly around, then the height of the tone changes.

The two graphics show the FFT of the signals.

Now it’s quite easy to extend the setup.

Python

When you select Build –> Execute, GnuRadio generates a python script in the current directory with the name top_block.py . The code generated by Gnuradio from the example is:

If you save this code, there is no need to run the GnuRadio construction tool. GnuRadio provides a powerful python API.

Updated: 03/01/2014 — 22:03
Open Cloud Blog © 2013-2018 Impressum Datenschutzerklärung Frontier Theme