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_q31.c
emh203 0:3d9c67d97d6f 9 *
emh203 0:3d9c67d97d6f 10 * Description: Processing function for the Q31 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 Q31 normalized LMS filter.
emh203 0:3d9c67d97d6f 54 * @param[in] *S points to an instance of the Q31 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 an internal 64-bit accumulator.
emh203 0:3d9c67d97d6f 65 * The accumulator has a 2.62 format and maintains full precision of the intermediate
emh203 0:3d9c67d97d6f 66 * multiplication results but provides only a single guard bit.
emh203 0:3d9c67d97d6f 67 * Thus, if the accumulator result overflows it wraps around rather than clip.
emh203 0:3d9c67d97d6f 68 * In order to avoid overflows completely the input signal must be scaled down by
emh203 0:3d9c67d97d6f 69 * log2(numTaps) bits. The reference signal should not be scaled down.
emh203 0:3d9c67d97d6f 70 * After all multiply-accumulates are performed, the 2.62 accumulator is shifted
emh203 0:3d9c67d97d6f 71 * and saturated to 1.31 format to yield the final result.
emh203 0:3d9c67d97d6f 72 * The output signal and error signal are in 1.31 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
emh203 0:3d9c67d97d6f 76 * updation of filter cofficients are saturted.
emh203 0:3d9c67d97d6f 77 *
emh203 0:3d9c67d97d6f 78 */
emh203 0:3d9c67d97d6f 79
emh203 0:3d9c67d97d6f 80 void arm_lms_norm_q31(
emh203 0:3d9c67d97d6f 81 arm_lms_norm_instance_q31 * S,
emh203 0:3d9c67d97d6f 82 q31_t * pSrc,
emh203 0:3d9c67d97d6f 83 q31_t * pRef,
emh203 0:3d9c67d97d6f 84 q31_t * pOut,
emh203 0:3d9c67d97d6f 85 q31_t * pErr,
emh203 0:3d9c67d97d6f 86 uint32_t blockSize)
emh203 0:3d9c67d97d6f 87 {
emh203 0:3d9c67d97d6f 88 q31_t *pState = S->pState; /* State pointer */
emh203 0:3d9c67d97d6f 89 q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emh203 0:3d9c67d97d6f 90 q31_t *pStateCurnt; /* Points to the current sample of the state */
emh203 0:3d9c67d97d6f 91 q31_t *px, *pb; /* Temporary pointers for state and coefficient buffers */
emh203 0:3d9c67d97d6f 92 q31_t mu = S->mu; /* Adaptive factor */
emh203 0:3d9c67d97d6f 93 uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */
emh203 0:3d9c67d97d6f 94 uint32_t tapCnt, blkCnt; /* Loop counters */
emh203 0:3d9c67d97d6f 95 q63_t energy; /* Energy of the input */
emh203 0:3d9c67d97d6f 96 q63_t acc; /* Accumulator */
emh203 0:3d9c67d97d6f 97 q31_t e = 0, d = 0; /* error, reference data sample */
emh203 0:3d9c67d97d6f 98 q31_t w = 0, in; /* weight factor and state */
emh203 0:3d9c67d97d6f 99 q31_t x0; /* temporary variable to hold input sample */
emh203 0:3d9c67d97d6f 100 // uint32_t shift = 32u - ((uint32_t) S->postShift + 1u); /* Shift to be applied to the output */
emh203 0:3d9c67d97d6f 101 q31_t errorXmu, oneByEnergy; /* Temporary variables to store error and mu product and reciprocal of energy */
emh203 0:3d9c67d97d6f 102 q31_t postShift; /* Post shift to be applied to weight after reciprocal calculation */
emh203 0:3d9c67d97d6f 103 q31_t coef; /* Temporary variable for coef */
emh203 0:3d9c67d97d6f 104 q31_t acc_l, acc_h; /* temporary input */
emh203 0:3d9c67d97d6f 105 uint32_t uShift = ((uint32_t) S->postShift + 1u);
emh203 0:3d9c67d97d6f 106 uint32_t lShift = 32u - uShift; /* Shift to be applied to the output */
emh203 0:3d9c67d97d6f 107
emh203 0:3d9c67d97d6f 108 energy = S->energy;
emh203 0:3d9c67d97d6f 109 x0 = S->x0;
emh203 0:3d9c67d97d6f 110
emh203 0:3d9c67d97d6f 111 /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */
emh203 0:3d9c67d97d6f 112 /* pStateCurnt points to the location where the new input data should be written */
emh203 0:3d9c67d97d6f 113 pStateCurnt = &(S->pState[(numTaps - 1u)]);
emh203 0:3d9c67d97d6f 114
emh203 0:3d9c67d97d6f 115 /* Loop over blockSize number of values */
emh203 0:3d9c67d97d6f 116 blkCnt = blockSize;
emh203 0:3d9c67d97d6f 117
emh203 0:3d9c67d97d6f 118
emh203 0:3d9c67d97d6f 119 #ifndef ARM_MATH_CM0_FAMILY
emh203 0:3d9c67d97d6f 120
emh203 0:3d9c67d97d6f 121 /* Run the below code for Cortex-M4 and Cortex-M3 */
emh203 0:3d9c67d97d6f 122
emh203 0:3d9c67d97d6f 123 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 124 {
emh203 0:3d9c67d97d6f 125
emh203 0:3d9c67d97d6f 126 /* Copy the new input sample into the state buffer */
emh203 0:3d9c67d97d6f 127 *pStateCurnt++ = *pSrc;
emh203 0:3d9c67d97d6f 128
emh203 0:3d9c67d97d6f 129 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 130 px = pState;
emh203 0:3d9c67d97d6f 131
emh203 0:3d9c67d97d6f 132 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 133 pb = (pCoeffs);
emh203 0:3d9c67d97d6f 134
emh203 0:3d9c67d97d6f 135 /* Read the sample from input buffer */
emh203 0:3d9c67d97d6f 136 in = *pSrc++;
emh203 0:3d9c67d97d6f 137
emh203 0:3d9c67d97d6f 138 /* Update the energy calculation */
emh203 0:3d9c67d97d6f 139 energy = (q31_t) ((((q63_t) energy << 32) -
emh203 0:3d9c67d97d6f 140 (((q63_t) x0 * x0) << 1)) >> 32);
emh203 0:3d9c67d97d6f 141 energy = (q31_t) (((((q63_t) in * in) << 1) + (energy << 32)) >> 32);
emh203 0:3d9c67d97d6f 142
emh203 0:3d9c67d97d6f 143 /* Set the accumulator to zero */
emh203 0:3d9c67d97d6f 144 acc = 0;
emh203 0:3d9c67d97d6f 145
emh203 0:3d9c67d97d6f 146 /* Loop unrolling. Process 4 taps at a time. */
emh203 0:3d9c67d97d6f 147 tapCnt = numTaps >> 2;
emh203 0:3d9c67d97d6f 148
emh203 0:3d9c67d97d6f 149 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 150 {
emh203 0:3d9c67d97d6f 151 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 152 acc += ((q63_t) (*px++)) * (*pb++);
emh203 0:3d9c67d97d6f 153 acc += ((q63_t) (*px++)) * (*pb++);
emh203 0:3d9c67d97d6f 154 acc += ((q63_t) (*px++)) * (*pb++);
emh203 0:3d9c67d97d6f 155 acc += ((q63_t) (*px++)) * (*pb++);
emh203 0:3d9c67d97d6f 156
emh203 0:3d9c67d97d6f 157 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 158 tapCnt--;
emh203 0:3d9c67d97d6f 159 }
emh203 0:3d9c67d97d6f 160
emh203 0:3d9c67d97d6f 161 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emh203 0:3d9c67d97d6f 162 tapCnt = numTaps % 0x4u;
emh203 0:3d9c67d97d6f 163
emh203 0:3d9c67d97d6f 164 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 165 {
emh203 0:3d9c67d97d6f 166 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 167 acc += ((q63_t) (*px++)) * (*pb++);
emh203 0:3d9c67d97d6f 168
emh203 0:3d9c67d97d6f 169 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 170 tapCnt--;
emh203 0:3d9c67d97d6f 171 }
emh203 0:3d9c67d97d6f 172
emh203 0:3d9c67d97d6f 173 /* Converting the result to 1.31 format */
emh203 0:3d9c67d97d6f 174 /* Calc lower part of acc */
emh203 0:3d9c67d97d6f 175 acc_l = acc & 0xffffffff;
emh203 0:3d9c67d97d6f 176
emh203 0:3d9c67d97d6f 177 /* Calc upper part of acc */
emh203 0:3d9c67d97d6f 178 acc_h = (acc >> 32) & 0xffffffff;
emh203 0:3d9c67d97d6f 179
emh203 0:3d9c67d97d6f 180 acc = (uint32_t) acc_l >> lShift | acc_h << uShift;
emh203 0:3d9c67d97d6f 181
emh203 0:3d9c67d97d6f 182 /* Store the result from accumulator into the destination buffer. */
emh203 0:3d9c67d97d6f 183 *pOut++ = (q31_t) acc;
emh203 0:3d9c67d97d6f 184
emh203 0:3d9c67d97d6f 185 /* Compute and store error */
emh203 0:3d9c67d97d6f 186 d = *pRef++;
emh203 0:3d9c67d97d6f 187 e = d - (q31_t) acc;
emh203 0:3d9c67d97d6f 188 *pErr++ = e;
emh203 0:3d9c67d97d6f 189
emh203 0:3d9c67d97d6f 190 /* Calculates the reciprocal of energy */
emh203 0:3d9c67d97d6f 191 postShift = arm_recip_q31(energy + DELTA_Q31,
emh203 0:3d9c67d97d6f 192 &oneByEnergy, &S->recipTable[0]);
emh203 0:3d9c67d97d6f 193
emh203 0:3d9c67d97d6f 194 /* Calculation of product of (e * mu) */
emh203 0:3d9c67d97d6f 195 errorXmu = (q31_t) (((q63_t) e * mu) >> 31);
emh203 0:3d9c67d97d6f 196
emh203 0:3d9c67d97d6f 197 /* Weighting factor for the normalized version */
emh203 0:3d9c67d97d6f 198 w = clip_q63_to_q31(((q63_t) errorXmu * oneByEnergy) >> (31 - postShift));
emh203 0:3d9c67d97d6f 199
emh203 0:3d9c67d97d6f 200 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 201 px = pState;
emh203 0:3d9c67d97d6f 202
emh203 0:3d9c67d97d6f 203 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 204 pb = (pCoeffs);
emh203 0:3d9c67d97d6f 205
emh203 0:3d9c67d97d6f 206 /* Loop unrolling. Process 4 taps at a time. */
emh203 0:3d9c67d97d6f 207 tapCnt = numTaps >> 2;
emh203 0:3d9c67d97d6f 208
emh203 0:3d9c67d97d6f 209 /* Update filter coefficients */
emh203 0:3d9c67d97d6f 210 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 211 {
emh203 0:3d9c67d97d6f 212 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 213
emh203 0:3d9c67d97d6f 214 /* coef is in 2.30 format */
emh203 0:3d9c67d97d6f 215 coef = (q31_t) (((q63_t) w * (*px++)) >> (32));
emh203 0:3d9c67d97d6f 216 /* get coef in 1.31 format by left shifting */
emh203 0:3d9c67d97d6f 217 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emh203 0:3d9c67d97d6f 218 /* update coefficient buffer to next coefficient */
emh203 0:3d9c67d97d6f 219 pb++;
emh203 0:3d9c67d97d6f 220
emh203 0:3d9c67d97d6f 221 coef = (q31_t) (((q63_t) w * (*px++)) >> (32));
emh203 0:3d9c67d97d6f 222 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emh203 0:3d9c67d97d6f 223 pb++;
emh203 0:3d9c67d97d6f 224
emh203 0:3d9c67d97d6f 225 coef = (q31_t) (((q63_t) w * (*px++)) >> (32));
emh203 0:3d9c67d97d6f 226 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emh203 0:3d9c67d97d6f 227 pb++;
emh203 0:3d9c67d97d6f 228
emh203 0:3d9c67d97d6f 229 coef = (q31_t) (((q63_t) w * (*px++)) >> (32));
emh203 0:3d9c67d97d6f 230 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emh203 0:3d9c67d97d6f 231 pb++;
emh203 0:3d9c67d97d6f 232
emh203 0:3d9c67d97d6f 233 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 234 tapCnt--;
emh203 0:3d9c67d97d6f 235 }
emh203 0:3d9c67d97d6f 236
emh203 0:3d9c67d97d6f 237 /* If the filter length is not a multiple of 4, compute the remaining filter taps */
emh203 0:3d9c67d97d6f 238 tapCnt = numTaps % 0x4u;
emh203 0:3d9c67d97d6f 239
emh203 0:3d9c67d97d6f 240 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 241 {
emh203 0:3d9c67d97d6f 242 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 243 coef = (q31_t) (((q63_t) w * (*px++)) >> (32));
emh203 0:3d9c67d97d6f 244 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emh203 0:3d9c67d97d6f 245 pb++;
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 + 1;
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 = (q31_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 /* Loop unrolling for (numTaps - 1u) samples copy */
emh203 0:3d9c67d97d6f 273 tapCnt = (numTaps - 1u) >> 2u;
emh203 0:3d9c67d97d6f 274
emh203 0:3d9c67d97d6f 275 /* copy data */
emh203 0:3d9c67d97d6f 276 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 277 {
emh203 0:3d9c67d97d6f 278 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 279 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 280 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 281 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 282
emh203 0:3d9c67d97d6f 283 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 284 tapCnt--;
emh203 0:3d9c67d97d6f 285 }
emh203 0:3d9c67d97d6f 286
emh203 0:3d9c67d97d6f 287 /* Calculate remaining number of copies */
emh203 0:3d9c67d97d6f 288 tapCnt = (numTaps - 1u) % 0x4u;
emh203 0:3d9c67d97d6f 289
emh203 0:3d9c67d97d6f 290 /* Copy the remaining q31_t data */
emh203 0:3d9c67d97d6f 291 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 292 {
emh203 0:3d9c67d97d6f 293 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 294
emh203 0:3d9c67d97d6f 295 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 296 tapCnt--;
emh203 0:3d9c67d97d6f 297 }
emh203 0:3d9c67d97d6f 298
emh203 0:3d9c67d97d6f 299 #else
emh203 0:3d9c67d97d6f 300
emh203 0:3d9c67d97d6f 301 /* Run the below code for Cortex-M0 */
emh203 0:3d9c67d97d6f 302
emh203 0:3d9c67d97d6f 303 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 304 {
emh203 0:3d9c67d97d6f 305
emh203 0:3d9c67d97d6f 306 /* Copy the new input sample into the state buffer */
emh203 0:3d9c67d97d6f 307 *pStateCurnt++ = *pSrc;
emh203 0:3d9c67d97d6f 308
emh203 0:3d9c67d97d6f 309 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 310 px = pState;
emh203 0:3d9c67d97d6f 311
emh203 0:3d9c67d97d6f 312 /* Initialize pCoeffs pointer */
emh203 0:3d9c67d97d6f 313 pb = pCoeffs;
emh203 0:3d9c67d97d6f 314
emh203 0:3d9c67d97d6f 315 /* Read the sample from input buffer */
emh203 0:3d9c67d97d6f 316 in = *pSrc++;
emh203 0:3d9c67d97d6f 317
emh203 0:3d9c67d97d6f 318 /* Update the energy calculation */
emh203 0:3d9c67d97d6f 319 energy =
emh203 0:3d9c67d97d6f 320 (q31_t) ((((q63_t) energy << 32) - (((q63_t) x0 * x0) << 1)) >> 32);
emh203 0:3d9c67d97d6f 321 energy = (q31_t) (((((q63_t) in * in) << 1) + (energy << 32)) >> 32);
emh203 0:3d9c67d97d6f 322
emh203 0:3d9c67d97d6f 323 /* Set the accumulator to zero */
emh203 0:3d9c67d97d6f 324 acc = 0;
emh203 0:3d9c67d97d6f 325
emh203 0:3d9c67d97d6f 326 /* Loop over numTaps number of values */
emh203 0:3d9c67d97d6f 327 tapCnt = numTaps;
emh203 0:3d9c67d97d6f 328
emh203 0:3d9c67d97d6f 329 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 330 {
emh203 0:3d9c67d97d6f 331 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 332 acc += ((q63_t) (*px++)) * (*pb++);
emh203 0:3d9c67d97d6f 333
emh203 0:3d9c67d97d6f 334 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 335 tapCnt--;
emh203 0:3d9c67d97d6f 336 }
emh203 0:3d9c67d97d6f 337
emh203 0:3d9c67d97d6f 338 /* Converting the result to 1.31 format */
emh203 0:3d9c67d97d6f 339 /* Converting the result to 1.31 format */
emh203 0:3d9c67d97d6f 340 /* Calc lower part of acc */
emh203 0:3d9c67d97d6f 341 acc_l = acc & 0xffffffff;
emh203 0:3d9c67d97d6f 342
emh203 0:3d9c67d97d6f 343 /* Calc upper part of acc */
emh203 0:3d9c67d97d6f 344 acc_h = (acc >> 32) & 0xffffffff;
emh203 0:3d9c67d97d6f 345
emh203 0:3d9c67d97d6f 346 acc = (uint32_t) acc_l >> lShift | acc_h << uShift;
emh203 0:3d9c67d97d6f 347
emh203 0:3d9c67d97d6f 348
emh203 0:3d9c67d97d6f 349 //acc = (q31_t) (acc >> shift);
emh203 0:3d9c67d97d6f 350
emh203 0:3d9c67d97d6f 351 /* Store the result from accumulator into the destination buffer. */
emh203 0:3d9c67d97d6f 352 *pOut++ = (q31_t) acc;
emh203 0:3d9c67d97d6f 353
emh203 0:3d9c67d97d6f 354 /* Compute and store error */
emh203 0:3d9c67d97d6f 355 d = *pRef++;
emh203 0:3d9c67d97d6f 356 e = d - (q31_t) acc;
emh203 0:3d9c67d97d6f 357 *pErr++ = e;
emh203 0:3d9c67d97d6f 358
emh203 0:3d9c67d97d6f 359 /* Calculates the reciprocal of energy */
emh203 0:3d9c67d97d6f 360 postShift =
emh203 0:3d9c67d97d6f 361 arm_recip_q31(energy + DELTA_Q31, &oneByEnergy, &S->recipTable[0]);
emh203 0:3d9c67d97d6f 362
emh203 0:3d9c67d97d6f 363 /* Calculation of product of (e * mu) */
emh203 0:3d9c67d97d6f 364 errorXmu = (q31_t) (((q63_t) e * mu) >> 31);
emh203 0:3d9c67d97d6f 365
emh203 0:3d9c67d97d6f 366 /* Weighting factor for the normalized version */
emh203 0:3d9c67d97d6f 367 w = clip_q63_to_q31(((q63_t) errorXmu * oneByEnergy) >> (31 - postShift));
emh203 0:3d9c67d97d6f 368
emh203 0:3d9c67d97d6f 369 /* Initialize pState pointer */
emh203 0:3d9c67d97d6f 370 px = pState;
emh203 0:3d9c67d97d6f 371
emh203 0:3d9c67d97d6f 372 /* Initialize coeff pointer */
emh203 0:3d9c67d97d6f 373 pb = (pCoeffs);
emh203 0:3d9c67d97d6f 374
emh203 0:3d9c67d97d6f 375 /* Loop over numTaps number of values */
emh203 0:3d9c67d97d6f 376 tapCnt = numTaps;
emh203 0:3d9c67d97d6f 377
emh203 0:3d9c67d97d6f 378 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 379 {
emh203 0:3d9c67d97d6f 380 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 381 /* coef is in 2.30 format */
emh203 0:3d9c67d97d6f 382 coef = (q31_t) (((q63_t) w * (*px++)) >> (32));
emh203 0:3d9c67d97d6f 383 /* get coef in 1.31 format by left shifting */
emh203 0:3d9c67d97d6f 384 *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u));
emh203 0:3d9c67d97d6f 385 /* update coefficient buffer to next coefficient */
emh203 0:3d9c67d97d6f 386 pb++;
emh203 0:3d9c67d97d6f 387
emh203 0:3d9c67d97d6f 388 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 389 tapCnt--;
emh203 0:3d9c67d97d6f 390 }
emh203 0:3d9c67d97d6f 391
emh203 0:3d9c67d97d6f 392 /* Read the sample from state buffer */
emh203 0:3d9c67d97d6f 393 x0 = *pState;
emh203 0:3d9c67d97d6f 394
emh203 0:3d9c67d97d6f 395 /* Advance state pointer by 1 for the next sample */
emh203 0:3d9c67d97d6f 396 pState = pState + 1;
emh203 0:3d9c67d97d6f 397
emh203 0:3d9c67d97d6f 398 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 399 blkCnt--;
emh203 0:3d9c67d97d6f 400 }
emh203 0:3d9c67d97d6f 401
emh203 0:3d9c67d97d6f 402 /* Save energy and x0 values for the next frame */
emh203 0:3d9c67d97d6f 403 S->energy = (q31_t) energy;
emh203 0:3d9c67d97d6f 404 S->x0 = x0;
emh203 0:3d9c67d97d6f 405
emh203 0:3d9c67d97d6f 406 /* Processing is complete. Now copy the last numTaps - 1 samples to the
emh203 0:3d9c67d97d6f 407 start of the state buffer. This prepares the state buffer for the
emh203 0:3d9c67d97d6f 408 next function call. */
emh203 0:3d9c67d97d6f 409
emh203 0:3d9c67d97d6f 410 /* Points to the start of the pState buffer */
emh203 0:3d9c67d97d6f 411 pStateCurnt = S->pState;
emh203 0:3d9c67d97d6f 412
emh203 0:3d9c67d97d6f 413 /* Loop for (numTaps - 1u) samples copy */
emh203 0:3d9c67d97d6f 414 tapCnt = (numTaps - 1u);
emh203 0:3d9c67d97d6f 415
emh203 0:3d9c67d97d6f 416 /* Copy the remaining q31_t data */
emh203 0:3d9c67d97d6f 417 while(tapCnt > 0u)
emh203 0:3d9c67d97d6f 418 {
emh203 0:3d9c67d97d6f 419 *pStateCurnt++ = *pState++;
emh203 0:3d9c67d97d6f 420
emh203 0:3d9c67d97d6f 421 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 422 tapCnt--;
emh203 0:3d9c67d97d6f 423 }
emh203 0:3d9c67d97d6f 424
emh203 0:3d9c67d97d6f 425 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emh203 0:3d9c67d97d6f 426
emh203 0:3d9c67d97d6f 427 }
emh203 0:3d9c67d97d6f 428
emh203 0:3d9c67d97d6f 429 /**
emh203 0:3d9c67d97d6f 430 * @} end of LMS_NORM group
emh203 0:3d9c67d97d6f 431 */