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
I replaced the arm_cmplx_mag_q15() with arm_cmplx_mag_squared_q15(). Result compared to the output of the f32 CFFT is a ratio between ~980 and ~1061 for the two outputs - so it seems this is working, with a reduced precision and a varying ratio.
So, why do I have to use the squared magnitude function for Q15? The floating point implementation uses the normal magnitude function.
And the magnitude function for Q15 seems to destroy the buffer - why? Is this a bug?