Package xal.tools.dsp

Class AbstractDigitalFilter

java.lang.Object
xal.tools.dsp.AbstractDigitalFilter
Direct Known Subclasses:
DigitalAverager, LtiDigitalFilter

public abstract class AbstractDigitalFilter extends 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.)

Author:
Christopher K. Allen
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractDigitalFilter(int intOrder)
    Create a new filter object for processing discrete signals.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    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
    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
    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.
    Write out the configuration and state of this filter as a string for inspection.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 time
      iDelay - 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 time
      iDelay - 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 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.

      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.reset() should be called.

      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.

      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 calls 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.
      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

      public String toString()
      Write out the configuration and state of this filter as a string for inspection.
      Overrides:
      toString in class Object
      Returns:
      configuration and state of this filter in text form
      See Also: