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_fast_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_biquad_cascade_df1_fast_q31.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Processing function for the |
emh203 | 0:3d9c67d97d6f | 11 | * Q31 Fast Biquad cascade DirectFormI(DF1) filter. |
emh203 | 0:3d9c67d97d6f | 12 | * |
emh203 | 0:3d9c67d97d6f | 13 | * Target Processor: Cortex-M4/Cortex-M3 |
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 | * @details |
emh203 | 0:3d9c67d97d6f | 55 | * |
emh203 | 0:3d9c67d97d6f | 56 | * @param[in] *S points to an instance of the Q31 Biquad cascade structure. |
emh203 | 0:3d9c67d97d6f | 57 | * @param[in] *pSrc points to the block of input data. |
emh203 | 0:3d9c67d97d6f | 58 | * @param[out] *pDst points to the block of output data. |
emh203 | 0:3d9c67d97d6f | 59 | * @param[in] blockSize number of samples to process per call. |
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 | * This function is optimized for speed at the expense of fixed-point precision and overflow protection. |
emh203 | 0:3d9c67d97d6f | 65 | * The result of each 1.31 x 1.31 multiplication is truncated to 2.30 format. |
emh203 | 0:3d9c67d97d6f | 66 | * These intermediate results are added to a 2.30 accumulator. |
emh203 | 0:3d9c67d97d6f | 67 | * Finally, the accumulator is saturated and converted to a 1.31 result. |
emh203 | 0:3d9c67d97d6f | 68 | * The fast version has the same overflow behavior as the standard version and provides less precision since it discards the low 32 bits of each multiplication result. |
emh203 | 0:3d9c67d97d6f | 69 | * In order to avoid overflows completely the input signal must be scaled down by two bits and lie in the range [-0.25 +0.25). Use the intialization function |
emh203 | 0:3d9c67d97d6f | 70 | * arm_biquad_cascade_df1_init_q31() to initialize filter structure. |
emh203 | 0:3d9c67d97d6f | 71 | * |
emh203 | 0:3d9c67d97d6f | 72 | * \par |
emh203 | 0:3d9c67d97d6f | 73 | * Refer to the function <code>arm_biquad_cascade_df1_q31()</code> for a slower implementation of this function which uses 64-bit accumulation to provide higher precision. Both the slow and the fast versions use the same instance structure. |
emh203 | 0:3d9c67d97d6f | 74 | * Use the function <code>arm_biquad_cascade_df1_init_q31()</code> to initialize the filter structure. |
emh203 | 0:3d9c67d97d6f | 75 | */ |
emh203 | 0:3d9c67d97d6f | 76 | |
emh203 | 0:3d9c67d97d6f | 77 | void arm_biquad_cascade_df1_fast_q31( |
emh203 | 0:3d9c67d97d6f | 78 | const arm_biquad_casd_df1_inst_q31 * S, |
emh203 | 0:3d9c67d97d6f | 79 | q31_t * pSrc, |
emh203 | 0:3d9c67d97d6f | 80 | q31_t * pDst, |
emh203 | 0:3d9c67d97d6f | 81 | uint32_t blockSize) |
emh203 | 0:3d9c67d97d6f | 82 | { |
emh203 | 0:3d9c67d97d6f | 83 | q31_t acc = 0; /* accumulator */ |
emh203 | 0:3d9c67d97d6f | 84 | q31_t Xn1, Xn2, Yn1, Yn2; /* Filter state variables */ |
emh203 | 0:3d9c67d97d6f | 85 | q31_t b0, b1, b2, a1, a2; /* Filter coefficients */ |
emh203 | 0:3d9c67d97d6f | 86 | q31_t *pIn = pSrc; /* input pointer initialization */ |
emh203 | 0:3d9c67d97d6f | 87 | q31_t *pOut = pDst; /* output pointer initialization */ |
emh203 | 0:3d9c67d97d6f | 88 | q31_t *pState = S->pState; /* pState pointer initialization */ |
emh203 | 0:3d9c67d97d6f | 89 | q31_t *pCoeffs = S->pCoeffs; /* coeff pointer initialization */ |
emh203 | 0:3d9c67d97d6f | 90 | q31_t Xn; /* temporary input */ |
emh203 | 0:3d9c67d97d6f | 91 | int32_t shift = (int32_t) S->postShift + 1; /* Shift to be applied to the output */ |
emh203 | 0:3d9c67d97d6f | 92 | uint32_t sample, stage = S->numStages; /* loop counters */ |
emh203 | 0:3d9c67d97d6f | 93 | |
emh203 | 0:3d9c67d97d6f | 94 | |
emh203 | 0:3d9c67d97d6f | 95 | do |
emh203 | 0:3d9c67d97d6f | 96 | { |
emh203 | 0:3d9c67d97d6f | 97 | /* Reading the coefficients */ |
emh203 | 0:3d9c67d97d6f | 98 | b0 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 99 | b1 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 100 | b2 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 101 | a1 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 102 | a2 = *pCoeffs++; |
emh203 | 0:3d9c67d97d6f | 103 | |
emh203 | 0:3d9c67d97d6f | 104 | /* Reading the state values */ |
emh203 | 0:3d9c67d97d6f | 105 | Xn1 = pState[0]; |
emh203 | 0:3d9c67d97d6f | 106 | Xn2 = pState[1]; |
emh203 | 0:3d9c67d97d6f | 107 | Yn1 = pState[2]; |
emh203 | 0:3d9c67d97d6f | 108 | Yn2 = pState[3]; |
emh203 | 0:3d9c67d97d6f | 109 | |
emh203 | 0:3d9c67d97d6f | 110 | /* Apply loop unrolling and compute 4 output values simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 111 | /* The variables acc ... acc3 hold output values that are being computed: |
emh203 | 0:3d9c67d97d6f | 112 | * |
emh203 | 0:3d9c67d97d6f | 113 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
emh203 | 0:3d9c67d97d6f | 114 | */ |
emh203 | 0:3d9c67d97d6f | 115 | |
emh203 | 0:3d9c67d97d6f | 116 | sample = blockSize >> 2u; |
emh203 | 0:3d9c67d97d6f | 117 | |
emh203 | 0:3d9c67d97d6f | 118 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
emh203 | 0:3d9c67d97d6f | 119 | ** a second loop below computes the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 120 | while(sample > 0u) |
emh203 | 0:3d9c67d97d6f | 121 | { |
emh203 | 0:3d9c67d97d6f | 122 | /* Read the input */ |
emh203 | 0:3d9c67d97d6f | 123 | Xn = *pIn; |
emh203 | 0:3d9c67d97d6f | 124 | |
emh203 | 0:3d9c67d97d6f | 125 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 126 | /* acc = b0 * x[n] */ |
emh203 | 0:3d9c67d97d6f | 127 | //acc = (q31_t) (((q63_t) b1 * Xn1) >> 32); |
emh203 | 0:3d9c67d97d6f | 128 | mult_32x32_keep32_R(acc, b1, Xn1); |
emh203 | 0:3d9c67d97d6f | 129 | /* acc += b1 * x[n-1] */ |
emh203 | 0:3d9c67d97d6f | 130 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b0 * (Xn))) >> 32); |
emh203 | 0:3d9c67d97d6f | 131 | multAcc_32x32_keep32_R(acc, b0, Xn); |
emh203 | 0:3d9c67d97d6f | 132 | /* acc += b[2] * x[n-2] */ |
emh203 | 0:3d9c67d97d6f | 133 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b2 * (Xn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 134 | multAcc_32x32_keep32_R(acc, b2, Xn2); |
emh203 | 0:3d9c67d97d6f | 135 | /* acc += a1 * y[n-1] */ |
emh203 | 0:3d9c67d97d6f | 136 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a1 * (Yn1))) >> 32); |
emh203 | 0:3d9c67d97d6f | 137 | multAcc_32x32_keep32_R(acc, a1, Yn1); |
emh203 | 0:3d9c67d97d6f | 138 | /* acc += a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 139 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a2 * (Yn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 140 | multAcc_32x32_keep32_R(acc, a2, Yn2); |
emh203 | 0:3d9c67d97d6f | 141 | |
emh203 | 0:3d9c67d97d6f | 142 | /* The result is converted to 1.31 , Yn2 variable is reused */ |
emh203 | 0:3d9c67d97d6f | 143 | Yn2 = acc << shift; |
emh203 | 0:3d9c67d97d6f | 144 | |
emh203 | 0:3d9c67d97d6f | 145 | /* Read the second input */ |
emh203 | 0:3d9c67d97d6f | 146 | Xn2 = *(pIn + 1u); |
emh203 | 0:3d9c67d97d6f | 147 | |
emh203 | 0:3d9c67d97d6f | 148 | /* Store the output in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 149 | *pOut = Yn2; |
emh203 | 0:3d9c67d97d6f | 150 | |
emh203 | 0:3d9c67d97d6f | 151 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 152 | /* acc = b0 * x[n] */ |
emh203 | 0:3d9c67d97d6f | 153 | //acc = (q31_t) (((q63_t) b0 * (Xn2)) >> 32); |
emh203 | 0:3d9c67d97d6f | 154 | mult_32x32_keep32_R(acc, b0, Xn2); |
emh203 | 0:3d9c67d97d6f | 155 | /* acc += b1 * x[n-1] */ |
emh203 | 0:3d9c67d97d6f | 156 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b1 * (Xn))) >> 32); |
emh203 | 0:3d9c67d97d6f | 157 | multAcc_32x32_keep32_R(acc, b1, Xn); |
emh203 | 0:3d9c67d97d6f | 158 | /* acc += b[2] * x[n-2] */ |
emh203 | 0:3d9c67d97d6f | 159 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b2 * (Xn1))) >> 32); |
emh203 | 0:3d9c67d97d6f | 160 | multAcc_32x32_keep32_R(acc, b2, Xn1); |
emh203 | 0:3d9c67d97d6f | 161 | /* acc += a1 * y[n-1] */ |
emh203 | 0:3d9c67d97d6f | 162 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a1 * (Yn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 163 | multAcc_32x32_keep32_R(acc, a1, Yn2); |
emh203 | 0:3d9c67d97d6f | 164 | /* acc += a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 165 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a2 * (Yn1))) >> 32); |
emh203 | 0:3d9c67d97d6f | 166 | multAcc_32x32_keep32_R(acc, a2, Yn1); |
emh203 | 0:3d9c67d97d6f | 167 | |
emh203 | 0:3d9c67d97d6f | 168 | /* The result is converted to 1.31, Yn1 variable is reused */ |
emh203 | 0:3d9c67d97d6f | 169 | Yn1 = acc << shift; |
emh203 | 0:3d9c67d97d6f | 170 | |
emh203 | 0:3d9c67d97d6f | 171 | /* Read the third input */ |
emh203 | 0:3d9c67d97d6f | 172 | Xn1 = *(pIn + 2u); |
emh203 | 0:3d9c67d97d6f | 173 | |
emh203 | 0:3d9c67d97d6f | 174 | /* Store the output in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 175 | *(pOut + 1u) = Yn1; |
emh203 | 0:3d9c67d97d6f | 176 | |
emh203 | 0:3d9c67d97d6f | 177 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 178 | /* acc = b0 * x[n] */ |
emh203 | 0:3d9c67d97d6f | 179 | //acc = (q31_t) (((q63_t) b0 * (Xn1)) >> 32); |
emh203 | 0:3d9c67d97d6f | 180 | mult_32x32_keep32_R(acc, b0, Xn1); |
emh203 | 0:3d9c67d97d6f | 181 | /* acc += b1 * x[n-1] */ |
emh203 | 0:3d9c67d97d6f | 182 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b1 * (Xn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 183 | multAcc_32x32_keep32_R(acc, b1, Xn2); |
emh203 | 0:3d9c67d97d6f | 184 | /* acc += b[2] * x[n-2] */ |
emh203 | 0:3d9c67d97d6f | 185 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b2 * (Xn))) >> 32); |
emh203 | 0:3d9c67d97d6f | 186 | multAcc_32x32_keep32_R(acc, b2, Xn); |
emh203 | 0:3d9c67d97d6f | 187 | /* acc += a1 * y[n-1] */ |
emh203 | 0:3d9c67d97d6f | 188 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a1 * (Yn1))) >> 32); |
emh203 | 0:3d9c67d97d6f | 189 | multAcc_32x32_keep32_R(acc, a1, Yn1); |
emh203 | 0:3d9c67d97d6f | 190 | /* acc += a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 191 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a2 * (Yn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 192 | multAcc_32x32_keep32_R(acc, a2, Yn2); |
emh203 | 0:3d9c67d97d6f | 193 | |
emh203 | 0:3d9c67d97d6f | 194 | /* The result is converted to 1.31, Yn2 variable is reused */ |
emh203 | 0:3d9c67d97d6f | 195 | Yn2 = acc << shift; |
emh203 | 0:3d9c67d97d6f | 196 | |
emh203 | 0:3d9c67d97d6f | 197 | /* Read the forth input */ |
emh203 | 0:3d9c67d97d6f | 198 | Xn = *(pIn + 3u); |
emh203 | 0:3d9c67d97d6f | 199 | |
emh203 | 0:3d9c67d97d6f | 200 | /* Store the output in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 201 | *(pOut + 2u) = Yn2; |
emh203 | 0:3d9c67d97d6f | 202 | pIn += 4u; |
emh203 | 0:3d9c67d97d6f | 203 | |
emh203 | 0:3d9c67d97d6f | 204 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 205 | /* acc = b0 * x[n] */ |
emh203 | 0:3d9c67d97d6f | 206 | //acc = (q31_t) (((q63_t) b0 * (Xn)) >> 32); |
emh203 | 0:3d9c67d97d6f | 207 | mult_32x32_keep32_R(acc, b0, Xn); |
emh203 | 0:3d9c67d97d6f | 208 | /* acc += b1 * x[n-1] */ |
emh203 | 0:3d9c67d97d6f | 209 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b1 * (Xn1))) >> 32); |
emh203 | 0:3d9c67d97d6f | 210 | multAcc_32x32_keep32_R(acc, b1, Xn1); |
emh203 | 0:3d9c67d97d6f | 211 | /* acc += b[2] * x[n-2] */ |
emh203 | 0:3d9c67d97d6f | 212 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b2 * (Xn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 213 | multAcc_32x32_keep32_R(acc, b2, Xn2); |
emh203 | 0:3d9c67d97d6f | 214 | /* acc += a1 * y[n-1] */ |
emh203 | 0:3d9c67d97d6f | 215 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a1 * (Yn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 216 | multAcc_32x32_keep32_R(acc, a1, Yn2); |
emh203 | 0:3d9c67d97d6f | 217 | /* acc += a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 218 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a2 * (Yn1))) >> 32); |
emh203 | 0:3d9c67d97d6f | 219 | multAcc_32x32_keep32_R(acc, a2, Yn1); |
emh203 | 0:3d9c67d97d6f | 220 | |
emh203 | 0:3d9c67d97d6f | 221 | /* Every time after the output is computed state should be updated. */ |
emh203 | 0:3d9c67d97d6f | 222 | /* The states should be updated as: */ |
emh203 | 0:3d9c67d97d6f | 223 | /* Xn2 = Xn1 */ |
emh203 | 0:3d9c67d97d6f | 224 | Xn2 = Xn1; |
emh203 | 0:3d9c67d97d6f | 225 | |
emh203 | 0:3d9c67d97d6f | 226 | /* The result is converted to 1.31, Yn1 variable is reused */ |
emh203 | 0:3d9c67d97d6f | 227 | Yn1 = acc << shift; |
emh203 | 0:3d9c67d97d6f | 228 | |
emh203 | 0:3d9c67d97d6f | 229 | /* Xn1 = Xn */ |
emh203 | 0:3d9c67d97d6f | 230 | Xn1 = Xn; |
emh203 | 0:3d9c67d97d6f | 231 | |
emh203 | 0:3d9c67d97d6f | 232 | /* Store the output in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 233 | *(pOut + 3u) = Yn1; |
emh203 | 0:3d9c67d97d6f | 234 | pOut += 4u; |
emh203 | 0:3d9c67d97d6f | 235 | |
emh203 | 0:3d9c67d97d6f | 236 | /* decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 237 | sample--; |
emh203 | 0:3d9c67d97d6f | 238 | } |
emh203 | 0:3d9c67d97d6f | 239 | |
emh203 | 0:3d9c67d97d6f | 240 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
emh203 | 0:3d9c67d97d6f | 241 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 242 | sample = (blockSize & 0x3u); |
emh203 | 0:3d9c67d97d6f | 243 | |
emh203 | 0:3d9c67d97d6f | 244 | while(sample > 0u) |
emh203 | 0:3d9c67d97d6f | 245 | { |
emh203 | 0:3d9c67d97d6f | 246 | /* Read the input */ |
emh203 | 0:3d9c67d97d6f | 247 | Xn = *pIn++; |
emh203 | 0:3d9c67d97d6f | 248 | |
emh203 | 0:3d9c67d97d6f | 249 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 250 | /* acc = b0 * x[n] */ |
emh203 | 0:3d9c67d97d6f | 251 | //acc = (q31_t) (((q63_t) b0 * (Xn)) >> 32); |
emh203 | 0:3d9c67d97d6f | 252 | mult_32x32_keep32_R(acc, b0, Xn); |
emh203 | 0:3d9c67d97d6f | 253 | /* acc += b1 * x[n-1] */ |
emh203 | 0:3d9c67d97d6f | 254 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b1 * (Xn1))) >> 32); |
emh203 | 0:3d9c67d97d6f | 255 | multAcc_32x32_keep32_R(acc, b1, Xn1); |
emh203 | 0:3d9c67d97d6f | 256 | /* acc += b[2] * x[n-2] */ |
emh203 | 0:3d9c67d97d6f | 257 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) b2 * (Xn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 258 | multAcc_32x32_keep32_R(acc, b2, Xn2); |
emh203 | 0:3d9c67d97d6f | 259 | /* acc += a1 * y[n-1] */ |
emh203 | 0:3d9c67d97d6f | 260 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a1 * (Yn1))) >> 32); |
emh203 | 0:3d9c67d97d6f | 261 | multAcc_32x32_keep32_R(acc, a1, Yn1); |
emh203 | 0:3d9c67d97d6f | 262 | /* acc += a2 * y[n-2] */ |
emh203 | 0:3d9c67d97d6f | 263 | //acc = (q31_t) ((((q63_t) acc << 32) + ((q63_t) a2 * (Yn2))) >> 32); |
emh203 | 0:3d9c67d97d6f | 264 | multAcc_32x32_keep32_R(acc, a2, Yn2); |
emh203 | 0:3d9c67d97d6f | 265 | |
emh203 | 0:3d9c67d97d6f | 266 | /* The result is converted to 1.31 */ |
emh203 | 0:3d9c67d97d6f | 267 | acc = acc << shift; |
emh203 | 0:3d9c67d97d6f | 268 | |
emh203 | 0:3d9c67d97d6f | 269 | /* Every time after the output is computed state should be updated. */ |
emh203 | 0:3d9c67d97d6f | 270 | /* The states should be updated as: */ |
emh203 | 0:3d9c67d97d6f | 271 | /* Xn2 = Xn1 */ |
emh203 | 0:3d9c67d97d6f | 272 | /* Xn1 = Xn */ |
emh203 | 0:3d9c67d97d6f | 273 | /* Yn2 = Yn1 */ |
emh203 | 0:3d9c67d97d6f | 274 | /* Yn1 = acc */ |
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 | |
emh203 | 0:3d9c67d97d6f | 280 | /* Store the output in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 281 | *pOut++ = acc; |
emh203 | 0:3d9c67d97d6f | 282 | |
emh203 | 0:3d9c67d97d6f | 283 | /* decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 284 | sample--; |
emh203 | 0:3d9c67d97d6f | 285 | } |
emh203 | 0:3d9c67d97d6f | 286 | |
emh203 | 0:3d9c67d97d6f | 287 | /* The first stage goes from the input buffer to the output buffer. */ |
emh203 | 0:3d9c67d97d6f | 288 | /* Subsequent stages occur in-place in the output buffer */ |
emh203 | 0:3d9c67d97d6f | 289 | pIn = pDst; |
emh203 | 0:3d9c67d97d6f | 290 | |
emh203 | 0:3d9c67d97d6f | 291 | /* Reset to destination pointer */ |
emh203 | 0:3d9c67d97d6f | 292 | pOut = pDst; |
emh203 | 0:3d9c67d97d6f | 293 | |
emh203 | 0:3d9c67d97d6f | 294 | /* Store the updated state variables back into the pState array */ |
emh203 | 0:3d9c67d97d6f | 295 | *pState++ = Xn1; |
emh203 | 0:3d9c67d97d6f | 296 | *pState++ = Xn2; |
emh203 | 0:3d9c67d97d6f | 297 | *pState++ = Yn1; |
emh203 | 0:3d9c67d97d6f | 298 | *pState++ = Yn2; |
emh203 | 0:3d9c67d97d6f | 299 | |
emh203 | 0:3d9c67d97d6f | 300 | } while(--stage); |
emh203 | 0:3d9c67d97d6f | 301 | } |
emh203 | 0:3d9c67d97d6f | 302 | |
emh203 | 0:3d9c67d97d6f | 303 | /** |
emh203 | 0:3d9c67d97d6f | 304 | * @} end of BiquadCascadeDF1 group |
emh203 | 0:3d9c67d97d6f | 305 | */ |