Question

I'm working on a project that requires a Fourier transform of a 2D array.

However, I'm far from being an expert with both FFT's or particularly vDSP.

I've seen some examples here, here or here but they are either for 1D arrays or I can't quite understand them.

What I wish to trasform is this array that I build as follows:

 if (!_double2DArray) {
  _double2DArray = (double**) malloc([traces count]*sizeof(double*));
}

for (NSInteger i=0; i<[traces count]; i++) {
  Trace *trace = [traces objectAtIndex:i];
  _double2DArray[i] = (double*) malloc(length*sizeof(double));

  NSMutableArray *traceAxis = [trace getTraceAxis:axis];
  for (NSInteger j=0; j<[[trace traceLength] integerValue]; j++) {
    _double2DArray[i][j] = [[traceAxis objectAtIndex:j] doubleValue];
  }
}
Was it helpful?

Solution

To use vDSP, you will need to use actual two-dimensional arrays. The code you show creates an array of pointers to arrays, which is not a two-dimensional array. (It is composed of pieces from separate allocations and may have irregular spacing. vDSP requires that the columns of arrays be regularly spaced.)

It is likely you want to perform a real-to-complex FFT. For various reasons, this requires reformatting the real input data into two arrays, one for the elements with even column indices and one for the elements with odd column indices. This is what the vDSP_ctoz call does in the demonstration code you linked to, but you would use vDSP_ctozD for double precision. (If you do not need double precision, use float. It will be greatly faster in the FFT routines and other high-volume work.)

Before you perform an FFT with vDSP, you must obtain a setup object by calling vDSP_create_fftsetupD, as shown in the demonstration code. To perform the FFT, you call vDSP_fft2d_zripD. The setup object is released by calling vDPS_destroy_fftsetupD.

The create and destroy calls are expensive and should be performed rarely. They should be used by creating a setup early in your program and using it repeatedly with FFT calls.

The data returned by vDSP_fft2d_zripD is packed in an unusual format, and you will need to refer to this documentation for information about it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top