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_biquad_cascade_df1_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_biquad_cascade_df1_q15.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Processing function for the |
emh203 | 0:3d9c67d97d6f | 11 | * Q15 Biquad cascade DirectFormI(DF1) filter. |
emh203 | 0:3d9c67d97d6f | 12 | * |
emh203 | 0:3d9c67d97d6f | 13 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
emh203 | 0:3d9c67d97d6f | 14 | * |
emh203 | 0:3d9c67d97d6f | 15 | * Redistribution and use in source and binary forms, with or without |
emh203 | 0:3d9c67d97d6f | 16 | * modification, are permitted provided that the following conditions |
emh203 | 0:3d9c67d97d6f | 17 | * are met: |
emh203 | 0:3d9c67d97d6f | 18 | * - Redistributions of source code must retain the above copyright |
emh203 | 0:3d9c67d97d6f | 19 | * notice, this list of conditions and the following disclaimer. |
emh203 | 0:3d9c67d97d6f | 20 | * - Redistributions in binary form must reproduce the above copyright |
emh203 | 0:3d9c67d97d6f | 21 | * notice, this list of conditions and the following disclaimer in |
emh203 | 0:3d9c67d97d6f | 22 | * the documentation and/or other materials provided with the |
emh203 | 0:3d9c67d97d6f | 23 | * distribution. |
emh203 | 0:3d9c67d97d6f | 24 | * - Neither the name of ARM LIMITED nor the names of its contributors |
emh203 | 0:3d9c67d97d6f | 25 | * may be used to endorse or promote products derived from this |
emh203 | 0:3d9c67d97d6f | 26 | * software without specific prior written permission. |
emh203 | 0:3d9c67d97d6f | 27 | * |
emh203 | 0:3d9c67d97d6f | 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
emh203 | 0:3d9c67d97d6f | 29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
emh203 | 0:3d9c67d97d6f | 30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
emh203 | 0:3d9c67d97d6f | 31 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
emh203 | 0:3d9c67d97d6f | 32 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
emh203 | 0:3d9c67d97d6f | 33 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
emh203 | 0:3d9c67d97d6f | 34 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
emh203 | 0:3d9c67d97d6f | 35 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
emh203 | 0:3d9c67d97d6f | 36 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
emh203 | 0:3d9c67d97d6f | 37 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
emh203 | 0:3d9c67d97d6f | 38 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
emh203 | 0:3d9c67d97d6f | 39 | * POSSIBILITY OF SUCH DAMAGE. |
emh203 | 0:3d9c67d97d6f | 40 | * -------------------------------------------------------------------- */ |
emh203 | 0:3d9c67d97d6f | 41 | |
emh203 | 0:3d9c67d97d6f | 42 | #include "arm_math.h" |
emh203 | 0:3d9c67d97d6f | 43 | |
emh203 | 0:3d9c67d97d6f | 44 | /** |
emh203 | 0:3d9c67d97d6f | 45 | * @ingroup groupFilters |
emh203 | 0:3d9c67d97d6f | 46 | */ |
emh203 | 0:3d9c67d97d6f | 47 | |
emh203 | 0:3d9c67d97d6f | 48 | /** |
emh203 | 0:3d9c67d97d6f | 49 | * @addtogroup BiquadCascadeDF1 |
emh203 | 0:3d9c67d97d6f | 50 | * @{ |
emh203 | 0:3d9c67d97d6f | 51 | */ |
emh203 | 0:3d9c67d97d6f | 52 | |
emh203 | 0:3d9c67d97d6f | 53 | /** |
emh203 | 0:3d9c67d97d6f | 54 | * @brief Processing function for the Q15 Biquad cascade filter. |
emh203 | 0:3d9c67d97d6f | 55 | * @param[in] *S points to an instance of the Q15 Biquad cascade structure. |
emh203 | 0:3d9c67d97d6f | 56 | * @param[in] *pSrc points to the block of input data. |
emh203 | 0:3d9c67d97d6f | 57 | * @param[out] *pDst points to the location where the output result is written. |
emh203 | 0:3d9c67d97d6f | 58 | * @param[in] blockSize number of samples to process per call. |
emh203 | 0:3d9c67d97d6f | 59 | * @return none. |
emh203 | 0:3d9c67d97d6f | 60 | * |
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 multiplications yield a 2.30 result. |
emh203 | 0:3d9c67d97d6f | 66 | * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. |
emh203 | 0:3d9c67d97d6f | 67 | * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. |
emh203 | 0:3d9c67d97d6f | 68 | * The accumulator is then shifted by <code>postShift</code> bits to truncate the result to 1.15 format by discarding the low 16 bits. |
emh203 | 0:3d9c67d97d6f | 69 | * Finally, the result is saturated to 1.15 format. |
emh203 | 0:3d9c67d97d6f | 70 | * |
emh203 | 0:3d9c67d97d6f | 71 | * \par |
emh203 | 0:3d9c67d97d6f | 72 | * Refer to the function <code>arm_biquad_cascade_df1_fast_q15()</code> for a faster but less precise implementation of this filter for Cortex-M3 and Cortex-M4. |
emh203 | 0:3d9c67d97d6f | 73 | */ |
emh203 | 0:3d9c67d97d6f | 74 | |
emh203 | 0:3d9c67d97d6f | 75 | void arm_biquad_cascade_df1_q15( |
emh203 | 0:3d9c67d97d6f | 76 | const arm_biquad_casd_df1_inst_q15 * S, |
emh203 | 0:3d9c67d97d6f | 77 | q15_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 78 | q15_t * pDst, |
emh203 | 0:3d9c67d97d6f | 79 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 80 | { |
emh203 | 0:3d9c67d97d6f | 81 | |
emh203 | 0:3d9c67d97d6f | 82 | |
emh203 | 0:3d9c67d97d6f | 83 | #ifndef ARM_MATH_CM0_FAMILY |
emh203 | 0:3d9c67d97d6f | 84 | |
emh203 | 0:3d9c67d97d6f | 85 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emh203 | 0:3d9c67d97d6f | 86 | |
emh203 | 0:3d9c67d97d6f | 87 | q15_t *pIn = pSrc; /* Source pointer */ |
emh203 | 0:3d9c67d97d6f | 88 | q15_t *pOut = pDst; /* Destination pointer */ |
emh203 | 0:3d9c67d97d6f | 89 | q31_t in; /* Temporary variable to hold input value */ |
emh203 | 0:3d9c67d97d6f | 90 | q31_t out; /* Temporary variable to hold output value */ |
emh203 | 0:3d9c67d97d6f | 91 | q31_t b0; /* Temporary variable to hold bo value */ |
emh203 | 0:3d9c67d97d6f | 92 | q31_t b1, a1; /* Filter coefficients */ |
emh203 | 0:3d9c67d97d6f | 93 | q31_t state_in, state_out; /* Filter state variables */ |
emh203 | 0:3d9c67d97d6f | 94 | q31_t acc_l, acc_h; |
emh203 | 0:3d9c67d97d6f | 95 | q63_t acc; /* Accumulator */ |
emh203 | 0:3d9c67d97d6f | 96 | int32_t lShift = (15 - (int32_t) S->postShift); /* Post shift */ |
emh203 | 0:3d9c67d97d6f | 97 | q15_t *pState = S->pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 98 | q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 99 | uint32_t sample, stage = (uint32_t) S->numStages; /* Stage loop counter */ |
emh203 | 0:3d9c67d97d6f | 100 | int32_t uShift = (32 - lShift); |
emh203 | 0:3d9c67d97d6f | 101 | |
emh203 | 0:3d9c67d97d6f | 102 | do |
emh203 | 0:3d9c67d97d6f | 103 | { |
emh203 | 0:3d9c67d97d6f | 104 | /* Read the b0 and 0 coefficients using SIMD */ |
emh203 | 0:3d9c67d97d6f | 105 | b0 = *__SIMD32(pCoeffs)++; |
emh203 | 0:3d9c67d97d6f | 106 | |
emh203 | 0:3d9c67d97d6f | 107 | /* Read the b1 and b2 coefficients using SIMD */ |
emh203 | 0:3d9c67d97d6f | 108 | b1 = *__SIMD32(pCoeffs)++; |
emh203 | 0:3d9c67d97d6f | 109 | |
emh203 | 0:3d9c67d97d6f | 110 | /* Read the a1 and a2 coefficients using SIMD */ |
emh203 | 0:3d9c67d97d6f | 111 | a1 = *__SIMD32(pCoeffs)++; |
emh203 | 0:3d9c67d97d6f | 112 | |
emh203 | 0:3d9c67d97d6f | 113 | /* Read the input state values from the state buffer: x[n-1], x[n-2] */ |
emh203 | 0:3d9c67d97d6f | 114 | state_in = *__SIMD32(pState)++; |
emh203 | 0:3d9c67d97d6f | 115 | |
emh203 | 0:3d9c67d97d6f | 116 | /* Read the output state values from the state buffer: y[n-1], y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 117 | state_out = *__SIMD32(pState)--; |
emh203 | 0:3d9c67d97d6f | 118 | |
emh203 | 0:3d9c67d97d6f | 119 | /* Apply loop unrolling and compute 2 output values simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 120 | /* The variable acc hold output values that are being computed: |
emh203 | 0:3d9c67d97d6f | 121 | * |
emh203 | 0:3d9c67d97d6f | 122 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
emh203 | 0:3d9c67d97d6f | 123 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
emh203 | 0:3d9c67d97d6f | 124 | */ |
emh203 | 0:3d9c67d97d6f | 125 | sample = blockSize >> 1u; |
emh203 | 0:3d9c67d97d6f | 126 | |
emh203 | 0:3d9c67d97d6f | 127 | /* First part of the processing with loop unrolling. Compute 2 outputs at a time. |
emh203 | 0:3d9c67d97d6f | 128 | ** a second loop below computes the remaining 1 sample. */ |
emh203 | 0:3d9c67d97d6f | 129 | while(sample > 0u) |
emh203 | 0:3d9c67d97d6f | 130 | { |
emh203 | 0:3d9c67d97d6f | 131 | |
emh203 | 0:3d9c67d97d6f | 132 | /* Read the input */ |
emh203 | 0:3d9c67d97d6f | 133 | in = *__SIMD32(pIn)++; |
emh203 | 0:3d9c67d97d6f | 134 | |
emh203 | 0:3d9c67d97d6f | 135 | /* out = b0 * x[n] + 0 * 0 */ |
emh203 | 0:3d9c67d97d6f | 136 | out = __SMUAD(b0, in); |
emh203 | 0:3d9c67d97d6f | 137 | |
emh203 | 0:3d9c67d97d6f | 138 | /* acc += b1 * x[n-1] + b2 * x[n-2] + out */ |
emh203 | 0:3d9c67d97d6f | 139 | acc = __SMLALD(b1, state_in, out); |
emh203 | 0:3d9c67d97d6f | 140 | /* acc += a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 141 | acc = __SMLALD(a1, state_out, acc); |
emh203 | 0:3d9c67d97d6f | 142 | |
emh203 | 0:3d9c67d97d6f | 143 | /* The result is converted from 3.29 to 1.31 if postShift = 1, and then saturation is applied */ |
emh203 | 0:3d9c67d97d6f | 144 | /* Calc lower part of acc */ |
emh203 | 0:3d9c67d97d6f | 145 | acc_l = acc & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 146 | |
emh203 | 0:3d9c67d97d6f | 147 | /* Calc upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 148 | acc_h = (acc >> 32) & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 149 | |
emh203 | 0:3d9c67d97d6f | 150 | /* Apply shift for lower part of acc and upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 151 | out = (uint32_t) acc_l >> lShift | acc_h << uShift; |
emh203 | 0:3d9c67d97d6f | 152 | |
emh203 | 0:3d9c67d97d6f | 153 | out = __SSAT(out, 16); |
emh203 | 0:3d9c67d97d6f | 154 | |
emh203 | 0:3d9c67d97d6f | 155 | /* Every time after the output is computed state should be updated. */ |
emh203 | 0:3d9c67d97d6f | 156 | /* The states should be updated as: */ |
emh203 | 0:3d9c67d97d6f | 157 | /* Xn2 = Xn1 */ |
emh203 | 0:3d9c67d97d6f | 158 | /* Xn1 = Xn */ |
emh203 | 0:3d9c67d97d6f | 159 | /* Yn2 = Yn1 */ |
emh203 | 0:3d9c67d97d6f | 160 | /* Yn1 = acc */ |
emh203 | 0:3d9c67d97d6f | 161 | /* x[n-N], x[n-N-1] are packed together to make state_in of type q31 */ |
emh203 | 0:3d9c67d97d6f | 162 | /* y[n-N], y[n-N-1] are packed together to make state_out of type q31 */ |
emh203 | 0:3d9c67d97d6f | 163 | |
emh203 | 0:3d9c67d97d6f | 164 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 165 | |
emh203 | 0:3d9c67d97d6f | 166 | state_in = __PKHBT(in, state_in, 16); |
emh203 | 0:3d9c67d97d6f | 167 | state_out = __PKHBT(out, state_out, 16); |
emh203 | 0:3d9c67d97d6f | 168 | |
emh203 | 0:3d9c67d97d6f | 169 | #else |
emh203 | 0:3d9c67d97d6f | 170 | |
emh203 | 0:3d9c67d97d6f | 171 | state_in = __PKHBT(state_in >> 16, (in >> 16), 16); |
emh203 | 0:3d9c67d97d6f | 172 | state_out = __PKHBT(state_out >> 16, (out), 16); |
emh203 | 0:3d9c67d97d6f | 173 | |
emh203 | 0:3d9c67d97d6f | 174 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 175 | |
emh203 | 0:3d9c67d97d6f | 176 | /* out = b0 * x[n] + 0 * 0 */ |
emh203 | 0:3d9c67d97d6f | 177 | out = __SMUADX(b0, in); |
emh203 | 0:3d9c67d97d6f | 178 | /* acc += b1 * x[n-1] + b2 * x[n-2] + out */ |
emh203 | 0:3d9c67d97d6f | 179 | acc = __SMLALD(b1, state_in, out); |
emh203 | 0:3d9c67d97d6f | 180 | /* acc += a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 181 | acc = __SMLALD(a1, state_out, acc); |
emh203 | 0:3d9c67d97d6f | 182 | |
emh203 | 0:3d9c67d97d6f | 183 | /* The result is converted from 3.29 to 1.31 if postShift = 1, and then saturation is applied */ |
emh203 | 0:3d9c67d97d6f | 184 | /* Calc lower part of acc */ |
emh203 | 0:3d9c67d97d6f | 185 | acc_l = acc & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 186 | |
emh203 | 0:3d9c67d97d6f | 187 | /* Calc upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 188 | acc_h = (acc >> 32) & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 189 | |
emh203 | 0:3d9c67d97d6f | 190 | /* Apply shift for lower part of acc and upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 191 | out = (uint32_t) acc_l >> lShift | acc_h << uShift; |
emh203 | 0:3d9c67d97d6f | 192 | |
emh203 | 0:3d9c67d97d6f | 193 | out = __SSAT(out, 16); |
emh203 | 0:3d9c67d97d6f | 194 | |
emh203 | 0:3d9c67d97d6f | 195 | /* Store the output in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 196 | |
emh203 | 0:3d9c67d97d6f | 197 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 198 | |
emh203 | 0:3d9c67d97d6f | 199 | *__SIMD32(pOut)++ = __PKHBT(state_out, out, 16); |
emh203 | 0:3d9c67d97d6f | 200 | |
emh203 | 0:3d9c67d97d6f | 201 | #else |
emh203 | 0:3d9c67d97d6f | 202 | |
emh203 | 0:3d9c67d97d6f | 203 | *__SIMD32(pOut)++ = __PKHBT(out, state_out >> 16, 16); |
emh203 | 0:3d9c67d97d6f | 204 | |
emh203 | 0:3d9c67d97d6f | 205 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 206 | |
emh203 | 0:3d9c67d97d6f | 207 | /* Every time after the output is computed state should be updated. */ |
emh203 | 0:3d9c67d97d6f | 208 | /* The states should be updated as: */ |
emh203 | 0:3d9c67d97d6f | 209 | /* Xn2 = Xn1 */ |
emh203 | 0:3d9c67d97d6f | 210 | /* Xn1 = Xn */ |
emh203 | 0:3d9c67d97d6f | 211 | /* Yn2 = Yn1 */ |
emh203 | 0:3d9c67d97d6f | 212 | /* Yn1 = acc */ |
emh203 | 0:3d9c67d97d6f | 213 | /* x[n-N], x[n-N-1] are packed together to make state_in of type q31 */ |
emh203 | 0:3d9c67d97d6f | 214 | /* y[n-N], y[n-N-1] are packed together to make state_out of type q31 */ |
emh203 | 0:3d9c67d97d6f | 215 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 216 | |
emh203 | 0:3d9c67d97d6f | 217 | state_in = __PKHBT(in >> 16, state_in, 16); |
emh203 | 0:3d9c67d97d6f | 218 | state_out = __PKHBT(out, state_out, 16); |
emh203 | 0:3d9c67d97d6f | 219 | |
emh203 | 0:3d9c67d97d6f | 220 | #else |
emh203 | 0:3d9c67d97d6f | 221 | |
emh203 | 0:3d9c67d97d6f | 222 | state_in = __PKHBT(state_in >> 16, in, 16); |
emh203 | 0:3d9c67d97d6f | 223 | state_out = __PKHBT(state_out >> 16, out, 16); |
emh203 | 0:3d9c67d97d6f | 224 | |
emh203 | 0:3d9c67d97d6f | 225 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 226 | |
emh203 | 0:3d9c67d97d6f | 227 | |
emh203 | 0:3d9c67d97d6f | 228 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 229 | sample--; |
emh203 | 0:3d9c67d97d6f | 230 | |
emh203 | 0:3d9c67d97d6f | 231 | } |
emh203 | 0:3d9c67d97d6f | 232 | |
emh203 | 0:3d9c67d97d6f | 233 | /* If the blockSize is not a multiple of 2, compute any remaining output samples here. |
emh203 | 0:3d9c67d97d6f | 234 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 235 | |
emh203 | 0:3d9c67d97d6f | 236 | if((blockSize & 0x1u) != 0u) |
emh203 | 0:3d9c67d97d6f | 237 | { |
emh203 | 0:3d9c67d97d6f | 238 | /* Read the input */ |
emh203 | 0:3d9c67d97d6f | 239 | in = *pIn++; |
emh203 | 0:3d9c67d97d6f | 240 | |
emh203 | 0:3d9c67d97d6f | 241 | /* out = b0 * x[n] + 0 * 0 */ |
emh203 | 0:3d9c67d97d6f | 242 | |
emh203 | 0:3d9c67d97d6f | 243 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 244 | |
emh203 | 0:3d9c67d97d6f | 245 | out = __SMUAD(b0, in); |
emh203 | 0:3d9c67d97d6f | 246 | |
emh203 | 0:3d9c67d97d6f | 247 | #else |
emh203 | 0:3d9c67d97d6f | 248 | |
emh203 | 0:3d9c67d97d6f | 249 | out = __SMUADX(b0, in); |
emh203 | 0:3d9c67d97d6f | 250 | |
emh203 | 0:3d9c67d97d6f | 251 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 252 | |
emh203 | 0:3d9c67d97d6f | 253 | /* acc = b1 * x[n-1] + b2 * x[n-2] + out */ |
emh203 | 0:3d9c67d97d6f | 254 | acc = __SMLALD(b1, state_in, out); |
emh203 | 0:3d9c67d97d6f | 255 | /* acc += a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 256 | acc = __SMLALD(a1, state_out, acc); |
emh203 | 0:3d9c67d97d6f | 257 | |
emh203 | 0:3d9c67d97d6f | 258 | /* The result is converted from 3.29 to 1.31 if postShift = 1, and then saturation is applied */ |
emh203 | 0:3d9c67d97d6f | 259 | /* Calc lower part of acc */ |
emh203 | 0:3d9c67d97d6f | 260 | acc_l = acc & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 261 | |
emh203 | 0:3d9c67d97d6f | 262 | /* Calc upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 263 | acc_h = (acc >> 32) & 0xffffffff; |
emh203 | 0:3d9c67d97d6f | 264 | |
emh203 | 0:3d9c67d97d6f | 265 | /* Apply shift for lower part of acc and upper part of acc */ |
emh203 | 0:3d9c67d97d6f | 266 | out = (uint32_t) acc_l >> lShift | acc_h << uShift; |
emh203 | 0:3d9c67d97d6f | 267 | |
emh203 | 0:3d9c67d97d6f | 268 | out = __SSAT(out, 16); |
emh203 | 0:3d9c67d97d6f | 269 | |
emh203 | 0:3d9c67d97d6f | 270 | /* Store the output in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 271 | *pOut++ = (q15_t) out; |
emh203 | 0:3d9c67d97d6f | 272 | |
emh203 | 0:3d9c67d97d6f | 273 | /* Every time after the output is computed state should be updated. */ |
emh203 | 0:3d9c67d97d6f | 274 | /* The states should be updated as: */ |
emh203 | 0:3d9c67d97d6f | 275 | /* Xn2 = Xn1 */ |
emh203 | 0:3d9c67d97d6f | 276 | /* Xn1 = Xn */ |
emh203 | 0:3d9c67d97d6f | 277 | /* Yn2 = Yn1 */ |
emh203 | 0:3d9c67d97d6f | 278 | /* Yn1 = acc */ |
emh203 | 0:3d9c67d97d6f | 279 | /* x[n-N], x[n-N-1] are packed together to make state_in of type q31 */ |
emh203 | 0:3d9c67d97d6f | 280 | /* y[n-N], y[n-N-1] are packed together to make state_out of type q31 */ |
emh203 | 0:3d9c67d97d6f | 281 | |
emh203 | 0:3d9c67d97d6f | 282 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 283 | |
emh203 | 0:3d9c67d97d6f | 284 | state_in = __PKHBT(in, state_in, 16); |
emh203 | 0:3d9c67d97d6f | 285 | state_out = __PKHBT(out, state_out, 16); |
emh203 | 0:3d9c67d97d6f | 286 | |
emh203 | 0:3d9c67d97d6f | 287 | #else |
emh203 | 0:3d9c67d97d6f | 288 | |
emh203 | 0:3d9c67d97d6f | 289 | state_in = __PKHBT(state_in >> 16, in, 16); |
emh203 | 0:3d9c67d97d6f | 290 | state_out = __PKHBT(state_out >> 16, out, 16); |
emh203 | 0:3d9c67d97d6f | 291 | |
emh203 | 0:3d9c67d97d6f | 292 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 293 | |
emh203 | 0:3d9c67d97d6f | 294 | } |
emh203 | 0:3d9c67d97d6f | 295 | |
emh203 | 0:3d9c67d97d6f | 296 | /* The first stage goes from the input wire to the output wire. */ |
emh203 | 0:3d9c67d97d6f | 297 | /* Subsequent numStages occur in-place in the output wire */ |
emh203 | 0:3d9c67d97d6f | 298 | pIn = pDst; |
emh203 | 0:3d9c67d97d6f | 299 | |
emh203 | 0:3d9c67d97d6f | 300 | /* Reset the output pointer */ |
emh203 | 0:3d9c67d97d6f | 301 | pOut = pDst; |
emh203 | 0:3d9c67d97d6f | 302 | |
emh203 | 0:3d9c67d97d6f | 303 | /* Store the updated state variables back into the state array */ |
emh203 | 0:3d9c67d97d6f | 304 | *__SIMD32(pState)++ = state_in; |
emh203 | 0:3d9c67d97d6f | 305 | *__SIMD32(pState)++ = state_out; |
emh203 | 0:3d9c67d97d6f | 306 | |
emh203 | 0:3d9c67d97d6f | 307 | |
emh203 | 0:3d9c67d97d6f | 308 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 309 | stage--; |
emh203 | 0:3d9c67d97d6f | 310 | |
emh203 | 0:3d9c67d97d6f | 311 | } while(stage > 0u); |
emh203 | 0:3d9c67d97d6f | 312 | |
emh203 | 0:3d9c67d97d6f | 313 | #else |
emh203 | 0:3d9c67d97d6f | 314 | |
emh203 | 0:3d9c67d97d6f | 315 | /* Run the below code for Cortex-M0 */ |
emh203 | 0:3d9c67d97d6f | 316 | |
emh203 | 0:3d9c67d97d6f | 317 | q15_t *pIn = pSrc; /* Source pointer */ |
emh203 | 0:3d9c67d97d6f | 318 | q15_t *pOut = pDst; /* Destination pointer */ |
emh203 | 0:3d9c67d97d6f | 319 | q15_t b0, b1, b2, a1, a2; /* Filter coefficients */ |
emh203 | 0:3d9c67d97d6f | 320 | q15_t Xn1, Xn2, Yn1, Yn2; /* Filter state variables */ |
emh203 | 0:3d9c67d97d6f | 321 | q15_t Xn; /* temporary input */ |
emh203 | 0:3d9c67d97d6f | 322 | q63_t acc; /* Accumulator */ |
emh203 | 0:3d9c67d97d6f | 323 | int32_t shift = (15 - (int32_t) S->postShift); /* Post shift */ |
emh203 | 0:3d9c67d97d6f | 324 | q15_t *pState = S->pState; /* State pointer */ |
emh203 | 0:3d9c67d97d6f | 325 | q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ |
emh203 | 0:3d9c67d97d6f | 326 | uint32_t sample, stage = (uint32_t) S->numStages; /* Stage loop counter */ |
emh203 | 0:3d9c67d97d6f | 327 | |
emh203 | 0:3d9c67d97d6f | 328 | do |
emh203 | 0:3d9c67d97d6f | 329 | { |
emh203 | 0:3d9c67d97d6f | 330 | /* Reading the coefficients */ |
emh203 | 0:3d9c67d97d6f | 331 | b0 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 332 | pCoeffs++; // skip the 0 coefficient |
emh203 | 0:3d9c67d97d6f | 333 | b1 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 334 | b2 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 335 | a1 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 336 | a2 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 337 | |
emh203 | 0:3d9c67d97d6f | 338 | /* Reading the state values */ |
emh203 | 0:3d9c67d97d6f | 339 | Xn1 = pState[0]; |
emh203 | 0:3d9c67d97d6f | 340 | Xn2 = pState[1]; |
emh203 | 0:3d9c67d97d6f | 341 | Yn1 = pState[2]; |
emh203 | 0:3d9c67d97d6f | 342 | Yn2 = pState[3]; |
emh203 | 0:3d9c67d97d6f | 343 | |
emh203 | 0:3d9c67d97d6f | 344 | /* The variables acc holds the output value that is computed: |
emh203 | 0:3d9c67d97d6f | 345 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
emh203 | 0:3d9c67d97d6f | 346 | */ |
emh203 | 0:3d9c67d97d6f | 347 | |
emh203 | 0:3d9c67d97d6f | 348 | sample = blockSize; |
emh203 | 0:3d9c67d97d6f | 349 | |
emh203 | 0:3d9c67d97d6f | 350 | while(sample > 0u) |
emh203 | 0:3d9c67d97d6f | 351 | { |
emh203 | 0:3d9c67d97d6f | 352 | /* Read the input */ |
emh203 | 0:3d9c67d97d6f | 353 | Xn = *pIn++; |
emh203 | 0:3d9c67d97d6f | 354 | |
emh203 | 0:3d9c67d97d6f | 355 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 356 | /* acc = b0 * x[n] */ |
emh203 | 0:3d9c67d97d6f | 357 | acc = (q31_t) b0 *Xn; |
emh203 | 0:3d9c67d97d6f | 358 | |
emh203 | 0:3d9c67d97d6f | 359 | /* acc += b1 * x[n-1] */ |
emh203 | 0:3d9c67d97d6f | 360 | acc += (q31_t) b1 *Xn1; |
emh203 | 0:3d9c67d97d6f | 361 | /* acc += b[2] * x[n-2] */ |
emh203 | 0:3d9c67d97d6f | 362 | acc += (q31_t) b2 *Xn2; |
emh203 | 0:3d9c67d97d6f | 363 | /* acc += a1 * y[n-1] */ |
emh203 | 0:3d9c67d97d6f | 364 | acc += (q31_t) a1 *Yn1; |
emh203 | 0:3d9c67d97d6f | 365 | /* acc += a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 366 | acc += (q31_t) a2 *Yn2; |
emh203 | 0:3d9c67d97d6f | 367 | |
emh203 | 0:3d9c67d97d6f | 368 | /* The result is converted to 1.31 */ |
emh203 | 0:3d9c67d97d6f | 369 | acc = __SSAT((acc >> shift), 16); |
emh203 | 0:3d9c67d97d6f | 370 | |
emh203 | 0:3d9c67d97d6f | 371 | /* Every time after the output is computed state should be updated. */ |
emh203 | 0:3d9c67d97d6f | 372 | /* The states should be updated as: */ |
emh203 | 0:3d9c67d97d6f | 373 | /* Xn2 = Xn1 */ |
emh203 | 0:3d9c67d97d6f | 374 | /* Xn1 = Xn */ |
emh203 | 0:3d9c67d97d6f | 375 | /* Yn2 = Yn1 */ |
emh203 | 0:3d9c67d97d6f | 376 | /* Yn1 = acc */ |
emh203 | 0:3d9c67d97d6f | 377 | Xn2 = Xn1; |
emh203 | 0:3d9c67d97d6f | 378 | Xn1 = Xn; |
emh203 | 0:3d9c67d97d6f | 379 | Yn2 = Yn1; |
emh203 | 0:3d9c67d97d6f | 380 | Yn1 = (q15_t) acc; |
emh203 | 0:3d9c67d97d6f | 381 | |
emh203 | 0:3d9c67d97d6f | 382 | /* Store the output in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 383 | *pOut++ = (q15_t) acc; |
emh203 | 0:3d9c67d97d6f | 384 | |
emh203 | 0:3d9c67d97d6f | 385 | /* decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 386 | sample--; |
emh203 | 0:3d9c67d97d6f | 387 | } |
emh203 | 0:3d9c67d97d6f | 388 | |
emh203 | 0:3d9c67d97d6f | 389 | /* The first stage goes from the input buffer to the output buffer. */ |
emh203 | 0:3d9c67d97d6f | 390 | /* Subsequent stages occur in-place in the output buffer */ |
emh203 | 0:3d9c67d97d6f | 391 | pIn = pDst; |
emh203 | 0:3d9c67d97d6f | 392 | |
emh203 | 0:3d9c67d97d6f | 393 | /* Reset to destination pointer */ |
emh203 | 0:3d9c67d97d6f | 394 | pOut = pDst; |
emh203 | 0:3d9c67d97d6f | 395 | |
emh203 | 0:3d9c67d97d6f | 396 | /* Store the updated state variables back into the pState array */ |
emh203 | 0:3d9c67d97d6f | 397 | *pState++ = Xn1; |
emh203 | 0:3d9c67d97d6f | 398 | *pState++ = Xn2; |
emh203 | 0:3d9c67d97d6f | 399 | *pState++ = Yn1; |
emh203 | 0:3d9c67d97d6f | 400 | *pState++ = Yn2; |
emh203 | 0:3d9c67d97d6f | 401 | |
emh203 | 0:3d9c67d97d6f | 402 | } while(--stage); |
emh203 | 0:3d9c67d97d6f | 403 | |
emh203 | 0:3d9c67d97d6f | 404 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emh203 | 0:3d9c67d97d6f | 405 | |
emh203 | 0:3d9c67d97d6f | 406 | } |
emh203 | 0:3d9c67d97d6f | 407 | |
emh203 | 0:3d9c67d97d6f | 408 | |
emh203 | 0:3d9c67d97d6f | 409 | /** |
emh203 | 0:3d9c67d97d6f | 410 | * @} end of BiquadCascadeDF1 group |
emh203 | 0:3d9c67d97d6f | 411 | */ |