CMSIS DSP library

Dependents:   performance_timer Surfboard_ gps2rtty Capstone ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Committer:
mbed_official
Date:
Fri Nov 20 08:45:18 2015 +0000
Revision:
5:3762170b6d4d
Parent:
3:7a284390b0ce
Synchronized with git revision 2eb940b9a73af188d3004a2575fdfbb05febe62b

Full URL: https://github.com/mbedmicro/mbed/commit/2eb940b9a73af188d3004a2575fdfbb05febe62b/

Added option to build rpc library. closes #1426

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
mbed_official 5:3762170b6d4d 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
mbed_official 5:3762170b6d4d 4 * $Date: 19. March 2015
mbed_official 5:3762170b6d4d 5 * $Revision: V.1.4.5
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_lms_q31.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Processing function for the Q31 LMS filter.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
mbed_official 3:7a284390b0ce 14 * Redistribution and use in source and binary forms, with or without
mbed_official 3:7a284390b0ce 15 * modification, are permitted provided that the following conditions
mbed_official 3:7a284390b0ce 16 * are met:
mbed_official 3:7a284390b0ce 17 * - Redistributions of source code must retain the above copyright
mbed_official 3:7a284390b0ce 18 * notice, this list of conditions and the following disclaimer.
mbed_official 3:7a284390b0ce 19 * - Redistributions in binary form must reproduce the above copyright
mbed_official 3:7a284390b0ce 20 * notice, this list of conditions and the following disclaimer in
mbed_official 3:7a284390b0ce 21 * the documentation and/or other materials provided with the
mbed_official 3:7a284390b0ce 22 * distribution.
mbed_official 3:7a284390b0ce 23 * - Neither the name of ARM LIMITED nor the names of its contributors
mbed_official 3:7a284390b0ce 24 * may be used to endorse or promote products derived from this
mbed_official 3:7a284390b0ce 25 * software without specific prior written permission.
mbed_official 3:7a284390b0ce 26 *
mbed_official 3:7a284390b0ce 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
mbed_official 3:7a284390b0ce 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
mbed_official 3:7a284390b0ce 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
mbed_official 3:7a284390b0ce 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
mbed_official 3:7a284390b0ce 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
mbed_official 3:7a284390b0ce 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
mbed_official 3:7a284390b0ce 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 3:7a284390b0ce 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 3:7a284390b0ce 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
mbed_official 3:7a284390b0ce 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 3:7a284390b0ce 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 3:7a284390b0ce 38 * POSSIBILITY OF SUCH DAMAGE.
emilmont 1:fdd22bb7aa52 39 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 40
emilmont 1:fdd22bb7aa52 41 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 42 /**
emilmont 1:fdd22bb7aa52 43 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 44 */
emilmont 1:fdd22bb7aa52 45
emilmont 1:fdd22bb7aa52 46 /**
emilmont 1:fdd22bb7aa52 47 * @addtogroup LMS
emilmont 1:fdd22bb7aa52 48 * @{
emilmont 1:fdd22bb7aa52 49 */
emilmont 1:fdd22bb7aa52 50
emilmont 1:fdd22bb7aa52 51 /**
emilmont 1:fdd22bb7aa52 52 * @brief Processing function for Q31 LMS filter.
emilmont 1:fdd22bb7aa52 53 * @param[in] *S points to an instance of the Q15 LMS filter structure.
emilmont 1:fdd22bb7aa52 54 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 55 * @param[in] *pRef points to the block of reference data.
emilmont 1:fdd22bb7aa52 56 * @param[out] *pOut points to the block of output data.
emilmont 1:fdd22bb7aa52 57 * @param[out] *pErr points to the block of error data.
emilmont 1:fdd22bb7aa52 58 * @param[in] blockSize number of samples to process.
emilmont 1:fdd22bb7aa52 59 * @return none.
emilmont 1:fdd22bb7aa52 60 *
emilmont 1:fdd22bb7aa52 61 * \par Scaling and Overflow Behavior:
emilmont 1:fdd22bb7aa52 62 * The function is implemented using an internal 64-bit accumulator.
emilmont 1:fdd22bb7aa52 63 * The accumulator has a 2.62 format and maintains full precision of the intermediate
emilmont 1:fdd22bb7aa52 64 * multiplication results but provides only a single guard bit.
emilmont 1:fdd22bb7aa52 65 * Thus, if the accumulator result overflows it wraps around rather than clips.
emilmont 1:fdd22bb7aa52 66 * In order to avoid overflows completely the input signal must be scaled down by
emilmont 1:fdd22bb7aa52 67 * log2(numTaps) bits.
emilmont 1:fdd22bb7aa52 68 * The reference signal should not be scaled down.
emilmont 1:fdd22bb7aa52 69 * After all multiply-accumulates are performed, the 2.62 accumulator is shifted
emilmont 1:fdd22bb7aa52 70 * and saturated to 1.31 format to yield the final result.
emilmont 1:fdd22bb7aa52 71 * The output signal and error signal are in 1.31 format.
emilmont 1:fdd22bb7aa52 72 *
emilmont 1:fdd22bb7aa52 73 * \par
emilmont 2:da51fb522205 74 * In this filter, filter coefficients are updated for each sample and the updation of filter cofficients are saturted.
emilmont 1:fdd22bb7aa52 75 */
emilmont 1:fdd22bb7aa52 76
emilmont 1:fdd22bb7aa52 77 void arm_lms_q31(
emilmont 1:fdd22bb7aa52 78 const arm_lms_instance_q31 * S,
emilmont 1:fdd22bb7aa52 79 q31_t * pSrc,
emilmont 1:fdd22bb7aa52 80 q31_t * pRef,
emilmont 1:fdd22bb7aa52 81 q31_t * pOut,
emilmont 1:fdd22bb7aa52 82 q31_t * pErr,
emilmont 1:fdd22bb7aa52 83 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 84 {
emilmont 1:fdd22bb7aa52 85 q31_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 86 uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */
emilmont 1:fdd22bb7aa52 87 q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 88 q31_t *pStateCurnt; /* Points to the current sample of the state */
emilmont 1:fdd22bb7aa52 89 q31_t mu = S->mu; /* Adaptive factor */
emilmont 1:fdd22bb7aa52 90 q31_t *px; /* Temporary pointer for state */
emilmont 1:fdd22bb7aa52 91 q31_t *pb; /* Temporary pointer for coefficient buffer */
emilmont 1:fdd22bb7aa52 92 uint32_t tapCnt, blkCnt; /* Loop counters */
emilmont 1:fdd22bb7aa52 93 q63_t acc; /* Accumulator */
emilmont 1:fdd22bb7aa52 94 q31_t e = 0; /* error of data sample */
emilmont 1:fdd22bb7aa52 95 q31_t alpha; /* Intermediate constant for taps update */
emilmont 1:fdd22bb7aa52 96 q31_t coef; /* Temporary variable for coef */
emilmont 1:fdd22bb7aa52 97 q31_t acc_l, acc_h; /* temporary input */
emilmont 1:fdd22bb7aa52 98 uint32_t uShift = ((uint32_t) S->postShift + 1u);
emilmont 1:fdd22bb7aa52 99 uint32_t lShift = 32u - uShift; /* Shift to be applied to the output */
emilmont 1:fdd22bb7aa52 100
emilmont 1:fdd22bb7aa52 101 /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */
emilmont 1:fdd22bb7aa52 102 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 103 pStateCurnt = &(S->pState[(numTaps - 1u)]);
emilmont 1:fdd22bb7aa52 104
emilmont 1:fdd22bb7aa52 105 /* Initializing blkCnt with blockSize */
emilmont 1:fdd22bb7aa52 106 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 107
emilmont 1:fdd22bb7aa52 108
mbed_official 3:7a284390b0ce 109 #ifndef ARM_MATH_CM0_FAMILY
emilmont 1:fdd22bb7aa52 110
emilmont 1:fdd22bb7aa52 111 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 112
emilmont 1:fdd22bb7aa52 113 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 114 {
emilmont 1:fdd22bb7aa52 115 /* Copy the new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 116 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 117
emilmont 1:fdd22bb7aa52 118 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 119 px = pState;
emilmont 1:fdd22bb7aa52 120
emilmont 1:fdd22bb7aa52 121 /* Initialize coefficient pointer */
emilmont 1:fdd22bb7aa52 122 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 123
emilmont 1:fdd22bb7aa52 124 /* Set the accumulator to zero */
emilmont 1:fdd22bb7aa52 125 acc = 0;
emilmont 1:fdd22bb7aa52 126
emilmont 1:fdd22bb7aa52 127 /* Loop unrolling. Process 4 taps at a time. */
emilmont 1:fdd22bb7aa52 128 tapCnt = numTaps >> 2;
emilmont 1:fdd22bb7aa52 129
emilmont 1:fdd22bb7aa52 130 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 131 {
emilmont 1:fdd22bb7aa52 132 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 133 /* acc += b[N] * x[n-N] */
emilmont 1:fdd22bb7aa52 134 acc += ((q63_t) (*px++)) * (*pb++);
emilmont 1:fdd22bb7aa52 135
emilmont 1:fdd22bb7aa52 136 /* acc += b[N-1] * x[n-N-1] */
emilmont 1:fdd22bb7aa52 137 acc += ((q63_t) (*px++)) * (*pb++);
emilmont 1:fdd22bb7aa52 138
emilmont 1:fdd22bb7aa52 139 /* acc += b[N-2] * x[n-N-2] */
emilmont 1:fdd22bb7aa52 140 acc += ((q63_t) (*px++)) * (*pb++);
emilmont 1:fdd22bb7aa52 141
emilmont 1:fdd22bb7aa52 142 /* acc += b[N-3] * x[n-N-3] */
emilmont 1:fdd22bb7aa52 143 acc += ((q63_t) (*px++)) * (*pb++);
emilmont 1:fdd22bb7aa52 144
emilmont 1:fdd22bb7aa52 145 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 146 tapCnt--;
emilmont 1:fdd22bb7aa52 147 }
emilmont 1:fdd22bb7aa52 148
emilmont 1:fdd22bb7aa52 149 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 150 tapCnt = numTaps % 0x4u;
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 153 {
emilmont 1:fdd22bb7aa52 154 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 155 acc += ((q63_t) (*px++)) * (*pb++);
emilmont 1:fdd22bb7aa52 156
emilmont 1:fdd22bb7aa52 157 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 158 tapCnt--;
emilmont 1:fdd22bb7aa52 159 }
emilmont 1:fdd22bb7aa52 160
emilmont 1:fdd22bb7aa52 161 /* Converting the result to 1.31 format */
emilmont 1:fdd22bb7aa52 162 /* Calc lower part of acc */
emilmont 1:fdd22bb7aa52 163 acc_l = acc & 0xffffffff;
emilmont 1:fdd22bb7aa52 164
emilmont 1:fdd22bb7aa52 165 /* Calc upper part of acc */
emilmont 1:fdd22bb7aa52 166 acc_h = (acc >> 32) & 0xffffffff;
emilmont 1:fdd22bb7aa52 167
emilmont 1:fdd22bb7aa52 168 acc = (uint32_t) acc_l >> lShift | acc_h << uShift;
emilmont 1:fdd22bb7aa52 169
emilmont 1:fdd22bb7aa52 170 /* Store the result from accumulator into the destination buffer. */
emilmont 1:fdd22bb7aa52 171 *pOut++ = (q31_t) acc;
emilmont 1:fdd22bb7aa52 172
emilmont 1:fdd22bb7aa52 173 /* Compute and store error */
emilmont 1:fdd22bb7aa52 174 e = *pRef++ - (q31_t) acc;
emilmont 1:fdd22bb7aa52 175
emilmont 1:fdd22bb7aa52 176 *pErr++ = (q31_t) e;
emilmont 1:fdd22bb7aa52 177
emilmont 1:fdd22bb7aa52 178 /* Compute alpha i.e. intermediate constant for taps update */
emilmont 1:fdd22bb7aa52 179 alpha = (q31_t) (((q63_t) e * mu) >> 31);
emilmont 1:fdd22bb7aa52 180
emilmont 1:fdd22bb7aa52 181 /* Initialize state pointer */
emilmont 1:fdd22bb7aa52 182 /* Advance state pointer by 1 for the next sample */
emilmont 1:fdd22bb7aa52 183 px = pState++;
emilmont 1:fdd22bb7aa52 184
emilmont 1:fdd22bb7aa52 185 /* Initialize coefficient pointer */
emilmont 1:fdd22bb7aa52 186 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 /* Loop unrolling. Process 4 taps at a time. */
emilmont 1:fdd22bb7aa52 189 tapCnt = numTaps >> 2;
emilmont 1:fdd22bb7aa52 190
emilmont 1:fdd22bb7aa52 191 /* Update filter coefficients */
emilmont 1:fdd22bb7aa52 192 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 193 {
emilmont 1:fdd22bb7aa52 194 /* coef is in 2.30 format */
emilmont 1:fdd22bb7aa52 195 coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32));
emilmont 1:fdd22bb7aa52 196 /* get coef in 1.31 format by left shifting */
emilmont 1:fdd22bb7aa52 197 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emilmont 1:fdd22bb7aa52 198 /* update coefficient buffer to next coefficient */
emilmont 1:fdd22bb7aa52 199 pb++;
emilmont 1:fdd22bb7aa52 200
emilmont 1:fdd22bb7aa52 201 coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32));
emilmont 1:fdd22bb7aa52 202 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emilmont 1:fdd22bb7aa52 203 pb++;
emilmont 1:fdd22bb7aa52 204
emilmont 1:fdd22bb7aa52 205 coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32));
emilmont 1:fdd22bb7aa52 206 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emilmont 1:fdd22bb7aa52 207 pb++;
emilmont 1:fdd22bb7aa52 208
emilmont 1:fdd22bb7aa52 209 coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32));
emilmont 1:fdd22bb7aa52 210 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emilmont 1:fdd22bb7aa52 211 pb++;
emilmont 1:fdd22bb7aa52 212
emilmont 1:fdd22bb7aa52 213 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 214 tapCnt--;
emilmont 1:fdd22bb7aa52 215 }
emilmont 1:fdd22bb7aa52 216
emilmont 1:fdd22bb7aa52 217 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 218 tapCnt = numTaps % 0x4u;
emilmont 1:fdd22bb7aa52 219
emilmont 1:fdd22bb7aa52 220 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 221 {
emilmont 1:fdd22bb7aa52 222 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 223 coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32));
emilmont 1:fdd22bb7aa52 224 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emilmont 1:fdd22bb7aa52 225 pb++;
emilmont 1:fdd22bb7aa52 226
emilmont 1:fdd22bb7aa52 227 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 228 tapCnt--;
emilmont 1:fdd22bb7aa52 229 }
emilmont 1:fdd22bb7aa52 230
emilmont 1:fdd22bb7aa52 231 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 232 blkCnt--;
emilmont 1:fdd22bb7aa52 233 }
emilmont 1:fdd22bb7aa52 234
emilmont 1:fdd22bb7aa52 235 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emilmont 1:fdd22bb7aa52 236 satrt of the state buffer. This prepares the state buffer for the
emilmont 1:fdd22bb7aa52 237 next function call. */
emilmont 1:fdd22bb7aa52 238
emilmont 1:fdd22bb7aa52 239 /* Points to the start of the pState buffer */
emilmont 1:fdd22bb7aa52 240 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 241
emilmont 1:fdd22bb7aa52 242 /* Loop unrolling for (numTaps - 1u) samples copy */
emilmont 1:fdd22bb7aa52 243 tapCnt = (numTaps - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 244
emilmont 1:fdd22bb7aa52 245 /* copy data */
emilmont 1:fdd22bb7aa52 246 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 247 {
emilmont 1:fdd22bb7aa52 248 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 249 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 250 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 251 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 252
emilmont 1:fdd22bb7aa52 253 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 254 tapCnt--;
emilmont 1:fdd22bb7aa52 255 }
emilmont 1:fdd22bb7aa52 256
emilmont 1:fdd22bb7aa52 257 /* Calculate remaining number of copies */
emilmont 1:fdd22bb7aa52 258 tapCnt = (numTaps - 1u) % 0x4u;
emilmont 1:fdd22bb7aa52 259
emilmont 1:fdd22bb7aa52 260 /* Copy the remaining q31_t data */
emilmont 1:fdd22bb7aa52 261 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 262 {
emilmont 1:fdd22bb7aa52 263 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 264
emilmont 1:fdd22bb7aa52 265 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 266 tapCnt--;
emilmont 1:fdd22bb7aa52 267 }
emilmont 1:fdd22bb7aa52 268
emilmont 1:fdd22bb7aa52 269 #else
emilmont 1:fdd22bb7aa52 270
emilmont 1:fdd22bb7aa52 271 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 272
emilmont 1:fdd22bb7aa52 273 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 274 {
emilmont 1:fdd22bb7aa52 275 /* Copy the new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 276 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 277
emilmont 1:fdd22bb7aa52 278 /* Initialize pState pointer */
emilmont 1:fdd22bb7aa52 279 px = pState;
emilmont 1:fdd22bb7aa52 280
emilmont 1:fdd22bb7aa52 281 /* Initialize pCoeffs pointer */
emilmont 1:fdd22bb7aa52 282 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 283
emilmont 1:fdd22bb7aa52 284 /* Set the accumulator to zero */
emilmont 1:fdd22bb7aa52 285 acc = 0;
emilmont 1:fdd22bb7aa52 286
emilmont 1:fdd22bb7aa52 287 /* Loop over numTaps number of values */
emilmont 1:fdd22bb7aa52 288 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 289
emilmont 1:fdd22bb7aa52 290 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 291 {
emilmont 1:fdd22bb7aa52 292 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 293 acc += ((q63_t) (*px++)) * (*pb++);
emilmont 1:fdd22bb7aa52 294
emilmont 1:fdd22bb7aa52 295 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 296 tapCnt--;
emilmont 1:fdd22bb7aa52 297 }
emilmont 1:fdd22bb7aa52 298
emilmont 1:fdd22bb7aa52 299 /* Converting the result to 1.31 format */
emilmont 1:fdd22bb7aa52 300 /* Store the result from accumulator into the destination buffer. */
emilmont 1:fdd22bb7aa52 301 /* Calc lower part of acc */
emilmont 1:fdd22bb7aa52 302 acc_l = acc & 0xffffffff;
emilmont 1:fdd22bb7aa52 303
emilmont 1:fdd22bb7aa52 304 /* Calc upper part of acc */
emilmont 1:fdd22bb7aa52 305 acc_h = (acc >> 32) & 0xffffffff;
emilmont 1:fdd22bb7aa52 306
emilmont 1:fdd22bb7aa52 307 acc = (uint32_t) acc_l >> lShift | acc_h << uShift;
emilmont 1:fdd22bb7aa52 308
emilmont 1:fdd22bb7aa52 309 *pOut++ = (q31_t) acc;
emilmont 1:fdd22bb7aa52 310
emilmont 1:fdd22bb7aa52 311 /* Compute and store error */
emilmont 1:fdd22bb7aa52 312 e = *pRef++ - (q31_t) acc;
emilmont 1:fdd22bb7aa52 313
emilmont 1:fdd22bb7aa52 314 *pErr++ = (q31_t) e;
emilmont 1:fdd22bb7aa52 315
emilmont 1:fdd22bb7aa52 316 /* Weighting factor for the LMS version */
emilmont 1:fdd22bb7aa52 317 alpha = (q31_t) (((q63_t) e * mu) >> 31);
emilmont 1:fdd22bb7aa52 318
emilmont 1:fdd22bb7aa52 319 /* Initialize pState pointer */
emilmont 1:fdd22bb7aa52 320 /* Advance state pointer by 1 for the next sample */
emilmont 1:fdd22bb7aa52 321 px = pState++;
emilmont 1:fdd22bb7aa52 322
emilmont 1:fdd22bb7aa52 323 /* Initialize pCoeffs pointer */
emilmont 1:fdd22bb7aa52 324 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 /* Loop over numTaps number of values */
emilmont 1:fdd22bb7aa52 327 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 328
emilmont 1:fdd22bb7aa52 329 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 330 {
emilmont 1:fdd22bb7aa52 331 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 332 coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32));
mbed_official 5:3762170b6d4d 333 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emilmont 1:fdd22bb7aa52 334 pb++;
emilmont 1:fdd22bb7aa52 335
emilmont 1:fdd22bb7aa52 336 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 337 tapCnt--;
emilmont 1:fdd22bb7aa52 338 }
emilmont 1:fdd22bb7aa52 339
emilmont 1:fdd22bb7aa52 340 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 341 blkCnt--;
emilmont 1:fdd22bb7aa52 342 }
emilmont 1:fdd22bb7aa52 343
emilmont 1:fdd22bb7aa52 344 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emilmont 1:fdd22bb7aa52 345 start of the state buffer. This prepares the state buffer for the
emilmont 1:fdd22bb7aa52 346 next function call. */
emilmont 1:fdd22bb7aa52 347
emilmont 1:fdd22bb7aa52 348 /* Points to the start of the pState buffer */
emilmont 1:fdd22bb7aa52 349 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 350
emilmont 1:fdd22bb7aa52 351 /* Copy (numTaps - 1u) samples */
emilmont 1:fdd22bb7aa52 352 tapCnt = (numTaps - 1u);
emilmont 1:fdd22bb7aa52 353
emilmont 1:fdd22bb7aa52 354 /* Copy the data */
emilmont 1:fdd22bb7aa52 355 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 356 {
emilmont 1:fdd22bb7aa52 357 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 358
emilmont 1:fdd22bb7aa52 359 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 360 tapCnt--;
emilmont 1:fdd22bb7aa52 361 }
emilmont 1:fdd22bb7aa52 362
mbed_official 3:7a284390b0ce 363 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 364
emilmont 1:fdd22bb7aa52 365 }
emilmont 1:fdd22bb7aa52 366
emilmont 1:fdd22bb7aa52 367 /**
emilmont 1:fdd22bb7aa52 368 * @} end of LMS group
emilmont 1:fdd22bb7aa52 369 */