-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqrms.dox
More file actions
80 lines (80 loc) · 2.36 KB
/
qrms.dox
File metadata and controls
80 lines (80 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*! @page qrms_desc 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.
*
* \ref 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.
*
* @section qrms_ex1 Example: Using a Timer Interrupt
*
* The following example demonstrates how to configure a timer to periodically update the RMS
* estimator at a 1 ms interval.
*
* @b File: @c rms_compute.c
* @code{.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;
* }
*
*
* @endcode
*
* @b File: @c rms_compute.h
* @code{.c}
*
* #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
* @endcode
*/
*/