jfftw
Class DataArray

java.lang.Object
  extended by jfftw.DataArray
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ComplexDataArray, RealDataArray

public abstract class DataArray
extends Object
implements Cloneable

Abstract Class type to manipulate hold data for FFTW methods. Internally the data is held as an interleaved double[] array as used by the FFTW library by this class take care of most of the array indexing and access problems via its supplied methods. This is however at the cost of some efficiency.

Users wanting to take simple one-off FFT should use this classes, and the extending classes RealDataArray and ComplexDataArray rather than the lower level FFTW classes.


Field Summary
protected  int conversionFlag
          Flag for Complex to double conversion, initially defaults to Complex.MODULUS
protected  int currentWidth
          Current width span of data, this will alter under FFTs of real data.
protected  double[] dataBuffer
          Internal data buffer holding the data in double[] array
protected  int depth
          Depth or third size of the data array
protected  PrintStream errorStream
          PrintStream on which errors are printed.
protected static FFTW fftw
          Static FFTW object used for taking the ffts, this is loaded statically once and pass shared to all instances.
protected  int height
          Height or secondary size of data array.
protected  int space
          Space flag initially defaults to FFTW.REAL
protected  int width
          Width or primary size of the data array.
 
Constructor Summary
DataArray()
           
 
Method Summary
 void add(DataArray d)
          Method to add a specified DataArray to the current DataArray, both must be the same size.
 void add(int i, Complex c)
          Method to add a Complex to an element in one-dimensions.
abstract  void add(int i, double a)
          Method to add a real double to an element in one-dimensions.
abstract  void add(int i, double a, double b)
          Method to add a complex to an element in one-dimensions.
 void add(int i, int j, Complex c)
          Method to add a Complex to an element in two-dimensions.
 void add(int i, int j, double a)
          Method to add a real double to an element in two-dimensions.
 void add(int i, int j, int k, Complex c)
          Method to add a Complex to an element in three-dimensions.
 void add(int i, int j, int k, double a)
          Method to add a real double to an element in three-dimensions.
 void centreFourier()
          Method to form centred Fourier using applying checker pattern to shift DC the centre of the array.
abstract  void checker()
          Abstract method to apply a checker pattern to shift the centre
 void clear()
          Method to clear the databuffer by setting all elements to zero.
 void conjugate()
          Method to take conjugate of the whole DataBuffer.
abstract  void conjugate(int i)
          Method to form the Complex conjugate of an element in one-dimensions.
 void conjugate(int i, int j)
          Method to form the Complex conjugate of an element in two-dimensions.
 void conjugate(int i, int j, int k)
          Method to form the Complex conjugate of an element in three-dimensions.
abstract  void fourier()
          Abstract method to form the un-shifted Fourier transform
abstract  Complex getComplex(int i)
          Method to get the value of Complex element in one-dimensions case.
 Complex getComplex(int i, int j)
          Method to get the value of a Complex element in two-dimensions.
 Complex getComplex(int i, int j, int k)
          Method to get the value of a Complex element in three-dimensions
 int getConversion()
          Method to get the current Complex to double conversion flag.
 int getCurrentWidth()
          Method to get the current width data width.
 double[] getDataBuffer()
          Method to get the current internal dataBuffer as a double[].
 int getDepth()
          Method to get the data depth (tertiary direction).
abstract  double getDouble(int i)
          Method to get value of double element in one-dimension.
 double getDouble(int i, int j)
          Method to get value of double element in two-dimensions.
 double getDouble(int i, int j, int k)
          Method to get value of double element in three-dimensions
 FFTW getFFTW()
          Method to return the underlying FFTW class.
 int getHeight()
          Method to get the data height (secondary direction).
 boolean getNormalisation()
          Method to get the normalisation flag.
 RealDataArray getRealDataArray()
          Get the current DataArray are a RealDataArray using the internal conversion flag
 RealDataArray getRealDataArray(int conversion)
          Get the current DataArray as a RealData array using the specified conversion flag.
 int getSpace()
          Method to get the current space description flag.
 String getType()
          Method to get the type (actually the class name) as a String.
 int getWidth()
          Method to get the data width (primary direction).
 boolean isComplex()
          Method to determine if the current data is Complex.
 int length()
          Method to get the length of the internal double[] dataBuffer
 double maxModSqr()
          Method to get the largest modulus square value in the DataBuffer This is valid for both real and complex data
 void mult(Complex c)
          Method to multiply the whole DataArray by a Complex.
 void mult(DataArray d)
          Method to multiply the current DataArray by a specified DataArray which must be of the same size, the result overwriting the contents of the current DataArray.
 void mult(double a)
          Method to muliply the whole DataArray by a scalar
 void mult(double a, double b)
          Method to multiply the whole DataArray by a complex specifed as two doubles.
 void mult(int i, Complex c)
          Method to multiply an element by a Complex in one-dimension.
abstract  void mult(int i, double a)
          Method to multiple an element by a double in one-dimensions.
abstract  void mult(int i, double a, double b)
          Method to multiply an element by a Complex in one-dimension.
 void mult(int i, int j, Complex c)
          Method to multiply an element by a Complex in two-dimension.
 void mult(int i, int j, double a)
          Method to multiple an element by a double in two-dimensions.
 void mult(int i, int j, int k, Complex c)
          Method to multiply an element by a Complex in three-dimension.
 void mult(int i, int j, int k, double a)
          Method to multiple an element by a double in three-dimensions.
 void multConjugate(DataArray d)
          Method to multiply the current DataArray by the Complex Conjugate of specified DataArray which must be of the same size the result overwriting the contents of the current DataArray.
protected  void normaliseDB()
          Protected method to normalise the data buffer
 double power()
          Method to get the total power in the DataSet being the sum of the modulus squared of all the elements
 RealDataArray powerSpectrum(boolean logPower)
          Method to get the PowerSpectrum as a RealDataArray In data is in real space, then it is automatically Fourier transformed using centreFourier.
 void setComplex(int i, Complex c)
          Method to set an element with a Complex in one dimensions.
abstract  void setComplex(int i, double a, double b)
          Method to set an element with a complex specified as two doubles in one-dimension.
 void setComplex(int i, int j, Complex c)
          Method to set an element with a Complex in two-dimensions.
 void setComplex(int i, int j, double a, double b)
          Method to set an element with a complex in two-dimensions
 void setComplex(int i, int j, int k, Complex c)
          Method to set an element with a Complex in three-dimensions.
 void setComplex(int i, int j, int k, double a, double b)
          Method to set an element with a Complex point in three-dimension.
 void setConversion(int flag)
          Method to set default conversion from Complex to double.
 void setDataBuffer(double[] db)
          Method to set the internal dataBuffer to specified double[] array.
 void setDimensions(int w, int h, int d)
          Method to set the sizes, not normally called directly since there is no interval sanity checking.
abstract  void setDouble(int i, double value)
          Method to set element with a double in one-dimension.
 void setDouble(int i, int j, double value)
          Method to set element with a double in two-dimensions.
 void setDouble(int i, int j, int k, double value)
          Method to set element with a double in three-dimensions.
 void setNormalisation(boolean b)
          Method to control auto normalisation on inverse flag, which is by default set to true.
 void setSpace(int s)
          Method to set the space.
 boolean sizeMatch(DataArray d)
          Method to test if specified DataArray is of the same size at the current DataArray
 String toString()
          Default toString method to report information about DataArray.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fftw

protected static FFTW fftw
Static FFTW object used for taking the ffts, this is loaded statically once and pass shared to all instances.


errorStream

protected PrintStream errorStream
PrintStream on which errors are printed. Initially defaults to System.err


dataBuffer

protected double[] dataBuffer
Internal data buffer holding the data in double[] array


conversionFlag

protected int conversionFlag
Flag for Complex to double conversion, initially defaults to Complex.MODULUS


width

protected int width
Width or primary size of the data array.


currentWidth

protected int currentWidth
Current width span of data, this will alter under FFTs of real data.


height

protected int height
Height or secondary size of data array.


depth

protected int depth
Depth or third size of the data array


space

protected int space
Space flag initially defaults to FFTW.REAL

Constructor Detail

DataArray

public DataArray()
Method Detail

length

public int length()
Method to get the length of the internal double[] dataBuffer

Returns:
int length of dataBuffer

getType

public String getType()
Method to get the type (actually the class name) as a String.

Returns:
String type

getDataBuffer

public double[] getDataBuffer()
Method to get the current internal dataBuffer as a double[].

Take great care using this with RealDataArray since the internal dataBuffer is re-located by its fourier() method.

Returns:
double[] the internal dataBuffer
See Also:
RealDataArray, fourier()

setDataBuffer

public void setDataBuffer(double[] db)
Method to set the internal dataBuffer to specified double[] array.

Warning there is no internal sanity checking here. Really check you know what you are doing before using this. If you are programming at this level your really should be using the direct FFTW classes!

Parameters:
db - the dataBuffer

setSpace

public void setSpace(int s)
Method to set the space. Initially defaults to FFTW.REAL.

If using RealDataArray class take extreme care using this; remember it does not change the data format, just the space designation flag.

Parameters:
s - FFTW.REAL or FFTW.FOURIER

setDimensions

public void setDimensions(int w,
                          int h,
                          int d)
Method to set the sizes, not normally called directly since there is no interval sanity checking.

Not normally called by users, use with extreme care. If sizes do not match the data buffer you will get rubbish or will crash your JRE, you have been warned!

Parameters:
w - the width
h - the height
d - the depth

getSpace

public int getSpace()
Method to get the current space description flag.

Returns:
intSpace code, either FFTW.REAL or FFTW.FOURIER

getWidth

public int getWidth()
Method to get the data width (primary direction).

Returns:
int the width
See Also:
getCurrentWidth()

getCurrentWidth

public int getCurrentWidth()
Method to get the current width data width. Only different from getWidth() when in real Hermition Complex form when using RealDataArray objects.

Returns:
int the current width.
See Also:
getWidth()

getHeight

public int getHeight()
Method to get the data height (secondary direction). This will be 1 for one-dimensional data.

Returns:
int the height

getDepth

public int getDepth()
Method to get the data depth (tertiary direction). This will be 1 for one or two-dimensional data.

Returns:
int the depth

getConversion

public int getConversion()
Method to get the current Complex to double conversion flag.

Returns:
int conversion flag

setConversion

public void setConversion(int flag)
Method to set default conversion from Complex to double. Default is Complex.MODULUS

Parameters:
flag - the conversion flag.

setNormalisation

public void setNormalisation(boolean b)
Method to control auto normalisation on inverse flag, which is by default set to true.

Parameters:
b - the flag

getNormalisation

public boolean getNormalisation()
Method to get the normalisation flag.

Returns:
boolean the normalisation flag

isComplex

public boolean isComplex()
Method to determine if the current data is Complex. Data will be complex unless it is a RealDataArray in real space.

Returns:
boolean true if data is Complex

getFFTW

public FFTW getFFTW()
Method to return the underlying FFTW class.

Warning the FFTW class is loaded as static so changes to this will affect all instances.


toString

public String toString()
Default toString method to report information about DataArray. This includes type, width, height, depth and current space.

Overrides:
toString in class Object
Returns:
String information String.

getDouble

public abstract double getDouble(int i)
Method to get value of double element in one-dimension. If data is Complex, then the current Complex to double conversion rule is applied.

Parameters:
i - the element index

getDouble

public double getDouble(int i,
                        int j)
Method to get value of double element in two-dimensions.

Parameters:
i - primary index
j - secondary index
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

getDouble

public double getDouble(int i,
                        int j,
                        int k)
Method to get value of double element in three-dimensions

Parameters:
i - primary index
j - secondary index
k - third index
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

getComplex

public abstract Complex getComplex(int i)
Method to get the value of Complex element in one-dimensions case. If the data is real then the values will be returned in the real part of the Complex, with the imaginary set to zero.

Parameters:
i - the element index

getComplex

public Complex getComplex(int i,
                          int j)
Method to get the value of a Complex element in two-dimensions.

Parameters:
i - primary index
j - secondary index
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

getComplex

public Complex getComplex(int i,
                          int j,
                          int k)
Method to get the value of a Complex element in three-dimensions

Parameters:
i - primary index
j - secondary index
k - third index
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

clear

public void clear()
Method to clear the databuffer by setting all elements to zero. Works for real and complex cases.


setDouble

public abstract void setDouble(int i,
                               double value)
Method to set element with a double in one-dimension. In the data is complex the Real part will be set.

Parameters:
i - the element index
value - the value

setDouble

public void setDouble(int i,
                      int j,
                      double value)
Method to set element with a double in two-dimensions.

Parameters:
i - primary index
j - secondary index
value - the value
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

setDouble

public void setDouble(int i,
                      int j,
                      int k,
                      double value)
Method to set element with a double in three-dimensions.

Parameters:
i - primary index
j - secondary index
k - third index
value - the value
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

setComplex

public abstract void setComplex(int i,
                                double a,
                                double b)
Method to set an element with a complex specified as two doubles in one-dimension.

Parameters:
i - the element index
a - the real part
b - the imaginary part

setComplex

public void setComplex(int i,
                       Complex c)
Method to set an element with a Complex in one dimensions.

Parameters:
i - the element
c - the Complex value

setComplex

public void setComplex(int i,
                       int j,
                       double a,
                       double b)
Method to set an element with a complex in two-dimensions

Parameters:
i - primary index
j - secondary index
a - the real part
b - the imaginary part
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

setComplex

public void setComplex(int i,
                       int j,
                       Complex c)
Method to set an element with a Complex in two-dimensions.

Parameters:
i - primary index
j - secondary index
c - the Complex value
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

setComplex

public void setComplex(int i,
                       int j,
                       int k,
                       double a,
                       double b)
Method to set an element with a Complex point in three-dimension.

Parameters:
i - primary index
j - secondary index
k - third index
a - the real part
b - the imaginary part
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

setComplex

public void setComplex(int i,
                       int j,
                       int k,
                       Complex c)
Method to set an element with a Complex in three-dimensions.

Parameters:
i - primary index
j - secondary index
k - third index
c - the Complex value
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

add

public abstract void add(int i,
                         double a)
Method to add a real double to an element in one-dimensions.

Parameters:
i - the element index
a - to be added

mult

public abstract void mult(int i,
                          double a)
Method to multiple an element by a double in one-dimensions.

Parameters:
i - the element index
a - the multiplier

add

public void add(int i,
                int j,
                double a)
Method to add a real double to an element in two-dimensions.

Parameters:
i - the primary index
j - the secondary index
a - to be added
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

mult

public void mult(int i,
                 int j,
                 double a)
Method to multiple an element by a double in two-dimensions.

Parameters:
i - the primary index
j - the secondary index
a - the multiplier
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

add

public void add(int i,
                int j,
                int k,
                double a)
Method to add a real double to an element in three-dimensions.

Parameters:
i - the primary index
j - the secondary index
k - the third index
a - to be added
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

mult

public void mult(int i,
                 int j,
                 int k,
                 double a)
Method to multiple an element by a double in three-dimensions.

Parameters:
i - the primary index
j - the secondary index
k - the third index
a - the multiplier
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

add

public abstract void add(int i,
                         double a,
                         double b)
Method to add a complex to an element in one-dimensions.

Parameters:
i - the element index
a - the real part
b - the imaginary parts

mult

public abstract void mult(int i,
                          double a,
                          double b)
Method to multiply an element by a Complex in one-dimension.

Parameters:
i - the element index
a - the real part
b - the imaginary parts

add

public void add(int i,
                Complex c)
Method to add a Complex to an element in one-dimensions.

Parameters:
i - the element index
c - to be added

mult

public void mult(int i,
                 Complex c)
Method to multiply an element by a Complex in one-dimension.

Parameters:
i - the element index
c - the multiplier

add

public void add(int i,
                int j,
                Complex c)
Method to add a Complex to an element in two-dimensions.

Parameters:
i - the primary index
j - the secondary index
c - to be added

mult

public void mult(int i,
                 int j,
                 Complex c)
Method to multiply an element by a Complex in two-dimension.

Parameters:
i - the primary index
j - the secondary index
c - the multiplier

add

public void add(int i,
                int j,
                int k,
                Complex c)
Method to add a Complex to an element in three-dimensions.

Parameters:
i - the primary index
j - the secondary index
k - the third index
c - to be added

mult

public void mult(int i,
                 int j,
                 int k,
                 Complex c)
Method to multiply an element by a Complex in three-dimension.

Parameters:
i - the primary index
j - the secondary index
k - the third index
c - the multiplier

mult

public void mult(double a)
Method to muliply the whole DataArray by a scalar

Parameters:
a - the scalar

mult

public void mult(double a,
                 double b)
Method to multiply the whole DataArray by a complex specifed as two doubles. This is only valid if the data is Complex.

Parameters:
a - the real part
b - the imaginary.

mult

public void mult(Complex c)
Method to multiply the whole DataArray by a Complex. This is only valid if the data is Complex.

Parameters:
c - the Complex multiplier.

conjugate

public abstract void conjugate(int i)
Method to form the Complex conjugate of an element in one-dimensions.

Parameters:
i - the element index

conjugate

public void conjugate(int i,
                      int j)
Method to form the Complex conjugate of an element in two-dimensions.

Parameters:
i - first element index
j - second element index
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

conjugate

public void conjugate(int i,
                      int j,
                      int k)
Method to form the Complex conjugate of an element in three-dimensions.

Parameters:
i - first element index
j - second element index
k - the third index
Throws:
ArrayIndexOutOfBoundsException - exception if out of data bounds.

conjugate

public void conjugate()
Method to take conjugate of the whole DataBuffer. If data is real this call is ignored.


fourier

public abstract void fourier()
Abstract method to form the un-shifted Fourier transform


checker

public abstract void checker()
Abstract method to apply a checker pattern to shift the centre


centreFourier

public void centreFourier()
Method to form centred Fourier using applying checker pattern to shift DC the centre of the array.

This will only work for even dimensions, if called with data of odd size, an error message will be printed and the normal fourier() will be taken.


maxModSqr

public double maxModSqr()
Method to get the largest modulus square value in the DataBuffer This is valid for both real and complex data

Returns:
double the maximum modulus square

power

public double power()
Method to get the total power in the DataSet being the sum of the modulus squared of all the elements

Returns:
double the power

getRealDataArray

public RealDataArray getRealDataArray(int conversion)
Get the current DataArray as a RealData array using the specified conversion flag.

If the current DataArray is RealDataArray in real space then the current DataArray is returned, else a new ReadDataArray of the correct dimensions is returned.

Parameters:
conversion - the conversion flag
Returns:
RealDataArray the converted Real array

getRealDataArray

public RealDataArray getRealDataArray()
Get the current DataArray are a RealDataArray using the internal conversion flag

Returns:
RealDataArray the converted Real array

powerSpectrum

public RealDataArray powerSpectrum(boolean logPower)
Method to get the PowerSpectrum as a RealDataArray In data is in real space, then it is automatically Fourier transformed using centreFourier.

After this call the current DataArray will be in Fourier space.

Parameters:
logPower - if true the log power formed, else modulus squared used.
Returns:
RealDataArray the power spectrum.

sizeMatch

public boolean sizeMatch(DataArray d)
Method to test if specified DataArray is of the same size at the current DataArray

Returns:
boolean true if match, false otherwise.

add

public void add(DataArray d)
Method to add a specified DataArray to the current DataArray, both must be the same size.

This will work for all conbinations expect for current DataArray being Real and specifed DataArray being Complex.

Internally this uses direct array access so it much more efficient than loops with setter/getters.

Parameters:
d - the DataArray to be added.

mult

public void mult(DataArray d)
Method to multiply the current DataArray by a specified DataArray which must be of the same size, the result overwriting the contents of the current DataArray.

This will work for all conbinations expect for current DataArray being Real and specifed DataArray being Complex.

Internal this uses uses direct array access so it much more efficient than loops with setter/getters.

Parameters:
d - the DataArray

multConjugate

public void multConjugate(DataArray d)
Method to multiply the current DataArray by the Complex Conjugate of specified DataArray which must be of the same size the result overwriting the contents of the current DataArray.

If the current or specifed DataArray(s) are real, then this method is identical to mult(DataArray)

Parameters:
d - the DataArray
See Also:
mult(DataArray)

normaliseDB

protected void normaliseDB()
Protected method to normalise the data buffer