Class AbstractDigitalFilter
- Direct Known Subclasses:
DigitalAverager
,LtiDigitalFilter
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.)
- Author:
- Christopher K. Allen
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractDigitalFilter
(int intOrder) Create a new filter object for processing discrete signals. -
Method Summary
Modifier and TypeMethodDescriptionint
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
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.toString()
Write out the configuration and state of this filter as a string for inspection.
-
Constructor Details
-
AbstractDigitalFilter
protected AbstractDigitalFilter(int intOrder) Create a new filter object for processing discrete signals.- Parameters:
intOrder
- filter order
-
-
Method Details
-
getInputCoefficient
public abstract double getInputCoefficient(int iTime, int iDelay) Get the input signal coefficient ak(n) for the given time and delay.- Parameters:
iTime
- current timeiDelay
- delay index of the coefficient- Returns:
- output coefficient at time iTime and delay iDelay
-
getOutputCoefficient
public abstract double getOutputCoefficient(int iTime, int iDelay) Get the output signal coefficient bk(n) for the given time and delay.- Parameters:
iTime
- current timeiDelay
- delay index of the coefficient- Returns:
- output coefficient at time iTime and delay iDelay
-
getOrder
public int getOrder()Returns the order of the digital filter.- Returns:
- filter order
-
getCoefficientCount
public int getCoefficientCount()Returns the number of input and output coefficients. This values is one larger than the filter order.- Returns:
- size of coefficient arrays (i.e., DigitalFilter#getOrder() + 1)
-
getTimeIndex
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 toreset()
. After callingreset()
the returned index is zero. Thus, after callingresponse(double)
for the first time the returned value is 1.IMPORTANT
For child classes implementing the methodsgetInputCoefficient(int, int)
andgetOutputCoefficient(int, int)
the methods are called before this index is updated. For example, upon the first call toresponse(double)
these methods will be called with the time index as 0.- Returns:
- the current signal index ("time" index)
- See Also:
-
response
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 methodsgetInputCoefficient(int, int)
andgetOutputCoefficient(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 toresponse(double)
these methods will be called with the time index as 0.- Parameters:
dblInput
- current input signal- Returns:
- response of this filter to the given signal
- See Also:
-
response
public double[] response(double[] arrTrain) Convenience function for computing the response of this filter to an input signal train. This method simply callsresponse(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.- Parameters:
arrTrain
- array of input signal- Returns:
- output signal response of the this filter to given input
- See Also:
-
reset
public void reset()Clears the input and output buffers, resetting filter for a new signal. -
toString
Write out the configuration and state of this filter as a string for inspection.
-