CMSIS DSP Software Library: arm_fir_decimate_q31.c Source File

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

- File List
- Globals

# arm_fir_decimate_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_q31.c
    00009 *
    00010 * Description:  Q31 FIR Decimator.
    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
    00064 void arm_fir_decimate_q31(
    00065   const arm_fir_decimate_instance_q31 * S,
    00066   q31_t * pSrc,
    00067   q31_t * pDst,
    00068   uint32_t blockSize)
    00069 {
    00070   q31_t *pState = S->pState;                     /* State pointer */
    00071   q31_t *pCoeffs = S->pCoeffs;                   /* Coefficient pointer */
    00072   q31_t *pStateCurnt;                            /* Points to the current sample of the state */
    00073   q31_t x0, c0;                                  /* Temporary variables to hold state and coefficient values */
    00074   q31_t *px;                                     /* Temporary pointers for state buffer */
    00075   q31_t *pb;                                     /* Temporary pointers for coefficient buffer */
    00076   q63_t sum0;                                    /* Accumulator */
    00077   uint32_t numTaps = S->numTaps;                 /* Number of taps */
    00078   uint32_t i, tapCnt, blkCnt, outBlockSize = blockSize / S->M;  /* Loop counters */
    00079
    00080
    00081 #ifndef ARM_MATH_CM0
    00082
    00083   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00084
    00085   /* S->pState buffer contains previous frame (numTaps - 1) samples */
    00086   /* pStateCurnt points to the location where the new input data should be written */
    00087   pStateCurnt = S->pState + (numTaps - 1u);
    00088
    00089   /* Total number of output samples to be computed */
    00090   blkCnt = outBlockSize;
    00091
    00092   while(blkCnt > 0u)
    00093   {
    00094     /* Copy decimation factor number of new input samples into the state buffer */
    00095     i = S->M;
    00096
    00097     do
    00098     {
    00099       *pStateCurnt++ = *pSrc++;
    00100
    00101     } while(--i);
    00102
    00103     /* Set accumulator to zero */
    00104     sum0 = 0;
    00105
    00106     /* Initialize state pointer */
    00107     px = pState;
    00108
    00109     /* Initialize coeff pointer */
    00110     pb = pCoeffs;
    00111
    00112     /* Loop unrolling.  Process 4 taps at a time. */
    00113     tapCnt = numTaps >> 2;
    00114
    00115     /* Loop over the number of taps.  Unroll by a factor of 4.
    00116      ** Repeat until we've computed numTaps-4 coefficients. */
    00117     while(tapCnt > 0u)
    00118     {
    00119       /* Read the b[numTaps-1] coefficient */
    00120       c0 = *(pb++);
    00121
    00122       /* Read x[n-numTaps-1] sample */
    00123       x0 = *(px++);
    00124
    00125       /* Perform the multiply-accumulate */
    00126       sum0 += (q63_t) x0 *c0;
    00127
    00128       /* Read the b[numTaps-2] coefficient */
    00129       c0 = *(pb++);
    00130
    00131       /* Read x[n-numTaps-2] sample */
    00132       x0 = *(px++);
    00133
    00134       /* Perform the multiply-accumulate */
    00135       sum0 += (q63_t) x0 *c0;
    00136
    00137       /* Read the b[numTaps-3] coefficient */
    00138       c0 = *(pb++);
    00139
    00140       /* Read x[n-numTaps-3] sample */
    00141       x0 = *(px++);
    00142
    00143       /* Perform the multiply-accumulate */
    00144       sum0 += (q63_t) x0 *c0;
    00145
    00146       /* Read the b[numTaps-4] coefficient */
    00147       c0 = *(pb++);
    00148
    00149       /* Read x[n-numTaps-4] sample */
    00150       x0 = *(px++);
    00151
    00152       /* Perform the multiply-accumulate */
    00153       sum0 += (q63_t) x0 *c0;
    00154
    00155       /* Decrement the loop counter */
    00156       tapCnt--;
    00157     }
    00158
    00159     /* If the filter length is not a multiple of 4, compute the remaining filter taps */
    00160     tapCnt = numTaps % 0x4u;
    00161
    00162     while(tapCnt > 0u)
    00163     {
    00164       /* Read coefficients */
    00165       c0 = *(pb++);
    00166
    00167       /* Fetch 1 state variable */
    00168       x0 = *(px++);
    00169
    00170       /* Perform the multiply-accumulate */
    00171       sum0 += (q63_t) x0 *c0;
    00172
    00173       /* Decrement the loop counter */
    00174       tapCnt--;
    00175     }
    00176
    00177     /* Advance the state pointer by the decimation factor
    00178      * to process the next group of decimation factor number samples */
    00179     pState = pState + S->M;
    00180
    00181     /* The result is in the accumulator, store in the destination buffer. */
    00182     *pDst++ = (q31_t) (sum0 >> 31);
    00183
    00184     /* Decrement the loop counter */
    00185     blkCnt--;
    00186   }
    00187
    00188   /* Processing is complete.
    00189    ** Now copy the last numTaps - 1 samples to the satrt of the state buffer.
    00190    ** This prepares the state buffer for the next function call. */
    00191
    00192   /* Points to the start of the state buffer */
    00193   pStateCurnt = S->pState;
    00194
    00195   i = (numTaps - 1u) >> 2u;
    00196
    00197   /* copy data */
    00198   while(i > 0u)
    00199   {
    00200     *pStateCurnt++ = *pState++;
    00201     *pStateCurnt++ = *pState++;
    00202     *pStateCurnt++ = *pState++;
    00203     *pStateCurnt++ = *pState++;
    00204
    00205     /* Decrement the loop counter */
    00206     i--;
    00207   }
    00208
    00209   i = (numTaps - 1u) % 0x04u;
    00210
    00211   /* copy data */
    00212   while(i > 0u)
    00213   {
    00214     *pStateCurnt++ = *pState++;
    00215
    00216     /* Decrement the loop counter */
    00217     i--;
    00218   }
    00219
    00220 #else
    00221
    00222 /* Run the below code for Cortex-M0 */
    00223
    00224   /* S->pState buffer contains previous frame (numTaps - 1) samples */
    00225   /* pStateCurnt points to the location where the new input data should be written */
    00226   pStateCurnt = S->pState + (numTaps - 1u);
    00227
    00228   /* Total number of output samples to be computed */
    00229   blkCnt = outBlockSize;
    00230
    00231   while(blkCnt > 0u)
    00232   {
    00233     /* Copy decimation factor number of new input samples into the state buffer */
    00234     i = S->M;
    00235
    00236     do
    00237     {
    00238       *pStateCurnt++ = *pSrc++;
    00239
    00240     } while(--i);
    00241
    00242     /* Set accumulator to zero */
    00243     sum0 = 0;
    00244
    00245     /* Initialize state pointer */
    00246     px = pState;
    00247
    00248     /* Initialize coeff pointer */
    00249     pb = pCoeffs;
    00250
    00251     tapCnt = numTaps;
    00252
    00253     while(tapCnt > 0u)
    00254     {
    00255       /* Read coefficients */
    00256       c0 = *pb++;
    00257
    00258       /* Fetch 1 state variable */
    00259       x0 = *px++;
    00260
    00261       /* Perform the multiply-accumulate */
    00262       sum0 += (q63_t) x0 *c0;
    00263
    00264       /* Decrement the loop counter */
    00265       tapCnt--;
    00266     }
    00267
    00268     /* Advance the state pointer by the decimation factor
    00269      * to process the next group of decimation factor number samples */
    00270     pState = pState + S->M;
    00271
    00272     /* The result is in the accumulator, store in the destination buffer. */
    00273     *pDst++ = (q31_t) (sum0 >> 31);
    00274
    00275     /* Decrement the loop counter */
    00276     blkCnt--;
    00277   }
    00278
    00279   /* Processing is complete.
    00280    ** Now copy the last numTaps - 1 samples to the start of the state buffer.
    00281    ** This prepares the state buffer for the next function call. */
    00282
    00283   /* Points to the start of the state buffer */
    00284   pStateCurnt = S->pState;
    00285
    00286   i = numTaps - 1u;
    00287
    00288   /* copy data */
    00289   while(i > 0u)
    00290   {
    00291     *pStateCurnt++ = *pState++;
    00292
    00293     /* Decrement the loop counter */
    00294     i--;
    00295   }
    00296
    00297 #endif /*   #ifndef ARM_MATH_CM0 */
    00298
    00299 }
    00300

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines