Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / ComplexMathFunctions / arm_cmplx_mag_f32.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_f32.c   
9 *   
10 * Description:  Floating-point 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  * @defgroup cmplx_mag Complex Magnitude   
38  *   
39  * Computes the magnitude of the elements of a complex data vector.   
40  *  
41  * The <code>pSrc</code> points to the source data and   
42  * <code>pDst</code> points to the where the result should be written.   
43  * <code>numSamples</code> specifies the number of complex samples   
44  * in the input array and the data is stored in an interleaved fashion   
45  * (real, imag, real, imag, ...).   
46  * The input array has a total of <code>2*numSamples</code> values;   
47  * the output array has a total of <code>numSamples</code> values.   
48  * The underlying algorithm is used:   
49  *   
50  * <pre>   
51  * for(n=0; n<numSamples; n++) {   
52  *     pDst[n] = sqrt(pSrc[(2*n)+0]^2 + pSrc[(2*n)+1]^2);   
53  * }   
54  * </pre>   
55  *   
56  * There are separate functions for floating-point, Q15, and Q31 data types.   
57  */
58
59 /**   
60  * @addtogroup cmplx_mag   
61  * @{   
62  */
63 /**   
64  * @brief Floating-point complex magnitude.   
65  * @param[in]       *pSrc points to complex input buffer   
66  * @param[out]      *pDst points to real output buffer   
67  * @param[in]       numSamples number of complex samples in the input vector   
68  * @return none.   
69  *   
70  */
71
72
73 void arm_cmplx_mag_f32(
74   float32_t * pSrc,
75   float32_t * pDst,
76   uint32_t numSamples)
77 {
78   float32_t realIn, imagIn;                      /* Temporary variables to hold input values */
79
80 #ifndef ARM_MATH_CM0
81
82   /* Run the below code for Cortex-M4 and Cortex-M3 */
83   uint32_t blkCnt;                               /* loop counter */
84
85   /*loop Unrolling */
86   blkCnt = numSamples >> 2u;
87
88   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
89    ** a second loop below computes the remaining 1 to 3 samples. */
90   while(blkCnt > 0u)
91   {
92
93     /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
94     realIn = *pSrc++;
95     imagIn = *pSrc++;
96     /* store the result in the destination buffer. */
97     arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
98
99     realIn = *pSrc++;
100     imagIn = *pSrc++;
101     arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
102
103     realIn = *pSrc++;
104     imagIn = *pSrc++;
105     arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
106
107     realIn = *pSrc++;
108     imagIn = *pSrc++;
109     arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
110
111
112     /* Decrement the loop counter */
113     blkCnt--;
114   }
115
116   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.   
117    ** No loop unrolling is used. */
118   blkCnt = numSamples % 0x4u;
119
120   while(blkCnt > 0u)
121   {
122     /* C[0] = sqrt(A[0] * A[0] + A[1] * A[1]) */
123     realIn = *pSrc++;
124     imagIn = *pSrc++;
125     /* store the result in the destination buffer. */
126     arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
127
128     /* Decrement the loop counter */
129     blkCnt--;
130   }
131
132 #else
133
134   /* Run the below code for Cortex-M0 */
135
136   while(numSamples > 0u)
137   {
138     /* out = sqrt((real * real) + (imag * imag)) */
139     realIn = *pSrc++;
140     imagIn = *pSrc++;
141     /* store the result in the destination buffer. */
142     arm_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
143
144     /* Decrement the loop counter */
145     numSamples--;
146   }
147
148 #endif /* #ifndef ARM_MATH_CM0 */
149
150 }
151
152 /**   
153  * @} end of cmplx_mag group   
154  */