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:
mbed_official
Date:
Fri Nov 08 13:45:10 2013 +0000
Revision:
3:7a284390b0ce
Parent:
2:da51fb522205
Child:
5:3762170b6d4d
Synchronized with git revision e69956aba2f68a2a26ac26b051f8d349deaa1ce8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
mbed_official 3:7a284390b0ce 2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
mbed_official 3:7a284390b0ce 4 * $Date: 17. January 2013
emilmont 1:fdd22bb7aa52 5 *
emilmont 2:da51fb522205 6 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 7 * Title: arm_biquad_cascade_df2T_f32.c
emilmont 1:fdd22bb7aa52 8 *
emilmont 1:fdd22bb7aa52 9 * Description: Processing function for the floating-point transposed
emilmont 1:fdd22bb7aa52 10 * direct form II Biquad cascade filter.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
mbed_official 3:7a284390b0ce 14 * Redistribution and use in source and binary forms, with or without
mbed_official 3:7a284390b0ce 15 * modification, are permitted provided that the following conditions
mbed_official 3:7a284390b0ce 16 * are met:
mbed_official 3:7a284390b0ce 17 * - Redistributions of source code must retain the above copyright
mbed_official 3:7a284390b0ce 18 * notice, this list of conditions and the following disclaimer.
mbed_official 3:7a284390b0ce 19 * - Redistributions in binary form must reproduce the above copyright
mbed_official 3:7a284390b0ce 20 * notice, this list of conditions and the following disclaimer in
mbed_official 3:7a284390b0ce 21 * the documentation and/or other materials provided with the
mbed_official 3:7a284390b0ce 22 * distribution.
mbed_official 3:7a284390b0ce 23 * - Neither the name of ARM LIMITED nor the names of its contributors
mbed_official 3:7a284390b0ce 24 * may be used to endorse or promote products derived from this
mbed_official 3:7a284390b0ce 25 * software without specific prior written permission.
mbed_official 3:7a284390b0ce 26 *
mbed_official 3:7a284390b0ce 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
mbed_official 3:7a284390b0ce 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
mbed_official 3:7a284390b0ce 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
mbed_official 3:7a284390b0ce 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
mbed_official 3:7a284390b0ce 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
mbed_official 3:7a284390b0ce 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
mbed_official 3:7a284390b0ce 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 3:7a284390b0ce 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 3:7a284390b0ce 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
mbed_official 3:7a284390b0ce 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 3:7a284390b0ce 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 3:7a284390b0ce 38 * POSSIBILITY OF SUCH DAMAGE.
emilmont 1:fdd22bb7aa52 39 * -------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 40
emilmont 1:fdd22bb7aa52 41 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /**
mbed_official 3:7a284390b0ce 44 * @ingroup groupFilters
mbed_official 3:7a284390b0ce 45 */
emilmont 1:fdd22bb7aa52 46
emilmont 1:fdd22bb7aa52 47 /**
mbed_official 3:7a284390b0ce 48 * @defgroup BiquadCascadeDF2T Biquad Cascade IIR Filters Using a Direct Form II Transposed Structure
mbed_official 3:7a284390b0ce 49 *
mbed_official 3:7a284390b0ce 50 * This set of functions implements arbitrary order recursive (IIR) filters using a transposed direct form II structure.
mbed_official 3:7a284390b0ce 51 * The filters are implemented as a cascade of second order Biquad sections.
mbed_official 3:7a284390b0ce 52 * These functions provide a slight memory savings as compared to the direct form I Biquad filter functions.
mbed_official 3:7a284390b0ce 53 * Only floating-point data is supported.
mbed_official 3:7a284390b0ce 54 *
mbed_official 3:7a284390b0ce 55 * This function operate on blocks of input and output data and each call to the function
mbed_official 3:7a284390b0ce 56 * processes <code>blockSize</code> samples through the filter.
mbed_official 3:7a284390b0ce 57 * <code>pSrc</code> points to the array of input data and
mbed_official 3:7a284390b0ce 58 * <code>pDst</code> points to the array of output data.
mbed_official 3:7a284390b0ce 59 * Both arrays contain <code>blockSize</code> values.
mbed_official 3:7a284390b0ce 60 *
mbed_official 3:7a284390b0ce 61 * \par Algorithm
mbed_official 3:7a284390b0ce 62 * Each Biquad stage implements a second order filter using the difference equation:
mbed_official 3:7a284390b0ce 63 * <pre>
mbed_official 3:7a284390b0ce 64 * y[n] = b0 * x[n] + d1
mbed_official 3:7a284390b0ce 65 * d1 = b1 * x[n] + a1 * y[n] + d2
mbed_official 3:7a284390b0ce 66 * d2 = b2 * x[n] + a2 * y[n]
mbed_official 3:7a284390b0ce 67 * </pre>
mbed_official 3:7a284390b0ce 68 * where d1 and d2 represent the two state values.
mbed_official 3:7a284390b0ce 69 *
mbed_official 3:7a284390b0ce 70 * \par
mbed_official 3:7a284390b0ce 71 * A Biquad filter using a transposed Direct Form II structure is shown below.
mbed_official 3:7a284390b0ce 72 * \image html BiquadDF2Transposed.gif "Single transposed Direct Form II Biquad"
mbed_official 3:7a284390b0ce 73 * Coefficients <code>b0, b1, and b2 </code> multiply the input signal <code>x[n]</code> and are referred to as the feedforward coefficients.
mbed_official 3:7a284390b0ce 74 * Coefficients <code>a1</code> and <code>a2</code> multiply the output signal <code>y[n]</code> and are referred to as the feedback coefficients.
mbed_official 3:7a284390b0ce 75 * Pay careful attention to the sign of the feedback coefficients.
mbed_official 3:7a284390b0ce 76 * Some design tools flip the sign of the feedback coefficients:
mbed_official 3:7a284390b0ce 77 * <pre>
mbed_official 3:7a284390b0ce 78 * y[n] = b0 * x[n] + d1;
mbed_official 3:7a284390b0ce 79 * d1 = b1 * x[n] - a1 * y[n] + d2;
mbed_official 3:7a284390b0ce 80 * d2 = b2 * x[n] - a2 * y[n];
mbed_official 3:7a284390b0ce 81 * </pre>
mbed_official 3:7a284390b0ce 82 * In this case the feedback coefficients <code>a1</code> and <code>a2</code> must be negated when used with the CMSIS DSP Library.
mbed_official 3:7a284390b0ce 83 *
mbed_official 3:7a284390b0ce 84 * \par
mbed_official 3:7a284390b0ce 85 * Higher order filters are realized as a cascade of second order sections.
mbed_official 3:7a284390b0ce 86 * <code>numStages</code> refers to the number of second order stages used.
mbed_official 3:7a284390b0ce 87 * For example, an 8th order filter would be realized with <code>numStages=4</code> second order stages.
mbed_official 3:7a284390b0ce 88 * A 9th order filter would be realized with <code>numStages=5</code> second order stages with the
mbed_official 3:7a284390b0ce 89 * coefficients for one of the stages configured as a first order filter (<code>b2=0</code> and <code>a2=0</code>).
mbed_official 3:7a284390b0ce 90 *
mbed_official 3:7a284390b0ce 91 * \par
mbed_official 3:7a284390b0ce 92 * <code>pState</code> points to the state variable array.
mbed_official 3:7a284390b0ce 93 * Each Biquad stage has 2 state variables <code>d1</code> and <code>d2</code>.
mbed_official 3:7a284390b0ce 94 * The state variables are arranged in the <code>pState</code> array as:
mbed_official 3:7a284390b0ce 95 * <pre>
mbed_official 3:7a284390b0ce 96 * {d11, d12, d21, d22, ...}
mbed_official 3:7a284390b0ce 97 * </pre>
mbed_official 3:7a284390b0ce 98 * where <code>d1x</code> refers to the state variables for the first Biquad and
mbed_official 3:7a284390b0ce 99 * <code>d2x</code> refers to the state variables for the second Biquad.
mbed_official 3:7a284390b0ce 100 * The state array has a total length of <code>2*numStages</code> values.
mbed_official 3:7a284390b0ce 101 * The state variables are updated after each block of data is processed; the coefficients are untouched.
mbed_official 3:7a284390b0ce 102 *
mbed_official 3:7a284390b0ce 103 * \par
mbed_official 3:7a284390b0ce 104 * The CMSIS library contains Biquad filters in both Direct Form I and transposed Direct Form II.
mbed_official 3:7a284390b0ce 105 * The advantage of the Direct Form I structure is that it is numerically more robust for fixed-point data types.
mbed_official 3:7a284390b0ce 106 * That is why the Direct Form I structure supports Q15 and Q31 data types.
mbed_official 3:7a284390b0ce 107 * 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>.
mbed_official 3:7a284390b0ce 108 * Because of this, the CMSIS library only has a floating-point version of the Direct Form II Biquad.
mbed_official 3:7a284390b0ce 109 * 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.
mbed_official 3:7a284390b0ce 110 *
mbed_official 3:7a284390b0ce 111 * \par Instance Structure
mbed_official 3:7a284390b0ce 112 * The coefficients and state variables for a filter are stored together in an instance data structure.
mbed_official 3:7a284390b0ce 113 * A separate instance structure must be defined for each filter.
mbed_official 3:7a284390b0ce 114 * Coefficient arrays may be shared among several instances while state variable arrays cannot be shared.
mbed_official 3:7a284390b0ce 115 *
mbed_official 3:7a284390b0ce 116 * \par Init Functions
mbed_official 3:7a284390b0ce 117 * There is also an associated initialization function.
mbed_official 3:7a284390b0ce 118 * The initialization function performs following operations:
mbed_official 3:7a284390b0ce 119 * - Sets the values of the internal structure fields.
mbed_official 3:7a284390b0ce 120 * - Zeros out the values in the state buffer.
mbed_official 3:7a284390b0ce 121 * To do this manually without calling the init function, assign the follow subfields of the instance structure:
mbed_official 3:7a284390b0ce 122 * numStages, pCoeffs, pState. Also set all of the values in pState to zero.
mbed_official 3:7a284390b0ce 123 *
mbed_official 3:7a284390b0ce 124 * \par
mbed_official 3:7a284390b0ce 125 * Use of the initialization function is optional.
mbed_official 3:7a284390b0ce 126 * However, if the initialization function is used, then the instance structure cannot be placed into a const data section.
mbed_official 3:7a284390b0ce 127 * To place an instance structure into a const data section, the instance structure must be manually initialized.
mbed_official 3:7a284390b0ce 128 * Set the values in the state buffer to zeros before static initialization.
mbed_official 3:7a284390b0ce 129 * For example, to statically initialize the instance structure use
mbed_official 3:7a284390b0ce 130 * <pre>
mbed_official 3:7a284390b0ce 131 * arm_biquad_cascade_df2T_instance_f32 S1 = {numStages, pState, pCoeffs};
mbed_official 3:7a284390b0ce 132 * </pre>
mbed_official 3:7a284390b0ce 133 * where <code>numStages</code> is the number of Biquad stages in the filter; <code>pState</code> is the address of the state buffer.
mbed_official 3:7a284390b0ce 134 * <code>pCoeffs</code> is the address of the coefficient buffer;
mbed_official 3:7a284390b0ce 135 *
mbed_official 3:7a284390b0ce 136 */
emilmont 1:fdd22bb7aa52 137
emilmont 1:fdd22bb7aa52 138 /**
mbed_official 3:7a284390b0ce 139 * @addtogroup BiquadCascadeDF2T
mbed_official 3:7a284390b0ce 140 * @{
mbed_official 3:7a284390b0ce 141 */
emilmont 1:fdd22bb7aa52 142
emilmont 1:fdd22bb7aa52 143 /**
mbed_official 3:7a284390b0ce 144 * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter.
mbed_official 3:7a284390b0ce 145 * @param[in] *S points to an instance of the filter data structure.
mbed_official 3:7a284390b0ce 146 * @param[in] *pSrc points to the block of input data.
mbed_official 3:7a284390b0ce 147 * @param[out] *pDst points to the block of output data
mbed_official 3:7a284390b0ce 148 * @param[in] blockSize number of samples to process.
mbed_official 3:7a284390b0ce 149 * @return none.
mbed_official 3:7a284390b0ce 150 */
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152
mbed_official 3:7a284390b0ce 153 LOW_OPTIMIZATION_ENTER
mbed_official 3:7a284390b0ce 154 void arm_biquad_cascade_df2T_f32(
mbed_official 3:7a284390b0ce 155 const arm_biquad_cascade_df2T_instance_f32 * S,
mbed_official 3:7a284390b0ce 156 float32_t * pSrc,
mbed_official 3:7a284390b0ce 157 float32_t * pDst,
mbed_official 3:7a284390b0ce 158 uint32_t blockSize)
mbed_official 3:7a284390b0ce 159 {
emilmont 1:fdd22bb7aa52 160
mbed_official 3:7a284390b0ce 161 float32_t *pIn = pSrc; /* source pointer */
mbed_official 3:7a284390b0ce 162 float32_t *pOut = pDst; /* destination pointer */
mbed_official 3:7a284390b0ce 163 float32_t *pState = S->pState; /* State pointer */
mbed_official 3:7a284390b0ce 164 float32_t *pCoeffs = S->pCoeffs; /* coefficient pointer */
mbed_official 3:7a284390b0ce 165 float32_t acc1; /* accumulator */
mbed_official 3:7a284390b0ce 166 float32_t b0, b1, b2, a1, a2; /* Filter coefficients */
mbed_official 3:7a284390b0ce 167 float32_t Xn1; /* temporary input */
mbed_official 3:7a284390b0ce 168 float32_t d1, d2; /* state variables */
mbed_official 3:7a284390b0ce 169 uint32_t sample, stage = S->numStages; /* loop counters */
emilmont 1:fdd22bb7aa52 170
mbed_official 3:7a284390b0ce 171 #ifndef ARM_MATH_CM0_FAMILY_FAMILY
emilmont 1:fdd22bb7aa52 172
mbed_official 3:7a284390b0ce 173 float32_t Xn2, Xn3, Xn4; /* Input State variables */
mbed_official 3:7a284390b0ce 174 float32_t acc2, acc3, acc4; /* accumulator */
mbed_official 3:7a284390b0ce 175
mbed_official 3:7a284390b0ce 176
mbed_official 3:7a284390b0ce 177 float32_t p0, p1, p2, p3, p4, A1;
emilmont 1:fdd22bb7aa52 178
mbed_official 3:7a284390b0ce 179 /* Run the below code for Cortex-M4 and Cortex-M3 */
mbed_official 3:7a284390b0ce 180 do
mbed_official 3:7a284390b0ce 181 {
mbed_official 3:7a284390b0ce 182 /* Reading the coefficients */
mbed_official 3:7a284390b0ce 183 b0 = *pCoeffs++;
mbed_official 3:7a284390b0ce 184 b1 = *pCoeffs++;
mbed_official 3:7a284390b0ce 185 b2 = *pCoeffs++;
mbed_official 3:7a284390b0ce 186 a1 = *pCoeffs++;
mbed_official 3:7a284390b0ce 187 a2 = *pCoeffs++;
mbed_official 3:7a284390b0ce 188
emilmont 1:fdd22bb7aa52 189
mbed_official 3:7a284390b0ce 190 /*Reading the state values */
mbed_official 3:7a284390b0ce 191 d1 = pState[0];
mbed_official 3:7a284390b0ce 192 d2 = pState[1];
emilmont 1:fdd22bb7aa52 193
mbed_official 3:7a284390b0ce 194 /* Apply loop unrolling and compute 4 output values simultaneously. */
mbed_official 3:7a284390b0ce 195 sample = blockSize >> 2u;
emilmont 1:fdd22bb7aa52 196
mbed_official 3:7a284390b0ce 197 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
mbed_official 3:7a284390b0ce 198 ** a second loop below computes the remaining 1 to 3 samples. */
mbed_official 3:7a284390b0ce 199 while(sample > 0u) {
emilmont 1:fdd22bb7aa52 200
mbed_official 3:7a284390b0ce 201 /* y[n] = b0 * x[n] + d1 */
mbed_official 3:7a284390b0ce 202 /* d1 = b1 * x[n] + a1 * y[n] + d2 */
mbed_official 3:7a284390b0ce 203 /* d2 = b2 * x[n] + a2 * y[n] */
emilmont 1:fdd22bb7aa52 204
mbed_official 3:7a284390b0ce 205 /* Read the four inputs */
mbed_official 3:7a284390b0ce 206 Xn1 = pIn[0];
mbed_official 3:7a284390b0ce 207 Xn2 = pIn[1];
mbed_official 3:7a284390b0ce 208 Xn3 = pIn[2];
mbed_official 3:7a284390b0ce 209 Xn4 = pIn[3];
mbed_official 3:7a284390b0ce 210 pIn += 4;
emilmont 1:fdd22bb7aa52 211
mbed_official 3:7a284390b0ce 212 p0 = b0 * Xn1;
mbed_official 3:7a284390b0ce 213 p1 = b1 * Xn1;
mbed_official 3:7a284390b0ce 214 acc1 = p0 + d1;
mbed_official 3:7a284390b0ce 215 p0 = b0 * Xn2;
mbed_official 3:7a284390b0ce 216 p3 = a1 * acc1;
mbed_official 3:7a284390b0ce 217 p2 = b2 * Xn1;
mbed_official 3:7a284390b0ce 218 A1 = p1 + p3;
mbed_official 3:7a284390b0ce 219 p4 = a2 * acc1;
mbed_official 3:7a284390b0ce 220 d1 = A1 + d2;
mbed_official 3:7a284390b0ce 221 d2 = p2 + p4;
emilmont 1:fdd22bb7aa52 222
mbed_official 3:7a284390b0ce 223 p1 = b1 * Xn2;
mbed_official 3:7a284390b0ce 224 acc2 = p0 + d1;
mbed_official 3:7a284390b0ce 225 p0 = b0 * Xn3;
mbed_official 3:7a284390b0ce 226 p3 = a1 * acc2;
mbed_official 3:7a284390b0ce 227 p2 = b2 * Xn2;
mbed_official 3:7a284390b0ce 228 A1 = p1 + p3;
mbed_official 3:7a284390b0ce 229 p4 = a2 * acc2;
mbed_official 3:7a284390b0ce 230 d1 = A1 + d2;
mbed_official 3:7a284390b0ce 231 d2 = p2 + p4;
emilmont 1:fdd22bb7aa52 232
mbed_official 3:7a284390b0ce 233 p1 = b1 * Xn3;
mbed_official 3:7a284390b0ce 234 acc3 = p0 + d1;
mbed_official 3:7a284390b0ce 235 p0 = b0 * Xn4;
mbed_official 3:7a284390b0ce 236 p3 = a1 * acc3;
mbed_official 3:7a284390b0ce 237 p2 = b2 * Xn3;
mbed_official 3:7a284390b0ce 238 A1 = p1 + p3;
mbed_official 3:7a284390b0ce 239 p4 = a2 * acc3;
mbed_official 3:7a284390b0ce 240 d1 = A1 + d2;
mbed_official 3:7a284390b0ce 241 d2 = p2 + p4;
emilmont 1:fdd22bb7aa52 242
mbed_official 3:7a284390b0ce 243 acc4 = p0 + d1;
mbed_official 3:7a284390b0ce 244 p1 = b1 * Xn4;
mbed_official 3:7a284390b0ce 245 p3 = a1 * acc4;
mbed_official 3:7a284390b0ce 246 p2 = b2 * Xn4;
mbed_official 3:7a284390b0ce 247 A1 = p1 + p3;
mbed_official 3:7a284390b0ce 248 p4 = a2 * acc4;
mbed_official 3:7a284390b0ce 249 d1 = A1 + d2;
mbed_official 3:7a284390b0ce 250 d2 = p2 + p4;
emilmont 1:fdd22bb7aa52 251
mbed_official 3:7a284390b0ce 252 pOut[0] = acc1;
mbed_official 3:7a284390b0ce 253 pOut[1] = acc2;
mbed_official 3:7a284390b0ce 254 pOut[2] = acc3;
mbed_official 3:7a284390b0ce 255 pOut[3] = acc4;
mbed_official 3:7a284390b0ce 256 pOut += 4;
mbed_official 3:7a284390b0ce 257
mbed_official 3:7a284390b0ce 258 sample--;
mbed_official 3:7a284390b0ce 259 }
emilmont 1:fdd22bb7aa52 260
mbed_official 3:7a284390b0ce 261 sample = blockSize & 0x3u;
mbed_official 3:7a284390b0ce 262 while(sample > 0u) {
mbed_official 3:7a284390b0ce 263 Xn1 = *pIn++;
emilmont 1:fdd22bb7aa52 264
mbed_official 3:7a284390b0ce 265 p0 = b0 * Xn1;
mbed_official 3:7a284390b0ce 266 p1 = b1 * Xn1;
mbed_official 3:7a284390b0ce 267 acc1 = p0 + d1;
mbed_official 3:7a284390b0ce 268 p3 = a1 * acc1;
mbed_official 3:7a284390b0ce 269 p2 = b2 * Xn1;
mbed_official 3:7a284390b0ce 270 A1 = p1 + p3;
mbed_official 3:7a284390b0ce 271 p4 = a2 * acc1;
mbed_official 3:7a284390b0ce 272 d1 = A1 + d2;
mbed_official 3:7a284390b0ce 273 d2 = p2 + p4;
mbed_official 3:7a284390b0ce 274
mbed_official 3:7a284390b0ce 275 *pOut++ = acc1;
mbed_official 3:7a284390b0ce 276
mbed_official 3:7a284390b0ce 277 sample--;
mbed_official 3:7a284390b0ce 278 }
emilmont 1:fdd22bb7aa52 279
mbed_official 3:7a284390b0ce 280 /* Store the updated state variables back into the state array */
mbed_official 3:7a284390b0ce 281 *pState++ = d1;
mbed_official 3:7a284390b0ce 282 *pState++ = d2;
emilmont 1:fdd22bb7aa52 283
mbed_official 3:7a284390b0ce 284 /* The current stage input is given as the output to the next stage */
mbed_official 3:7a284390b0ce 285 pIn = pDst;
emilmont 1:fdd22bb7aa52 286
mbed_official 3:7a284390b0ce 287 /*Reset the output working pointer */
mbed_official 3:7a284390b0ce 288 pOut = pDst;
emilmont 1:fdd22bb7aa52 289
emilmont 1:fdd22bb7aa52 290 /* decrement the loop counter */
mbed_official 3:7a284390b0ce 291 stage--;
emilmont 1:fdd22bb7aa52 292
mbed_official 3:7a284390b0ce 293 } while(stage > 0u);
emilmont 1:fdd22bb7aa52 294
emilmont 1:fdd22bb7aa52 295 #else
emilmont 1:fdd22bb7aa52 296
mbed_official 3:7a284390b0ce 297 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 298
mbed_official 3:7a284390b0ce 299 do
mbed_official 3:7a284390b0ce 300 {
mbed_official 3:7a284390b0ce 301 /* Reading the coefficients */
mbed_official 3:7a284390b0ce 302 b0 = *pCoeffs++;
mbed_official 3:7a284390b0ce 303 b1 = *pCoeffs++;
mbed_official 3:7a284390b0ce 304 b2 = *pCoeffs++;
mbed_official 3:7a284390b0ce 305 a1 = *pCoeffs++;
mbed_official 3:7a284390b0ce 306 a2 = *pCoeffs++;
emilmont 1:fdd22bb7aa52 307
mbed_official 3:7a284390b0ce 308 /*Reading the state values */
mbed_official 3:7a284390b0ce 309 d1 = pState[0];
mbed_official 3:7a284390b0ce 310 d2 = pState[1];
emilmont 1:fdd22bb7aa52 311
emilmont 1:fdd22bb7aa52 312
mbed_official 3:7a284390b0ce 313 sample = blockSize;
mbed_official 3:7a284390b0ce 314
mbed_official 3:7a284390b0ce 315 while(sample > 0u)
mbed_official 3:7a284390b0ce 316 {
mbed_official 3:7a284390b0ce 317 /* Read the input */
mbed_official 3:7a284390b0ce 318 Xn1 = *pIn++;
emilmont 1:fdd22bb7aa52 319
mbed_official 3:7a284390b0ce 320 /* y[n] = b0 * x[n] + d1 */
mbed_official 3:7a284390b0ce 321 acc1 = (b0 * Xn1) + d1;
emilmont 1:fdd22bb7aa52 322
mbed_official 3:7a284390b0ce 323 /* Store the result in the accumulator in the destination buffer. */
mbed_official 3:7a284390b0ce 324 *pOut++ = acc1;
mbed_official 3:7a284390b0ce 325
mbed_official 3:7a284390b0ce 326 /* Every time after the output is computed state should be updated. */
mbed_official 3:7a284390b0ce 327 /* d1 = b1 * x[n] + a1 * y[n] + d2 */
mbed_official 3:7a284390b0ce 328 d1 = ((b1 * Xn1) + (a1 * acc1)) + d2;
emilmont 1:fdd22bb7aa52 329
mbed_official 3:7a284390b0ce 330 /* d2 = b2 * x[n] + a2 * y[n] */
mbed_official 3:7a284390b0ce 331 d2 = (b2 * Xn1) + (a2 * acc1);
mbed_official 3:7a284390b0ce 332
mbed_official 3:7a284390b0ce 333 /* decrement the loop counter */
mbed_official 3:7a284390b0ce 334 sample--;
mbed_official 3:7a284390b0ce 335 }
emilmont 1:fdd22bb7aa52 336
mbed_official 3:7a284390b0ce 337 /* Store the updated state variables back into the state array */
mbed_official 3:7a284390b0ce 338 *pState++ = d1;
mbed_official 3:7a284390b0ce 339 *pState++ = d2;
emilmont 1:fdd22bb7aa52 340
mbed_official 3:7a284390b0ce 341 /* The current stage input is given as the output to the next stage */
mbed_official 3:7a284390b0ce 342 pIn = pDst;
mbed_official 3:7a284390b0ce 343
mbed_official 3:7a284390b0ce 344 /*Reset the output working pointer */
mbed_official 3:7a284390b0ce 345 pOut = pDst;
emilmont 1:fdd22bb7aa52 346
emilmont 1:fdd22bb7aa52 347 /* decrement the loop counter */
mbed_official 3:7a284390b0ce 348 stage--;
emilmont 1:fdd22bb7aa52 349
mbed_official 3:7a284390b0ce 350 } while(stage > 0u);
emilmont 1:fdd22bb7aa52 351
mbed_official 3:7a284390b0ce 352 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 353
emilmont 1:fdd22bb7aa52 354 }
mbed_official 3:7a284390b0ce 355 LOW_OPTIMIZATION_EXIT
emilmont 1:fdd22bb7aa52 356
mbed_official 3:7a284390b0ce 357 /**
emilmont 1:fdd22bb7aa52 358 * @} end of BiquadCascadeDF2T group
emilmont 1:fdd22bb7aa52 359 */