The CMSIS DSP 5 library
Dependents: Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more
functions/StatisticsFunctions/arm_min_q31.c@3:4098b9d3d571, 2018-06-21 (annotated)
- Committer:
- xorjoep
- Date:
- Thu Jun 21 11:56:27 2018 +0000
- Revision:
- 3:4098b9d3d571
- Parent:
- 1:24714b45cd1b
headers is a folder not a library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xorjoep | 1:24714b45cd1b | 1 | /* ---------------------------------------------------------------------- |
xorjoep | 1:24714b45cd1b | 2 | * Project: CMSIS DSP Library |
xorjoep | 1:24714b45cd1b | 3 | * Title: arm_min_q31.c |
xorjoep | 1:24714b45cd1b | 4 | * Description: Minimum value of a Q31 vector |
xorjoep | 1:24714b45cd1b | 5 | * |
xorjoep | 1:24714b45cd1b | 6 | * $Date: 27. January 2017 |
xorjoep | 1:24714b45cd1b | 7 | * $Revision: V.1.5.1 |
xorjoep | 1:24714b45cd1b | 8 | * |
xorjoep | 1:24714b45cd1b | 9 | * Target Processor: Cortex-M cores |
xorjoep | 1:24714b45cd1b | 10 | * -------------------------------------------------------------------- */ |
xorjoep | 1:24714b45cd1b | 11 | /* |
xorjoep | 1:24714b45cd1b | 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
xorjoep | 1:24714b45cd1b | 13 | * |
xorjoep | 1:24714b45cd1b | 14 | * SPDX-License-Identifier: Apache-2.0 |
xorjoep | 1:24714b45cd1b | 15 | * |
xorjoep | 1:24714b45cd1b | 16 | * Licensed under the Apache License, Version 2.0 (the License); you may |
xorjoep | 1:24714b45cd1b | 17 | * not use this file except in compliance with the License. |
xorjoep | 1:24714b45cd1b | 18 | * You may obtain a copy of the License at |
xorjoep | 1:24714b45cd1b | 19 | * |
xorjoep | 1:24714b45cd1b | 20 | * www.apache.org/licenses/LICENSE-2.0 |
xorjoep | 1:24714b45cd1b | 21 | * |
xorjoep | 1:24714b45cd1b | 22 | * Unless required by applicable law or agreed to in writing, software |
xorjoep | 1:24714b45cd1b | 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
xorjoep | 1:24714b45cd1b | 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
xorjoep | 1:24714b45cd1b | 25 | * See the License for the specific language governing permissions and |
xorjoep | 1:24714b45cd1b | 26 | * limitations under the License. |
xorjoep | 1:24714b45cd1b | 27 | */ |
xorjoep | 1:24714b45cd1b | 28 | |
xorjoep | 1:24714b45cd1b | 29 | #include "arm_math.h" |
xorjoep | 1:24714b45cd1b | 30 | |
xorjoep | 1:24714b45cd1b | 31 | /** |
xorjoep | 1:24714b45cd1b | 32 | * @ingroup groupStats |
xorjoep | 1:24714b45cd1b | 33 | */ |
xorjoep | 1:24714b45cd1b | 34 | |
xorjoep | 1:24714b45cd1b | 35 | |
xorjoep | 1:24714b45cd1b | 36 | /** |
xorjoep | 1:24714b45cd1b | 37 | * @addtogroup Min |
xorjoep | 1:24714b45cd1b | 38 | * @{ |
xorjoep | 1:24714b45cd1b | 39 | */ |
xorjoep | 1:24714b45cd1b | 40 | |
xorjoep | 1:24714b45cd1b | 41 | |
xorjoep | 1:24714b45cd1b | 42 | /** |
xorjoep | 1:24714b45cd1b | 43 | * @brief Minimum value of a Q31 vector. |
xorjoep | 1:24714b45cd1b | 44 | * @param[in] *pSrc points to the input vector |
xorjoep | 1:24714b45cd1b | 45 | * @param[in] blockSize length of the input vector |
xorjoep | 1:24714b45cd1b | 46 | * @param[out] *pResult minimum value returned here |
xorjoep | 1:24714b45cd1b | 47 | * @param[out] *pIndex index of minimum value returned here |
xorjoep | 1:24714b45cd1b | 48 | * @return none. |
xorjoep | 1:24714b45cd1b | 49 | */ |
xorjoep | 1:24714b45cd1b | 50 | |
xorjoep | 1:24714b45cd1b | 51 | void arm_min_q31( |
xorjoep | 1:24714b45cd1b | 52 | q31_t * pSrc, |
xorjoep | 1:24714b45cd1b | 53 | uint32_t blockSize, |
xorjoep | 1:24714b45cd1b | 54 | q31_t * pResult, |
xorjoep | 1:24714b45cd1b | 55 | uint32_t * pIndex) |
xorjoep | 1:24714b45cd1b | 56 | { |
xorjoep | 1:24714b45cd1b | 57 | #if defined (ARM_MATH_DSP) |
xorjoep | 1:24714b45cd1b | 58 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
xorjoep | 1:24714b45cd1b | 59 | |
xorjoep | 1:24714b45cd1b | 60 | q31_t minVal1, minVal2, out; /* Temporary variables to store the output value. */ |
xorjoep | 1:24714b45cd1b | 61 | uint32_t blkCnt, outIndex, count; /* loop counter */ |
xorjoep | 1:24714b45cd1b | 62 | |
xorjoep | 1:24714b45cd1b | 63 | /* Initialise the count value. */ |
xorjoep | 1:24714b45cd1b | 64 | count = 0U; |
xorjoep | 1:24714b45cd1b | 65 | /* Initialise the index value to zero. */ |
xorjoep | 1:24714b45cd1b | 66 | outIndex = 0U; |
xorjoep | 1:24714b45cd1b | 67 | /* Load first input value that act as reference value for comparision */ |
xorjoep | 1:24714b45cd1b | 68 | out = *pSrc++; |
xorjoep | 1:24714b45cd1b | 69 | |
xorjoep | 1:24714b45cd1b | 70 | /* Loop unrolling */ |
xorjoep | 1:24714b45cd1b | 71 | blkCnt = (blockSize - 1U) >> 2U; |
xorjoep | 1:24714b45cd1b | 72 | |
xorjoep | 1:24714b45cd1b | 73 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 74 | { |
xorjoep | 1:24714b45cd1b | 75 | /* Initialize minVal to the next consecutive values one by one */ |
xorjoep | 1:24714b45cd1b | 76 | minVal1 = *pSrc++; |
xorjoep | 1:24714b45cd1b | 77 | minVal2 = *pSrc++; |
xorjoep | 1:24714b45cd1b | 78 | |
xorjoep | 1:24714b45cd1b | 79 | /* compare for the minimum value */ |
xorjoep | 1:24714b45cd1b | 80 | if (out > minVal1) |
xorjoep | 1:24714b45cd1b | 81 | { |
xorjoep | 1:24714b45cd1b | 82 | /* Update the minimum value and its index */ |
xorjoep | 1:24714b45cd1b | 83 | out = minVal1; |
xorjoep | 1:24714b45cd1b | 84 | outIndex = count + 1U; |
xorjoep | 1:24714b45cd1b | 85 | } |
xorjoep | 1:24714b45cd1b | 86 | |
xorjoep | 1:24714b45cd1b | 87 | /* compare for the minimum value */ |
xorjoep | 1:24714b45cd1b | 88 | if (out > minVal2) |
xorjoep | 1:24714b45cd1b | 89 | { |
xorjoep | 1:24714b45cd1b | 90 | /* Update the minimum value and its index */ |
xorjoep | 1:24714b45cd1b | 91 | out = minVal2; |
xorjoep | 1:24714b45cd1b | 92 | outIndex = count + 2U; |
xorjoep | 1:24714b45cd1b | 93 | } |
xorjoep | 1:24714b45cd1b | 94 | |
xorjoep | 1:24714b45cd1b | 95 | /* Initialize minVal to the next consecutive values one by one */ |
xorjoep | 1:24714b45cd1b | 96 | minVal1 = *pSrc++; |
xorjoep | 1:24714b45cd1b | 97 | minVal2 = *pSrc++; |
xorjoep | 1:24714b45cd1b | 98 | |
xorjoep | 1:24714b45cd1b | 99 | /* compare for the minimum value */ |
xorjoep | 1:24714b45cd1b | 100 | if (out > minVal1) |
xorjoep | 1:24714b45cd1b | 101 | { |
xorjoep | 1:24714b45cd1b | 102 | /* Update the minimum value and its index */ |
xorjoep | 1:24714b45cd1b | 103 | out = minVal1; |
xorjoep | 1:24714b45cd1b | 104 | outIndex = count + 3U; |
xorjoep | 1:24714b45cd1b | 105 | } |
xorjoep | 1:24714b45cd1b | 106 | |
xorjoep | 1:24714b45cd1b | 107 | /* compare for the minimum value */ |
xorjoep | 1:24714b45cd1b | 108 | if (out > minVal2) |
xorjoep | 1:24714b45cd1b | 109 | { |
xorjoep | 1:24714b45cd1b | 110 | /* Update the minimum value and its index */ |
xorjoep | 1:24714b45cd1b | 111 | out = minVal2; |
xorjoep | 1:24714b45cd1b | 112 | outIndex = count + 4U; |
xorjoep | 1:24714b45cd1b | 113 | } |
xorjoep | 1:24714b45cd1b | 114 | |
xorjoep | 1:24714b45cd1b | 115 | count += 4U; |
xorjoep | 1:24714b45cd1b | 116 | |
xorjoep | 1:24714b45cd1b | 117 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 118 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 119 | } |
xorjoep | 1:24714b45cd1b | 120 | |
xorjoep | 1:24714b45cd1b | 121 | /* if (blockSize - 1U) is not multiple of 4 */ |
xorjoep | 1:24714b45cd1b | 122 | blkCnt = (blockSize - 1U) % 4U; |
xorjoep | 1:24714b45cd1b | 123 | |
xorjoep | 1:24714b45cd1b | 124 | #else |
xorjoep | 1:24714b45cd1b | 125 | /* Run the below code for Cortex-M0 */ |
xorjoep | 1:24714b45cd1b | 126 | |
xorjoep | 1:24714b45cd1b | 127 | q31_t minVal1, out; /* Temporary variables to store the output value. */ |
xorjoep | 1:24714b45cd1b | 128 | uint32_t blkCnt, outIndex; /* loop counter */ |
xorjoep | 1:24714b45cd1b | 129 | |
xorjoep | 1:24714b45cd1b | 130 | /* Initialise the index value to zero. */ |
xorjoep | 1:24714b45cd1b | 131 | outIndex = 0U; |
xorjoep | 1:24714b45cd1b | 132 | /* Load first input value that act as reference value for comparision */ |
xorjoep | 1:24714b45cd1b | 133 | out = *pSrc++; |
xorjoep | 1:24714b45cd1b | 134 | |
xorjoep | 1:24714b45cd1b | 135 | blkCnt = (blockSize - 1U); |
xorjoep | 1:24714b45cd1b | 136 | |
xorjoep | 1:24714b45cd1b | 137 | #endif /* #if defined (ARM_MATH_DSP) */ |
xorjoep | 1:24714b45cd1b | 138 | |
xorjoep | 1:24714b45cd1b | 139 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 140 | { |
xorjoep | 1:24714b45cd1b | 141 | /* Initialize minVal to the next consecutive values one by one */ |
xorjoep | 1:24714b45cd1b | 142 | minVal1 = *pSrc++; |
xorjoep | 1:24714b45cd1b | 143 | |
xorjoep | 1:24714b45cd1b | 144 | /* compare for the minimum value */ |
xorjoep | 1:24714b45cd1b | 145 | if (out > minVal1) |
xorjoep | 1:24714b45cd1b | 146 | { |
xorjoep | 1:24714b45cd1b | 147 | /* Update the minimum value and it's index */ |
xorjoep | 1:24714b45cd1b | 148 | out = minVal1; |
xorjoep | 1:24714b45cd1b | 149 | outIndex = blockSize - blkCnt; |
xorjoep | 1:24714b45cd1b | 150 | } |
xorjoep | 1:24714b45cd1b | 151 | |
xorjoep | 1:24714b45cd1b | 152 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 153 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 154 | } |
xorjoep | 1:24714b45cd1b | 155 | |
xorjoep | 1:24714b45cd1b | 156 | /* Store the minimum value and it's index into destination pointers */ |
xorjoep | 1:24714b45cd1b | 157 | *pResult = out; |
xorjoep | 1:24714b45cd1b | 158 | *pIndex = outIndex; |
xorjoep | 1:24714b45cd1b | 159 | } |
xorjoep | 1:24714b45cd1b | 160 | |
xorjoep | 1:24714b45cd1b | 161 | /** |
xorjoep | 1:24714b45cd1b | 162 | * @} end of Min group |
xorjoep | 1:24714b45cd1b | 163 | */ |