arm_std_f32.c
1 /* ---------------------------------------------------------------------- 2 * Project: CMSIS DSP Library 3 * Title: arm_std_f32.c 4 * Description: Standard deviation 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.h" 30 31 /** 32 @ingroup groupStats 33 */ 34 35 /** 36 @defgroup STD Standard deviation 37 38 Calculates the standard deviation of the elements in the input vector. 39 40 The float implementation is relying on arm_var_f32 which is using a two-pass algorithm 41 to avoid problem of numerical instabilities and cancellation errors. 42 43 Fixed point versions are using the standard textbook algorithm since the fixed point 44 numerical behavior is different from the float one. 45 46 Algorithm for fixed point versions is summarized below: 47 48 49 <pre> 50 Result = sqrt((sumOfSquares - sum<sup>2</sup> / blockSize) / (blockSize - 1)) 51 52 sumOfSquares = pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] * pSrc[blockSize-1] 53 sum = pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1] 54 </pre> 55 56 There are separate functions for floating point, Q31, and Q15 data types. 57 */ 58 59 /** 60 @addtogroup STD 61 @{ 62 */ 63 64 /** 65 @brief Standard deviation of the elements of a floating-point vector. 66 @param[in] pSrc points to the input vector 67 @param[in] blockSize number of samples in input vector 68 @param[out] pResult standard deviation value returned here 69 @return none 70 */ 71 void arm_std_f32( 72 const float32_t * pSrc, 73 uint32_t blockSize, 74 float32_t * pResult) 75 { 76 float32_t var; 77 arm_var_f32(pSrc,blockSize,&var); 78 arm_sqrt_f32(var, pResult); 79 } 80 81 /** 82 @} end of STD group 83 */