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++)
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
Another idea, instead of doing
Handle this in floating point. You might be cutting off the top bit of the results of complex mag.
Daniel White schrieb:Another idea, instead of doingarm_shift_q15(testOutput_q15_cfft, 1, testOutput_q15_cfft, fftSize); //convert to 1.15Handle this in floating point. You might be cutting off the top bit of the results of complex mag.
Daniel White schrieb:
I checked this by setting a breakpoint at this line and looked in the testOutput_q15_cfft array - the contents are already corrupted before the Q15 shift.
I also compared the values of the input buffer after the CFFT/RFFT and before the mag calculation - they're identical except of the ratios.
Currently I'm investigating what happens inside the arm_cfft_q15() function. I identified a difference between the Q15 CFFT and RFFT: for the RFFT it's clearly stated that the output must be downscaled. However, the CFFT Q15 documentation doesn't mention any scaling, therefore my code currently doesn't scale the CFFT result before calculating the magnitude. Maybe this is the problem...