class Filter

Digital filter design and implementation API.

Public Methods

Filter(void)
Default constructor.
Filter(int length, float Sample)
Construct an empty filter instance.
~Filter(void)
Filter destructor.
int getLength(void) const
Get the filter length.
double getRate(void) const
Get the sample rate.
bool getStat(void) const
Test the history status.
int estLen(int nBand, const double* Bands, const double* Ripple) const
Estimate the length of a multi-band filter.
int estLPLen(double Fpass, double Fstop, double rip, double atten) const
Estimate the number of terms needed for a low-pass filter.
void design(int nPoles, const dComplex* Poles, int nZeros=0, const dComplex* Zeros=0)
Filter design from poles and zeroes.
void dRemez(int nBand, const double* Bands, const double* Func, const double* Weight=0)
FIR filter design using the McClellan-Parks algorithm.
void dFirW(int N, const char* window, const char* type, double Flow, double Fhigh=0, double dF=0, double Ripple=0)
Filter design from window function.
void dump(ostream& ostr) const
Print the Filter status.
DVector& operator)(DVector& in)
Filter a DVector.
TSeries operator)(const TSeries& in)
Filter a Time Series.
TSeries& apply(const TSeries& in, TSeries& out)
Filter a TSeries into an output object.
TSeries& apply(TSeries& in)
Filter a TSeries in place.
void apply(int N, const float* in, float* out)
Filter a float array.
void apply(int N, const fComplex* in, fComplex* out)
Filter a Complex array.
void setCoefs(int N, const double* Coefs)
Set filter coefficients.
void setHistory(int N, const float* Hist=0, Time t=Time(0))
Set history.
void setHistory(int N, const fComplex* Hist, Time t=Time(0))
Set history.
void setLength(int N)
Set Length.
void setRate(double F)
Set the filter sample Rate.
FSeries Xfer(float Fmin=0.0, float Fmax=0.0, float dF=1.0) const
Get the transfer function of a Filter.

Documentation

The Filter class object implements a digital FIR filter that can be used to filter time series (TSeries) data. Filter class instances carry the signal history as well as the filter coefficients to prevent the introduction of edge effect when filtering a long series in serveral pieces. Each signal (channel) to be filtered must use a separate Filter instance.
Filter(void)
Default constructor. No coefficient or history storage is allocated.

Filter(int length, float Sample)
A real-valued Order 'length'-1 digital FIR filter is constructed which will operate on data sampled with specified frequency. The filter coefficients remain uninitialized and the history data is cleared.
Parameters:
length - Number of terms( poles or zeros) in the filter.
Sample - Nominal sampling rate.

~Filter(void)
Destroy the filter object and release any memory allocated for filter coefficients or history information.

int getLength(void) const
Get the filter length. The filter state is not affected.
Returns:
The filter length (Order+1)

double getRate(void) const
Get the sample rate. The filter state is not affected.
Returns:
The nominal sample rate in Hz.

bool getStat(void) const
Tests whether the previous filter operation used valid history data. History data is considered to be valid if the history buffer is full and the start time of the input data is equal to the time stamp on the history data. The filter state is not affected.
Returns:
true if the filter history data was valid for the last operation.

int estLen(int nBand, const double* Bands, const double* Ripple) const
Estimate the number of terms needed for a multi-band filter. The desired filter response is described as a series of bands with corresponding limits on the ripple. The filter state is not affected.
Returns:
The estimated number of terms needed for a filter with the specified response.
Parameters:
nBand - The number of pass or stop bands in the filter response.
Bands - A list of band frequency edges.
Ripple - The desired ripple in a pass-band or attenuation in a stop-band for each frequency band.

int estLPLen(double Fpass, double Fstop, double rip, double atten) const
Estimate the number of terms needed for a low-pass filter. The filter is specified by two frequencies (the upper limit of the pass band and the lower limit of the stop band), the maximum desired ripple and the minimum desired attenuation. The frequencies must be in the range 0 < Fpass < Fstop < Fnyquist = Rate/2.
Returns:
The estimated number of terms needed for a filter with the specified response.
Parameters:
Fpass - Upper edge frequency in Hz of the pass band.
FStop - Lower edge frequency in Hz of the stop band.
rip - Desired maximum pass band ripple (as a fraction).
atten - Desired stop band attenuation (as a fraction).

void design(int nPoles, const dComplex* Poles, int nZeros=0, const dComplex* Zeros=0)
Design a filter from lists of poles and zeros (Not yet implemented).

void dRemez(int nBand, const double* Bands, const double* Func, const double* Weight=0)
Design a optimal equiripple linear phase FIR filter from a list of bands and the desired amplitudes in each band. nBand defines the number of bands in which the response will be specified. 'Bands' contains a minimum and a maximum frequency for each band. 'Func' contains the desired amplitude for each band and 'Weight' contains an optional weighting factor for each band. The resulting filter coefficients are stored in the Filter object. The filter history is left unmodified.
Parameters:
nBand - Number of bands.
Bands - Band limit frequencies in Hz.
Func - Desired response in each band.
Weight - Weighting factor for each band. If not specified, Weight is assumed to be 1.0 for each band.

void dFirW(int N, const char* window, const char* type, double Flow, double Fhigh=0, double dF=0, double Ripple=0)
Design a linear phase FIR filter using the window function technique. The windowing functions that may be used are "Rectangle", "Triangle", "Hamming", "Hanning", "Kaiser" or "Cheby". Filter types that may be designed are "LowPass", "HighPass", "BandPass" or "BandStop". N or dF will be inferred from the other parameters if omitted or set to zero in Kaiser and Chebyshev designs. The same is true of Ripple if it is omitted or set to zero in Chebyshev designs. The designed Filter coefficients replace the current coefficients. The Filter history is not affected.
Parameters:
N - Number of filter coefficients.
window - Type of window on which to base the design.
type - Type of filter.
Flow - Transition frequency of a low-pass or high-pass filter, or lower edge of a band-pass or band-stop filter.
Fhigh - Upper edge of a band-pass or band-stop filter.
dF - Transition band width in Kaiser and Chebyshev filters.
Ripple - Desired attenuation for Kaiser filters or the desired pass-band ripple for Chebyshev filters (in dB).

void dump(ostream& ostr) const
All filter coefficients and history data are formatted and written to the specified ostream.
Parameters:
ostr - Output stream to receive the Filter info.

DVector& operator)(DVector& in)
Filter the data series in a DVector. The filter response data replace the original data in the DVector, and a reference to the target DVector is returned.
Returns:
reference to the updated DVector.
Parameters:
in - Data vector containing the data to be filtered.

TSeries operator)(const TSeries& in)
The TSeries is filtered and the result placed in a new TSeries. The resulting TSeries is left on the stack and must be copied to be made permanent. The filter status flag is set if there are insufficient history entries (less than the Filter order) or if the TSeries start time isn't contiguous with the previous data. The input samples are appended to the filter history as the filter response is calculated.
Returns:
A new TSeries containing the filter response to the input series.
Parameters:
in - Time series to be filtered.

TSeries& apply(const TSeries& in, TSeries& out)
The TSeries is filtered and the result stored in a specified output TSeries. The output TSeries must already exist. The filter status flag is set if there are insufficient history entries (less than the Filter order) or if the TSeries start time isn't contiguous with the previous data. The input samples are appended to the filter history as the filter response is calculated.
Returns:
reference to the TSeries containing the filter response.
Parameters:
in - Time series to be filtered.
out - Time series into which the filter response will be stored.

TSeries& apply(TSeries& in)
The TSeries is filtered and the result replaces the input TSeries. The filter status flag is set if there are insufficient history entries (less than the Filter order) or if the TSeries start time isn't contiguous with the previous data. The input samples are appended to the filter history as the filter response is calculated.
Returns:
reference to the argument TSeries.
Parameters:
in - TSeries containing the data to be filtered. The filter response is also return in 'in'.

void apply(int N, const float* in, float* out)
An N-point float series is filtered from in and stored in out. in may overlap out. The input samples are appended to the filter history as the filter response is calculated.
Parameters:
N - Number of elements in the input series.
in - Float array containing the input series.
out - Float array to contain the filter response. the end of out may overlap the start of in.

void apply(int N, const fComplex* in, fComplex* out)
An N-point complex series is filtered from in and stored in out. in may overlap out. The input samples are appended to the filter history as the filter response is calculated.
Parameters:
N - Number of elements in the input series.
in - Float array containing the input series.
out - Float array to contain the filter response. the end of out may overlap the start of in.

void setCoefs(int N, const double* Coefs)
Set the filter length and coefficients. The filter history buffer is cleared.
Parameters:
N - Number of coefficients to set.
Coefs - A list of filter coefficients (filter impulse response).

void setHistory(int N, const float* Hist=0, Time t=Time(0))
The specified samples are copied to the Filter history vector. If the number of samples specified is greater than the filter size, only the last Norder samples are used. If the data vector argument is omitted the number of history terms is set as specified and any current data are prefixed with zeroes as needed to fill out the requested number of terms. The history time is optional and represents the time of the latest sample.
Parameters:
N - Number of history elements to preset.
Hist - Filter history vector.
t - Time of the last sample in the history list.

void setHistory(int N, const fComplex* Hist, Time t=Time(0))
The specified samples are copied to the Filter history vector. If the number of samples specified is greater than the filter size, only the last Norder samples are used. If the data vector argument is omitted the number of history terms is set as specified and any current data are prefixed with zeroes as needed to fill out the requested number of terms. The history time is optional and represents the time of the latest sample.
Parameters:
N - Number of history elements to preset.
Hist - Filter history vector.
t - Time of the last sample in the history list.

void setLength(int N)
Set the filter length (order+1). The coefficients and history of the filter are cleared.
Parameters:
N - new filter length.

void setRate(double F)
Set the filter sample Rate.
Parameters:
F - New sample frequency.

FSeries Xfer(float Fmin=0.0, float Fmax=0.0, float dF=1.0) const
The transfer function of the filter in the specified frequency interval is calculated and returned as a complex frequency series.
Returns:
a complex FSeries containing the Filter response at each frequency step.
Parameters:
Fmin - Minimum frequency at which to sample the transfer function.
Fmax - Maximum frequency at which to sample the transfer function.
dF - Frequency step.


This class has no child classes.
Author:
John G. Zweizig
Version:
1.1; Last modified: July 23, 1999

alphabetic index hierarchy of classes


generated by doc++