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.

qlibs::rms 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 <qlibs.h>
using namespace qlibs;
static rms rms_instance;
static volatile real_t rms_value = 0.0f;
static real_t window[ 8 ] = { 0.0f };
void TimerA0_Int_Handler( void ) //interrupt tick at 1mS
{
rms_value = rms_instance.update( get_sample() );
HAL_TimerA0_ClearStatusFlag();
}
void rms_setup( void )
{
rms_instance.setup( window );
HAL_TimerA0_Init();
HAL_TimerA0_SetPeriod_mS( 1 );
HAL_TimerA0_EnableInterrupts();
HAL_TimerA0_Enable();
}
float rms_getvalue( void )
{
return rms_value;
}
RMS calculator object.
Definition rms.hpp:30
bool setup(real_t *const window, const size_t wsize) noexcept
Initialize the RMS instance by setting the default optimal parameters.
Definition rms.cpp:7
real_t update(const real_t x) noexcept
Computes the moving root mean square (RMS) of the input signal. The object uses both the exponential ...
Definition rms.cpp:22
The qLibs++ library namespace.
Definition fp16.cpp:4
float real_t
A type to instantiate a real variable double-precision of 64-bits IEEE 754.
Definition qlibs_types.hpp:43

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