Subversion Repositories dashGPS

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* ----------------------------------------------------------------------
2
 * Project:      CMSIS DSP Library
3
 * Title:        arm_mean_q15.c
4
 * Description:  Mean value of a Q15 vector
5
 *
6
 * $Date:        27. January 2017
7
 * $Revision:    V.1.5.1
8
 *
9
 * Target Processor: Cortex-M cores
10
 * -------------------------------------------------------------------- */
11
/*
12
 * Copyright (C) 2010-2017 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
 
29
#include "arm_math.h"
30
 
31
/**
32
 * @ingroup groupStats
33
 */
34
 
35
/**
36
 * @addtogroup mean
37
 * @{
38
 */
39
 
40
 
41
/**
42
 * @brief Mean value of a Q15 vector.
43
 * @param[in]       *pSrc points to the input vector
44
 * @param[in]       blockSize length of the input vector
45
 * @param[out]      *pResult mean value returned here
46
 * @return none.
47
 *
48
 * @details
49
 * <b>Scaling and Overflow Behavior:</b>
50
 * \par
51
 * The function is implemented using a 32-bit internal accumulator.
52
 * The input is represented in 1.15 format and is accumulated in a 32-bit
53
 * accumulator in 17.15 format.
54
 * There is no risk of internal overflow with this approach, and the
55
 * full precision of intermediate result is preserved.
56
 * Finally, the accumulator is saturated and truncated to yield a result of 1.15 format.
57
 *
58
 */
59
 
60
void arm_mean_q15(
61
  q15_t * pSrc,
62
  uint32_t blockSize,
63
  q15_t * pResult)
64
{
65
  q31_t sum = 0;                                 /* Temporary result storage */
66
  uint32_t blkCnt;                               /* loop counter */
67
 
68
#if defined (ARM_MATH_DSP)
69
  /* Run the below code for Cortex-M4 and Cortex-M3 */
70
 
71
  q31_t in;
72
 
73
  /*loop Unrolling */
74
  blkCnt = blockSize >> 2U;
75
 
76
  /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
77
   ** a second loop below computes the remaining 1 to 3 samples. */
78
  while (blkCnt > 0U)
79
  {
80
    /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
81
    in = *__SIMD32(pSrc)++;
82
    sum += ((in << 16U) >> 16U);
83
    sum +=  (in >> 16U);
84
    in = *__SIMD32(pSrc)++;
85
    sum += ((in << 16U) >> 16U);
86
    sum +=  (in >> 16U);
87
 
88
    /* Decrement the loop counter */
89
    blkCnt--;
90
  }
91
 
92
  /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
93
   ** No loop unrolling is used. */
94
  blkCnt = blockSize % 0x4U;
95
 
96
#else
97
  /* Run the below code for Cortex-M0 */
98
 
99
  /* Loop over blockSize number of values */
100
  blkCnt = blockSize;
101
 
102
#endif /* #if defined (ARM_MATH_DSP) */
103
 
104
  while (blkCnt > 0U)
105
  {
106
    /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
107
    sum += *pSrc++;
108
 
109
    /* Decrement the loop counter */
110
    blkCnt--;
111
  }
112
 
113
  /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) / blockSize  */
114
  /* Store the result to the destination */
115
  *pResult = (q15_t) (sum / (q31_t)blockSize);
116
}
117
 
118
/**
119
 * @} end of mean group
120
 */