transformShuffled method
Computes the discrete FFT of a complex array.
complArray
= the complex values of the array if isComplex
is true (the
default value). The array must be ordered
in the form real value 0, imag value 0, real value 1, imag value 1,...
.
If isComplex
is false, the array must be ordered
in the form real value 0, real value 1, ...
.
Throws if the length is not a power of 2.
Returns the result: The result consists of 2 new arrays representing
complex data, the input array remains unchanged:
The real part is the array stored under index 0 of the returned list, the
imaginary part corresponds to index 1.
If isComplex
is true, the lengths of the resulting real part and of the
corresponding imaginary part are half of the length of the input array
complArray
. If isComplex
is false, the lengths of the resulting real
part and of the corresponding imaginary part are the same as the length of
the input array complArray
because internally complArray
is treated
as a complex array with a zero imaginary part.
The resulting array values are scaled relatively (non absolute values).
groupDelay
= a double in String format. In some measurement time data, the
actual data do not start at 0, but groupDelay
later, in terms of
complex points. For such types of data
the FFT would produce a "phase shifted" result (see function phascor below).
This phase shift is accounted for if groupDelay
is chosen not be zero
but according to the measurement.
swapMode
= one of FT_SWAP_MODE_NO, FT_SWAP_MODE_FULL, FT_SWAP_MODE_HALF.
These modes are needed depending on how the data to be transformed
were sampled on a measurement device, e.g. a spectrometer.
FT_SWAP_MODE_NO: no special effect
FT_SWAP_MODE_FULL: 1) every other complex points is negated before th
transform. 2) The order of the real data points is reversed after transform.
The same is done for the imaginary data points.
FT_SWAP_MODE_HALF: The order of the first half of the real data points,
and of the seconds half of the real data points is reversed after transform.
The same is applied to the imaginary data points.
Implementation
static List<Float64List> transformShuffled(
Float64List complArray, String groupDelay, int swapMode,
[bool isComplex = true]) {
// reim in new, shuffledArray remains unchanged.
List<Float64List> reim;
if (isComplex) {
reim = Array1D.unshuffle(complArray); // returns 2 new arrays
} else {
reim = List<Float64List>(2); // creates 2 new arrays
reim[0] = Float64List(complArray.length);
for (int i = 0; i < complArray.length; i++) {
reim[0][i] = complArray[i];
}
reim[1] = Float64List(complArray.length);
}
// negation of every other (complex) point needed
// e.g. data with bruker groupDelay -1, but DECIM and DSPFVS > 0
if (swapMode == FT_SWAP_MODE_FULL) {
for (int i = 0; i < reim[0].length; i += 2) {
reim[0][i + 1] = -reim[0][i + 1];
reim[1][i + 1] = -reim[1][i + 1];
}
}
transform(reim[0], reim[1]); // in-place transform of complex data
if (groupDelay != null && double.parse(groupDelay) > 0) {
phascor(reim[0], reim[1], 0, double.parse(groupDelay) * 360); // orig
}
// e.g. data with groupDelay -1, but DECIM and DSPFVS > 0
if (swapMode == FT_SWAP_MODE_FULL) {
Array1D.swap(reim[0]);
Array1D.swap(reim[1]);
} else if (swapMode == FT_SWAP_MODE_HALF) {
// e.g. data with bruker groupDelay > 0,
Array1D.swapHalf(reim[0]);
Array1D.swapHalf(reim[1]);
}
return reim;
}