Streams and Vectors

From GNU Radio
Revision as of 14:19, 15 March 2022 by Mattcarrick (talk | contribs) (→‎Vectors: tech writer & making easier for ESL to understand)
Jump to navigation Jump to search
Beginner Tutorials

Introducing GNU Radio

  1. What is GNU Radio?
  2. Installing GNU Radio
  3. Your First Flowgraph

Flowgraph Fundamentals

  1. Python Variables in GRC
  2. Variables in Flowgraphs
  3. Runtime Updating Variables
  4. Signal Data Types
  5. Converting Data Types
  6. Packing Bits
  7. Streams and Vectors
  8. Hier Blocks and Parameters

Creating and Modifying Python Blocks

  1. Creating Your First Block
  2. Python Block With Vectors
  3. Python Block Message Passing
  4. Python Block Tags

DSP Blocks

  1. Low Pass Filter Example
  2. Designing Filter Taps
  3. Sample Rate Change
  4. Frequency Shifting
  5. Reading and Writing Binary Files

SDR Hardware

  1. RTL-SDR FM Receiver
  2. B200-B205mini FM Receiver

This tutorial describes the differences between a Stream and a Vector.

The previous tutorial, Packing Bits, describes how to pack a stream of bits into the byte or char data type, and then unpack them back into a stream of bits. The next tutorial, Hier Blocks and Parameters, demonstrates how to create a Hierarchical Block and using Parameters.

Streams

Blocks in GNU Radio can be connected using either streams or vectors. A stream carries 1 sample for each time instance. A stream produces serialized data. A stream must have a data type, such as Float 32 or Byte.

The Signal Source block produces a Complex Float 32 stream. The output of the block at each time instance contains 1 complex sample:

SignalSourceStreamExample.png

The figure shows there is a single complex sample at each time instance.

Vectors

Vectors carry multiple samples per time instance, representing data in parallel. A stream represents a scalar at each time instance, a vector represents an array at each time instance.

GRC uses lighter colors to represent streams and darker colors to represent vector outputs:

StreamVectorDarkerColors.png

Streams to Vector Flowgraph Example

The following example will describe how to convert a stream to a vector and back to a stream. Two complex sinusoid streams will be converted to a 2-element vector, displayed, and then converted back to their independent streams.

Add two Signal Source blocks to the workspace:

TwoSignalSourceBlocks.png


Edit the parameters of the second Signal Source to have a frequency of 100 and amplitude of 0.1 to distinguish it visually from the first Signal Source:

ChangeFrequencyAmplitudeSignalSource.png

Click OK to accept the parameters.

Search for the Streams to Vector block, drag it into the workspace and connect it to the Signal Source blocks:

ConnectStreamsToVector.png

The Streams to Vector block acts as an interleaver, taking the two serial stream inputs and converting them to a two-dimensional vector output. The block takes the sample from the in0 port and places it into the first element in the output vector, and then takes the a sample from the in1 port and places into the second element in the vector.

Search for the Vector to Stream block which will serialize the vector data, and then add three QT GUI Time Sink blocks:

InterleavedSignalSourceWithTimeSinks.png


Edit the titles for the three QT GUI Time Sink blocks so the can be distinguished from one another. First, edit the block connected to the Signal Source with frequency 1000 and amplitude 1 to have the title Signal Source A:

TimeSinkAProperty.png

SignalSourceATimeSink.png


Now edit the QT GUI Time Sink connected to the second Signal Source with frequency 100 and Amplitude 0.1 to have the title Signal Source B:

TimeSinkBProperty.png

SignalSourceBTimeSink.png


Finally, edit the QT GUI Time Sink connected to the Vector to Stream block to have the title Interleaved Signal Sources:

TimeSinkInterleavedProperty.png

InterleavedSignalSourceTimeSink.png


Running the flowgraph will now display three time sinks, Signal Source A, Signal Source B, and Interleaved Signal Sources. Note that the Interleaved Signal Sources time sink displays interleaved samples from Signal Source A and Signal Source B:

TimeSinkSignalSources.png


Vector to Streams Flowgraph Example

The following example will deinterleave the vectorized data and convert it back into two streams.

Search for the Vector to Streams block, add it to the workspace, and connect it to the Streams to Vector block:

AddVectorToStreamsBlock.png


The Vector to Streams block deserializes vector samples and converts them into streams, performing the inverse operation to the Streams to Vector block. Right-click and delete the arrows connecting the two Signal Source blocks to the QT GUI Time Sink blocks:

DeleteTimeSinks.png


Then move and reconnect the two QT GUI Time Sink blocks to the Vector to Streams outputs:

ReconnectedTimeSinks.png


Running the flowgraph shows the vectorized samples have been separated back into the two correct streams:

DeserializedTimeSink.png


The next tutorial, Hier Blocks and Parameters, demonstrates how to create a Hierarchical Block and using Parameters.