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:
emilmont
Date:
Thu May 30 17:10:11 2013 +0100
Revision:
2:da51fb522205
Parent:
1:fdd22bb7aa52
Child:
3:7a284390b0ce
Keep "cmsis-dsp" module in synch with its source

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
emilmont 1:fdd22bb7aa52 2 * Copyright (C) 2010 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
emilmont 1:fdd22bb7aa52 4 * $Date: 15. February 2012
emilmont 2:da51fb522205 5 * $Revision: V1.1.0
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_lms_f32.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Processing function for the floating-point LMS filter.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
emilmont 1:fdd22bb7aa52 14 * Version 1.1.0 2012/02/15
emilmont 1:fdd22bb7aa52 15 * Updated with more optimizations, bug fixes and minor API changes.
emilmont 1:fdd22bb7aa52 16 *
emilmont 1:fdd22bb7aa52 17 * Version 1.0.10 2011/7/15
emilmont 1:fdd22bb7aa52 18 * Big Endian support added and Merged M0 and M3/M4 Source code.
emilmont 1:fdd22bb7aa52 19 *
emilmont 1:fdd22bb7aa52 20 * Version 1.0.3 2010/11/29
emilmont 1:fdd22bb7aa52 21 * Re-organized the CMSIS folders and updated documentation.
emilmont 1:fdd22bb7aa52 22 *
emilmont 1:fdd22bb7aa52 23 * Version 1.0.2 2010/11/11
emilmont 1:fdd22bb7aa52 24 * Documentation updated.
emilmont 1:fdd22bb7aa52 25 *
emilmont 1:fdd22bb7aa52 26 * Version 1.0.1 2010/10/05
emilmont 1:fdd22bb7aa52 27 * Production release and review comments incorporated.
emilmont 1:fdd22bb7aa52 28 *
emilmont 1:fdd22bb7aa52 29 * Version 1.0.0 2010/09/20
emilmont 1:fdd22bb7aa52 30 * Production release and review comments incorporated
emilmont 1:fdd22bb7aa52 31 *
emilmont 1:fdd22bb7aa52 32 * Version 0.0.7 2010/06/10
emilmont 1:fdd22bb7aa52 33 * Misra-C changes done
emilmont 1:fdd22bb7aa52 34 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 35
emilmont 1:fdd22bb7aa52 36 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 37
emilmont 1:fdd22bb7aa52 38 /**
emilmont 1:fdd22bb7aa52 39 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 40 */
emilmont 1:fdd22bb7aa52 41
emilmont 1:fdd22bb7aa52 42 /**
emilmont 1:fdd22bb7aa52 43 * @defgroup LMS Least Mean Square (LMS) Filters
emilmont 1:fdd22bb7aa52 44 *
emilmont 1:fdd22bb7aa52 45 * LMS filters are a class of adaptive filters that are able to "learn" an unknown transfer functions.
emilmont 1:fdd22bb7aa52 46 * LMS filters use a gradient descent method in which the filter coefficients are updated based on the instantaneous error signal.
emilmont 1:fdd22bb7aa52 47 * Adaptive filters are often used in communication systems, equalizers, and noise removal.
emilmont 1:fdd22bb7aa52 48 * The CMSIS DSP Library contains LMS filter functions that operate on Q15, Q31, and floating-point data types.
emilmont 1:fdd22bb7aa52 49 * The library also contains normalized LMS filters in which the filter coefficient adaptation is indepedent of the level of the input signal.
emilmont 1:fdd22bb7aa52 50 *
emilmont 1:fdd22bb7aa52 51 * An LMS filter consists of two components as shown below.
emilmont 1:fdd22bb7aa52 52 * The first component is a standard transversal or FIR filter.
emilmont 1:fdd22bb7aa52 53 * The second component is a coefficient update mechanism.
emilmont 1:fdd22bb7aa52 54 * The LMS filter has two input signals.
emilmont 1:fdd22bb7aa52 55 * The "input" feeds the FIR filter while the "reference input" corresponds to the desired output of the FIR filter.
emilmont 1:fdd22bb7aa52 56 * That is, the FIR filter coefficients are updated so that the output of the FIR filter matches the reference input.
emilmont 1:fdd22bb7aa52 57 * The filter coefficient update mechanism is based on the difference between the FIR filter output and the reference input.
emilmont 1:fdd22bb7aa52 58 * This "error signal" tends towards zero as the filter adapts.
emilmont 1:fdd22bb7aa52 59 * The LMS processing functions accept the input and reference input signals and generate the filter output and error signal.
emilmont 1:fdd22bb7aa52 60 * \image html LMS.gif "Internal structure of the Least Mean Square filter"
emilmont 1:fdd22bb7aa52 61 *
emilmont 1:fdd22bb7aa52 62 * The functions operate on blocks of data and each call to the function processes
emilmont 1:fdd22bb7aa52 63 * <code>blockSize</code> samples through the filter.
emilmont 1:fdd22bb7aa52 64 * <code>pSrc</code> points to input signal, <code>pRef</code> points to reference signal,
emilmont 1:fdd22bb7aa52 65 * <code>pOut</code> points to output signal and <code>pErr</code> points to error signal.
emilmont 1:fdd22bb7aa52 66 * All arrays contain <code>blockSize</code> values.
emilmont 1:fdd22bb7aa52 67 *
emilmont 1:fdd22bb7aa52 68 * The functions operate on a block-by-block basis.
emilmont 1:fdd22bb7aa52 69 * Internally, the filter coefficients <code>b[n]</code> are updated on a sample-by-sample basis.
emilmont 1:fdd22bb7aa52 70 * The convergence of the LMS filter is slower compared to the normalized LMS algorithm.
emilmont 1:fdd22bb7aa52 71 *
emilmont 1:fdd22bb7aa52 72 * \par Algorithm:
emilmont 1:fdd22bb7aa52 73 * The output signal <code>y[n]</code> is computed by a standard FIR filter:
emilmont 1:fdd22bb7aa52 74 * <pre>
emilmont 1:fdd22bb7aa52 75 * y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[numTaps-1] * x[n-numTaps+1]
emilmont 1:fdd22bb7aa52 76 * </pre>
emilmont 1:fdd22bb7aa52 77 *
emilmont 1:fdd22bb7aa52 78 * \par
emilmont 1:fdd22bb7aa52 79 * The error signal equals the difference between the reference signal <code>d[n]</code> and the filter output:
emilmont 1:fdd22bb7aa52 80 * <pre>
emilmont 1:fdd22bb7aa52 81 * e[n] = d[n] - y[n].
emilmont 1:fdd22bb7aa52 82 * </pre>
emilmont 1:fdd22bb7aa52 83 *
emilmont 1:fdd22bb7aa52 84 * \par
emilmont 1:fdd22bb7aa52 85 * After each sample of the error signal is computed, the filter coefficients <code>b[k]</code> are updated on a sample-by-sample basis:
emilmont 1:fdd22bb7aa52 86 * <pre>
emilmont 1:fdd22bb7aa52 87 * b[k] = b[k] + e[n] * mu * x[n-k], for k=0, 1, ..., numTaps-1
emilmont 1:fdd22bb7aa52 88 * </pre>
emilmont 1:fdd22bb7aa52 89 * where <code>mu</code> is the step size and controls the rate of coefficient convergence.
emilmont 1:fdd22bb7aa52 90 *\par
emilmont 1:fdd22bb7aa52 91 * In the APIs, <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>.
emilmont 1:fdd22bb7aa52 92 * Coefficients are stored in time reversed order.
emilmont 1:fdd22bb7aa52 93 * \par
emilmont 1:fdd22bb7aa52 94 * <pre>
emilmont 1:fdd22bb7aa52 95 * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
emilmont 1:fdd22bb7aa52 96 * </pre>
emilmont 1:fdd22bb7aa52 97 * \par
emilmont 1:fdd22bb7aa52 98 * <code>pState</code> points to a state array of size <code>numTaps + blockSize - 1</code>.
emilmont 1:fdd22bb7aa52 99 * Samples in the state buffer are stored in the order:
emilmont 1:fdd22bb7aa52 100 * \par
emilmont 1:fdd22bb7aa52 101 * <pre>
emilmont 1:fdd22bb7aa52 102 * {x[n-numTaps+1], x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2]....x[0], x[1], ..., x[blockSize-1]}
emilmont 1:fdd22bb7aa52 103 * </pre>
emilmont 1:fdd22bb7aa52 104 * \par
emilmont 1:fdd22bb7aa52 105 * Note that the length of the state buffer exceeds the length of the coefficient array by <code>blockSize-1</code> samples.
emilmont 1:fdd22bb7aa52 106 * The increased state buffer length allows circular addressing, which is traditionally used in FIR filters,
emilmont 1:fdd22bb7aa52 107 * to be avoided and yields a significant speed improvement.
emilmont 1:fdd22bb7aa52 108 * The state variables are updated after each block of data is processed.
emilmont 1:fdd22bb7aa52 109 * \par Instance Structure
emilmont 1:fdd22bb7aa52 110 * The coefficients and state variables for a filter are stored together in an instance data structure.
emilmont 1:fdd22bb7aa52 111 * A separate instance structure must be defined for each filter and
emilmont 1:fdd22bb7aa52 112 * coefficient and state arrays cannot be shared among instances.
emilmont 1:fdd22bb7aa52 113 * There are separate instance structure declarations for each of the 3 supported data types.
emilmont 1:fdd22bb7aa52 114 *
emilmont 1:fdd22bb7aa52 115 * \par Initialization Functions
emilmont 1:fdd22bb7aa52 116 * There is also an associated initialization function for each data type.
emilmont 1:fdd22bb7aa52 117 * The initialization function performs the following operations:
emilmont 1:fdd22bb7aa52 118 * - Sets the values of the internal structure fields.
emilmont 1:fdd22bb7aa52 119 * - Zeros out the values in the state buffer.
emilmont 1:fdd22bb7aa52 120 * \par
emilmont 1:fdd22bb7aa52 121 * Use of the initialization function is optional.
emilmont 1:fdd22bb7aa52 122 * However, if the initialization function is used, then the instance structure cannot be placed into a const data section.
emilmont 1:fdd22bb7aa52 123 * To place an instance structure into a const data section, the instance structure must be manually initialized.
emilmont 1:fdd22bb7aa52 124 * Set the values in the state buffer to zeros before static initialization.
emilmont 1:fdd22bb7aa52 125 * The code below statically initializes each of the 3 different data type filter instance structures
emilmont 1:fdd22bb7aa52 126 * <pre>
emilmont 1:fdd22bb7aa52 127 * arm_lms_instance_f32 S = {numTaps, pState, pCoeffs, mu};
emilmont 1:fdd22bb7aa52 128 * arm_lms_instance_q31 S = {numTaps, pState, pCoeffs, mu, postShift};
emilmont 1:fdd22bb7aa52 129 * arm_lms_instance_q15 S = {numTaps, pState, pCoeffs, mu, postShift};
emilmont 1:fdd22bb7aa52 130 * </pre>
emilmont 1:fdd22bb7aa52 131 * where <code>numTaps</code> is the number of filter coefficients in the filter; <code>pState</code> is the address of the state buffer;
emilmont 1:fdd22bb7aa52 132 * <code>pCoeffs</code> is the address of the coefficient buffer; <code>mu</code> is the step size parameter; and <code>postShift</code> is the shift applied to coefficients.
emilmont 1:fdd22bb7aa52 133 *
emilmont 1:fdd22bb7aa52 134 * \par Fixed-Point Behavior:
emilmont 1:fdd22bb7aa52 135 * Care must be taken when using the Q15 and Q31 versions of the LMS filter.
emilmont 1:fdd22bb7aa52 136 * The following issues must be considered:
emilmont 1:fdd22bb7aa52 137 * - Scaling of coefficients
emilmont 1:fdd22bb7aa52 138 * - Overflow and saturation
emilmont 1:fdd22bb7aa52 139 *
emilmont 1:fdd22bb7aa52 140 * \par Scaling of Coefficients:
emilmont 1:fdd22bb7aa52 141 * Filter coefficients are represented as fractional values and
emilmont 1:fdd22bb7aa52 142 * coefficients are restricted to lie in the range <code>[-1 +1)</code>.
emilmont 1:fdd22bb7aa52 143 * The fixed-point functions have an additional scaling parameter <code>postShift</code>.
emilmont 1:fdd22bb7aa52 144 * At the output of the filter's accumulator is a shift register which shifts the result by <code>postShift</code> bits.
emilmont 1:fdd22bb7aa52 145 * This essentially scales the filter coefficients by <code>2^postShift</code> and
emilmont 1:fdd22bb7aa52 146 * allows the filter coefficients to exceed the range <code>[+1 -1)</code>.
emilmont 1:fdd22bb7aa52 147 * The value of <code>postShift</code> is set by the user based on the expected gain through the system being modeled.
emilmont 1:fdd22bb7aa52 148 *
emilmont 1:fdd22bb7aa52 149 * \par Overflow and Saturation:
emilmont 1:fdd22bb7aa52 150 * Overflow and saturation behavior of the fixed-point Q15 and Q31 versions are
emilmont 1:fdd22bb7aa52 151 * described separately as part of the function specific documentation below.
emilmont 1:fdd22bb7aa52 152 */
emilmont 1:fdd22bb7aa52 153
emilmont 1:fdd22bb7aa52 154 /**
emilmont 1:fdd22bb7aa52 155 * @addtogroup LMS
emilmont 1:fdd22bb7aa52 156 * @{
emilmont 1:fdd22bb7aa52 157 */
emilmont 1:fdd22bb7aa52 158
emilmont 1:fdd22bb7aa52 159 /**
emilmont 1:fdd22bb7aa52 160 * @details
emilmont 1:fdd22bb7aa52 161 * This function operates on floating-point data types.
emilmont 1:fdd22bb7aa52 162 *
emilmont 1:fdd22bb7aa52 163 * @brief Processing function for floating-point LMS filter.
emilmont 1:fdd22bb7aa52 164 * @param[in] *S points to an instance of the floating-point LMS filter structure.
emilmont 1:fdd22bb7aa52 165 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 166 * @param[in] *pRef points to the block of reference data.
emilmont 1:fdd22bb7aa52 167 * @param[out] *pOut points to the block of output data.
emilmont 1:fdd22bb7aa52 168 * @param[out] *pErr points to the block of error data.
emilmont 1:fdd22bb7aa52 169 * @param[in] blockSize number of samples to process.
emilmont 1:fdd22bb7aa52 170 * @return none.
emilmont 1:fdd22bb7aa52 171 */
emilmont 1:fdd22bb7aa52 172
emilmont 1:fdd22bb7aa52 173 void arm_lms_f32(
emilmont 1:fdd22bb7aa52 174 const arm_lms_instance_f32 * S,
emilmont 1:fdd22bb7aa52 175 float32_t * pSrc,
emilmont 1:fdd22bb7aa52 176 float32_t * pRef,
emilmont 1:fdd22bb7aa52 177 float32_t * pOut,
emilmont 1:fdd22bb7aa52 178 float32_t * pErr,
emilmont 1:fdd22bb7aa52 179 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 180 {
emilmont 1:fdd22bb7aa52 181 float32_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 182 float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 183 float32_t *pStateCurnt; /* Points to the current sample of the state */
emilmont 1:fdd22bb7aa52 184 float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */
emilmont 1:fdd22bb7aa52 185 float32_t mu = S->mu; /* Adaptive factor */
emilmont 1:fdd22bb7aa52 186 uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */
emilmont 1:fdd22bb7aa52 187 uint32_t tapCnt, blkCnt; /* Loop counters */
emilmont 1:fdd22bb7aa52 188 float32_t sum, e, d; /* accumulator, error, reference data sample */
emilmont 1:fdd22bb7aa52 189 float32_t w = 0.0f; /* weight factor */
emilmont 1:fdd22bb7aa52 190
emilmont 1:fdd22bb7aa52 191 e = 0.0f;
emilmont 1:fdd22bb7aa52 192 d = 0.0f;
emilmont 1:fdd22bb7aa52 193
emilmont 1:fdd22bb7aa52 194 /* S->pState points to state array which contains previous frame (numTaps - 1) samples */
emilmont 1:fdd22bb7aa52 195 /* pStateCurnt points to the location where the new input data should be written */
emilmont 1:fdd22bb7aa52 196 pStateCurnt = &(S->pState[(numTaps - 1u)]);
emilmont 1:fdd22bb7aa52 197
emilmont 1:fdd22bb7aa52 198 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 199
emilmont 1:fdd22bb7aa52 200
emilmont 1:fdd22bb7aa52 201 #ifndef ARM_MATH_CM0
emilmont 1:fdd22bb7aa52 202
emilmont 1:fdd22bb7aa52 203 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 204
emilmont 1:fdd22bb7aa52 205 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 206 {
emilmont 1:fdd22bb7aa52 207 /* Copy the new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 208 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 209
emilmont 1:fdd22bb7aa52 210 /* Initialize pState pointer */
emilmont 1:fdd22bb7aa52 211 px = pState;
emilmont 1:fdd22bb7aa52 212
emilmont 1:fdd22bb7aa52 213 /* Initialize coeff pointer */
emilmont 1:fdd22bb7aa52 214 pb = (pCoeffs);
emilmont 1:fdd22bb7aa52 215
emilmont 1:fdd22bb7aa52 216 /* Set the accumulator to zero */
emilmont 1:fdd22bb7aa52 217 sum = 0.0f;
emilmont 1:fdd22bb7aa52 218
emilmont 1:fdd22bb7aa52 219 /* Loop unrolling. Process 4 taps at a time. */
emilmont 1:fdd22bb7aa52 220 tapCnt = numTaps >> 2;
emilmont 1:fdd22bb7aa52 221
emilmont 1:fdd22bb7aa52 222 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 223 {
emilmont 1:fdd22bb7aa52 224 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 225 sum += (*px++) * (*pb++);
emilmont 1:fdd22bb7aa52 226 sum += (*px++) * (*pb++);
emilmont 1:fdd22bb7aa52 227 sum += (*px++) * (*pb++);
emilmont 1:fdd22bb7aa52 228 sum += (*px++) * (*pb++);
emilmont 1:fdd22bb7aa52 229
emilmont 1:fdd22bb7aa52 230 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 231 tapCnt--;
emilmont 1:fdd22bb7aa52 232 }
emilmont 1:fdd22bb7aa52 233
emilmont 1:fdd22bb7aa52 234 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 235 tapCnt = numTaps % 0x4u;
emilmont 1:fdd22bb7aa52 236
emilmont 1:fdd22bb7aa52 237 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 238 {
emilmont 1:fdd22bb7aa52 239 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 240 sum += (*px++) * (*pb++);
emilmont 1:fdd22bb7aa52 241
emilmont 1:fdd22bb7aa52 242 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 243 tapCnt--;
emilmont 1:fdd22bb7aa52 244 }
emilmont 1:fdd22bb7aa52 245
emilmont 1:fdd22bb7aa52 246 /* The result in the accumulator, store in the destination buffer. */
emilmont 1:fdd22bb7aa52 247 *pOut++ = sum;
emilmont 1:fdd22bb7aa52 248
emilmont 1:fdd22bb7aa52 249 /* Compute and store error */
emilmont 1:fdd22bb7aa52 250 d = (float32_t) (*pRef++);
emilmont 1:fdd22bb7aa52 251 e = d - sum;
emilmont 1:fdd22bb7aa52 252 *pErr++ = e;
emilmont 1:fdd22bb7aa52 253
emilmont 1:fdd22bb7aa52 254 /* Calculation of Weighting factor for the updating filter coefficients */
emilmont 1:fdd22bb7aa52 255 w = e * mu;
emilmont 1:fdd22bb7aa52 256
emilmont 1:fdd22bb7aa52 257 /* Initialize pState pointer */
emilmont 1:fdd22bb7aa52 258 px = pState;
emilmont 1:fdd22bb7aa52 259
emilmont 1:fdd22bb7aa52 260 /* Initialize coeff pointer */
emilmont 1:fdd22bb7aa52 261 pb = (pCoeffs);
emilmont 1:fdd22bb7aa52 262
emilmont 1:fdd22bb7aa52 263 /* Loop unrolling. Process 4 taps at a time. */
emilmont 1:fdd22bb7aa52 264 tapCnt = numTaps >> 2;
emilmont 1:fdd22bb7aa52 265
emilmont 1:fdd22bb7aa52 266 /* Update filter coefficients */
emilmont 1:fdd22bb7aa52 267 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 268 {
emilmont 1:fdd22bb7aa52 269 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 270 *pb = *pb + (w * (*px++));
emilmont 1:fdd22bb7aa52 271 pb++;
emilmont 1:fdd22bb7aa52 272
emilmont 1:fdd22bb7aa52 273 *pb = *pb + (w * (*px++));
emilmont 1:fdd22bb7aa52 274 pb++;
emilmont 1:fdd22bb7aa52 275
emilmont 1:fdd22bb7aa52 276 *pb = *pb + (w * (*px++));
emilmont 1:fdd22bb7aa52 277 pb++;
emilmont 1:fdd22bb7aa52 278
emilmont 1:fdd22bb7aa52 279 *pb = *pb + (w * (*px++));
emilmont 1:fdd22bb7aa52 280 pb++;
emilmont 1:fdd22bb7aa52 281
emilmont 1:fdd22bb7aa52 282 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 283 tapCnt--;
emilmont 1:fdd22bb7aa52 284 }
emilmont 1:fdd22bb7aa52 285
emilmont 1:fdd22bb7aa52 286 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emilmont 1:fdd22bb7aa52 287 tapCnt = numTaps % 0x4u;
emilmont 1:fdd22bb7aa52 288
emilmont 1:fdd22bb7aa52 289 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 290 {
emilmont 1:fdd22bb7aa52 291 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 292 *pb = *pb + (w * (*px++));
emilmont 1:fdd22bb7aa52 293 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 /* Advance state pointer by 1 for the next sample */
emilmont 1:fdd22bb7aa52 300 pState = pState + 1;
emilmont 1:fdd22bb7aa52 301
emilmont 1:fdd22bb7aa52 302 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 303 blkCnt--;
emilmont 1:fdd22bb7aa52 304 }
emilmont 1:fdd22bb7aa52 305
emilmont 1:fdd22bb7aa52 306
emilmont 1:fdd22bb7aa52 307 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emilmont 1:fdd22bb7aa52 308 satrt of the state buffer. This prepares the state buffer for the
emilmont 1:fdd22bb7aa52 309 next function call. */
emilmont 1:fdd22bb7aa52 310
emilmont 1:fdd22bb7aa52 311 /* Points to the start of the pState buffer */
emilmont 1:fdd22bb7aa52 312 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 313
emilmont 1:fdd22bb7aa52 314 /* Loop unrolling for (numTaps - 1u) samples copy */
emilmont 1:fdd22bb7aa52 315 tapCnt = (numTaps - 1u) >> 2u;
emilmont 1:fdd22bb7aa52 316
emilmont 1:fdd22bb7aa52 317 /* copy data */
emilmont 1:fdd22bb7aa52 318 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 319 {
emilmont 1:fdd22bb7aa52 320 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 321 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 322 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 323 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 324
emilmont 1:fdd22bb7aa52 325 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 326 tapCnt--;
emilmont 1:fdd22bb7aa52 327 }
emilmont 1:fdd22bb7aa52 328
emilmont 1:fdd22bb7aa52 329 /* Calculate remaining number of copies */
emilmont 1:fdd22bb7aa52 330 tapCnt = (numTaps - 1u) % 0x4u;
emilmont 1:fdd22bb7aa52 331
emilmont 1:fdd22bb7aa52 332 /* Copy the remaining q31_t data */
emilmont 1:fdd22bb7aa52 333 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 334 {
emilmont 1:fdd22bb7aa52 335 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 336
emilmont 1:fdd22bb7aa52 337 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 338 tapCnt--;
emilmont 1:fdd22bb7aa52 339 }
emilmont 1:fdd22bb7aa52 340
emilmont 1:fdd22bb7aa52 341 #else
emilmont 1:fdd22bb7aa52 342
emilmont 1:fdd22bb7aa52 343 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 344
emilmont 1:fdd22bb7aa52 345 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 346 {
emilmont 1:fdd22bb7aa52 347 /* Copy the new input sample into the state buffer */
emilmont 1:fdd22bb7aa52 348 *pStateCurnt++ = *pSrc++;
emilmont 1:fdd22bb7aa52 349
emilmont 1:fdd22bb7aa52 350 /* Initialize pState pointer */
emilmont 1:fdd22bb7aa52 351 px = pState;
emilmont 1:fdd22bb7aa52 352
emilmont 1:fdd22bb7aa52 353 /* Initialize pCoeffs pointer */
emilmont 1:fdd22bb7aa52 354 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 355
emilmont 1:fdd22bb7aa52 356 /* Set the accumulator to zero */
emilmont 1:fdd22bb7aa52 357 sum = 0.0f;
emilmont 1:fdd22bb7aa52 358
emilmont 1:fdd22bb7aa52 359 /* Loop over numTaps number of values */
emilmont 1:fdd22bb7aa52 360 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 363 {
emilmont 1:fdd22bb7aa52 364 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 365 sum += (*px++) * (*pb++);
emilmont 1:fdd22bb7aa52 366
emilmont 1:fdd22bb7aa52 367 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 368 tapCnt--;
emilmont 1:fdd22bb7aa52 369 }
emilmont 1:fdd22bb7aa52 370
emilmont 1:fdd22bb7aa52 371 /* The result is stored in the destination buffer. */
emilmont 1:fdd22bb7aa52 372 *pOut++ = sum;
emilmont 1:fdd22bb7aa52 373
emilmont 1:fdd22bb7aa52 374 /* Compute and store error */
emilmont 1:fdd22bb7aa52 375 d = (float32_t) (*pRef++);
emilmont 1:fdd22bb7aa52 376 e = d - sum;
emilmont 1:fdd22bb7aa52 377 *pErr++ = e;
emilmont 1:fdd22bb7aa52 378
emilmont 1:fdd22bb7aa52 379 /* Weighting factor for the LMS version */
emilmont 1:fdd22bb7aa52 380 w = e * mu;
emilmont 1:fdd22bb7aa52 381
emilmont 1:fdd22bb7aa52 382 /* Initialize pState pointer */
emilmont 1:fdd22bb7aa52 383 px = pState;
emilmont 1:fdd22bb7aa52 384
emilmont 1:fdd22bb7aa52 385 /* Initialize pCoeffs pointer */
emilmont 1:fdd22bb7aa52 386 pb = pCoeffs;
emilmont 1:fdd22bb7aa52 387
emilmont 1:fdd22bb7aa52 388 /* Loop over numTaps number of values */
emilmont 1:fdd22bb7aa52 389 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 390
emilmont 1:fdd22bb7aa52 391 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 392 {
emilmont 1:fdd22bb7aa52 393 /* Perform the multiply-accumulate */
emilmont 1:fdd22bb7aa52 394 *pb = *pb + (w * (*px++));
emilmont 1:fdd22bb7aa52 395 pb++;
emilmont 1:fdd22bb7aa52 396
emilmont 1:fdd22bb7aa52 397 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 398 tapCnt--;
emilmont 1:fdd22bb7aa52 399 }
emilmont 1:fdd22bb7aa52 400
emilmont 1:fdd22bb7aa52 401 /* Advance state pointer by 1 for the next sample */
emilmont 1:fdd22bb7aa52 402 pState = pState + 1;
emilmont 1:fdd22bb7aa52 403
emilmont 1:fdd22bb7aa52 404 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 405 blkCnt--;
emilmont 1:fdd22bb7aa52 406 }
emilmont 1:fdd22bb7aa52 407
emilmont 1:fdd22bb7aa52 408
emilmont 1:fdd22bb7aa52 409 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emilmont 1:fdd22bb7aa52 410 * start of the state buffer. This prepares the state buffer for the
emilmont 1:fdd22bb7aa52 411 * next function call. */
emilmont 1:fdd22bb7aa52 412
emilmont 1:fdd22bb7aa52 413 /* Points to the start of the pState buffer */
emilmont 1:fdd22bb7aa52 414 pStateCurnt = S->pState;
emilmont 1:fdd22bb7aa52 415
emilmont 1:fdd22bb7aa52 416 /* Copy (numTaps - 1u) samples */
emilmont 1:fdd22bb7aa52 417 tapCnt = (numTaps - 1u);
emilmont 1:fdd22bb7aa52 418
emilmont 1:fdd22bb7aa52 419 /* Copy the data */
emilmont 1:fdd22bb7aa52 420 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 421 {
emilmont 1:fdd22bb7aa52 422 *pStateCurnt++ = *pState++;
emilmont 1:fdd22bb7aa52 423
emilmont 1:fdd22bb7aa52 424 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 425 tapCnt--;
emilmont 1:fdd22bb7aa52 426 }
emilmont 1:fdd22bb7aa52 427
emilmont 1:fdd22bb7aa52 428 #endif /* #ifndef ARM_MATH_CM0 */
emilmont 1:fdd22bb7aa52 429
emilmont 1:fdd22bb7aa52 430 }
emilmont 1:fdd22bb7aa52 431
emilmont 1:fdd22bb7aa52 432 /**
emilmont 1:fdd22bb7aa52 433 * @} end of LMS group
emilmont 1:fdd22bb7aa52 434 */