• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_rms_f16.c
4  * Description:  Root mean square value of the elements of a floating-point vector
5  *
6  * $Date:        23 April 2021
7  * $Revision:    V1.9.0
8  *
9  * Target Processor: Cortex-M and Cortex-A cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13  *
14  * SPDX-License-Identifier: Apache-2.0
15  *
16  * Licensed under the Apache License, Version 2.0 (the License); you may
17  * not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  */
28 
29 #include "dsp/statistics_functions_f16.h"
30 
31 #if defined(ARM_FLOAT16_SUPPORTED)
32 
33 
34 /**
35   @ingroup groupStats
36  */
37 
38 /**
39   @defgroup RMS Root mean square (RMS)
40 
41   Calculates the Root Mean Square of the elements in the input vector.
42   The underlying algorithm is used:
43 
44   <pre>
45       Result = sqrt(((pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] * pSrc[blockSize-1]) / blockSize));
46   </pre>
47 
48   There are separate functions for floating point, Q31, and Q15 data types.
49  */
50 
51 /**
52   @addtogroup RMS
53   @{
54  */
55 
56 /**
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  number of samples in input vector
60   @param[out]    pResult    root mean square value returned here
61   @return        none
62  */
63 
64 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
65 
arm_rms_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)66 void arm_rms_f16(
67   const float16_t * pSrc,
68   uint32_t blockSize,
69   float16_t * pResult)
70 {
71     float16_t pow = 0.0f;
72 
73     arm_power_f16(pSrc, blockSize, &pow);
74 
75     /* Compute Rms and store the result in the destination */
76     arm_sqrt_f16(pow / (float16_t) blockSize, pResult);
77 }
78 #else
79 
arm_rms_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)80 void arm_rms_f16(
81   const float16_t * pSrc,
82         uint32_t blockSize,
83         float16_t * pResult)
84 {
85         uint32_t blkCnt;                               /* Loop counter */
86         _Float16 sum = 0.0f16;                          /* Temporary result storage */
87         _Float16 in;                                  /* Temporary variable to store input value */
88 
89 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
90 
91   /* Loop unrolling: Compute 4 outputs at a time */
92   blkCnt = blockSize >> 2U;
93 
94   while (blkCnt > 0U)
95   {
96     /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
97 
98     in = *pSrc++;
99     /* Compute sum of squares and store result in a temporary variable, sum. */
100     sum += in * in;
101 
102     in = *pSrc++;
103     sum += in * in;
104 
105     in = *pSrc++;
106     sum += in * in;
107 
108     in = *pSrc++;
109     sum += in * in;
110 
111     /* Decrement loop counter */
112     blkCnt--;
113   }
114 
115   /* Loop unrolling: Compute remaining outputs */
116   blkCnt = blockSize % 0x4U;
117 
118 #else
119 
120   /* Initialize blkCnt with number of samples */
121   blkCnt = blockSize;
122 
123 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
124 
125   while (blkCnt > 0U)
126   {
127     /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
128 
129     in = *pSrc++;
130     /* Compute sum of squares and store result in a temporary variable. */
131     sum += ( in * in);
132 
133     /* Decrement loop counter */
134     blkCnt--;
135   }
136 
137   /* Compute Rms and store result in destination */
138   arm_sqrt_f16(sum / (float16_t) blockSize, pResult);
139 }
140 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
141 
142 /**
143   @} end of RMS group
144  */
145 
146 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
147 
148