Cortex-M0 and FFT Integration

Problem Statement: Processing the array with sound samples through FFT on Cortex M0

I am using the ARM CMSIS DSP Library for the Cortex-M0, using following command

data_length = 256;

  float32_t sample_data[data_length*2];

  int16_t   data_temp[] = {-163, -181, -206, -194, -167, -119, -46, 20, 84, 139, 195, 223, 221, 190, 135, 96, 32, -34, -95, -179, -205, -201, -174, -129, -70, -4, 60, 119, 169, 204, 222, 220, 196, 145, 88, 23, -42, -102, -171, -187, -203, -190, -147, -92, -29, 37, 108, 166, 197, 219, 221, 201, 162, 109, 14, -61, -117, -174, -192, -202, -192, -153, -101, -40, 25, 86, 140, 183, 211, 219, 208, 176, 127, 68, 4, -69, -124, -176, -192, -197, -159, -121, -62, 1, 63, 120, 167, 204, 216, 201, 152, 98, 37, -27, -86, -136, -183, -194, -195, -175, -137, -84, -23, 51, 108, 156, 192, 211, 212, 191, 153, 100, 39, -24, -83, -133, -184, -195, -193, -172, -132, -78, -17, 45, 102, 150, 187, 206, 208, 189, 152, 91, 31, -31, -89, -138, -186, -193, -194, -175, -136, -84, -24, 38, 95, 150, 185, 205, 191, 159, 111, 54, -8, -78, -129, -190, -197, -182, -149, -100, -41, 20, 88, 150, 190, 200, 187, 162, 118, 62, 1, -59, -113, -157, -194, -200, -206, -194, -167, -119, -46, 20, 84, 139, 195, 223, 221, 190, 135, 96, 32, -34, -95, -179, -205, -206, -194, -167, -119, -46, 20, 84, 139, 195, 223, 221, 190, 135, 96, 32, -34, -95, -179, -205, -206, -194, -167, -119, -46, 20, 84, 139, 195, 223, 221, 190, 135, 96, 32, -34, -95, -179, -205, -206, -194, -167, -119, -46, 20, 84, 139, 195, 223, 221, 190, 135, 96, 32, -34, -95, -179, -205, -206, -194, -167, -192 };

  // Assign the value here

  // odd samples are complex values, set each to zero

  for (z = 0; z < data_length; z++) {

  sample_data[z*2] = data_temp[z];

  sample_data[z*2+1] = 0.0;

  }

  // Actual FFT processing with ARM optimized library function

  // FFT is done in-place, sample_data will contain the results

  arm_cfft_f32(&arm_cfft_sR_f32_len256, sample_data, 0, 1);  // no inverse, do bit reverse

However, when I try to execute it on the microcontroller the arm_cfft_f32 function calls

arm_cfft_radix8by4_f32  ( (arm_cfft_instance_f32 *) S, p1);

where S is arm_cfft_sR_f32_len256, and p1 is  sample_data,

however, it got hanged in the function, and does not give back results.

I am currently using LPC114/333 MCU Settings.

Need your advise, specially if you have an experience of running this FFT library on Cortex-M0, Thank you

  • Hi ihaabi,

    Have you tried single stepping through the function? Where does it hang?

  • Hello ihaabi,

    I can not confirm your statement.
    I used CMSIS V3.20 (which contains CMSIS-DSP  Verison 1.4.1) to reproduce your test.

    Function arm_cfft_f32 finished without problems.


    Below is the code I used.

    #include "arm_math.h"
    #include "arm_const_structs.h"
    
    #define TEST_LENGTH_SAMPLES  512
    
    float32_t sample_data_f32[TEST_LENGTH_SAMPLES];
    
     int16_t data_temp[] = {
       -163, -181, -206, -194, -167, -119,  -46,   20,   84,  139,  195,  223,  221,  190,  135,   96, 
         32,  -34,  -95, -179, -205, -201, -174, -129,  -70,   -4,   60,  119,  169,  204,  222,  220, 
        196,  145,   88,   23,  -42, -102, -171, -187, -203, -190, -147,  -92,  -29,   37,  108,  166, 
        197,  219,  221,  201,  162,  109,   14,  -61, -117, -174, -192, -202, -192, -153, -101,  -40, 
         25,   86,  140,  183,  211,  219,  208,  176,  127,   68,    4,  -69, -124, -176, -192, -197, 
       -159, -121,  -62,    1,   63,  120,  167,  204,  216,  201,  152,   98,   37,  -27,  -86, -136, 
       -183, -194, -195, -175, -137,  -84,  -23,   51,  108,  156,  192,  211,  212,  191,  153,  100, 
         39,  -24,  -83, -133, -184, -195, -193, -172, -132,  -78,  -17,   45,  102,  150,  187,  206, 
        208,  189,  152,   91,   31,  -31,  -89, -138, -186, -193, -194, -175, -136,  -84,  -24,   38, 
         95,  150,  185,  205,  191,  159,  111,   54,   -8,  -78, -129, -190, -197, -182, -149, -100, 
        -41,   20,   88,  150,  190,  200,  187,  162,  118,   62,    1,  -59, -113, -157, -194, -200, 
       -206, -194, -167, -119,  -46,   20,   84,  139,  195,  223,  221,  190,  135,   96,   32,  -34, 
        -95, -179, -205, -206, -194, -167, -119,  -46,   20,   84,  139,  195,  223,  221,  190,  135, 
         96,   32,  -34,  -95, -179, -205, -206, -194, -167, -119,  -46,   20,   84,  139,  195,  223, 
        221,  190,  135,   96,   32,  -34,  -95, -179, -205, -206, -194, -167, -119,  -46,   20,   84, 
        139,  195,  223,  221,  190,  135,   96,   32,  -34,  -95, -179, -205, -206, -194, -167, -192 };
    
    int32_t main(void) {
      uint32_t z;
    
      // odd samples are complex values, set each to zero
      for (z = 0; z < (TEST_LENGTH_SAMPLES/2); z++) {
        sample_data_f32[z*2  ] = data_temp[z];
        sample_data_f32[z*2+1] = 0.0;
      }
    
      // FFT is done in-place, sample_data_f32 will contain the results
      arm_cfft_f32(&arm_cfft_sR_f32_len256, sample_data_f32, 0, 1);  // no inverse, do bit reverse
    
      while(1);                             /* main function does not return */
    }
    

    Be sure to set define 'ARM_MATH_CM0' for use of Cortex-M0 DSP lib code.


    Best Regards, Martin

  • Hi Ihaabi

    Did you find the solution for this issue? I also tried implementing this function in Cortex-M4 and I am the same issue. The program is hanging in arm_cfft_f32() I am giving floating values i/p according to the arm_fft_bin_example_f32  present in the CMSIS library. My function worked if i didn't do bit reversal. while debugging I found out that it was getting hanged in bitreversalpart. I don't know if the issue was from ARM but I used their library and there functions. SO my recommendation to you is check if it works without bitreversal. If It works for you also then I think there is an issue with the function in the library.

      arm_cfft_f32(&arm_cfft_sR_f32_len256, sample_data, 0, 0);  // no inverse, no bit reverse


    Just check if it works this way


    One more corrections which I think should be done to your sample data is that since this function supports float32_t values so it is recommended to store the real sample data in this format.

    i.e float32_t   data_temp[] = {-163.0, -181.0, -206.0, .... and so on }



    Kind Regards

    Amit Kumar

More questions in this forum