numeric
Public Member Functions | List of all members
numeric::DiscreteFilter Class Reference

#include <DiscreteFilter.hpp>

Public Member Functions

 DiscreteFilter (double sampleTime, int numberElements=1)
 
bool calcOutput (double &filteredSignal, double &inputSignal)
 
bool calcOutput (base::VectorXd &filteredSignal, base::VectorXd &inputSignal)
 
bool setPoles (double pole1, double pole2=1)
 
bool getPoles (double &pole1, double &pole2)
 
bool getSamplingTime (double &sampleTime)
 
bool getNumberElements (int &numberElements)
 
bool resetFilter ()
 

Detailed Description

This library implements a second order low pass discrete filter from a continuous filter using the matched pole-zero methods.

   (CONTINUOUS FILTER)                                              (DISCRETE FILTER)
                kc                                                                         kd

G(s) = --------------— ======> G(z) = -----------------------------— (s + p1)(s + p2) (1 - ep1T*z^⁻1)(1 - ep2T*z^-2)

where:

- epT: Continuous pole matched in discrete time ===> epT = exp(p*T)
- p:   Continuous pole = -p1 and -p2
- T:   Sample time
- kd:  Unitary static gain                  ===> kd = 1 - (ep1T + ep2T) + ep1T*ep2T

The resulting difference equation is:

y[k] = kd*u[k] + (ep1T + ep2T)*y[k-1] - ep1T*ep2T*y[k-2]

This difference equation is implemented in this library to filter a specified input signal.

The user may worry about setting only the pole1, because the pole2 will copy the pole1's value if pole2's value is not set. The value of pole1 must be less than zero, and basically, the smaller pole1's value the more intense is the filtering (the cutting frequency is lower).

Constructor & Destructor Documentation

◆ DiscreteFilter()

numeric::DiscreteFilter::DiscreteFilter ( double  sampleTime,
int  numberElements = 1 
)

Member Function Documentation

◆ calcOutput() [1/2]

bool numeric::DiscreteFilter::calcOutput ( double &  filteredSignal,
double &  inputSignal 
)

Calculates the filtered signal for a univariable input.

Parameters
inputSignal- Signal to be filtered.
filteredSignal- Univariable filtered signal.
Returns
- Boolean variable to confirm that everything went fine.

◆ calcOutput() [2/2]

bool numeric::DiscreteFilter::calcOutput ( base::VectorXd &  filteredSignal,
base::VectorXd &  inputSignal 
)

Calculates the filtered signal for a multivariable input.

Parameters
inputSignal- Signal to be filtered.
filteredSignal- Multivariable filtered signal.
Returns
- Boolean variable to confirm that everything went fine.

◆ getNumberElements()

bool numeric::DiscreteFilter::getNumberElements ( int &  numberElements)

Gets the number of input elements that the filter expects.

Parameters
pole1- Number of input elements.
Returns
- Boolean variable to confirm that everything went fine

◆ getPoles()

bool numeric::DiscreteFilter::getPoles ( double &  pole1,
double &  pole2 
)

Gets the continuous filter poles.

Parameters
pole1- First continuous filter pole.
pole1- Second continuous filter pole.
Returns
- Boolean variable to confirm that everything went fine.

◆ getSamplingTime()

bool numeric::DiscreteFilter::getSamplingTime ( double &  sampleTime)

Gets the sampling time.

Parameters
sampleTime- Sampling time.
Returns
- Boolean variable to confirm that everything went fine.

◆ resetFilter()

bool numeric::DiscreteFilter::resetFilter ( )

Resets the filter (resets the past values matrix).

Returns
- Boolean variable to confirm that everything went fine

◆ setPoles()

bool numeric::DiscreteFilter::setPoles ( double  pole1,
double  pole2 = 1 
)

Sets the continuous filter poles.

Parameters
pole1- First continuous filter pole (must be greater than zero).
pole1- Second continuous filter pole (optional).
Returns
- Boolean variable to confirm that everything went fine.

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