numeric
|
#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 () |
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).
numeric::DiscreteFilter::DiscreteFilter | ( | double | sampleTime, |
int | numberElements = 1 |
||
) |
bool numeric::DiscreteFilter::calcOutput | ( | double & | filteredSignal, |
double & | inputSignal | ||
) |
Calculates the filtered signal for a univariable input.
inputSignal | - Signal to be filtered. |
filteredSignal | - Univariable filtered signal. |
bool numeric::DiscreteFilter::calcOutput | ( | base::VectorXd & | filteredSignal, |
base::VectorXd & | inputSignal | ||
) |
Calculates the filtered signal for a multivariable input.
inputSignal | - Signal to be filtered. |
filteredSignal | - Multivariable filtered signal. |
bool numeric::DiscreteFilter::getNumberElements | ( | int & | numberElements | ) |
Gets the number of input elements that the filter expects.
pole1 | - Number of input elements. |
bool numeric::DiscreteFilter::getPoles | ( | double & | pole1, |
double & | pole2 | ||
) |
Gets the continuous filter poles.
pole1 | - First continuous filter pole. |
pole1 | - Second continuous filter pole. |
bool numeric::DiscreteFilter::getSamplingTime | ( | double & | sampleTime | ) |
Gets the sampling time.
sampleTime | - Sampling time. |
bool numeric::DiscreteFilter::resetFilter | ( | ) |
Resets the filter (resets the past values matrix).
bool numeric::DiscreteFilter::setPoles | ( | double | pole1, |
double | pole2 = 1 |
||
) |
Sets the continuous filter poles.
pole1 | - First continuous filter pole (must be greater than zero). |
pole1 | - Second continuous filter pole (optional). |