V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.

Dependents:   MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more

Committer:
emh203
Date:
Mon Jul 28 15:03:15 2014 +0000
Revision:
0:3d9c67d97d6f
1st working commit.   Had to remove arm_bitreversal2.s     arm_cfft_f32.c and arm_rfft_fast_f32.c.    The .s will not assemble.      For now I removed these functions so we could at least have a library for the other functions.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emh203 0:3d9c67d97d6f 1 /* ----------------------------------------------------------------------
emh203 0:3d9c67d97d6f 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
emh203 0:3d9c67d97d6f 3 *
emh203 0:3d9c67d97d6f 4 * $Date: 12. March 2014
emh203 0:3d9c67d97d6f 5 * $Revision: V1.4.3
emh203 0:3d9c67d97d6f 6 *
emh203 0:3d9c67d97d6f 7 * Project: CMSIS DSP Library
emh203 0:3d9c67d97d6f 8 * Title: arm_lms_norm_f32.c
emh203 0:3d9c67d97d6f 9 *
emh203 0:3d9c67d97d6f 10 * Description: Processing function for the floating-point Normalised LMS.
emh203 0:3d9c67d97d6f 11 *
emh203 0:3d9c67d97d6f 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emh203 0:3d9c67d97d6f 13 *
emh203 0:3d9c67d97d6f 14 * Redistribution and use in source and binary forms, with or without
emh203 0:3d9c67d97d6f 15 * modification, are permitted provided that the following conditions
emh203 0:3d9c67d97d6f 16 * are met:
emh203 0:3d9c67d97d6f 17 * - Redistributions of source code must retain the above copyright
emh203 0:3d9c67d97d6f 18 * notice, this list of conditions and the following disclaimer.
emh203 0:3d9c67d97d6f 19 * - Redistributions in binary form must reproduce the above copyright
emh203 0:3d9c67d97d6f 20 * notice, this list of conditions and the following disclaimer in
emh203 0:3d9c67d97d6f 21 * the documentation and/or other materials provided with the
emh203 0:3d9c67d97d6f 22 * distribution.
emh203 0:3d9c67d97d6f 23 * - Neither the name of ARM LIMITED nor the names of its contributors
emh203 0:3d9c67d97d6f 24 * may be used to endorse or promote products derived from this
emh203 0:3d9c67d97d6f 25 * software without specific prior written permission.
emh203 0:3d9c67d97d6f 26 *
emh203 0:3d9c67d97d6f 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
emh203 0:3d9c67d97d6f 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
emh203 0:3d9c67d97d6f 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
emh203 0:3d9c67d97d6f 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
emh203 0:3d9c67d97d6f 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
emh203 0:3d9c67d97d6f 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
emh203 0:3d9c67d97d6f 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
emh203 0:3d9c67d97d6f 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
emh203 0:3d9c67d97d6f 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
emh203 0:3d9c67d97d6f 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
emh203 0:3d9c67d97d6f 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
emh203 0:3d9c67d97d6f 38 * POSSIBILITY OF SUCH DAMAGE.
emh203 0:3d9c67d97d6f 39 * -------------------------------------------------------------------- */
emh203 0:3d9c67d97d6f 40
emh203 0:3d9c67d97d6f 41 #include "arm_math.h"
emh203 0:3d9c67d97d6f 42
emh203 0:3d9c67d97d6f 43 /**
emh203 0:3d9c67d97d6f 44 * @ingroup groupFilters
emh203 0:3d9c67d97d6f 45 */
emh203 0:3d9c67d97d6f 46
emh203 0:3d9c67d97d6f 47 /**
emh203 0:3d9c67d97d6f 48 * @defgroup LMS_NORM Normalized LMS Filters
emh203 0:3d9c67d97d6f 49 *
emh203 0:3d9c67d97d6f 50 * This set of functions implements a commonly used adaptive filter.
emh203 0:3d9c67d97d6f 51 * It is related to the Least Mean Square (LMS) adaptive filter and includes an additional normalization
emh203 0:3d9c67d97d6f 52 * factor which increases the adaptation rate of the filter.
emh203 0:3d9c67d97d6f 53 * The CMSIS DSP Library contains normalized LMS filter functions that operate on Q15, Q31, and floating-point data types.
emh203 0:3d9c67d97d6f 54 *
emh203 0:3d9c67d97d6f 55 * A normalized least mean square (NLMS) filter consists of two components as shown below.
emh203 0:3d9c67d97d6f 56 * The first component is a standard transversal or FIR filter.
emh203 0:3d9c67d97d6f 57 * The second component is a coefficient update mechanism.
emh203 0:3d9c67d97d6f 58 * The NLMS filter has two input signals.
emh203 0:3d9c67d97d6f 59 * The "input" feeds the FIR filter while the "reference input" corresponds to the desired output of the FIR filter.
emh203 0:3d9c67d97d6f 60 * That is, the FIR filter coefficients are updated so that the output of the FIR filter matches the reference input.
emh203 0:3d9c67d97d6f 61 * The filter coefficient update mechanism is based on the difference between the FIR filter output and the reference input.
emh203 0:3d9c67d97d6f 62 * This "error signal" tends towards zero as the filter adapts.
emh203 0:3d9c67d97d6f 63 * The NLMS processing functions accept the input and reference input signals and generate the filter output and error signal.
emh203 0:3d9c67d97d6f 64 * \image html LMS.gif "Internal structure of the NLMS adaptive filter"
emh203 0:3d9c67d97d6f 65 *
emh203 0:3d9c67d97d6f 66 * The functions operate on blocks of data and each call to the function processes
emh203 0:3d9c67d97d6f 67 * <code>blockSize</code> samples through the filter.
emh203 0:3d9c67d97d6f 68 * <code>pSrc</code> points to input signal, <code>pRef</code> points to reference signal,
emh203 0:3d9c67d97d6f 69 * <code>pOut</code> points to output signal and <code>pErr</code> points to error signal.
emh203 0:3d9c67d97d6f 70 * All arrays contain <code>blockSize</code> values.
emh203 0:3d9c67d97d6f 71 *
emh203 0:3d9c67d97d6f 72 * The functions operate on a block-by-block basis.
emh203 0:3d9c67d97d6f 73 * Internally, the filter coefficients <code>b[n]</code> are updated on a sample-by-sample basis.
emh203 0:3d9c67d97d6f 74 * The convergence of the LMS filter is slower compared to the normalized LMS algorithm.
emh203 0:3d9c67d97d6f 75 *
emh203 0:3d9c67d97d6f 76 * \par Algorithm:
emh203 0:3d9c67d97d6f 77 * The output signal <code>y[n]</code> is computed by a standard FIR filter:
emh203 0:3d9c67d97d6f 78 * <pre>
emh203 0:3d9c67d97d6f 79 * y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[numTaps-1] * x[n-numTaps+1]
emh203 0:3d9c67d97d6f 80 * </pre>
emh203 0:3d9c67d97d6f 81 *
emh203 0:3d9c67d97d6f 82 * \par
emh203 0:3d9c67d97d6f 83 * The error signal equals the difference between the reference signal <code>d[n]</code> and the filter output:
emh203 0:3d9c67d97d6f 84 * <pre>
emh203 0:3d9c67d97d6f 85 * e[n] = d[n] - y[n].
emh203 0:3d9c67d97d6f 86 * </pre>
emh203 0:3d9c67d97d6f 87 *
emh203 0:3d9c67d97d6f 88 * \par
emh203 0:3d9c67d97d6f 89 * After each sample of the error signal is computed the instanteous energy of the filter state variables is calculated:
emh203 0:3d9c67d97d6f 90 * <pre>
emh203 0:3d9c67d97d6f 91 * E = x[n]^2 + x[n-1]^2 + ... + x[n-numTaps+1]^2.
emh203 0:3d9c67d97d6f 92 * </pre>
emh203 0:3d9c67d97d6f 93 * The filter coefficients <code>b[k]</code> are then updated on a sample-by-sample basis:
emh203 0:3d9c67d97d6f 94 * <pre>
emh203 0:3d9c67d97d6f 95 * b[k] = b[k] + e[n] * (mu/E) * x[n-k], for k=0, 1, ..., numTaps-1
emh203 0:3d9c67d97d6f 96 * </pre>
emh203 0:3d9c67d97d6f 97 * where <code>mu</code> is the step size and controls the rate of coefficient convergence.
emh203 0:3d9c67d97d6f 98 *\par
emh203 0:3d9c67d97d6f 99 * In the APIs, <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>.
emh203 0:3d9c67d97d6f 100 * Coefficients are stored in time reversed order.
emh203 0:3d9c67d97d6f 101 * \par
emh203 0:3d9c67d97d6f 102 * <pre>
emh203 0:3d9c67d97d6f 103 * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
emh203 0:3d9c67d97d6f 104 * </pre>
emh203 0:3d9c67d97d6f 105 * \par
emh203 0:3d9c67d97d6f 106 * <code>pState</code> points to a state array of size <code>numTaps + blockSize - 1</code>.
emh203 0:3d9c67d97d6f 107 * Samples in the state buffer are stored in the order:
emh203 0:3d9c67d97d6f 108 * \par
emh203 0:3d9c67d97d6f 109 * <pre>
emh203 0:3d9c67d97d6f 110 * {x[n-numTaps+1], x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2]....x[0], x[1], ..., x[blockSize-1]}
emh203 0:3d9c67d97d6f 111 * </pre>
emh203 0:3d9c67d97d6f 112 * \par
emh203 0:3d9c67d97d6f 113 * Note that the length of the state buffer exceeds the length of the coefficient array by <code>blockSize-1</code> samples.
emh203 0:3d9c67d97d6f 114 * The increased state buffer length allows circular addressing, which is traditionally used in FIR filters,
emh203 0:3d9c67d97d6f 115 * to be avoided and yields a significant speed improvement.
emh203 0:3d9c67d97d6f 116 * The state variables are updated after each block of data is processed.
emh203 0:3d9c67d97d6f 117 * \par Instance Structure
emh203 0:3d9c67d97d6f 118 * The coefficients and state variables for a filter are stored together in an instance data structure.
emh203 0:3d9c67d97d6f 119 * A separate instance structure must be defined for each filter and
emh203 0:3d9c67d97d6f 120 * coefficient and state arrays cannot be shared among instances.
emh203 0:3d9c67d97d6f 121 * There are separate instance structure declarations for each of the 3 supported data types.
emh203 0:3d9c67d97d6f 122 *
emh203 0:3d9c67d97d6f 123 * \par Initialization Functions
emh203 0:3d9c67d97d6f 124 * There is also an associated initialization function for each data type.
emh203 0:3d9c67d97d6f 125 * The initialization function performs the following operations:
emh203 0:3d9c67d97d6f 126 * - Sets the values of the internal structure fields.
emh203 0:3d9c67d97d6f 127 * - Zeros out the values in the state buffer.
emh203 0:3d9c67d97d6f 128 * To do this manually without calling the init function, assign the follow subfields of the instance structure:
emh203 0:3d9c67d97d6f 129 * numTaps, pCoeffs, mu, energy, x0, pState. Also set all of the values in pState to zero.
emh203 0:3d9c67d97d6f 130 * For Q7, Q15, and Q31 the following fields must also be initialized;
emh203 0:3d9c67d97d6f 131 * recipTable, postShift
emh203 0:3d9c67d97d6f 132 *
emh203 0:3d9c67d97d6f 133 * \par
emh203 0:3d9c67d97d6f 134 * Instance structure cannot be placed into a const data section and it is recommended to use the initialization function.
emh203 0:3d9c67d97d6f 135 * \par Fixed-Point Behavior:
emh203 0:3d9c67d97d6f 136 * Care must be taken when using the Q15 and Q31 versions of the normalised LMS filter.
emh203 0:3d9c67d97d6f 137 * The following issues must be considered:
emh203 0:3d9c67d97d6f 138 * - Scaling of coefficients
emh203 0:3d9c67d97d6f 139 * - Overflow and saturation
emh203 0:3d9c67d97d6f 140 *
emh203 0:3d9c67d97d6f 141 * \par Scaling of Coefficients:
emh203 0:3d9c67d97d6f 142 * Filter coefficients are represented as fractional values and
emh203 0:3d9c67d97d6f 143 * coefficients are restricted to lie in the range <code>[-1 +1)</code>.
emh203 0:3d9c67d97d6f 144 * The fixed-point functions have an additional scaling parameter <code>postShift</code>.
emh203 0:3d9c67d97d6f 145 * At the output of the filter's accumulator is a shift register which shifts the result by <code>postShift</code> bits.
emh203 0:3d9c67d97d6f 146 * This essentially scales the filter coefficients by <code>2^postShift</code> and
emh203 0:3d9c67d97d6f 147 * allows the filter coefficients to exceed the range <code>[+1 -1)</code>.
emh203 0:3d9c67d97d6f 148 * The value of <code>postShift</code> is set by the user based on the expected gain through the system being modeled.
emh203 0:3d9c67d97d6f 149 *
emh203 0:3d9c67d97d6f 150 * \par Overflow and Saturation:
emh203 0:3d9c67d97d6f 151 * Overflow and saturation behavior of the fixed-point Q15 and Q31 versions are
emh203 0:3d9c67d97d6f 152 * described separately as part of the function specific documentation below.
emh203 0:3d9c67d97d6f 153 */
emh203 0:3d9c67d97d6f 154
emh203 0:3d9c67d97d6f 155
emh203 0:3d9c67d97d6f 156 /**
emh203 0:3d9c67d97d6f 157 * @addtogroup LMS_NORM
emh203 0:3d9c67d97d6f 158 * @{
emh203 0:3d9c67d97d6f 159 */
emh203 0:3d9c67d97d6f 160
emh203 0:3d9c67d97d6f 161
emh203 0:3d9c67d97d6f 162 /**
emh203 0:3d9c67d97d6f 163 * @brief Processing function for floating-point normalized LMS filter.
emh203 0:3d9c67d97d6f 164 * @param[in] *S points to an instance of the floating-point normalized LMS filter structure.
emh203 0:3d9c67d97d6f 165 * @param[in] *pSrc points to the block of input data.
emh203 0:3d9c67d97d6f 166 * @param[in] *pRef points to the block of reference data.
emh203 0:3d9c67d97d6f 167 * @param[out] *pOut points to the block of output data.
emh203 0:3d9c67d97d6f 168 * @param[out] *pErr points to the block of error data.
emh203 0:3d9c67d97d6f 169 * @param[in] blockSize number of samples to process.
emh203 0:3d9c67d97d6f 170 * @return none.
emh203 0:3d9c67d97d6f 171 */
emh203 0:3d9c67d97d6f 172
emh203 0:3d9c67d97d6f 173 void arm_lms_norm_f32(
emh203 0:3d9c67d97d6f 174 arm_lms_norm_instance_f32 * S,
emh203 0:3d9c67d97d6f 175 float32_t * pSrc,
emh203 0:3d9c67d97d6f 176 float32_t * pRef,
emh203 0:3d9c67d97d6f 177 float32_t * pOut,
emh203 0:3d9c67d97d6f 178 float32_t * pErr,
emh203 0:3d9c67d97d6f 179 uint32_t blockSize)
emh203 0:3d9c67d97d6f 180 {
emh203 0:3d9c67d97d6f 181 float32_t *pState = S->pState; /* State pointer */
emh203 0:3d9c67d97d6f 182 float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emh203 0:3d9c67d97d6f 183 float32_t *pStateCurnt; /* Points to the current sample of the state */
emh203 0:3d9c67d97d6f 184 float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */
emh203 0:3d9c67d97d6f 185 float32_t mu = S->mu; /* Adaptive factor */
emh203 0:3d9c67d97d6f 186 uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */
emh203 0:3d9c67d97d6f 187 uint32_t tapCnt, blkCnt; /* Loop counters */
emh203 0:3d9c67d97d6f 188 float32_t energy; /* Energy of the input */
emh203 0:3d9c67d97d6f 189 float32_t sum, e, d; /* accumulator, error, reference data sample */
emh203 0:3d9c67d97d6f 190 float32_t w, x0, in; /* weight factor, temporary variable to hold input sample and state */
emh203 0:3d9c67d97d6f 191
emh203 0:3d9c67d97d6f 192 /* Initializations of error, difference, Coefficient update */
emh203 0:3d9c67d97d6f 193 e = 0.0f;
emh203 0:3d9c67d97d6f 194 d = 0.0f;
emh203 0:3d9c67d97d6f 195 w = 0.0f;
emh203 0:3d9c67d97d6f 196
emh203 0:3d9c67d97d6f 197 energy = S->energy;
emh203 0:3d9c67d97d6f 198 x0 = S->x0;
emh203 0:3d9c67d97d6f 199
emh203 0:3d9c67d97d6f 200 /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */
emh203 0:3d9c67d97d6f 201 /* pStateCurnt points to the location where the new input data should be written */
emh203 0:3d9c67d97d6f 202 pStateCurnt = &(S->pState[(numTaps - 1u)]);
emh203 0:3d9c67d97d6f 203
emh203 0:3d9c67d97d6f 204 /* Loop over blockSize number of values */
emh203 0:3d9c67d97d6f 205 blkCnt = blockSize;
emh203 0:3d9c67d97d6f 206
emh203 0:3d9c67d97d6f 207
emh203 0:3d9c67d97d6f 208 #ifndef ARM_MATH_CM0_FAMILY
emh203 0:3d9c67d97d6f 209
emh203 0:3d9c67d97d6f 210 /* Run the below code for Cortex-M4 and Cortex-M3 */
emh203 0:3d9c67d97d6f 211
emh203 0:3d9c67d97d6f 212 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 213 {
emh203 0:3d9c67d97d6f 214 /* Copy the new input sample into the state buffer */
emh203 0:3d9c67d97d6f 215 *pStateCurnt++ = *pSrc;
emh203 0:3d9c67d97d6f 216
emh203 0:3d9c67d97d6f 217 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 218 px = pState;
emh203 0:3d9c67d97d6f 219
emh203 0:3d9c67d97d6f 220 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 221 pb = (pCoeffs);
emh203 0:3d9c67d97d6f 222
emh203 0:3d9c67d97d6f 223 /* Read the sample from input buffer */
emh203 0:3d9c67d97d6f 224 in = *pSrc++;
emh203 0:3d9c67d97d6f 225
emh203 0:3d9c67d97d6f 226 /* Update the energy calculation */
emh203 0:3d9c67d97d6f 227 energy -= x0 * x0;
emh203 0:3d9c67d97d6f 228 energy += in * in;
emh203 0:3d9c67d97d6f 229
emh203 0:3d9c67d97d6f 230 /* Set the accumulator to zero */
emh203 0:3d9c67d97d6f 231 sum = 0.0f;
emh203 0:3d9c67d97d6f 232
emh203 0:3d9c67d97d6f 233 /* Loop unrolling. Process 4 taps at a time. */
emh203 0:3d9c67d97d6f 234 tapCnt = numTaps >> 2;
emh203 0:3d9c67d97d6f 235
emh203 0:3d9c67d97d6f 236 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 237 {
emh203 0:3d9c67d97d6f 238 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 239 sum += (*px++) * (*pb++);
emh203 0:3d9c67d97d6f 240 sum += (*px++) * (*pb++);
emh203 0:3d9c67d97d6f 241 sum += (*px++) * (*pb++);
emh203 0:3d9c67d97d6f 242 sum += (*px++) * (*pb++);
emh203 0:3d9c67d97d6f 243
emh203 0:3d9c67d97d6f 244 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 245 tapCnt--;
emh203 0:3d9c67d97d6f 246 }
emh203 0:3d9c67d97d6f 247
emh203 0:3d9c67d97d6f 248 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emh203 0:3d9c67d97d6f 249 tapCnt = numTaps % 0x4u;
emh203 0:3d9c67d97d6f 250
emh203 0:3d9c67d97d6f 251 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 252 {
emh203 0:3d9c67d97d6f 253 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 254 sum += (*px++) * (*pb++);
emh203 0:3d9c67d97d6f 255
emh203 0:3d9c67d97d6f 256 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 257 tapCnt--;
emh203 0:3d9c67d97d6f 258 }
emh203 0:3d9c67d97d6f 259
emh203 0:3d9c67d97d6f 260 /* The result in the accumulator, store in the destination buffer. */
emh203 0:3d9c67d97d6f 261 *pOut++ = sum;
emh203 0:3d9c67d97d6f 262
emh203 0:3d9c67d97d6f 263 /* Compute and store error */
emh203 0:3d9c67d97d6f 264 d = (float32_t) (*pRef++);
emh203 0:3d9c67d97d6f 265 e = d - sum;
emh203 0:3d9c67d97d6f 266 *pErr++ = e;
emh203 0:3d9c67d97d6f 267
emh203 0:3d9c67d97d6f 268 /* Calculation of Weighting factor for updating filter coefficients */
emh203 0:3d9c67d97d6f 269 /* epsilon value 0.000000119209289f */
emh203 0:3d9c67d97d6f 270 w = (e * mu) / (energy + 0.000000119209289f);
emh203 0:3d9c67d97d6f 271
emh203 0:3d9c67d97d6f 272 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 273 px = pState;
emh203 0:3d9c67d97d6f 274
emh203 0:3d9c67d97d6f 275 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 276 pb = (pCoeffs);
emh203 0:3d9c67d97d6f 277
emh203 0:3d9c67d97d6f 278 /* Loop unrolling. Process 4 taps at a time. */
emh203 0:3d9c67d97d6f 279 tapCnt = numTaps >> 2;
emh203 0:3d9c67d97d6f 280
emh203 0:3d9c67d97d6f 281 /* Update filter coefficients */
emh203 0:3d9c67d97d6f 282 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 283 {
emh203 0:3d9c67d97d6f 284 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 285 *pb += w * (*px++);
emh203 0:3d9c67d97d6f 286 pb++;
emh203 0:3d9c67d97d6f 287
emh203 0:3d9c67d97d6f 288 *pb += w * (*px++);
emh203 0:3d9c67d97d6f 289 pb++;
emh203 0:3d9c67d97d6f 290
emh203 0:3d9c67d97d6f 291 *pb += w * (*px++);
emh203 0:3d9c67d97d6f 292 pb++;
emh203 0:3d9c67d97d6f 293
emh203 0:3d9c67d97d6f 294 *pb += w * (*px++);
emh203 0:3d9c67d97d6f 295 pb++;
emh203 0:3d9c67d97d6f 296
emh203 0:3d9c67d97d6f 297
emh203 0:3d9c67d97d6f 298 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 299 tapCnt--;
emh203 0:3d9c67d97d6f 300 }
emh203 0:3d9c67d97d6f 301
emh203 0:3d9c67d97d6f 302 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emh203 0:3d9c67d97d6f 303 tapCnt = numTaps % 0x4u;
emh203 0:3d9c67d97d6f 304
emh203 0:3d9c67d97d6f 305 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 306 {
emh203 0:3d9c67d97d6f 307 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 308 *pb += w * (*px++);
emh203 0:3d9c67d97d6f 309 pb++;
emh203 0:3d9c67d97d6f 310
emh203 0:3d9c67d97d6f 311 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 312 tapCnt--;
emh203 0:3d9c67d97d6f 313 }
emh203 0:3d9c67d97d6f 314
emh203 0:3d9c67d97d6f 315 x0 = *pState;
emh203 0:3d9c67d97d6f 316
emh203 0:3d9c67d97d6f 317 /* Advance state pointer by 1 for the next sample */
emh203 0:3d9c67d97d6f 318 pState = pState + 1;
emh203 0:3d9c67d97d6f 319
emh203 0:3d9c67d97d6f 320 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 321 blkCnt--;
emh203 0:3d9c67d97d6f 322 }
emh203 0:3d9c67d97d6f 323
emh203 0:3d9c67d97d6f 324 S->energy = energy;
emh203 0:3d9c67d97d6f 325 S->x0 = x0;
emh203 0:3d9c67d97d6f 326
emh203 0:3d9c67d97d6f 327 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emh203 0:3d9c67d97d6f 328 satrt of the state buffer. This prepares the state buffer for the
emh203 0:3d9c67d97d6f 329 next function call. */
emh203 0:3d9c67d97d6f 330
emh203 0:3d9c67d97d6f 331 /* Points to the start of the pState buffer */
emh203 0:3d9c67d97d6f 332 pStateCurnt = S->pState;
emh203 0:3d9c67d97d6f 333
emh203 0:3d9c67d97d6f 334 /* Loop unrolling for (numTaps - 1u)/4 samples copy */
emh203 0:3d9c67d97d6f 335 tapCnt = (numTaps - 1u) >> 2u;
emh203 0:3d9c67d97d6f 336
emh203 0:3d9c67d97d6f 337 /* copy data */
emh203 0:3d9c67d97d6f 338 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 339 {
emh203 0:3d9c67d97d6f 340 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 341 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 342 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 343 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 344
emh203 0:3d9c67d97d6f 345 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 346 tapCnt--;
emh203 0:3d9c67d97d6f 347 }
emh203 0:3d9c67d97d6f 348
emh203 0:3d9c67d97d6f 349 /* Calculate remaining number of copies */
emh203 0:3d9c67d97d6f 350 tapCnt = (numTaps - 1u) % 0x4u;
emh203 0:3d9c67d97d6f 351
emh203 0:3d9c67d97d6f 352 /* Copy the remaining q31_t data */
emh203 0:3d9c67d97d6f 353 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 354 {
emh203 0:3d9c67d97d6f 355 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 356
emh203 0:3d9c67d97d6f 357 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 358 tapCnt--;
emh203 0:3d9c67d97d6f 359 }
emh203 0:3d9c67d97d6f 360
emh203 0:3d9c67d97d6f 361 #else
emh203 0:3d9c67d97d6f 362
emh203 0:3d9c67d97d6f 363 /* Run the below code for Cortex-M0 */
emh203 0:3d9c67d97d6f 364
emh203 0:3d9c67d97d6f 365 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 366 {
emh203 0:3d9c67d97d6f 367 /* Copy the new input sample into the state buffer */
emh203 0:3d9c67d97d6f 368 *pStateCurnt++ = *pSrc;
emh203 0:3d9c67d97d6f 369
emh203 0:3d9c67d97d6f 370 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 371 px = pState;
emh203 0:3d9c67d97d6f 372
emh203 0:3d9c67d97d6f 373 /* Initialize pCoeffs pointer */
emh203 0:3d9c67d97d6f 374 pb = pCoeffs;
emh203 0:3d9c67d97d6f 375
emh203 0:3d9c67d97d6f 376 /* Read the sample from input buffer */
emh203 0:3d9c67d97d6f 377 in = *pSrc++;
emh203 0:3d9c67d97d6f 378
emh203 0:3d9c67d97d6f 379 /* Update the energy calculation */
emh203 0:3d9c67d97d6f 380 energy -= x0 * x0;
emh203 0:3d9c67d97d6f 381 energy += in * in;
emh203 0:3d9c67d97d6f 382
emh203 0:3d9c67d97d6f 383 /* Set the accumulator to zero */
emh203 0:3d9c67d97d6f 384 sum = 0.0f;
emh203 0:3d9c67d97d6f 385
emh203 0:3d9c67d97d6f 386 /* Loop over numTaps number of values */
emh203 0:3d9c67d97d6f 387 tapCnt = numTaps;
emh203 0:3d9c67d97d6f 388
emh203 0:3d9c67d97d6f 389 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 390 {
emh203 0:3d9c67d97d6f 391 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 392 sum += (*px++) * (*pb++);
emh203 0:3d9c67d97d6f 393
emh203 0:3d9c67d97d6f 394 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 395 tapCnt--;
emh203 0:3d9c67d97d6f 396 }
emh203 0:3d9c67d97d6f 397
emh203 0:3d9c67d97d6f 398 /* The result in the accumulator is stored in the destination buffer. */
emh203 0:3d9c67d97d6f 399 *pOut++ = sum;
emh203 0:3d9c67d97d6f 400
emh203 0:3d9c67d97d6f 401 /* Compute and store error */
emh203 0:3d9c67d97d6f 402 d = (float32_t) (*pRef++);
emh203 0:3d9c67d97d6f 403 e = d - sum;
emh203 0:3d9c67d97d6f 404 *pErr++ = e;
emh203 0:3d9c67d97d6f 405
emh203 0:3d9c67d97d6f 406 /* Calculation of Weighting factor for updating filter coefficients */
emh203 0:3d9c67d97d6f 407 /* epsilon value 0.000000119209289f */
emh203 0:3d9c67d97d6f 408 w = (e * mu) / (energy + 0.000000119209289f);
emh203 0:3d9c67d97d6f 409
emh203 0:3d9c67d97d6f 410 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 411 px = pState;
emh203 0:3d9c67d97d6f 412
emh203 0:3d9c67d97d6f 413 /* Initialize pCcoeffs pointer */
emh203 0:3d9c67d97d6f 414 pb = pCoeffs;
emh203 0:3d9c67d97d6f 415
emh203 0:3d9c67d97d6f 416 /* Loop over numTaps number of values */
emh203 0:3d9c67d97d6f 417 tapCnt = numTaps;
emh203 0:3d9c67d97d6f 418
emh203 0:3d9c67d97d6f 419 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 420 {
emh203 0:3d9c67d97d6f 421 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 422 *pb += w * (*px++);
emh203 0:3d9c67d97d6f 423 pb++;
emh203 0:3d9c67d97d6f 424
emh203 0:3d9c67d97d6f 425 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 426 tapCnt--;
emh203 0:3d9c67d97d6f 427 }
emh203 0:3d9c67d97d6f 428
emh203 0:3d9c67d97d6f 429 x0 = *pState;
emh203 0:3d9c67d97d6f 430
emh203 0:3d9c67d97d6f 431 /* Advance state pointer by 1 for the next sample */
emh203 0:3d9c67d97d6f 432 pState = pState + 1;
emh203 0:3d9c67d97d6f 433
emh203 0:3d9c67d97d6f 434 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 435 blkCnt--;
emh203 0:3d9c67d97d6f 436 }
emh203 0:3d9c67d97d6f 437
emh203 0:3d9c67d97d6f 438 S->energy = energy;
emh203 0:3d9c67d97d6f 439 S->x0 = x0;
emh203 0:3d9c67d97d6f 440
emh203 0:3d9c67d97d6f 441 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emh203 0:3d9c67d97d6f 442 satrt of the state buffer. This prepares the state buffer for the
emh203 0:3d9c67d97d6f 443 next function call. */
emh203 0:3d9c67d97d6f 444
emh203 0:3d9c67d97d6f 445 /* Points to the start of the pState buffer */
emh203 0:3d9c67d97d6f 446 pStateCurnt = S->pState;
emh203 0:3d9c67d97d6f 447
emh203 0:3d9c67d97d6f 448 /* Copy (numTaps - 1u) samples */
emh203 0:3d9c67d97d6f 449 tapCnt = (numTaps - 1u);
emh203 0:3d9c67d97d6f 450
emh203 0:3d9c67d97d6f 451 /* Copy the remaining q31_t data */
emh203 0:3d9c67d97d6f 452 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 453 {
emh203 0:3d9c67d97d6f 454 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 455
emh203 0:3d9c67d97d6f 456 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 457 tapCnt--;
emh203 0:3d9c67d97d6f 458 }
emh203 0:3d9c67d97d6f 459
emh203 0:3d9c67d97d6f 460 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emh203 0:3d9c67d97d6f 461
emh203 0:3d9c67d97d6f 462 }
emh203 0:3d9c67d97d6f 463
emh203 0:3d9c67d97d6f 464 /**
emh203 0:3d9c67d97d6f 465 * @} end of LMS_NORM group
emh203 0:3d9c67d97d6f 466 */