libiir  1.0.2
Public Member Functions
IIR::Filter Class Reference

IIR filter coefficient set More...

Public Member Functions

 Filter (const Coeff &coeff)
 Construct from coefficient set.
 Filter (const Filter &other)
 Copy constructor.
 Filter (const char *desc)
 Construct from filter description string.
virtual ~Filter ()
 Destructor.
bool valid () const
 Determine whether object is valid.
double f (double x)
 Filter a sample.
int numCoeffSet () const
 Retrieve number of coefficient sets.
const CoeffgetCoeffSet (int idx) const
 Retrieve coefficient set.
void chainCoeffSet (const Coeff &coeff)
 Add another set of coefficients to the filter chain.
std::complex< double > response (double freq) const
 Evaluate response of filter at given frequency.
std::vector< double > responseMinus3dB (double gain) const
 Search for -3dB points.

Detailed Description

IIR filter coefficient set

An instance of this class contains both a copy of the set of coefficients used in each filter stage (of which there may be multiple), and all of the state (i.e. previous inputs and outputs) associated with each stage.

Constructor & Destructor Documentation

IIR::Filter::Filter ( const Coeff coeff)

Construct from coefficient set.

Parameters
coeffCoefficient set.

This constructor builds a filter chain with one stage. Additional stages may be added via chainCoeffSet(). This constructor will always result in a valid object.

IIR::Filter::Filter ( const Filter other)

Copy constructor.

Parameters
otherFilter to copy.

Copies the structure (but not the state) of the filter other. This constructor will always result in a valid object.

IIR::Filter::Filter ( const char *  desc)

Construct from filter description string.

Parameters
descDescription string.

This constructor will parse the description string desc (see Describing IIR filters as strings for details on what is accepted) and build up a filter as described.

If the parsing step fails, then valid() will return false and the object must not be used (no other functions except the destructor will be safe to call).

Member Function Documentation

bool IIR::Filter::valid ( ) const

Determine whether object is valid.

Return values
trueif object is valid.
falseif object is not valid.

A Filter object might not be valid if it was constructed from a description string that contained an error. In that case this function will return false and the object should not be used (no other functions except the destructor will be safe to call).

double IIR::Filter::f ( double  x)

Filter a sample.

Parameters
xSample.
Returns
Filter output.

Injects a single sample into the filter and returns the output value.

int IIR::Filter::numCoeffSet ( ) const

Retrieve number of coefficient sets.

Returns
Number of sets in use (≥1).
const Coeff& IIR::Filter::getCoeffSet ( int  idx) const

Retrieve coefficient set.

Parameters
idxIndex of set (0 ≤ idx < numCoeffSet()).
Returns
Reference to coefficient set.
void IIR::Filter::chainCoeffSet ( const Coeff coeff)

Add another set of coefficients to the filter chain.

Parameters
coeffCoefficient set to add.
std::complex<double> IIR::Filter::response ( double  freq) const

Evaluate response of filter at given frequency.

Parameters
freqFrequency (0 ≤ freq ≤ 1).
Returns
Complex response of filter at given frequency.

Returns the steady-state response of the filter to a pure input signal of the given frequency. freq is expressed as a fraction of the intended sampling rate (with 0.5 being the Nyquist frequency).

std::vector<double> IIR::Filter::responseMinus3dB ( double  gain) const

Search for -3dB points.

Parameters
gainNominal gain of filter.
Returns
List of frequency ratios at which filter magnitude is -3dB.

This function will perform a linear scan of the frequency response of the filter between DC and the Nyquist frequency. It will then search for any pair of points between which the magnitude transitions the -3dB level. It then performs a few levels of binary search in order to provide a more accurate answer.

Returned frequencies are expressed as a fraction of the sampling rate.