CMSIS DSP library

Dependents:   performance_timer Surfboard_ gps2rtty Capstone ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Committer:
emilmont
Date:
Wed Nov 28 12:30:09 2012 +0000
Revision:
1:fdd22bb7aa52
Child:
2:da51fb522205
DSP library code

Who changed what in which revision?

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