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_q15.c
emh203 0:3d9c67d97d6f 9 *
emh203 0:3d9c67d97d6f 10 * Description: Q15 NLMS filter.
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 * @addtogroup LMS_NORM
emh203 0:3d9c67d97d6f 49 * @{
emh203 0:3d9c67d97d6f 50 */
emh203 0:3d9c67d97d6f 51
emh203 0:3d9c67d97d6f 52 /**
emh203 0:3d9c67d97d6f 53 * @brief Processing function for Q15 normalized LMS filter.
emh203 0:3d9c67d97d6f 54 * @param[in] *S points to an instance of the Q15 normalized LMS filter structure.
emh203 0:3d9c67d97d6f 55 * @param[in] *pSrc points to the block of input data.
emh203 0:3d9c67d97d6f 56 * @param[in] *pRef points to the block of reference data.
emh203 0:3d9c67d97d6f 57 * @param[out] *pOut points to the block of output data.
emh203 0:3d9c67d97d6f 58 * @param[out] *pErr points to the block of error data.
emh203 0:3d9c67d97d6f 59 * @param[in] blockSize number of samples to process.
emh203 0:3d9c67d97d6f 60 * @return none.
emh203 0:3d9c67d97d6f 61 *
emh203 0:3d9c67d97d6f 62 * <b>Scaling and Overflow Behavior:</b>
emh203 0:3d9c67d97d6f 63 * \par
emh203 0:3d9c67d97d6f 64 * The function is implemented using a 64-bit internal accumulator.
emh203 0:3d9c67d97d6f 65 * Both coefficients and state variables are represented in 1.15 format and
emh203 0:3d9c67d97d6f 66 * multiplications yield a 2.30 result. The 2.30 intermediate results are
emh203 0:3d9c67d97d6f 67 * accumulated in a 64-bit accumulator in 34.30 format.
emh203 0:3d9c67d97d6f 68 * There is no risk of internal overflow with this approach and the full
emh203 0:3d9c67d97d6f 69 * precision of intermediate multiplications is preserved. After all additions
emh203 0:3d9c67d97d6f 70 * have been performed, the accumulator is truncated to 34.15 format by
emh203 0:3d9c67d97d6f 71 * discarding low 15 bits. Lastly, the accumulator is saturated to yield a
emh203 0:3d9c67d97d6f 72 * result in 1.15 format.
emh203 0:3d9c67d97d6f 73 *
emh203 0:3d9c67d97d6f 74 * \par
emh203 0:3d9c67d97d6f 75 * In this filter, filter coefficients are updated for each sample and the updation of filter cofficients are saturted.
emh203 0:3d9c67d97d6f 76 *
emh203 0:3d9c67d97d6f 77 */
emh203 0:3d9c67d97d6f 78
emh203 0:3d9c67d97d6f 79 void arm_lms_norm_q15(
emh203 0:3d9c67d97d6f 80 arm_lms_norm_instance_q15 * S,
emh203 0:3d9c67d97d6f 81 q15_t * pSrc,
emh203 0:3d9c67d97d6f 82 q15_t * pRef,
emh203 0:3d9c67d97d6f 83 q15_t * pOut,
emh203 0:3d9c67d97d6f 84 q15_t * pErr,
emh203 0:3d9c67d97d6f 85 uint32_t blockSize)
emh203 0:3d9c67d97d6f 86 {
emh203 0:3d9c67d97d6f 87 q15_t *pState = S->pState; /* State pointer */
emh203 0:3d9c67d97d6f 88 q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emh203 0:3d9c67d97d6f 89 q15_t *pStateCurnt; /* Points to the current sample of the state */
emh203 0:3d9c67d97d6f 90 q15_t *px, *pb; /* Temporary pointers for state and coefficient buffers */
emh203 0:3d9c67d97d6f 91 q15_t mu = S->mu; /* Adaptive factor */
emh203 0:3d9c67d97d6f 92 uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */
emh203 0:3d9c67d97d6f 93 uint32_t tapCnt, blkCnt; /* Loop counters */
emh203 0:3d9c67d97d6f 94 q31_t energy; /* Energy of the input */
emh203 0:3d9c67d97d6f 95 q63_t acc; /* Accumulator */
emh203 0:3d9c67d97d6f 96 q15_t e = 0, d = 0; /* error, reference data sample */
emh203 0:3d9c67d97d6f 97 q15_t w = 0, in; /* weight factor and state */
emh203 0:3d9c67d97d6f 98 q15_t x0; /* temporary variable to hold input sample */
emh203 0:3d9c67d97d6f 99 //uint32_t shift = (uint32_t) S->postShift + 1u; /* Shift to be applied to the output */
emh203 0:3d9c67d97d6f 100 q15_t errorXmu, oneByEnergy; /* Temporary variables to store error and mu product and reciprocal of energy */
emh203 0:3d9c67d97d6f 101 q15_t postShift; /* Post shift to be applied to weight after reciprocal calculation */
emh203 0:3d9c67d97d6f 102 q31_t coef; /* Teporary variable for coefficient */
emh203 0:3d9c67d97d6f 103 q31_t acc_l, acc_h;
emh203 0:3d9c67d97d6f 104 int32_t lShift = (15 - (int32_t) S->postShift); /* Post shift */
emh203 0:3d9c67d97d6f 105 int32_t uShift = (32 - lShift);
emh203 0:3d9c67d97d6f 106
emh203 0:3d9c67d97d6f 107 energy = S->energy;
emh203 0:3d9c67d97d6f 108 x0 = S->x0;
emh203 0:3d9c67d97d6f 109
emh203 0:3d9c67d97d6f 110 /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */
emh203 0:3d9c67d97d6f 111 /* pStateCurnt points to the location where the new input data should be written */
emh203 0:3d9c67d97d6f 112 pStateCurnt = &(S->pState[(numTaps - 1u)]);
emh203 0:3d9c67d97d6f 113
emh203 0:3d9c67d97d6f 114 /* Loop over blockSize number of values */
emh203 0:3d9c67d97d6f 115 blkCnt = blockSize;
emh203 0:3d9c67d97d6f 116
emh203 0:3d9c67d97d6f 117
emh203 0:3d9c67d97d6f 118 #ifndef ARM_MATH_CM0_FAMILY
emh203 0:3d9c67d97d6f 119
emh203 0:3d9c67d97d6f 120 /* Run the below code for Cortex-M4 and Cortex-M3 */
emh203 0:3d9c67d97d6f 121
emh203 0:3d9c67d97d6f 122 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 123 {
emh203 0:3d9c67d97d6f 124 /* Copy the new input sample into the state buffer */
emh203 0:3d9c67d97d6f 125 *pStateCurnt++ = *pSrc;
emh203 0:3d9c67d97d6f 126
emh203 0:3d9c67d97d6f 127 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 128 px = pState;
emh203 0:3d9c67d97d6f 129
emh203 0:3d9c67d97d6f 130 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 131 pb = (pCoeffs);
emh203 0:3d9c67d97d6f 132
emh203 0:3d9c67d97d6f 133 /* Read the sample from input buffer */
emh203 0:3d9c67d97d6f 134 in = *pSrc++;
emh203 0:3d9c67d97d6f 135
emh203 0:3d9c67d97d6f 136 /* Update the energy calculation */
emh203 0:3d9c67d97d6f 137 energy -= (((q31_t) x0 * (x0)) >> 15);
emh203 0:3d9c67d97d6f 138 energy += (((q31_t) in * (in)) >> 15);
emh203 0:3d9c67d97d6f 139
emh203 0:3d9c67d97d6f 140 /* Set the accumulator to zero */
emh203 0:3d9c67d97d6f 141 acc = 0;
emh203 0:3d9c67d97d6f 142
emh203 0:3d9c67d97d6f 143 /* Loop unrolling. Process 4 taps at a time. */
emh203 0:3d9c67d97d6f 144 tapCnt = numTaps >> 2;
emh203 0:3d9c67d97d6f 145
emh203 0:3d9c67d97d6f 146 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 147 {
emh203 0:3d9c67d97d6f 148
emh203 0:3d9c67d97d6f 149 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 150 #ifndef UNALIGNED_SUPPORT_DISABLE
emh203 0:3d9c67d97d6f 151
emh203 0:3d9c67d97d6f 152 acc = __SMLALD(*__SIMD32(px)++, (*__SIMD32(pb)++), acc);
emh203 0:3d9c67d97d6f 153 acc = __SMLALD(*__SIMD32(px)++, (*__SIMD32(pb)++), acc);
emh203 0:3d9c67d97d6f 154
emh203 0:3d9c67d97d6f 155 #else
emh203 0:3d9c67d97d6f 156
emh203 0:3d9c67d97d6f 157 acc += (((q31_t) * px++ * (*pb++)));
emh203 0:3d9c67d97d6f 158 acc += (((q31_t) * px++ * (*pb++)));
emh203 0:3d9c67d97d6f 159 acc += (((q31_t) * px++ * (*pb++)));
emh203 0:3d9c67d97d6f 160 acc += (((q31_t) * px++ * (*pb++)));
emh203 0:3d9c67d97d6f 161
emh203 0:3d9c67d97d6f 162 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
emh203 0:3d9c67d97d6f 163
emh203 0:3d9c67d97d6f 164 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 165 tapCnt--;
emh203 0:3d9c67d97d6f 166 }
emh203 0:3d9c67d97d6f 167
emh203 0:3d9c67d97d6f 168 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emh203 0:3d9c67d97d6f 169 tapCnt = numTaps % 0x4u;
emh203 0:3d9c67d97d6f 170
emh203 0:3d9c67d97d6f 171 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 172 {
emh203 0:3d9c67d97d6f 173 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 174 acc += (((q31_t) * px++ * (*pb++)));
emh203 0:3d9c67d97d6f 175
emh203 0:3d9c67d97d6f 176 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 177 tapCnt--;
emh203 0:3d9c67d97d6f 178 }
emh203 0:3d9c67d97d6f 179
emh203 0:3d9c67d97d6f 180 /* Calc lower part of acc */
emh203 0:3d9c67d97d6f 181 acc_l = acc & 0xffffffff;
emh203 0:3d9c67d97d6f 182
emh203 0:3d9c67d97d6f 183 /* Calc upper part of acc */
emh203 0:3d9c67d97d6f 184 acc_h = (acc >> 32) & 0xffffffff;
emh203 0:3d9c67d97d6f 185
emh203 0:3d9c67d97d6f 186 /* Apply shift for lower part of acc and upper part of acc */
emh203 0:3d9c67d97d6f 187 acc = (uint32_t) acc_l >> lShift | acc_h << uShift;
emh203 0:3d9c67d97d6f 188
emh203 0:3d9c67d97d6f 189 /* Converting the result to 1.15 format and saturate the output */
emh203 0:3d9c67d97d6f 190 acc = __SSAT(acc, 16u);
emh203 0:3d9c67d97d6f 191
emh203 0:3d9c67d97d6f 192 /* Store the result from accumulator into the destination buffer. */
emh203 0:3d9c67d97d6f 193 *pOut++ = (q15_t) acc;
emh203 0:3d9c67d97d6f 194
emh203 0:3d9c67d97d6f 195 /* Compute and store error */
emh203 0:3d9c67d97d6f 196 d = *pRef++;
emh203 0:3d9c67d97d6f 197 e = d - (q15_t) acc;
emh203 0:3d9c67d97d6f 198 *pErr++ = e;
emh203 0:3d9c67d97d6f 199
emh203 0:3d9c67d97d6f 200 /* Calculation of 1/energy */
emh203 0:3d9c67d97d6f 201 postShift = arm_recip_q15((q15_t) energy + DELTA_Q15,
emh203 0:3d9c67d97d6f 202 &oneByEnergy, S->recipTable);
emh203 0:3d9c67d97d6f 203
emh203 0:3d9c67d97d6f 204 /* Calculation of e * mu value */
emh203 0:3d9c67d97d6f 205 errorXmu = (q15_t) (((q31_t) e * mu) >> 15);
emh203 0:3d9c67d97d6f 206
emh203 0:3d9c67d97d6f 207 /* Calculation of (e * mu) * (1/energy) value */
emh203 0:3d9c67d97d6f 208 acc = (((q31_t) errorXmu * oneByEnergy) >> (15 - postShift));
emh203 0:3d9c67d97d6f 209
emh203 0:3d9c67d97d6f 210 /* Weighting factor for the normalized version */
emh203 0:3d9c67d97d6f 211 w = (q15_t) __SSAT((q31_t) acc, 16);
emh203 0:3d9c67d97d6f 212
emh203 0:3d9c67d97d6f 213 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 214 px = pState;
emh203 0:3d9c67d97d6f 215
emh203 0:3d9c67d97d6f 216 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 217 pb = (pCoeffs);
emh203 0:3d9c67d97d6f 218
emh203 0:3d9c67d97d6f 219 /* Loop unrolling. Process 4 taps at a time. */
emh203 0:3d9c67d97d6f 220 tapCnt = numTaps >> 2;
emh203 0:3d9c67d97d6f 221
emh203 0:3d9c67d97d6f 222 /* Update filter coefficients */
emh203 0:3d9c67d97d6f 223 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 224 {
emh203 0:3d9c67d97d6f 225 coef = *pb + (((q31_t) w * (*px++)) >> 15);
emh203 0:3d9c67d97d6f 226 *pb++ = (q15_t) __SSAT((coef), 16);
emh203 0:3d9c67d97d6f 227 coef = *pb + (((q31_t) w * (*px++)) >> 15);
emh203 0:3d9c67d97d6f 228 *pb++ = (q15_t) __SSAT((coef), 16);
emh203 0:3d9c67d97d6f 229 coef = *pb + (((q31_t) w * (*px++)) >> 15);
emh203 0:3d9c67d97d6f 230 *pb++ = (q15_t) __SSAT((coef), 16);
emh203 0:3d9c67d97d6f 231 coef = *pb + (((q31_t) w * (*px++)) >> 15);
emh203 0:3d9c67d97d6f 232 *pb++ = (q15_t) __SSAT((coef), 16);
emh203 0:3d9c67d97d6f 233
emh203 0:3d9c67d97d6f 234 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 235 tapCnt--;
emh203 0:3d9c67d97d6f 236 }
emh203 0:3d9c67d97d6f 237
emh203 0:3d9c67d97d6f 238 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emh203 0:3d9c67d97d6f 239 tapCnt = numTaps % 0x4u;
emh203 0:3d9c67d97d6f 240
emh203 0:3d9c67d97d6f 241 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 242 {
emh203 0:3d9c67d97d6f 243 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 244 coef = *pb + (((q31_t) w * (*px++)) >> 15);
emh203 0:3d9c67d97d6f 245 *pb++ = (q15_t) __SSAT((coef), 16);
emh203 0:3d9c67d97d6f 246
emh203 0:3d9c67d97d6f 247 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 248 tapCnt--;
emh203 0:3d9c67d97d6f 249 }
emh203 0:3d9c67d97d6f 250
emh203 0:3d9c67d97d6f 251 /* Read the sample from state buffer */
emh203 0:3d9c67d97d6f 252 x0 = *pState;
emh203 0:3d9c67d97d6f 253
emh203 0:3d9c67d97d6f 254 /* Advance state pointer by 1 for the next sample */
emh203 0:3d9c67d97d6f 255 pState = pState + 1u;
emh203 0:3d9c67d97d6f 256
emh203 0:3d9c67d97d6f 257 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 258 blkCnt--;
emh203 0:3d9c67d97d6f 259 }
emh203 0:3d9c67d97d6f 260
emh203 0:3d9c67d97d6f 261 /* Save energy and x0 values for the next frame */
emh203 0:3d9c67d97d6f 262 S->energy = (q15_t) energy;
emh203 0:3d9c67d97d6f 263 S->x0 = x0;
emh203 0:3d9c67d97d6f 264
emh203 0:3d9c67d97d6f 265 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emh203 0:3d9c67d97d6f 266 satrt of the state buffer. This prepares the state buffer for the
emh203 0:3d9c67d97d6f 267 next function call. */
emh203 0:3d9c67d97d6f 268
emh203 0:3d9c67d97d6f 269 /* Points to the start of the pState buffer */
emh203 0:3d9c67d97d6f 270 pStateCurnt = S->pState;
emh203 0:3d9c67d97d6f 271
emh203 0:3d9c67d97d6f 272 /* Calculation of count for copying integer writes */
emh203 0:3d9c67d97d6f 273 tapCnt = (numTaps - 1u) >> 2;
emh203 0:3d9c67d97d6f 274
emh203 0:3d9c67d97d6f 275 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 276 {
emh203 0:3d9c67d97d6f 277
emh203 0:3d9c67d97d6f 278 #ifndef UNALIGNED_SUPPORT_DISABLE
emh203 0:3d9c67d97d6f 279
emh203 0:3d9c67d97d6f 280 *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;
emh203 0:3d9c67d97d6f 281 *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;
emh203 0:3d9c67d97d6f 282
emh203 0:3d9c67d97d6f 283 #else
emh203 0:3d9c67d97d6f 284
emh203 0:3d9c67d97d6f 285 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 286 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 287 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 288 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 289
emh203 0:3d9c67d97d6f 290 #endif
emh203 0:3d9c67d97d6f 291
emh203 0:3d9c67d97d6f 292 tapCnt--;
emh203 0:3d9c67d97d6f 293
emh203 0:3d9c67d97d6f 294 }
emh203 0:3d9c67d97d6f 295
emh203 0:3d9c67d97d6f 296 /* Calculation of count for remaining q15_t data */
emh203 0:3d9c67d97d6f 297 tapCnt = (numTaps - 1u) % 0x4u;
emh203 0:3d9c67d97d6f 298
emh203 0:3d9c67d97d6f 299 /* copy data */
emh203 0:3d9c67d97d6f 300 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 301 {
emh203 0:3d9c67d97d6f 302 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 303
emh203 0:3d9c67d97d6f 304 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 305 tapCnt--;
emh203 0:3d9c67d97d6f 306 }
emh203 0:3d9c67d97d6f 307
emh203 0:3d9c67d97d6f 308 #else
emh203 0:3d9c67d97d6f 309
emh203 0:3d9c67d97d6f 310 /* Run the below code for Cortex-M0 */
emh203 0:3d9c67d97d6f 311
emh203 0:3d9c67d97d6f 312 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 313 {
emh203 0:3d9c67d97d6f 314 /* Copy the new input sample into the state buffer */
emh203 0:3d9c67d97d6f 315 *pStateCurnt++ = *pSrc;
emh203 0:3d9c67d97d6f 316
emh203 0:3d9c67d97d6f 317 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 318 px = pState;
emh203 0:3d9c67d97d6f 319
emh203 0:3d9c67d97d6f 320 /* Initialize pCoeffs pointer */
emh203 0:3d9c67d97d6f 321 pb = pCoeffs;
emh203 0:3d9c67d97d6f 322
emh203 0:3d9c67d97d6f 323 /* Read the sample from input buffer */
emh203 0:3d9c67d97d6f 324 in = *pSrc++;
emh203 0:3d9c67d97d6f 325
emh203 0:3d9c67d97d6f 326 /* Update the energy calculation */
emh203 0:3d9c67d97d6f 327 energy -= (((q31_t) x0 * (x0)) >> 15);
emh203 0:3d9c67d97d6f 328 energy += (((q31_t) in * (in)) >> 15);
emh203 0:3d9c67d97d6f 329
emh203 0:3d9c67d97d6f 330 /* Set the accumulator to zero */
emh203 0:3d9c67d97d6f 331 acc = 0;
emh203 0:3d9c67d97d6f 332
emh203 0:3d9c67d97d6f 333 /* Loop over numTaps number of values */
emh203 0:3d9c67d97d6f 334 tapCnt = numTaps;
emh203 0:3d9c67d97d6f 335
emh203 0:3d9c67d97d6f 336 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 337 {
emh203 0:3d9c67d97d6f 338 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 339 acc += (((q31_t) * px++ * (*pb++)));
emh203 0:3d9c67d97d6f 340
emh203 0:3d9c67d97d6f 341 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 342 tapCnt--;
emh203 0:3d9c67d97d6f 343 }
emh203 0:3d9c67d97d6f 344
emh203 0:3d9c67d97d6f 345 /* Calc lower part of acc */
emh203 0:3d9c67d97d6f 346 acc_l = acc & 0xffffffff;
emh203 0:3d9c67d97d6f 347
emh203 0:3d9c67d97d6f 348 /* Calc upper part of acc */
emh203 0:3d9c67d97d6f 349 acc_h = (acc >> 32) & 0xffffffff;
emh203 0:3d9c67d97d6f 350
emh203 0:3d9c67d97d6f 351 /* Apply shift for lower part of acc and upper part of acc */
emh203 0:3d9c67d97d6f 352 acc = (uint32_t) acc_l >> lShift | acc_h << uShift;
emh203 0:3d9c67d97d6f 353
emh203 0:3d9c67d97d6f 354 /* Converting the result to 1.15 format and saturate the output */
emh203 0:3d9c67d97d6f 355 acc = __SSAT(acc, 16u);
emh203 0:3d9c67d97d6f 356
emh203 0:3d9c67d97d6f 357 /* Converting the result to 1.15 format */
emh203 0:3d9c67d97d6f 358 //acc = __SSAT((acc >> (16u - shift)), 16u);
emh203 0:3d9c67d97d6f 359
emh203 0:3d9c67d97d6f 360 /* Store the result from accumulator into the destination buffer. */
emh203 0:3d9c67d97d6f 361 *pOut++ = (q15_t) acc;
emh203 0:3d9c67d97d6f 362
emh203 0:3d9c67d97d6f 363 /* Compute and store error */
emh203 0:3d9c67d97d6f 364 d = *pRef++;
emh203 0:3d9c67d97d6f 365 e = d - (q15_t) acc;
emh203 0:3d9c67d97d6f 366 *pErr++ = e;
emh203 0:3d9c67d97d6f 367
emh203 0:3d9c67d97d6f 368 /* Calculation of 1/energy */
emh203 0:3d9c67d97d6f 369 postShift = arm_recip_q15((q15_t) energy + DELTA_Q15,
emh203 0:3d9c67d97d6f 370 &oneByEnergy, S->recipTable);
emh203 0:3d9c67d97d6f 371
emh203 0:3d9c67d97d6f 372 /* Calculation of e * mu value */
emh203 0:3d9c67d97d6f 373 errorXmu = (q15_t) (((q31_t) e * mu) >> 15);
emh203 0:3d9c67d97d6f 374
emh203 0:3d9c67d97d6f 375 /* Calculation of (e * mu) * (1/energy) value */
emh203 0:3d9c67d97d6f 376 acc = (((q31_t) errorXmu * oneByEnergy) >> (15 - postShift));
emh203 0:3d9c67d97d6f 377
emh203 0:3d9c67d97d6f 378 /* Weighting factor for the normalized version */
emh203 0:3d9c67d97d6f 379 w = (q15_t) __SSAT((q31_t) acc, 16);
emh203 0:3d9c67d97d6f 380
emh203 0:3d9c67d97d6f 381 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 382 px = pState;
emh203 0:3d9c67d97d6f 383
emh203 0:3d9c67d97d6f 384 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 385 pb = (pCoeffs);
emh203 0:3d9c67d97d6f 386
emh203 0:3d9c67d97d6f 387 /* Loop over numTaps number of values */
emh203 0:3d9c67d97d6f 388 tapCnt = numTaps;
emh203 0:3d9c67d97d6f 389
emh203 0:3d9c67d97d6f 390 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 391 {
emh203 0:3d9c67d97d6f 392 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 393 coef = *pb + (((q31_t) w * (*px++)) >> 15);
emh203 0:3d9c67d97d6f 394 *pb++ = (q15_t) __SSAT((coef), 16);
emh203 0:3d9c67d97d6f 395
emh203 0:3d9c67d97d6f 396 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 397 tapCnt--;
emh203 0:3d9c67d97d6f 398 }
emh203 0:3d9c67d97d6f 399
emh203 0:3d9c67d97d6f 400 /* Read the sample from state buffer */
emh203 0:3d9c67d97d6f 401 x0 = *pState;
emh203 0:3d9c67d97d6f 402
emh203 0:3d9c67d97d6f 403 /* Advance state pointer by 1 for the next sample */
emh203 0:3d9c67d97d6f 404 pState = pState + 1u;
emh203 0:3d9c67d97d6f 405
emh203 0:3d9c67d97d6f 406 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 407 blkCnt--;
emh203 0:3d9c67d97d6f 408 }
emh203 0:3d9c67d97d6f 409
emh203 0:3d9c67d97d6f 410 /* Save energy and x0 values for the next frame */
emh203 0:3d9c67d97d6f 411 S->energy = (q15_t) energy;
emh203 0:3d9c67d97d6f 412 S->x0 = x0;
emh203 0:3d9c67d97d6f 413
emh203 0:3d9c67d97d6f 414 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emh203 0:3d9c67d97d6f 415 satrt of the state buffer. This prepares the state buffer for the
emh203 0:3d9c67d97d6f 416 next function call. */
emh203 0:3d9c67d97d6f 417
emh203 0:3d9c67d97d6f 418 /* Points to the start of the pState buffer */
emh203 0:3d9c67d97d6f 419 pStateCurnt = S->pState;
emh203 0:3d9c67d97d6f 420
emh203 0:3d9c67d97d6f 421 /* copy (numTaps - 1u) data */
emh203 0:3d9c67d97d6f 422 tapCnt = (numTaps - 1u);
emh203 0:3d9c67d97d6f 423
emh203 0:3d9c67d97d6f 424 /* copy data */
emh203 0:3d9c67d97d6f 425 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 426 {
emh203 0:3d9c67d97d6f 427 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 428
emh203 0:3d9c67d97d6f 429 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 430 tapCnt--;
emh203 0:3d9c67d97d6f 431 }
emh203 0:3d9c67d97d6f 432
emh203 0:3d9c67d97d6f 433 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emh203 0:3d9c67d97d6f 434
emh203 0:3d9c67d97d6f 435 }
emh203 0:3d9c67d97d6f 436
emh203 0:3d9c67d97d6f 437
emh203 0:3d9c67d97d6f 438 /**
emh203 0:3d9c67d97d6f 439 * @} end of LMS_NORM group
emh203 0:3d9c67d97d6f 440 */