arm_correlation_distance_f16.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_correlation_distance_f16.c
  4. * Description: Correlation distance between two vectors
  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. #include "dsp/distance_functions_f16.h"
  29. #if defined(ARM_FLOAT16_SUPPORTED)
  30. #include <limits.h>
  31. #include <math.h>
  32. /**
  33. @ingroup FloatDist
  34. */
  35. /**
  36. @defgroup Correlation Correlation distance
  37. Correlation distance
  38. */
  39. /**
  40. @addtogroup Correlation
  41. @{
  42. */
  43. /**
  44. * @brief Correlation distance between two vectors
  45. *
  46. * The input vectors are modified in place !
  47. *
  48. * @param[in] pA First vector
  49. * @param[in] pB Second vector
  50. * @param[in] blockSize vector length
  51. * @return distance
  52. *
  53. */
  54. float16_t arm_correlation_distance_f16(float16_t *pA,float16_t *pB, uint32_t blockSize)
  55. {
  56. float16_t ma,mb,pwra,pwrb,dot,tmp;
  57. arm_mean_f16(pA, blockSize, &ma);
  58. arm_mean_f16(pB, blockSize, &mb);
  59. arm_offset_f16(pA, -(_Float16)ma, pA, blockSize);
  60. arm_offset_f16(pB, -(_Float16)mb, pB, blockSize);
  61. arm_power_f16(pA, blockSize, &pwra);
  62. arm_power_f16(pB, blockSize, &pwrb);
  63. arm_dot_prod_f16(pA,pB,blockSize,&dot);
  64. dot = (_Float16)dot / (_Float16)blockSize;
  65. pwra = (_Float16)pwra / (_Float16)blockSize;
  66. pwrb = (_Float16)pwrb / (_Float16)blockSize;
  67. arm_sqrt_f16((_Float16)pwra * (_Float16)pwrb,&tmp);
  68. return(1.0f16 - (_Float16)dot / (_Float16)tmp);
  69. }
  70. /**
  71. * @} end of Correlation group
  72. */
  73. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */