Question

I've been working on some vDSP code and I have come up against an annoying problem. My code is cross platform and hence uses std::complex to store its complex values.

Now I assumed that I would be able to set up an FFT as follows:

DSPSplitComplex dspsc;
dspsc.realp = &complexVector.front().real();
dspsc.imagp = &complexVector.front().imag();

And then use a stride of 2 in the appropriate vDSP_fft_* call.

However this just doesn't seem to work. I can solve the issue by doing a vDSP_ztoc but this requires temporary buffers that I really don't want hanging around. Is there any way to use the vDSP_fft_* functions directly on interleaved complex data? Also can anyone explain why I can't do as I do above with a stride of 2?

Thanks

Edit: As pointed out by Bo Persson the real and imag functions don't actually return a reference.

However it still doesn't work if I do the following instead

DSPSplitComplex dspsc;
dspsc.realp = ((float*)&complexVector.front()) + 0;
dspsc.imagp = ((float*)&complexVector.front()) + 1;

So my original question still does stand :(

Was it helpful?

Solution

The std::complex functions real() and imag() return by value, they do not return a reference to the members of complex.

This means that you cannot get their addresses this way.

OTHER TIPS

This is how you do it.

const COMPLEX *in = reinterpret_cast<const COMPLEX*>(std::complex);

Source: http://www.fftw.org/doc/Complex-numbers.html

EDIT: To clarify the source; COMPLEX and fftw_complex use the same data layout (although fftw_complex uses double and COMPLEX float)

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