Flowgraph Python Code

Dial Tone Flowgraph
The following example flowgraph implements a dial-tone:

https://raw.githubusercontent.com/gnuradio/gr-tutorial/master/examples/tutorial3/images/tutorial_three_1.png

When we click the Generate button from within GRC, the terminal tells us that it produced a &quot;tutorial_three_1.py&quot; file, so let's open it to examine the code.

Once GRC has created a Python file, the user is free to modify it in any desired manner, such as changing parameters, sample rate, and even connections among the blocks.

To execute this file from a terminal, enter:

Warning: After the Python file has been modified, running GRC again with that flowgraph will wipe out your changes!

Dial Tone Python Code Dissected
Let's examine pertinent lines of the code:

This tells the shell to use the Python3 interpreter to run this file.

These tell Python what modules to include. We must always have gr to run GNU Radio applications. The audio sink is included in the audio module and the signal source is included in the analog module.

Define a class called "tutorial_three_1" which is derived from another class, gr.top_block. This class is basically a container for the flow graph. By deriving from gr.top_block, we get all the hooks and functions we need to add blocks and interconnect them.

Only one member function is defined for this class: the function "init", which is the constructor of this class.

The parent constructor is called.

Variable declaration for sample rate.

There are 2 inputs to the Audio Sink block. The first line connects the only output of analog_sig_source_x_0 (440 Hz waveform) to the first input of audio_sink_0. The second line connects the only output of analog_sig_source_x_1 (350 Hz waveform) to the second input of audio_sink_0.