Accelerate FFT: Intermittent crashes

I've implemented FFT using the Accelerate frame work and I'm not sure I've done it correctly.

For starters, I don't like that the imaginary array is filled with zeroes, this seems to be a waste of memory. However the more serious issue is that I get intermittent crashes when using the vDSP API (malloc errors)

I've read the online docs, tried to follow several online samples. Could somebody more knowledgeable with these APIs have a look?

See attached file:

Replies

Hi,

You might want to look over this article: https://developer.apple.com/documentation/accelerate/data_packing_for_fourier_transforms

vDSP's FFT routines are designed to work with a real signal that's converted to split-complex format. That is, the routines accept collections of complex types but the even real signal elements reside in the complex real parts, and the odd real signal elements reside in the complex imaginary parts. That article shows how to convert your input signal to split-complex.

This means that for a real signal of n elements, the real and imaginary parts of the data to send to the FFT routines in n/2 elements.

May I also suggest that you look at https://developer.apple.com/documentation/accelerate/vdsp/discretefouriertransform - the vDSP DFT provides an API that allows you to specify complex-real or complex-complex and has better support for different problem sizes. The vDSP DFT will use the FFT routines where possible, so there's no loss of performance.

  • Thanks for the reply. I have looked at the links you mentioned. I'll readily admit that I might not be packing the data properly, but it's the crashing I'm concerned about.

    Is there anything wrong with the code I provided which would cause it to crash?

  • I can't see any issues, and I've run your code in a loop several hundred times without issue.

    The underlying function to the Swift FFT is vDSP_fft_zropD. The log2n parameter is the number of complex elements which usually would be half the number of real elements, so that might cause an issue.

  • Did you try to free the FFT instance? I can get it to crash within 10-12 attempts within my iOS app.

deleted

The Swift double-precision FFT wraps FFTSetupD and it correctly calls vDSP_destroy_fftsetupD on its deinitialization. How many elements are in self.filtered? Have you tried removing the FFT related code to see if the issue is related to a non-vDSP issue?