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

- File List
- Globals

# arm_fir_decimate_fast_q31.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_fir_decimate_fast_q31.c
    00009 *
    00010 * Description:  Fast Q31 FIR Decimator.
    00011 *
    00012 * Target Processor: Cortex-M4/Cortex-M3
    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
    00030 #include "arm_math.h"
    00031
    00065 void arm_fir_decimate_fast_q31(
    00066   arm_fir_decimate_instance_q31 * S,
    00067   q31_t * pSrc,
    00068   q31_t * pDst,
    00069   uint32_t blockSize)
    00070 {
    00071   q31_t *pState = S->pState;                     /* State pointer */
    00072   q31_t *pCoeffs = S->pCoeffs;                   /* Coefficient pointer */
    00073   q31_t *pStateCurnt;                            /* Points to the current sample of the state */
    00074   q31_t x0, c0;                                  /* Temporary variables to hold state and coefficient values */
    00075   q31_t *px;                                     /* Temporary pointers for state buffer */
    00076   q31_t *pb;                                     /* Temporary pointers for coefficient buffer */
    00077   q63_t sum0;                                    /* Accumulator */
    00078   uint32_t numTaps = S->numTaps;                 /* Number of taps */
    00079   uint32_t i, tapCnt, blkCnt, outBlockSize = blockSize / S->M;  /* Loop counters */
    00080
    00081
    00082   /* S->pState buffer contains previous frame (numTaps - 1) samples */
    00083   /* pStateCurnt points to the location where the new input data should be written */
    00084   pStateCurnt = S->pState + (numTaps - 1u);
    00085
    00086   /* Total number of output samples to be computed */
    00087   blkCnt = outBlockSize;
    00088
    00089   while(blkCnt > 0u)
    00090   {
    00091     /* Copy decimation factor number of new input samples into the state buffer */
    00092     i = S->M;
    00093
    00094     do
    00095     {
    00096       *pStateCurnt++ = *pSrc++;
    00097
    00098     } while(--i);
    00099
    00100     /* Set accumulator to zero */
    00101     sum0 = 0;
    00102
    00103     /* Initialize state pointer */
    00104     px = pState;
    00105
    00106     /* Initialize coeff pointer */
    00107     pb = pCoeffs;
    00108
    00109     /* Loop unrolling.  Process 4 taps at a time. */
    00110     tapCnt = numTaps >> 2;
    00111
    00112     /* Loop over the number of taps.  Unroll by a factor of 4.
    00113      ** Repeat until we've computed numTaps-4 coefficients. */
    00114     while(tapCnt > 0u)
    00115     {
    00116       /* Read the b[numTaps-1] coefficient */
    00117       c0 = *(pb++);
    00118
    00119       /* Read x[n-numTaps-1] sample */
    00120       x0 = *(px++);
    00121
    00122       /* Perform the multiply-accumulate */
    00123       sum0 = (q31_t) ((((q63_t) x0 * c0) + (sum0 << 32)) >> 32);
    00124
    00125       /* Read the b[numTaps-2] coefficient */
    00126       c0 = *(pb++);
    00127
    00128       /* Read x[n-numTaps-2] sample */
    00129       x0 = *(px++);
    00130
    00131       /* Perform the multiply-accumulate */
    00132       sum0 = (q31_t) ((((q63_t) x0 * c0) + (sum0 << 32)) >> 32);
    00133
    00134       /* Read the b[numTaps-3] coefficient */
    00135       c0 = *(pb++);
    00136
    00137       /* Read x[n-numTaps-3] sample */
    00138       x0 = *(px++);
    00139
    00140       /* Perform the multiply-accumulate */
    00141       sum0 = (q31_t) ((((q63_t) x0 * c0) + (sum0 << 32)) >> 32);
    00142
    00143       /* Read the b[numTaps-4] coefficient */
    00144       c0 = *(pb++);
    00145
    00146       /* Read x[n-numTaps-4] sample */
    00147       x0 = *(px++);
    00148
    00149       /* Perform the multiply-accumulate */
    00150       sum0 = (q31_t) ((((q63_t) x0 * c0) + (sum0 << 32)) >> 32);
    00151
    00152       /* Decrement the loop counter */
    00153       tapCnt--;
    00154     }
    00155
    00156     /* If the filter length is not a multiple of 4, compute the remaining filter taps */
    00157     tapCnt = numTaps % 0x4u;
    00158
    00159     while(tapCnt > 0u)
    00160     {
    00161       /* Read coefficients */
    00162       c0 = *(pb++);
    00163
    00164       /* Fetch 1 state variable */
    00165       x0 = *(px++);
    00166
    00167       /* Perform the multiply-accumulate */
    00168       sum0 = (q31_t) ((((q63_t) x0 * c0) + (sum0 << 32)) >> 32);
    00169
    00170       /* Decrement the loop counter */
    00171       tapCnt--;
    00172     }
    00173
    00174     /* Advance the state pointer by the decimation factor
    00175      * to process the next group of decimation factor number samples */
    00176     pState = pState + S->M;
    00177
    00178     /* The result is in the accumulator, store in the destination buffer. */
    00179     *pDst++ = (q31_t) (sum0 << 1);
    00180
    00181     /* Decrement the loop counter */
    00182     blkCnt--;
    00183   }
    00184
    00185   /* Processing is complete.
    00186    ** Now copy the last numTaps - 1 samples to the satrt of the state buffer.
    00187    ** This prepares the state buffer for the next function call. */
    00188
    00189   /* Points to the start of the state buffer */
    00190   pStateCurnt = S->pState;
    00191
    00192   i = (numTaps - 1u) >> 2u;
    00193
    00194   /* copy data */
    00195   while(i > 0u)
    00196   {
    00197     *pStateCurnt++ = *pState++;
    00198     *pStateCurnt++ = *pState++;
    00199     *pStateCurnt++ = *pState++;
    00200     *pStateCurnt++ = *pState++;
    00201
    00202     /* Decrement the loop counter */
    00203     i--;
    00204   }
    00205
    00206   i = (numTaps - 1u) % 0x04u;
    00207
    00208   /* copy data */
    00209   while(i > 0u)
    00210   {
    00211     *pStateCurnt++ = *pState++;
    00212
    00213     /* Decrement the loop counter */
    00214     i--;
    00215   }
    00216 }
    00217

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines