Python Block Tags

TODO:
 * use a threshold
 * set a tag when threshold exceeded
 * feed in a noise source (average it?)
 * tag blocker
 * block to read tag, then change the output
 * make a picture associating tags with samples

The flowgraph will use two Embedded Python Blocks for detecting when the input signal crosses the threshold and setting a tag for it and then reading the tag and updating an output counter with the time since the last detection.

The previous tutorial, Python Block Message Passing demonstrates how to send and receive messages using the Embedded Python Block. The next tutorial, Low Pass Filter Example, demonstrates how to use filtering blocks in GNU Radio.

Tags Overview
Tags are a way to convey information alongside digitized RF samples in a time-synchronous fashion. Tags are particularly useful when downstream blocks need to know upon which sample the receiver was tuned to a new frequency, or for including timestamps with specific samples.

Where messages convey information in an asynchronous fashion with no clock-based time guarantee, tags are information which are associated with specific RF samples. Tags ride alongside digitized RF samples in data streams and vectors, including Complex Float 32, Float 32, Byte and all of the other formats.

More information about tags can be found here: Stream Tags

Creating Test Signal
A test signal is needed. Begin by dragging in the blocks for the input signal:
 * GLFSR Source
 * Repeat
 * Multiply Const
 * Add Const
 * Single Pole IIR Filter
 * Throttle
 * QT GUI Time Sink

Change the following parameters:
 * GLFSR Source, Degree: 32
 * Repeat, Interpolation: 128
 * Multiply Const, Constant: 0.5
 * Add Const, Constant: 0.5
 * Single Pole IIR Filter, Alpha: 0.05
 * QT GUI Time Sink
 * Number of Points: 2048
 * Y min: 0
 * samp_rate Variable, Value: 3200

Change all of the blocks to be Float input and output. Connect them all according to the following flowgraph:



Run the flowgraph. A randomized sequence of filtered 0s and 1s is generated:



Threshold Detector: Defining the Block
Drag in a Python Block and double-click it to edit the source code.

Change the example_param variable name:

Update the block name:

Change the input and output types to Float:

Change the variable name from self.example_param:

Remove the multiplication by self.example_param:

The code should now look like the following:



Save the code (CTRL + S) and return to GRC. The block will now look like the following:



If the block did not update properly there may be a problem with the Python syntax. Double-click the Embedded Python Block to view any potential syntax errors. The following image gives an example of where the synax errors are located:



Add a Virtual Sink and Virtual Source block to the flowgraph. Change the following block properties:
 * Threshold Detector, threshold: 0.75
 * Virtual Sink, Stream ID: signal
 * Virtual Source, Stream ID: signal

Connect the blocks according to the flowgraph:



Threshold: Writing the Tags
The next tutorial, Low Pass Filter Example, demonstrates how to use filtering blocks in GNU Radio.