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

CMSIS-DSP: CFFT with Q15, wrong output

Hi,

I changed the CMSIS-DSP frequency bin example to Q15 format (or at least I'm trying to do so), but I'm getting wrong results. My changed code:

/* =================================================================================================

    for(testIndex = 0; testIndex < TEST_LENGTH_SAMPLES; testIndex++)

    for(testIndex = 0; testIndex < TEST_LENGTH_SAMPLES; testIndex++)

        testInput_f32_10khz_cfft[testIndex] /= 6.2f;     //divide the example test  data by 6.2 to get it in the range -1...+1

    testIndex = 0;

    arm_float_to_q15(testInput_f32_10khz_cfft, testInput_q15_10khz_cfft, TEST_LENGTH_SAMPLES);     //convert the data to Q15

    /* Process the data through the CFFT/CIFFT module */

    arm_cfft_q15(&arm_cfft_sR_q15_len1024, testInput_q15_10khz_cfft, ifftFlag, doBitReverse);

    /* Process the data through the Complex Magnitude Module for calculating the magnitude at each bin */

    arm_cmplx_mag_q15(testInput_q15_10khz_cfft, testOutput_q15_cfft, fftSize);    //output 2.14

    arm_shift_q15(testOutput_q15_cfft, 1, testOutput_q15_cfft, fftSize);            //convert to 1.15

    arm_q15_to_float(testOutput_q15_cfft, testOutput_q15_to_f32_cfft, 2048);  //for better readability in debug view

/* =================================================================================================

The output of this is:

0.0110473633, 0.000000000, 0.000000000, 0.000000000, 0.000000000, 0.000000000, 0.0110473633, 0.000000000,

0.000000000, 0.0110473633, 0.0110473633, 0.000000000, 0.000000000, 0.0110473633, 0.0191040039, 0.000000000,

0.000000000, 0.0110473633, 0.0191040039, 0.0110473633, 0.000000000, 0.0110473633, 0.000000000, 0.000000000,

0.0110473633, 0.000000000, 0.000000000, 0.000000000, 0.000000000, 0.000000000, 0.000000000, 0.000000000,

...

The output of the frequency bin example is:

89.4459534, 26.1034775, 35.7469597, 34.7221146, 49.2430763, 55.420784, 89.1215439, 20.6131191,

37.0284195, 98.7423096, 93.8422165, 63.7021141, 61.6773682, 84.585701, 123.891975, 25.0829983,

52.0468674, 74.8693924, 134.225296, 76.7762985, 16.0060749, 94.5713272, 65.412468, 24.5386391,

77.5796204, 56.8698654, 28.9609737, 18.5632, 26.0725956, 17.7821369, 24.5758419, 5.75964499,

...

I don't get where my error is. Except of the Q15 shift after the magnitude calculation, I (think I) do the same as in the frequency bin example. I know that I can't expect the same values since Q15 is in the range of -1...+1, but as the output shows, there are many zero values and most of the other values are identical. I expected to have values with the same ratios.

Any ideas what I'm doing wrong? I really don't see my error

Regards,

Ralf

Parents
  • The fixed point ffts downshift the data in order to prevent overflow.  In order to properly interpret the output, you'll have to multiply it by a scale factor after it's been converted to floating point.  Some documentation about it here Complex FFT Functions . I think you'll just have to multiply by the fft length, but I could be off by a bit.   However, this won't fix those zeros you're seeing obviously.  Maybe the divide by 6.2 makes the input values too small and it's losing precision?  Hard to say.  When you show the normal frequency bin example output, try changing the input to that to be /= 6.2 as well to get a more direct comparison of outputs.  Could you post those expected results too please?  I'm curious to see

    I'm not sure what to say about mag vs squared mag.

Reply
  • The fixed point ffts downshift the data in order to prevent overflow.  In order to properly interpret the output, you'll have to multiply it by a scale factor after it's been converted to floating point.  Some documentation about it here Complex FFT Functions . I think you'll just have to multiply by the fft length, but I could be off by a bit.   However, this won't fix those zeros you're seeing obviously.  Maybe the divide by 6.2 makes the input values too small and it's losing precision?  Hard to say.  When you show the normal frequency bin example output, try changing the input to that to be /= 6.2 as well to get a more direct comparison of outputs.  Could you post those expected results too please?  I'm curious to see

    I'm not sure what to say about mag vs squared mag.

Children