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_df2T_f32.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 1:fdd22bb7aa52 10 * Description: Processing function for the floating-point transposed
emilmont 1:fdd22bb7aa52 11 * direct form II Biquad cascade 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.7 2010/06/10
emilmont 1:fdd22bb7aa52 34 * Misra-C changes done
emilmont 1:fdd22bb7aa52 35 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 36
emilmont 1:fdd22bb7aa52 37 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 38
emilmont 1:fdd22bb7aa52 39 /**
emilmont 1:fdd22bb7aa52 40 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 41 */
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /**
emilmont 1:fdd22bb7aa52 44 * @defgroup BiquadCascadeDF2T Biquad Cascade IIR Filters Using a Direct Form II Transposed Structure
emilmont 1:fdd22bb7aa52 45 *
emilmont 1:fdd22bb7aa52 46 * This set of functions implements arbitrary order recursive (IIR) filters using a transposed direct form II structure.
emilmont 1:fdd22bb7aa52 47 * The filters are implemented as a cascade of second order Biquad sections.
emilmont 1:fdd22bb7aa52 48 * These functions provide a slight memory savings as compared to the direct form I Biquad filter functions.
emilmont 1:fdd22bb7aa52 49 * Only floating-point data is supported.
emilmont 1:fdd22bb7aa52 50 *
emilmont 1:fdd22bb7aa52 51 * This function operate on blocks of input and output data and each call to the function
emilmont 1:fdd22bb7aa52 52 * processes <code>blockSize</code> samples through the filter.
emilmont 1:fdd22bb7aa52 53 * <code>pSrc</code> points to the array of input data and
emilmont 1:fdd22bb7aa52 54 * <code>pDst</code> points to the array of output data.
emilmont 1:fdd22bb7aa52 55 * Both arrays contain <code>blockSize</code> values.
emilmont 1:fdd22bb7aa52 56 *
emilmont 1:fdd22bb7aa52 57 * \par Algorithm
emilmont 1:fdd22bb7aa52 58 * Each Biquad stage implements a second order filter using the difference equation:
emilmont 1:fdd22bb7aa52 59 * <pre>
emilmont 1:fdd22bb7aa52 60 * y[n] = b0 * x[n] + d1
emilmont 1:fdd22bb7aa52 61 * d1 = b1 * x[n] + a1 * y[n] + d2
emilmont 1:fdd22bb7aa52 62 * d2 = b2 * x[n] + a2 * y[n]
emilmont 1:fdd22bb7aa52 63 * </pre>
emilmont 1:fdd22bb7aa52 64 * where d1 and d2 represent the two state values.
emilmont 1:fdd22bb7aa52 65 *
emilmont 1:fdd22bb7aa52 66 * \par
emilmont 1:fdd22bb7aa52 67 * A Biquad filter using a transposed Direct Form II structure is shown below.
emilmont 1:fdd22bb7aa52 68 * \image html BiquadDF2Transposed.gif "Single transposed Direct Form II Biquad"
emilmont 1:fdd22bb7aa52 69 * 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 70 * 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 71 * Pay careful attention to the sign of the feedback coefficients.
emilmont 1:fdd22bb7aa52 72 * Some design tools flip the sign of the feedback coefficients:
emilmont 1:fdd22bb7aa52 73 * <pre>
emilmont 1:fdd22bb7aa52 74 * y[n] = b0 * x[n] + d1;
emilmont 1:fdd22bb7aa52 75 * d1 = b1 * x[n] - a1 * y[n] + d2;
emilmont 1:fdd22bb7aa52 76 * d2 = b2 * x[n] - a2 * y[n];
emilmont 1:fdd22bb7aa52 77 * </pre>
emilmont 1:fdd22bb7aa52 78 * 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 79 *
emilmont 1:fdd22bb7aa52 80 * \par
emilmont 1:fdd22bb7aa52 81 * Higher order filters are realized as a cascade of second order sections.
emilmont 1:fdd22bb7aa52 82 * <code>numStages</code> refers to the number of second order stages used.
emilmont 1:fdd22bb7aa52 83 * For example, an 8th order filter would be realized with <code>numStages=4</code> second order stages.
emilmont 1:fdd22bb7aa52 84 * A 9th order filter would be realized with <code>numStages=5</code> second order stages with the
emilmont 1:fdd22bb7aa52 85 * coefficients for one of the stages configured as a first order filter (<code>b2=0</code> and <code>a2=0</code>).
emilmont 1:fdd22bb7aa52 86 *
emilmont 1:fdd22bb7aa52 87 * \par
emilmont 1:fdd22bb7aa52 88 * <code>pState</code> points to the state variable array.
emilmont 1:fdd22bb7aa52 89 * Each Biquad stage has 2 state variables <code>d1</code> and <code>d2</code>.
emilmont 1:fdd22bb7aa52 90 * The state variables are arranged in the <code>pState</code> array as:
emilmont 1:fdd22bb7aa52 91 * <pre>
emilmont 1:fdd22bb7aa52 92 * {d11, d12, d21, d22, ...}
emilmont 1:fdd22bb7aa52 93 * </pre>
emilmont 1:fdd22bb7aa52 94 * where <code>d1x</code> refers to the state variables for the first Biquad and
emilmont 1:fdd22bb7aa52 95 * <code>d2x</code> refers to the state variables for the second Biquad.
emilmont 1:fdd22bb7aa52 96 * The state array has a total length of <code>2*numStages</code> values.
emilmont 1:fdd22bb7aa52 97 * The state variables are updated after each block of data is processed; the coefficients are untouched.
emilmont 1:fdd22bb7aa52 98 *
emilmont 1:fdd22bb7aa52 99 * \par
emilmont 1:fdd22bb7aa52 100 * The CMSIS library contains Biquad filters in both Direct Form I and transposed Direct Form II.
emilmont 1:fdd22bb7aa52 101 * The advantage of the Direct Form I structure is that it is numerically more robust for fixed-point data types.
emilmont 1:fdd22bb7aa52 102 * That is why the Direct Form I structure supports Q15 and Q31 data types.
emilmont 1:fdd22bb7aa52 103 * The transposed Direct Form II structure, on the other hand, requires a wide dynamic range for the state variables <code>d1</code> and <code>d2</code>.
emilmont 1:fdd22bb7aa52 104 * Because of this, the CMSIS library only has a floating-point version of the Direct Form II Biquad.
emilmont 1:fdd22bb7aa52 105 * The advantage of the Direct Form II Biquad is that it requires half the number of state variables, 2 rather than 4, per Biquad stage.
emilmont 1:fdd22bb7aa52 106 *
emilmont 1:fdd22bb7aa52 107 * \par Instance Structure
emilmont 1:fdd22bb7aa52 108 * The coefficients and state variables for a filter are stored together in an instance data structure.
emilmont 1:fdd22bb7aa52 109 * A separate instance structure must be defined for each filter.
emilmont 1:fdd22bb7aa52 110 * Coefficient arrays may be shared among several instances while state variable arrays cannot be shared.
emilmont 1:fdd22bb7aa52 111 *
emilmont 1:fdd22bb7aa52 112 * \par Init Functions
emilmont 1:fdd22bb7aa52 113 * There is also an associated initialization function.
emilmont 1:fdd22bb7aa52 114 * The initialization function performs following operations:
emilmont 1:fdd22bb7aa52 115 * - Sets the values of the internal structure fields.
emilmont 1:fdd22bb7aa52 116 * - Zeros out the values in the state buffer.
emilmont 1:fdd22bb7aa52 117 *
emilmont 1:fdd22bb7aa52 118 * \par
emilmont 1:fdd22bb7aa52 119 * Use of the initialization function is optional.
emilmont 1:fdd22bb7aa52 120 * However, if the initialization function is used, then the instance structure cannot be placed into a const data section.
emilmont 1:fdd22bb7aa52 121 * To place an instance structure into a const data section, the instance structure must be manually initialized.
emilmont 1:fdd22bb7aa52 122 * Set the values in the state buffer to zeros before static initialization.
emilmont 1:fdd22bb7aa52 123 * For example, to statically initialize the instance structure use
emilmont 1:fdd22bb7aa52 124 * <pre>
emilmont 1:fdd22bb7aa52 125 * arm_biquad_cascade_df2T_instance_f32 S1 = {numStages, pState, pCoeffs};
emilmont 1:fdd22bb7aa52 126 * </pre>
emilmont 1:fdd22bb7aa52 127 * 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 128 * <code>pCoeffs</code> is the address of the coefficient buffer;
emilmont 1:fdd22bb7aa52 129 *
emilmont 1:fdd22bb7aa52 130 */
emilmont 1:fdd22bb7aa52 131
emilmont 1:fdd22bb7aa52 132 /**
emilmont 1:fdd22bb7aa52 133 * @addtogroup BiquadCascadeDF2T
emilmont 1:fdd22bb7aa52 134 * @{
emilmont 1:fdd22bb7aa52 135 */
emilmont 1:fdd22bb7aa52 136
emilmont 1:fdd22bb7aa52 137 /**
emilmont 1:fdd22bb7aa52 138 * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter.
emilmont 1:fdd22bb7aa52 139 * @param[in] *S points to an instance of the filter data structure.
emilmont 1:fdd22bb7aa52 140 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 141 * @param[out] *pDst points to the block of output data
emilmont 1:fdd22bb7aa52 142 * @param[in] blockSize number of samples to process.
emilmont 1:fdd22bb7aa52 143 * @return none.
emilmont 1:fdd22bb7aa52 144 */
emilmont 1:fdd22bb7aa52 145
emilmont 1:fdd22bb7aa52 146 void arm_biquad_cascade_df2T_f32(
emilmont 1:fdd22bb7aa52 147 const arm_biquad_cascade_df2T_instance_f32 * S,
emilmont 1:fdd22bb7aa52 148 float32_t * pSrc,
emilmont 1:fdd22bb7aa52 149 float32_t * pDst,
emilmont 1:fdd22bb7aa52 150 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 151 {
emilmont 1:fdd22bb7aa52 152
emilmont 1:fdd22bb7aa52 153 float32_t *pIn = pSrc; /* source pointer */
emilmont 1:fdd22bb7aa52 154 float32_t *pOut = pDst; /* destination pointer */
emilmont 1:fdd22bb7aa52 155 float32_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 156 float32_t *pCoeffs = S->pCoeffs; /* coefficient pointer */
emilmont 1:fdd22bb7aa52 157 float32_t acc0; /* accumulator */
emilmont 1:fdd22bb7aa52 158 float32_t b0, b1, b2, a1, a2; /* Filter coefficients */
emilmont 1:fdd22bb7aa52 159 float32_t Xn; /* temporary input */
emilmont 1:fdd22bb7aa52 160 float32_t d1, d2; /* state variables */
emilmont 1:fdd22bb7aa52 161 uint32_t sample, stage = S->numStages; /* loop counters */
emilmont 1:fdd22bb7aa52 162
emilmont 1:fdd22bb7aa52 163 #ifndef ARM_MATH_CM0
emilmont 1:fdd22bb7aa52 164
emilmont 1:fdd22bb7aa52 165 float32_t Xn1, Xn2; /* Input State variables */
emilmont 1:fdd22bb7aa52 166 float32_t acc1; /* accumulator */
emilmont 1:fdd22bb7aa52 167
emilmont 1:fdd22bb7aa52 168
emilmont 1:fdd22bb7aa52 169
emilmont 1:fdd22bb7aa52 170 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 171 do
emilmont 1:fdd22bb7aa52 172 {
emilmont 1:fdd22bb7aa52 173 /* Reading the coefficients */
emilmont 1:fdd22bb7aa52 174 b0 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 175 b1 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 176 b2 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 177 a1 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 178 a2 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 179
emilmont 1:fdd22bb7aa52 180 /*Reading the state values */
emilmont 1:fdd22bb7aa52 181 d1 = pState[0];
emilmont 1:fdd22bb7aa52 182 d2 = pState[1];
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 /* Apply loop unrolling and compute 4 output values simultaneously. */
emilmont 1:fdd22bb7aa52 185 sample = blockSize >> 2u;
emilmont 1:fdd22bb7aa52 186
emilmont 1:fdd22bb7aa52 187 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
emilmont 1:fdd22bb7aa52 188 ** a second loop below computes the remaining 1 to 3 samples. */
emilmont 1:fdd22bb7aa52 189 while(sample > 0u)
emilmont 1:fdd22bb7aa52 190 {
emilmont 1:fdd22bb7aa52 191
emilmont 1:fdd22bb7aa52 192 /* y[n] = b0 * x[n] + d1 */
emilmont 1:fdd22bb7aa52 193 /* d1 = b1 * x[n] + a1 * y[n] + d2 */
emilmont 1:fdd22bb7aa52 194 /* d2 = b2 * x[n] + a2 * y[n] */
emilmont 1:fdd22bb7aa52 195
emilmont 1:fdd22bb7aa52 196 /* Read the first input */
emilmont 1:fdd22bb7aa52 197 Xn1 = *pIn++;
emilmont 1:fdd22bb7aa52 198
emilmont 1:fdd22bb7aa52 199 /* y[n] = b0 * x[n] + d1 */
emilmont 1:fdd22bb7aa52 200 acc0 = (b0 * Xn1) + d1;
emilmont 1:fdd22bb7aa52 201
emilmont 1:fdd22bb7aa52 202 /* d1 = b1 * x[n] + d2 */
emilmont 1:fdd22bb7aa52 203 d1 = (b1 * Xn1) + d2;
emilmont 1:fdd22bb7aa52 204
emilmont 1:fdd22bb7aa52 205 /* d2 = b2 * x[n] */
emilmont 1:fdd22bb7aa52 206 d2 = (b2 * Xn1);
emilmont 1:fdd22bb7aa52 207
emilmont 1:fdd22bb7aa52 208 /* Read the second input */
emilmont 1:fdd22bb7aa52 209 Xn2 = *pIn++;
emilmont 1:fdd22bb7aa52 210
emilmont 1:fdd22bb7aa52 211 /* d1 = b1 * x[n] + a1 * y[n] */
emilmont 1:fdd22bb7aa52 212 d1 = (a1 * acc0) + d1;
emilmont 1:fdd22bb7aa52 213
emilmont 1:fdd22bb7aa52 214 /* Store the result in the accumulator in the destination buffer. */
emilmont 1:fdd22bb7aa52 215 *pOut++ = acc0;
emilmont 1:fdd22bb7aa52 216
emilmont 1:fdd22bb7aa52 217 d2 = (a2 * acc0) + d2;
emilmont 1:fdd22bb7aa52 218
emilmont 1:fdd22bb7aa52 219 /* y[n] = b0 * x[n] + d1 */
emilmont 1:fdd22bb7aa52 220 acc1 = (b0 * Xn2) + d1;
emilmont 1:fdd22bb7aa52 221
emilmont 1:fdd22bb7aa52 222 /* Read the third input */
emilmont 1:fdd22bb7aa52 223 Xn1 = *pIn++;
emilmont 1:fdd22bb7aa52 224
emilmont 1:fdd22bb7aa52 225 d1 = (b1 * Xn2) + d2;
emilmont 1:fdd22bb7aa52 226
emilmont 1:fdd22bb7aa52 227 d2 = (b2 * Xn2);
emilmont 1:fdd22bb7aa52 228
emilmont 1:fdd22bb7aa52 229 /* Store the result in the accumulator in the destination buffer. */
emilmont 1:fdd22bb7aa52 230 *pOut++ = acc1;
emilmont 1:fdd22bb7aa52 231
emilmont 1:fdd22bb7aa52 232 d1 = (a1 * acc1) + d1;
emilmont 1:fdd22bb7aa52 233
emilmont 1:fdd22bb7aa52 234 d2 = (a2 * acc1) + d2;
emilmont 1:fdd22bb7aa52 235
emilmont 1:fdd22bb7aa52 236 /* y[n] = b0 * x[n] + d1 */
emilmont 1:fdd22bb7aa52 237 acc0 = (b0 * Xn1) + d1;
emilmont 1:fdd22bb7aa52 238
emilmont 1:fdd22bb7aa52 239 d1 = (b1 * Xn1) + d2;
emilmont 1:fdd22bb7aa52 240
emilmont 1:fdd22bb7aa52 241 d2 = (b2 * Xn1);
emilmont 1:fdd22bb7aa52 242
emilmont 1:fdd22bb7aa52 243 /* Read the fourth input */
emilmont 1:fdd22bb7aa52 244 Xn2 = *pIn++;
emilmont 1:fdd22bb7aa52 245
emilmont 1:fdd22bb7aa52 246 d1 = (a1 * acc0) + d1;
emilmont 1:fdd22bb7aa52 247
emilmont 1:fdd22bb7aa52 248 /* Store the result in the accumulator in the destination buffer. */
emilmont 1:fdd22bb7aa52 249 *pOut++ = acc0;
emilmont 1:fdd22bb7aa52 250
emilmont 1:fdd22bb7aa52 251 d2 = (a2 * acc0) + d2;
emilmont 1:fdd22bb7aa52 252
emilmont 1:fdd22bb7aa52 253 /* y[n] = b0 * x[n] + d1 */
emilmont 1:fdd22bb7aa52 254 acc1 = (b0 * Xn2) + d1;
emilmont 1:fdd22bb7aa52 255
emilmont 1:fdd22bb7aa52 256 d1 = (b1 * Xn2) + d2;
emilmont 1:fdd22bb7aa52 257
emilmont 1:fdd22bb7aa52 258 d2 = (b2 * Xn2);
emilmont 1:fdd22bb7aa52 259
emilmont 1:fdd22bb7aa52 260 /* Store the result in the accumulator in the destination buffer. */
emilmont 1:fdd22bb7aa52 261 *pOut++ = acc1;
emilmont 1:fdd22bb7aa52 262
emilmont 1:fdd22bb7aa52 263 d1 = (a1 * acc1) + d1;
emilmont 1:fdd22bb7aa52 264
emilmont 1:fdd22bb7aa52 265 d2 = (a2 * acc1) + d2;
emilmont 1:fdd22bb7aa52 266
emilmont 1:fdd22bb7aa52 267 /* decrement the loop counter */
emilmont 1:fdd22bb7aa52 268 sample--;
emilmont 1:fdd22bb7aa52 269
emilmont 1:fdd22bb7aa52 270 }
emilmont 1:fdd22bb7aa52 271
emilmont 1:fdd22bb7aa52 272 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
emilmont 1:fdd22bb7aa52 273 ** No loop unrolling is used. */
emilmont 1:fdd22bb7aa52 274 sample = blockSize & 0x3u;
emilmont 1:fdd22bb7aa52 275
emilmont 1:fdd22bb7aa52 276 while(sample > 0u)
emilmont 1:fdd22bb7aa52 277 {
emilmont 1:fdd22bb7aa52 278 /* Read the input */
emilmont 1:fdd22bb7aa52 279 Xn = *pIn++;
emilmont 1:fdd22bb7aa52 280
emilmont 1:fdd22bb7aa52 281 /* y[n] = b0 * x[n] + d1 */
emilmont 1:fdd22bb7aa52 282 acc0 = (b0 * Xn) + d1;
emilmont 1:fdd22bb7aa52 283
emilmont 1:fdd22bb7aa52 284 /* Store the result in the accumulator in the destination buffer. */
emilmont 1:fdd22bb7aa52 285 *pOut++ = acc0;
emilmont 1:fdd22bb7aa52 286
emilmont 1:fdd22bb7aa52 287 /* Every time after the output is computed state should be updated. */
emilmont 1:fdd22bb7aa52 288 /* d1 = b1 * x[n] + a1 * y[n] + d2 */
emilmont 1:fdd22bb7aa52 289 d1 = ((b1 * Xn) + (a1 * acc0)) + d2;
emilmont 1:fdd22bb7aa52 290
emilmont 1:fdd22bb7aa52 291 /* d2 = b2 * x[n] + a2 * y[n] */
emilmont 1:fdd22bb7aa52 292 d2 = (b2 * Xn) + (a2 * acc0);
emilmont 1:fdd22bb7aa52 293
emilmont 1:fdd22bb7aa52 294 /* decrement the loop counter */
emilmont 1:fdd22bb7aa52 295 sample--;
emilmont 1:fdd22bb7aa52 296 }
emilmont 1:fdd22bb7aa52 297
emilmont 1:fdd22bb7aa52 298 /* Store the updated state variables back into the state array */
emilmont 1:fdd22bb7aa52 299 *pState++ = d1;
emilmont 1:fdd22bb7aa52 300 *pState++ = d2;
emilmont 1:fdd22bb7aa52 301
emilmont 1:fdd22bb7aa52 302 /* The current stage input is given as the output to the next stage */
emilmont 1:fdd22bb7aa52 303 pIn = pDst;
emilmont 1:fdd22bb7aa52 304
emilmont 1:fdd22bb7aa52 305 /*Reset the output working pointer */
emilmont 1:fdd22bb7aa52 306 pOut = pDst;
emilmont 1:fdd22bb7aa52 307
emilmont 1:fdd22bb7aa52 308 /* decrement the loop counter */
emilmont 1:fdd22bb7aa52 309 stage--;
emilmont 1:fdd22bb7aa52 310
emilmont 1:fdd22bb7aa52 311 } while(stage > 0u);
emilmont 1:fdd22bb7aa52 312
emilmont 1:fdd22bb7aa52 313 #else
emilmont 1:fdd22bb7aa52 314
emilmont 1:fdd22bb7aa52 315 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 316
emilmont 1:fdd22bb7aa52 317 do
emilmont 1:fdd22bb7aa52 318 {
emilmont 1:fdd22bb7aa52 319 /* Reading the coefficients */
emilmont 1:fdd22bb7aa52 320 b0 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 321 b1 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 322 b2 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 323 a1 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 324 a2 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 /*Reading the state values */
emilmont 1:fdd22bb7aa52 327 d1 = pState[0];
emilmont 1:fdd22bb7aa52 328 d2 = pState[1];
emilmont 1:fdd22bb7aa52 329
emilmont 1:fdd22bb7aa52 330
emilmont 1:fdd22bb7aa52 331 sample = blockSize;
emilmont 1:fdd22bb7aa52 332
emilmont 1:fdd22bb7aa52 333 while(sample > 0u)
emilmont 1:fdd22bb7aa52 334 {
emilmont 1:fdd22bb7aa52 335 /* Read the input */
emilmont 1:fdd22bb7aa52 336 Xn = *pIn++;
emilmont 1:fdd22bb7aa52 337
emilmont 1:fdd22bb7aa52 338 /* y[n] = b0 * x[n] + d1 */
emilmont 1:fdd22bb7aa52 339 acc0 = (b0 * Xn) + d1;
emilmont 1:fdd22bb7aa52 340
emilmont 1:fdd22bb7aa52 341 /* Store the result in the accumulator in the destination buffer. */
emilmont 1:fdd22bb7aa52 342 *pOut++ = acc0;
emilmont 1:fdd22bb7aa52 343
emilmont 1:fdd22bb7aa52 344 /* Every time after the output is computed state should be updated. */
emilmont 1:fdd22bb7aa52 345 /* d1 = b1 * x[n] + a1 * y[n] + d2 */
emilmont 1:fdd22bb7aa52 346 d1 = ((b1 * Xn) + (a1 * acc0)) + d2;
emilmont 1:fdd22bb7aa52 347
emilmont 1:fdd22bb7aa52 348 /* d2 = b2 * x[n] + a2 * y[n] */
emilmont 1:fdd22bb7aa52 349 d2 = (b2 * Xn) + (a2 * acc0);
emilmont 1:fdd22bb7aa52 350
emilmont 1:fdd22bb7aa52 351 /* decrement the loop counter */
emilmont 1:fdd22bb7aa52 352 sample--;
emilmont 1:fdd22bb7aa52 353 }
emilmont 1:fdd22bb7aa52 354
emilmont 1:fdd22bb7aa52 355 /* Store the updated state variables back into the state array */
emilmont 1:fdd22bb7aa52 356 *pState++ = d1;
emilmont 1:fdd22bb7aa52 357 *pState++ = d2;
emilmont 1:fdd22bb7aa52 358
emilmont 1:fdd22bb7aa52 359 /* The current stage input is given as the output to the next stage */
emilmont 1:fdd22bb7aa52 360 pIn = pDst;
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362 /*Reset the output working pointer */
emilmont 1:fdd22bb7aa52 363 pOut = pDst;
emilmont 1:fdd22bb7aa52 364
emilmont 1:fdd22bb7aa52 365 /* decrement the loop counter */
emilmont 1:fdd22bb7aa52 366 stage--;
emilmont 1:fdd22bb7aa52 367
emilmont 1:fdd22bb7aa52 368 } while(stage > 0u);
emilmont 1:fdd22bb7aa52 369
emilmont 1:fdd22bb7aa52 370 #endif /* #ifndef ARM_MATH_CM0 */
emilmont 1:fdd22bb7aa52 371
emilmont 1:fdd22bb7aa52 372 }
emilmont 1:fdd22bb7aa52 373
emilmont 1:fdd22bb7aa52 374
emilmont 1:fdd22bb7aa52 375 /**
emilmont 1:fdd22bb7aa52 376 * @} end of BiquadCascadeDF2T group
emilmont 1:fdd22bb7aa52 377 */