1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
10 * Description: Root mean square value of an array of F32 type
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Version 1.0.10 2011/7/15
15 * Big Endian support added and Merged M0 and M3/M4 Source code.
17 * Version 1.0.3 2010/11/29
18 * Re-organized the CMSIS folders and updated documentation.
20 * Version 1.0.2 2010/11/11
21 * Documentation updated.
23 * Version 1.0.1 2010/10/05
24 * Production release and review comments incorporated.
26 * Version 1.0.0 2010/09/20
27 * Production release and review comments incorporated.
28 * ---------------------------------------------------------------------------- */
37 * @defgroup RMS Root mean square (RMS)
40 * Calculates the Root Mean Sqaure of the elements in the input vector.
41 * The underlying algorithm is used:
44 * Result = sqrt(((pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] * pSrc[blockSize-1]) / blockSize));
47 * There are separate functions for floating point, Q31, and Q15 data types.
57 * @brief Root Mean Square of the elements of a floating-point vector.
58 * @param[in] *pSrc points to the input vector
59 * @param[in] blockSize length of the input vector
60 * @param[out] *pResult rms value returned here
70 float32_t sum = 0.0f; /* Accumulator */
71 float32_t in; /* Tempoprary variable to store input value */
72 uint32_t blkCnt; /* loop counter */
76 /* Run the below code for Cortex-M4 and Cortex-M3 */
79 blkCnt = blockSize >> 2u;
81 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
82 ** a second loop below computes the remaining 1 to 3 samples. */
85 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */
86 /* Compute sum of the squares and then store the result in a temporary variable, sum */
96 /* Decrement the loop counter */
100 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
101 ** No loop unrolling is used. */
102 blkCnt = blockSize % 0x4u;
106 /* Run the below code for Cortex-M0 */
108 /* Loop over blockSize number of values */
111 #endif /* #ifndef ARM_MATH_CM0 */
115 /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */
116 /* Compute sum of the squares and then store the results in a temporary variable, sum */
120 /* Decrement the loop counter */
124 /* Compute Rms and store the result in the destination */
125 arm_sqrt_f32(sum / (float32_t) blockSize, pResult);
129 * @} end of RMS group