com.oregondsp.signalProcessing.filter.iir
Class Polynomial

java.lang.Object
  extended by com.oregondsp.signalProcessing.filter.iir.Polynomial

public class Polynomial
extends java.lang.Object

Class to implement polynomial functions

This class represents polynomials by their coefficients, stored in a double array, with the lowest coefficient (constant) stored at the 0 location. Consequently the polynomial is of the form:

A(x) = a[0] + a[1]*x + a[2]*x2 + ... + a[N]*xN

The class implements basic polynomial arithmetic and other functions useful in designing analog and digital filters. An example of the latter includes the calculation of reflection coefficients for use in allpass filters.

Author:
David B. Harris, Deschutes Signal Processing LLC

Constructor Summary
Polynomial(double c)
          Instantiates a new constant polynomial.
Polynomial(double[] a)
          Instantiates a new polynomial from a double array containing the coefficients.
Polynomial(int order)
          Instantiates a new zero polynomial.
Polynomial(Polynomial B)
          Instantiates (copies) a new polynomial from an existing Polynomial instance.
 
Method Summary
 double[] coefficients()
          Returns the polynomial coefficients.
 Polynomial derivative()
          Computes the derivative of a polynomial.
 double discreteTimeGroupDelay(double Omega)
          Evaluates the group delay of a discrete time filter transfer function specified by this polynomial.
 Complex evaluate(Complex c)
          Evaluates this polynomial for a complex argument.
 double evaluate(double x)
          Evaluates this polynomial for a real argument.
 double groupDelay(double omega)
          Evaluates the group delay of an analog filter transfer function specified by this polynomial.
 Polynomial minus(double c)
          Returns a new Polynomial containing the difference between this polynomial and a constant.
 Polynomial minus(Polynomial B)
          Subtracts a polynomial from this polynomial.
 void minusEquals(double c)
          Subtracts a constant from this polynomial.
 void minusEquals(Polynomial B)
          Subtracts a polynomial from this polynomial.
 int order()
          Returns the order (degree) of the polynomal.
 Polynomial over(double c)
          Divides this polynomial by a constant and returns the result of division in a new Polynomial object.
 Rational over(Polynomial B)
          Divides this polynomial by another polynomial.
 void overEquals(double c)
          Divides this polynomial by a constant.
 Polynomial plus(double c)
          Returns a new Polynomial object containing the sum polynomial of this and a constant.
 Polynomial plus(Polynomial B)
          Returns a new Polynomial object containing the sum of this and the argument polynomial.
 void plusEquals(double c)
          Adds a constant to this polynomial.
 void plusEquals(Polynomial B)
          Adds a polynomial to this polynomial.
 void print(java.io.PrintStream ps)
          Prints the coefficients of this polynomial to a PrintStream.
 double[] reflectionCoefficients()
          Computes reflection coefficients for this polynomial.
 Polynomial times(double c)
          Computes the product of a constant and this polynomial.
 Polynomial times(Polynomial B)
          Computes the product of this polynomial with another polynomial.
 void timesEquals(double c)
          Multiplies (scales) this polynomial by a constant.
 void timesEquals(Polynomial B)
          Multiplies this by a Polynomial factor.
 void trim()
          Removes leading zero coefficients in a polynomial.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Polynomial

public Polynomial(double[] a)
Instantiates a new polynomial from a double array containing the coefficients.

Parameters:
a - double[] containing the polynomial coefficients.

Polynomial

public Polynomial(Polynomial B)
Instantiates (copies) a new polynomial from an existing Polynomial instance.

Parameters:
B - Polynomial to be copied into the new Instance.

Polynomial

public Polynomial(int order)
Instantiates a new zero polynomial.

Parameters:
order - int containing the order (degree) of the polynomial.

Polynomial

public Polynomial(double c)
Instantiates a new constant polynomial.

Parameters:
c - double containing the constant.
Method Detail

trim

public void trim()
Removes leading zero coefficients in a polynomial. This method is used by the Rational class when new polynomials have been constructed in a rational mapping operation.


order

public int order()
Returns the order (degree) of the polynomal.

Returns:
int containing the degree of the polynomial.

coefficients

public double[] coefficients()
Returns the polynomial coefficients.

Returns:
double[] containing a copy of the coefficients.

plus

public Polynomial plus(double c)
Returns a new Polynomial object containing the sum polynomial of this and a constant. The original Polynomial is unchanged.

Parameters:
c - double constant to be added to this polynomial.
Returns:
The new polynomial containing the sum of this polynomial and the constant.

plusEquals

public void plusEquals(double c)
Adds a constant to this polynomial. Alters this to contain the sum.

Parameters:
c - double constant to be added to this polynomial.

plus

public Polynomial plus(Polynomial B)
Returns a new Polynomial object containing the sum of this and the argument polynomial. The original Polynomial is unchanged.

Parameters:
B - Polynomial to be added to this polynomial.
Returns:
Polynomial object containing the new sum.

plusEquals

public void plusEquals(Polynomial B)
Adds a polynomial to this polynomial. Alters this to contain the sum.

Parameters:
B - Polynomial object containing the polynomial to be added to this polynomial.

minus

public Polynomial minus(double c)
Returns a new Polynomial containing the difference between this polynomial and a constant. This polynomial is unchanged.

Parameters:
c - double containing the constant to be subtracted from this polynomial.
Returns:
The new Polynomial object containing the difference polynomial.

minusEquals

public void minusEquals(double c)
Subtracts a constant from this polynomial. Alters this to contain the difference.

Parameters:
c - double constant to be subtracted from this polynomial.

minus

public Polynomial minus(Polynomial B)
Subtracts a polynomial from this polynomial. Returns the difference as a new Polynomial. This polynomial is unchanged.

Parameters:
B - Polynomial to be subtracted from this Polynomial.
Returns:
Polynomial containing the difference.

minusEquals

public void minusEquals(Polynomial B)
Subtracts a polynomial from this polynomial. Alters this to contain the difference.

Parameters:
B - Polynomial to be subtracted from this polynomial.

times

public Polynomial times(double c)
Computes the product of a constant and this polynomial. The product is returned as a new Polynomial. This polynomial is unchanged.

Parameters:
c - The double constant factor multiplying this polynomial.
Returns:
The resulting product polynomial.

timesEquals

public void timesEquals(double c)
Multiplies (scales) this polynomial by a constant. This polynomial is changed to contain the product.

Parameters:
c - The constant multiplicative factor.

times

public Polynomial times(Polynomial B)
Computes the product of this polynomial with another polynomial. The product is returned in a new Polynomial.

Parameters:
B - Polynomial object containing the multiplicative factor.
Returns:
New Polynomial object containing the product.

timesEquals

public void timesEquals(Polynomial B)
Multiplies this by a Polynomial factor. Alters this polynomial to contain the product.

Parameters:
B - Polynomial object containing the multiplicative factor.

over

public Polynomial over(double c)
Divides this polynomial by a constant and returns the result of division in a new Polynomial object. This polynomial is unchanged by this method.

Parameters:
c - The double divisor.
Returns:
New Polynomial object containing the result of division.

overEquals

public void overEquals(double c)
Divides this polynomial by a constant. This polynomial is altered to contain the result of division.

Parameters:
c - The double divisor.

over

public Rational over(Polynomial B)
Divides this polynomial by another polynomial. Returns the result of division in a new Rational object. This polynomial is unchanged by this operation.

Parameters:
B - The Polynomial divisor.
Returns:
New Rational object containing the result of division.

derivative

public Polynomial derivative()
Computes the derivative of a polynomial. Returns the derivative as a new Polynomial object.

Returns:
New Polynomial object containing the derivative of this polynomial.

evaluate

public double evaluate(double x)
Evaluates this polynomial for a real argument.

Parameters:
x - double containing the argument of the polynomial.
Returns:
double containing the value of the polynomial at this argument.

evaluate

public Complex evaluate(Complex c)
Evaluates this polynomial for a complex argument.

Parameters:
c - Complex object containing the argument of the polynomial.
Returns:
Complex object containing the value of the polynomial at this argument.

groupDelay

public double groupDelay(double omega)
Evaluates the group delay of an analog filter transfer function specified by this polynomial.

Parameters:
omega - double specifying the radial frequency (2*pi*f) at which the group delay is evaluated.
Returns:
double containing the resulting group delay in seconds.

discreteTimeGroupDelay

public double discreteTimeGroupDelay(double Omega)
Evaluates the group delay of a discrete time filter transfer function specified by this polynomial.

Parameters:
Omega - double specifying the value discrete-time frequency [0 pi] at which the group delay is evaluated.
Returns:
double containing the resulting group delay in samples.

reflectionCoefficients

public double[] reflectionCoefficients()
Computes reflection coefficients for this polynomial.

Returns:
double[] containing the reflection coefficient representation for this polynomial.

print

public void print(java.io.PrintStream ps)
Prints the coefficients of this polynomial to a PrintStream.

Parameters:
ps - PrintStream object to which this polynomial's coefficients are printed.