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
FilteringFunctions/arm_lms_q31.c@0:3d9c67d97d6f, 2014-07-28 (annotated)
- 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?
User | Revision | Line number | New 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_q31.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Processing function for the Q31 LMS 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 | * @ingroup groupFilters |
emh203 | 0:3d9c67d97d6f | 44 | */ |
emh203 | 0:3d9c67d97d6f | 45 | |
emh203 | 0:3d9c67d97d6f | 46 | /** |
emh203 | 0:3d9c67d97d6f | 47 | * @addtogroup LMS |
emh203 | 0:3d9c67d97d6f | 48 | * @{ |
emh203 | 0:3d9c67d97d6f | 49 | */ |
emh203 | 0:3d9c67d97d6f | 50 | |
emh203 | 0:3d9c67d97d6f | 51 | /** |
emh203 | 0:3d9c67d97d6f | 52 | * @brief Processing function for Q31 LMS filter. |
emh203 | 0:3d9c67d97d6f | 53 | * @param[in] *S points to an instance of the Q15 LMS filter structure. |
emh203 | 0:3d9c67d97d6f | 54 | * @param[in] *pSrc points to the block of input data. |
emh203 | 0:3d9c67d97d6f | 55 | * @param[in] *pRef points to the block of reference data. |
emh203 | 0:3d9c67d97d6f | 56 | * @param[out] *pOut points to the block of output data. |
emh203 | 0:3d9c67d97d6f | 57 | * @param[out] *pErr points to the block of error data. |
emh203 | 0:3d9c67d97d6f | 58 | * @param[in] blockSize number of samples to process. |
emh203 | 0:3d9c67d97d6f | 59 | * @return none. |
emh203 | 0:3d9c67d97d6f | 60 | * |
emh203 | 0:3d9c67d97d6f | 61 | * \par Scaling and Overflow Behavior: |
emh203 | 0:3d9c67d97d6f | 62 | * The function is implemented using an internal 64-bit accumulator. |
emh203 | 0:3d9c67d97d6f | 63 | * The accumulator has a 2.62 format and maintains full precision of the intermediate |
emh203 | 0:3d9c67d97d6f | 64 | * multiplication results but provides only a single guard bit. |
emh203 | 0:3d9c67d97d6f | 65 | * Thus, if the accumulator result overflows it wraps around rather than clips. |
emh203 | 0:3d9c67d97d6f | 66 | * In order to avoid overflows completely the input signal must be scaled down by |
emh203 | 0:3d9c67d97d6f | 67 | * log2(numTaps) bits. |
emh203 | 0:3d9c67d97d6f | 68 | * The reference signal should not be scaled down. |
emh203 | 0:3d9c67d97d6f | 69 | * After all multiply-accumulates are performed, the 2.62 accumulator is shifted |
emh203 | 0:3d9c67d97d6f | 70 | * and saturated to 1.31 format to yield the final result. |
emh203 | 0:3d9c67d97d6f | 71 | * The output signal and error signal are in 1.31 format. |
emh203 | 0:3d9c67d97d6f | 72 | * |
emh203 | 0:3d9c67d97d6f | 73 | * \par |
emh203 | 0:3d9c67d97d6f | 74 | * In this filter, filter coefficients are updated for each sample and the updation of filter cofficients are saturted. |
emh203 | 0:3d9c67d97d6f | 75 | */ |
emh203 | 0:3d9c67d97d6f | 76 | |
emh203 | 0:3d9c67d97d6f | 77 | void arm_lms_q31( |
emh203 | 0:3d9c67d97d6f | 78 | const arm_lms_instance_q31 * S, |
emh203 | 0:3d9c67d97d6f | 79 | q31_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 80 | q31_t * pRef, |
emh203 | 0:3d9c67d97d6f | 81 | q31_t * pOut, |
emh203 | 0:3d9c67d97d6f | 82 | q31_t * pErr, |
emh203 | 0:3d9c67d97d6f | 83 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 84 | { |
emh203 | 0:3d9c67d97d6f | 85 | q31_t *pState = S->pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 86 | uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
emh203 | 0:3d9c67d97d6f | 87 | q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 88 | q31_t *pStateCurnt; /* Points to the current sample of the state */ |
emh203 | 0:3d9c67d97d6f | 89 | q31_t mu = S->mu; /* Adaptive factor */ |
emh203 | 0:3d9c67d97d6f | 90 | q31_t *px; /* Temporary pointer for state */ |
emh203 | 0:3d9c67d97d6f | 91 | q31_t *pb; /* Temporary pointer for coefficient buffer */ |
emh203 | 0:3d9c67d97d6f | 92 | uint32_t tapCnt, blkCnt; /* Loop counters */ |
emh203 | 0:3d9c67d97d6f | 93 | q63_t acc; /* Accumulator */ |
emh203 | 0:3d9c67d97d6f | 94 | q31_t e = 0; /* error of data sample */ |
emh203 | 0:3d9c67d97d6f | 95 | q31_t alpha; /* Intermediate constant for taps update */ |
emh203 | 0:3d9c67d97d6f | 96 | q31_t coef; /* Temporary variable for coef */ |
emh203 | 0:3d9c67d97d6f | 97 | q31_t acc_l, acc_h; /* temporary input */ |
emh203 | 0:3d9c67d97d6f | 98 | uint32_t uShift = ((uint32_t) S->postShift + 1u); |
emh203 | 0:3d9c67d97d6f | 99 | uint32_t lShift = 32u - uShift; /* Shift to be applied to the output */ |
emh203 | 0:3d9c67d97d6f | 100 | |
emh203 | 0:3d9c67d97d6f | 101 | /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ |
emh203 | 0:3d9c67d97d6f | 102 | /* pStateCurnt points to the location where the new input data should be written */ |
emh203 | 0:3d9c67d97d6f | 103 | pStateCurnt = &(S->pState[(numTaps - 1u)]); |
emh203 | 0:3d9c67d97d6f | 104 | |
emh203 | 0:3d9c67d97d6f | 105 | /* Initializing blkCnt with blockSize */ |
emh203 | 0:3d9c67d97d6f | 106 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 107 | |
emh203 | 0:3d9c67d97d6f | 108 | |
emh203 | 0:3d9c67d97d6f | 109 | #ifndef ARM_MATH_CM0_FAMILY |
emh203 | 0:3d9c67d97d6f | 110 | |
emh203 | 0:3d9c67d97d6f | 111 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emh203 | 0:3d9c67d97d6f | 112 | |
emh203 | 0:3d9c67d97d6f | 113 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 114 | { |
emh203 | 0:3d9c67d97d6f | 115 | /* Copy the new input sample into the state buffer */ |
emh203 | 0:3d9c67d97d6f | 116 | *pStateCurnt++ = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 117 | |
emh203 | 0:3d9c67d97d6f | 118 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 119 | px = pState; |
emh203 | 0:3d9c67d97d6f | 120 | |
emh203 | 0:3d9c67d97d6f | 121 | /* Initialize coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 122 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 123 | |
emh203 | 0:3d9c67d97d6f | 124 | /* Set the accumulator to zero */ |
emh203 | 0:3d9c67d97d6f | 125 | acc = 0; |
emh203 | 0:3d9c67d97d6f | 126 | |
emh203 | 0:3d9c67d97d6f | 127 | /* Loop unrolling. Process 4 taps at a time. */ |
emh203 | 0:3d9c67d97d6f | 128 | tapCnt = numTaps >> 2; |
emh203 | 0:3d9c67d97d6f | 129 | |
emh203 | 0:3d9c67d97d6f | 130 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 131 | { |
emh203 | 0:3d9c67d97d6f | 132 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 133 | /* acc += b[N] * x[n-N] */ |
emh203 | 0:3d9c67d97d6f | 134 | acc += ((q63_t) (*px++)) * (*pb++); |
emh203 | 0:3d9c67d97d6f | 135 | |
emh203 | 0:3d9c67d97d6f | 136 | /* acc += b[N-1] * x[n-N-1] */ |
emh203 | 0:3d9c67d97d6f | 137 | acc += ((q63_t) (*px++)) * (*pb++); |
emh203 | 0:3d9c67d97d6f | 138 | |
emh203 | 0:3d9c67d97d6f | 139 | /* acc += b[N-2] * x[n-N-2] */ |
emh203 | 0:3d9c67d97d6f | 140 | acc += ((q63_t) (*px++)) * (*pb++); |
emh203 | 0:3d9c67d97d6f | 141 | |
emh203 | 0:3d9c67d97d6f | 142 | /* acc += b[N-3] * x[n-N-3] */ |
emh203 | 0:3d9c67d97d6f | 143 | acc += ((q63_t) (*px++)) * (*pb++); |
emh203 | 0:3d9c67d97d6f | 144 | |
emh203 | 0:3d9c67d97d6f | 145 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 146 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 147 | } |
emh203 | 0:3d9c67d97d6f | 148 | |
emh203 | 0:3d9c67d97d6f | 149 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
emh203 | 0:3d9c67d97d6f | 150 | tapCnt = numTaps % 0x4u; |
emh203 | 0:3d9c67d97d6f | 151 | |
emh203 | 0:3d9c67d97d6f | 152 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 153 | { |
emh203 | 0:3d9c67d97d6f | 154 | /* Perform the multiply-accumulate */ |
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 | /* Converting the result to 1.31 format */ |
emh203 | 0:3d9c67d97d6f | 162 | /* Calc lower part of acc */ |
emh203 | 0:3d9c67d97d6f | 163 | acc_l = acc & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 164 | |
emh203 | 0:3d9c67d97d6f | 165 | /* Calc upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 166 | acc_h = (acc >> 32) & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 167 | |
emh203 | 0:3d9c67d97d6f | 168 | acc = (uint32_t) acc_l >> lShift | acc_h << uShift; |
emh203 | 0:3d9c67d97d6f | 169 | |
emh203 | 0:3d9c67d97d6f | 170 | /* Store the result from accumulator into the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 171 | *pOut++ = (q31_t) acc; |
emh203 | 0:3d9c67d97d6f | 172 | |
emh203 | 0:3d9c67d97d6f | 173 | /* Compute and store error */ |
emh203 | 0:3d9c67d97d6f | 174 | e = *pRef++ - (q31_t) acc; |
emh203 | 0:3d9c67d97d6f | 175 | |
emh203 | 0:3d9c67d97d6f | 176 | *pErr++ = (q31_t) e; |
emh203 | 0:3d9c67d97d6f | 177 | |
emh203 | 0:3d9c67d97d6f | 178 | /* Compute alpha i.e. intermediate constant for taps update */ |
emh203 | 0:3d9c67d97d6f | 179 | alpha = (q31_t) (((q63_t) e * mu) >> 31); |
emh203 | 0:3d9c67d97d6f | 180 | |
emh203 | 0:3d9c67d97d6f | 181 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 182 | /* Advance state pointer by 1 for the next sample */ |
emh203 | 0:3d9c67d97d6f | 183 | px = pState++; |
emh203 | 0:3d9c67d97d6f | 184 | |
emh203 | 0:3d9c67d97d6f | 185 | /* Initialize coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 186 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 187 | |
emh203 | 0:3d9c67d97d6f | 188 | /* Loop unrolling. Process 4 taps at a time. */ |
emh203 | 0:3d9c67d97d6f | 189 | tapCnt = numTaps >> 2; |
emh203 | 0:3d9c67d97d6f | 190 | |
emh203 | 0:3d9c67d97d6f | 191 | /* Update filter coefficients */ |
emh203 | 0:3d9c67d97d6f | 192 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 193 | { |
emh203 | 0:3d9c67d97d6f | 194 | /* coef is in 2.30 format */ |
emh203 | 0:3d9c67d97d6f | 195 | coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32)); |
emh203 | 0:3d9c67d97d6f | 196 | /* get coef in 1.31 format by left shifting */ |
emh203 | 0:3d9c67d97d6f | 197 | *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u)); |
emh203 | 0:3d9c67d97d6f | 198 | /* update coefficient buffer to next coefficient */ |
emh203 | 0:3d9c67d97d6f | 199 | pb++; |
emh203 | 0:3d9c67d97d6f | 200 | |
emh203 | 0:3d9c67d97d6f | 201 | coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32)); |
emh203 | 0:3d9c67d97d6f | 202 | *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u)); |
emh203 | 0:3d9c67d97d6f | 203 | pb++; |
emh203 | 0:3d9c67d97d6f | 204 | |
emh203 | 0:3d9c67d97d6f | 205 | coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32)); |
emh203 | 0:3d9c67d97d6f | 206 | *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u)); |
emh203 | 0:3d9c67d97d6f | 207 | pb++; |
emh203 | 0:3d9c67d97d6f | 208 | |
emh203 | 0:3d9c67d97d6f | 209 | coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32)); |
emh203 | 0:3d9c67d97d6f | 210 | *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u)); |
emh203 | 0:3d9c67d97d6f | 211 | pb++; |
emh203 | 0:3d9c67d97d6f | 212 | |
emh203 | 0:3d9c67d97d6f | 213 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 214 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 215 | } |
emh203 | 0:3d9c67d97d6f | 216 | |
emh203 | 0:3d9c67d97d6f | 217 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
emh203 | 0:3d9c67d97d6f | 218 | tapCnt = numTaps % 0x4u; |
emh203 | 0:3d9c67d97d6f | 219 | |
emh203 | 0:3d9c67d97d6f | 220 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 221 | { |
emh203 | 0:3d9c67d97d6f | 222 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 223 | coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32)); |
emh203 | 0:3d9c67d97d6f | 224 | *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u)); |
emh203 | 0:3d9c67d97d6f | 225 | pb++; |
emh203 | 0:3d9c67d97d6f | 226 | |
emh203 | 0:3d9c67d97d6f | 227 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 228 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 229 | } |
emh203 | 0:3d9c67d97d6f | 230 | |
emh203 | 0:3d9c67d97d6f | 231 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 232 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 233 | } |
emh203 | 0:3d9c67d97d6f | 234 | |
emh203 | 0:3d9c67d97d6f | 235 | /* Processing is complete. Now copy the last numTaps - 1 samples to the |
emh203 | 0:3d9c67d97d6f | 236 | satrt of the state buffer. This prepares the state buffer for the |
emh203 | 0:3d9c67d97d6f | 237 | next function call. */ |
emh203 | 0:3d9c67d97d6f | 238 | |
emh203 | 0:3d9c67d97d6f | 239 | /* Points to the start of the pState buffer */ |
emh203 | 0:3d9c67d97d6f | 240 | pStateCurnt = S->pState; |
emh203 | 0:3d9c67d97d6f | 241 | |
emh203 | 0:3d9c67d97d6f | 242 | /* Loop unrolling for (numTaps - 1u) samples copy */ |
emh203 | 0:3d9c67d97d6f | 243 | tapCnt = (numTaps - 1u) >> 2u; |
emh203 | 0:3d9c67d97d6f | 244 | |
emh203 | 0:3d9c67d97d6f | 245 | /* copy data */ |
emh203 | 0:3d9c67d97d6f | 246 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 247 | { |
emh203 | 0:3d9c67d97d6f | 248 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 249 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 250 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 251 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 252 | |
emh203 | 0:3d9c67d97d6f | 253 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 254 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 255 | } |
emh203 | 0:3d9c67d97d6f | 256 | |
emh203 | 0:3d9c67d97d6f | 257 | /* Calculate remaining number of copies */ |
emh203 | 0:3d9c67d97d6f | 258 | tapCnt = (numTaps - 1u) % 0x4u; |
emh203 | 0:3d9c67d97d6f | 259 | |
emh203 | 0:3d9c67d97d6f | 260 | /* Copy the remaining q31_t data */ |
emh203 | 0:3d9c67d97d6f | 261 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 262 | { |
emh203 | 0:3d9c67d97d6f | 263 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 264 | |
emh203 | 0:3d9c67d97d6f | 265 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 266 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 267 | } |
emh203 | 0:3d9c67d97d6f | 268 | |
emh203 | 0:3d9c67d97d6f | 269 | #else |
emh203 | 0:3d9c67d97d6f | 270 | |
emh203 | 0:3d9c67d97d6f | 271 | /* Run the below code for Cortex-M0 */ |
emh203 | 0:3d9c67d97d6f | 272 | |
emh203 | 0:3d9c67d97d6f | 273 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 274 | { |
emh203 | 0:3d9c67d97d6f | 275 | /* Copy the new input sample into the state buffer */ |
emh203 | 0:3d9c67d97d6f | 276 | *pStateCurnt++ = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 277 | |
emh203 | 0:3d9c67d97d6f | 278 | /* Initialize pState pointer */ |
emh203 | 0:3d9c67d97d6f | 279 | px = pState; |
emh203 | 0:3d9c67d97d6f | 280 | |
emh203 | 0:3d9c67d97d6f | 281 | /* Initialize pCoeffs pointer */ |
emh203 | 0:3d9c67d97d6f | 282 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 283 | |
emh203 | 0:3d9c67d97d6f | 284 | /* Set the accumulator to zero */ |
emh203 | 0:3d9c67d97d6f | 285 | acc = 0; |
emh203 | 0:3d9c67d97d6f | 286 | |
emh203 | 0:3d9c67d97d6f | 287 | /* Loop over numTaps number of values */ |
emh203 | 0:3d9c67d97d6f | 288 | tapCnt = numTaps; |
emh203 | 0:3d9c67d97d6f | 289 | |
emh203 | 0:3d9c67d97d6f | 290 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 291 | { |
emh203 | 0:3d9c67d97d6f | 292 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 293 | acc += ((q63_t) (*px++)) * (*pb++); |
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 | /* Converting the result to 1.31 format */ |
emh203 | 0:3d9c67d97d6f | 300 | /* Store the result from accumulator into the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 301 | /* Calc lower part of acc */ |
emh203 | 0:3d9c67d97d6f | 302 | acc_l = acc & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 303 | |
emh203 | 0:3d9c67d97d6f | 304 | /* Calc upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 305 | acc_h = (acc >> 32) & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 306 | |
emh203 | 0:3d9c67d97d6f | 307 | acc = (uint32_t) acc_l >> lShift | acc_h << uShift; |
emh203 | 0:3d9c67d97d6f | 308 | |
emh203 | 0:3d9c67d97d6f | 309 | *pOut++ = (q31_t) acc; |
emh203 | 0:3d9c67d97d6f | 310 | |
emh203 | 0:3d9c67d97d6f | 311 | /* Compute and store error */ |
emh203 | 0:3d9c67d97d6f | 312 | e = *pRef++ - (q31_t) acc; |
emh203 | 0:3d9c67d97d6f | 313 | |
emh203 | 0:3d9c67d97d6f | 314 | *pErr++ = (q31_t) e; |
emh203 | 0:3d9c67d97d6f | 315 | |
emh203 | 0:3d9c67d97d6f | 316 | /* Weighting factor for the LMS version */ |
emh203 | 0:3d9c67d97d6f | 317 | alpha = (q31_t) (((q63_t) e * mu) >> 31); |
emh203 | 0:3d9c67d97d6f | 318 | |
emh203 | 0:3d9c67d97d6f | 319 | /* Initialize pState pointer */ |
emh203 | 0:3d9c67d97d6f | 320 | /* Advance state pointer by 1 for the next sample */ |
emh203 | 0:3d9c67d97d6f | 321 | px = pState++; |
emh203 | 0:3d9c67d97d6f | 322 | |
emh203 | 0:3d9c67d97d6f | 323 | /* Initialize pCoeffs pointer */ |
emh203 | 0:3d9c67d97d6f | 324 | pb = pCoeffs; |
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 | coef = (q31_t) (((q63_t) alpha * (*px++)) >> (32)); |
emh203 | 0:3d9c67d97d6f | 333 | *pb = clip_q63_to_q31((q63_t) * pb + (coef << 1u)); |
emh203 | 0:3d9c67d97d6f | 334 | pb++; |
emh203 | 0:3d9c67d97d6f | 335 | |
emh203 | 0:3d9c67d97d6f | 336 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 337 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 338 | } |
emh203 | 0:3d9c67d97d6f | 339 | |
emh203 | 0:3d9c67d97d6f | 340 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 341 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 342 | } |
emh203 | 0:3d9c67d97d6f | 343 | |
emh203 | 0:3d9c67d97d6f | 344 | /* Processing is complete. Now copy the last numTaps - 1 samples to the |
emh203 | 0:3d9c67d97d6f | 345 | start of the state buffer. This prepares the state buffer for the |
emh203 | 0:3d9c67d97d6f | 346 | next function call. */ |
emh203 | 0:3d9c67d97d6f | 347 | |
emh203 | 0:3d9c67d97d6f | 348 | /* Points to the start of the pState buffer */ |
emh203 | 0:3d9c67d97d6f | 349 | pStateCurnt = S->pState; |
emh203 | 0:3d9c67d97d6f | 350 | |
emh203 | 0:3d9c67d97d6f | 351 | /* Copy (numTaps - 1u) samples */ |
emh203 | 0:3d9c67d97d6f | 352 | tapCnt = (numTaps - 1u); |
emh203 | 0:3d9c67d97d6f | 353 | |
emh203 | 0:3d9c67d97d6f | 354 | /* Copy the data */ |
emh203 | 0:3d9c67d97d6f | 355 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 356 | { |
emh203 | 0:3d9c67d97d6f | 357 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 358 | |
emh203 | 0:3d9c67d97d6f | 359 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 360 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 361 | } |
emh203 | 0:3d9c67d97d6f | 362 | |
emh203 | 0:3d9c67d97d6f | 363 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emh203 | 0:3d9c67d97d6f | 364 | |
emh203 | 0:3d9c67d97d6f | 365 | } |
emh203 | 0:3d9c67d97d6f | 366 | |
emh203 | 0:3d9c67d97d6f | 367 | /** |
emh203 | 0:3d9c67d97d6f | 368 | * @} end of LMS group |
emh203 | 0:3d9c67d97d6f | 369 | */ |