Variables in Flowgraphs: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:
This page describes the fundamentals of a flowgraph: how to make and edit variables, and data types. The flowgraph from the previous guide ([[Your_First_Flowgraph|Your First Flowgraph]]) will be used as a reference.
This page describes the fundamentals of a flowgraph: how to make and edit variables, and data types. The flowgraph from the previous guide ([[Your_First_Flowgraph|Your First Flowgraph]]) will be used as a reference.


=='''Variables'''==
=='''Basic Variables'''==


A GNURadio flowgraph is a ''.py'' Python file. Just as Python code can have variables so too can a GNURadio flowgraph by using the ''Variable'' block.
A GNURadio flowgraph is a ''.py'' Python file. Just as Python code can have variables so too can a GNURadio flowgraph by using the ''Variable'' block.
Line 27: Line 27:
Click ''OK'' to save.
Click ''OK'' to save.


Double-click the ''Signal Source'' block to :
Double-click the ''Signal Source'' block to modify its parameters:


[[File:SignalSourceProperties.png|500px]]
[[File:SignalSourceProperties.png|500px]]


You'll notice that ''samp_rate'' is the variable being used for the Sample Rate but Frequency is hard coded to 1000. Enter ''frequency'' into the Frequency field:
[[File:SignalSourceFrequency.png|500px]]
Click ''OK'' to save and re-run the flowgraph.
=='''Dependent Variables'''==
Variables can be dependent on one another in the same way variables in Python can be derived from other variables.


You'll notice that ''samp_rate'' is the variable being used for the Sample Rate but Frequency is hard coded to 1000.


TODO:
TODO:

Revision as of 18:45, 3 January 2022

This page describes the fundamentals of a flowgraph: how to make and edit variables, and data types. The flowgraph from the previous guide (Your First Flowgraph) will be used as a reference.

Basic Variables

A GNURadio flowgraph is a .py Python file. Just as Python code can have variables so too can a GNURadio flowgraph by using the Variable block.

Every new flowgraph starts with the samp_rate variable:

VariableSampRate.png


GNURadio blocks are implemented as functions and can take parameters which modify their behavior. All of the blocks in the flowgraph above use samp_rate as a parameter. Create a new variable block by dragging and dropping it from the block library on the right:

NewVariableBlock.png


Double-click the variable_0 block to view and modify it's parameters.

VariableProperties.png


The Id field is the name of the variable. The variable is going to represent the frequency of the Signal Source block, so edit the name to frequency. Now edit the value to 4000.

FrequencyVariable.png

Click OK to save.

Double-click the Signal Source block to modify its parameters:

SignalSourceProperties.png

You'll notice that samp_rate is the variable being used for the Sample Rate but Frequency is hard coded to 1000. Enter frequency into the Frequency field:

SignalSourceFrequency.png


Click OK to save and re-run the flowgraph.



Dependent Variables

Variables can be dependent on one another in the same way variables in Python can be derived from other variables.


TODO: make/edit variables complex vs float (blue vs orange) compare the python .py code with the visual GRC flowgraph