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_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_q31.c |
| emh203 | 0:3d9c67d97d6f | 9 | * |
| emh203 | 0:3d9c67d97d6f | 10 | * Description: Processing function for the |
| emh203 | 0:3d9c67d97d6f | 11 | * Q31 Biquad cascade 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 Q31 Biquad cascade filter. |
| emh203 | 0:3d9c67d97d6f | 55 | * @param[in] *S points to an instance of the Q31 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 block of output data. |
| 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 | * <b>Scaling and Overflow Behavior:</b> |
| emh203 | 0:3d9c67d97d6f | 62 | * \par |
| emh203 | 0:3d9c67d97d6f | 63 | * The function is implemented using an internal 64-bit accumulator. |
| emh203 | 0:3d9c67d97d6f | 64 | * The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. |
| emh203 | 0:3d9c67d97d6f | 65 | * Thus, if the accumulator result overflows it wraps around rather than clip. |
| emh203 | 0:3d9c67d97d6f | 66 | * In order to avoid overflows completely the input signal must be scaled down by 2 bits and lie in the range [-0.25 +0.25). |
| emh203 | 0:3d9c67d97d6f | 67 | * After all 5 multiply-accumulates are performed, the 2.62 accumulator is shifted by <code>postShift</code> bits and the result truncated to |
| emh203 | 0:3d9c67d97d6f | 68 | * 1.31 format by discarding the low 32 bits. |
| emh203 | 0:3d9c67d97d6f | 69 | * |
| emh203 | 0:3d9c67d97d6f | 70 | * \par |
| emh203 | 0:3d9c67d97d6f | 71 | * Refer to the function <code>arm_biquad_cascade_df1_fast_q31()</code> for a faster but less precise implementation of this filter for Cortex-M3 and Cortex-M4. |
| emh203 | 0:3d9c67d97d6f | 72 | */ |
| emh203 | 0:3d9c67d97d6f | 73 | |
| emh203 | 0:3d9c67d97d6f | 74 | void arm_biquad_cascade_df1_q31( |
| emh203 | 0:3d9c67d97d6f | 75 | const arm_biquad_casd_df1_inst_q31 * S, |
| emh203 | 0:3d9c67d97d6f | 76 | q31_t * pSrc, |
| emh203 | 0:3d9c67d97d6f | 77 | q31_t * pDst, |
| emh203 | 0:3d9c67d97d6f | 78 | uint32_t blockSize) |
| emh203 | 0:3d9c67d97d6f | 79 | { |
| emh203 | 0:3d9c67d97d6f | 80 | q63_t acc; /* accumulator */ |
| emh203 | 0:3d9c67d97d6f | 81 | uint32_t uShift = ((uint32_t) S->postShift + 1u); |
| emh203 | 0:3d9c67d97d6f | 82 | uint32_t lShift = 32u - uShift; /* Shift to be applied to the output */ |
| emh203 | 0:3d9c67d97d6f | 83 | q31_t *pIn = pSrc; /* input pointer initialization */ |
| emh203 | 0:3d9c67d97d6f | 84 | q31_t *pOut = pDst; /* output pointer initialization */ |
| emh203 | 0:3d9c67d97d6f | 85 | q31_t *pState = S->pState; /* pState pointer initialization */ |
| emh203 | 0:3d9c67d97d6f | 86 | q31_t *pCoeffs = S->pCoeffs; /* coeff pointer initialization */ |
| emh203 | 0:3d9c67d97d6f | 87 | q31_t Xn1, Xn2, Yn1, Yn2; /* Filter state variables */ |
| emh203 | 0:3d9c67d97d6f | 88 | q31_t b0, b1, b2, a1, a2; /* Filter coefficients */ |
| emh203 | 0:3d9c67d97d6f | 89 | q31_t Xn; /* temporary input */ |
| emh203 | 0:3d9c67d97d6f | 90 | uint32_t sample, stage = S->numStages; /* loop counters */ |
| emh203 | 0:3d9c67d97d6f | 91 | |
| emh203 | 0:3d9c67d97d6f | 92 | |
| emh203 | 0:3d9c67d97d6f | 93 | #ifndef ARM_MATH_CM0_FAMILY_FAMILY |
| emh203 | 0:3d9c67d97d6f | 94 | |
| emh203 | 0:3d9c67d97d6f | 95 | q31_t acc_l, acc_h; /* temporary output variables */ |
| emh203 | 0:3d9c67d97d6f | 96 | |
| emh203 | 0:3d9c67d97d6f | 97 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
| emh203 | 0:3d9c67d97d6f | 98 | |
| emh203 | 0:3d9c67d97d6f | 99 | do |
| emh203 | 0:3d9c67d97d6f | 100 | { |
| emh203 | 0:3d9c67d97d6f | 101 | /* Reading the coefficients */ |
| emh203 | 0:3d9c67d97d6f | 102 | b0 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 103 | b1 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 104 | b2 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 105 | a1 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 106 | a2 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 107 | |
| emh203 | 0:3d9c67d97d6f | 108 | /* Reading the state values */ |
| emh203 | 0:3d9c67d97d6f | 109 | Xn1 = pState[0]; |
| emh203 | 0:3d9c67d97d6f | 110 | Xn2 = pState[1]; |
| emh203 | 0:3d9c67d97d6f | 111 | Yn1 = pState[2]; |
| emh203 | 0:3d9c67d97d6f | 112 | Yn2 = pState[3]; |
| emh203 | 0:3d9c67d97d6f | 113 | |
| emh203 | 0:3d9c67d97d6f | 114 | /* Apply loop unrolling and compute 4 output values simultaneously. */ |
| emh203 | 0:3d9c67d97d6f | 115 | /* The variable acc hold output values that are being computed: |
| emh203 | 0:3d9c67d97d6f | 116 | * |
| emh203 | 0:3d9c67d97d6f | 117 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
| emh203 | 0:3d9c67d97d6f | 118 | */ |
| emh203 | 0:3d9c67d97d6f | 119 | |
| emh203 | 0:3d9c67d97d6f | 120 | sample = blockSize >> 2u; |
| emh203 | 0:3d9c67d97d6f | 121 | |
| emh203 | 0:3d9c67d97d6f | 122 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
| emh203 | 0:3d9c67d97d6f | 123 | ** a second loop below computes the remaining 1 to 3 samples. */ |
| emh203 | 0:3d9c67d97d6f | 124 | while(sample > 0u) |
| emh203 | 0:3d9c67d97d6f | 125 | { |
| emh203 | 0:3d9c67d97d6f | 126 | /* Read the input */ |
| emh203 | 0:3d9c67d97d6f | 127 | Xn = *pIn++; |
| emh203 | 0:3d9c67d97d6f | 128 | |
| emh203 | 0:3d9c67d97d6f | 129 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 130 | |
| emh203 | 0:3d9c67d97d6f | 131 | /* acc = b0 * x[n] */ |
| emh203 | 0:3d9c67d97d6f | 132 | acc = (q63_t) b0 *Xn; |
| emh203 | 0:3d9c67d97d6f | 133 | /* acc += b1 * x[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 134 | acc += (q63_t) b1 *Xn1; |
| emh203 | 0:3d9c67d97d6f | 135 | /* acc += b[2] * x[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 136 | acc += (q63_t) b2 *Xn2; |
| emh203 | 0:3d9c67d97d6f | 137 | /* acc += a1 * y[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 138 | acc += (q63_t) a1 *Yn1; |
| emh203 | 0:3d9c67d97d6f | 139 | /* acc += a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 140 | acc += (q63_t) 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 | |
| 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 | Yn2 = (uint32_t) acc_l >> lShift | acc_h << uShift; |
| emh203 | 0:3d9c67d97d6f | 152 | |
| emh203 | 0:3d9c67d97d6f | 153 | /* Store the output in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 154 | *pOut++ = Yn2; |
| emh203 | 0:3d9c67d97d6f | 155 | |
| emh203 | 0:3d9c67d97d6f | 156 | /* Read the second input */ |
| emh203 | 0:3d9c67d97d6f | 157 | Xn2 = *pIn++; |
| emh203 | 0:3d9c67d97d6f | 158 | |
| emh203 | 0:3d9c67d97d6f | 159 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 160 | |
| emh203 | 0:3d9c67d97d6f | 161 | /* acc = b0 * x[n] */ |
| emh203 | 0:3d9c67d97d6f | 162 | acc = (q63_t) b0 *Xn2; |
| emh203 | 0:3d9c67d97d6f | 163 | /* acc += b1 * x[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 164 | acc += (q63_t) b1 *Xn; |
| emh203 | 0:3d9c67d97d6f | 165 | /* acc += b[2] * x[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 166 | acc += (q63_t) b2 *Xn1; |
| emh203 | 0:3d9c67d97d6f | 167 | /* acc += a1 * y[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 168 | acc += (q63_t) a1 *Yn2; |
| emh203 | 0:3d9c67d97d6f | 169 | /* acc += a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 170 | acc += (q63_t) a2 *Yn1; |
| emh203 | 0:3d9c67d97d6f | 171 | |
| emh203 | 0:3d9c67d97d6f | 172 | |
| emh203 | 0:3d9c67d97d6f | 173 | /* The result is converted to 1.31, Yn1 variable is reused */ |
| emh203 | 0:3d9c67d97d6f | 174 | |
| emh203 | 0:3d9c67d97d6f | 175 | /* Calc lower part of acc */ |
| emh203 | 0:3d9c67d97d6f | 176 | acc_l = acc & 0xffffffff; |
| emh203 | 0:3d9c67d97d6f | 177 | |
| emh203 | 0:3d9c67d97d6f | 178 | /* Calc upper part of acc */ |
| emh203 | 0:3d9c67d97d6f | 179 | acc_h = (acc >> 32) & 0xffffffff; |
| emh203 | 0:3d9c67d97d6f | 180 | |
| emh203 | 0:3d9c67d97d6f | 181 | |
| emh203 | 0:3d9c67d97d6f | 182 | /* Apply shift for lower part of acc and upper part of acc */ |
| emh203 | 0:3d9c67d97d6f | 183 | Yn1 = (uint32_t) acc_l >> lShift | acc_h << uShift; |
| emh203 | 0:3d9c67d97d6f | 184 | |
| emh203 | 0:3d9c67d97d6f | 185 | /* Store the output in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 186 | *pOut++ = Yn1; |
| emh203 | 0:3d9c67d97d6f | 187 | |
| emh203 | 0:3d9c67d97d6f | 188 | /* Read the third input */ |
| emh203 | 0:3d9c67d97d6f | 189 | Xn1 = *pIn++; |
| emh203 | 0:3d9c67d97d6f | 190 | |
| emh203 | 0:3d9c67d97d6f | 191 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 192 | |
| emh203 | 0:3d9c67d97d6f | 193 | /* acc = b0 * x[n] */ |
| emh203 | 0:3d9c67d97d6f | 194 | acc = (q63_t) b0 *Xn1; |
| emh203 | 0:3d9c67d97d6f | 195 | /* acc += b1 * x[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 196 | acc += (q63_t) b1 *Xn2; |
| emh203 | 0:3d9c67d97d6f | 197 | /* acc += b[2] * x[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 198 | acc += (q63_t) b2 *Xn; |
| emh203 | 0:3d9c67d97d6f | 199 | /* acc += a1 * y[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 200 | acc += (q63_t) a1 *Yn1; |
| emh203 | 0:3d9c67d97d6f | 201 | /* acc += a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 202 | acc += (q63_t) a2 *Yn2; |
| emh203 | 0:3d9c67d97d6f | 203 | |
| emh203 | 0:3d9c67d97d6f | 204 | /* The result is converted to 1.31, Yn2 variable is reused */ |
| emh203 | 0:3d9c67d97d6f | 205 | /* Calc lower part of acc */ |
| emh203 | 0:3d9c67d97d6f | 206 | acc_l = acc & 0xffffffff; |
| emh203 | 0:3d9c67d97d6f | 207 | |
| emh203 | 0:3d9c67d97d6f | 208 | /* Calc upper part of acc */ |
| emh203 | 0:3d9c67d97d6f | 209 | acc_h = (acc >> 32) & 0xffffffff; |
| emh203 | 0:3d9c67d97d6f | 210 | |
| emh203 | 0:3d9c67d97d6f | 211 | |
| emh203 | 0:3d9c67d97d6f | 212 | /* Apply shift for lower part of acc and upper part of acc */ |
| emh203 | 0:3d9c67d97d6f | 213 | Yn2 = (uint32_t) acc_l >> lShift | acc_h << uShift; |
| emh203 | 0:3d9c67d97d6f | 214 | |
| emh203 | 0:3d9c67d97d6f | 215 | /* Store the output in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 216 | *pOut++ = Yn2; |
| emh203 | 0:3d9c67d97d6f | 217 | |
| emh203 | 0:3d9c67d97d6f | 218 | /* Read the forth input */ |
| emh203 | 0:3d9c67d97d6f | 219 | Xn = *pIn++; |
| emh203 | 0:3d9c67d97d6f | 220 | |
| emh203 | 0:3d9c67d97d6f | 221 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 222 | |
| emh203 | 0:3d9c67d97d6f | 223 | /* acc = b0 * x[n] */ |
| emh203 | 0:3d9c67d97d6f | 224 | acc = (q63_t) b0 *Xn; |
| emh203 | 0:3d9c67d97d6f | 225 | /* acc += b1 * x[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 226 | acc += (q63_t) b1 *Xn1; |
| emh203 | 0:3d9c67d97d6f | 227 | /* acc += b[2] * x[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 228 | acc += (q63_t) b2 *Xn2; |
| emh203 | 0:3d9c67d97d6f | 229 | /* acc += a1 * y[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 230 | acc += (q63_t) a1 *Yn2; |
| emh203 | 0:3d9c67d97d6f | 231 | /* acc += a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 232 | acc += (q63_t) a2 *Yn1; |
| emh203 | 0:3d9c67d97d6f | 233 | |
| emh203 | 0:3d9c67d97d6f | 234 | /* The result is converted to 1.31, Yn1 variable is reused */ |
| emh203 | 0:3d9c67d97d6f | 235 | /* Calc lower part of acc */ |
| emh203 | 0:3d9c67d97d6f | 236 | acc_l = acc & 0xffffffff; |
| emh203 | 0:3d9c67d97d6f | 237 | |
| emh203 | 0:3d9c67d97d6f | 238 | /* Calc upper part of acc */ |
| emh203 | 0:3d9c67d97d6f | 239 | acc_h = (acc >> 32) & 0xffffffff; |
| emh203 | 0:3d9c67d97d6f | 240 | |
| emh203 | 0:3d9c67d97d6f | 241 | /* Apply shift for lower part of acc and upper part of acc */ |
| emh203 | 0:3d9c67d97d6f | 242 | Yn1 = (uint32_t) acc_l >> lShift | acc_h << uShift; |
| emh203 | 0:3d9c67d97d6f | 243 | |
| emh203 | 0:3d9c67d97d6f | 244 | /* Every time after the output is computed state should be updated. */ |
| emh203 | 0:3d9c67d97d6f | 245 | /* The states should be updated as: */ |
| emh203 | 0:3d9c67d97d6f | 246 | /* Xn2 = Xn1 */ |
| emh203 | 0:3d9c67d97d6f | 247 | /* Xn1 = Xn */ |
| emh203 | 0:3d9c67d97d6f | 248 | /* Yn2 = Yn1 */ |
| emh203 | 0:3d9c67d97d6f | 249 | /* Yn1 = acc */ |
| emh203 | 0:3d9c67d97d6f | 250 | Xn2 = Xn1; |
| emh203 | 0:3d9c67d97d6f | 251 | Xn1 = Xn; |
| emh203 | 0:3d9c67d97d6f | 252 | |
| emh203 | 0:3d9c67d97d6f | 253 | /* Store the output in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 254 | *pOut++ = Yn1; |
| emh203 | 0:3d9c67d97d6f | 255 | |
| emh203 | 0:3d9c67d97d6f | 256 | /* decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 257 | sample--; |
| emh203 | 0:3d9c67d97d6f | 258 | } |
| emh203 | 0:3d9c67d97d6f | 259 | |
| emh203 | 0:3d9c67d97d6f | 260 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
| emh203 | 0:3d9c67d97d6f | 261 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 262 | sample = (blockSize & 0x3u); |
| emh203 | 0:3d9c67d97d6f | 263 | |
| emh203 | 0:3d9c67d97d6f | 264 | while(sample > 0u) |
| emh203 | 0:3d9c67d97d6f | 265 | { |
| emh203 | 0:3d9c67d97d6f | 266 | /* Read the input */ |
| emh203 | 0:3d9c67d97d6f | 267 | Xn = *pIn++; |
| emh203 | 0:3d9c67d97d6f | 268 | |
| emh203 | 0:3d9c67d97d6f | 269 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 270 | |
| emh203 | 0:3d9c67d97d6f | 271 | /* acc = b0 * x[n] */ |
| emh203 | 0:3d9c67d97d6f | 272 | acc = (q63_t) b0 *Xn; |
| emh203 | 0:3d9c67d97d6f | 273 | /* acc += b1 * x[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 274 | acc += (q63_t) b1 *Xn1; |
| emh203 | 0:3d9c67d97d6f | 275 | /* acc += b[2] * x[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 276 | acc += (q63_t) b2 *Xn2; |
| emh203 | 0:3d9c67d97d6f | 277 | /* acc += a1 * y[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 278 | acc += (q63_t) a1 *Yn1; |
| emh203 | 0:3d9c67d97d6f | 279 | /* acc += a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 280 | acc += (q63_t) a2 *Yn2; |
| emh203 | 0:3d9c67d97d6f | 281 | |
| emh203 | 0:3d9c67d97d6f | 282 | /* The result is converted to 1.31 */ |
| emh203 | 0:3d9c67d97d6f | 283 | acc = acc >> lShift; |
| emh203 | 0:3d9c67d97d6f | 284 | |
| emh203 | 0:3d9c67d97d6f | 285 | /* Every time after the output is computed state should be updated. */ |
| emh203 | 0:3d9c67d97d6f | 286 | /* The states should be updated as: */ |
| emh203 | 0:3d9c67d97d6f | 287 | /* Xn2 = Xn1 */ |
| emh203 | 0:3d9c67d97d6f | 288 | /* Xn1 = Xn */ |
| emh203 | 0:3d9c67d97d6f | 289 | /* Yn2 = Yn1 */ |
| emh203 | 0:3d9c67d97d6f | 290 | /* Yn1 = acc */ |
| emh203 | 0:3d9c67d97d6f | 291 | Xn2 = Xn1; |
| emh203 | 0:3d9c67d97d6f | 292 | Xn1 = Xn; |
| emh203 | 0:3d9c67d97d6f | 293 | Yn2 = Yn1; |
| emh203 | 0:3d9c67d97d6f | 294 | Yn1 = (q31_t) acc; |
| emh203 | 0:3d9c67d97d6f | 295 | |
| emh203 | 0:3d9c67d97d6f | 296 | /* Store the output in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 297 | *pOut++ = (q31_t) acc; |
| emh203 | 0:3d9c67d97d6f | 298 | |
| emh203 | 0:3d9c67d97d6f | 299 | /* decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 300 | sample--; |
| emh203 | 0:3d9c67d97d6f | 301 | } |
| emh203 | 0:3d9c67d97d6f | 302 | |
| emh203 | 0:3d9c67d97d6f | 303 | /* The first stage goes from the input buffer to the output buffer. */ |
| emh203 | 0:3d9c67d97d6f | 304 | /* Subsequent stages occur in-place in the output buffer */ |
| emh203 | 0:3d9c67d97d6f | 305 | pIn = pDst; |
| emh203 | 0:3d9c67d97d6f | 306 | |
| emh203 | 0:3d9c67d97d6f | 307 | /* Reset to destination pointer */ |
| emh203 | 0:3d9c67d97d6f | 308 | pOut = pDst; |
| emh203 | 0:3d9c67d97d6f | 309 | |
| emh203 | 0:3d9c67d97d6f | 310 | /* Store the updated state variables back into the pState array */ |
| emh203 | 0:3d9c67d97d6f | 311 | *pState++ = Xn1; |
| emh203 | 0:3d9c67d97d6f | 312 | *pState++ = Xn2; |
| emh203 | 0:3d9c67d97d6f | 313 | *pState++ = Yn1; |
| emh203 | 0:3d9c67d97d6f | 314 | *pState++ = Yn2; |
| emh203 | 0:3d9c67d97d6f | 315 | |
| emh203 | 0:3d9c67d97d6f | 316 | } while(--stage); |
| emh203 | 0:3d9c67d97d6f | 317 | |
| emh203 | 0:3d9c67d97d6f | 318 | #else |
| emh203 | 0:3d9c67d97d6f | 319 | |
| emh203 | 0:3d9c67d97d6f | 320 | /* Run the below code for Cortex-M0 */ |
| emh203 | 0:3d9c67d97d6f | 321 | |
| emh203 | 0:3d9c67d97d6f | 322 | do |
| emh203 | 0:3d9c67d97d6f | 323 | { |
| emh203 | 0:3d9c67d97d6f | 324 | /* Reading the coefficients */ |
| emh203 | 0:3d9c67d97d6f | 325 | b0 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 326 | b1 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 327 | b2 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 328 | a1 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 329 | a2 = *pCoeffs++; |
| emh203 | 0:3d9c67d97d6f | 330 | |
| emh203 | 0:3d9c67d97d6f | 331 | /* Reading the state values */ |
| emh203 | 0:3d9c67d97d6f | 332 | Xn1 = pState[0]; |
| emh203 | 0:3d9c67d97d6f | 333 | Xn2 = pState[1]; |
| emh203 | 0:3d9c67d97d6f | 334 | Yn1 = pState[2]; |
| emh203 | 0:3d9c67d97d6f | 335 | Yn2 = pState[3]; |
| emh203 | 0:3d9c67d97d6f | 336 | |
| emh203 | 0:3d9c67d97d6f | 337 | /* The variables acc holds the output value that is computed: |
| emh203 | 0:3d9c67d97d6f | 338 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
| emh203 | 0:3d9c67d97d6f | 339 | */ |
| emh203 | 0:3d9c67d97d6f | 340 | |
| emh203 | 0:3d9c67d97d6f | 341 | sample = blockSize; |
| emh203 | 0:3d9c67d97d6f | 342 | |
| emh203 | 0:3d9c67d97d6f | 343 | while(sample > 0u) |
| emh203 | 0:3d9c67d97d6f | 344 | { |
| emh203 | 0:3d9c67d97d6f | 345 | /* Read the input */ |
| emh203 | 0:3d9c67d97d6f | 346 | Xn = *pIn++; |
| emh203 | 0:3d9c67d97d6f | 347 | |
| emh203 | 0:3d9c67d97d6f | 348 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 349 | /* acc = b0 * x[n] */ |
| emh203 | 0:3d9c67d97d6f | 350 | acc = (q63_t) b0 *Xn; |
| emh203 | 0:3d9c67d97d6f | 351 | |
| emh203 | 0:3d9c67d97d6f | 352 | /* acc += b1 * x[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 353 | acc += (q63_t) b1 *Xn1; |
| emh203 | 0:3d9c67d97d6f | 354 | /* acc += b[2] * x[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 355 | acc += (q63_t) b2 *Xn2; |
| emh203 | 0:3d9c67d97d6f | 356 | /* acc += a1 * y[n-1] */ |
| emh203 | 0:3d9c67d97d6f | 357 | acc += (q63_t) a1 *Yn1; |
| emh203 | 0:3d9c67d97d6f | 358 | /* acc += a2 * y[n-2] */ |
| emh203 | 0:3d9c67d97d6f | 359 | acc += (q63_t) a2 *Yn2; |
| emh203 | 0:3d9c67d97d6f | 360 | |
| emh203 | 0:3d9c67d97d6f | 361 | /* The result is converted to 1.31 */ |
| emh203 | 0:3d9c67d97d6f | 362 | acc = acc >> lShift; |
| emh203 | 0:3d9c67d97d6f | 363 | |
| emh203 | 0:3d9c67d97d6f | 364 | /* Every time after the output is computed state should be updated. */ |
| emh203 | 0:3d9c67d97d6f | 365 | /* The states should be updated as: */ |
| emh203 | 0:3d9c67d97d6f | 366 | /* Xn2 = Xn1 */ |
| emh203 | 0:3d9c67d97d6f | 367 | /* Xn1 = Xn */ |
| emh203 | 0:3d9c67d97d6f | 368 | /* Yn2 = Yn1 */ |
| emh203 | 0:3d9c67d97d6f | 369 | /* Yn1 = acc */ |
| emh203 | 0:3d9c67d97d6f | 370 | Xn2 = Xn1; |
| emh203 | 0:3d9c67d97d6f | 371 | Xn1 = Xn; |
| emh203 | 0:3d9c67d97d6f | 372 | Yn2 = Yn1; |
| emh203 | 0:3d9c67d97d6f | 373 | Yn1 = (q31_t) acc; |
| emh203 | 0:3d9c67d97d6f | 374 | |
| emh203 | 0:3d9c67d97d6f | 375 | /* Store the output in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 376 | *pOut++ = (q31_t) acc; |
| emh203 | 0:3d9c67d97d6f | 377 | |
| emh203 | 0:3d9c67d97d6f | 378 | /* decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 379 | sample--; |
| emh203 | 0:3d9c67d97d6f | 380 | } |
| emh203 | 0:3d9c67d97d6f | 381 | |
| emh203 | 0:3d9c67d97d6f | 382 | /* The first stage goes from the input buffer to the output buffer. */ |
| emh203 | 0:3d9c67d97d6f | 383 | /* Subsequent stages occur in-place in the output buffer */ |
| emh203 | 0:3d9c67d97d6f | 384 | pIn = pDst; |
| emh203 | 0:3d9c67d97d6f | 385 | |
| emh203 | 0:3d9c67d97d6f | 386 | /* Reset to destination pointer */ |
| emh203 | 0:3d9c67d97d6f | 387 | pOut = pDst; |
| emh203 | 0:3d9c67d97d6f | 388 | |
| emh203 | 0:3d9c67d97d6f | 389 | /* Store the updated state variables back into the pState array */ |
| emh203 | 0:3d9c67d97d6f | 390 | *pState++ = Xn1; |
| emh203 | 0:3d9c67d97d6f | 391 | *pState++ = Xn2; |
| emh203 | 0:3d9c67d97d6f | 392 | *pState++ = Yn1; |
| emh203 | 0:3d9c67d97d6f | 393 | *pState++ = Yn2; |
| emh203 | 0:3d9c67d97d6f | 394 | |
| emh203 | 0:3d9c67d97d6f | 395 | } while(--stage); |
| emh203 | 0:3d9c67d97d6f | 396 | |
| emh203 | 0:3d9c67d97d6f | 397 | #endif /* #ifndef ARM_MATH_CM0_FAMILY_FAMILY */ |
| emh203 | 0:3d9c67d97d6f | 398 | } |
| emh203 | 0:3d9c67d97d6f | 399 | |
| emh203 | 0:3d9c67d97d6f | 400 | |
| emh203 | 0:3d9c67d97d6f | 401 | |
| emh203 | 0:3d9c67d97d6f | 402 | |
| emh203 | 0:3d9c67d97d6f | 403 | /** |
| emh203 | 0:3d9c67d97d6f | 404 | * @} end of BiquadCascadeDF1 group |
| emh203 | 0:3d9c67d97d6f | 405 | */ |
Eli Hughes