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