This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with arm_rfft_fast_f32

Hi I tested  arm_rfft_fast_f32 function from CMSIS-DSP 1.4.4 with generated 50hz sine wave at 1000Hz sample rate using 1024 samples, but i get peek value at 102, not 51 which i should get 1000/1024 ~0,97 * 51 = 50Hz:

uint16_t i;

     float32_t khz10[1024];

     float32_t maxvalue;

     uint32_t maxindex;

     //float32_t output2[1024];

     arm_rfft_fast_instance_f32 S;

     arm_rfft_fast_init_f32(&S, 1024);

     printf("Input=[");

     for(i=0; i<1024; i++){

         khz10[i] = 1.2f*arm_sin_f32(2*3.1415926f*50*i/1000)+1;

         printf("%f,",khz10[i]);

     }

     printf("]\r\n");

     arm_rfft_fast_f32(&S, khz10,khz10,0);

     arm_abs_f32(khz10, khz10, 1024);

     arm_max_f32(khz10+1, 1023, &maxvalue, &maxindex);

     printf("Max:[%ld]:%f Output=[",maxindex,maxvalue);

     for(i=0; i<1024; i++){

         printf("%f,",khz10[i]);

     }

     printf("]\r\n");

I later tested this function  with real data from adc and I can only get 1/4 of frequency spectrum

not about 1/2 as I expected. Can anyone could me explain this ?

Parents
  • Hi gregoryk,

    Try replacing this block of code

         arm_rfft_fast_f32(&S, khz10,khz10,0);

         arm_abs_f32(khz10, khz10, 1024);

         arm_max_f32(khz10+1, 1023, &maxvalue, &maxindex);

         printf("Max:[%ld]:%f Output=[",maxindex,maxvalue);

         for(i=0; i<1024; i++){

             printf("%f,",khz10[i]);

         }

    with

         arm_rfft_fast_f32(&S, khz10,khz10,0);

         arm_cmplx_mag_f32(khz10, khz10, 512);                           /**/

         arm_max_f32(khz10[1], 511, &maxvalue, &maxindex);        /**/

         printf("Max:[%ld]:%f Output=[",maxindex,maxvalue);

         for(i=0; i<512; i++){                                                       /**/

             printf("%f,",khz10[i]);

         }

    The altered lines are marked with /**/ and the changes are in red.

    If you are using MATLAB, its function abs distinguishes between a real and a complex parameter.

    The CMSIS function arm_abs_f32 computes the absolute value of a real number(s). The output samples of FFT are always complex numbers. "Real FFT" means the input samples are real-valued but the output samples are still complex-valued. Hence, you should use arm_cmplx_mag_f32 instead.

    I'm not sure if that is the solution to the problem, I ran out of time and I also cannot make the necessary explanations for all the changes. I would just encourage you to post the result of those modifications.

    Regards,

    Goodwin

Reply
  • Hi gregoryk,

    Try replacing this block of code

         arm_rfft_fast_f32(&S, khz10,khz10,0);

         arm_abs_f32(khz10, khz10, 1024);

         arm_max_f32(khz10+1, 1023, &maxvalue, &maxindex);

         printf("Max:[%ld]:%f Output=[",maxindex,maxvalue);

         for(i=0; i<1024; i++){

             printf("%f,",khz10[i]);

         }

    with

         arm_rfft_fast_f32(&S, khz10,khz10,0);

         arm_cmplx_mag_f32(khz10, khz10, 512);                           /**/

         arm_max_f32(khz10[1], 511, &maxvalue, &maxindex);        /**/

         printf("Max:[%ld]:%f Output=[",maxindex,maxvalue);

         for(i=0; i<512; i++){                                                       /**/

             printf("%f,",khz10[i]);

         }

    The altered lines are marked with /**/ and the changes are in red.

    If you are using MATLAB, its function abs distinguishes between a real and a complex parameter.

    The CMSIS function arm_abs_f32 computes the absolute value of a real number(s). The output samples of FFT are always complex numbers. "Real FFT" means the input samples are real-valued but the output samples are still complex-valued. Hence, you should use arm_cmplx_mag_f32 instead.

    I'm not sure if that is the solution to the problem, I ran out of time and I also cannot make the necessary explanations for all the changes. I would just encourage you to post the result of those modifications.

    Regards,

    Goodwin

Children