The CMSIS DSP 5 library
Dependents: Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more
functions/FilteringFunctions/arm_lms_q15.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_lms_q15.c |
xorjoep | 1:24714b45cd1b | 4 | * Description: Processing function for the Q15 LMS filter |
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 | * @ingroup groupFilters |
xorjoep | 1:24714b45cd1b | 32 | */ |
xorjoep | 1:24714b45cd1b | 33 | |
xorjoep | 1:24714b45cd1b | 34 | /** |
xorjoep | 1:24714b45cd1b | 35 | * @addtogroup LMS |
xorjoep | 1:24714b45cd1b | 36 | * @{ |
xorjoep | 1:24714b45cd1b | 37 | */ |
xorjoep | 1:24714b45cd1b | 38 | |
xorjoep | 1:24714b45cd1b | 39 | /** |
xorjoep | 1:24714b45cd1b | 40 | * @brief Processing function for Q15 LMS filter. |
xorjoep | 1:24714b45cd1b | 41 | * @param[in] *S points to an instance of the Q15 LMS filter structure. |
xorjoep | 1:24714b45cd1b | 42 | * @param[in] *pSrc points to the block of input data. |
xorjoep | 1:24714b45cd1b | 43 | * @param[in] *pRef points to the block of reference data. |
xorjoep | 1:24714b45cd1b | 44 | * @param[out] *pOut points to the block of output data. |
xorjoep | 1:24714b45cd1b | 45 | * @param[out] *pErr points to the block of error data. |
xorjoep | 1:24714b45cd1b | 46 | * @param[in] blockSize number of samples to process. |
xorjoep | 1:24714b45cd1b | 47 | * @return none. |
xorjoep | 1:24714b45cd1b | 48 | * |
xorjoep | 1:24714b45cd1b | 49 | * \par Scaling and Overflow Behavior: |
xorjoep | 1:24714b45cd1b | 50 | * The function is implemented using a 64-bit internal accumulator. |
xorjoep | 1:24714b45cd1b | 51 | * Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. |
xorjoep | 1:24714b45cd1b | 52 | * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. |
xorjoep | 1:24714b45cd1b | 53 | * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. |
xorjoep | 1:24714b45cd1b | 54 | * After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. |
xorjoep | 1:24714b45cd1b | 55 | * Lastly, the accumulator is saturated to yield a result in 1.15 format. |
xorjoep | 1:24714b45cd1b | 56 | * |
xorjoep | 1:24714b45cd1b | 57 | * \par |
xorjoep | 1:24714b45cd1b | 58 | * In this filter, filter coefficients are updated for each sample and the updation of filter cofficients are saturted. |
xorjoep | 1:24714b45cd1b | 59 | * |
xorjoep | 1:24714b45cd1b | 60 | */ |
xorjoep | 1:24714b45cd1b | 61 | |
xorjoep | 1:24714b45cd1b | 62 | void arm_lms_q15( |
xorjoep | 1:24714b45cd1b | 63 | const arm_lms_instance_q15 * S, |
xorjoep | 1:24714b45cd1b | 64 | q15_t * pSrc, |
xorjoep | 1:24714b45cd1b | 65 | q15_t * pRef, |
xorjoep | 1:24714b45cd1b | 66 | q15_t * pOut, |
xorjoep | 1:24714b45cd1b | 67 | q15_t * pErr, |
xorjoep | 1:24714b45cd1b | 68 | uint32_t blockSize) |
xorjoep | 1:24714b45cd1b | 69 | { |
xorjoep | 1:24714b45cd1b | 70 | q15_t *pState = S->pState; /* State pointer */ |
xorjoep | 1:24714b45cd1b | 71 | uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
xorjoep | 1:24714b45cd1b | 72 | q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
xorjoep | 1:24714b45cd1b | 73 | q15_t *pStateCurnt; /* Points to the current sample of the state */ |
xorjoep | 1:24714b45cd1b | 74 | q15_t mu = S->mu; /* Adaptive factor */ |
xorjoep | 1:24714b45cd1b | 75 | q15_t *px; /* Temporary pointer for state */ |
xorjoep | 1:24714b45cd1b | 76 | q15_t *pb; /* Temporary pointer for coefficient buffer */ |
xorjoep | 1:24714b45cd1b | 77 | uint32_t tapCnt, blkCnt; /* Loop counters */ |
xorjoep | 1:24714b45cd1b | 78 | q63_t acc; /* Accumulator */ |
xorjoep | 1:24714b45cd1b | 79 | q15_t e = 0; /* error of data sample */ |
xorjoep | 1:24714b45cd1b | 80 | q15_t alpha; /* Intermediate constant for taps update */ |
xorjoep | 1:24714b45cd1b | 81 | q31_t coef; /* Teporary variable for coefficient */ |
xorjoep | 1:24714b45cd1b | 82 | q31_t acc_l, acc_h; |
xorjoep | 1:24714b45cd1b | 83 | int32_t lShift = (15 - (int32_t) S->postShift); /* Post shift */ |
xorjoep | 1:24714b45cd1b | 84 | int32_t uShift = (32 - lShift); |
xorjoep | 1:24714b45cd1b | 85 | |
xorjoep | 1:24714b45cd1b | 86 | |
xorjoep | 1:24714b45cd1b | 87 | #if defined (ARM_MATH_DSP) |
xorjoep | 1:24714b45cd1b | 88 | |
xorjoep | 1:24714b45cd1b | 89 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
xorjoep | 1:24714b45cd1b | 90 | |
xorjoep | 1:24714b45cd1b | 91 | |
xorjoep | 1:24714b45cd1b | 92 | /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ |
xorjoep | 1:24714b45cd1b | 93 | /* pStateCurnt points to the location where the new input data should be written */ |
xorjoep | 1:24714b45cd1b | 94 | pStateCurnt = &(S->pState[(numTaps - 1U)]); |
xorjoep | 1:24714b45cd1b | 95 | |
xorjoep | 1:24714b45cd1b | 96 | /* Initializing blkCnt with blockSize */ |
xorjoep | 1:24714b45cd1b | 97 | blkCnt = blockSize; |
xorjoep | 1:24714b45cd1b | 98 | |
xorjoep | 1:24714b45cd1b | 99 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 100 | { |
xorjoep | 1:24714b45cd1b | 101 | /* Copy the new input sample into the state buffer */ |
xorjoep | 1:24714b45cd1b | 102 | *pStateCurnt++ = *pSrc++; |
xorjoep | 1:24714b45cd1b | 103 | |
xorjoep | 1:24714b45cd1b | 104 | /* Initialize state pointer */ |
xorjoep | 1:24714b45cd1b | 105 | px = pState; |
xorjoep | 1:24714b45cd1b | 106 | |
xorjoep | 1:24714b45cd1b | 107 | /* Initialize coefficient pointer */ |
xorjoep | 1:24714b45cd1b | 108 | pb = pCoeffs; |
xorjoep | 1:24714b45cd1b | 109 | |
xorjoep | 1:24714b45cd1b | 110 | /* Set the accumulator to zero */ |
xorjoep | 1:24714b45cd1b | 111 | acc = 0; |
xorjoep | 1:24714b45cd1b | 112 | |
xorjoep | 1:24714b45cd1b | 113 | /* Loop unrolling. Process 4 taps at a time. */ |
xorjoep | 1:24714b45cd1b | 114 | tapCnt = numTaps >> 2U; |
xorjoep | 1:24714b45cd1b | 115 | |
xorjoep | 1:24714b45cd1b | 116 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 117 | { |
xorjoep | 1:24714b45cd1b | 118 | /* acc += b[N] * x[n-N] + b[N-1] * x[n-N-1] */ |
xorjoep | 1:24714b45cd1b | 119 | /* Perform the multiply-accumulate */ |
xorjoep | 1:24714b45cd1b | 120 | #ifndef UNALIGNED_SUPPORT_DISABLE |
xorjoep | 1:24714b45cd1b | 121 | |
xorjoep | 1:24714b45cd1b | 122 | acc = __SMLALD(*__SIMD32(px)++, (*__SIMD32(pb)++), acc); |
xorjoep | 1:24714b45cd1b | 123 | acc = __SMLALD(*__SIMD32(px)++, (*__SIMD32(pb)++), acc); |
xorjoep | 1:24714b45cd1b | 124 | |
xorjoep | 1:24714b45cd1b | 125 | #else |
xorjoep | 1:24714b45cd1b | 126 | |
xorjoep | 1:24714b45cd1b | 127 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
xorjoep | 1:24714b45cd1b | 128 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
xorjoep | 1:24714b45cd1b | 129 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
xorjoep | 1:24714b45cd1b | 130 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
xorjoep | 1:24714b45cd1b | 131 | |
xorjoep | 1:24714b45cd1b | 132 | |
xorjoep | 1:24714b45cd1b | 133 | #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */ |
xorjoep | 1:24714b45cd1b | 134 | |
xorjoep | 1:24714b45cd1b | 135 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 136 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 137 | } |
xorjoep | 1:24714b45cd1b | 138 | |
xorjoep | 1:24714b45cd1b | 139 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
xorjoep | 1:24714b45cd1b | 140 | tapCnt = numTaps % 0x4U; |
xorjoep | 1:24714b45cd1b | 141 | |
xorjoep | 1:24714b45cd1b | 142 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 143 | { |
xorjoep | 1:24714b45cd1b | 144 | /* Perform the multiply-accumulate */ |
xorjoep | 1:24714b45cd1b | 145 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
xorjoep | 1:24714b45cd1b | 146 | |
xorjoep | 1:24714b45cd1b | 147 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 148 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 149 | } |
xorjoep | 1:24714b45cd1b | 150 | |
xorjoep | 1:24714b45cd1b | 151 | /* Calc lower part of acc */ |
xorjoep | 1:24714b45cd1b | 152 | acc_l = acc & 0xffffffff; |
xorjoep | 1:24714b45cd1b | 153 | |
xorjoep | 1:24714b45cd1b | 154 | /* Calc upper part of acc */ |
xorjoep | 1:24714b45cd1b | 155 | acc_h = (acc >> 32) & 0xffffffff; |
xorjoep | 1:24714b45cd1b | 156 | |
xorjoep | 1:24714b45cd1b | 157 | /* Apply shift for lower part of acc and upper part of acc */ |
xorjoep | 1:24714b45cd1b | 158 | acc = (uint32_t) acc_l >> lShift | acc_h << uShift; |
xorjoep | 1:24714b45cd1b | 159 | |
xorjoep | 1:24714b45cd1b | 160 | /* Converting the result to 1.15 format and saturate the output */ |
xorjoep | 1:24714b45cd1b | 161 | acc = __SSAT(acc, 16); |
xorjoep | 1:24714b45cd1b | 162 | |
xorjoep | 1:24714b45cd1b | 163 | /* Store the result from accumulator into the destination buffer. */ |
xorjoep | 1:24714b45cd1b | 164 | *pOut++ = (q15_t) acc; |
xorjoep | 1:24714b45cd1b | 165 | |
xorjoep | 1:24714b45cd1b | 166 | /* Compute and store error */ |
xorjoep | 1:24714b45cd1b | 167 | e = *pRef++ - (q15_t) acc; |
xorjoep | 1:24714b45cd1b | 168 | |
xorjoep | 1:24714b45cd1b | 169 | *pErr++ = (q15_t) e; |
xorjoep | 1:24714b45cd1b | 170 | |
xorjoep | 1:24714b45cd1b | 171 | /* Compute alpha i.e. intermediate constant for taps update */ |
xorjoep | 1:24714b45cd1b | 172 | alpha = (q15_t) (((q31_t) e * (mu)) >> 15); |
xorjoep | 1:24714b45cd1b | 173 | |
xorjoep | 1:24714b45cd1b | 174 | /* Initialize state pointer */ |
xorjoep | 1:24714b45cd1b | 175 | /* Advance state pointer by 1 for the next sample */ |
xorjoep | 1:24714b45cd1b | 176 | px = pState++; |
xorjoep | 1:24714b45cd1b | 177 | |
xorjoep | 1:24714b45cd1b | 178 | /* Initialize coefficient pointer */ |
xorjoep | 1:24714b45cd1b | 179 | pb = pCoeffs; |
xorjoep | 1:24714b45cd1b | 180 | |
xorjoep | 1:24714b45cd1b | 181 | /* Loop unrolling. Process 4 taps at a time. */ |
xorjoep | 1:24714b45cd1b | 182 | tapCnt = numTaps >> 2U; |
xorjoep | 1:24714b45cd1b | 183 | |
xorjoep | 1:24714b45cd1b | 184 | /* Update filter coefficients */ |
xorjoep | 1:24714b45cd1b | 185 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 186 | { |
xorjoep | 1:24714b45cd1b | 187 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
xorjoep | 1:24714b45cd1b | 188 | *pb++ = (q15_t) __SSAT((coef), 16); |
xorjoep | 1:24714b45cd1b | 189 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
xorjoep | 1:24714b45cd1b | 190 | *pb++ = (q15_t) __SSAT((coef), 16); |
xorjoep | 1:24714b45cd1b | 191 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
xorjoep | 1:24714b45cd1b | 192 | *pb++ = (q15_t) __SSAT((coef), 16); |
xorjoep | 1:24714b45cd1b | 193 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
xorjoep | 1:24714b45cd1b | 194 | *pb++ = (q15_t) __SSAT((coef), 16); |
xorjoep | 1:24714b45cd1b | 195 | |
xorjoep | 1:24714b45cd1b | 196 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 197 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 198 | } |
xorjoep | 1:24714b45cd1b | 199 | |
xorjoep | 1:24714b45cd1b | 200 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
xorjoep | 1:24714b45cd1b | 201 | tapCnt = numTaps % 0x4U; |
xorjoep | 1:24714b45cd1b | 202 | |
xorjoep | 1:24714b45cd1b | 203 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 204 | { |
xorjoep | 1:24714b45cd1b | 205 | /* Perform the multiply-accumulate */ |
xorjoep | 1:24714b45cd1b | 206 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
xorjoep | 1:24714b45cd1b | 207 | *pb++ = (q15_t) __SSAT((coef), 16); |
xorjoep | 1:24714b45cd1b | 208 | |
xorjoep | 1:24714b45cd1b | 209 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 210 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 211 | } |
xorjoep | 1:24714b45cd1b | 212 | |
xorjoep | 1:24714b45cd1b | 213 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 214 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 215 | |
xorjoep | 1:24714b45cd1b | 216 | } |
xorjoep | 1:24714b45cd1b | 217 | |
xorjoep | 1:24714b45cd1b | 218 | /* Processing is complete. Now copy the last numTaps - 1 samples to the |
xorjoep | 1:24714b45cd1b | 219 | satrt of the state buffer. This prepares the state buffer for the |
xorjoep | 1:24714b45cd1b | 220 | next function call. */ |
xorjoep | 1:24714b45cd1b | 221 | |
xorjoep | 1:24714b45cd1b | 222 | /* Points to the start of the pState buffer */ |
xorjoep | 1:24714b45cd1b | 223 | pStateCurnt = S->pState; |
xorjoep | 1:24714b45cd1b | 224 | |
xorjoep | 1:24714b45cd1b | 225 | /* Calculation of count for copying integer writes */ |
xorjoep | 1:24714b45cd1b | 226 | tapCnt = (numTaps - 1U) >> 2; |
xorjoep | 1:24714b45cd1b | 227 | |
xorjoep | 1:24714b45cd1b | 228 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 229 | { |
xorjoep | 1:24714b45cd1b | 230 | |
xorjoep | 1:24714b45cd1b | 231 | #ifndef UNALIGNED_SUPPORT_DISABLE |
xorjoep | 1:24714b45cd1b | 232 | |
xorjoep | 1:24714b45cd1b | 233 | *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++; |
xorjoep | 1:24714b45cd1b | 234 | *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++; |
xorjoep | 1:24714b45cd1b | 235 | #else |
xorjoep | 1:24714b45cd1b | 236 | *pStateCurnt++ = *pState++; |
xorjoep | 1:24714b45cd1b | 237 | *pStateCurnt++ = *pState++; |
xorjoep | 1:24714b45cd1b | 238 | *pStateCurnt++ = *pState++; |
xorjoep | 1:24714b45cd1b | 239 | *pStateCurnt++ = *pState++; |
xorjoep | 1:24714b45cd1b | 240 | #endif |
xorjoep | 1:24714b45cd1b | 241 | |
xorjoep | 1:24714b45cd1b | 242 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 243 | |
xorjoep | 1:24714b45cd1b | 244 | } |
xorjoep | 1:24714b45cd1b | 245 | |
xorjoep | 1:24714b45cd1b | 246 | /* Calculation of count for remaining q15_t data */ |
xorjoep | 1:24714b45cd1b | 247 | tapCnt = (numTaps - 1U) % 0x4U; |
xorjoep | 1:24714b45cd1b | 248 | |
xorjoep | 1:24714b45cd1b | 249 | /* copy data */ |
xorjoep | 1:24714b45cd1b | 250 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 251 | { |
xorjoep | 1:24714b45cd1b | 252 | *pStateCurnt++ = *pState++; |
xorjoep | 1:24714b45cd1b | 253 | |
xorjoep | 1:24714b45cd1b | 254 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 255 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 256 | } |
xorjoep | 1:24714b45cd1b | 257 | |
xorjoep | 1:24714b45cd1b | 258 | #else |
xorjoep | 1:24714b45cd1b | 259 | |
xorjoep | 1:24714b45cd1b | 260 | /* Run the below code for Cortex-M0 */ |
xorjoep | 1:24714b45cd1b | 261 | |
xorjoep | 1:24714b45cd1b | 262 | /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ |
xorjoep | 1:24714b45cd1b | 263 | /* pStateCurnt points to the location where the new input data should be written */ |
xorjoep | 1:24714b45cd1b | 264 | pStateCurnt = &(S->pState[(numTaps - 1U)]); |
xorjoep | 1:24714b45cd1b | 265 | |
xorjoep | 1:24714b45cd1b | 266 | /* Loop over blockSize number of values */ |
xorjoep | 1:24714b45cd1b | 267 | blkCnt = blockSize; |
xorjoep | 1:24714b45cd1b | 268 | |
xorjoep | 1:24714b45cd1b | 269 | while (blkCnt > 0U) |
xorjoep | 1:24714b45cd1b | 270 | { |
xorjoep | 1:24714b45cd1b | 271 | /* Copy the new input sample into the state buffer */ |
xorjoep | 1:24714b45cd1b | 272 | *pStateCurnt++ = *pSrc++; |
xorjoep | 1:24714b45cd1b | 273 | |
xorjoep | 1:24714b45cd1b | 274 | /* Initialize pState pointer */ |
xorjoep | 1:24714b45cd1b | 275 | px = pState; |
xorjoep | 1:24714b45cd1b | 276 | |
xorjoep | 1:24714b45cd1b | 277 | /* Initialize pCoeffs pointer */ |
xorjoep | 1:24714b45cd1b | 278 | pb = pCoeffs; |
xorjoep | 1:24714b45cd1b | 279 | |
xorjoep | 1:24714b45cd1b | 280 | /* Set the accumulator to zero */ |
xorjoep | 1:24714b45cd1b | 281 | acc = 0; |
xorjoep | 1:24714b45cd1b | 282 | |
xorjoep | 1:24714b45cd1b | 283 | /* Loop over numTaps number of values */ |
xorjoep | 1:24714b45cd1b | 284 | tapCnt = numTaps; |
xorjoep | 1:24714b45cd1b | 285 | |
xorjoep | 1:24714b45cd1b | 286 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 287 | { |
xorjoep | 1:24714b45cd1b | 288 | /* Perform the multiply-accumulate */ |
xorjoep | 1:24714b45cd1b | 289 | acc += (q63_t) ((q31_t) (*px++) * (*pb++)); |
xorjoep | 1:24714b45cd1b | 290 | |
xorjoep | 1:24714b45cd1b | 291 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 292 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 293 | } |
xorjoep | 1:24714b45cd1b | 294 | |
xorjoep | 1:24714b45cd1b | 295 | /* Calc lower part of acc */ |
xorjoep | 1:24714b45cd1b | 296 | acc_l = acc & 0xffffffff; |
xorjoep | 1:24714b45cd1b | 297 | |
xorjoep | 1:24714b45cd1b | 298 | /* Calc upper part of acc */ |
xorjoep | 1:24714b45cd1b | 299 | acc_h = (acc >> 32) & 0xffffffff; |
xorjoep | 1:24714b45cd1b | 300 | |
xorjoep | 1:24714b45cd1b | 301 | /* Apply shift for lower part of acc and upper part of acc */ |
xorjoep | 1:24714b45cd1b | 302 | acc = (uint32_t) acc_l >> lShift | acc_h << uShift; |
xorjoep | 1:24714b45cd1b | 303 | |
xorjoep | 1:24714b45cd1b | 304 | /* Converting the result to 1.15 format and saturate the output */ |
xorjoep | 1:24714b45cd1b | 305 | acc = __SSAT(acc, 16); |
xorjoep | 1:24714b45cd1b | 306 | |
xorjoep | 1:24714b45cd1b | 307 | /* Store the result from accumulator into the destination buffer. */ |
xorjoep | 1:24714b45cd1b | 308 | *pOut++ = (q15_t) acc; |
xorjoep | 1:24714b45cd1b | 309 | |
xorjoep | 1:24714b45cd1b | 310 | /* Compute and store error */ |
xorjoep | 1:24714b45cd1b | 311 | e = *pRef++ - (q15_t) acc; |
xorjoep | 1:24714b45cd1b | 312 | |
xorjoep | 1:24714b45cd1b | 313 | *pErr++ = (q15_t) e; |
xorjoep | 1:24714b45cd1b | 314 | |
xorjoep | 1:24714b45cd1b | 315 | /* Compute alpha i.e. intermediate constant for taps update */ |
xorjoep | 1:24714b45cd1b | 316 | alpha = (q15_t) (((q31_t) e * (mu)) >> 15); |
xorjoep | 1:24714b45cd1b | 317 | |
xorjoep | 1:24714b45cd1b | 318 | /* Initialize pState pointer */ |
xorjoep | 1:24714b45cd1b | 319 | /* Advance state pointer by 1 for the next sample */ |
xorjoep | 1:24714b45cd1b | 320 | px = pState++; |
xorjoep | 1:24714b45cd1b | 321 | |
xorjoep | 1:24714b45cd1b | 322 | /* Initialize pCoeffs pointer */ |
xorjoep | 1:24714b45cd1b | 323 | pb = pCoeffs; |
xorjoep | 1:24714b45cd1b | 324 | |
xorjoep | 1:24714b45cd1b | 325 | /* Loop over numTaps number of values */ |
xorjoep | 1:24714b45cd1b | 326 | tapCnt = numTaps; |
xorjoep | 1:24714b45cd1b | 327 | |
xorjoep | 1:24714b45cd1b | 328 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 329 | { |
xorjoep | 1:24714b45cd1b | 330 | /* Perform the multiply-accumulate */ |
xorjoep | 1:24714b45cd1b | 331 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
xorjoep | 1:24714b45cd1b | 332 | *pb++ = (q15_t) __SSAT((coef), 16); |
xorjoep | 1:24714b45cd1b | 333 | |
xorjoep | 1:24714b45cd1b | 334 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 335 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 336 | } |
xorjoep | 1:24714b45cd1b | 337 | |
xorjoep | 1:24714b45cd1b | 338 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 339 | blkCnt--; |
xorjoep | 1:24714b45cd1b | 340 | |
xorjoep | 1:24714b45cd1b | 341 | } |
xorjoep | 1:24714b45cd1b | 342 | |
xorjoep | 1:24714b45cd1b | 343 | /* Processing is complete. Now copy the last numTaps - 1 samples to the |
xorjoep | 1:24714b45cd1b | 344 | start of the state buffer. This prepares the state buffer for the |
xorjoep | 1:24714b45cd1b | 345 | next function call. */ |
xorjoep | 1:24714b45cd1b | 346 | |
xorjoep | 1:24714b45cd1b | 347 | /* Points to the start of the pState buffer */ |
xorjoep | 1:24714b45cd1b | 348 | pStateCurnt = S->pState; |
xorjoep | 1:24714b45cd1b | 349 | |
xorjoep | 1:24714b45cd1b | 350 | /* Copy (numTaps - 1U) samples */ |
xorjoep | 1:24714b45cd1b | 351 | tapCnt = (numTaps - 1U); |
xorjoep | 1:24714b45cd1b | 352 | |
xorjoep | 1:24714b45cd1b | 353 | /* Copy the data */ |
xorjoep | 1:24714b45cd1b | 354 | while (tapCnt > 0U) |
xorjoep | 1:24714b45cd1b | 355 | { |
xorjoep | 1:24714b45cd1b | 356 | *pStateCurnt++ = *pState++; |
xorjoep | 1:24714b45cd1b | 357 | |
xorjoep | 1:24714b45cd1b | 358 | /* Decrement the loop counter */ |
xorjoep | 1:24714b45cd1b | 359 | tapCnt--; |
xorjoep | 1:24714b45cd1b | 360 | } |
xorjoep | 1:24714b45cd1b | 361 | |
xorjoep | 1:24714b45cd1b | 362 | #endif /* #if defined (ARM_MATH_DSP) */ |
xorjoep | 1:24714b45cd1b | 363 | |
xorjoep | 1:24714b45cd1b | 364 | } |
xorjoep | 1:24714b45cd1b | 365 | |
xorjoep | 1:24714b45cd1b | 366 | /** |
xorjoep | 1:24714b45cd1b | 367 | * @} end of LMS group |
xorjoep | 1:24714b45cd1b | 368 | */ |