AudiClean
Public Member Functions | List of all members
Fir1 Class Reference

#include <Fir1.h>

Collaboration diagram for Fir1:
Collaboration graph

Public Member Functions

template<unsigned nTaps>
 Fir1 (const double(&_coefficients)[nTaps])
 
 Fir1 (std::vector< double > _coefficients)
 
 Fir1 (double *coefficients, unsigned number_of_taps)
 
 Fir1 (const char *coeffFile, unsigned number_of_taps=0)
 
 Fir1 (unsigned number_of_taps)
 
 ~Fir1 ()
 
double filter (double input)
 
void lms_update (double error)
 
void setLearningRate (double _mu)
 
double getLearningRate ()
 
void reset ()
 
void zeroCoeff ()
 
void getCoeff (double *coeff_data, unsigned number_of_taps) const
 
std::vector< double > getCoeffVector () const
 
unsigned getTaps ()
 
double getTapInputPower ()
 

Detailed Description

Finite impulse response filter. The precision is double. It takes as an input a file with coefficients or an double array.

Constructor & Destructor Documentation

◆ Fir1() [1/5]

template<unsigned nTaps>
Fir1::Fir1 ( const double(&)  _coefficients[nTaps])
inline

Coefficients as a const double array. Because the array is const the number of taps is identical to the length of the array.

Parameters
_coefficientsA const double array with the impulse response.

◆ Fir1() [2/5]

Fir1::Fir1 ( std::vector< double >  _coefficients)
inline

Coefficients as a C++ vector

Parameters
_coefficientsis a Vector of doubles.

◆ Fir1() [3/5]

Fir1::Fir1 ( double *  _coefficients,
unsigned  number_of_taps 
)
Coefficients as a (non-constant-) double array where the length needs to be specified.
Parameters
coefficientsCoefficients as double array.
number_of_tapsNumber of taps (needs to match the number of coefficients

Initialise the filter from coefficients, assigned as array

Parameters
_coefficientscoeffs to be assigned
number_of_tapsnr of taps (array length)

◆ Fir1() [4/5]

Fir1::Fir1 ( const char *  coeffFile,
unsigned  number_of_taps = 0 
)

Coefficients as a text file (for example from Python) The number of taps is automatically detected when the taps are kept zero.

Parameters
coeffFilePatht to textfile where every line contains one coefficient
number_of_tapsNumber of taps (0 = autodetect)

Initialise the filter coefficients with a text file where each line is has one coefficient

Parameters
coeffFiletext file for initialisation
number_of_tapsnr of fiter taps (order)

◆ Fir1() [5/5]

Fir1::Fir1 ( unsigned  number_of_taps)
Inits all coefficients and the buffer to zero

This is useful for adaptive filters where we start with zero valued coefficients.

Initalise the filter with empty coefficients

Parameters
number_of_tapsnr of taps (filter order)

◆ ~Fir1()

Fir1::~Fir1 ( )

Releases the coefficients and buffer.

Filter destructor

Member Function Documentation

◆ filter()

double Fir1::filter ( double  input)
inline

The actual filter function operation: it receives one sample and returns one sample.

Parameters
inputThe input sample.

◆ getCoeff()

void Fir1::getCoeff ( double *  coeff_data,
unsigned  number_of_taps 
) const

Copies the current filter coefficients into a provided array. Useful after an adaptive filter has been trained to query the result of its training.

Parameters
coeff_datatarget where coefficients are copied
number_of_tapsnumber of doubles to be copied
Exceptions
std::out_of_rangenumber_of_taps is less the actual number of taps.

Copies a coeffs to coeff_data array

Parameters
coeff_data
number_of_taps

◆ getCoeffVector()

std::vector<double> Fir1::getCoeffVector ( ) const
inline

Returns the coefficients as a vector

◆ getLearningRate()

double Fir1::getLearningRate ( )
inline

Getting the learning rate for the adaptive filter.

◆ getTapInputPower()

double Fir1::getTapInputPower ( )
inline
Returns the power of the of the buffer content:

sum_k buffer[k]^2 which is needed to implement a normalised LMS algorithm.

◆ getTaps()

unsigned Fir1::getTaps ( )
inline

Returns the number of taps.

◆ lms_update()

void Fir1::lms_update ( double  error)
inline
LMS adaptive filter weight update:

Every filter coefficient is updated with: w_k(n+1) = w_k(n) + learning_rate * buffer_k(n) * error(n)

Parameters
errorIs the term error(n), the error which adjusts the FIR conefficients.

◆ reset()

void Fir1::reset ( )

Resets the buffer (but not the coefficients)

sets all tap outputs to zero

◆ setLearningRate()

void Fir1::setLearningRate ( double  _mu)
inline

Setting the learning rate for the adaptive filter.

Parameters
_muThe learning rate (i.e. rate of the change by the error signal)

◆ zeroCoeff()

void Fir1::zeroCoeff ( )

Sets all coefficients to zero

Sets all coeffs to zero


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