CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details
Dependents: K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more
src/Cortex-M4-M3/FilteringFunctions/arm_biquad_cascade_df1_f32.c@0:1014af42efd9, 2011-03-10 (annotated)
- Committer:
- simon
- Date:
- Thu Mar 10 15:07:50 2011 +0000
- Revision:
- 0:1014af42efd9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:1014af42efd9 | 1 | /* ---------------------------------------------------------------------- |
simon | 0:1014af42efd9 | 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. |
simon | 0:1014af42efd9 | 3 | * |
simon | 0:1014af42efd9 | 4 | * $Date: 29. November 2010 |
simon | 0:1014af42efd9 | 5 | * $Revision: V1.0.3 |
simon | 0:1014af42efd9 | 6 | * |
simon | 0:1014af42efd9 | 7 | * Project: CMSIS DSP Library |
simon | 0:1014af42efd9 | 8 | * Title: arm_biquad_cascade_df1_f32.c |
simon | 0:1014af42efd9 | 9 | * |
simon | 0:1014af42efd9 | 10 | * Description: Processing function for the |
simon | 0:1014af42efd9 | 11 | * floating-point Biquad cascade DirectFormI(DF1) filter. |
simon | 0:1014af42efd9 | 12 | * |
simon | 0:1014af42efd9 | 13 | * Target Processor: Cortex-M4/Cortex-M3 |
simon | 0:1014af42efd9 | 14 | * |
simon | 0:1014af42efd9 | 15 | * Version 1.0.3 2010/11/29 |
simon | 0:1014af42efd9 | 16 | * Re-organized the CMSIS folders and updated documentation. |
simon | 0:1014af42efd9 | 17 | * |
simon | 0:1014af42efd9 | 18 | * Version 1.0.2 2010/11/11 |
simon | 0:1014af42efd9 | 19 | * Documentation updated. |
simon | 0:1014af42efd9 | 20 | * |
simon | 0:1014af42efd9 | 21 | * Version 1.0.1 2010/10/05 |
simon | 0:1014af42efd9 | 22 | * Production release and review comments incorporated. |
simon | 0:1014af42efd9 | 23 | * |
simon | 0:1014af42efd9 | 24 | * Version 1.0.0 2010/09/20 |
simon | 0:1014af42efd9 | 25 | * Production release and review comments incorporated. |
simon | 0:1014af42efd9 | 26 | * |
simon | 0:1014af42efd9 | 27 | * Version 0.0.5 2010/04/26 |
simon | 0:1014af42efd9 | 28 | * incorporated review comments and updated with latest CMSIS layer |
simon | 0:1014af42efd9 | 29 | * |
simon | 0:1014af42efd9 | 30 | * Version 0.0.3 2010/03/10 |
simon | 0:1014af42efd9 | 31 | * Initial version |
simon | 0:1014af42efd9 | 32 | * -------------------------------------------------------------------- */ |
simon | 0:1014af42efd9 | 33 | |
simon | 0:1014af42efd9 | 34 | #include "arm_math.h" |
simon | 0:1014af42efd9 | 35 | |
simon | 0:1014af42efd9 | 36 | /** |
simon | 0:1014af42efd9 | 37 | * @ingroup groupFilters |
simon | 0:1014af42efd9 | 38 | */ |
simon | 0:1014af42efd9 | 39 | |
simon | 0:1014af42efd9 | 40 | /** |
simon | 0:1014af42efd9 | 41 | * @defgroup BiquadCascadeDF1 Biquad Cascade IIR Filters Using Direct Form I Structure |
simon | 0:1014af42efd9 | 42 | * |
simon | 0:1014af42efd9 | 43 | * This set of functions implements arbitrary order recursive (IIR) filters. |
simon | 0:1014af42efd9 | 44 | * The filters are implemented as a cascade of second order Biquad sections. |
simon | 0:1014af42efd9 | 45 | * The functions support Q15, Q31 and floating-point data types. Fast version of Q15 and Q31 also supported. |
simon | 0:1014af42efd9 | 46 | * |
simon | 0:1014af42efd9 | 47 | * The functions operate on blocks of input and output data and each call to the function |
simon | 0:1014af42efd9 | 48 | * processes <code>blockSize</code> samples through the filter. |
simon | 0:1014af42efd9 | 49 | * <code>pSrc</code> points to the array of input data and |
simon | 0:1014af42efd9 | 50 | * <code>pDst</code> points to the array of output data. |
simon | 0:1014af42efd9 | 51 | * Both arrays contain <code>blockSize</code> values. |
simon | 0:1014af42efd9 | 52 | * |
simon | 0:1014af42efd9 | 53 | * \par Algorithm |
simon | 0:1014af42efd9 | 54 | * Each Biquad stage implements a second order filter using the difference equation: |
simon | 0:1014af42efd9 | 55 | * <pre> |
simon | 0:1014af42efd9 | 56 | * y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
simon | 0:1014af42efd9 | 57 | * </pre> |
simon | 0:1014af42efd9 | 58 | * A Direct Form I algorithm is used with 5 coefficients and 4 state variables per stage. |
simon | 0:1014af42efd9 | 59 | * \image html Biquad.gif "Single Biquad filter stage" |
simon | 0:1014af42efd9 | 60 | * Coefficients <code>b0, b1 and b2 </code> multiply the input signal <code>x[n]</code> and are referred to as the feedforward coefficients. |
simon | 0:1014af42efd9 | 61 | * Coefficients <code>a1</code> and <code>a2</code> multiply the output signal <code>y[n]</code> and are referred to as the feedback coefficients. |
simon | 0:1014af42efd9 | 62 | * Pay careful attention to the sign of the feedback coefficients. |
simon | 0:1014af42efd9 | 63 | * Some design tools use the difference equation |
simon | 0:1014af42efd9 | 64 | * <pre> |
simon | 0:1014af42efd9 | 65 | * y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] - a1 * y[n-1] - a2 * y[n-2] |
simon | 0:1014af42efd9 | 66 | * </pre> |
simon | 0:1014af42efd9 | 67 | * In this case the feedback coefficients <code>a1</code> and <code>a2</code> must be negated when used with the CMSIS DSP Library. |
simon | 0:1014af42efd9 | 68 | * |
simon | 0:1014af42efd9 | 69 | * \par |
simon | 0:1014af42efd9 | 70 | * Higher order filters are realized as a cascade of second order sections. |
simon | 0:1014af42efd9 | 71 | * <code>numStages</code> refers to the number of second order stages used. |
simon | 0:1014af42efd9 | 72 | * For example, an 8th order filter would be realized with <code>numStages=4</code> second order stages. |
simon | 0:1014af42efd9 | 73 | * \image html BiquadCascade.gif "8th order filter using a cascade of Biquad stages" |
simon | 0:1014af42efd9 | 74 | * A 9th order filter would be realized with <code>numStages=5</code> second order stages with the coefficients for one of the stages configured as a first order filter (<code>b2=0</code> and <code>a2=0</code>). |
simon | 0:1014af42efd9 | 75 | * |
simon | 0:1014af42efd9 | 76 | * \par |
simon | 0:1014af42efd9 | 77 | * The <code>pState</code> points to state variables array. |
simon | 0:1014af42efd9 | 78 | * Each Biquad stage has 4 state variables <code>x[n-1], x[n-2], y[n-1],</code> and <code>y[n-2]</code>. |
simon | 0:1014af42efd9 | 79 | * The state variables are arranged in the <code>pState</code> array as: |
simon | 0:1014af42efd9 | 80 | * <pre> |
simon | 0:1014af42efd9 | 81 | * {x[n-1], x[n-2], y[n-1], y[n-2]} |
simon | 0:1014af42efd9 | 82 | * </pre> |
simon | 0:1014af42efd9 | 83 | * |
simon | 0:1014af42efd9 | 84 | * \par |
simon | 0:1014af42efd9 | 85 | * The 4 state variables for stage 1 are first, then the 4 state variables for stage 2, and so on. |
simon | 0:1014af42efd9 | 86 | * The state array has a total length of <code>4*numStages</code> values. |
simon | 0:1014af42efd9 | 87 | * The state variables are updated after each block of data is processed, the coefficients are untouched. |
simon | 0:1014af42efd9 | 88 | * |
simon | 0:1014af42efd9 | 89 | * \par Instance Structure |
simon | 0:1014af42efd9 | 90 | * The coefficients and state variables for a filter are stored together in an instance data structure. |
simon | 0:1014af42efd9 | 91 | * A separate instance structure must be defined for each filter. |
simon | 0:1014af42efd9 | 92 | * Coefficient arrays may be shared among several instances while state variable arrays cannot be shared. |
simon | 0:1014af42efd9 | 93 | * There are separate instance structure declarations for each of the 3 supported data types. |
simon | 0:1014af42efd9 | 94 | * |
simon | 0:1014af42efd9 | 95 | * \par Init Functions |
simon | 0:1014af42efd9 | 96 | * There is also an associated initialization function for each data type. |
simon | 0:1014af42efd9 | 97 | * The initialization function performs following operations: |
simon | 0:1014af42efd9 | 98 | * - Sets the values of the internal structure fields. |
simon | 0:1014af42efd9 | 99 | * - Zeros out the values in the state buffer. |
simon | 0:1014af42efd9 | 100 | * |
simon | 0:1014af42efd9 | 101 | * \par |
simon | 0:1014af42efd9 | 102 | * Use of the initialization function is optional. |
simon | 0:1014af42efd9 | 103 | * However, if the initialization function is used, then the instance structure cannot be placed into a const data section. |
simon | 0:1014af42efd9 | 104 | * To place an instance structure into a const data section, the instance structure must be manually initialized. |
simon | 0:1014af42efd9 | 105 | * Set the values in the state buffer to zeros before static initialization. |
simon | 0:1014af42efd9 | 106 | * The code below statically initializes each of the 3 different data type filter instance structures |
simon | 0:1014af42efd9 | 107 | * <pre> |
simon | 0:1014af42efd9 | 108 | * arm_biquad_casd_df1_inst_f32 S1 = {numStages, pState, pCoeffs}; |
simon | 0:1014af42efd9 | 109 | * arm_biquad_casd_df1_inst_q15 S2 = {numStages, pState, pCoeffs, postShift}; |
simon | 0:1014af42efd9 | 110 | * arm_biquad_casd_df1_inst_q31 S3 = {numStages, pState, pCoeffs, postShift}; |
simon | 0:1014af42efd9 | 111 | * </pre> |
simon | 0:1014af42efd9 | 112 | * where <code>numStages</code> is the number of Biquad stages in the filter; <code>pState</code> is the address of the state buffer; |
simon | 0:1014af42efd9 | 113 | * <code>pCoeffs</code> is the address of the coefficient buffer; <code>postShift</code> shift to be applied. |
simon | 0:1014af42efd9 | 114 | * |
simon | 0:1014af42efd9 | 115 | * \par Fixed-Point Behavior |
simon | 0:1014af42efd9 | 116 | * Care must be taken when using the Q15 and Q31 versions of the Biquad Cascade filter functions. |
simon | 0:1014af42efd9 | 117 | * Following issues must be considered: |
simon | 0:1014af42efd9 | 118 | * - Scaling of coefficients |
simon | 0:1014af42efd9 | 119 | * - Filter gain |
simon | 0:1014af42efd9 | 120 | * - Overflow and saturation |
simon | 0:1014af42efd9 | 121 | * |
simon | 0:1014af42efd9 | 122 | * \par |
simon | 0:1014af42efd9 | 123 | * <b>Scaling of coefficients: </b> |
simon | 0:1014af42efd9 | 124 | * Filter coefficients are represented as fractional values and |
simon | 0:1014af42efd9 | 125 | * coefficients are restricted to lie in the range <code>[-1 +1)</code>. |
simon | 0:1014af42efd9 | 126 | * The fixed-point functions have an additional scaling parameter <code>postShift</code> |
simon | 0:1014af42efd9 | 127 | * which allow the filter coefficients to exceed the range <code>[+1 -1)</code>. |
simon | 0:1014af42efd9 | 128 | * At the output of the filter's accumulator is a shift register which shifts the result by <code>postShift</code> bits. |
simon | 0:1014af42efd9 | 129 | * \image html BiquadPostshift.gif "Fixed-point Biquad with shift by postShift bits after accumulator" |
simon | 0:1014af42efd9 | 130 | * This essentially scales the filter coefficients by <code>2^postShift</code>. |
simon | 0:1014af42efd9 | 131 | * For example, to realize the coefficients |
simon | 0:1014af42efd9 | 132 | * <pre> |
simon | 0:1014af42efd9 | 133 | * {1.5, -0.8, 1.2, 1.6, -0.9} |
simon | 0:1014af42efd9 | 134 | * </pre> |
simon | 0:1014af42efd9 | 135 | * set the pCoeffs array to: |
simon | 0:1014af42efd9 | 136 | * <pre> |
simon | 0:1014af42efd9 | 137 | * {0.75, -0.4, 0.6, 0.8, -0.45} |
simon | 0:1014af42efd9 | 138 | * </pre> |
simon | 0:1014af42efd9 | 139 | * and set <code>postShift=1</code> |
simon | 0:1014af42efd9 | 140 | * |
simon | 0:1014af42efd9 | 141 | * \par |
simon | 0:1014af42efd9 | 142 | * <b>Filter gain: </b> |
simon | 0:1014af42efd9 | 143 | * The frequency response of a Biquad filter is a function of its coefficients. |
simon | 0:1014af42efd9 | 144 | * It is possible for the gain through the filter to exceed 1.0 meaning that the filter increases the amplitude of certain frequencies. |
simon | 0:1014af42efd9 | 145 | * This means that an input signal with amplitude < 1.0 may result in an output > 1.0 and these are saturated or overflowed based on the implementation of the filter. |
simon | 0:1014af42efd9 | 146 | * To avoid this behavior the filter needs to be scaled down such that its peak gain < 1.0 or the input signal must be scaled down so that the combination of input and filter are never overflowed. |
simon | 0:1014af42efd9 | 147 | * |
simon | 0:1014af42efd9 | 148 | * \par |
simon | 0:1014af42efd9 | 149 | * <b>Overflow and saturation: </b> |
simon | 0:1014af42efd9 | 150 | * For Q15 and Q31 versions, it is described separately as part of the function specific documentation below. |
simon | 0:1014af42efd9 | 151 | */ |
simon | 0:1014af42efd9 | 152 | |
simon | 0:1014af42efd9 | 153 | /** |
simon | 0:1014af42efd9 | 154 | * @addtogroup BiquadCascadeDF1 |
simon | 0:1014af42efd9 | 155 | * @{ |
simon | 0:1014af42efd9 | 156 | */ |
simon | 0:1014af42efd9 | 157 | |
simon | 0:1014af42efd9 | 158 | /** |
simon | 0:1014af42efd9 | 159 | * @param[in] *S points to an instance of the floating-point Biquad cascade structure. |
simon | 0:1014af42efd9 | 160 | * @param[in] *pSrc points to the block of input data. |
simon | 0:1014af42efd9 | 161 | * @param[out] *pDst points to the block of output data. |
simon | 0:1014af42efd9 | 162 | * @param[in] blockSize number of samples to process per call. |
simon | 0:1014af42efd9 | 163 | * @return none. |
simon | 0:1014af42efd9 | 164 | * |
simon | 0:1014af42efd9 | 165 | */ |
simon | 0:1014af42efd9 | 166 | |
simon | 0:1014af42efd9 | 167 | void arm_biquad_cascade_df1_f32( |
simon | 0:1014af42efd9 | 168 | const arm_biquad_casd_df1_inst_f32 * S, |
simon | 0:1014af42efd9 | 169 | float32_t * pSrc, |
simon | 0:1014af42efd9 | 170 | float32_t * pDst, |
simon | 0:1014af42efd9 | 171 | uint32_t blockSize) |
simon | 0:1014af42efd9 | 172 | { |
simon | 0:1014af42efd9 | 173 | float32_t *pIn = pSrc; /* source pointer */ |
simon | 0:1014af42efd9 | 174 | float32_t *pOut = pDst; /* destination pointer */ |
simon | 0:1014af42efd9 | 175 | float32_t *pState = S->pState; /* pState pointer */ |
simon | 0:1014af42efd9 | 176 | float32_t *pCoeffs = S->pCoeffs; /* coefficient pointer */ |
simon | 0:1014af42efd9 | 177 | float32_t acc; /* Simulates the accumulator */ |
simon | 0:1014af42efd9 | 178 | float32_t b0, b1, b2, a1, a2; /* Filter coefficients */ |
simon | 0:1014af42efd9 | 179 | float32_t Xn1, Xn2, Yn1, Yn2; /* Filter pState variables */ |
simon | 0:1014af42efd9 | 180 | float32_t Xn; /* temporary input */ |
simon | 0:1014af42efd9 | 181 | uint32_t sample, stage = S->numStages; /* loop counters */ |
simon | 0:1014af42efd9 | 182 | |
simon | 0:1014af42efd9 | 183 | |
simon | 0:1014af42efd9 | 184 | do |
simon | 0:1014af42efd9 | 185 | { |
simon | 0:1014af42efd9 | 186 | /* Reading the coefficients */ |
simon | 0:1014af42efd9 | 187 | b0 = *pCoeffs++; |
simon | 0:1014af42efd9 | 188 | b1 = *pCoeffs++; |
simon | 0:1014af42efd9 | 189 | b2 = *pCoeffs++; |
simon | 0:1014af42efd9 | 190 | a1 = *pCoeffs++; |
simon | 0:1014af42efd9 | 191 | a2 = *pCoeffs++; |
simon | 0:1014af42efd9 | 192 | |
simon | 0:1014af42efd9 | 193 | /* Reading the pState values */ |
simon | 0:1014af42efd9 | 194 | Xn1 = pState[0]; |
simon | 0:1014af42efd9 | 195 | Xn2 = pState[1]; |
simon | 0:1014af42efd9 | 196 | Yn1 = pState[2]; |
simon | 0:1014af42efd9 | 197 | Yn2 = pState[3]; |
simon | 0:1014af42efd9 | 198 | |
simon | 0:1014af42efd9 | 199 | /* Apply loop unrolling and compute 4 output values simultaneously. */ |
simon | 0:1014af42efd9 | 200 | /* The variable acc hold output values that are being computed: |
simon | 0:1014af42efd9 | 201 | * |
simon | 0:1014af42efd9 | 202 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
simon | 0:1014af42efd9 | 203 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
simon | 0:1014af42efd9 | 204 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
simon | 0:1014af42efd9 | 205 | * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] |
simon | 0:1014af42efd9 | 206 | */ |
simon | 0:1014af42efd9 | 207 | |
simon | 0:1014af42efd9 | 208 | sample = blockSize >> 2u; |
simon | 0:1014af42efd9 | 209 | |
simon | 0:1014af42efd9 | 210 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
simon | 0:1014af42efd9 | 211 | ** a second loop below computes the remaining 1 to 3 samples. */ |
simon | 0:1014af42efd9 | 212 | while(sample > 0u) |
simon | 0:1014af42efd9 | 213 | { |
simon | 0:1014af42efd9 | 214 | /* Read the first input */ |
simon | 0:1014af42efd9 | 215 | Xn = *pIn++; |
simon | 0:1014af42efd9 | 216 | |
simon | 0:1014af42efd9 | 217 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
simon | 0:1014af42efd9 | 218 | Yn2 = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn1) + (a2 * Yn2); |
simon | 0:1014af42efd9 | 219 | |
simon | 0:1014af42efd9 | 220 | /* Store the result in the accumulator in the destination buffer. */ |
simon | 0:1014af42efd9 | 221 | *pOut++ = Yn2; |
simon | 0:1014af42efd9 | 222 | |
simon | 0:1014af42efd9 | 223 | /* Every time after the output is computed state should be updated. */ |
simon | 0:1014af42efd9 | 224 | /* The states should be updated as: */ |
simon | 0:1014af42efd9 | 225 | /* Xn2 = Xn1 */ |
simon | 0:1014af42efd9 | 226 | /* Xn1 = Xn */ |
simon | 0:1014af42efd9 | 227 | /* Yn2 = Yn1 */ |
simon | 0:1014af42efd9 | 228 | /* Yn1 = acc */ |
simon | 0:1014af42efd9 | 229 | |
simon | 0:1014af42efd9 | 230 | /* Read the second input */ |
simon | 0:1014af42efd9 | 231 | Xn2 = *pIn++; |
simon | 0:1014af42efd9 | 232 | |
simon | 0:1014af42efd9 | 233 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
simon | 0:1014af42efd9 | 234 | Yn1 = (b0 * Xn2) + (b1 * Xn) + (b2 * Xn1) + (a1 * Yn2) + (a2 * Yn1); |
simon | 0:1014af42efd9 | 235 | |
simon | 0:1014af42efd9 | 236 | /* Store the result in the accumulator in the destination buffer. */ |
simon | 0:1014af42efd9 | 237 | *pOut++ = Yn1; |
simon | 0:1014af42efd9 | 238 | |
simon | 0:1014af42efd9 | 239 | /* Every time after the output is computed state should be updated. */ |
simon | 0:1014af42efd9 | 240 | /* The states should be updated as: */ |
simon | 0:1014af42efd9 | 241 | /* Xn2 = Xn1 */ |
simon | 0:1014af42efd9 | 242 | /* Xn1 = Xn */ |
simon | 0:1014af42efd9 | 243 | /* Yn2 = Yn1 */ |
simon | 0:1014af42efd9 | 244 | /* Yn1 = acc */ |
simon | 0:1014af42efd9 | 245 | |
simon | 0:1014af42efd9 | 246 | /* Read the third input */ |
simon | 0:1014af42efd9 | 247 | Xn1 = *pIn++; |
simon | 0:1014af42efd9 | 248 | |
simon | 0:1014af42efd9 | 249 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
simon | 0:1014af42efd9 | 250 | Yn2 = (b0 * Xn1) + (b1 * Xn2) + (b2 * Xn) + (a1 * Yn1) + (a2 * Yn2); |
simon | 0:1014af42efd9 | 251 | |
simon | 0:1014af42efd9 | 252 | /* Store the result in the accumulator in the destination buffer. */ |
simon | 0:1014af42efd9 | 253 | *pOut++ = Yn2; |
simon | 0:1014af42efd9 | 254 | |
simon | 0:1014af42efd9 | 255 | /* Every time after the output is computed state should be updated. */ |
simon | 0:1014af42efd9 | 256 | /* The states should be updated as: */ |
simon | 0:1014af42efd9 | 257 | /* Xn2 = Xn1 */ |
simon | 0:1014af42efd9 | 258 | /* Xn1 = Xn */ |
simon | 0:1014af42efd9 | 259 | /* Yn2 = Yn1 */ |
simon | 0:1014af42efd9 | 260 | /* Yn1 = acc */ |
simon | 0:1014af42efd9 | 261 | |
simon | 0:1014af42efd9 | 262 | /* Read the forth input */ |
simon | 0:1014af42efd9 | 263 | Xn = *pIn++; |
simon | 0:1014af42efd9 | 264 | |
simon | 0:1014af42efd9 | 265 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
simon | 0:1014af42efd9 | 266 | Yn1 = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn2) + (a2 * Yn1); |
simon | 0:1014af42efd9 | 267 | |
simon | 0:1014af42efd9 | 268 | /* Store the result in the accumulator in the destination buffer. */ |
simon | 0:1014af42efd9 | 269 | *pOut++ = Yn1; |
simon | 0:1014af42efd9 | 270 | |
simon | 0:1014af42efd9 | 271 | /* Every time after the output is computed state should be updated. */ |
simon | 0:1014af42efd9 | 272 | /* The states should be updated as: */ |
simon | 0:1014af42efd9 | 273 | /* Xn2 = Xn1 */ |
simon | 0:1014af42efd9 | 274 | /* Xn1 = Xn */ |
simon | 0:1014af42efd9 | 275 | /* Yn2 = Yn1 */ |
simon | 0:1014af42efd9 | 276 | /* Yn1 = acc */ |
simon | 0:1014af42efd9 | 277 | Xn2 = Xn1; |
simon | 0:1014af42efd9 | 278 | Xn1 = Xn; |
simon | 0:1014af42efd9 | 279 | |
simon | 0:1014af42efd9 | 280 | /* decrement the loop counter */ |
simon | 0:1014af42efd9 | 281 | sample--; |
simon | 0:1014af42efd9 | 282 | |
simon | 0:1014af42efd9 | 283 | } |
simon | 0:1014af42efd9 | 284 | |
simon | 0:1014af42efd9 | 285 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
simon | 0:1014af42efd9 | 286 | ** No loop unrolling is used. */ |
simon | 0:1014af42efd9 | 287 | sample = blockSize & 0x3u; |
simon | 0:1014af42efd9 | 288 | |
simon | 0:1014af42efd9 | 289 | while(sample > 0u) |
simon | 0:1014af42efd9 | 290 | { |
simon | 0:1014af42efd9 | 291 | /* Read the input */ |
simon | 0:1014af42efd9 | 292 | Xn = *pIn++; |
simon | 0:1014af42efd9 | 293 | |
simon | 0:1014af42efd9 | 294 | /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ |
simon | 0:1014af42efd9 | 295 | acc = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn1) + (a2 * Yn2); |
simon | 0:1014af42efd9 | 296 | |
simon | 0:1014af42efd9 | 297 | /* Store the result in the accumulator in the destination buffer. */ |
simon | 0:1014af42efd9 | 298 | *pOut++ = acc; |
simon | 0:1014af42efd9 | 299 | |
simon | 0:1014af42efd9 | 300 | /* Every time after the output is computed state should be updated. */ |
simon | 0:1014af42efd9 | 301 | /* The states should be updated as: */ |
simon | 0:1014af42efd9 | 302 | /* Xn2 = Xn1 */ |
simon | 0:1014af42efd9 | 303 | /* Xn1 = Xn */ |
simon | 0:1014af42efd9 | 304 | /* Yn2 = Yn1 */ |
simon | 0:1014af42efd9 | 305 | /* Yn1 = acc */ |
simon | 0:1014af42efd9 | 306 | Xn2 = Xn1; |
simon | 0:1014af42efd9 | 307 | Xn1 = Xn; |
simon | 0:1014af42efd9 | 308 | Yn2 = Yn1; |
simon | 0:1014af42efd9 | 309 | Yn1 = acc; |
simon | 0:1014af42efd9 | 310 | |
simon | 0:1014af42efd9 | 311 | /* decrement the loop counter */ |
simon | 0:1014af42efd9 | 312 | sample--; |
simon | 0:1014af42efd9 | 313 | |
simon | 0:1014af42efd9 | 314 | } |
simon | 0:1014af42efd9 | 315 | |
simon | 0:1014af42efd9 | 316 | /* Store the updated state variables back into the pState array */ |
simon | 0:1014af42efd9 | 317 | *pState++ = Xn1; |
simon | 0:1014af42efd9 | 318 | *pState++ = Xn2; |
simon | 0:1014af42efd9 | 319 | *pState++ = Yn1; |
simon | 0:1014af42efd9 | 320 | *pState++ = Yn2; |
simon | 0:1014af42efd9 | 321 | |
simon | 0:1014af42efd9 | 322 | /* The first stage goes from the input wire to the output wire. */ |
simon | 0:1014af42efd9 | 323 | /* Subsequent numStages occur in-place in the output wire */ |
simon | 0:1014af42efd9 | 324 | pIn = pDst; |
simon | 0:1014af42efd9 | 325 | |
simon | 0:1014af42efd9 | 326 | /* Reset the output pointer */ |
simon | 0:1014af42efd9 | 327 | pOut = pDst; |
simon | 0:1014af42efd9 | 328 | |
simon | 0:1014af42efd9 | 329 | /* decrement the loop counter */ |
simon | 0:1014af42efd9 | 330 | stage--; |
simon | 0:1014af42efd9 | 331 | |
simon | 0:1014af42efd9 | 332 | } while(stage > 0u); |
simon | 0:1014af42efd9 | 333 | |
simon | 0:1014af42efd9 | 334 | } |
simon | 0:1014af42efd9 | 335 | |
simon | 0:1014af42efd9 | 336 | |
simon | 0:1014af42efd9 | 337 | /** |
simon | 0:1014af42efd9 | 338 | * @} end of BiquadCascadeDF1 group |
simon | 0:1014af42efd9 | 339 | */ |