public abstract class AbstractDigitalFilter
extends java.lang.Object
Implements the fundamental behavior and characteristics of a digital filter of finite order with real coefficients. Child classes can implement methods for determining the filter coefficients for desired bandwidth and other transfer characteristics (i.e., Butterworth, Chebychev, etc.). Once the filter coefficients are determined this class contains most of the common behavior of a general digital filter.
The transfer characteristics for an Nth order digital
filter are given by the following:
b0(n)y(n)
+ b1(n)y(n-1)
+ …
+ bN(n)y(n-N)
= a0(n)x(n)
+ a1(n)x(n-1)
+ …
+ aN(n)x(n-N)
where n is the current ("time") index, the {x(n)} are the
inputs to the filter at time n, the {ak(n)}
are the input coefficients at time n for delay k,
the {y(n)} are the filter outputs at time n,
and the {bk(n)} are the output coefficients at time n
for delay k. The equation can be
rearranged to explicitly demonstrate the current output y(n) in terms
of the past N inputs and output
y(n)
= (
a0(n)x(n)
+ a1(n)x(n-1)
+ …
+ aN(n)x(n-N)
- b1(n)y(n-1)
- …
- bN(n)y(n-N)
)/b0(n)
Note that the coefficient b0 is essentially just an attenuation/amplification
factor. (In fact, a zeroth-order digital filter is just that.)
Constructor and Description |
---|
AbstractDigitalFilter(int intOrder)
Create a new filter object for processing discrete signals.
|
Modifier and Type | Method and Description |
---|---|
int |
getCoefficientCount()
Returns the number of input and output coefficients.
|
abstract double |
getInputCoefficient(int iTime,
int iDelay)
Get the input signal coefficient ak(n) for
the given time and delay.
|
int |
getOrder()
Returns the order of the digital filter.
|
abstract double |
getOutputCoefficient(int iTime,
int iDelay)
Get the output signal coefficient bk(n) for
the given time and delay.
|
int |
getTimeIndex()
Return the value of the current time index.
|
void |
reset()
Clears the input and output buffers, resetting filter for
a new signal.
|
double |
response(double dblInput)
Compute and return the response of the filter to the given
input.
|
double[] |
response(double[] arrTrain)
Convenience function for computing the response of this filter to
an input signal train.
|
java.lang.String |
toString()
Write out the configuration and state of this filter
as a string for inspection.
|
public AbstractDigitalFilter(int intOrder)
intOrder
- filter orderpublic abstract double getInputCoefficient(int iTime, int iDelay)
iTime
- current timeiDelay
- delay index of the coefficientpublic abstract double getOutputCoefficient(int iTime, int iDelay)
iTime
- current timeiDelay
- delay index of the coefficientpublic int getOrder()
public int getCoefficientCount()
public int getTimeIndex()
Return the value of the current time index. This value is the number
of signal values processed (by a call to response(double)
)
since the last call to reset()
.
After calling reset()
the returned index is zero. Thus, after
calling response(double)
for the first time the returned value is 1.
IMPORTANT
For child classes implementing the methods
getInputCoefficient(int, int)
and
getOutputCoefficient(int, int)
the methods are called before this index is updated.
For example, upon the first call to response(double)
these methods will be called with the time index as 0.
reset()
,
response(double)
public double response(double dblInput)
Compute and return the response of the filter to the given input. The returned response is assumed to be part of a train of values with depends upon the previous inputs to this method. The number of previous input values to which the output depends is given by the order of this filter.
To begin processing a new input signal train the method
DigitalFilter.
should be called.
reset()
IMPORTANT
For child classes, the methods
getInputCoefficient(int, int)
and
getOutputCoefficient(int, int)
are called within this method to retrieve the filter coefficients
at the current time index. The index used in these calls is the
pre-updated value, not the value after this function returns.
For example, upon the first call to response(double)
these methods will be called with the time index as 0.
dblInput
- current input signalreset()
,
getOrder()
public double[] response(double[] arrTrain)
response(double)
sequentially by increasing index
for each element of the argument arrTrain. Thus, the
returned response depends upon the initial state of the filter when
this method is called.arrTrain
- array of input signalresponse(double)
public void reset()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()