Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:50:09+00:00 2026-06-06T08:50:09+00:00

Not sure what I am doing wrong. The results I get from the Accelerate

  • 0

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
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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:50:10+00:00Added an answer on June 6, 2026 at 8:50 am

    After the following subroutine

    vDSP_ctoz((DSPComplex *)realData, 2, complexData, 1,samplesOver2);
    

    is executed, complexData has samplesOver2 elements. But soon after that, you call

    vDSP_zvabs(complexData, 1, spectrumData, 1, samples);
    

    which expects complexData to have samples elements, i.e. twice as many. This cannot be.

    Also, how is realData laid out? I ask because vDSP_ctoz expects its first argument to be laid out in the form

    real0, imag0, real1, imag1, ... real(n-1), imag(n-1).
    

    If your data is indeed real, then imag0, imag1, ... imag(n-1) should all be 0. If it is not, then vDSP_ctoz may 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

    vDSP_create_fftsetup(16, 0);
    

    ===================================================================

    My sample code appended in postscript:

      FFTSetup fftSetup = vDSP_create_fftsetup(
                                               16,         // vDSP_Length __vDSP_log2n,
                                               kFFTRadix2  // FFTRadix __vDSP_radix
                                               // CAUTION: kFFTRadix2 is an enum that is equal to 0
                                               //          kFFTRadix5 is an enum that is equal to 2
                                               // DO NOT USE 2 IF YOU MEAN kFFTRadix2
                                               );
      NSAssert(fftSetup != NULL, @"vDSP_create_fftsetup() failed to allocate storage");
    
      int numSamples = 65536;  // numSamples must be an integer power of 2; in this case 65536 = 2 ^ 16
      float realData[numSamples];
    
      // Prepare the real data with (ahem) fake data, in this case
      // the sum of 3 sinusoidal waves representing a C major chord.
      // The fake data is rigged to have a sampling frequency of 44100 Hz (as for a CD).
      // As always, the Nyquist frequency is just half the sampling frequency, i.e., 22050 Hz.
      for (int i = 0; i < numSamples; i++)
      {
        realData[i] = sin(2 * M_PI * 261.76300048828125 * i / 44100.0)  // C4 = 261.626 Hz
                    + sin(2 * M_PI * 329.72717285156250 * i / 44100.0)  // E4 = 329.628 Hz
                    + sin(2 * M_PI * 392.30804443359375 * i / 44100.0); // G4 = 391.995 Hz
      }
    
      float splitReal[numSamples / 2];
      float splitImag[numSamples / 2];
    
      DSPSplitComplex splitComplex;
      splitComplex.realp = splitReal;
      splitComplex.imagp = splitImag;
    
      vDSP_ctoz(
                (const DSPComplex *)realData,  // const DSPComplex __vDSP_C[],
                2,                             // vDSP_Stride __vDSP_strideC,  MUST BE A MULTIPLE OF 2
                &splitComplex,                 // DSPSplitComplex *__vDSP_Z,
                1,                             // vDSP_Stride __vDSP_strideZ,
                (numSamples / 2)               // vDSP_Length __vDSP_size
                );
    
      vDSP_fft_zrip(
                    fftSetup,                               // FFTSetup __vDSP_setup,
                    &splitComplex,                          // DSPSplitComplex *__vDSP_ioData,
                    1,                                      // vDSP_Stride __vDSP_stride,
                    (vDSP_Length)lround(log2(numSamples)),  // vDSP_Length __vDSP_log2n,
                    // IMPORTANT: THE PRECEDING ARGUMENT MUST BE LOG_BASE_2 OF THE NUMBER OF floats IN splitComplex
                    // FOR OUR EXAMPLE, THIS WOULD BE (numSamples / 2) + (numSamples / 2) = numSamples
                    kFFTDirection_Forward                   // FFTDirection __vDSP_direction
                    );
    
      printf("DC component = %f\n", splitComplex.realp[0]);
      printf("Nyquist component = %f\n\n", splitComplex.imagp[0]);
    
      // Next, we compute the Power Spectral Density (PSD) from the FFT.
      // (The PSD is just the magnitude-squared of the FFT.)
      // (We don't bother with scaling as we are only interested in relative values of the PSD.)
      float powerSpectralDensity[(numSamples / 2) + 1];  // the "+ 1" is to make room for the Nyquist component
    
      // We move the Nyquist component out of splitComplex.imagp[0] and place it
      // at the end of the array powerSpectralDensity, squaring it as we go:
      powerSpectralDensity[numSamples / 2] = splitComplex.imagp[0] * splitComplex.imagp[0];
    
      // We can now zero out splitComplex.imagp[0] since the imaginary part of the DC component is, in fact, zero:
      splitComplex.imagp[0] = 0.0;
    
      // Finally, we compute the squares of the magnitudes of the elements of the FFT:
      vDSP_zvmags(
                  &splitComplex,         // DSPSplitComplex *__vDSP_A,
                  1,                     // vDSP_Stride __vDSP_I,
                  powerSpectralDensity,  // float *__vDSP_C,
                  1,                     // vDSP_Stride __vDSP_K,
                  (numSamples / 2)       // vDSP_Length __vDSP_N
                  );
    
      // We print out a table of the PSD as a function of frequency
      // Replace the "< 600" in the for-loop below with "<= (numSamples / 2)" if you want
      // the entire spectrum up to and including the Nyquist frequency:
      printf("Frequency_in_Hz    Power_Spectral_Density\n");
      for (int i = 0; i < 600; i++)  
      {
        printf("%f,          %f\n", (i / (float)(numSamples / 2)) * 22050.0, powerSpectralDensity[i]);
        // Recall that the array index i = 0 corresponds to zero frequency
        // and that i = (numSamples / 2) corresponds to the Nyquist frequency of 22050 Hz.
        // Frequency values intermediate between these two limits are scaled proportionally (linearly).
      }
    
      // The output PSD should be zero everywhere except at the three frequencies
      // corresponding to the C major triad.  It should be something like this:
    
    /***************************************************************************
     DC component = -0.000000
     Nyquist component = -0.000000
    
     Frequency_in_Hz    Power_Spectral_Density
     0.000000,          0.000000
     0.672913,          0.000000
     1.345825,          0.000000
     2.018738,          0.000000
     2.691650,          0.000000
     .
     .
     .
     260.417175,          0.000000
     261.090088,          0.000000
     261.763000,          4294967296.000000
     262.435913,          0.000000
     263.108826,          0.000000
     .
     .
     .
     328.381348,          0.000000
     329.054260,          0.000000
     329.727173,          4294967296.000000
     330.400085,          0.000000
     331.072998,          0.000000
     .
     .
     .
     390.962219,          0.000000
     391.635132,          0.000000
     392.308044,          4294966784.000000
     392.980957,          0.000000
     393.653870,          0.000000
     .
     .
     .
    ***************************************************************************/
    
      vDSP_destroy_fftsetup(fftSetup);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure what I'm doing wrong but I can't get my JQuery AJAX call
I am not sure what I am doing wrong, It would be great if
I know this probably really simple but Im not sure what im doing wrong...
Not sure what I'm doing wrong with .live() $(function(){ var wrapper = $('#trailer_wrapper'); var
I am not sure what I could be doing wrong that causes info level
I'm not sure what I am doing wrong, but the text for my JPanels
I'm not sure what I'm doing wrong, but I'm not able to read a
I'm not sure what I'm doing wrong, but two versions of code that should
I'm not sure what I'm doing wrong. I created a timer that updates a
I'm not sure what I'm doing wrong here, I have a file in lib/acts_as_votable.rb

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.