## Facemorph Class Complex

java.lang.Object
Facemorph.Complex

public class Complex
extends java.lang.Object

Basic complex number class

Field Summary
double x
The real component
double y
The imaginary component

Constructor Summary
Complex(double a, double b)
Constructor for complex number

Method Summary
Add z to this and return the result as a new complex number
Complex conjugate()
Conjugate the complex number
Complex copy()
Returns a new copy of this complex number
Complex divide(Complex z)
Multiply this by z (result = this*z) and return the result as a new complex number
Complex dotProduct(Complex z)
Returns the complex dot product of this with z
static Complex exp(Complex val)
Calculate complex exponential
static Complex[] fft1d(Complex[] data, boolean inverse)
1D FFT
static void fft1d(Complex[] data, Complex[] fft, int N, int step, int start, int out, boolean inverse)
FFT using Danielson-Lancoz lemma to make O(NlogN)
static Complex[] fftNd(Complex[] data, int[] dim, boolean inverse)
Multidimensional FFT, note input data is destroyed by running this and the answer will end up in data, and is also returned
static Complex[] ft1d(Complex[] data, boolean inverse)
Slow direct calculation of fourier transform.
double magnitude()
calculate the magnitude of this complex number
double magnitudeSquared()
calculate the magnitude of this complex number
static void main(java.lang.String[] args)
Main method used for testing
Complex multiply(Complex z)
Multiply this by z (result = this*z) and return the result as a new complex number
Complex subtract(Complex z)
Add z to this and return the result as a new complex number
java.lang.String toString()

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail

### x

public double x
The real component

### y

public double y
The imaginary component

Constructor Detail

### Complex

public Complex(double a,
double b)
Constructor for complex number

Parameters:
a - real part
b - imaginary part
Method Detail

### magnitude

public double magnitude()
calculate the magnitude of this complex number

Returns:
returns the magnitude of the complex number

### conjugate

public Complex conjugate()
Conjugate the complex number

Returns:
returns the complex conjugate of this

### magnitudeSquared

public double magnitudeSquared()
calculate the magnitude of this complex number

Returns:
returns the magnitude of the complex number

### exp

public static Complex exp(Complex val)
Calculate complex exponential

Parameters:
val - the complex value to exponentiate
Returns:
the exponential function result exp(real)(cos(image)+isin(imag))

### ft1d

public static Complex[] ft1d(Complex[] data,
boolean inverse)
Slow direct calculation of fourier transform. Used to test FFT

Parameters:
data - inptu data vector
inverse - used to perform the inverse FT
Returns:
returns the fourier transform of the dta

### fft1d

public static void fft1d(Complex[] data,
Complex[] fft,
int N,
int step,
int start,
int out,
boolean inverse)
FFT using Danielson-Lancoz lemma to make O(NlogN)

Parameters:
data - input data array
fft - outout data array
N - length of portion of data to transform
step - step size along input vector
start - start point to read from
out - start point to write to
inverse - true for inverse FFT

### fft1d

public static Complex[] fft1d(Complex[] data,
boolean inverse)
1D FFT

Parameters:
data - the data to perform the FFT on
inverse - boolean indicates if inverse FFT is needed
Returns:
return the FFT of the input data

### fftNd

public static Complex[] fftNd(Complex[] data,
int[] dim,
boolean inverse)
Multidimensional FFT, note input data is destroyed by running this and the answer will end up in data, and is also returned

Parameters:
data - the input data to transform
dim - the size of each dimension
inverse - true for inverse transform
Returns:
returns the Complex array representing the FFT of the input data

### main

public static void main(java.lang.String[] args)
Main method used for testing

Parameters:
args - args not used

### multiply

public Complex multiply(Complex z)
Multiply this by z (result = this*z) and return the result as a new complex number

Parameters:
z - the number to multiply by this
Returns:
returns the this*z

### divide

public Complex divide(Complex z)
Multiply this by z (result = this*z) and return the result as a new complex number

Parameters:
z - the number to multiply by this
Returns:
returns the this*z

Add z to this and return the result as a new complex number

Parameters:
z - the number to add
Returns:
returns this+z

### copy

public Complex copy()
Returns a new copy of this complex number

Returns:
returns the copy

### subtract

public Complex subtract(Complex z)
Add z to this and return the result as a new complex number

Parameters:
z - the number to add
Returns:
returns this+z

### dotProduct

public Complex dotProduct(Complex z)
Returns the complex dot product of this with z

Parameters:
z - the number to dot product with
Returns:
returns the result of the dot product

### toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object