- Main Page
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

# arm_iir_lattice_q15.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------
    00002 * Copyright (C) 2010 ARM Limited. All rights reserved.
    00003 *
    00004 * $Date:        15. July 2011
    00005 * $Revision:    V1.0.10
    00006 *
    00007 * Project:      CMSIS DSP Library
    00008 * Title:        arm_iir_lattice_q15.c
    00009 *
    00010 * Description:  Q15 IIR lattice filter processing function.
    00011 *
    00012 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
    00013 *
    00014 * Version 1.0.10 2011/7/15
    00015 *    Big Endian support added and Merged M0 and M3/M4 Source code.
    00016 *
    00017 * Version 1.0.3 2010/11/29
    00018 *    Re-organized the CMSIS folders and updated documentation.
    00019 *
    00020 * Version 1.0.2 2010/11/11
    00021 *    Documentation updated.
    00022 *
    00023 * Version 1.0.1 2010/10/05
    00024 *    Production release and review comments incorporated.
    00025 *
    00026 * Version 1.0.0 2010/09/20
    00027 *    Production release and review comments incorporated
    00028 *
    00029 * Version 0.0.7  2010/06/10
    00030 *    Misra-C changes done
    00031 * -------------------------------------------------------------------- */
    00032
    00033 #include "arm_math.h"
    00034
    00063 void arm_iir_lattice_q15(
    00064   const arm_iir_lattice_instance_q15 * S,
    00065   q15_t * pSrc,
    00066   q15_t * pDst,
    00067   uint32_t blockSize)
    00068 {
    00069
    00070
    00071 #ifndef ARM_MATH_CM0
    00072
    00073   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00074
    00075   q31_t fcurr, fnext, gcurr = 0, gnext;          /* Temporary variables for lattice stages */
    00076   q15_t gnext1, gnext2;                          /* Temporary variables for lattice stages */
    00077   uint32_t stgCnt;                               /* Temporary variables for counts */
    00078   q63_t acc;                                     /* Accumlator */
    00079   uint32_t blkCnt, tapCnt;                       /* Temporary variables for counts */
    00080   q15_t *px1, *px2, *pk, *pv;                    /* temporary pointers for state and coef */
    00081   uint32_t numStages = S->numStages;             /* number of stages */
    00082   q15_t *pState;                                 /* State pointer */
    00083   q15_t *pStateCurnt;                            /* State current pointer */
    00084   q15_t out;                                     /* Temporary variable for output */
    00085   q31_t v;                                       /* Temporary variable for ladder coefficient */
    00086
    00087
    00088   blkCnt = blockSize;
    00089
    00090   pState = &S->pState[0];
    00091
    00092   /* Sample processing */
    00093   while(blkCnt > 0u)
    00094   {
    00095     /* Read Sample from input buffer */
    00096     /* fN(n) = x(n) */
    00097     fcurr = *pSrc++;
    00098
    00099     /* Initialize state read pointer */
    00100     px1 = pState;
    00101     /* Initialize state write pointer */
    00102     px2 = pState;
    00103     /* Set accumulator to zero */
    00104     acc = 0;
    00105     /* Initialize Ladder coeff pointer */
    00106     pv = &S->pvCoeffs[0];
    00107     /* Initialize Reflection coeff pointer */
    00108     pk = &S->pkCoeffs[0];
    00109
    00110
    00111     /* Process sample for first tap */
    00112     gcurr = *px1++;
    00113     /* fN-1(n) = fN(n) - kN * gN-1(n-1) */
    00114     fnext = fcurr - (((q31_t) gcurr * (*pk)) >> 15);
    00115     fnext = __SSAT(fnext, 16);
    00116     /* gN(n) = kN * fN-1(n) + gN-1(n-1) */
    00117     gnext = (((q31_t) fnext * (*pk++)) >> 15) + gcurr;
    00118     gnext = __SSAT(gnext, 16);
    00119     /* write gN(n) into state for next sample processing */
    00120     *px2++ = (q15_t) gnext;
    00121     /* y(n) += gN(n) * vN  */
    00122     acc += (q31_t) ((gnext * (*pv++)));
    00123
    00124
    00125     /* Update f values for next coefficient processing */
    00126     fcurr = fnext;
    00127
    00128     /* Loop unrolling.  Process 4 taps at a time. */
    00129     tapCnt = (numStages - 1u) >> 2;
    00130
    00131     while(tapCnt > 0u)
    00132     {
    00133
    00134       /* Process sample for 2nd, 6th ...taps */
    00135       /* Read gN-2(n-1) from state buffer */
    00136       gcurr = *px1++;
    00137       /* Process sample for 2nd, 6th .. taps */
    00138       /* fN-2(n) = fN-1(n) - kN-1 * gN-2(n-1) */
    00139       fnext = fcurr - (((q31_t) gcurr * (*pk)) >> 15);
    00140       fnext = __SSAT(fnext, 16);
    00141       /* gN-1(n) = kN-1 * fN-2(n) + gN-2(n-1) */
    00142       gnext = (((q31_t) fnext * (*pk++)) >> 15) + gcurr;
    00143       gnext1 = (q15_t) __SSAT(gnext, 16);
    00144       /* write gN-1(n) into state */
    00145       *px2++ = (q15_t) gnext1;
    00146
    00147
    00148       /* Process sample for 3nd, 7th ...taps */
    00149       /* Read gN-3(n-1) from state */
    00150       gcurr = *px1++;
    00151       /* Process sample for 3rd, 7th .. taps */
    00152       /* fN-3(n) = fN-2(n) - kN-2 * gN-3(n-1) */
    00153       fcurr = fnext - (((q31_t) gcurr * (*pk)) >> 15);
    00154       fcurr = __SSAT(fcurr, 16);
    00155       /* gN-2(n) = kN-2 * fN-3(n) + gN-3(n-1) */
    00156       gnext = (((q31_t) fcurr * (*pk++)) >> 15) + gcurr;
    00157       gnext2 = (q15_t) __SSAT(gnext, 16);
    00158       /* write gN-2(n) into state */
    00159       *px2++ = (q15_t) gnext2;
    00160
    00161       /* Read vN-1 and vN-2 at a time */
    00162       v = *__SIMD32(pv)++;
    00163
    00164
    00165       /* Pack gN-1(n) and gN-2(n) */
    00166
    00167 #ifndef  ARM_MATH_BIG_ENDIAN
    00168
    00169       gnext = __PKHBT(gnext1, gnext2, 16);
    00170
    00171 #else
    00172
    00173       gnext = __PKHBT(gnext2, gnext1, 16);
    00174
    00175 #endif /*   #ifndef  ARM_MATH_BIG_ENDIAN    */
    00176
    00177       /* y(n) += gN-1(n) * vN-1  */
    00178       /* process for gN-5(n) * vN-5, gN-9(n) * vN-9 ... */
    00179       /* y(n) += gN-2(n) * vN-2  */
    00180       /* process for gN-6(n) * vN-6, gN-10(n) * vN-10 ... */
    00181       acc = __SMLALD(gnext, v, acc);
    00182
    00183
    00184       /* Process sample for 4th, 8th ...taps */
    00185       /* Read gN-4(n-1) from state */
    00186       gcurr = *px1++;
    00187       /* Process sample for 4th, 8th .. taps */
    00188       /* fN-4(n) = fN-3(n) - kN-3 * gN-4(n-1) */
    00189       fnext = fcurr - (((q31_t) gcurr * (*pk)) >> 15);
    00190       fnext = __SSAT(fnext, 16);
    00191       /* gN-3(n) = kN-3 * fN-1(n) + gN-1(n-1) */
    00192       gnext = (((q31_t) fnext * (*pk++)) >> 15) + gcurr;
    00193       gnext1 = (q15_t) __SSAT(gnext, 16);
    00194       /* write  gN-3(n) for the next sample process */
    00195       *px2++ = (q15_t) gnext1;
    00196
    00197
    00198       /* Process sample for 5th, 9th ...taps */
    00199       /* Read gN-5(n-1) from state */
    00200       gcurr = *px1++;
    00201       /* Process sample for 5th, 9th .. taps */
    00202       /* fN-5(n) = fN-4(n) - kN-4 * gN-5(n-1) */
    00203       fcurr = fnext - (((q31_t) gcurr * (*pk)) >> 15);
    00204       fcurr = __SSAT(fcurr, 16);
    00205       /* gN-4(n) = kN-4 * fN-5(n) + gN-5(n-1) */
    00206       gnext = (((q31_t) fcurr * (*pk++)) >> 15) + gcurr;
    00207       gnext2 = (q15_t) __SSAT(gnext, 16);
    00208       /* write      gN-4(n) for the next sample process */
    00209       *px2++ = (q15_t) gnext2;
    00210
    00211       /* Read vN-3 and vN-4 at a time */
    00212       v = *__SIMD32(pv)++;
    00213
    00214       /* Pack gN-3(n) and gN-4(n) */
    00215 #ifndef  ARM_MATH_BIG_ENDIAN
    00216
    00217       gnext = __PKHBT(gnext1, gnext2, 16);
    00218
    00219 #else
    00220
    00221       gnext = __PKHBT(gnext2, gnext1, 16);
    00222
    00223 #endif /*      #ifndef  ARM_MATH_BIG_ENDIAN    */
    00224
    00225       /* y(n) += gN-4(n) * vN-4  */
    00226       /* process for gN-8(n) * vN-8, gN-12(n) * vN-12 ... */
    00227       /* y(n) += gN-3(n) * vN-3  */
    00228       /* process for gN-7(n) * vN-7, gN-11(n) * vN-11 ... */
    00229       acc = __SMLALD(gnext, v, acc);
    00230
    00231       tapCnt--;
    00232
    00233     }
    00234
    00235     fnext = fcurr;
    00236
    00237     /* If the filter length is not a multiple of 4, compute the remaining filter taps */
    00238     tapCnt = (numStages - 1u) % 0x4u;
    00239
    00240     while(tapCnt > 0u)
    00241     {
    00242       gcurr = *px1++;
    00243       /* Process sample for last taps */
    00244       fnext = fcurr - (((q31_t) gcurr * (*pk)) >> 15);
    00245       fnext = __SSAT(fnext, 16);
    00246       gnext = (((q31_t) fnext * (*pk++)) >> 15) + gcurr;
    00247       gnext = __SSAT(gnext, 16);
    00248       /* Output samples for last taps */
    00249       acc += (q31_t) (((q31_t) gnext * (*pv++)));
    00250       *px2++ = (q15_t) gnext;
    00251       fcurr = fnext;
    00252
    00253       tapCnt--;
    00254     }
    00255
    00256     /* y(n) += g0(n) * v0 */
    00257     acc += (q31_t) (((q31_t) fnext * (*pv++)));
    00258
    00259     out = (q15_t) __SSAT(acc >> 15, 16);
    00260     *px2++ = (q15_t) fnext;
    00261
    00262     /* write out into pDst */
    00263     *pDst++ = out;
    00264
    00265     /* Advance the state pointer by 4 to process the next group of 4 samples */
    00266     pState = pState + 1u;
    00267     blkCnt--;
    00268
    00269   }
    00270
    00271   /* Processing is complete. Now copy last S->numStages samples to start of the buffer
    00272      for the preperation of next frame process */
    00273   /* Points to the start of the state buffer */
    00274   pStateCurnt = &S->pState[0];
    00275   pState = &S->pState[blockSize];
    00276
    00277   stgCnt = (numStages >> 2u);
    00278
    00279   /* copy data */
    00280   while(stgCnt > 0u)
    00281   {
    00282     *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;
    00283     *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;
    00284
    00285     /* Decrement the loop counter */
    00286     stgCnt--;
    00287
    00288   }
    00289
    00290   /* Calculation of count for remaining q15_t data */
    00291   stgCnt = (numStages) % 0x4u;
    00292
    00293   /* copy data */
    00294   while(stgCnt > 0u)
    00295   {
    00296     *pStateCurnt++ = *pState++;
    00297
    00298     /* Decrement the loop counter */
    00299     stgCnt--;
    00300   }
    00301
    00302 #else
    00303
    00304   /* Run the below code for Cortex-M0 */
    00305
    00306   q31_t fcurr, fnext = 0, gcurr = 0, gnext;      /* Temporary variables for lattice stages */
    00307   uint32_t stgCnt;                               /* Temporary variables for counts */
    00308   q63_t acc;                                     /* Accumlator */
    00309   uint32_t blkCnt, tapCnt;                       /* Temporary variables for counts */
    00310   q15_t *px1, *px2, *pk, *pv;                    /* temporary pointers for state and coef */
    00311   uint32_t numStages = S->numStages;             /* number of stages */
    00312   q15_t *pState;                                 /* State pointer */
    00313   q15_t *pStateCurnt;                            /* State current pointer */
    00314   q15_t out;                                     /* Temporary variable for output */
    00315
    00316
    00317   blkCnt = blockSize;
    00318
    00319   pState = &S->pState[0];
    00320
    00321   /* Sample processing */
    00322   while(blkCnt > 0u)
    00323   {
    00324     /* Read Sample from input buffer */
    00325     /* fN(n) = x(n) */
    00326     fcurr = *pSrc++;
    00327
    00328     /* Initialize state read pointer */
    00329     px1 = pState;
    00330     /* Initialize state write pointer */
    00331     px2 = pState;
    00332     /* Set accumulator to zero */
    00333     acc = 0;
    00334     /* Initialize Ladder coeff pointer */
    00335     pv = &S->pvCoeffs[0];
    00336     /* Initialize Reflection coeff pointer */
    00337     pk = &S->pkCoeffs[0];
    00338
    00339     tapCnt = numStages;
    00340
    00341     while(tapCnt > 0u)
    00342     {
    00343       gcurr = *px1++;
    00344       /* Process sample */
    00345       /* fN-1(n) = fN(n) - kN * gN-1(n-1) */
    00346       fnext = fcurr - ((gcurr * (*pk)) >> 15);
    00347       fnext = __SSAT(fnext, 16);
    00348       /* gN(n) = kN * fN-1(n) + gN-1(n-1) */
    00349       gnext = ((fnext * (*pk++)) >> 15) + gcurr;
    00350       gnext = __SSAT(gnext, 16);
    00351       /* Output samples */
    00352       /* y(n) += gN(n) * vN */
    00353       acc += (q31_t) ((gnext * (*pv++)));
    00354       /* write gN(n) into state for next sample processing */
    00355       *px2++ = (q15_t) gnext;
    00356       /* Update f values for next coefficient processing */
    00357       fcurr = fnext;
    00358
    00359       tapCnt--;
    00360     }
    00361
    00362     /* y(n) += g0(n) * v0 */
    00363     acc += (q31_t) ((fnext * (*pv++)));
    00364
    00365     out = (q15_t) __SSAT(acc >> 15, 16);
    00366     *px2++ = (q15_t) fnext;
    00367
    00368     /* write out into pDst */
    00369     *pDst++ = out;
    00370
    00371     /* Advance the state pointer by 1 to process the next group of samples */
    00372     pState = pState + 1u;
    00373     blkCnt--;
    00374
    00375   }
    00376
    00377   /* Processing is complete. Now copy last S->numStages samples to start of the buffer
    00378      for the preperation of next frame process */
    00379   /* Points to the start of the state buffer */
    00380   pStateCurnt = &S->pState[0];
    00381   pState = &S->pState[blockSize];
    00382
    00383   stgCnt = numStages;
    00384
    00385   /* copy data */
    00386   while(stgCnt > 0u)
    00387   {
    00388     *pStateCurnt++ = *pState++;
    00389
    00390     /* Decrement the loop counter */
    00391     stgCnt--;
    00392   }
    00393
    00394 #endif /*   #ifndef ARM_MATH_CM0 */
    00395
    00396 }
    00397
    00398
    00399
    00400

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines