/ Drivers / CMSIS / DSP / Source / DistanceFunctions / arm_correlation_distance_f16.c
arm_correlation_distance_f16.c
 1  
 2  /* ----------------------------------------------------------------------
 3   * Project:      CMSIS DSP Library
 4   * Title:        arm_correlation_distance_f16.c
 5   * Description:  Correlation distance between two vectors
 6   *
 7   * $Date:        23 April 2021
 8   * $Revision:    V1.9.0
 9   *
10   * Target Processor: Cortex-M and Cortex-A cores
11   * -------------------------------------------------------------------- */
12  /*
13   * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
14   *
15   * SPDX-License-Identifier: Apache-2.0
16   *
17   * Licensed under the Apache License, Version 2.0 (the License); you may
18   * not use this file except in compliance with the License.
19   * You may obtain a copy of the License at
20   *
21   * www.apache.org/licenses/LICENSE-2.0
22   *
23   * Unless required by applicable law or agreed to in writing, software
24   * distributed under the License is distributed on an AS IS BASIS, WITHOUT
25   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26   * See the License for the specific language governing permissions and
27   * limitations under the License.
28   */
29  
30  #include "dsp/distance_functions_f16.h"
31  
32  #if defined(ARM_FLOAT16_SUPPORTED)
33  
34  #include <limits.h>
35  #include <math.h>
36  
37  
38  /**
39    @ingroup FloatDist
40   */
41  
42  /**
43    @defgroup Correlation Correlation distance
44  
45    Correlation distance
46   */
47  
48  /**
49    @addtogroup Correlation
50    @{
51   */
52  
53  
54  /**
55   * @brief        Correlation distance between two vectors
56   *
57   * The input vectors are modified in place !
58   *
59   * @param[in]    pA         First vector
60   * @param[in]    pB         Second vector
61   * @param[in]    blockSize  vector length
62   * @return distance
63   *
64   */
65  
66  float16_t arm_correlation_distance_f16(float16_t *pA,float16_t *pB, uint32_t blockSize)
67  {
68      float16_t ma,mb,pwra,pwrb,dot,tmp;
69  
70      arm_mean_f16(pA, blockSize, &ma);
71      arm_mean_f16(pB, blockSize, &mb);
72  
73      arm_offset_f16(pA, -(_Float16)ma, pA, blockSize);
74      arm_offset_f16(pB, -(_Float16)mb, pB, blockSize);
75  
76      arm_power_f16(pA, blockSize, &pwra);
77      arm_power_f16(pB, blockSize, &pwrb);
78  
79      arm_dot_prod_f16(pA,pB,blockSize,&dot);
80  
81      dot = (_Float16)dot / (_Float16)blockSize;
82      pwra = (_Float16)pwra / (_Float16)blockSize;
83      pwrb = (_Float16)pwrb / (_Float16)blockSize;
84  
85      arm_sqrt_f16((_Float16)pwra * (_Float16)pwrb,&tmp);
86   
87      return(1.0f16 - (_Float16)dot / (_Float16)tmp);
88  
89     
90  }
91  
92  
93  
94  /**
95   * @} end of Correlation group
96   */
97  
98  #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */ 
99