1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
8 * Title: arm_mean_q31.c
10 * Description: Mean value of a Q31 vector.
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Version 1.0.10 2011/7/15
15 * Big Endian support added and Merged M0 and M3/M4 Source code.
17 * Version 1.0.3 2010/11/29
18 * Re-organized the CMSIS folders and updated documentation.
20 * Version 1.0.2 2010/11/11
21 * Documentation updated.
23 * Version 1.0.1 2010/10/05
24 * Production release and review comments incorporated.
26 * Version 1.0.0 2010/09/20
27 * Production release and review comments incorporated.
28 * -------------------------------------------------------------------- */
42 * @brief Mean value of a Q31 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
49 * <b>Scaling and Overflow Behavior:</b>
51 * The function is implemented using a 64-bit internal accumulator.
52 * The input is represented in 1.31 format and is accumulated in a 64-bit
53 * accumulator in 33.31 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 truncated to yield a result of 1.31 format.
66 q63_t sum = 0; /* Temporary result storage */
67 uint32_t blkCnt; /* loop counter */
71 /* Run the below code for Cortex-M4 and Cortex-M3 */
74 blkCnt = blockSize >> 2u;
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. */
80 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
86 /* Decrement the loop counter */
90 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
91 ** No loop unrolling is used. */
92 blkCnt = blockSize % 0x4u;
96 /* Run the below code for Cortex-M0 */
98 /* Loop over blockSize number of values */
101 #endif /* #ifndef ARM_MATH_CM0 */
105 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
108 /* Decrement the loop counter */
112 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) / blockSize */
113 /* Store the result to the destination */
114 *pResult = (q31_t) (sum / (int32_t) blockSize);
118 * @} end of mean group