Python Block Tags: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
Line 66: Line 66:


<code>in_sig=[np.float32],</code>
<code>in_sig=[np.float32],</code>
<code>out_sig=[np.float32]</code>
<code>out_sig=[np.float32]</code>



Revision as of 12:55, 28 January 2022

Template:TutorialNavigation

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:

TestSignalFlowgraph.png

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

TestSignalTimeSink.png

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:

def __init__(self, threshold=1.0):

Update the block name:

name='Threshold Detector',

Change the input and output types to Float:

in_sig=[np.float32],

out_sig=[np.float32]

Change the variable name from self.example_param:

self.threshold = threshold

Remove the multiplication by self.example_param:

output_items[0][:] = input_items[0]

The code should now look like the following:

DefineBlockThresholdDetector.png

Threshold: Writing the Tags

The next tutorial, Low Pass Filter Example, demonstrates how to use filtering blocks in GNU Radio.