edu.emory.mathcs.jtransforms.fft

## Class RealFFTUtils_2D

• ```public class RealFFTUtils_2D
extends Object```

This is a set of utility methods for R/W access to data resulting from a call to the Fourier transform of real data. Memory optimized methods, namely

are implemented to handle this case specifically. However, packing of the data in the data array is somewhat obscure. This class provides methods for direct access to the data, without the burden of all necessary tests.

### Example for Fourier Transform of real, double precision 1d data

```   DoubleFFT_2D fft = new DoubleFFT_2D(rows, columns);
double[] data = new double[2 * rows * columns];
...
fft.realForwardFull(data);
data[r1 * 2 * columns + c1] = val1;
val2 = data[r2 * 2 * columns + c2];
```
is equivalent to
```   DoubleFFT_2D fft = new DoubleFFT_2D(rows, columns);
RealFFTUtils_2D unpacker = new RealFFTUtils_2D(rows, columns);
double[] data = new double[rows * columns];
...
fft.realForward(data);
unpacker.pack(val1, r1, c1, data);
val2 = unpacker.unpack(r2, c2, data, 0);
```
Even (resp. odd) values of `c` correspond to the real (resp. imaginary) part of the Fourier mode.

### Example for Fourier Transform of real, double precision 2d data

```   DoubleFFT_2D fft = new DoubleFFT_2D(rows, columns);
double[][] data = new double[rows][2 * columns];
...
fft.realForwardFull(data);
data[r1][c1] = val1;
val2 = data[r2][c2];
```
is equivalent to
```   DoubleFFT_2D fft = new DoubleFFT_2D(rows, columns);
RealFFTUtils_2D unpacker = new RealFFTUtils_2D(rows, columns);
double[][] data = new double[rows][columns];
...
fft.realForward(data);
unpacker.pack(val1, r1, c1, data);
val2 = unpacker.unpack(r2, c2, data, 0);
```
Even (resp. odd) values of `c` correspond to the real (resp. imaginary) part of the Fourier mode.

Author:
Sébastien Brisard
• ### Constructor Summary

Constructors
Constructor and Description
```RealFFTUtils_2D(int rows, int columns)```
Creates a new instance of this class.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`int` ```getIndex(int r, int c)```
Returns the 1d index of the specified 2d Fourier mode.
`void` ```pack(double val, int r, int c, double[][] packed)```
Sets the specified Fourier mode of the transformed data.
`void` ```pack(double val, int r, int c, double[] packed, int pos)```
Sets the specified Fourier mode of the transformed data.
`void` ```pack(float val, int r, int c, float[][] packed)```
Sets the specified Fourier mode of the transformed data.
`void` ```pack(float val, int r, int c, float[] packed, int pos)```
Sets the specified Fourier mode of the transformed data.
`double` ```unpack(int r, int c, double[][] packed)```
Returns the specified Fourier mode of the transformed data.
`double` ```unpack(int r, int c, double[] packed, int pos)```
Returns the specified Fourier mode of the transformed data.
`float` ```unpack(int r, int c, float[][] packed)```
Returns the specified Fourier mode of the transformed data.
`float` ```unpack(int r, int c, float[] packed, int pos)```
Returns the specified Fourier mode of the transformed data.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### RealFFTUtils_2D

```public RealFFTUtils_2D(int rows,
int columns)```
Creates a new instance of this class. The size of the underlying `DoubleFFT_2D` or `FloatFFT_2D` must be specified.
Parameters:
`rows` - number of rows
`columns` - number of columns
• ### Method Detail

• #### getIndex

```public int getIndex(int r,
int c)```

Returns the 1d index of the specified 2d Fourier mode. In other words, if `packed` contains the transformed data following a call to `DoubleFFT_2D.realForward(double[])` or `FloatFFT_2D.realForward(float[])`, then the returned value `index` gives access to the `[r][c]` Fourier mode

• if `index == Integer.MIN_VALUE`, then the Fourier mode is zero,
• if `index >= 0`, then the Fourier mode is `packed[index]`,
• if `index < 0`, then the Fourier mode is `-packed[-index]`,

Parameters:
`r` - the row index
`c` - the column index
Returns:
the value of `index`
• #### pack

```public void pack(double val,
int r,
int c,
double[] packed,
int pos)```
Sets the specified Fourier mode of the transformed data. The data array results from a call to `DoubleFFT_2D.realForward(double[])`.
Parameters:
`val` - the new value of the `[r][c]` Fourier mode
`r` - the row index
`c` - the column index
`packed` - the transformed data
`pos` - index of the first element in array `packed`
• #### pack

```public void pack(double val,
int r,
int c,
double[][] packed)```
Sets the specified Fourier mode of the transformed data. The data array results from a call to `DoubleFFT_2D.realForward(double[][])`.
Parameters:
`val` - the new value of the `[r][c]` Fourier mode
`r` - the row index
`c` - the column index
`packed` - the transformed data
• #### pack

```public void pack(float val,
int r,
int c,
float[] packed,
int pos)```
Sets the specified Fourier mode of the transformed data. The data array results from a call to `FloatFFT_2D.realForward(float[])`.
Parameters:
`val` - the new value of the `[r][c]` Fourier mode
`r` - the row index
`c` - the column index
`packed` - the transformed data
`pos` - index of the first element in array `packed`
• #### pack

```public void pack(float val,
int r,
int c,
float[][] packed)```
Sets the specified Fourier mode of the transformed data. The data array results from a call to `FloatFFT_2D.realForward(float[][])`.
Parameters:
`val` - the new value of the `[r][c]` Fourier mode
`r` - the row index
`c` - the column index
`packed` - the transformed data
• #### unpack

```public double unpack(int r,
int c,
double[] packed,
int pos)```
Returns the specified Fourier mode of the transformed data. The data array results from a call to `DoubleFFT_2D.realForward(double[])`.
Parameters:
`r` - the row index
`c` - the column index
`packed` - the transformed data
`pos` - index of the first element in array `packed`
Returns:
the value of the `[r][c]` Fourier mode
• #### unpack

```public double unpack(int r,
int c,
double[][] packed)```
Returns the specified Fourier mode of the transformed data. The data array results from a call to `DoubleFFT_2D.realForward(double[][])` .
Parameters:
`r` - the row index
`c` - the column index
`packed` - the transformed data
Returns:
the value of the `[r][c]` Fourier mode
• #### unpack

```public float unpack(int r,
int c,
float[] packed,
int pos)```
Returns the specified Fourier mode of the transformed data. The data array results from a call to `FloatFFT_2D.realForward(float[])` .
Parameters:
`r` - the row index
`c` - the column index
`packed` - the transformed data
`pos` - index of the first element in array `packed`
Returns:
the value of the `[r][c]` Fourier mode
• #### unpack

```public float unpack(int r,
int c,
float[][] packed)```
Returns the specified Fourier mode of the transformed data. The data array results from a call to `FloatFFT_2D.realForward(float[][])` .
Parameters:
`r` - the row index
`c` - the column index
`packed` - the transformed data
Returns:
the value of the `[r][c]` Fourier mode