Not sure what I am doing wrong. The results I get from the Accelerate framework seem incorrect to me. Any help would be much appreciated!
Here are some graphs comparing AForge with vDPS

This is the vDSP Code I run
fftSetup = vDSP_create_fftsetup( 16, 2);
// Convert the data into a DSPSplitComplex
int samples = spectrumDataSize;
int samplesOver2 = samples/2;
DSPSplitComplex * complexData = new DSPSplitComplex;
float *realpart = (float *)calloc(samplesOver2, sizeof(float));
float *imagpart = (float *)calloc(samplesOver2, sizeof(float));
complexData->realp = realpart;
complexData->imagp = imagpart;
vDSP_ctoz((DSPComplex *)realData, 2, complexData, 1,samplesOver2);
// Calculate the FFT
// ( I'm assuming here you've already called vDSP_create_fftsetup() )
vDSP_fft_zrip(fftSetup, complexData, 1, log2f(samples), FFT_FORWARD);
// Scale the data
//float scale = (float) FFT_SCALE; //scale is 32
vDSP_vsmul(complexData->realp, 1, &scale, complexData->realp, 1,samplesOver2);
vDSP_vsmul(complexData->imagp, 1, &scale, complexData->imagp, 1, samplesOver2);
vDSP_zvabs(complexData, 1, spectrumData, 1, samples);
free(complexData->realp);
free(complexData->imagp);
delete complexData;
// All done!
return spectrumData;
This is what I do in AForge
foreach (float f in floatData)
{
if (i >= this.fft.Length)
break;
this.fft[i++] = new Complex(f * fftSize, 0);
}
AForge.Math.FourierTransform.FFT(this.fft, FourierTransform.Direction.Forward);
After the following subroutine
is executed,
complexDatahassamplesOver2elements. But soon after that, you callwhich expects
complexDatato havesampleselements, i.e. twice as many. This cannot be.Also, how is
realDatalaid out? I ask becausevDSP_ctozexpects its first argument to be laid out in the formIf your data is indeed real, then
imag0, imag1, ... imag(n-1)should all be 0. If it is not, thenvDSP_ctozmay not be expecting that. (Unless you are packing the real data in some clever way, which would be two [sic] clever by half!)Finally,
vDSP_create_fftsetup( 16, 2);should probably be changed to===================================================================
My sample code appended in postscript: