Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
Recursive Root Mean Square estimator

Real-time digital systems often require the calculation of a root-mean, such as a root-mean-square (RMS) level or average magnitude of a complex signal. While averaging can be efficiently implemented by most microprocessors, obtaining an efficient and rapidly converging algorithm is surely a time-consuming task due to the adjustments and optimizations that need to be performed. On the other hand, calculating the square root can be challenging, especially with low-cost hardware. If the processor does not have a built-in fast square root function, it must be implemented in software. While this can provide accurate results, it may not be as efficient.

qRMS provides a super-efficient method to compute the Recursive Root Mean Square (RMS). The implementation uses 3-stage filtering and Newton's method to obtain the square root. The filter parameters are perfectly tuned and optimized to converge in around 16 cycles, operating at a sampling rate of 1mS. This means that you must configure your embedded system to meet those specifications, either by configuring a timer interrupt or by delegating responsibility to a real-time task.

Example : By using a timer interrupt

rms_compute.c

#include "bsp.h"
#include "hal_timer.h"
#include "qrms.h"
#define RMS_WIN_SIZE ( 8 )
static qRMS_t rms_instance;
static volatile float rms_value = 0.0f;
static float window[ RMS_WIN_SIZE ] = { 0.0f };
void TimerA0_Int_Handler( void ) //interrupt tick at 1mS
{
rms_value = qRMS_Update( &rms_instance, get_sample() );
HAL_TimerA0_ClearStatusFlag();
}
void rms_setup( void )
{
qRMS_Setup( &rms_instance, window, RMS_WIN_SIZE );
HAL_TimerA0_Init();
HAL_TimerA0_SetPeriod_mS( 1 );
HAL_TimerA0_EnableInterrupts();
HAL_TimerA0_Enable();
}
float rms_getvalue( void )
{
return rms_value;
}
int qRMS_Setup(qRMS_t *const q, float *const window, const size_t wsize)
Initialize the RMS instance by setting the default optimal parameters.
Definition qrms.c:11
float qRMS_Update(qRMS_t *const q, const float x)
Computes the moving root mean square (RMS) of the input signal. The object uses both the exponential ...
Definition qrms.c:28
RMS calculator instance.
Definition qrms.h:30

rms_compute.h

#ifndef RMS_COMPUTE_H
#define RMS_COMPUTE_H
#ifdef __cplusplus
extern "C" {
#endif
void rms_setup( void );
float rms_getvalue( void );
#ifdef __cplusplus
}
#endif
#endif