官方提供的绘制时域波形的 block 名字叫做 QT GUI Time Sink,其底层实现是用 C++ 写的,但是我发现如果要是对收到的信号做一些其他的显示,例如在实现雷达测距的时候将 x 轴改为距离轴,y 轴改为主副瓣比,那么直接对 QT GUI Time Sink 这个模块做一些修改还是比较难的,因此就想通过 python OOT 实现一个简单的绘制时域波形的 block,并且这个 block 方便后面做自定义修改,例如修改成显示距离或者速度等等。
sudo apt install python3-pip
pip install matplotlib numpy
参考官方教程 Creating Python OOT with gr-modtool 创建自定义的 OOT块
①、在 gr-customModule 目录下添加一个名为 Zadoff-Chu 的新块:
gr_modtool add my_time_plot
将显示块的类型:
GNU Radio module name identified: myModule
('sink', 'source', 'sync', 'decimator', 'interpolator', 'general', 'tagged_stream', 'hier', 'noblock')
②、my_time_plot 模块需要根据输入数据同步显示,因此这里选择 sync
Enter block type: sync
③、使用 Python 代码实现
Language (python/cpp): python
Language: Python
Block/code identifier: my_time_plot
④、输入版权所有者的名称或组织:
Please specify the copyright holder: gnep
⑤、输入采样率作为参数
Enter valid argument list, including default arguments:
samp_rate = 32000.0
⑥、选择是否需要 QA 代码:
Add Python QA code? [Y/n] n
⑦、然后将创建或修改以下文件:
Adding file 'python/my_time_plot.py'...
Adding file 'grc/customModule_my_time_plot.block.yml'...
Editing grc/CMakeLists.txt...
相关配置如下图:
my_time_plot.py
部分核心程序:
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
部分核心配置:
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
详细代码及配置文件文末自取
1、该块需要编译和安装,确保目前位于 gr-customModule 目录中:
cd gr-customModule
2、如果 build/ 目录已存在,请将其删除:
rm -rf build/
3、创建 build/ 目录
mkdir build
4、进入 build 目录
cd build/
5、运行 cmake 来构建 makefile
cmake ..
6、编译模块
make
7、安装模块
sudo make install
8、更新 customModule 库的链接
sudo ldconfig
这里用一个 10Hz 的信号源做测试,采样率设置大一些,设置成10 kHz
官方 QT GUI Time Sink 显示内容:
自定义制作的 time plot 显示内容:
链接:GNU Radio创建qt time plot python OOT块