Hier Blocks and Parameters: Difference between revisions

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


[[File:EditFrequencyParameterProperties.png|500px]]
[[File:EditFrequencyParameterProperties.png|500px]]
Add the ''frequency'' parameter to the Signal Source ''Frequency'' property. The flowgraph should now look like:
[[File:HierBlockSampRateFrequencyParameters.png|500px]]


== Input and Output Ports ==
== Input and Output Ports ==

Revision as of 18:11, 12 January 2022

Template:TutorialNavigation

This tutorial describes how to create a hierarchical block, or Hier block, in GRC. The previous tutorial, Creating Your First Block, demonstrates how to create your first GNU Radio block using the Embedded Python Block.

Creating the Initial Flowgraph

A hier block is used to encapsulate and simplify multiple GNU Radio blocks into a single block. The example hier block will be a frequency shifter block which multiplies a Signal Source against an input signal.

The first step is creating the flowgraph. Drag and drop the following blocks into the workspace:

  1. Signal Source
  2. Multiply
  3. Noise Source
  4. Low Pass Filter
  5. Throttle
  6. QT GUI Frequency Sink
  7. QT GUI Range

Connect the blocks:

StartingFlowgraphHierBlock.png

Update the QT GUI Range properties:

  • Id: frequency
  • Default Value: 0
  • Start: -samp_rate/2
  • Stop: samp_rate/2

Update the Low Pass Filter properties:

  • Cutoff Freq (Hz): samp_rate/4
  • Transition Width (Hz): samp_rate/8

Create The Hier Block

Click and drag in the workspace window to select the Signal Source and Multiply blocks, as well as the connection between them:

ClickAndDragSelect.png


Right-click on the highlighted blocks and select More > Create Hier:

ClickCreateHier.png


A flowgraph will be created in a new GRC tab:

NewHierBlock.png


Double-click the Options block and edit the properties. Update the properties:

  • Id: FrequencyShifter
  • Title: Frequency Shifter Block
  • Generate Options: Hier Block

OptionsSelectHierBlock.png

The remaining properties will then change, showing the Category:

ShowGRCHierBlocksCategory.png

The Category is where the block can be found in the block library on the right hand of GRC. The hier block will be located under GRC Hier Blocks, instead of Core where the rest of the GNU Radio blocks are located.

Save the flowgraph.

Variables vs Parameters

A variable is different than a parameter in GNU Radio. A parameter creates an interface for the hier block to accept a value from an external source, where as a variable can only be accessed from within a hier block.

For example, the samp_rate variable can only be accessed from within the hier block:

HierBlockWithVariable.png


The samp_rate needs to be a parameter that way it can be passed in from another block in the larger flowgraph. Delete the samp_rate variable and add a Parameter block into the GRC workspace:

AddParameterToHierBlock.png

Edit the Parameter properties:

  • Id: samp_rate
  • Label: Sample Rate
  • Type: Float

EditParameterProerties.png

Add a second Parameter:

  • Id: frequency
  • Label: Frequency
  • Type: float

EditFrequencyParameterProperties.png


Add the frequency parameter to the Signal Source Frequency property. The flowgraph should now look like:

HierBlockSampRateFrequencyParameters.png

Input and Output Ports

A pad is used to specify input and output ports on a hier block. Add a Pad Source and Pad Sink to the flowgraph to act as the in and out ports:

AddPadSourcePadSink.png

Generate the Hier Block Code

Click Generate the flow graph to create the hier block source code:

ClickGenerateFlowgraph.png


A Python .py file and YAML .yml file will be created in your home directory:

/home/$USER/.grc_gnuradio/

HierBlockPyYml.png


GRC needs to update it's internal memory of the blocks it has access to before the Frequency Shifter block can be used in a flowgraph. Click the Reload Blocks button:

ClickReloadBlocks.png

You'll notice that there is a new category GRC Hier Blocks in the block library below Core, and the Frequency Shifter Block can be used in flowgraphs:

GRCHierBlocksUpdated.png