CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details

Dependents:   K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_cmplx_mag_q15.c Source File

arm_cmplx_mag_q15.c

00001 /* ----------------------------------------------------------------------  
00002 * Copyright (C) 2010 ARM Limited. All rights reserved.  
00003 *  
00004 * $Date:        29. November 2010  
00005 * $Revision:    V1.0.3  
00006 *  
00007 * Project:      CMSIS DSP Library  
00008 * Title:        arm_cmplx_mag_q15.c  
00009 *  
00010 * Description:  Q15 complex magnitude.  
00011 *  
00012 * Target Processor: Cortex-M4/Cortex-M3
00013 *  
00014 * Version 1.0.3 2010/11/29 
00015 *    Re-organized the CMSIS folders and updated documentation.  
00016 *   
00017 * Version 1.0.2 2010/11/11  
00018 *    Documentation updated.   
00019 *  
00020 * Version 1.0.1 2010/10/05   
00021 *    Production release and review comments incorporated.  
00022 *  
00023 * Version 1.0.0 2010/09/20   
00024 *    Production release and review comments incorporated.  
00025 * ---------------------------------------------------------------------------- */ 
00026  
00027 #include "arm_math.h" 
00028  
00029 /**  
00030  * @ingroup groupCmplxMath  
00031  */ 
00032  
00033 /**  
00034  * @addtogroup cmplx_mag  
00035  * @{  
00036  */ 
00037  
00038  
00039 /**  
00040  * @brief  Q15 complex magnitude  
00041  * @param  *pSrc points to the complex input vector  
00042  * @param  *pDst points to the real output vector  
00043  * @param  numSamples number of complex samples in the input vector  
00044  * @return none.  
00045  *  
00046  * <b>Scaling and Overflow Behavior:</b>  
00047  * \par  
00048  * The function implements 1.15 by 1.15 multiplications and finally output is converted into 2.14 format.  
00049  */ 
00050  
00051 void arm_cmplx_mag_q15( 
00052   q15_t * pSrc, 
00053   q15_t * pDst, 
00054   uint32_t numSamples) 
00055 { 
00056   q15_t real, imag;                              /* Temporary variables to hold input values */ 
00057   q31_t acc0, acc1;                              /* Accumulators */ 
00058   uint32_t blkCnt;                               /* loop counter */ 
00059  
00060  
00061   /*loop Unrolling */ 
00062   blkCnt = numSamples >> 2u; 
00063  
00064   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.  
00065    ** a second loop below computes the remaining 1 to 3 samples. */ 
00066   while(blkCnt > 0u) 
00067   { 
00068  
00069     /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */ 
00070     real = *pSrc++; 
00071     imag = *pSrc++; 
00072     acc0 = __SMUAD(real, real); 
00073     acc1 = __SMUAD(imag, imag); 
00074     /* store the result in 2.14 format in the destination buffer. */ 
00075     arm_sqrt_q15((q15_t) (((q63_t) acc0 + acc1) >> 17), pDst++); 
00076  
00077     real = *pSrc++; 
00078     imag = *pSrc++; 
00079     acc0 = __SMUAD(real, real); 
00080     acc1 = __SMUAD(imag, imag); 
00081     /* store the result in 2.14 format in the destination buffer. */ 
00082     arm_sqrt_q15((q15_t) (((q63_t) acc0 + acc1) >> 17), pDst++); 
00083  
00084     real = *pSrc++; 
00085     imag = *pSrc++; 
00086     acc0 = __SMUAD(real, real); 
00087     acc1 = __SMUAD(imag, imag); 
00088     /* store the result in 2.14 format in the destination buffer. */ 
00089     arm_sqrt_q15((q15_t) (((q63_t) acc0 + acc1) >> 17), pDst++); 
00090  
00091     real = *pSrc++; 
00092     imag = *pSrc++; 
00093     acc0 = __SMUAD(real, real); 
00094     acc1 = __SMUAD(imag, imag); 
00095     /* store the result in 2.14 format in the destination buffer. */ 
00096     arm_sqrt_q15((q15_t) (((q63_t) acc0 + acc1) >> 17), pDst++); 
00097  
00098     /* Decrement the loop counter */ 
00099     blkCnt--; 
00100   } 
00101  
00102   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.  
00103    ** No loop unrolling is used. */ 
00104   blkCnt = numSamples % 0x4u; 
00105  
00106   while(blkCnt > 0u) 
00107   { 
00108     /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */ 
00109     real = *pSrc++; 
00110     imag = *pSrc++; 
00111     acc0 = __SMUAD(real, real); 
00112     acc1 = __SMUAD(imag, imag); 
00113     /* store the result in 2.14 format in the destination buffer. */ 
00114     arm_sqrt_q15((q15_t) (((q63_t) acc0 + acc1) >> 17), pDst++); 
00115  
00116     /* Decrement the loop counter */ 
00117     blkCnt--; 
00118   } 
00119 } 
00120  
00121 /**  
00122  * @} end of cmplx_mag group  
00123  */