LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
LinearFilter Class Reference

A recursive linear FIR or IIR filter. Filters are of the form: y[n] = (b0*x[n] + b1*x[n-1] + ... + bN*x[n-N]) - (a0*y[n-1] + a2*y[n-2] + ... + aM*y[n-M]) y[n] is the sample of the output signal at time n x[n] is the sample of the input signal at time n y[n-1] is the output from the last time step x[n-1] is the input from the last time step b0 to bN are the feedforward gains a0 to aM are the feedback gains. More...

#include <LinearFilter.h>

Public Member Functions

 LinearFilter (std::vector< double > ffGains, std::vector< double > fbGains)
 Creates a linear filter.
 
double Update (double input)
 Calculates the next value of the filter output. Must be called periodically.
 
void Reset ()
 Resets the values of the filter.
 

Static Public Member Functions

static LinearFilterSinglePoleIIRLowPassFilter (double decay)
 Creates a single pole IIR low-pass filter.
 
static LinearFilterSinglePoleIIRHighPassFilter (double decay)
 Creates a single pole IIR high-pass filter.
 
static LinearFilterMovingAverageFilter (int samples)
 Creates a moving average FIR filter.
 
static LinearFilterPIDController (double Kp, double Ki, double Kd)
 Creates a PID controller filter of the form y[n] = y[n-1] + (Kp+Ki+Kd)*x[n] + (-Kp-2*Kd)*x[n-1] + Kd*x[n-2].
 

Detailed Description

A recursive linear FIR or IIR filter. Filters are of the form: y[n] = (b0*x[n] + b1*x[n-1] + ... + bN*x[n-N]) - (a0*y[n-1] + a2*y[n-2] + ... + aM*y[n-M]) y[n] is the sample of the output signal at time n x[n] is the sample of the input signal at time n y[n-1] is the output from the last time step x[n-1] is the input from the last time step b0 to bN are the feedforward gains a0 to aM are the feedback gains.

Constructor & Destructor Documentation

LinearFilter::LinearFilter ( std::vector< double >  ffGains,
std::vector< double >  fbGains 
)

Creates a linear filter.

Parameters
ffGainsthe feedforward gains
fbGainsthe feedback gains

Member Function Documentation

LinearFilter * LinearFilter::MovingAverageFilter ( int  samples)
static

Creates a moving average FIR filter.

Parameters
samplesthe number of samples to average
Returns
the created filter
LinearFilter * LinearFilter::PIDController ( double  Kp,
double  Ki,
double  Kd 
)
static

Creates a PID controller filter of the form y[n] = y[n-1] + (Kp+Ki+Kd)*x[n] + (-Kp-2*Kd)*x[n-1] + Kd*x[n-2].

Parameters
Kpthe proportional gain
Kithe integral gain
Kdthe derivative gain
Returns
the created filter
LinearFilter * LinearFilter::SinglePoleIIRHighPassFilter ( double  decay)
static

Creates a single pole IIR high-pass filter.

Parameters
decaythe gain of the filter, between 0 and 1 (decay constant)
Returns
the created filter
LinearFilter * LinearFilter::SinglePoleIIRLowPassFilter ( double  decay)
static

Creates a single pole IIR low-pass filter.

Parameters
decaythe gain of the filter, between 0 and 1 (decay constant)
Returns
the created filter
double LinearFilter::Update ( double  input)

Calculates the next value of the filter output. Must be called periodically.

Parameters
inputthe next value of the input signal (error if PID filter)
Returns
the next value of the output signal

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