基于gnuradio的OOT模块,iirnotch(iir 陷波滤波器)

本教程详细介绍了如何基于gnuradio创建一个自定义的OOT模块——iirNotch陷波滤波器。内容包括修改头文件、实现文件、配置yaml文件以及模块的安装和测试。通过修改源代码,实现了中心频率和陷波宽度的动态更新,并通过gnuradio-companion进行测试,展示了iirNotch和adaptiveNotch在滤波效果上的差异。
摘要由CSDN通过智能技术生成

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


To start

OOT模块的制作教程可以看上一篇内容:基于gnuradio的自适应陷波滤波器OOT模块,本篇主要就iirnotch的制作进行说明

iirnotch 的原理请参考这一篇:陷波滤波器的离散化设计

如上一篇所说,输入gr_modtool 相关指令,就能生成相关的模块代码,之后只用修改代码即可:
在这里插入图片描述


一、修改iirNotch.h

在类定义中,添加这两句:

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

运行效果如下:
在这里插入图片描述

二、修改iirNotch_impl.h

添加对父类中刚刚加入的两个纯虚函数的继承:

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 sample
  float a0,a1,a2;
  //coefficient of delayed output sample
  float b1,b2;
  double wc;
  double wb;
  double sampleRate;

public:
  iirNotch_impl(double sampRate, double targetFreq, double width);
  ~iirNotch_impl();

  // Where all the action really happens
  int work(int noutput_items, gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
  
  void set_wc(float wc) override;
  void set_wb(float wb) override;
};

} 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值