# CMSIS DSP Library and RMS

I'm using a STM32 Cortex M0+ controller which does not have FPU. I'm reading 50/60Hz sine wave and I would like to calculate the RMS using the DSP library: keil.com/pack/doc/CMSIS/DSP/html/group__RMS.html. Looking into this library, there are three functions to compute the RMS:

void arm_rms_f32 (const float32_t *pSrc, uint32_t blockSize, float32_t *pResult)
Root Mean Square of the elements of a floating-point vector.

void arm_rms_q15 (const q15_t *pSrc, uint32_t blockSize, q15_t *pResult)
Root Mean Square of the elements of a Q15 vector.

void arm_rms_q31 (const q31_t *pSrc, uint32_t blockSize, q31_t *pResult)
Root Mean Square of the elements of a Q31 vector.


As the micro doesn't have FPU, is it more convenient to avoid floating calculation and use Q15 or Q31 format? If so, do I need to convert the data from the ADC to Q15/Q31 format, right?

In the other hand, my AC signal has DC bias equal to Vcc/2 or 1.65V. Converting this to digital, it is equal to 2048. But when I sampling, this value actually varies from 2044 to 2052 (my noise floor I guess) I have seen several methods to deal with this offset:

1. Subtract a fixed value of 2048 from each ADC reading. This is no so good as I said above this value may vary slightly. Also, if I want to detect zero cross it may cause errors to choose exactly 2048 as reference.
2. Sample the DC bias and average it
3. Leave it and get the DC value as RMS result when there's no input signal
4. Use a more sophisticated software high pass filter
5. Use the formula below

Using Fixed Point is a good Idea. other than providing a huge numberspace, floating point has only drawbacks: slower to process, sideeffects, less precision.

Fixpoint is in most cases the better choice. In fact a DSP manufacturer with a floting and a fixpoint line told me once, fixpoint is driven by simulation tools like matlab to transfer their code 1:1 to the embedded world. But the fixpoint devices are better in almost all application.