SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Private Attributes | List of all members
IIRFilter< Type, Order > Class Template Reference

#include <iirfilter.h>

Public Member Functions

 IIRFilter (const Type *a, const Type *b)
 
 ~IIRFilter ()
 
void setCoeffs (const Type *a, const Type *b)
 
Type run (const Type &sample)
 

Private Attributes

Type * m_a
 
Type * m_b
 
Type * m_x
 
Type * m_y
 

Detailed Description

template<typename Type, uint32_t Order>
class IIRFilter< Type, Order >

IIR filter See: https://cdn.mikroe.com/ebooks/img/8/2016/02/digital-filter-design-chapter-03-image-2-9.gif

Definition at line 31 of file iirfilter.h.

Constructor & Destructor Documentation

◆ IIRFilter()

template<typename Type, uint32_t Order>
IIRFilter< Type, Order >::IIRFilter ( const Type *  a,
const Type *  b 
)

Definition at line 62 of file iirfilter.h.

63 {
64  assert(Order > 1);
65 
66  m_a = new Type[Order+1];
67  m_b = new Type[Order+1];
68  m_x = new Type[Order];
69  m_y = new Type[Order];
70 
71  setCoeffs(a, b);
72 }
Type * m_a
Definition: iirfilter.h:40
void setCoeffs(const Type *a, const Type *b)
Definition: iirfilter.h:84
Type * m_y
Definition: iirfilter.h:43
Type * m_x
Definition: iirfilter.h:42
Type * m_b
Definition: iirfilter.h:41

◆ ~IIRFilter()

template<typename Type , uint32_t Order>
IIRFilter< Type, Order >::~IIRFilter ( )

Definition at line 75 of file iirfilter.h.

76 {
77  delete[] m_y;
78  delete[] m_x;
79  delete[] m_b;
80  delete[] m_a;
81 }
Type * m_a
Definition: iirfilter.h:40
Type * m_y
Definition: iirfilter.h:43
Type * m_x
Definition: iirfilter.h:42
Type * m_b
Definition: iirfilter.h:41

Member Function Documentation

◆ run()

template<typename Type, uint32_t Order>
Type IIRFilter< Type, Order >::run ( const Type &  sample)

Definition at line 98 of file iirfilter.h.

Referenced by AudioFilter::run(), MBEAudioInterpolatorFilter::run(), AudioFilter::runHP(), MBEAudioInterpolatorFilter::runHP(), AudioFilter::runLP(), and MBEAudioInterpolatorFilter::runLP().

99 {
100  Type y = m_b[0] * sample;
101 
102  for (uint32_t i = Order; i > 0; i--)
103  {
104  y += m_b[i] * m_x[i-1] + m_a[i] * m_y[i-1];
105 
106  if (i > 1) // shift
107  {
108  m_x[i-1] = m_x[i-2];
109  m_y[i-1] = m_y[i-2];
110  }
111  }
112 
113  // last shift
114  m_x[0] = sample;
115  m_y[0] = y;
116 
117  return y;
118 }
Type * m_a
Definition: iirfilter.h:40
Type * m_y
Definition: iirfilter.h:43
unsigned int uint32_t
Definition: rtptypes_win.h:46
Type * m_x
Definition: iirfilter.h:42
int32_t i
Definition: decimators.h:244
Type * m_b
Definition: iirfilter.h:41
+ Here is the caller graph for this function:

◆ setCoeffs()

template<typename Type, uint32_t Order>
void IIRFilter< Type, Order >::setCoeffs ( const Type *  a,
const Type *  b 
)

Definition at line 84 of file iirfilter.h.

Referenced by IIRFilter< float, 2 >::IIRFilter(), IIRFilter< Type, 2 >::IIRFilter(), and AudioFilter::setDecimFilters().

85 {
86  memcpy(m_a, b, (Order+1)*sizeof(Type));
87  memcpy(m_b, a, (Order+1)*sizeof(Type));
88 
89  for (uint32_t i = 0; i < Order; i++)
90  {
91  m_x[i] = 0;
92  m_y[i] = 0;
93  }
94 }
Type * m_a
Definition: iirfilter.h:40
Type * m_y
Definition: iirfilter.h:43
unsigned int uint32_t
Definition: rtptypes_win.h:46
Type * m_x
Definition: iirfilter.h:42
int32_t i
Definition: decimators.h:244
Type * m_b
Definition: iirfilter.h:41
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_a

template<typename Type, uint32_t Order>
Type* IIRFilter< Type, Order >::m_a
private

◆ m_b

template<typename Type, uint32_t Order>
Type* IIRFilter< Type, Order >::m_b
private

◆ m_x

template<typename Type, uint32_t Order>
Type* IIRFilter< Type, Order >::m_x
private

◆ m_y

template<typename Type, uint32_t Order>
Type* IIRFilter< Type, Order >::m_y
private

The documentation for this class was generated from the following file: