2024-01-04 04:17 AM
Hello,
I am using STM32G491 controller for my application. I am trying to use FMAC module for FIR filter implementation for my application. I am referring the STM32G4-Peripheral-Filter_Math_Accelerator_FMAC.pdf FMAC pdf document. I have also referred the FMAC example sample code https://github.com/STMicroelectronics/STM32CubeG4/tree/master/Projects/NUCLEO-G474RE/Examples/FMAC/FMAC_FIR_DMAToIT
As the FMAC module accepts input buffer in q1.15 format.
I have used below formula to convert int16_t value to q1.15 format.
Number = 100;
/First , normalization
float v1_f = 100/32767.0;
//second, convert the normalized results into Q Format
v1_q15 = int16_t(V1_f *0x8000) +0.5;
placed this v1_q15 value as the buffer element. Is the above formula for q1.15 conversion is correct? I am not getting the expected output which I have calculated from the FIR filter formula.
Can any one support me to convert the integer value to q1.15 format and q1.15 format output to integer number? Any help would be appreciated.
Thanks in advance
Kirti
Solved! Go to Solution.
2024-01-04 06:15 AM
That is the correct conversion. Note that q1.15 format can only store values between 0 and 2, and they must remain in that range during/after FIR calculation.
I don't understand what you're showing in the screenshot. You're initializing a bunch of int16_t values as 0x64 and 0xA but I don't understand why that's relevant here.
2024-01-04 06:15 AM
That is the correct conversion. Note that q1.15 format can only store values between 0 and 2, and they must remain in that range during/after FIR calculation.
I don't understand what you're showing in the screenshot. You're initializing a bunch of int16_t values as 0x64 and 0xA but I don't understand why that's relevant here.
2024-01-04 07:57 AM
Q1.15 (from Wikipedia)
is in "arm world" -0,999 ... +0,999 , 1 sign + 15 bits fractional.
Simplest conversion for example 100 : in Q1.15 -> 100 ( 0x0064 as int16 ).
And back conversion : 0x0064 -> 100 . great , simple. :)
Now you think: whats the deeper sense of this ?
Its just about doing complex math in integer, not float, but not get internal overflow in the calculation.
So the integer is treated as always smaller than 1 , giving in multiplication ( 1 * 1 -> ) 1 maximum, no overflow can happen. Thats it.
Any normalization only makes sense, if your data lets say, is in range 5...100. (100 is maximum.)
So you want best precision, then adjust by: data * (32767/100) , and back after math : result *(100/32767) , so keeping best dynamic range .
2024-01-12 04:02 AM
Thanks for confirmation on the Q15 formula. Actually I was given 2 buffers (sample buffer and coefficient buffer) as input to FMAC module and wanted to get the output as per FIR filter formula
but the result was not as expected (not matched with calculated result). For FIR filter to work, the coefficient buffer elements need to convert to Q15 format (in the range of 1 to -1), I did that conversion and getting the result as expected.
Thank you ..
2024-01-12 04:07 AM
Thank you for the detailed explanation on Q15. I wanted FIR filter to perform averaging on the input buffer and get the result. The calculated and FMAC module results were not matching So thought of asking for Q15 format conversion formula. But as I mentioned in above reply the coefficient buffer elements need to be in Q15 range (-1 to 1) and it resolved.
Thank you