arm_std_f32.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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. #include "arm_math.h"
  29. /**
  30. @ingroup groupStats
  31. */
  32. /**
  33. @defgroup STD Standard deviation
  34. Calculates the standard deviation of the elements in the input vector.
  35. The float implementation is relying on arm_var_f32 which is using a two-pass algorithm
  36. to avoid problem of numerical instabilities and cancellation errors.
  37. Fixed point versions are using the standard textbook algorithm since the fixed point
  38. numerical behavior is different from the float one.
  39. Algorithm for fixed point versions is summarized below:
  40. <pre>
  41. Result = sqrt((sumOfSquares - sum<sup>2</sup> / blockSize) / (blockSize - 1))
  42. sumOfSquares = pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] * pSrc[blockSize-1]
  43. sum = pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1]
  44. </pre>
  45. There are separate functions for floating point, Q31, and Q15 data types.
  46. */
  47. /**
  48. @addtogroup STD
  49. @{
  50. */
  51. /**
  52. @brief Standard deviation of the elements of a floating-point vector.
  53. @param[in] pSrc points to the input vector
  54. @param[in] blockSize number of samples in input vector
  55. @param[out] pResult standard deviation value returned here
  56. @return none
  57. */
  58. void arm_std_f32(
  59. const float32_t * pSrc,
  60. uint32_t blockSize,
  61. float32_t * pResult)
  62. {
  63. float32_t var;
  64. arm_var_f32(pSrc,blockSize,&var);
  65. arm_sqrt_f32(var, pResult);
  66. }
  67. /**
  68. @} end of STD group
  69. */