arm_correlation_distance_f32.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_correlation_distance_f32.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.h"
  29. #include <limits.h>
  30. #include <math.h>
  31. /**
  32. @addtogroup Correlation
  33. @{
  34. */
  35. /**
  36. * @brief Correlation distance between two vectors
  37. *
  38. * The input vectors are modified in place !
  39. *
  40. * @param[in] pA First vector
  41. * @param[in] pB Second vector
  42. * @param[in] blockSize vector length
  43. * @return distance
  44. *
  45. */
  46. float32_t arm_correlation_distance_f32(float32_t *pA,float32_t *pB, uint32_t blockSize)
  47. {
  48. float32_t ma,mb,pwra,pwrb,dot,tmp;
  49. arm_mean_f32(pA, blockSize, &ma);
  50. arm_mean_f32(pB, blockSize, &mb);
  51. arm_offset_f32(pA, -ma, pA, blockSize);
  52. arm_offset_f32(pB, -mb, pB, blockSize);
  53. arm_power_f32(pA, blockSize, &pwra);
  54. arm_power_f32(pB, blockSize, &pwrb);
  55. arm_dot_prod_f32(pA,pB,blockSize,&dot);
  56. dot = dot / blockSize;
  57. pwra = pwra / blockSize;
  58. pwrb = pwrb / blockSize;
  59. arm_sqrt_f32(pwra * pwrb,&tmp);
  60. return(1.0f - dot / tmp);
  61. }
  62. /**
  63. * @} end of Correlation group
  64. */