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

- File List
- Globals

# arm_cmplx_mag_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_cmplx_mag_q31.c
    00009 *
    00010 * Description:  Q31 complex magnitude
    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
    00030 #include "arm_math.h"
    00031
    00054 void arm_cmplx_mag_q31(
    00055   q31_t * pSrc,
    00056   q31_t * pDst,
    00057   uint32_t numSamples)
    00058 {
    00059   q31_t real, imag;                              /* Temporary variables to hold input values */
    00060   q31_t acc0, acc1;                              /* Accumulators */
    00061
    00062 #ifndef ARM_MATH_CM0
    00063
    00064   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00065   uint32_t blkCnt;                               /* loop counter */
    00066
    00067
    00068   /*loop Unrolling */
    00069   blkCnt = numSamples >> 2u;
    00070
    00071   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00072    ** a second loop below computes the remaining 1 to 3 samples. */
    00073   while(blkCnt > 0u)
    00074   {
    00075
    00076     /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
    00077     real = *pSrc++;
    00078     imag = *pSrc++;
    00079     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00080     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00081     /* store the result in 2.30 format in the destination buffer. */
    00082     arm_sqrt_q31(acc0 + acc1, pDst++);
    00083
    00084     real = *pSrc++;
    00085     imag = *pSrc++;
    00086     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00087     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00088     /* store the result in 2.30 format in the destination buffer. */
    00089     arm_sqrt_q31(acc0 + acc1, pDst++);
    00090
    00091     real = *pSrc++;
    00092     imag = *pSrc++;
    00093     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00094     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00095     /* store the result in 2.30 format in the destination buffer. */
    00096     arm_sqrt_q31(acc0 + acc1, pDst++);
    00097
    00098     real = *pSrc++;
    00099     imag = *pSrc++;
    00100     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00101     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00102     /* store the result in 2.30 format in the destination buffer. */
    00103     arm_sqrt_q31(acc0 + acc1, pDst++);
    00104
    00105     /* Decrement the loop counter */
    00106     blkCnt--;
    00107   }
    00108
    00109   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
    00110    ** No loop unrolling is used. */
    00111   blkCnt = numSamples % 0x4u;
    00112
    00113   while(blkCnt > 0u)
    00114   {
    00115     /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
    00116     real = *pSrc++;
    00117     imag = *pSrc++;
    00118     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00119     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00120     /* store the result in 2.30 format in the destination buffer. */
    00121     arm_sqrt_q31(acc0 + acc1, pDst++);
    00122
    00123     /* Decrement the loop counter */
    00124     blkCnt--;
    00125   }
    00126
    00127 #else
    00128
    00129   /* Run the below code for Cortex-M0 */
    00130
    00131   while(numSamples > 0u)
    00132   {
    00133     /* out = sqrt((real * real) + (imag * imag)) */
    00134     real = *pSrc++;
    00135     imag = *pSrc++;
    00136     acc0 = (q31_t) (((q63_t) real * real) >> 33);
    00137     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
    00138     /* store the result in 2.30 format in the destination buffer. */
    00139     arm_sqrt_q31(acc0 + acc1, pDst++);
    00140
    00141     /* Decrement the loop counter */
    00142     numSamples--;
    00143   }
    00144
    00145 #endif /* #ifndef ARM_MATH_CM0 */
    00146
    00147 }
    00148

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines