一、创建你的第一个块
本教程介绍了如何利用Embedded python block创建一个信号处理模块。
本教程使用Embedded python block,它只能在创建它的流程图中使用。教程使用 gr-modtool 创建 Python OOT ,演示了如何将自定义 Python 块创建为树外 (OOT) 模块,该模块可以在任何流程图中安装和使用。
1.打开代码编辑器
嵌入式 Python 块是一种在流程图中快速原型化块的工具。搜索Python 块并将其添加到工作区:
双击块以编辑属性。嵌入式 Python 块有两个属性:
1.Code,一个单击框,其中包含指向该块的 Python 代码的链接,
2.Example_Param,块的输入参数。
编辑器窗口显示Embedded python block的python代码:
2、python模块的组成
Python模块的代码由三个重要部分组成:
1.import statements in green
2.__init__ function in blue
3.work function in red
①The import statement includes the NumPy and GNU Radio libraries.
②The __init__ statement:
Accepts the example_param parameter with a default argument of 1.0.
Declares the block to have a np.complex64 input and output, which is the GNU Radio Complex Float 32 data type.
Stores the self.example_param variable from the input parameter.
③The work function:
Has the input input_items and output output_items parameters.
Applies a mathematical operation to input_items and stores the result in output_items.
Returns the number of samples produced.
3.更改参数名称
修改代码以添加自定义行为。
第一步是将example_param重命名为additionalFlag。从编辑器菜单中选择Find and Replace:
将默认值更改为True:
Save之后:
4.更改输入参数的数量
默认块有一个输入和一个输出,但是我们需要两个输入用于该块。要添加输入,将第二个np.complex64添加到in_sig列表中:
将模块名称更改为Add or Multiply Block:
Save之后:
5.编辑work函数
首先看我们所需要的伪代码:
根据伪代码修改work函数
在编辑Python代码开始新行时,请记住以 4 个空格的倍数(4、8、12 等)缩进!
6.结果
输入为true:
点击鼠标滚轮选择Auto Scale可看到完整幅度。
输入为false:
GN