]> git.gag.com Git - fw/stlink/blob - exampleF4/CMSIS/DSP_Lib/Source/ComplexMathFunctions/arm_cmplx_mag_q31.c
Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / ComplexMathFunctions / arm_cmplx_mag_q31.c
1 /* ----------------------------------------------------------------------   
2 * Copyright (C) 2010 ARM Limited. All rights reserved.   
3 *   
4 * $Date:        15. July 2011  
5 * $Revision:    V1.0.10  
6 *   
7 * Project:          CMSIS DSP Library   
8 * Title:                arm_cmplx_mag_q31.c   
9 *   
10 * Description:  Q31 complex magnitude   
11 *   
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 *  
14 * Version 1.0.10 2011/7/15 
15 *    Big Endian support added and Merged M0 and M3/M4 Source code.  
16 *   
17 * Version 1.0.3 2010/11/29  
18 *    Re-organized the CMSIS folders and updated documentation.   
19 *    
20 * Version 1.0.2 2010/11/11   
21 *    Documentation updated.    
22 *   
23 * Version 1.0.1 2010/10/05    
24 *    Production release and review comments incorporated.   
25 *   
26 * Version 1.0.0 2010/09/20    
27 *    Production release and review comments incorporated.   
28 * ---------------------------------------------------------------------------- */
29
30 #include "arm_math.h"
31
32 /**   
33  * @ingroup groupCmplxMath   
34  */
35
36 /**   
37  * @addtogroup cmplx_mag   
38  * @{   
39  */
40
41 /**   
42  * @brief  Q31 complex magnitude   
43  * @param  *pSrc points to the complex input vector   
44  * @param  *pDst points to the real output vector   
45  * @param  numSamples number of complex samples in the input vector   
46  * @return none.   
47  *   
48  * <b>Scaling and Overflow Behavior:</b>   
49  * \par   
50  * The function implements 1.31 by 1.31 multiplications and finally output is converted into 2.30 format.   
51  * Input down scaling is not required.   
52  */
53
54 void arm_cmplx_mag_q31(
55   q31_t * pSrc,
56   q31_t * pDst,
57   uint32_t numSamples)
58 {
59   q31_t real, imag;                              /* Temporary variables to hold input values */
60   q31_t acc0, acc1;                              /* Accumulators */
61
62 #ifndef ARM_MATH_CM0
63
64   /* Run the below code for Cortex-M4 and Cortex-M3 */
65   uint32_t blkCnt;                               /* loop counter */
66
67
68   /*loop Unrolling */
69   blkCnt = numSamples >> 2u;
70
71   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
72    ** a second loop below computes the remaining 1 to 3 samples. */
73   while(blkCnt > 0u)
74   {
75
76     /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
77     real = *pSrc++;
78     imag = *pSrc++;
79     acc0 = (q31_t) (((q63_t) real * real) >> 33);
80     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
81     /* store the result in 2.30 format in the destination buffer. */
82     arm_sqrt_q31(acc0 + acc1, pDst++);
83
84     real = *pSrc++;
85     imag = *pSrc++;
86     acc0 = (q31_t) (((q63_t) real * real) >> 33);
87     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
88     /* store the result in 2.30 format in the destination buffer. */
89     arm_sqrt_q31(acc0 + acc1, pDst++);
90
91     real = *pSrc++;
92     imag = *pSrc++;
93     acc0 = (q31_t) (((q63_t) real * real) >> 33);
94     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
95     /* store the result in 2.30 format in the destination buffer. */
96     arm_sqrt_q31(acc0 + acc1, pDst++);
97
98     real = *pSrc++;
99     imag = *pSrc++;
100     acc0 = (q31_t) (((q63_t) real * real) >> 33);
101     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
102     /* store the result in 2.30 format in the destination buffer. */
103     arm_sqrt_q31(acc0 + acc1, pDst++);
104
105     /* Decrement the loop counter */
106     blkCnt--;
107   }
108
109   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.   
110    ** No loop unrolling is used. */
111   blkCnt = numSamples % 0x4u;
112
113   while(blkCnt > 0u)
114   {
115     /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
116     real = *pSrc++;
117     imag = *pSrc++;
118     acc0 = (q31_t) (((q63_t) real * real) >> 33);
119     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
120     /* store the result in 2.30 format in the destination buffer. */
121     arm_sqrt_q31(acc0 + acc1, pDst++);
122
123     /* Decrement the loop counter */
124     blkCnt--;
125   }
126
127 #else
128
129   /* Run the below code for Cortex-M0 */
130
131   while(numSamples > 0u)
132   {
133     /* out = sqrt((real * real) + (imag * imag)) */
134     real = *pSrc++;
135     imag = *pSrc++;
136     acc0 = (q31_t) (((q63_t) real * real) >> 33);
137     acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
138     /* store the result in 2.30 format in the destination buffer. */
139     arm_sqrt_q31(acc0 + acc1, pDst++);
140
141     /* Decrement the loop counter */
142     numSamples--;
143   }
144
145 #endif /* #ifndef ARM_MATH_CM0 */
146
147 }
148
149 /**   
150  * @} end of cmplx_mag group   
151  */