CMSIS DSP Software Library: arm_fir_decimate_q15.c Source File

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

- File List
- Globals

# arm_fir_decimate_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_fir_decimate_q15.c
    00009 *
    00010 * Description:  Q15 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
    00065 void arm_fir_decimate_q15(
    00066   const arm_fir_decimate_instance_q15 * S,
    00067   q15_t * pSrc,
    00068   q15_t * pDst,
    00069   uint32_t blockSize)
    00070 {
    00071   q15_t *pState = S->pState;                     /* State pointer */
    00072   q15_t *pCoeffs = S->pCoeffs;                   /* Coefficient pointer */
    00073   q15_t *pStateCurnt;                            /* Points to the current sample of the state */
    00074   q15_t *px;                                     /* Temporary pointer for state buffer */
    00075   q15_t *pb;                                     /* Temporary pointer coefficient buffer */
    00076   q31_t x0, c0;                                  /* Temporary variables to hold state and coefficient values */
    00077   q63_t sum0;                                    /* Accumulators */
    00078   uint32_t numTaps = S->numTaps;                 /* Number of taps */
    00079   uint32_t i, blkCnt, tapCnt, outBlockSize = blockSize / S->M;  /* Loop counters */
    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 sum 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 Read b[numTaps-1] and b[numTaps-2]  coefficients */
    00120       c0 = *__SIMD32(pb)++;
    00121
    00122       /* Read x[n-numTaps-1] and x[n-numTaps-2]sample */
    00123       x0 = *__SIMD32(px)++;
    00124
    00125       /* Perform the multiply-accumulate */
    00126       sum0 = __SMLALD(x0, c0, sum0);
    00127
    00128       /* Read the b[numTaps-3] and b[numTaps-4] coefficient */
    00129       c0 = *__SIMD32(pb)++;
    00130
    00131       /* Read x[n-numTaps-2] and x[n-numTaps-3] sample */
    00132       x0 = *__SIMD32(px)++;
    00133
    00134       /* Perform the multiply-accumulate */
    00135       sum0 = __SMLALD(x0, c0, sum0);
    00136
    00137       /* Decrement the loop counter */
    00138       tapCnt--;
    00139     }
    00140
    00141     /* If the filter length is not a multiple of 4, compute the remaining filter taps */
    00142     tapCnt = numTaps % 0x4u;
    00143
    00144     while(tapCnt > 0u)
    00145     {
    00146       /* Read coefficients */
    00147       c0 = *pb++;
    00148
    00149       /* Fetch 1 state variable */
    00150       x0 = *px++;
    00151
    00152       /* Perform the multiply-accumulate */
    00153       sum0 = __SMLALD(x0, c0, sum0);
    00154
    00155       /* Decrement the loop counter */
    00156       tapCnt--;
    00157     }
    00158
    00159     /* Advance the state pointer by the decimation factor
    00160      * to process the next group of decimation factor number samples */
    00161     pState = pState + S->M;
    00162
    00163     /* Store filter output, smlad returns the values in 2.14 format */
    00164     /* so downsacle by 15 to get output in 1.15 */
    00165     *pDst++ = (q15_t) (__SSAT((sum0 >> 15), 16));
    00166
    00167     /* Decrement the loop counter */
    00168     blkCnt--;
    00169   }
    00170
    00171   /* Processing is complete.
    00172    ** Now copy the last numTaps - 1 samples to the satrt of the state buffer.
    00173    ** This prepares the state buffer for the next function call. */
    00174
    00175   /* Points to the start of the state buffer */
    00176   pStateCurnt = S->pState;
    00177
    00178   i = (numTaps - 1u) >> 2u;
    00179
    00180   /* copy data */
    00181   while(i > 0u)
    00182   {
    00183     *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;
    00184     *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;
    00185
    00186     /* Decrement the loop counter */
    00187     i--;
    00188   }
    00189
    00190   i = (numTaps - 1u) % 0x04u;
    00191
    00192   /* copy data */
    00193   while(i > 0u)
    00194   {
    00195     *pStateCurnt++ = *pState++;
    00196
    00197     /* Decrement the loop counter */
    00198     i--;
    00199   }
    00200
    00201 #else
    00202
    00203 /* Run the below code for Cortex-M0 */
    00204
    00205   /* S->pState buffer contains previous frame (numTaps - 1) samples */
    00206   /* pStateCurnt points to the location where the new input data should be written */
    00207   pStateCurnt = S->pState + (numTaps - 1u);
    00208
    00209   /* Total number of output samples to be computed */
    00210   blkCnt = outBlockSize;
    00211
    00212   while(blkCnt > 0u)
    00213   {
    00214     /* Copy decimation factor number of new input samples into the state buffer */
    00215     i = S->M;
    00216
    00217     do
    00218     {
    00219       *pStateCurnt++ = *pSrc++;
    00220
    00221     } while(--i);
    00222
    00223     /*Set sum to zero */
    00224     sum0 = 0;
    00225
    00226     /* Initialize state pointer */
    00227     px = pState;
    00228
    00229     /* Initialize coeff pointer */
    00230     pb = pCoeffs;
    00231
    00232     tapCnt = numTaps;
    00233
    00234     while(tapCnt > 0u)
    00235     {
    00236       /* Read coefficients */
    00237       c0 = *pb++;
    00238
    00239       /* Fetch 1 state variable */
    00240       x0 = *px++;
    00241
    00242       /* Perform the multiply-accumulate */
    00243       sum0 += (q31_t) x0 *c0;
    00244
    00245       /* Decrement the loop counter */
    00246       tapCnt--;
    00247     }
    00248
    00249     /* Advance the state pointer by the decimation factor
    00250      * to process the next group of decimation factor number samples */
    00251     pState = pState + S->M;
    00252
    00253     /*Store filter output , smlad will return the values in 2.14 format */
    00254     /* so downsacle by 15 to get output in 1.15 */
    00255     *pDst++ = (q15_t) (__SSAT((sum0 >> 15), 16));
    00256
    00257     /* Decrement the loop counter */
    00258     blkCnt--;
    00259   }
    00260
    00261   /* Processing is complete.
    00262    ** Now copy the last numTaps - 1 samples to the start of the state buffer.
    00263    ** This prepares the state buffer for the next function call. */
    00264
    00265   /* Points to the start of the state buffer */
    00266   pStateCurnt = S->pState;
    00267
    00268   i = numTaps - 1u;
    00269
    00270   /* copy data */
    00271   while(i > 0u)
    00272   {
    00273     *pStateCurnt++ = *pState++;
    00274
    00275     /* Decrement the loop counter */
    00276     i--;
    00277   }
    00278
    00279 #endif /*   #ifndef ARM_MATH_CM0 */
    00280
    00281 }
    00282

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines