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_q15.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_q15.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Processing function for the Q15 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 Q15 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 a 64-bit internal accumulator. |
emh203 | 0:3d9c67d97d6f | 63 | * Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. |
emh203 | 0:3d9c67d97d6f | 64 | * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. |
emh203 | 0:3d9c67d97d6f | 65 | * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. |
emh203 | 0:3d9c67d97d6f | 66 | * After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. |
emh203 | 0:3d9c67d97d6f | 67 | * Lastly, the accumulator is saturated to yield a result in 1.15 format. |
emh203 | 0:3d9c67d97d6f | 68 | * |
emh203 | 0:3d9c67d97d6f | 69 | * \par |
emh203 | 0:3d9c67d97d6f | 70 | * In this filter, filter coefficients are updated for each sample and the updation of filter cofficients are saturted. |
emh203 | 0:3d9c67d97d6f | 71 | * |
emh203 | 0:3d9c67d97d6f | 72 | */ |
emh203 | 0:3d9c67d97d6f | 73 | |
emh203 | 0:3d9c67d97d6f | 74 | void arm_lms_q15( |
emh203 | 0:3d9c67d97d6f | 75 | const arm_lms_instance_q15 * S, |
emh203 | 0:3d9c67d97d6f | 76 | q15_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 77 | q15_t * pRef, |
emh203 | 0:3d9c67d97d6f | 78 | q15_t * pOut, |
emh203 | 0:3d9c67d97d6f | 79 | q15_t * pErr, |
emh203 | 0:3d9c67d97d6f | 80 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 81 | { |
emh203 | 0:3d9c67d97d6f | 82 | q15_t *pState = S->pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 83 | uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ |
emh203 | 0:3d9c67d97d6f | 84 | q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 85 | q15_t *pStateCurnt; /* Points to the current sample of the state */ |
emh203 | 0:3d9c67d97d6f | 86 | q15_t mu = S->mu; /* Adaptive factor */ |
emh203 | 0:3d9c67d97d6f | 87 | q15_t *px; /* Temporary pointer for state */ |
emh203 | 0:3d9c67d97d6f | 88 | q15_t *pb; /* Temporary pointer for coefficient buffer */ |
emh203 | 0:3d9c67d97d6f | 89 | uint32_t tapCnt, blkCnt; /* Loop counters */ |
emh203 | 0:3d9c67d97d6f | 90 | q63_t acc; /* Accumulator */ |
emh203 | 0:3d9c67d97d6f | 91 | q15_t e = 0; /* error of data sample */ |
emh203 | 0:3d9c67d97d6f | 92 | q15_t alpha; /* Intermediate constant for taps update */ |
emh203 | 0:3d9c67d97d6f | 93 | q31_t coef; /* Teporary variable for coefficient */ |
emh203 | 0:3d9c67d97d6f | 94 | q31_t acc_l, acc_h; |
emh203 | 0:3d9c67d97d6f | 95 | int32_t lShift = (15 - (int32_t) S->postShift); /* Post shift */ |
emh203 | 0:3d9c67d97d6f | 96 | int32_t uShift = (32 - lShift); |
emh203 | 0:3d9c67d97d6f | 97 | |
emh203 | 0:3d9c67d97d6f | 98 | |
emh203 | 0:3d9c67d97d6f | 99 | #ifndef ARM_MATH_CM0_FAMILY |
emh203 | 0:3d9c67d97d6f | 100 | |
emh203 | 0:3d9c67d97d6f | 101 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emh203 | 0:3d9c67d97d6f | 102 | |
emh203 | 0:3d9c67d97d6f | 103 | |
emh203 | 0:3d9c67d97d6f | 104 | /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ |
emh203 | 0:3d9c67d97d6f | 105 | /* pStateCurnt points to the location where the new input data should be written */ |
emh203 | 0:3d9c67d97d6f | 106 | pStateCurnt = &(S->pState[(numTaps - 1u)]); |
emh203 | 0:3d9c67d97d6f | 107 | |
emh203 | 0:3d9c67d97d6f | 108 | /* Initializing blkCnt with blockSize */ |
emh203 | 0:3d9c67d97d6f | 109 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 110 | |
emh203 | 0:3d9c67d97d6f | 111 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 112 | { |
emh203 | 0:3d9c67d97d6f | 113 | /* Copy the new input sample into the state buffer */ |
emh203 | 0:3d9c67d97d6f | 114 | *pStateCurnt++ = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 115 | |
emh203 | 0:3d9c67d97d6f | 116 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 117 | px = pState; |
emh203 | 0:3d9c67d97d6f | 118 | |
emh203 | 0:3d9c67d97d6f | 119 | /* Initialize coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 120 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 121 | |
emh203 | 0:3d9c67d97d6f | 122 | /* Set the accumulator to zero */ |
emh203 | 0:3d9c67d97d6f | 123 | acc = 0; |
emh203 | 0:3d9c67d97d6f | 124 | |
emh203 | 0:3d9c67d97d6f | 125 | /* Loop unrolling. Process 4 taps at a time. */ |
emh203 | 0:3d9c67d97d6f | 126 | tapCnt = numTaps >> 2u; |
emh203 | 0:3d9c67d97d6f | 127 | |
emh203 | 0:3d9c67d97d6f | 128 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 129 | { |
emh203 | 0:3d9c67d97d6f | 130 | /* acc += b[N] * x[n-N] + b[N-1] * x[n-N-1] */ |
emh203 | 0:3d9c67d97d6f | 131 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 132 | #ifndef UNALIGNED_SUPPORT_DISABLE |
emh203 | 0:3d9c67d97d6f | 133 | |
emh203 | 0:3d9c67d97d6f | 134 | acc = __SMLALD(*__SIMD32(px)++, (*__SIMD32(pb)++), acc); |
emh203 | 0:3d9c67d97d6f | 135 | acc = __SMLALD(*__SIMD32(px)++, (*__SIMD32(pb)++), acc); |
emh203 | 0:3d9c67d97d6f | 136 | |
emh203 | 0:3d9c67d97d6f | 137 | #else |
emh203 | 0:3d9c67d97d6f | 138 | |
emh203 | 0:3d9c67d97d6f | 139 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
emh203 | 0:3d9c67d97d6f | 140 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
emh203 | 0:3d9c67d97d6f | 141 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
emh203 | 0:3d9c67d97d6f | 142 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
emh203 | 0:3d9c67d97d6f | 143 | |
emh203 | 0:3d9c67d97d6f | 144 | |
emh203 | 0:3d9c67d97d6f | 145 | #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */ |
emh203 | 0:3d9c67d97d6f | 146 | |
emh203 | 0:3d9c67d97d6f | 147 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 148 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 149 | } |
emh203 | 0:3d9c67d97d6f | 150 | |
emh203 | 0:3d9c67d97d6f | 151 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
emh203 | 0:3d9c67d97d6f | 152 | tapCnt = numTaps % 0x4u; |
emh203 | 0:3d9c67d97d6f | 153 | |
emh203 | 0:3d9c67d97d6f | 154 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 155 | { |
emh203 | 0:3d9c67d97d6f | 156 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 157 | acc += (q63_t) (((q31_t) (*px++) * (*pb++))); |
emh203 | 0:3d9c67d97d6f | 158 | |
emh203 | 0:3d9c67d97d6f | 159 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 160 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 161 | } |
emh203 | 0:3d9c67d97d6f | 162 | |
emh203 | 0:3d9c67d97d6f | 163 | /* Calc lower part of acc */ |
emh203 | 0:3d9c67d97d6f | 164 | acc_l = acc & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 165 | |
emh203 | 0:3d9c67d97d6f | 166 | /* Calc upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 167 | acc_h = (acc >> 32) & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 168 | |
emh203 | 0:3d9c67d97d6f | 169 | /* Apply shift for lower part of acc and upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 170 | acc = (uint32_t) acc_l >> lShift | acc_h << uShift; |
emh203 | 0:3d9c67d97d6f | 171 | |
emh203 | 0:3d9c67d97d6f | 172 | /* Converting the result to 1.15 format and saturate the output */ |
emh203 | 0:3d9c67d97d6f | 173 | acc = __SSAT(acc, 16); |
emh203 | 0:3d9c67d97d6f | 174 | |
emh203 | 0:3d9c67d97d6f | 175 | /* Store the result from accumulator into the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 176 | *pOut++ = (q15_t) acc; |
emh203 | 0:3d9c67d97d6f | 177 | |
emh203 | 0:3d9c67d97d6f | 178 | /* Compute and store error */ |
emh203 | 0:3d9c67d97d6f | 179 | e = *pRef++ - (q15_t) acc; |
emh203 | 0:3d9c67d97d6f | 180 | |
emh203 | 0:3d9c67d97d6f | 181 | *pErr++ = (q15_t) e; |
emh203 | 0:3d9c67d97d6f | 182 | |
emh203 | 0:3d9c67d97d6f | 183 | /* Compute alpha i.e. intermediate constant for taps update */ |
emh203 | 0:3d9c67d97d6f | 184 | alpha = (q15_t) (((q31_t) e * (mu)) >> 15); |
emh203 | 0:3d9c67d97d6f | 185 | |
emh203 | 0:3d9c67d97d6f | 186 | /* Initialize state pointer */ |
emh203 | 0:3d9c67d97d6f | 187 | /* Advance state pointer by 1 for the next sample */ |
emh203 | 0:3d9c67d97d6f | 188 | px = pState++; |
emh203 | 0:3d9c67d97d6f | 189 | |
emh203 | 0:3d9c67d97d6f | 190 | /* Initialize coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 191 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 192 | |
emh203 | 0:3d9c67d97d6f | 193 | /* Loop unrolling. Process 4 taps at a time. */ |
emh203 | 0:3d9c67d97d6f | 194 | tapCnt = numTaps >> 2u; |
emh203 | 0:3d9c67d97d6f | 195 | |
emh203 | 0:3d9c67d97d6f | 196 | /* Update filter coefficients */ |
emh203 | 0:3d9c67d97d6f | 197 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 198 | { |
emh203 | 0:3d9c67d97d6f | 199 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
emh203 | 0:3d9c67d97d6f | 200 | *pb++ = (q15_t) __SSAT((coef), 16); |
emh203 | 0:3d9c67d97d6f | 201 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
emh203 | 0:3d9c67d97d6f | 202 | *pb++ = (q15_t) __SSAT((coef), 16); |
emh203 | 0:3d9c67d97d6f | 203 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
emh203 | 0:3d9c67d97d6f | 204 | *pb++ = (q15_t) __SSAT((coef), 16); |
emh203 | 0:3d9c67d97d6f | 205 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
emh203 | 0:3d9c67d97d6f | 206 | *pb++ = (q15_t) __SSAT((coef), 16); |
emh203 | 0:3d9c67d97d6f | 207 | |
emh203 | 0:3d9c67d97d6f | 208 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 209 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 210 | } |
emh203 | 0:3d9c67d97d6f | 211 | |
emh203 | 0:3d9c67d97d6f | 212 | /* If the filter length is not a multiple of 4, compute the remaining filter taps */ |
emh203 | 0:3d9c67d97d6f | 213 | tapCnt = numTaps % 0x4u; |
emh203 | 0:3d9c67d97d6f | 214 | |
emh203 | 0:3d9c67d97d6f | 215 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 216 | { |
emh203 | 0:3d9c67d97d6f | 217 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 218 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
emh203 | 0:3d9c67d97d6f | 219 | *pb++ = (q15_t) __SSAT((coef), 16); |
emh203 | 0:3d9c67d97d6f | 220 | |
emh203 | 0:3d9c67d97d6f | 221 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 222 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 223 | } |
emh203 | 0:3d9c67d97d6f | 224 | |
emh203 | 0:3d9c67d97d6f | 225 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 226 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 227 | |
emh203 | 0:3d9c67d97d6f | 228 | } |
emh203 | 0:3d9c67d97d6f | 229 | |
emh203 | 0:3d9c67d97d6f | 230 | /* Processing is complete. Now copy the last numTaps - 1 samples to the |
emh203 | 0:3d9c67d97d6f | 231 | satrt of the state buffer. This prepares the state buffer for the |
emh203 | 0:3d9c67d97d6f | 232 | next function call. */ |
emh203 | 0:3d9c67d97d6f | 233 | |
emh203 | 0:3d9c67d97d6f | 234 | /* Points to the start of the pState buffer */ |
emh203 | 0:3d9c67d97d6f | 235 | pStateCurnt = S->pState; |
emh203 | 0:3d9c67d97d6f | 236 | |
emh203 | 0:3d9c67d97d6f | 237 | /* Calculation of count for copying integer writes */ |
emh203 | 0:3d9c67d97d6f | 238 | tapCnt = (numTaps - 1u) >> 2; |
emh203 | 0:3d9c67d97d6f | 239 | |
emh203 | 0:3d9c67d97d6f | 240 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 241 | { |
emh203 | 0:3d9c67d97d6f | 242 | |
emh203 | 0:3d9c67d97d6f | 243 | #ifndef UNALIGNED_SUPPORT_DISABLE |
emh203 | 0:3d9c67d97d6f | 244 | |
emh203 | 0:3d9c67d97d6f | 245 | *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++; |
emh203 | 0:3d9c67d97d6f | 246 | *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++; |
emh203 | 0:3d9c67d97d6f | 247 | #else |
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 | #endif |
emh203 | 0:3d9c67d97d6f | 253 | |
emh203 | 0:3d9c67d97d6f | 254 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 255 | |
emh203 | 0:3d9c67d97d6f | 256 | } |
emh203 | 0:3d9c67d97d6f | 257 | |
emh203 | 0:3d9c67d97d6f | 258 | /* Calculation of count for remaining q15_t data */ |
emh203 | 0:3d9c67d97d6f | 259 | tapCnt = (numTaps - 1u) % 0x4u; |
emh203 | 0:3d9c67d97d6f | 260 | |
emh203 | 0:3d9c67d97d6f | 261 | /* copy data */ |
emh203 | 0:3d9c67d97d6f | 262 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 263 | { |
emh203 | 0:3d9c67d97d6f | 264 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 265 | |
emh203 | 0:3d9c67d97d6f | 266 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 267 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 268 | } |
emh203 | 0:3d9c67d97d6f | 269 | |
emh203 | 0:3d9c67d97d6f | 270 | #else |
emh203 | 0:3d9c67d97d6f | 271 | |
emh203 | 0:3d9c67d97d6f | 272 | /* Run the below code for Cortex-M0 */ |
emh203 | 0:3d9c67d97d6f | 273 | |
emh203 | 0:3d9c67d97d6f | 274 | /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ |
emh203 | 0:3d9c67d97d6f | 275 | /* pStateCurnt points to the location where the new input data should be written */ |
emh203 | 0:3d9c67d97d6f | 276 | pStateCurnt = &(S->pState[(numTaps - 1u)]); |
emh203 | 0:3d9c67d97d6f | 277 | |
emh203 | 0:3d9c67d97d6f | 278 | /* Loop over blockSize number of values */ |
emh203 | 0:3d9c67d97d6f | 279 | blkCnt = blockSize; |
emh203 | 0:3d9c67d97d6f | 280 | |
emh203 | 0:3d9c67d97d6f | 281 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 282 | { |
emh203 | 0:3d9c67d97d6f | 283 | /* Copy the new input sample into the state buffer */ |
emh203 | 0:3d9c67d97d6f | 284 | *pStateCurnt++ = *pSrc++; |
emh203 | 0:3d9c67d97d6f | 285 | |
emh203 | 0:3d9c67d97d6f | 286 | /* Initialize pState pointer */ |
emh203 | 0:3d9c67d97d6f | 287 | px = pState; |
emh203 | 0:3d9c67d97d6f | 288 | |
emh203 | 0:3d9c67d97d6f | 289 | /* Initialize pCoeffs pointer */ |
emh203 | 0:3d9c67d97d6f | 290 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 291 | |
emh203 | 0:3d9c67d97d6f | 292 | /* Set the accumulator to zero */ |
emh203 | 0:3d9c67d97d6f | 293 | acc = 0; |
emh203 | 0:3d9c67d97d6f | 294 | |
emh203 | 0:3d9c67d97d6f | 295 | /* Loop over numTaps number of values */ |
emh203 | 0:3d9c67d97d6f | 296 | tapCnt = numTaps; |
emh203 | 0:3d9c67d97d6f | 297 | |
emh203 | 0:3d9c67d97d6f | 298 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 299 | { |
emh203 | 0:3d9c67d97d6f | 300 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 301 | acc += (q63_t) ((q31_t) (*px++) * (*pb++)); |
emh203 | 0:3d9c67d97d6f | 302 | |
emh203 | 0:3d9c67d97d6f | 303 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 304 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 305 | } |
emh203 | 0:3d9c67d97d6f | 306 | |
emh203 | 0:3d9c67d97d6f | 307 | /* Calc lower part of acc */ |
emh203 | 0:3d9c67d97d6f | 308 | acc_l = acc & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 309 | |
emh203 | 0:3d9c67d97d6f | 310 | /* Calc upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 311 | acc_h = (acc >> 32) & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 312 | |
emh203 | 0:3d9c67d97d6f | 313 | /* Apply shift for lower part of acc and upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 314 | acc = (uint32_t) acc_l >> lShift | acc_h << uShift; |
emh203 | 0:3d9c67d97d6f | 315 | |
emh203 | 0:3d9c67d97d6f | 316 | /* Converting the result to 1.15 format and saturate the output */ |
emh203 | 0:3d9c67d97d6f | 317 | acc = __SSAT(acc, 16); |
emh203 | 0:3d9c67d97d6f | 318 | |
emh203 | 0:3d9c67d97d6f | 319 | /* Store the result from accumulator into the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 320 | *pOut++ = (q15_t) acc; |
emh203 | 0:3d9c67d97d6f | 321 | |
emh203 | 0:3d9c67d97d6f | 322 | /* Compute and store error */ |
emh203 | 0:3d9c67d97d6f | 323 | e = *pRef++ - (q15_t) acc; |
emh203 | 0:3d9c67d97d6f | 324 | |
emh203 | 0:3d9c67d97d6f | 325 | *pErr++ = (q15_t) e; |
emh203 | 0:3d9c67d97d6f | 326 | |
emh203 | 0:3d9c67d97d6f | 327 | /* Compute alpha i.e. intermediate constant for taps update */ |
emh203 | 0:3d9c67d97d6f | 328 | alpha = (q15_t) (((q31_t) e * (mu)) >> 15); |
emh203 | 0:3d9c67d97d6f | 329 | |
emh203 | 0:3d9c67d97d6f | 330 | /* Initialize pState pointer */ |
emh203 | 0:3d9c67d97d6f | 331 | /* Advance state pointer by 1 for the next sample */ |
emh203 | 0:3d9c67d97d6f | 332 | px = pState++; |
emh203 | 0:3d9c67d97d6f | 333 | |
emh203 | 0:3d9c67d97d6f | 334 | /* Initialize pCoeffs pointer */ |
emh203 | 0:3d9c67d97d6f | 335 | pb = pCoeffs; |
emh203 | 0:3d9c67d97d6f | 336 | |
emh203 | 0:3d9c67d97d6f | 337 | /* Loop over numTaps number of values */ |
emh203 | 0:3d9c67d97d6f | 338 | tapCnt = numTaps; |
emh203 | 0:3d9c67d97d6f | 339 | |
emh203 | 0:3d9c67d97d6f | 340 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 341 | { |
emh203 | 0:3d9c67d97d6f | 342 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 343 | coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); |
emh203 | 0:3d9c67d97d6f | 344 | *pb++ = (q15_t) __SSAT((coef), 16); |
emh203 | 0:3d9c67d97d6f | 345 | |
emh203 | 0:3d9c67d97d6f | 346 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 347 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 348 | } |
emh203 | 0:3d9c67d97d6f | 349 | |
emh203 | 0:3d9c67d97d6f | 350 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 351 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 352 | |
emh203 | 0:3d9c67d97d6f | 353 | } |
emh203 | 0:3d9c67d97d6f | 354 | |
emh203 | 0:3d9c67d97d6f | 355 | /* Processing is complete. Now copy the last numTaps - 1 samples to the |
emh203 | 0:3d9c67d97d6f | 356 | start of the state buffer. This prepares the state buffer for the |
emh203 | 0:3d9c67d97d6f | 357 | next function call. */ |
emh203 | 0:3d9c67d97d6f | 358 | |
emh203 | 0:3d9c67d97d6f | 359 | /* Points to the start of the pState buffer */ |
emh203 | 0:3d9c67d97d6f | 360 | pStateCurnt = S->pState; |
emh203 | 0:3d9c67d97d6f | 361 | |
emh203 | 0:3d9c67d97d6f | 362 | /* Copy (numTaps - 1u) samples */ |
emh203 | 0:3d9c67d97d6f | 363 | tapCnt = (numTaps - 1u); |
emh203 | 0:3d9c67d97d6f | 364 | |
emh203 | 0:3d9c67d97d6f | 365 | /* Copy the data */ |
emh203 | 0:3d9c67d97d6f | 366 | while(tapCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 367 | { |
emh203 | 0:3d9c67d97d6f | 368 | *pStateCurnt++ = *pState++; |
emh203 | 0:3d9c67d97d6f | 369 | |
emh203 | 0:3d9c67d97d6f | 370 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 371 | tapCnt--; |
emh203 | 0:3d9c67d97d6f | 372 | } |
emh203 | 0:3d9c67d97d6f | 373 | |
emh203 | 0:3d9c67d97d6f | 374 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emh203 | 0:3d9c67d97d6f | 375 | |
emh203 | 0:3d9c67d97d6f | 376 | } |
emh203 | 0:3d9c67d97d6f | 377 | |
emh203 | 0:3d9c67d97d6f | 378 | /** |
emh203 | 0:3d9c67d97d6f | 379 | * @} end of LMS group |
emh203 | 0:3d9c67d97d6f | 380 | */ |