文章目录
- 前言
- 一、ZC序列是什么?
- 二、创建自定义的 OOT 块
- 三、相关文件
- 四、测试
- 1、grc 图
- 2、运行结果
- ①、时域图
- ②、时域幅值模图
- ③、IQ 曲线
前言
本文实现在 GNU Radio 中创建 Zadoff-Chu 序列 python OOT 块,仅做代码调试记录。
一、ZC序列是什么?
参考我之前的博客:ZC序列理论学习及仿真
二、创建自定义的 OOT 块
参考官方教程 Creating Python OOT with gr-modtool 创建自定义的 OOT块
三、相关文件
zcSequence.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2024 gnep.
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
import numpy as np
from gnuradio import gr
class zcSequence(gr.sync_block):
"""
docstring for block zcSequence
"""
def __init__(self, sequence_length = 64, root_index = 5):
gr.sync_block.__init__(self,
name="zcSequence",
in_sig=None,
out_sig=[np.complex64])
self.sequence_length = sequence_length # ZC序列的长度
self.root_index = root_index # ZC序列的根索引
self.set_output_multiple(sequence_length) # 确保输出大小与序列长度匹配
def work(self, input_items, output_items):
noutput_items = len(output_items[0])
if self.sequence_length != noutput_items:
# 如果输出项的长度与预期的序列长度不匹配,调整序列长度
self.sequence_length = noutput_items
if self.sequence_length % 2 == 0:
zc_sequence = np.exp(-1j * np.pi * self.root_index * np.arange(self.sequence_length) * np.arange(self.sequence_length) / self.sequence_length)
else:
zc_sequence = np.exp(-1j * np.pi * self.root_index * np.arange(self.sequence_length) * (np.arange(self.sequence_length) + 1) / self.sequence_length)
# 确保zc_sequence的长度与output_items[0]相匹配
output_items[0][:self.sequence_length] = zc_sequence
return self.sequence_length
customModule_zcSequence.block.yml
id: customModule_zcSequence
label: zcSequence
category: '[customModule]'
templates:
imports: import customModule
make: customModule.zcSequence(${sequence_length}, ${root_index})
# Make one 'parameters' list entry for every parameter you want settable from the GUI.
# Keys include:
# * id (makes the value accessible as \$keyname, e.g. in the make entry)
# * label (label shown in the GUI)
# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
parameters:
- id: sequence_length
label: zc len
dtype: int
default: 64
- id: root_index
label: root index
dtype: int
default: 5
# 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: ...
# domain: ...
# dtype: ...
# vlen: ...
# optional: ...
outputs:
- label: out0
domain: stream
dtype: complex
# vlen: ...
# optional: ...
# 'file_format' specifies the version of the GRC yml format used in the file
# and should usually not be changed.
file_format: 1
四、测试
1、grc 图
2、运行结果
①、时域图
②、时域幅值模图
③、IQ 曲线
我的qq:2442391036,欢迎交流!