createConjugates method

Float64x2List createConjugates(
  1. int outputLength
)

Creates redundant conjugate terms. This is the inverse of discardConjugates, and it only really makes sense to recreate conjugates after they have been discarded using that method.

When discarding the conjugates, an array of e.g. 10 elements or 11 elements will both end up with 6 elements left. So when recreating them, the outputLength needs to be specified. It should be the same as the length of the array before discardConjugates was called.

The intended use case for this function is as part of a signal processing pipeline like this:

  1. Take in a real valued time domain input
  2. Perform an FFT to get the frequency domain signal
  3. Discard the redundant conjugates using discardConjugates
  4. Perform some manipulations on the complex frequency domain signal
  5. Recreate the conjugates using createConjugates
  6. Inverse FFT to get a real valued time domain output

You could get the same output by skipping steps 3 and 5, but in that case, care must be taken to ensure that step 4 preserves the conjugate symmetry, which can be fiddly. If that symmetry is lost, then the final time domain output will contain complex values, not just real values. So it's usually easier to discard the conjugates and then recreate them later.

This method returns a totally new array containing a copy of this array, with the extra values appended at the end.

Implementation

Float64x2List createConjugates(int outputLength) {
  if (discardConjugatesLength(outputLength) != length) {
    throw ArgumentError(
      'Output length must be either (2 * length - 2) or (2 * length - 1).',
      'outputLength',
    );
  }
  final out = Float64x2List(outputLength);
  for (int i = 0; i < length; ++i) {
    out[i] = this[i];
  }
  for (int i = length; i < outputLength; ++i) {
    final a = this[outputLength - i];
    out[i] = Float64x2(a.x, -a.y);
  }
  return out;
}