Types of Blocks

Introduction
To take advantage of the gnuradio framework, users will create various blocks to implement the desired data processing. There are several types of blocks to choose from:


 * Synchronous Blocks (1:1)
 * Decimation Blocks (N:1)
 * Interpolation Blocks (1:M)
 * Basic (a.k.a. General) Blocks (N:M)

Synchronous Block
The sync block allows users to write blocks that consume and produce an equal number of items per port. A sync block may have any number of inputs or outputs. When a sync block has zero inputs, its called a source. When a sync block has zero outputs, its called a sink.

An example sync block in C++:

Some observations:


 * noutput_items is the length in items of all input and output buffers
 * an input signature of gr_make_io_signature(0, 0, 0) makes this a source block
 * an output signature of gr_make_io_signature(0, 0, 0) makes this a sink block

An example sync block in Python:

The input_items and output_items are lists of lists. The input_items contains a vector of input samples for every input stream, and the output_items is a vector for each output stream where we can place items. Then length of output_items[0] is equivalent to the noutput_items concept we are so familiar with from the C++ blocks.

Some observations:
 * The length of all input vector and all output vectors is identical
 * in_sig=None would turn this into a source block
 * out_sig=None would turn this into a sink block. In this case, use len(input_items [0]) since output_items is empty!
 * Unlike in C++ where we use the gr::io_signature class, here we can just create a Python list of the I/O data sizes using numpy data types, e.g.: numpy.int8, numpy.int16, numpy.float32

Decimation Block
The decimation block is another type of fixed rate block where the number of input items is a fixed multiple of the number of output items.

An example decimation block in c++

Some observations:


 * The gr_sync_decimator constructor takes a 4th parameter, the decimation factor
 * The user should assume that the number of input items = noutput_items*decimation

An example decimation block in Python:

Some observations:


 * The set_relative_rate call configures the input/output relationship
 * To set an interpolation, use self.set_relative_rate(interpolation)
 * The following will be true len(input_items[i]) = len(output_items[j])*decimation

Interpolation Block
The interpolation block is another type of fixed rate block where the number of output items is a fixed multiple of the number of input items.

An example interpolation block in c++

Some observations:


 * The gr_sync_interpolator constructor takes a 4th parameter, the interpolation factor
 * The user should assume that the number of input items = noutput_items/interpolation

An example interpolation block in Python:

Basic Block
The basic block provides no relation between the number of input items and the number of output items. All other blocks are just simplifications of the basic block. Users should choose to inherit from basic block when the other blocks are not suitable.

The adder revisited as a basic block in C++:

Some observations:


 * This class overloads the general_work method, not work
 * The general work has a parameter: ninput_items
 * ninput_items is a vector describing the length of each input buffer
 * Before return, general_work must manually consume the used inputs
 * The number of items in the input buffers is assumed to be noutput_items
 * This behaviour can be altered by overloading the forecast method but is not mandatory

The adder revisited as a basic block in Python: