GNU Radio创建qt time plot python OOT块

文章目录


前言

官方提供的绘制时域波形的 block 名字叫做 QT GUI Time Sink,其底层实现是用 C++ 写的,但是我发现如果要是对收到的信号做一些其他的显示,例如在实现雷达测距的时候将 x 轴改为距离轴,y 轴改为主副瓣比,那么直接对 QT GUI Time Sink 这个模块做一些修改还是比较难的,因此就想通过 python OOT 实现一个简单的绘制时域波形的 block,并且这个 block 方便后面做自定义修改,例如修改成显示距离或者速度等等。


一、创建自定义的 OOT 块

1、安装相应依赖

  • Matplotlib:一个数据可视化库,提供了一个类似于 MATLAB 的绘图框架。
  • NumPy:一个提供多维数组对象和一系列针对数组操作的函数的库,它是几乎所有进行科学计算的Python软件包的核心库。
bash 复制代码
sudo apt install python3-pip
pip install matplotlib numpy

2、创建 OOT 块

参考官方教程 Creating Python OOT with gr-modtool 创建自定义的 OOT块

①、在 gr-customModule 目录下添加一个名为 Zadoff-Chu 的新块:

bash 复制代码
gr_modtool add my_time_plot

将显示块的类型:

bash 复制代码
GNU Radio module name identified: myModule
('sink', 'source', 'sync', 'decimator', 'interpolator', 'general', 'tagged_stream', 'hier', 'noblock')

②、my_time_plot 模块需要根据输入数据同步显示,因此这里选择 sync

bash 复制代码
Enter block type: sync

③、使用 Python 代码实现

bash 复制代码
Language (python/cpp): python
Language: Python
Block/code identifier: my_time_plot

④、输入版权所有者的名称或组织:

bash 复制代码
Please specify the copyright holder: gnep

⑤、输入采样率作为参数

bash 复制代码
Enter valid argument list, including default arguments: 
samp_rate = 32000.0

⑥、选择是否需要 QA 代码:

bash 复制代码
Add Python QA code? [Y/n] n

⑦、然后将创建或修改以下文件:

bash 复制代码
Adding file 'python/my_time_plot.py'...
Adding file 'grc/customModule_my_time_plot.block.yml'...
Editing grc/CMakeLists.txt...

相关配置如下图:

3、修改相关

my_time_plot.py 部分核心程序:

python 复制代码
    def work(self, input_items, output_items):
        in0 = input_items[0]
        n_samples = len(in0)
        t = np.arange(0, n_samples) / self.sampling_rate  # 生成时间向量

        # Send data to the queue
        self.q.put((t, in0))
        return len(in0)

customModule_zcSequence.block.yml 部分核心配置:

yaml 复制代码
parameters:
- id: samp_rate
  label: samp rate
  dtype: float

#  Make one 'inputs' list entry per input and one 'outputs' list entry per output.
#  Keys include:
#      * label (an identifier for the GUI)
#      * domain (optional - stream or message. Default is stream)
#      * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
#      * vlen (optional - data stream vector length. Default is 1)
#      * optional (optional - set to 1 for optional inputs. Default is 0)
inputs:
- label: in
  domain: stream
  dtype: float

详细代码及配置文件文末自取

4、编译及安装 OOT 块

1、该块需要编译和安装,确保目前位于 gr-customModule 目录中:

bash 复制代码
cd gr-customModule

2、如果 build/ 目录已存在,请将其删除:

bash 复制代码
rm -rf build/

3、创建 build/ 目录

bash 复制代码
mkdir build

4、进入 build 目录

bash 复制代码
cd build/ 

5、运行 cmake 来构建 makefile

bash 复制代码
cmake ..

6、编译模块

bash 复制代码
make

7、安装模块

bash 复制代码
sudo make install

8、更新 customModule 库的链接

bash 复制代码
sudo ldconfig 

二、测试

1、grc 图

这里用一个 10Hz 的信号源做测试,采样率设置大一些,设置成10 kHz

2、运行结果

官方 QT GUI Time Sink 显示内容:

自定义制作的 time plot 显示内容:

三、资源自取

链接:GNU Radio创建qt time plot python OOT块


我的qq:2442391036,欢迎交流!


相关推荐
JJ1M84 小时前
用 Python 快速搭建一个支持 HTTPS、CORS 和断点续传的文件服务器
服务器·python·https
汤姆yu4 小时前
基于python大数据的小说数据可视化及预测系统
大数据·python·信息可视化
x***J3484 小时前
Python多线程爬虫
开发语言·爬虫·python
m***D2864 小时前
Python网络爬虫实战案例
开发语言·爬虫·python
ID_180079054735 小时前
基于 Python 的淘宝商品详情数据结构化解析:SKU、价格与库存字段提取
开发语言·数据结构·python
Laughtin5 小时前
终端Python环境的选择与切换
开发语言·python
JHC0000005 小时前
Python PDF 相关操作
开发语言·python·pdf
databook5 小时前
Manim进阶:用背景图片让你的数学视频脱颖而出
python·动效
lqj_本人5 小时前
鸿蒙Qt生命周期:后台被杀后的数据自救
qt·华为·harmonyos
温轻舟6 小时前
Python自动办公工具01-Excel文件编辑器
开发语言·python·编辑器·excel·温轻舟