edu.cmu.sphinx.util
Class Complex

java.lang.Object
  extended byedu.cmu.sphinx.util.Complex

public class Complex
extends java.lang.Object

Implements complex types and arythmetics


Constructor Summary
Complex()
          Create a default complex number
Complex(double real)
          Create a complex number from a real one
Complex(double real, double imaginary)
          Create a complex number from the real and imaginary parts
 
Method Summary
 void addComplex(Complex a, Complex b)
          Method to add two complex numbers.
 void divideComplex(Complex a, Complex b)
          Method to divide two complex numbers.
 double getImaginary()
          Returns the imaginary part of this Complex number.
 double getReal()
          Returns the real part of this Complex number.
 void multiplyComplex(Complex a, Complex b)
          Method to multiply two complex numbers.
 void reset()
          Sets both the real and imaginary parts of this complex number to zero.
 void scaleComplex(Complex a, double b)
          Method to scale a complex number by a real one.
 void set(double real, double imaginary)
          Sets the real and imaginary parts of this complex number.
 double squaredMagnitudeComplex()
          Method to compute the squared magnitude of a complex number.
 void subtractComplex(Complex a, Complex b)
          Method to subtract two complex numbers.
 java.lang.String toString()
          Returns this complex number as a string in the format (real, imaginary).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Complex

public Complex()
Create a default complex number


Complex

public Complex(double real)
Create a complex number from a real one


Complex

public Complex(double real,
               double imaginary)
Create a complex number from the real and imaginary parts

Method Detail

getReal

public double getReal()
Returns the real part of this Complex number.

Returns:
the real part

getImaginary

public double getImaginary()
Returns the imaginary part of this Complex number.

Returns:
the imaginary part

reset

public void reset()
Sets both the real and imaginary parts of this complex number to zero.


set

public void set(double real,
                double imaginary)
Sets the real and imaginary parts of this complex number.

Parameters:
real - the value of the real part
imaginary - the value of the imaginary part

addComplex

public void addComplex(Complex a,
                       Complex b)
Method to add two complex numbers.

Parameters:
a - the first element to be added
b - the second element to be added

subtractComplex

public void subtractComplex(Complex a,
                            Complex b)
Method to subtract two complex numbers.

Parameters:
a - the element we subtract from
b - the element to be subtracted

multiplyComplex

public void multiplyComplex(Complex a,
                            Complex b)
Method to multiply two complex numbers.

Parameters:
a - the first element to multiply
b - the second element to multiply

divideComplex

public void divideComplex(Complex a,
                          Complex b)
Method to divide two complex numbers. To divide two complexes, we multiply by the complex conjugate of the denominator, thus resulting in a real number in the denominator.

Parameters:
a - the numerator
b - the denominator

scaleComplex

public void scaleComplex(Complex a,
                         double b)
Method to scale a complex number by a real one. The input complex number is modified in place.

Parameters:
a - the complex number
b - the real scaling factor

squaredMagnitudeComplex

public double squaredMagnitudeComplex()
Method to compute the squared magnitude of a complex number.

Returns:
the squared magnitude of the complex number

toString

public java.lang.String toString()
Returns this complex number as a string in the format (real, imaginary).