# IIRFilter Class

The IIRFilter class is the 1st order IIR low-pass filter. Implements the difference equation: More...

Header: | #include <Filter/Filter.h> |

Inherits: | CDPBaseObject |

## Public Functions

IIRFilter() | |

double | Calculate(double x) |

double | Getb0() |

void | Init(double b0) |

void | Setb0(double newb0) |

void | SetF3dB(double f3dB, double frequency) |

void | SetValue(double newValue) |

double | Value() |

## Reimplemented Public Functions

virtual void | Create(const char *shortName, CDPBaseObject *pParent) |

virtual std::string | GetNodeTypeName() const override |

- 42 public functions inherited from CDPBaseObject
- 26 public functions inherited from CDP::StudioAPI::CDPNode
- 22 public functions inherited from CDP::StudioAPI::ICDPNode

### Additional Inherited Members

- 1 static public member inherited from CDPBaseObject
- 1 protected function inherited from CDP::StudioAPI::CDPNode
- 9 protected variables inherited from CDPBaseObject

## Detailed Description

The IIRFilter class is the 1st order IIR low-pass filter. Implements the difference equation:

y[n] = b0 * x[n] + (1-b0) * y[n-1];

or in C++ form:

y_n = b0 * x + (1.0 - b0) * y_n1; or y_n += b0*(x - y_n)

#### Selecting a suitable cut-off frequency

The b0 parameter for the filter may either be set directly with Setb0(), or the cut-off frequency (-3dB frequency) may be set using the function SetF3dB().

SetF3dB() sets a new b0 using the following formula:

b = 2 * PI * f3dB / fs

This relationship between b and the cut-off frequency is valid only for b << 1.

It is recommended to use SetF3db(), as this will prevent the filter characteristic from changing if the sampling freqency is changed.

**Note: **The stability requirement for the first order filter is that b>0 and b<=1. This leads to the following requirement on f3db:

f3db < fs / (2 * PI)

or, expressed as digital frequency F = f/Fs:

F3db < 1 / (2 * PI)'

**See also **IIRFilter, RateLimitedFilter, and Integrator.

## Member Function Documentation

### IIRFilter::IIRFilter()

Constructor. Initializes members to safe values.

### double IIRFilter::Calculate(double *x*)

Calculates filter output from *x*. Call this function periodically at a fixed sample interval, exacly once each period. Returns output value from filter.

**Note: **To read output from filter more than once each period, use Value() method to prevent a new output from being calculated again.

`[virtual] `

void IIRFilter::Create(const char **shortName*, CDPBaseObject **pParent*)

Reimplemented from CDPBaseObject::Create().

Creates the IIRFilter with *shortName* and *pParent* object.

### double IIRFilter::Getb0()

Returns filter constant b0 value.

`[override virtual] `

std::string IIRFilter::GetNodeTypeName() const

Reimplemented from ICDPNode::GetNodeTypeName().

Returns *"IIRFilter"*.

### void IIRFilter::Init(double *b0*)

Initializes the filter and sets filter *b0*. This function can also be used to reset the filter memory and output. For a frequency-invariant filter,

**See also **SetF3dB().

### void IIRFilter::Setb0(double *newb0*)

Sets new filter constant b0 from *newb0*

### void IIRFilter::SetF3dB(double *f3dB*, double *frequency*)

Sets new filter constant b0 by specifying cut-off frequency *f3db* and *frequency* (both in Hz).

### void IIRFilter::SetValue(double *newValue*)

Sets the output directly from *newValue*

### double IIRFilter::Value()

Returns current output value.

## Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.