提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
OOT模块的制作教程可以看上一篇内容:基于gnuradio的自适应陷波滤波器OOT模块,本篇主要就iirnotch的制作进行说明
iirnotch 的原理请参考这一篇:陷波滤波器的离散化设计
如上一篇所说,输入gr_modtool 相关指令,就能生成相关的模块代码,之后只用修改代码即可:
在类定义中,添加这两句:
virtual void set_wc(float wc)=0;
virtual void set_wb(float wb)=0;
分别作为回调函数(在模块执行完一次数据处理操作后自动调用),更新wc(中心频率)和wb(陷波宽度)。
另外给这两句话加上注释,那么整个文件就是:
/* -*- c++ -*- */
/** Copyright 2022 mortarboard-H.** SPDX-License-Identifier: GPL-3.0-or-later*/#ifndef INCLUDED_NOTCHFILTER_IIRNOTCH_H
#define INCLUDED_NOTCHFILTER_IIRNOTCH_H#include <gnuradio/sync_block.h>
#include <notchFilter/api.h>namespace gr {
namespace notchFilter {/*!* brief <+description of block+>* ingroup notchFilter**/
class NOTCHFILTER_API iirNotch : virtual public gr::sync_block {
public:typedef std::shared_ptr<iirNotch> sptr;/*!* brief Return a shared_ptr to a new instance of notchFilter::iirNotch.** To avoid accidental use of raw pointers, notchFilter::iirNotch's* constructor is in a private implementation* class. notchFilter::iirNotch::make is the public interface for* creating new instances.*/static sptr make(double sampRate, double targetFreq, double width);/*!* brief call back function to update centre frequency*/virtual void set_wc(float wc)=0;/*!* brief call back function to update band frequency*/virtual void set_wb(float wb)=0;
};} // namespace notchFilter
} // namespace gr#endif /* INCLUDED_NOTCHFILTER_IIRNOTCH_H */
更新完头文件后,要注意重新绑定,在module所在的文件夹下打开terminal,然后输入:
gr_modtool bind iirNotch
运行效果如下:
添加对父类中刚刚加入的两个纯虚函数的继承:
void set_wc(float wc) override;
void set_wb(float wb) override;
添加几个成员变量:
//coefficient of input sample
float a0,a1,a2;
//coefficient of delayed output sample
float b1,b2;
double wc;
double wb;
double sampleRate;
这几个成员变量是使用极零点配置法离散化传递函数后得到的,具体的计算和含义参考开头提到的博客。
那么整个文件看起来就像这样:
/* -*- c++ -*- */
/** Copyright 2022 mortarboard-H.** SPDX-License-Identifier: GPL-3.0-or-later*/#ifndef INCLUDED_NOTCHFILTER_IIRNOTCH_IMPL_H
#define INCLUDED_NOTCHFILTER_IIRNOTCH_IMPL_H#include <notchFilter/iirNotch.h>namespace gr {
namespace notchFilter {class iirNotch_impl : public iirNotch {
private://coefficient of input samplefloat a0,a1,a2;//coefficient of delayed output samplefloat b1,b2;double wc;double wb;double sampleRate;public:iirNotch_impl(double sampRate, double targetFreq, double width);~iirNotch_impl();// Where all the action really happensint work(int noutput_items, gr_vector_const_void_star &input_items,gr_vector_void_star &output_items);void set_wc(
本文发布于:2024-01-28 08:18:44,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17064011266059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |