GNU Radio教程2.创建和修改python块

一、创建你的第一个块

本教程介绍了如何利用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 

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值